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
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#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
144 // 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
245 // 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
269 // waveform4_map
270 // waveform4
271
276typedef 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;
288
293typedef 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
322
339
355
370
386err_t waveform4_write_registers ( waveform4_t *ctx, uint16_t reg, uint16_t *data_in, uint8_t len );
387
403err_t waveform4_read_registers ( waveform4_t *ctx, uint16_t reg, uint16_t *data_out, uint8_t len );
404
418err_t waveform4_write_register ( waveform4_t *ctx, uint16_t reg, uint16_t data_in );
419
433err_t waveform4_read_register ( waveform4_t *ctx, uint16_t reg, uint16_t *data_out );
434
444void waveform4_set_rst_pin ( waveform4_t *ctx, uint8_t state );
445
455void waveform4_set_trg_pin ( waveform4_t *ctx, uint8_t state );
456
466
480
494
508
524err_t waveform4_write_sram ( waveform4_t *ctx, uint16_t address, uint16_t *data_in, uint16_t len );
525
541err_t waveform4_read_sram ( waveform4_t *ctx, uint16_t address, uint16_t *data_out, uint16_t len );
542
555err_t waveform4_set_frequency ( waveform4_t *ctx, uint32_t freq );
556
570err_t waveform4_set_gain ( waveform4_t *ctx, uint8_t channel, float gain );
571
589err_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
596 // waveform4
597
598// ------------------------------------------------------------------------ END
err_t waveform4_update_settings(waveform4_t *ctx)
Waveform 4 update settings function.
void waveform4_set_trg_pin(waveform4_t *ctx, uint8_t state)
Waveform 4 set TRG pin function.
err_t waveform4_read_registers(waveform4_t *ctx, uint16_t reg, uint16_t *data_out, uint8_t len)
Waveform 4 data reading function.
err_t waveform4_init(waveform4_t *ctx, waveform4_cfg_t *cfg)
Waveform 4 initialization function.
err_t waveform4_read_register(waveform4_t *ctx, uint16_t reg, uint16_t *data_out)
Waveform 4 single data reading function.
err_t waveform4_write_register(waveform4_t *ctx, uint16_t reg, uint16_t data_in)
Waveform 4 single data writing function.
void waveform4_cfg_setup(waveform4_cfg_t *cfg)
Waveform 4 configuration object setup function.
void waveform4_set_rst_pin(waveform4_t *ctx, uint8_t state)
Waveform 4 set RST pin function.
err_t waveform4_start_pattern(waveform4_t *ctx)
Waveform 4 start pattern function.
err_t waveform4_stop_pattern(waveform4_t *ctx)
Waveform 4 stop pattern function.
err_t waveform4_set_frequency(waveform4_t *ctx, uint32_t freq)
Waveform 4 set frequency function.
void waveform4_reset_registers(waveform4_t *ctx)
Waveform 4 reset registers function.
err_t waveform4_default_cfg(waveform4_t *ctx)
Waveform 4 default configuration function.
err_t waveform4_set_gain(waveform4_t *ctx, uint8_t channel, float gain)
Waveform 4 set gain function.
err_t waveform4_write_registers(waveform4_t *ctx, uint16_t reg, uint16_t *data_in, uint8_t len)
Waveform 4 data writing function.
err_t waveform4_write_sram(waveform4_t *ctx, uint16_t address, uint16_t *data_in, uint16_t len)
Waveform 4 write sram function.
err_t waveform4_read_sram(waveform4_t *ctx, uint16_t address, uint16_t *data_out, uint16_t len)
Waveform 4 read sram function.
err_t waveform4_set_wave_output(waveform4_t *ctx, uint8_t channel, uint8_t wave)
Waveform 4 set wave output function.
uint8_t channel
Definition main.c:36
uint32_t freq
Definition main.c:34
float gain
Definition main.c:35
uint8_t wave
Definition main.c:37
This file contains SPI specific macros, functions, etc.
Waveform 4 Click configuration object.
Definition waveform4.h:294
spi_master_chip_select_polarity_t cs_polarity
Definition waveform4.h:308
pin_name_t sck
Definition waveform4.h:298
spi_master_mode_t spi_mode
Definition waveform4.h:307
pin_name_t mosi
Definition waveform4.h:297
uint32_t spi_speed
Definition waveform4.h:306
pin_name_t trg
Definition waveform4.h:303
pin_name_t miso
Definition waveform4.h:296
pin_name_t rst
Definition waveform4.h:302
pin_name_t cs
Definition waveform4.h:299
Waveform 4 Click context object.
Definition waveform4.h:277
spi_master_t spi
Definition waveform4.h:283
digital_out_t trg
Definition waveform4.h:280
digital_out_t rst
Definition waveform4.h:279
pin_name_t chip_select
Definition waveform4.h:285
waveform4_return_value_t
Waveform 4 Click return value data.
Definition waveform4.h:317
@ WAVEFORM4_ERROR
Definition waveform4.h:319
@ WAVEFORM4_OK
Definition waveform4.h:318