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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define RMSTODC_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS )
56 
63 #define RMSTODC_RETVAL uint8_t
64 
65 #define RMSTODC_OK 0x00
66 #define RMSTODC_INIT_ERROR 0xFF
67 
73 #define ADC_RESOLUTION 4096
74 #define RMS2DC_DEVICE_ADDR 0x4D
75 
81 #define RMS2DC_DEVICE_EN 0x00
82 #define RMS2DC_DEVICE_DIS 0x01
83 
89 #define RMS2DC_VCC_3V3 3300
90 #define RMS2DC_VCC_5V 5000
91  // End group macro
94 // --------------------------------------------------------------- PUBLIC TYPES
103 typedef struct
104 {
105  // Output pins
106 
107  digital_out_t en;
108 
109  // Modules
110 
111  i2c_master_t i2c;
112 
113  // ctx variable
114 
115  uint8_t slave_address;
116 
117 } rmstodc_t;
118 
122 typedef struct
123 {
124  // Communication gpio pins
125 
126  pin_name_t scl;
127  pin_name_t sda;
128 
129  // Additional gpio pins
130 
131  pin_name_t en;
132 
133  // static variable
134 
135  uint32_t i2c_speed;
136  uint8_t i2c_address;
137 
138 } rmstodc_cfg_t;
139  // End types group
141 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
142 
148 #ifdef __cplusplus
149 extern "C"{
150 #endif
151 
161 
171 
179 uint16_t rms2dc_read_adc ( rmstodc_t *ctx );
180 
190 uint16_t rms2dc_vout_adc ( rmstodc_t *ctx, uint16_t vcc_sel );
191 
199 void rms2dc_enable ( rmstodc_t *ctx, uint8_t state );
200 
201 #ifdef __cplusplus
202 }
203 #endif
204 #endif // _RMSTODC_H_
205  // End public_function group
208 
209 // ------------------------------------------------------------------------- END
rmstodc_cfg_setup
void rmstodc_cfg_setup(rmstodc_cfg_t *cfg)
Config Object Initialization function.
RMSTODC_RETVAL
#define RMSTODC_RETVAL
Definition: rmstodc.h:63
rmstodc_cfg_t
Click configuration structure definition.
Definition: rmstodc.h:123
rmstodc_t::i2c
i2c_master_t i2c
Definition: rmstodc.h:111
rmstodc_cfg_t::en
pin_name_t en
Definition: rmstodc.h:131
rms2dc_read_adc
uint16_t rms2dc_read_adc(rmstodc_t *ctx)
ADC Read function.
rmstodc_t
Click ctx object definition.
Definition: rmstodc.h:104
rmstodc_cfg_t::i2c_address
uint8_t i2c_address
Definition: rmstodc.h:136
rmstodc_t::slave_address
uint8_t slave_address
Definition: rmstodc.h:115
rmstodc_cfg_t::sda
pin_name_t sda
Definition: rmstodc.h:127
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:107
rms2dc_enable
void rms2dc_enable(rmstodc_t *ctx, uint8_t state)
Enable function.
rmstodc_cfg_t::scl
pin_name_t scl
Definition: rmstodc.h:126
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:135