waveform4  2.0.0.0
waveform4.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 WAVEFORM4_H
29 #define WAVEFORM4_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 #include "spi_specifics.h"
53 
74 #define WAVEFORM4_REG_SPI_CONFIG 0x0000
75 #define WAVEFORM4_REG_POWER_CONFIG 0x0001
76 #define WAVEFORM4_REG_CLOCK_CONFIG 0x0002
77 #define WAVEFORM4_REG_REF_ADJ 0x0003
78 #define WAVEFORM4_REG_DAC4_AGAIN 0x0004
79 #define WAVEFORM4_REG_DAC3_AGAIN 0x0005
80 #define WAVEFORM4_REG_DAC2_AGAIN 0x0006
81 #define WAVEFORM4_REG_DAC1_AGAIN 0x0007
82 #define WAVEFORM4_REG_DACX_RANGE 0x0008
83 #define WAVEFORM4_REG_DAC4_RSET 0x0009
84 #define WAVEFORM4_REG_DAC3_RSET 0x000A
85 #define WAVEFORM4_REG_DAC2_RSET 0x000B
86 #define WAVEFORM4_REG_DAC1_RSET 0x000C
87 #define WAVEFORM4_REG_CAL_CONFIG 0x000D
88 #define WAVEFORM4_REG_COMP_OFFSET 0x000E
89 #define WAVEFORM4_REG_RAM_UPDATE 0x001D
90 #define WAVEFORM4_REG_PAT_STATUS 0x001E
91 #define WAVEFORM4_REG_PAT_TYPE 0x001F
92 #define WAVEFORM4_REG_PATTERN_DLY 0x0020
93 #define WAVEFORM4_REG_DAC4_DOF 0x0022
94 #define WAVEFORM4_REG_DAC3_DOF 0x0023
95 #define WAVEFORM4_REG_DAC2_DOF 0x0024
96 #define WAVEFORM4_REG_DAC1_DOF 0x0025
97 #define WAVEFORM4_REG_WAV43_CONFIG 0x0026
98 #define WAVEFORM4_REG_WAV21_CONFIG 0x0027
99 #define WAVEFORM4_REG_PAT_TIMEBASE 0x0028
100 #define WAVEFORM4_REG_PAT_PERIOD 0x0029
101 #define WAVEFORM4_REG_DAC43_PATX 0x002A
102 #define WAVEFORM4_REG_DAC21_PATX 0x002B
103 #define WAVEFORM4_REG_DOUT_START_DLY 0x002C
104 #define WAVEFORM4_REG_DOUT_CONFIG 0x002D
105 #define WAVEFORM4_REG_DAC4_CST 0x002E
106 #define WAVEFORM4_REG_DAC3_CST 0x002F
107 #define WAVEFORM4_REG_DAC2_CST 0x0030
108 #define WAVEFORM4_REG_DAC1_CST 0x0031
109 #define WAVEFORM4_REG_DAC4_DGAIN 0x0032
110 #define WAVEFORM4_REG_DAC3_DGAIN 0x0033
111 #define WAVEFORM4_REG_DAC2_DGAIN 0x0034
112 #define WAVEFORM4_REG_DAC1_DGAIN 0x0035
113 #define WAVEFORM4_REG_SAW43_CONFIG 0x0036
114 #define WAVEFORM4_REG_SAW21_CONFIG 0x0037
115 #define WAVEFORM4_REG_DDS_TW32 0x003E
116 #define WAVEFORM4_REG_DDS_TW1 0x003F
117 #define WAVEFORM4_REG_DDS4_PW 0x0040
118 #define WAVEFORM4_REG_DDS3_PW 0x0041
119 #define WAVEFORM4_REG_DDS2_PW 0x0042
120 #define WAVEFORM4_REG_DDS1_PW 0x0043
121 #define WAVEFORM4_REG_TRIG_TW_SEL 0x0044
122 #define WAVEFORM4_REG_DDSX_CONFIG 0x0045
123 #define WAVEFORM4_REG_TW_RAM_CONFIG 0x0047
124 #define WAVEFORM4_REG_START_DLY4 0x0050
125 #define WAVEFORM4_REG_START_ADDR4 0x0051
126 #define WAVEFORM4_REG_STOP_ADDR4 0x0052
127 #define WAVEFORM4_REG_DDS_CYC4 0x0053
128 #define WAVEFORM4_REG_START_DLY3 0x0054
129 #define WAVEFORM4_REG_START_ADDR3 0x0055
130 #define WAVEFORM4_REG_STOP_ADDR3 0x0056
131 #define WAVEFORM4_REG_DDS_CYC3 0x0057
132 #define WAVEFORM4_REG_START_DLY2 0x0058
133 #define WAVEFORM4_REG_START_ADDR2 0x0059
134 #define WAVEFORM4_REG_STOP_ADDR2 0x005A
135 #define WAVEFORM4_REG_DDS_CYC2 0x005B
136 #define WAVEFORM4_REG_START_DLY1 0x005C
137 #define WAVEFORM4_REG_START_ADDR1 0x005D
138 #define WAVEFORM4_REG_STOP_ADDR1 0x005E
139 #define WAVEFORM4_REG_DDS_CYC1 0x005F
140 #define WAVEFORM4_REG_CFG_ERROR 0x0060
141 #define WAVEFORM4_SRAM_ADDRESS_MIN 0x6000
142 #define WAVEFORM4_SRAM_ADDRESS_MAX 0x6FFF
143  // waveform4_reg
145 
160 #define WAVEFORM4_WAV_CFG_PRESTORE_CST 0x00
161 #define WAVEFORM4_WAV_CFG_PRESTORE_SAWTOOTH 0x10
162 #define WAVEFORM4_WAV_CFG_PRESTORE_PSEUDO 0x20
163 #define WAVEFORM4_WAV_CFG_PRESTORE_DDS 0x30
164 #define WAVEFORM4_WAV_CFG_WAVE_FROM_RAM 0x00
165 #define WAVEFORM4_WAV_CFG_WAVE_PRESTORED 0x01
166 #define WAVEFORM4_WAV_CFG_WAVE_PRESTORED_DELAY 0x02
167 #define WAVEFORM4_WAV_CFG_WAVE_PRESTORED_RAM 0x03
168 #define WAVEFORM4_DDSX_CFG_ENABLE_COSINE 0x08
169 #define WAVEFORM4_SAW_CFG_RAMP_UP 0x00
170 #define WAVEFORM4_SAW_CFG_RAMP_DOWN 0x01
171 #define WAVEFORM4_SAW_CFG_TRIANGLE 0x02
172 #define WAVEFORM4_SAW_CFG_NO_WAVE 0x03
173 #define WAVEFORM4_SAW_CFG_STEP_1 0x04
174 
179 #define WAVEFORM4_DEFAULT_GAIN 0.5
180 #define WAVEFORM4_DEFAULT_FREQUENCY 100000
181 
186 #define WAVEFORM4_UPDATE_SETTINGS 0x01
187 #define WAVEFORM4_MEM_ACCESS_ENABLE 0x04
188 #define WAVEFORM4_MEM_ACCESS_DISABLE 0x00
189 #define WAVEFORM4_BUF_READ 0x08
190 #define WAVEFORM4_START_PATTERN 0x01
191 #define WAVEFORM4_STOP_PATTERN 0x00
192 
197 #define WAVEFORM4_CHANNEL_1 0x00
198 #define WAVEFORM4_CHANNEL_2 0x01
199 #define WAVEFORM4_CHANNEL_3 0x02
200 #define WAVEFORM4_CHANNEL_4 0x03
201 
206 #define WAVEFORM4_WAVE_SINE 0x00
207 #define WAVEFORM4_WAVE_COSINE 0x01
208 #define WAVEFORM4_WAVE_TRIANGLE 0x02
209 #define WAVEFORM4_WAVE_POSITIVE_SAWTOOTH 0x03
210 #define WAVEFORM4_WAVE_NEGATIVE_SAWTOOTH 0x04
211 
216 #define WAVEFORM4_GAIN_MAX 2.0
217 #define WAVEFORM4_GAIN_MIN (-2.0)
218 #define WAVEFORM4_GAIN_RESOLUTION 1024
219 
224 #define WAVEFORM4_MASTER_CLOCK 125000000
225 #define WAVEFORM4_FREQ_RESOLUTION 0x1000000
226 
231 #define WAVEFORM4_SPI_READ_MASK 0x80
232 #define WAVEFORM4_SPI_WRITE_MASK 0x7F
233 
242 #define WAVEFORM4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
243 #define WAVEFORM4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
244  // waveform4_set
246 
261 #define WAVEFORM4_MAP_MIKROBUS( cfg, mikrobus ) \
262  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
263  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
264  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
265  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
266  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
267  cfg.trg = MIKROBUS( mikrobus, MIKROBUS_PWM );
268  // waveform4_map // waveform4
271 
276 typedef struct
277 {
278  // Output pins
279  digital_out_t rst;
280  digital_out_t trg;
282  // Modules
283  spi_master_t spi;
285  pin_name_t chip_select;
287 } waveform4_t;
288 
293 typedef struct
294 {
295  // Communication gpio pins
296  pin_name_t miso;
297  pin_name_t mosi;
298  pin_name_t sck;
299  pin_name_t cs;
301  // Additional gpio pins
302  pin_name_t rst;
303  pin_name_t trg;
305  // static variable
306  uint32_t spi_speed;
307  spi_master_mode_t spi_mode;
308  spi_master_chip_select_polarity_t cs_polarity;
311 
316 typedef enum
317 {
319  WAVEFORM4_ERROR = -1
320 
322 
339 
355 
370 
386 err_t waveform4_write_registers ( waveform4_t *ctx, uint16_t reg, uint16_t *data_in, uint8_t len );
387 
403 err_t waveform4_read_registers ( waveform4_t *ctx, uint16_t reg, uint16_t *data_out, uint8_t len );
404 
418 err_t waveform4_write_register ( waveform4_t *ctx, uint16_t reg, uint16_t data_in );
419 
433 err_t waveform4_read_register ( waveform4_t *ctx, uint16_t reg, uint16_t *data_out );
434 
444 void waveform4_set_rst_pin ( waveform4_t *ctx, uint8_t state );
445 
455 void waveform4_set_trg_pin ( waveform4_t *ctx, uint8_t state );
456 
466 
480 
494 
508 
524 err_t waveform4_write_sram ( waveform4_t *ctx, uint16_t address, uint16_t *data_in, uint16_t len );
525 
541 err_t waveform4_read_sram ( waveform4_t *ctx, uint16_t address, uint16_t *data_out, uint16_t len );
542 
555 err_t waveform4_set_frequency ( waveform4_t *ctx, uint32_t freq );
556 
570 err_t waveform4_set_gain ( waveform4_t *ctx, uint8_t channel, float gain );
571 
589 err_t waveform4_set_wave_output ( waveform4_t *ctx, uint8_t channel, uint8_t wave );
590 
591 #ifdef __cplusplus
592 }
593 #endif
594 #endif // WAVEFORM4_H
595  // waveform4
597 
598 // ------------------------------------------------------------------------ END
waveform4_write_register
err_t waveform4_write_register(waveform4_t *ctx, uint16_t reg, uint16_t data_in)
Waveform 4 single data writing function.
waveform4_t::chip_select
pin_name_t chip_select
Definition: waveform4.h:285
freq
uint32_t freq
Definition: main.c:34
waveform4_start_pattern
err_t waveform4_start_pattern(waveform4_t *ctx)
Waveform 4 start pattern function.
waveform4_stop_pattern
err_t waveform4_stop_pattern(waveform4_t *ctx)
Waveform 4 stop pattern function.
waveform4_t::trg
digital_out_t trg
Definition: waveform4.h:280
WAVEFORM4_OK
@ WAVEFORM4_OK
Definition: waveform4.h:318
waveform4_cfg_t::miso
pin_name_t miso
Definition: waveform4.h:296
gain
float gain
Definition: main.c:35
spi_specifics.h
This file contains SPI specific macros, functions, etc.
waveform4_init
err_t waveform4_init(waveform4_t *ctx, waveform4_cfg_t *cfg)
Waveform 4 initialization function.
waveform4_reset_registers
void waveform4_reset_registers(waveform4_t *ctx)
Waveform 4 reset registers function.
waveform4_cfg_t
Waveform 4 Click configuration object.
Definition: waveform4.h:294
waveform4_t
Waveform 4 Click context object.
Definition: waveform4.h:277
waveform4_return_value_t
waveform4_return_value_t
Waveform 4 Click return value data.
Definition: waveform4.h:317
waveform4_cfg_t::mosi
pin_name_t mosi
Definition: waveform4.h:297
waveform4_set_frequency
err_t waveform4_set_frequency(waveform4_t *ctx, uint32_t freq)
Waveform 4 set frequency function.
waveform4_t::rst
digital_out_t rst
Definition: waveform4.h:279
waveform4_cfg_t::rst
pin_name_t rst
Definition: waveform4.h:302
waveform4_t::spi
spi_master_t spi
Definition: waveform4.h:283
waveform4_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: waveform4.h:307
waveform4_read_sram
err_t waveform4_read_sram(waveform4_t *ctx, uint16_t address, uint16_t *data_out, uint16_t len)
Waveform 4 read sram function.
waveform4_write_registers
err_t waveform4_write_registers(waveform4_t *ctx, uint16_t reg, uint16_t *data_in, uint8_t len)
Waveform 4 data writing function.
waveform4_cfg_t::spi_speed
uint32_t spi_speed
Definition: waveform4.h:306
waveform4_set_gain
err_t waveform4_set_gain(waveform4_t *ctx, uint8_t channel, float gain)
Waveform 4 set gain function.
waveform4_cfg_t::trg
pin_name_t trg
Definition: waveform4.h:303
waveform4_cfg_t::sck
pin_name_t sck
Definition: waveform4.h:298
waveform4_cfg_t::cs
pin_name_t cs
Definition: waveform4.h:299
waveform4_default_cfg
err_t waveform4_default_cfg(waveform4_t *ctx)
Waveform 4 default configuration function.
channel
uint8_t channel
Definition: main.c:36
wave
uint8_t wave
Definition: main.c:37
waveform4_cfg_setup
void waveform4_cfg_setup(waveform4_cfg_t *cfg)
Waveform 4 configuration object setup function.
waveform4_set_wave_output
err_t waveform4_set_wave_output(waveform4_t *ctx, uint8_t channel, uint8_t wave)
Waveform 4 set wave output function.
waveform4_set_trg_pin
void waveform4_set_trg_pin(waveform4_t *ctx, uint8_t state)
Waveform 4 set TRG pin function.
waveform4_update_settings
err_t waveform4_update_settings(waveform4_t *ctx)
Waveform 4 update settings function.
waveform4_write_sram
err_t waveform4_write_sram(waveform4_t *ctx, uint16_t address, uint16_t *data_in, uint16_t len)
Waveform 4 write sram function.
waveform4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: waveform4.h:308
waveform4_set_rst_pin
void waveform4_set_rst_pin(waveform4_t *ctx, uint8_t state)
Waveform 4 set RST pin function.
WAVEFORM4_ERROR
@ WAVEFORM4_ERROR
Definition: waveform4.h:319
waveform4_read_register
err_t waveform4_read_register(waveform4_t *ctx, uint16_t reg, uint16_t *data_out)
Waveform 4 single data reading function.
waveform4_read_registers
err_t waveform4_read_registers(waveform4_t *ctx, uint16_t reg, uint16_t *data_out, uint8_t len)
Waveform 4 data reading function.