rmstodc  2.0.0.0
rmstodc.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef RMSTODC_H
36 #define RMSTODC_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define RMSTODC_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS )
66 
73 #define RMSTODC_RETVAL uint8_t
74 
75 #define RMSTODC_OK 0x00
76 #define RMSTODC_INIT_ERROR 0xFF
77 
83 #define ADC_RESOLUTION 4096
84 #define RMS2DC_DEVICE_ADDR 0x4D
85 
91 #define RMS2DC_DEVICE_EN 0x00
92 #define RMS2DC_DEVICE_DIS 0x01
93 
99 #define RMS2DC_VCC_3V3 3300
100 #define RMS2DC_VCC_5V 5000
101  // End group macro
104 // --------------------------------------------------------------- PUBLIC TYPES
113 typedef struct
114 {
115  // Output pins
116 
117  digital_out_t en;
118 
119  // Modules
120 
121  i2c_master_t i2c;
122 
123  // ctx variable
124 
125  uint8_t slave_address;
126 
127 } rmstodc_t;
128 
132 typedef struct
133 {
134  // Communication gpio pins
135 
136  pin_name_t scl;
137  pin_name_t sda;
138 
139  // Additional gpio pins
140 
141  pin_name_t en;
142 
143  // static variable
144 
145  uint32_t i2c_speed;
146  uint8_t i2c_address;
147 
148 } rmstodc_cfg_t;
149  // End types group
151 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
152 
158 #ifdef __cplusplus
159 extern "C"{
160 #endif
161 
171 
181 
189 uint16_t rms2dc_read_adc ( rmstodc_t *ctx );
190 
200 uint16_t rms2dc_vout_adc ( rmstodc_t *ctx, uint16_t vcc_sel );
201 
209 void rms2dc_enable ( rmstodc_t *ctx, uint8_t state );
210 
211 #ifdef __cplusplus
212 }
213 #endif
214 #endif // _RMSTODC_H_
215  // End public_function group
218 
219 // ------------------------------------------------------------------------- END
rmstodc_cfg_setup
void rmstodc_cfg_setup(rmstodc_cfg_t *cfg)
Config Object Initialization function.
RMSTODC_RETVAL
#define RMSTODC_RETVAL
Definition: rmstodc.h:73
rmstodc_cfg_t
Click configuration structure definition.
Definition: rmstodc.h:133
rmstodc_t::i2c
i2c_master_t i2c
Definition: rmstodc.h:121
rmstodc_cfg_t::en
pin_name_t en
Definition: rmstodc.h:141
rms2dc_read_adc
uint16_t rms2dc_read_adc(rmstodc_t *ctx)
ADC Read function.
rmstodc_t
Click ctx object definition.
Definition: rmstodc.h:114
rmstodc_cfg_t::i2c_address
uint8_t i2c_address
Definition: rmstodc.h:146
rmstodc_t::slave_address
uint8_t slave_address
Definition: rmstodc.h:125
rmstodc_cfg_t::sda
pin_name_t sda
Definition: rmstodc.h:137
rmstodc_init
RMSTODC_RETVAL rmstodc_init(rmstodc_t *ctx, rmstodc_cfg_t *cfg)
Initialization function.
rmstodc_t::en
digital_out_t en
Definition: rmstodc.h:117
rms2dc_enable
void rms2dc_enable(rmstodc_t *ctx, uint8_t state)
Enable function.
rmstodc_cfg_t::scl
pin_name_t scl
Definition: rmstodc.h:136
rms2dc_vout_adc
uint16_t rms2dc_vout_adc(rmstodc_t *ctx, uint16_t vcc_sel)
Get Output Voltage function.
rmstodc_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rmstodc.h:145