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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define WAVEFORM4_REG_SPI_CONFIG 0x0000
61 #define WAVEFORM4_REG_POWER_CONFIG 0x0001
62 #define WAVEFORM4_REG_CLOCK_CONFIG 0x0002
63 #define WAVEFORM4_REG_REF_ADJ 0x0003
64 #define WAVEFORM4_REG_DAC4_AGAIN 0x0004
65 #define WAVEFORM4_REG_DAC3_AGAIN 0x0005
66 #define WAVEFORM4_REG_DAC2_AGAIN 0x0006
67 #define WAVEFORM4_REG_DAC1_AGAIN 0x0007
68 #define WAVEFORM4_REG_DACX_RANGE 0x0008
69 #define WAVEFORM4_REG_DAC4_RSET 0x0009
70 #define WAVEFORM4_REG_DAC3_RSET 0x000A
71 #define WAVEFORM4_REG_DAC2_RSET 0x000B
72 #define WAVEFORM4_REG_DAC1_RSET 0x000C
73 #define WAVEFORM4_REG_CAL_CONFIG 0x000D
74 #define WAVEFORM4_REG_COMP_OFFSET 0x000E
75 #define WAVEFORM4_REG_RAM_UPDATE 0x001D
76 #define WAVEFORM4_REG_PAT_STATUS 0x001E
77 #define WAVEFORM4_REG_PAT_TYPE 0x001F
78 #define WAVEFORM4_REG_PATTERN_DLY 0x0020
79 #define WAVEFORM4_REG_DAC4_DOF 0x0022
80 #define WAVEFORM4_REG_DAC3_DOF 0x0023
81 #define WAVEFORM4_REG_DAC2_DOF 0x0024
82 #define WAVEFORM4_REG_DAC1_DOF 0x0025
83 #define WAVEFORM4_REG_WAV43_CONFIG 0x0026
84 #define WAVEFORM4_REG_WAV21_CONFIG 0x0027
85 #define WAVEFORM4_REG_PAT_TIMEBASE 0x0028
86 #define WAVEFORM4_REG_PAT_PERIOD 0x0029
87 #define WAVEFORM4_REG_DAC43_PATX 0x002A
88 #define WAVEFORM4_REG_DAC21_PATX 0x002B
89 #define WAVEFORM4_REG_DOUT_START_DLY 0x002C
90 #define WAVEFORM4_REG_DOUT_CONFIG 0x002D
91 #define WAVEFORM4_REG_DAC4_CST 0x002E
92 #define WAVEFORM4_REG_DAC3_CST 0x002F
93 #define WAVEFORM4_REG_DAC2_CST 0x0030
94 #define WAVEFORM4_REG_DAC1_CST 0x0031
95 #define WAVEFORM4_REG_DAC4_DGAIN 0x0032
96 #define WAVEFORM4_REG_DAC3_DGAIN 0x0033
97 #define WAVEFORM4_REG_DAC2_DGAIN 0x0034
98 #define WAVEFORM4_REG_DAC1_DGAIN 0x0035
99 #define WAVEFORM4_REG_SAW43_CONFIG 0x0036
100 #define WAVEFORM4_REG_SAW21_CONFIG 0x0037
101 #define WAVEFORM4_REG_DDS_TW32 0x003E
102 #define WAVEFORM4_REG_DDS_TW1 0x003F
103 #define WAVEFORM4_REG_DDS4_PW 0x0040
104 #define WAVEFORM4_REG_DDS3_PW 0x0041
105 #define WAVEFORM4_REG_DDS2_PW 0x0042
106 #define WAVEFORM4_REG_DDS1_PW 0x0043
107 #define WAVEFORM4_REG_TRIG_TW_SEL 0x0044
108 #define WAVEFORM4_REG_DDSX_CONFIG 0x0045
109 #define WAVEFORM4_REG_TW_RAM_CONFIG 0x0047
110 #define WAVEFORM4_REG_START_DLY4 0x0050
111 #define WAVEFORM4_REG_START_ADDR4 0x0051
112 #define WAVEFORM4_REG_STOP_ADDR4 0x0052
113 #define WAVEFORM4_REG_DDS_CYC4 0x0053
114 #define WAVEFORM4_REG_START_DLY3 0x0054
115 #define WAVEFORM4_REG_START_ADDR3 0x0055
116 #define WAVEFORM4_REG_STOP_ADDR3 0x0056
117 #define WAVEFORM4_REG_DDS_CYC3 0x0057
118 #define WAVEFORM4_REG_START_DLY2 0x0058
119 #define WAVEFORM4_REG_START_ADDR2 0x0059
120 #define WAVEFORM4_REG_STOP_ADDR2 0x005A
121 #define WAVEFORM4_REG_DDS_CYC2 0x005B
122 #define WAVEFORM4_REG_START_DLY1 0x005C
123 #define WAVEFORM4_REG_START_ADDR1 0x005D
124 #define WAVEFORM4_REG_STOP_ADDR1 0x005E
125 #define WAVEFORM4_REG_DDS_CYC1 0x005F
126 #define WAVEFORM4_REG_CFG_ERROR 0x0060
127 #define WAVEFORM4_SRAM_ADDRESS_MIN 0x6000
128 #define WAVEFORM4_SRAM_ADDRESS_MAX 0x6FFF
129  // waveform4_reg
131 
146 #define WAVEFORM4_WAV_CFG_PRESTORE_CST 0x00
147 #define WAVEFORM4_WAV_CFG_PRESTORE_SAWTOOTH 0x10
148 #define WAVEFORM4_WAV_CFG_PRESTORE_PSEUDO 0x20
149 #define WAVEFORM4_WAV_CFG_PRESTORE_DDS 0x30
150 #define WAVEFORM4_WAV_CFG_WAVE_FROM_RAM 0x00
151 #define WAVEFORM4_WAV_CFG_WAVE_PRESTORED 0x01
152 #define WAVEFORM4_WAV_CFG_WAVE_PRESTORED_DELAY 0x02
153 #define WAVEFORM4_WAV_CFG_WAVE_PRESTORED_RAM 0x03
154 #define WAVEFORM4_DDSX_CFG_ENABLE_COSINE 0x08
155 #define WAVEFORM4_SAW_CFG_RAMP_UP 0x00
156 #define WAVEFORM4_SAW_CFG_RAMP_DOWN 0x01
157 #define WAVEFORM4_SAW_CFG_TRIANGLE 0x02
158 #define WAVEFORM4_SAW_CFG_NO_WAVE 0x03
159 #define WAVEFORM4_SAW_CFG_STEP_1 0x04
160 
165 #define WAVEFORM4_DEFAULT_GAIN 0.5
166 #define WAVEFORM4_DEFAULT_FREQUENCY 100000
167 
172 #define WAVEFORM4_UPDATE_SETTINGS 0x01
173 #define WAVEFORM4_MEM_ACCESS_ENABLE 0x04
174 #define WAVEFORM4_MEM_ACCESS_DISABLE 0x00
175 #define WAVEFORM4_BUF_READ 0x08
176 #define WAVEFORM4_START_PATTERN 0x01
177 #define WAVEFORM4_STOP_PATTERN 0x00
178 
183 #define WAVEFORM4_CHANNEL_1 0x00
184 #define WAVEFORM4_CHANNEL_2 0x01
185 #define WAVEFORM4_CHANNEL_3 0x02
186 #define WAVEFORM4_CHANNEL_4 0x03
187 
192 #define WAVEFORM4_WAVE_SINE 0x00
193 #define WAVEFORM4_WAVE_COSINE 0x01
194 #define WAVEFORM4_WAVE_TRIANGLE 0x02
195 #define WAVEFORM4_WAVE_POSITIVE_SAWTOOTH 0x03
196 #define WAVEFORM4_WAVE_NEGATIVE_SAWTOOTH 0x04
197 
202 #define WAVEFORM4_GAIN_MAX 2.0
203 #define WAVEFORM4_GAIN_MIN (-2.0)
204 #define WAVEFORM4_GAIN_RESOLUTION 1024
205 
210 #define WAVEFORM4_MASTER_CLOCK 125000000
211 #define WAVEFORM4_FREQ_RESOLUTION 0x1000000
212 
217 #define WAVEFORM4_SPI_READ_MASK 0x80
218 #define WAVEFORM4_SPI_WRITE_MASK 0x7F
219 
228 #define WAVEFORM4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
229 #define WAVEFORM4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
230  // waveform4_set
232 
247 #define WAVEFORM4_MAP_MIKROBUS( cfg, mikrobus ) \
248  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
249  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
250  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
251  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
252  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
253  cfg.trg = MIKROBUS( mikrobus, MIKROBUS_PWM );
254  // waveform4_map // waveform4
257 
262 typedef struct
263 {
264  // Output pins
265  digital_out_t rst;
266  digital_out_t trg;
268  // Modules
269  spi_master_t spi;
271  pin_name_t chip_select;
273 } waveform4_t;
274 
279 typedef struct
280 {
281  // Communication gpio pins
282  pin_name_t miso;
283  pin_name_t mosi;
284  pin_name_t sck;
285  pin_name_t cs;
287  // Additional gpio pins
288  pin_name_t rst;
289  pin_name_t trg;
291  // static variable
292  uint32_t spi_speed;
293  spi_master_mode_t spi_mode;
294  spi_master_chip_select_polarity_t cs_polarity;
297 
302 typedef enum
303 {
305  WAVEFORM4_ERROR = -1
306 
308 
325 
341 
356 
372 err_t waveform4_write_registers ( waveform4_t *ctx, uint16_t reg, uint16_t *data_in, uint8_t len );
373 
389 err_t waveform4_read_registers ( waveform4_t *ctx, uint16_t reg, uint16_t *data_out, uint8_t len );
390 
404 err_t waveform4_write_register ( waveform4_t *ctx, uint16_t reg, uint16_t data_in );
405 
419 err_t waveform4_read_register ( waveform4_t *ctx, uint16_t reg, uint16_t *data_out );
420 
430 void waveform4_set_rst_pin ( waveform4_t *ctx, uint8_t state );
431 
441 void waveform4_set_trg_pin ( waveform4_t *ctx, uint8_t state );
442 
452 
466 
480 
494 
510 err_t waveform4_write_sram ( waveform4_t *ctx, uint16_t address, uint16_t *data_in, uint16_t len );
511 
527 err_t waveform4_read_sram ( waveform4_t *ctx, uint16_t address, uint16_t *data_out, uint16_t len );
528 
541 err_t waveform4_set_frequency ( waveform4_t *ctx, uint32_t freq );
542 
556 err_t waveform4_set_gain ( waveform4_t *ctx, uint8_t channel, float gain );
557 
575 err_t waveform4_set_wave_output ( waveform4_t *ctx, uint8_t channel, uint8_t wave );
576 
577 #ifdef __cplusplus
578 }
579 #endif
580 #endif // WAVEFORM4_H
581  // waveform4
583 
584 // ------------------------------------------------------------------------ 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:271
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:266
WAVEFORM4_OK
@ WAVEFORM4_OK
Definition: waveform4.h:304
waveform4_cfg_t::miso
pin_name_t miso
Definition: waveform4.h:282
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:280
waveform4_t
Waveform 4 Click context object.
Definition: waveform4.h:263
waveform4_return_value_t
waveform4_return_value_t
Waveform 4 Click return value data.
Definition: waveform4.h:303
waveform4_cfg_t::mosi
pin_name_t mosi
Definition: waveform4.h:283
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:265
waveform4_cfg_t::rst
pin_name_t rst
Definition: waveform4.h:288
waveform4_t::spi
spi_master_t spi
Definition: waveform4.h:269
waveform4_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: waveform4.h:293
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:292
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:289
waveform4_cfg_t::sck
pin_name_t sck
Definition: waveform4.h:284
waveform4_cfg_t::cs
pin_name_t cs
Definition: waveform4.h:285
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:294
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:305
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.