amrcurent  2.0.0.0
amrcurent.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef AMRCURENT_H
36 #define AMRCURENT_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define AMRCURENT_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
56 
63 #define AMRCURENT_RETVAL uint8_t
64 
65 #define AMRCURENT_OK 0x00
66 #define AMRCURENT_INIT_ERROR 0xFF
67 
73 #define AMRCURRENT_PIN_STATE_HIGH 1
74 #define AMRCURRENT_PIN_STATE_LOW 0
75  // End group macro
78 // --------------------------------------------------------------- PUBLIC TYPES
87 typedef struct
88 {
89  // Output pins
90 
91  digital_out_t voc;
92 
93  // Input pins
94 
95  digital_in_t an;
96  digital_in_t flt;
97 
98  // Modules
99 
100  i2c_master_t i2c;
101 
102  // ctx variable
103 
104  hal_i2c_address_t slave_address;
105 
106 } amrcurent_t;
107 
111 typedef struct
112 {
113  // Communication gpio pins
114 
115  pin_name_t scl;
116  pin_name_t sda;
117 
118  // Additional gpio pins
119 
120  pin_name_t an;
121  pin_name_t voc;
122  pin_name_t flt;
123 
124  // static variable
125 
126  hal_i2c_speed_t i2c_speed;
127  hal_i2c_address_t i2c_address;
128 
130  // End types group
132 
133 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
134 
140 #ifdef __cplusplus
141 extern "C"{
142 #endif
143 
153 
162 
170 void amrcurent_default_cfg ( amrcurent_t *ctx );
171 
182 void amrcurent_generic_write ( amrcurent_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
183 
195 void amrcurent_generic_read ( amrcurent_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
196 
205 uint16_t amrcurrent_read_value ( amrcurent_t *ctx );
206 
216 
226 void amrcurrent_set_rst_pin_state ( amrcurent_t *ctx, uint8_t pin_state );
227 
236 void amrcurrent_hw_reset ( amrcurent_t *ctx );
237 
246 float amrcurrent_get_current ( amrcurent_t *ctx );
247 
248 #ifdef __cplusplus
249 }
250 #endif
251 #endif // _AMRCURENT_H_
252  // End public_function group
255 
256 // ------------------------------------------------------------------------- END
amrcurent_cfg_t::sda
pin_name_t sda
Definition: amrcurent.h:116
amrcurent_t::slave_address
hal_i2c_address_t slave_address
Definition: amrcurent.h:104
amrcurent_cfg_t::i2c_speed
hal_i2c_speed_t i2c_speed
Definition: amrcurent.h:126
amrcurent_t
Click ctx object definition.
Definition: amrcurent.h:87
amrcurent_cfg_setup
void amrcurent_cfg_setup(amrcurent_cfg_t *cfg)
Config Object Initialization function.
amrcurent_t::i2c
i2c_master_t i2c
Definition: amrcurent.h:100
amrcurent_t::flt
digital_in_t flt
Definition: amrcurent.h:96
amrcurrent_read_value
uint16_t amrcurrent_read_value(amrcurent_t *ctx)
Reads ADC current data.
amrcurent_t::voc
digital_out_t voc
Definition: amrcurent.h:91
amrcurent_generic_write
void amrcurent_generic_write(amrcurent_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
amrcurrent_set_rst_pin_state
void amrcurrent_set_rst_pin_state(amrcurent_t *ctx, uint8_t pin_state)
Sets state of the reset pin.
amrcurent_default_cfg
void amrcurent_default_cfg(amrcurent_t *ctx)
Click Default Configuration function.
amrcurent_generic_read
void amrcurent_generic_read(amrcurent_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
amrcurent_init
AMRCURENT_RETVAL amrcurent_init(amrcurent_t *ctx, amrcurent_cfg_t *cfg)
Initialization function.
AMRCURENT_RETVAL
#define AMRCURENT_RETVAL
Definition: amrcurent.h:63
amrcurrent_get_current
float amrcurrent_get_current(amrcurent_t *ctx)
Reads current data in mA.
amrcurent_cfg_t::scl
pin_name_t scl
Definition: amrcurent.h:115
amrcurent_cfg_t::an
pin_name_t an
Definition: amrcurent.h:120
amrcurent_cfg_t::voc
pin_name_t voc
Definition: amrcurent.h:121
amrcurent_t::an
digital_in_t an
Definition: amrcurent.h:95
amrcurent_cfg_t::i2c_address
hal_i2c_address_t i2c_address
Definition: amrcurent.h:127
amrcurrent_get_int_pin_state
uint8_t amrcurrent_get_int_pin_state(amrcurent_t *ctx)
Gets state of the FLTB pin on int.
amrcurent_cfg_t
Click configuration structure definition.
Definition: amrcurent.h:111
amrcurrent_hw_reset
void amrcurrent_hw_reset(amrcurent_t *ctx)
Hardware reset device.
amrcurent_cfg_t::flt
pin_name_t flt
Definition: amrcurent.h:122