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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_i2c_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define RMSTODC_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS )
70 
77 #define RMSTODC_RETVAL uint8_t
78 
79 #define RMSTODC_OK 0x00
80 #define RMSTODC_INIT_ERROR 0xFF
81 
87 #define ADC_RESOLUTION 4096
88 #define RMS2DC_DEVICE_ADDR 0x4D
89 
95 #define RMS2DC_DEVICE_EN 0x00
96 #define RMS2DC_DEVICE_DIS 0x01
97 
103 #define RMS2DC_VCC_3V3 3300
104 #define RMS2DC_VCC_5V 5000
105  // End group macro
108 // --------------------------------------------------------------- PUBLIC TYPES
117 typedef struct
118 {
119  // Output pins
120 
121  digital_out_t en;
122 
123  // Modules
124 
125  i2c_master_t i2c;
126 
127  // ctx variable
128 
129  uint8_t slave_address;
130 
131 } rmstodc_t;
132 
136 typedef struct
137 {
138  // Communication gpio pins
139 
140  pin_name_t scl;
141  pin_name_t sda;
142 
143  // Additional gpio pins
144 
145  pin_name_t en;
146 
147  // static variable
148 
149  uint32_t i2c_speed;
150  uint8_t i2c_address;
151 
152 } rmstodc_cfg_t;
153  // End types group
155 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
156 
162 #ifdef __cplusplus
163 extern "C"{
164 #endif
165 
175 
185 
193 uint16_t rms2dc_read_adc ( rmstodc_t *ctx );
194 
204 uint16_t rms2dc_vout_adc ( rmstodc_t *ctx, uint16_t vcc_sel );
205 
213 void rms2dc_enable ( rmstodc_t *ctx, uint8_t state );
214 
215 #ifdef __cplusplus
216 }
217 #endif
218 #endif // _RMSTODC_H_
219  // End public_function group
222 
223 // ------------------------------------------------------------------------- END
rmstodc_cfg_setup
void rmstodc_cfg_setup(rmstodc_cfg_t *cfg)
Config Object Initialization function.
RMSTODC_RETVAL
#define RMSTODC_RETVAL
Definition: rmstodc.h:77
rmstodc_cfg_t
Click configuration structure definition.
Definition: rmstodc.h:137
rmstodc_t::i2c
i2c_master_t i2c
Definition: rmstodc.h:125
rmstodc_cfg_t::en
pin_name_t en
Definition: rmstodc.h:145
rms2dc_read_adc
uint16_t rms2dc_read_adc(rmstodc_t *ctx)
ADC Read function.
rmstodc_t
Click ctx object definition.
Definition: rmstodc.h:118
rmstodc_cfg_t::i2c_address
uint8_t i2c_address
Definition: rmstodc.h:150
rmstodc_t::slave_address
uint8_t slave_address
Definition: rmstodc.h:129
rmstodc_cfg_t::sda
pin_name_t sda
Definition: rmstodc.h:141
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:121
rms2dc_enable
void rms2dc_enable(rmstodc_t *ctx, uint8_t state)
Enable function.
rmstodc_cfg_t::scl
pin_name_t scl
Definition: rmstodc.h:140
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:149