current10  2.1.0.0
current10.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 CURRENT10_H
29 #define CURRENT10_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_analog_in.h"
52 #include "drv_i2c_master.h"
53 
74 #define CURRENT10_NUM_CONVERSIONS 200
75 
80 #define CURRENT10_ADC_RESOLUTION 0x0FFF
81 #define CURRENT10_VREF_3V3 3.3
82 #define CURRENT10_VREF_5V 5.0
83 
88 #define CURRENT10_TIMEOUT_MS 2000
89 
95 #define CURRENT10_SET_DEV_ADDR 0x4D
96  // current10_set
98 
113 #define CURRENT10_MAP_MIKROBUS( cfg, mikrobus ) \
114  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
115  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
116  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
117  // current10_map // current10
120 
125 typedef enum
126 {
131 
136 typedef struct
137 {
138  analog_in_t adc;
139  i2c_master_t i2c;
141  uint8_t slave_address;
142  float vref;
148 } current10_t;
149 
154 typedef struct
155 {
156  pin_name_t an;
157  pin_name_t scl;
158  pin_name_t sda;
160  analog_in_resolution_t resolution;
161  float vref;
163  uint32_t i2c_speed;
164  uint8_t i2c_address;
169 
174 typedef enum
175 {
177  CURRENT10_ERROR = -1
178 
180 
197 
213 
228 
240 err_t current10_read_raw_adc ( current10_t *ctx, uint16_t *raw_adc );
241 
253 err_t current10_read_voltage ( current10_t *ctx, float *voltage );
254 
267 err_t current10_read_voltage_avg ( current10_t *ctx, uint16_t num_conv, float *voltage_avg );
268 
280 err_t current10_set_vref ( current10_t *ctx, float vref );
281 
293 
306 err_t current10_calib_resolution ( current10_t *ctx, float calib_current );
307 
320 err_t current10_read_current ( current10_t *ctx, float *current );
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 #endif // CURRENT10_H
326  // current10
328 
329 // ------------------------------------------------------------------------ END
CURRENT10_DRV_SEL_ADC
@ CURRENT10_DRV_SEL_ADC
Definition: current10.h:127
current10_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: current10.h:163
current10_set_vref
err_t current10_set_vref(current10_t *ctx, float vref)
Current 10 set vref function.
current10_drv_t
current10_drv_t
Current 10 Click driver selector.
Definition: current10.h:126
current10_cfg_t
Current 10 Click configuration object.
Definition: current10.h:155
current10_t::vref
float vref
Definition: current10.h:142
current10_return_value_t
current10_return_value_t
Current 10 Click return value data.
Definition: current10.h:175
current10_t::data_resolution
float data_resolution
Definition: current10.h:146
current10_t::adc
analog_in_t adc
Definition: current10.h:138
current10_read_voltage_avg
err_t current10_read_voltage_avg(current10_t *ctx, uint16_t num_conv, float *voltage_avg)
Current 10 read average voltage level function.
current10_cfg_t::drv_sel
current10_drv_t drv_sel
Definition: current10.h:166
current10_read_current
err_t current10_read_current(current10_t *ctx, float *current)
Current 10 read current function.
CURRENT10_ERROR
@ CURRENT10_ERROR
Definition: current10.h:177
current10_calib_offset
err_t current10_calib_offset(current10_t *ctx)
Current 10 calib offset function.
current10_t::drv_sel
current10_drv_t drv_sel
Definition: current10.h:143
current10_cfg_t::resolution
analog_in_resolution_t resolution
Definition: current10.h:160
CURRENT10_OK
@ CURRENT10_OK
Definition: current10.h:176
current10_cfg_t::sda
pin_name_t sda
Definition: current10.h:158
current10_cfg_setup
void current10_cfg_setup(current10_cfg_t *cfg)
Current 10 configuration object setup function.
current10_t::i2c
i2c_master_t i2c
Definition: current10.h:139
current10_init
err_t current10_init(current10_t *ctx, current10_cfg_t *cfg)
Current 10 initialization function.
current10_read_voltage
err_t current10_read_voltage(current10_t *ctx, float *voltage)
Current 10 read voltage level function.
current10_cfg_t::i2c_address
uint8_t i2c_address
Definition: current10.h:164
current10_t::zero_curr_offset
float zero_curr_offset
Definition: current10.h:145
current10_cfg_t::vref
float vref
Definition: current10.h:161
current10_t::slave_address
uint8_t slave_address
Definition: current10.h:141
CURRENT10_DRV_SEL_I2C
@ CURRENT10_DRV_SEL_I2C
Definition: current10.h:128
current10_t
Current 10 Click context object.
Definition: current10.h:137
current10_read_raw_adc
err_t current10_read_raw_adc(current10_t *ctx, uint16_t *raw_adc)
Current 10 read raw ADC value function.
current10_cfg_t::an
pin_name_t an
Definition: current10.h:156
current10_cfg_t::scl
pin_name_t scl
Definition: current10.h:157
current10_drv_interface_sel
void current10_drv_interface_sel(current10_cfg_t *cfg, current10_drv_t drv_sel)
Current 10 driver interface setup function.
current10_calib_resolution
err_t current10_calib_resolution(current10_t *ctx, float calib_current)
Current 10 calib resolution function.