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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 
70 #define WAVEFORM3_REG_B28_BIT 1 << 13
71 
77 #define WAVEFORM3_REG_HLB_BIT 1 << 12
78 
84 #define WAVEFORM3_REG_FSEL_BIT 1 << 11
85 
91 #define WAVEFORM3_REG_PSEL_BIT 1 << 10
92 
97 #define WAVEFORM3_REG_RESET_BIT 1 << 8
98 
104 #define WAVEFORM3_REG_SLEEP1_BIT 1 << 7
105 
111 #define WAVEFORM3_REG_SLEEP12_BIT 1 << 6
112 
118 #define WAVEFORM3_REG_OPBITEN_BIT 1 << 5
119 
125 #define WAVEFORM3_REG_DIV2_BIT 1 << 3
126 
132 #define WAVEFORM3_REG_MODE_BIT 1 << 1
133 
138 #define WAVEFORM3_REG_RESET_CLEAR 0x0000
139  // waveform3_reg
141 
156 #define WAVEFORM3_CFG_MODE_SINUSOIDAL 0x00
157 
162 #define WAVEFORM3_CFG_MODE_TRIANGLE 0x01
163 
169 #define WAVEFORM3_CFG_MODE_DAC_2 0x02
170 
175 #define WAVEFORM3_CFG_MODE_DAC 0x03
176  // mode
178 
193 #define WAVEFORM3_CFG_FREQ_REG0 0x00
194 
199 #define WAVEFORM3_CFG_FREQ_REG1 0x01
200  // freq_reg
202 
217 #define WAVEFORM3_CFG_PHASE_REG0 0x00
218 
223 #define WAVEFORM3_CFG_PHASE_REG1 0x01
224  // phase_reg
226 
241 #define WAVEFORM3_DEFAULT_FREQ0 0
242 
247 #define WAVEFORM3_DEFAULT_FREQ1 0
248 
253 #define WAVEFORM3_DEFAULT_PHASE0 0
254 
259 #define WAVEFORM3_DEFAULT_PHASE1 0
260  // waveform3_default_settings
262 
277 #define WAVEFORM3_MAP_MIKROBUS( cfg, mikrobus ) \
278  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
279  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
280  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
281  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
282  // waveform3_map // waveform3
285 
290 typedef struct
291 {
292  // Modules
293 
294  spi_master_t spi;
296  pin_name_t chip_select;
298 } waveform3_t;
299 
304 typedef struct
305 {
306  // Communication gpio pins
307 
308  pin_name_t miso;
309  pin_name_t mosi;
310  pin_name_t sck;
311  pin_name_t cs;
313  // static variable
314 
315  uint32_t spi_speed;
316  spi_master_mode_t spi_mode;
317  spi_master_chip_select_polarity_t cs_polarity;
320 
325 typedef enum
326 {
328  WAVEFORM3_ERROR = -1
329 
331 
348 
364 
376 
386 void waveform3_write_register ( waveform3_t *ctx, uint16_t data_in );
387 
397 
410 uint32_t waveform3_set_freq ( waveform3_t *ctx, uint32_t frequency, uint8_t freq_reg );
411 
423 uint16_t waveform3_set_phase ( waveform3_t *ctx, float phase, uint8_t phase_reg );
424 
436 void waveform3_set_mode ( waveform3_t *ctx, uint8_t mode, uint8_t freq_reg, uint8_t phase_reg );
437 
438 #ifdef __cplusplus
439 }
440 #endif
441 #endif // WAVEFORM3_H
442  // waveform3
444 
445 // ------------------------------------------------------------------------ END
waveform3_cfg_t::cs
pin_name_t cs
Definition: waveform3.h:311
waveform3_return_value_t
waveform3_return_value_t
Waveform 3 Click return value data.
Definition: waveform3.h:326
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:291
waveform3_t::spi
spi_master_t spi
Definition: waveform3.h:294
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:305
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:296
WAVEFORM3_OK
@ WAVEFORM3_OK
Definition: waveform3.h:327
waveform3_cfg_t::sck
pin_name_t sck
Definition: waveform3.h:310
waveform3_reset
void waveform3_reset(waveform3_t *ctx)
Waveform 3 reset function.
waveform3_cfg_t::mosi
pin_name_t mosi
Definition: waveform3.h:309
waveform3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: waveform3.h:317
WAVEFORM3_ERROR
@ WAVEFORM3_ERROR
Definition: waveform3.h:328
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:316
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:315
waveform3_cfg_t::miso
pin_name_t miso
Definition: waveform3.h:308
waveform3_cfg_setup
void waveform3_cfg_setup(waveform3_cfg_t *cfg)
Waveform 3 configuration object setup function.