waveform3  2.0.0.0
waveform3.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef WAVEFORM3_H
29 #define WAVEFORM3_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_spi_master.h"
52 
74 #define WAVEFORM3_REG_B28_BIT 1 << 13
75 
81 #define WAVEFORM3_REG_HLB_BIT 1 << 12
82 
88 #define WAVEFORM3_REG_FSEL_BIT 1 << 11
89 
95 #define WAVEFORM3_REG_PSEL_BIT 1 << 10
96 
101 #define WAVEFORM3_REG_RESET_BIT 1 << 8
102 
108 #define WAVEFORM3_REG_SLEEP1_BIT 1 << 7
109 
115 #define WAVEFORM3_REG_SLEEP12_BIT 1 << 6
116 
122 #define WAVEFORM3_REG_OPBITEN_BIT 1 << 5
123 
129 #define WAVEFORM3_REG_DIV2_BIT 1 << 3
130 
136 #define WAVEFORM3_REG_MODE_BIT 1 << 1
137 
142 #define WAVEFORM3_REG_RESET_CLEAR 0x0000
143  // waveform3_reg
145 
160 #define WAVEFORM3_CFG_MODE_SINUSOIDAL 0x00
161 
166 #define WAVEFORM3_CFG_MODE_TRIANGLE 0x01
167 
173 #define WAVEFORM3_CFG_MODE_DAC_2 0x02
174 
179 #define WAVEFORM3_CFG_MODE_DAC 0x03
180  // mode
182 
197 #define WAVEFORM3_CFG_FREQ_REG0 0x00
198 
203 #define WAVEFORM3_CFG_FREQ_REG1 0x01
204  // freq_reg
206 
221 #define WAVEFORM3_CFG_PHASE_REG0 0x00
222 
227 #define WAVEFORM3_CFG_PHASE_REG1 0x01
228  // phase_reg
230 
245 #define WAVEFORM3_DEFAULT_FREQ0 0
246 
251 #define WAVEFORM3_DEFAULT_FREQ1 0
252 
257 #define WAVEFORM3_DEFAULT_PHASE0 0
258 
263 #define WAVEFORM3_DEFAULT_PHASE1 0
264  // waveform3_default_settings
266 
281 #define WAVEFORM3_MAP_MIKROBUS( cfg, mikrobus ) \
282  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
283  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
284  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
285  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
286  // waveform3_map // waveform3
289 
294 typedef struct
295 {
296  // Modules
297 
298  spi_master_t spi;
300  pin_name_t chip_select;
302 } waveform3_t;
303 
308 typedef struct
309 {
310  // Communication gpio pins
311 
312  pin_name_t miso;
313  pin_name_t mosi;
314  pin_name_t sck;
315  pin_name_t cs;
317  // static variable
318 
319  uint32_t spi_speed;
320  spi_master_mode_t spi_mode;
321  spi_master_chip_select_polarity_t cs_polarity;
324 
329 typedef enum
330 {
332  WAVEFORM3_ERROR = -1
333 
335 
352 
368 
380 
390 void waveform3_write_register ( waveform3_t *ctx, uint16_t data_in );
391 
401 
414 uint32_t waveform3_set_freq ( waveform3_t *ctx, uint32_t frequency, uint8_t freq_reg );
415 
427 uint16_t waveform3_set_phase ( waveform3_t *ctx, float phase, uint8_t phase_reg );
428 
440 void waveform3_set_mode ( waveform3_t *ctx, uint8_t mode, uint8_t freq_reg, uint8_t phase_reg );
441 
442 #ifdef __cplusplus
443 }
444 #endif
445 #endif // WAVEFORM3_H
446  // waveform3
448 
449 // ------------------------------------------------------------------------ END
waveform3_cfg_t::cs
pin_name_t cs
Definition: waveform3.h:315
waveform3_return_value_t
waveform3_return_value_t
Waveform 3 Click return value data.
Definition: waveform3.h:330
waveform3_set_mode
void waveform3_set_mode(waveform3_t *ctx, uint8_t mode, uint8_t freq_reg, uint8_t phase_reg)
Waveform 3 set mode function.
waveform3_t
Waveform 3 Click context object.
Definition: waveform3.h:295
waveform3_t::spi
spi_master_t spi
Definition: waveform3.h:298
waveform3_write_register
void waveform3_write_register(waveform3_t *ctx, uint16_t data_in)
Waveform 3 write register function.
waveform3_cfg_t
Waveform 3 Click configuration object.
Definition: waveform3.h:309
waveform3_init
err_t waveform3_init(waveform3_t *ctx, waveform3_cfg_t *cfg)
Waveform 3 initialization function.
waveform3_t::chip_select
pin_name_t chip_select
Definition: waveform3.h:300
WAVEFORM3_OK
@ WAVEFORM3_OK
Definition: waveform3.h:331
waveform3_cfg_t::sck
pin_name_t sck
Definition: waveform3.h:314
waveform3_reset
void waveform3_reset(waveform3_t *ctx)
Waveform 3 reset function.
waveform3_cfg_t::mosi
pin_name_t mosi
Definition: waveform3.h:313
waveform3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: waveform3.h:321
WAVEFORM3_ERROR
@ WAVEFORM3_ERROR
Definition: waveform3.h:332
waveform3_set_freq
uint32_t waveform3_set_freq(waveform3_t *ctx, uint32_t frequency, uint8_t freq_reg)
Waveform 3 set frequency function.
waveform3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: waveform3.h:320
waveform3_set_phase
uint16_t waveform3_set_phase(waveform3_t *ctx, float phase, uint8_t phase_reg)
Waveform 3 set phase function.
waveform3_default_cfg
void waveform3_default_cfg(waveform3_t *ctx)
Waveform 3 default configuration function.
waveform3_cfg_t::spi_speed
uint32_t spi_speed
Definition: waveform3.h:319
waveform3_cfg_t::miso
pin_name_t miso
Definition: waveform3.h:312
waveform3_cfg_setup
void waveform3_cfg_setup(waveform3_cfg_t *cfg)
Waveform 3 configuration object setup function.