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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 
60 #define WAVEFORM3_REG_B28_BIT 1 << 13
61 
67 #define WAVEFORM3_REG_HLB_BIT 1 << 12
68 
74 #define WAVEFORM3_REG_FSEL_BIT 1 << 11
75 
81 #define WAVEFORM3_REG_PSEL_BIT 1 << 10
82 
87 #define WAVEFORM3_REG_RESET_BIT 1 << 8
88 
94 #define WAVEFORM3_REG_SLEEP1_BIT 1 << 7
95 
101 #define WAVEFORM3_REG_SLEEP12_BIT 1 << 6
102 
108 #define WAVEFORM3_REG_OPBITEN_BIT 1 << 5
109 
115 #define WAVEFORM3_REG_DIV2_BIT 1 << 3
116 
122 #define WAVEFORM3_REG_MODE_BIT 1 << 1
123 
128 #define WAVEFORM3_REG_RESET_CLEAR 0x0000
129  // waveform3_reg
131 
146 #define WAVEFORM3_CFG_MODE_SINUSOIDAL 0x00
147 
152 #define WAVEFORM3_CFG_MODE_TRIANGLE 0x01
153 
159 #define WAVEFORM3_CFG_MODE_DAC_2 0x02
160 
165 #define WAVEFORM3_CFG_MODE_DAC 0x03
166  // mode
168 
183 #define WAVEFORM3_CFG_FREQ_REG0 0x00
184 
189 #define WAVEFORM3_CFG_FREQ_REG1 0x01
190  // freq_reg
192 
207 #define WAVEFORM3_CFG_PHASE_REG0 0x00
208 
213 #define WAVEFORM3_CFG_PHASE_REG1 0x01
214  // phase_reg
216 
231 #define WAVEFORM3_DEFAULT_FREQ0 0
232 
237 #define WAVEFORM3_DEFAULT_FREQ1 0
238 
243 #define WAVEFORM3_DEFAULT_PHASE0 0
244 
249 #define WAVEFORM3_DEFAULT_PHASE1 0
250  // waveform3_default_settings
252 
267 #define WAVEFORM3_MAP_MIKROBUS( cfg, mikrobus ) \
268  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
269  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
270  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
271  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
272  // waveform3_map // waveform3
275 
280 typedef struct
281 {
282  // Modules
283 
284  spi_master_t spi;
286  pin_name_t chip_select;
288 } waveform3_t;
289 
294 typedef struct
295 {
296  // Communication gpio pins
297 
298  pin_name_t miso;
299  pin_name_t mosi;
300  pin_name_t sck;
301  pin_name_t cs;
303  // static variable
304 
305  uint32_t spi_speed;
306  spi_master_mode_t spi_mode;
307  spi_master_chip_select_polarity_t cs_polarity;
310 
315 typedef enum
316 {
318  WAVEFORM3_ERROR = -1
319 
321 
338 
354 
366 
376 void waveform3_write_register ( waveform3_t *ctx, uint16_t data_in );
377 
387 
400 uint32_t waveform3_set_freq ( waveform3_t *ctx, uint32_t frequency, uint8_t freq_reg );
401 
413 uint16_t waveform3_set_phase ( waveform3_t *ctx, float phase, uint8_t phase_reg );
414 
426 void waveform3_set_mode ( waveform3_t *ctx, uint8_t mode, uint8_t freq_reg, uint8_t phase_reg );
427 
428 #ifdef __cplusplus
429 }
430 #endif
431 #endif // WAVEFORM3_H
432  // waveform3
434 
435 // ------------------------------------------------------------------------ END
waveform3_cfg_t::cs
pin_name_t cs
Definition: waveform3.h:301
waveform3_return_value_t
waveform3_return_value_t
Waveform 3 Click return value data.
Definition: waveform3.h:316
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:281
waveform3_t::spi
spi_master_t spi
Definition: waveform3.h:284
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:295
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:286
WAVEFORM3_OK
@ WAVEFORM3_OK
Definition: waveform3.h:317
waveform3_cfg_t::sck
pin_name_t sck
Definition: waveform3.h:300
waveform3_reset
void waveform3_reset(waveform3_t *ctx)
Waveform 3 reset function.
waveform3_cfg_t::mosi
pin_name_t mosi
Definition: waveform3.h:299
waveform3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: waveform3.h:307
WAVEFORM3_ERROR
@ WAVEFORM3_ERROR
Definition: waveform3.h:318
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:306
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:305
waveform3_cfg_t::miso
pin_name_t miso
Definition: waveform3.h:298
waveform3_cfg_setup
void waveform3_cfg_setup(waveform3_cfg_t *cfg)
Waveform 3 configuration object setup function.