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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_analog_in.h"
38 #include "drv_i2c_master.h"
39 
61 #define RMSTODC2_RMS_VOLTAGE_COEF 1.045f
62 
67 #define RMSTODC2_ADC_RESOLUTION 0x0FFF
68 #define RMSTODC2_VREF_3V3 3.3
69 #define RMSTODC2_VREF_5V 5.0
70 
76 #define RMSTODC2_SET_DEV_ADDR 0x4D
77  // rmstodc2_set
79 
94 #define RMSTODC2_MAP_MIKROBUS( cfg, mikrobus ) \
95  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
96  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
97  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
98  // rmstodc2_map // rmstodc2
101 
106 typedef enum
107 {
112 
117 typedef struct
118 {
119  analog_in_t adc;
120  i2c_master_t i2c;
122  uint8_t slave_address;
123  float vref;
126 } rmstodc2_t;
127 
132 typedef struct
133 {
134  pin_name_t an;
135  pin_name_t scl;
136  pin_name_t sda;
138  analog_in_resolution_t resolution;
139  float vref;
141  uint32_t i2c_speed;
142  uint8_t i2c_address;
147 
152 typedef enum
153 {
155  RMSTODC2_ERROR = -1
156 
158 
175 
191 
206 
218 err_t rmstodc2_read_raw_adc ( rmstodc2_t *ctx, uint16_t *raw_adc );
219 
231 err_t rmstodc2_read_voltage ( rmstodc2_t *ctx, float *voltage );
232 
244 err_t rmstodc2_set_vref ( rmstodc2_t *ctx, float vref );
245 
246 #ifdef __cplusplus
247 }
248 #endif
249 #endif // RMSTODC2_H
250  // rmstodc2
252 
253 // ------------------------------------------------------------------------ END
rmstodc2_drv_t
rmstodc2_drv_t
RMS to DC 2 Click driver selector.
Definition: rmstodc2.h:107
rmstodc2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rmstodc2.h:141
RMSTODC2_DRV_SEL_ADC
@ RMSTODC2_DRV_SEL_ADC
Definition: rmstodc2.h:108
rmstodc2_cfg_t::drv_sel
rmstodc2_drv_t drv_sel
Definition: rmstodc2.h:144
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:109
rmstodc2_t::vref
float vref
Definition: rmstodc2.h:123
rmstodc2_t::adc
analog_in_t adc
Definition: rmstodc2.h:119
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:133
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:134
rmstodc2_cfg_t::i2c_address
uint8_t i2c_address
Definition: rmstodc2.h:142
rmstodc2_cfg_t::resolution
analog_in_resolution_t resolution
Definition: rmstodc2.h:138
rmstodc2_cfg_t::sda
pin_name_t sda
Definition: rmstodc2.h:136
rmstodc2_t::drv_sel
rmstodc2_drv_t drv_sel
Definition: rmstodc2.h:124
rmstodc2_cfg_t::scl
pin_name_t scl
Definition: rmstodc2.h:135
rmstodc2_cfg_t::vref
float vref
Definition: rmstodc2.h:139
RMSTODC2_OK
@ RMSTODC2_OK
Definition: rmstodc2.h:154
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:118
rmstodc2_t::i2c
i2c_master_t i2c
Definition: rmstodc2.h:120
rmstodc2_return_value_t
rmstodc2_return_value_t
RMS to DC 2 Click return value data.
Definition: rmstodc2.h:153
rmstodc2_t::slave_address
uint8_t slave_address
Definition: rmstodc2.h:122
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:155