current7  2.0.0.0
current7.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 CURRENT7_H
29 #define CURRENT7_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_i2c_master.h"
46 #include "drv_analog_in.h"
47 
68 #define CURRENT7_NUM_CONVERSIONS 100
69 #define CURRENT7_SENSITIVITY_V_TO_A 0.8f
70 
75 #define CURRENT7_ADC_RESOLUTION 0x0FFF
76 #define CURRENT7_VREF_3V3 3.3
77 #define CURRENT7_VREF_5V 5.0
78 
84 #define CURRENT7_SET_DEV_ADDR 0x4D
85  // current7_set
87 
102 #define CURRENT7_MAP_MIKROBUS( cfg, mikrobus ) \
103  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
104  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
105  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
106  // current7_map // current7
109 
114 typedef enum
115 {
120 
125 typedef struct current7_s
126 {
127  analog_in_t adc;
128  i2c_master_t i2c;
130  uint8_t slave_address;
131  float vref;
135 
140 typedef struct
141 {
142  pin_name_t an;
143  pin_name_t scl;
144  pin_name_t sda;
146  analog_in_resolution_t resolution;
147  float vref;
149  uint32_t i2c_speed;
150  uint8_t i2c_address;
155 
160 typedef enum
161 {
163  CURRENT7_ERROR = -1
164 
166 
183 
199 
214 
226 err_t current7_read_raw_adc ( current7_t *ctx, uint16_t *raw_adc );
227 
239 err_t current7_read_voltage ( current7_t *ctx, float *voltage );
240 
252 err_t current7_set_vref ( current7_t *ctx, float vref );
253 
266 err_t current7_get_current ( current7_t *ctx, float *current );
267 
268 #ifdef __cplusplus
269 }
270 #endif
271 #endif // CURRENT7_H
272  // current7
274 
275 // ------------------------------------------------------------------------ END
current7_cfg_t::an
pin_name_t an
Definition: current7.h:142
current7_init
err_t current7_init(current7_t *ctx, current7_cfg_t *cfg)
Current 7 initialization function.
current7_s
Current 7 Click context object.
Definition: current7.h:126
current7_s::slave_address
uint8_t slave_address
Definition: current7.h:130
CURRENT7_DRV_SEL_I2C
@ CURRENT7_DRV_SEL_I2C
Definition: current7.h:117
current7_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: current7.h:149
current7_s::adc
analog_in_t adc
Definition: current7.h:127
current7_s::drv_sel
current7_drv_t drv_sel
Definition: current7.h:132
current7_cfg_t
Current 7 Click configuration object.
Definition: current7.h:141
current7_cfg_t::i2c_address
uint8_t i2c_address
Definition: current7.h:150
current7_cfg_t::sda
pin_name_t sda
Definition: current7.h:144
current7_cfg_t::vref
float vref
Definition: current7.h:147
current7_return_value_t
current7_return_value_t
Current 7 Click return value data.
Definition: current7.h:161
current7_set_vref
err_t current7_set_vref(current7_t *ctx, float vref)
Current 7 set vref function.
current7_cfg_t::drv_sel
current7_drv_t drv_sel
Definition: current7.h:152
current7_cfg_setup
void current7_cfg_setup(current7_cfg_t *cfg)
Current 7 configuration object setup function.
CURRENT7_OK
@ CURRENT7_OK
Definition: current7.h:162
current7_drv_interface_selection
void current7_drv_interface_selection(current7_cfg_t *cfg, current7_drv_t drv_sel)
Current 7 driver interface setup function.
CURRENT7_DRV_SEL_ADC
@ CURRENT7_DRV_SEL_ADC
Definition: current7.h:116
current7_read_voltage
err_t current7_read_voltage(current7_t *ctx, float *voltage)
Current 7 read voltage level function.
current7_read_raw_adc
err_t current7_read_raw_adc(current7_t *ctx, uint16_t *raw_adc)
Current 7 read raw ADC value function.
current7_cfg_t::resolution
analog_in_resolution_t resolution
Definition: current7.h:146
CURRENT7_ERROR
@ CURRENT7_ERROR
Definition: current7.h:163
current7_t
struct current7_s current7_t
Current 7 Click context object.
current7_cfg_t::scl
pin_name_t scl
Definition: current7.h:143
current7_drv_t
current7_drv_t
Current 7 Click driver selector.
Definition: current7.h:115
current7_get_current
err_t current7_get_current(current7_t *ctx, float *current)
Current 7 get current function.
current7_s::i2c
i2c_master_t i2c
Definition: current7.h:128
current7_s::vref
float vref
Definition: current7.h:131