rmstodc2  2.1.0.0
rmstodc2.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 RMSTODC2_H
29 #define RMSTODC2_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 
75 #define RMSTODC2_RMS_VOLTAGE_COEF 1.045f
76 
81 #define RMSTODC2_ADC_RESOLUTION 0x0FFF
82 #define RMSTODC2_VREF_3V3 3.3
83 #define RMSTODC2_VREF_5V 5.0
84 
90 #define RMSTODC2_SET_DEV_ADDR 0x4D
91  // rmstodc2_set
93 
108 #define RMSTODC2_MAP_MIKROBUS( cfg, mikrobus ) \
109  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
110  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
111  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
112  // rmstodc2_map // rmstodc2
115 
120 typedef enum
121 {
126 
131 typedef struct
132 {
133  analog_in_t adc;
134  i2c_master_t i2c;
136  uint8_t slave_address;
137  float vref;
140 } rmstodc2_t;
141 
146 typedef struct
147 {
148  pin_name_t an;
149  pin_name_t scl;
150  pin_name_t sda;
152  analog_in_resolution_t resolution;
153  float vref;
155  uint32_t i2c_speed;
156  uint8_t i2c_address;
161 
166 typedef enum
167 {
169  RMSTODC2_ERROR = -1
170 
172 
189 
205 
220 
232 err_t rmstodc2_read_raw_adc ( rmstodc2_t *ctx, uint16_t *raw_adc );
233 
245 err_t rmstodc2_read_voltage ( rmstodc2_t *ctx, float *voltage );
246 
258 err_t rmstodc2_set_vref ( rmstodc2_t *ctx, float vref );
259 
260 #ifdef __cplusplus
261 }
262 #endif
263 #endif // RMSTODC2_H
264  // rmstodc2
266 
267 // ------------------------------------------------------------------------ END
rmstodc2_drv_t
rmstodc2_drv_t
RMS to DC 2 Click driver selector.
Definition: rmstodc2.h:121
rmstodc2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rmstodc2.h:155
RMSTODC2_DRV_SEL_ADC
@ RMSTODC2_DRV_SEL_ADC
Definition: rmstodc2.h:122
rmstodc2_cfg_t::drv_sel
rmstodc2_drv_t drv_sel
Definition: rmstodc2.h:158
rmstodc2_read_voltage
err_t rmstodc2_read_voltage(rmstodc2_t *ctx, float *voltage)
RMS to DC 2 read voltage level function.
RMSTODC2_DRV_SEL_I2C
@ RMSTODC2_DRV_SEL_I2C
Definition: rmstodc2.h:123
rmstodc2_t::vref
float vref
Definition: rmstodc2.h:137
rmstodc2_t::adc
analog_in_t adc
Definition: rmstodc2.h:133
rmstodc2_set_vref
err_t rmstodc2_set_vref(rmstodc2_t *ctx, float vref)
RMS to DC 2 set vref function.
rmstodc2_cfg_t
RMS to DC 2 Click configuration object.
Definition: rmstodc2.h:147
rmstodc2_cfg_setup
void rmstodc2_cfg_setup(rmstodc2_cfg_t *cfg)
RMS to DC 2 configuration object setup function.
rmstodc2_read_raw_adc
err_t rmstodc2_read_raw_adc(rmstodc2_t *ctx, uint16_t *raw_adc)
RMS to DC 2 read raw ADC value function.
rmstodc2_cfg_t::an
pin_name_t an
Definition: rmstodc2.h:148
rmstodc2_cfg_t::i2c_address
uint8_t i2c_address
Definition: rmstodc2.h:156
rmstodc2_cfg_t::resolution
analog_in_resolution_t resolution
Definition: rmstodc2.h:152
rmstodc2_cfg_t::sda
pin_name_t sda
Definition: rmstodc2.h:150
rmstodc2_t::drv_sel
rmstodc2_drv_t drv_sel
Definition: rmstodc2.h:138
rmstodc2_cfg_t::scl
pin_name_t scl
Definition: rmstodc2.h:149
rmstodc2_cfg_t::vref
float vref
Definition: rmstodc2.h:153
RMSTODC2_OK
@ RMSTODC2_OK
Definition: rmstodc2.h:168
rmstodc2_init
err_t rmstodc2_init(rmstodc2_t *ctx, rmstodc2_cfg_t *cfg)
RMS to DC 2 initialization function.
rmstodc2_t
RMS to DC 2 Click context object.
Definition: rmstodc2.h:132
rmstodc2_t::i2c
i2c_master_t i2c
Definition: rmstodc2.h:134
rmstodc2_return_value_t
rmstodc2_return_value_t
RMS to DC 2 Click return value data.
Definition: rmstodc2.h:167
rmstodc2_t::slave_address
uint8_t slave_address
Definition: rmstodc2.h:136
rmstodc2_drv_interface_sel
void rmstodc2_drv_interface_sel(rmstodc2_cfg_t *cfg, rmstodc2_drv_t drv_sel)
RMS to DC 2 driver interface setup function.
RMSTODC2_ERROR
@ RMSTODC2_ERROR
Definition: rmstodc2.h:169