daq3 2.0.0.0
daq3.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 DAQ3_H
29#define DAQ3_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_spi_master.h"
38
59#define DAQ3_REG_0 0x00
60#define DAQ3_REG_1 0x01
61#define DAQ3_REG_2 0x02
62#define DAQ3_REG_3 0x03
63#define DAQ3_REG_CMD 0x14
64 // daq3_reg
66
81#define DAQ3_CMD_WEN 0x00
82#define DAQ3_CMD_REG_READ 0x40
83#define DAQ3_CMD_REG_WRITE 0x00
84 // daq3_set
86
96#define DAQ3_CMD_REG_DEFAULT 0xE1
97 // daq3_set
99
110#define DAQ3_LOW_POWER_MODE 0x00
111#define DAQ3_FULL_PERFORMANCE_MODE 0x01
112 // mode
114
125#define DAQ3_PD_REF_POWER_DOWN 0x00
126#define DAQ3_PD_REF_POWER_UP 0x01
127 // pd_ref
129
140#define DAQ3_PD_AMP_POWER_DOWN 0x00
141#define DAQ3_PD_AMP_POWER_UP 0x01
142 // pd_amp
144
159#define DAQ3_MAP_MIKROBUS( cfg, mikrobus ) \
160 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
161 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
162 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
163 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
164 cfg.dam = MIKROBUS( mikrobus, MIKROBUS_AN ); \
165 cfg.dre = MIKROBUS( mikrobus, MIKROBUS_RST ); \
166 cfg.mod = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
167 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
168 // daq3_map // daq3
171
176typedef struct
177{
178 // Output pins
179
180 digital_out_t dam;
181 digital_out_t dre;
182 digital_out_t mod;
184 // Input pins
185
186 digital_in_t int_pin;
188 // Modules
189
190 spi_master_t spi;
192 pin_name_t chip_select;
194} daq3_t;
195
200typedef struct
201{
203 uint8_t span_comp;
204 uint8_t high_z_mode;
205 uint8_t turbo_mode;
209
214typedef struct
215{
216 // Communication gpio pins
217
218 pin_name_t miso;
219 pin_name_t mosi;
220 pin_name_t sck;
221 pin_name_t cs;
223 // Additional gpio pins
224
225 pin_name_t dam;
226 pin_name_t dre;
227 pin_name_t mod;
228 pin_name_t int_pin;
230 // static variable
231
232 uint32_t spi_speed;
233 spi_master_mode_t spi_mode;
234 spi_master_chip_select_polarity_t cs_polarity;
236} daq3_cfg_t;
237
254
269err_t daq3_init ( daq3_t *ctx, daq3_cfg_t *cfg );
270
282
297void daq3_set_pwr_mode ( daq3_t *ctx, uint8_t mode );
298
313void daq3_set_pwr_down_ref_buf ( daq3_t *ctx, uint8_t pd_ref );
314
329void daq3_set_pwr_down_amp ( daq3_t *ctx, uint8_t pd_amp );
330
331
345uint8_t daq3_get_sdo ( daq3_t *ctx );
346
361err_t daq3_generic_write ( daq3_t *ctx, uint8_t reg, uint8_t data_in );
362
377err_t daq3_generic_read ( daq3_t *ctx, uint8_t reg, uint8_t *data_out );
378
393err_t daq3_set_reg_cfg ( daq3_t *ctx, daq3_reg_cfg_t cfg_data );
394
409err_t daq3_get_reg_cfg ( daq3_t *ctx, daq3_reg_cfg_t *cfg_data );
410
425
440
441#ifdef __cplusplus
442}
443#endif
444#endif // DAQ3_H
445 // daq3
447
448// ------------------------------------------------------------------------ END
void daq3_set_pwr_mode(daq3_t *ctx, uint8_t mode)
DAQ 3 set power mode function.
err_t daq3_init(daq3_t *ctx, daq3_cfg_t *cfg)
DAQ 3 initialization function.
err_t daq3_generic_read(daq3_t *ctx, uint8_t reg, uint8_t *data_out)
DAQ 3 data reading function.
uint8_t daq3_get_sdo(daq3_t *ctx)
DAQ 3 get state of SDO function.
float daq3_get_voltage(daq3_t *ctx)
DAQ 3 get voltage function.
void daq3_default_cfg(daq3_t *ctx)
DAQ 3 default configuration function.
void daq3_set_pwr_down_amp(daq3_t *ctx, uint8_t pd_amp)
DAQ 3 set power Amplifier function.
void daq3_cfg_setup(daq3_cfg_t *cfg)
DAQ 3 configuration object setup function.
err_t daq3_generic_write(daq3_t *ctx, uint8_t reg, uint8_t data_in)
DAQ 3 data writing function.
int32_t daq3_get_conversion_result(daq3_t *ctx, daq3_reg_cfg_t cfg_data)
DAQ 3 get conversion result function.
err_t daq3_set_reg_cfg(daq3_t *ctx, daq3_reg_cfg_t cfg_data)
DAQ 3 set command register function.
err_t daq3_get_reg_cfg(daq3_t *ctx, daq3_reg_cfg_t *cfg_data)
DAQ 3 get command register function.
void daq3_set_pwr_down_ref_buf(daq3_t *ctx, uint8_t pd_ref)
DAQ 3 set power reference buffer function.
DAQ 3 Click configuration object.
Definition: daq3.h:215
pin_name_t dam
Definition: daq3.h:225
spi_master_chip_select_polarity_t cs_polarity
Definition: daq3.h:234
pin_name_t sck
Definition: daq3.h:220
spi_master_mode_t spi_mode
Definition: daq3.h:233
pin_name_t mod
Definition: daq3.h:227
pin_name_t mosi
Definition: daq3.h:219
uint32_t spi_speed
Definition: daq3.h:232
pin_name_t dre
Definition: daq3.h:226
pin_name_t int_pin
Definition: daq3.h:228
pin_name_t miso
Definition: daq3.h:218
pin_name_t cs
Definition: daq3.h:221
DAQ 3 Click configuration object.
Definition: daq3.h:201
uint8_t span_comp
Definition: daq3.h:203
uint8_t ov_clamp_flag
Definition: daq3.h:206
uint8_t turbo_mode
Definition: daq3.h:205
uint8_t en_six_st_bits
Definition: daq3.h:202
uint8_t high_z_mode
Definition: daq3.h:204
DAQ 3 Click context object.
Definition: daq3.h:177
digital_out_t mod
Definition: daq3.h:182
digital_out_t dre
Definition: daq3.h:181
spi_master_t spi
Definition: daq3.h:190
digital_out_t dam
Definition: daq3.h:180
digital_in_t int_pin
Definition: daq3.h:186
pin_name_t chip_select
Definition: daq3.h:192