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
32extern "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
144 // 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
181 // mode
182
197#define WAVEFORM3_CFG_FREQ_REG0 0x00
198
203#define WAVEFORM3_CFG_FREQ_REG1 0x01
204
205 // freq_reg
206
221#define WAVEFORM3_CFG_PHASE_REG0 0x00
222
227#define WAVEFORM3_CFG_PHASE_REG1 0x01
228
229 // 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
265 // 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
287 // waveform3_map
288 // waveform3
289
294typedef struct
295{
296 // Modules
297
298 spi_master_t spi;
300 pin_name_t chip_select;
303
308typedef 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
335
352
368
380
390void waveform3_write_register ( waveform3_t *ctx, uint16_t data_in );
391
401
414uint32_t waveform3_set_freq ( waveform3_t *ctx, uint32_t frequency, uint8_t freq_reg );
415
427uint16_t waveform3_set_phase ( waveform3_t *ctx, float phase, uint8_t phase_reg );
428
440void 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
447 // waveform3
448
449// ------------------------------------------------------------------------ END
void waveform3_set_mode(waveform3_t *ctx, uint8_t mode, uint8_t freq_reg, uint8_t phase_reg)
Waveform 3 set mode function.
uint16_t waveform3_set_phase(waveform3_t *ctx, float phase, uint8_t phase_reg)
Waveform 3 set phase function.
void waveform3_cfg_setup(waveform3_cfg_t *cfg)
Waveform 3 configuration object setup function.
void waveform3_reset(waveform3_t *ctx)
Waveform 3 reset function.
void waveform3_default_cfg(waveform3_t *ctx)
Waveform 3 default configuration function.
uint32_t waveform3_set_freq(waveform3_t *ctx, uint32_t frequency, uint8_t freq_reg)
Waveform 3 set frequency function.
err_t waveform3_init(waveform3_t *ctx, waveform3_cfg_t *cfg)
Waveform 3 initialization function.
void waveform3_write_register(waveform3_t *ctx, uint16_t data_in)
Waveform 3 write register function.
Waveform 3 Click configuration object.
Definition waveform3.h:309
spi_master_chip_select_polarity_t cs_polarity
Definition waveform3.h:321
pin_name_t sck
Definition waveform3.h:314
spi_master_mode_t spi_mode
Definition waveform3.h:320
pin_name_t mosi
Definition waveform3.h:313
uint32_t spi_speed
Definition waveform3.h:319
pin_name_t miso
Definition waveform3.h:312
pin_name_t cs
Definition waveform3.h:315
Waveform 3 Click context object.
Definition waveform3.h:295
spi_master_t spi
Definition waveform3.h:298
pin_name_t chip_select
Definition waveform3.h:300
waveform3_return_value_t
Waveform 3 Click return value data.
Definition waveform3.h:330
@ WAVEFORM3_OK
Definition waveform3.h:331
@ WAVEFORM3_ERROR
Definition waveform3.h:332