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
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 
69 #define DAQ3_REG_0 0x00
70 #define DAQ3_REG_1 0x01
71 #define DAQ3_REG_2 0x02
72 #define DAQ3_REG_3 0x03
73 #define DAQ3_REG_CMD 0x14
74  // daq3_reg
76 
91 #define DAQ3_CMD_WEN 0x00
92 #define DAQ3_CMD_REG_READ 0x40
93 #define DAQ3_CMD_REG_WRITE 0x00
94  // daq3_set
96 
106 #define DAQ3_CMD_REG_DEFAULT 0xE1
107  // daq3_set
109 
120 #define DAQ3_LOW_POWER_MODE 0x00
121 #define DAQ3_FULL_PERFORMANCE_MODE 0x01
122  // mode
124 
135 #define DAQ3_PD_REF_POWER_DOWN 0x00
136 #define DAQ3_PD_REF_POWER_UP 0x01
137  // pd_ref
139 
150 #define DAQ3_PD_AMP_POWER_DOWN 0x00
151 #define DAQ3_PD_AMP_POWER_UP 0x01
152  // pd_amp
154 
169 #define DAQ3_MAP_MIKROBUS( cfg, mikrobus ) \
170  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
171  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
172  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
173  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
174  cfg.dam = MIKROBUS( mikrobus, MIKROBUS_AN ); \
175  cfg.dre = MIKROBUS( mikrobus, MIKROBUS_RST ); \
176  cfg.mod = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
177  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
178  // daq3_map // daq3
181 
186 typedef struct
187 {
188  // Output pins
189 
190  digital_out_t dam;
191  digital_out_t dre;
192  digital_out_t mod;
194  // Input pins
195 
196  digital_in_t int_pin;
198  // Modules
199 
200  spi_master_t spi;
202  pin_name_t chip_select;
204 } daq3_t;
205 
210 typedef struct
211 {
212  uint8_t en_six_st_bits;
213  uint8_t span_comp;
214  uint8_t high_z_mode;
215  uint8_t turbo_mode;
216  uint8_t ov_clamp_flag;
219 
224 typedef struct
225 {
226  // Communication gpio pins
227 
228  pin_name_t miso;
229  pin_name_t mosi;
230  pin_name_t sck;
231  pin_name_t cs;
233  // Additional gpio pins
234 
235  pin_name_t dam;
236  pin_name_t dre;
237  pin_name_t mod;
238  pin_name_t int_pin;
240  // static variable
241 
242  uint32_t spi_speed;
243  spi_master_mode_t spi_mode;
244  spi_master_chip_select_polarity_t cs_polarity;
246 } daq3_cfg_t;
247 
264 
279 err_t daq3_init ( daq3_t *ctx, daq3_cfg_t *cfg );
280 
291 void daq3_default_cfg ( daq3_t *ctx );
292 
307 void daq3_set_pwr_mode ( daq3_t *ctx, uint8_t mode );
308 
323 void daq3_set_pwr_down_ref_buf ( daq3_t *ctx, uint8_t pd_ref );
324 
339 void daq3_set_pwr_down_amp ( daq3_t *ctx, uint8_t pd_amp );
340 
341 
355 uint8_t daq3_get_sdo ( daq3_t *ctx );
356 
371 err_t daq3_generic_write ( daq3_t *ctx, uint8_t reg, uint8_t data_in );
372 
387 err_t daq3_generic_read ( daq3_t *ctx, uint8_t reg, uint8_t *data_out );
388 
403 err_t daq3_set_reg_cfg ( daq3_t *ctx, daq3_reg_cfg_t cfg_data );
404 
419 err_t daq3_get_reg_cfg ( daq3_t *ctx, daq3_reg_cfg_t *cfg_data );
420 
435 
449 float daq3_get_voltage ( daq3_t *ctx );
450 
451 #ifdef __cplusplus
452 }
453 #endif
454 #endif // DAQ3_H
455  // daq3
457 
458 // ------------------------------------------------------------------------ END
daq3_t::dam
digital_out_t dam
Definition: daq3.h:190
daq3_reg_cfg_t::span_comp
uint8_t span_comp
Definition: daq3.h:213
daq3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: daq3.h:244
daq3_set_pwr_down_ref_buf
void daq3_set_pwr_down_ref_buf(daq3_t *ctx, uint8_t pd_ref)
DAQ 3 set power reference buffer function.
daq3_generic_write
err_t daq3_generic_write(daq3_t *ctx, uint8_t reg, uint8_t data_in)
DAQ 3 data writing function.
daq3_cfg_t::dre
pin_name_t dre
Definition: daq3.h:236
daq3_cfg_t::miso
pin_name_t miso
Definition: daq3.h:228
daq3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: daq3.h:243
daq3_get_voltage
float daq3_get_voltage(daq3_t *ctx)
DAQ 3 get voltage function.
daq3_t::spi
spi_master_t spi
Definition: daq3.h:200
daq3_cfg_t::int_pin
pin_name_t int_pin
Definition: daq3.h:238
daq3_cfg_t::sck
pin_name_t sck
Definition: daq3.h:230
daq3_set_pwr_mode
void daq3_set_pwr_mode(daq3_t *ctx, uint8_t mode)
DAQ 3 set power mode function.
daq3_t::mod
digital_out_t mod
Definition: daq3.h:192
daq3_get_sdo
uint8_t daq3_get_sdo(daq3_t *ctx)
DAQ 3 get state of SDO function.
daq3_set_pwr_down_amp
void daq3_set_pwr_down_amp(daq3_t *ctx, uint8_t pd_amp)
DAQ 3 set power Amplifier function.
daq3_cfg_t::mod
pin_name_t mod
Definition: daq3.h:237
daq3_t::dre
digital_out_t dre
Definition: daq3.h:191
daq3_t
DAQ 3 Click context object.
Definition: daq3.h:187
daq3_default_cfg
void daq3_default_cfg(daq3_t *ctx)
DAQ 3 default configuration function.
daq3_t::chip_select
pin_name_t chip_select
Definition: daq3.h:202
daq3_reg_cfg_t::high_z_mode
uint8_t high_z_mode
Definition: daq3.h:214
daq3_cfg_t::spi_speed
uint32_t spi_speed
Definition: daq3.h:242
daq3_t::int_pin
digital_in_t int_pin
Definition: daq3.h:196
daq3_get_conversion_result
int32_t daq3_get_conversion_result(daq3_t *ctx, daq3_reg_cfg_t cfg_data)
DAQ 3 get conversion result function.
daq3_cfg_t::cs
pin_name_t cs
Definition: daq3.h:231
daq3_cfg_t::mosi
pin_name_t mosi
Definition: daq3.h:229
daq3_reg_cfg_t::turbo_mode
uint8_t turbo_mode
Definition: daq3.h:215
daq3_reg_cfg_t::en_six_st_bits
uint8_t en_six_st_bits
Definition: daq3.h:212
daq3_set_reg_cfg
err_t daq3_set_reg_cfg(daq3_t *ctx, daq3_reg_cfg_t cfg_data)
DAQ 3 set command register function.
daq3_cfg_t
DAQ 3 Click configuration object.
Definition: daq3.h:225
daq3_reg_cfg_t::ov_clamp_flag
uint8_t ov_clamp_flag
Definition: daq3.h:216
daq3_reg_cfg_t
DAQ 3 Click configuration object.
Definition: daq3.h:211
daq3_get_reg_cfg
err_t daq3_get_reg_cfg(daq3_t *ctx, daq3_reg_cfg_t *cfg_data)
DAQ 3 get command register function.
daq3_cfg_t::dam
pin_name_t dam
Definition: daq3.h:235
daq3_cfg_setup
void daq3_cfg_setup(daq3_cfg_t *cfg)
DAQ 3 configuration object setup function.
daq3_generic_read
err_t daq3_generic_read(daq3_t *ctx, uint8_t reg, uint8_t *data_out)
DAQ 3 data reading function.
daq3_init
err_t daq3_init(daq3_t *ctx, daq3_cfg_t *cfg)
DAQ 3 initialization function.