amrcurent  2.0.0.0
amrcurrent.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 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 // -------------------------------------------------------------- PUBLIC MACROS
52 #define AMRCURENT_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
55 
62 #define AMRCURENT_RETVAL uint8_t
63 
64 #define AMRCURENT_OK 0x00
65 #define AMRCURENT_INIT_ERROR 0xFF
66 
72 #define AMRCURRENT_PIN_STATE_HIGH 1
73 #define AMRCURRENT_PIN_STATE_LOW 0
74  // End group macro
77 // --------------------------------------------------------------- PUBLIC TYPES
86 typedef struct
87 {
88  // Output pins
89 
90  digital_out_t voc;
91 
92  // Input pins
93 
94  digital_in_t an;
95  digital_in_t flt;
96 
97  // Modules
98 
99  i2c_master_t i2c;
100 
101  // ctx variable
102 
103  uint8_t slave_address;
104 
105 } amrcurent_t;
106 
110 typedef struct
111 {
112  // Communication gpio pins
113 
114  pin_name_t scl;
115  pin_name_t sda;
116 
117  // Additional gpio pins
118 
119  pin_name_t an;
120  pin_name_t voc;
121  pin_name_t flt;
122 
123  // static variable
124 
125  uint32_t i2c_speed;
126  uint8_t i2c_address;
127 
129  // End types group
131 
132 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
133 
139 #ifdef __cplusplus
140 extern "C"{
141 #endif
142 
152 
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 
194 void amrcurent_generic_read ( amrcurent_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
195 
203 uint16_t amrcurrent_read_value ( amrcurent_t *ctx );
204 
213 
222 void amrcurrent_set_rst_pin_state ( amrcurent_t *ctx, uint8_t pin_state );
223 
231 void amrcurrent_hw_reset ( amrcurent_t *ctx );
232 
240 float amrcurrent_get_current ( amrcurent_t *ctx );
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 #endif // _AMRCURENT_H_
246  // End public_function group
249 
250 // ------------------------------------------------------------------------- END
Click ctx object definition.
Definition: amrcurrent.h:86
void amrcurrent_hw_reset(amrcurent_t *ctx)
Hardware reset device.
pin_name_t voc
Definition: amrcurrent.h:120
pin_name_t sda
Definition: amrcurrent.h:115
float amrcurrent_get_current(amrcurent_t *ctx)
Reads current data in mA.
digital_in_t flt
Definition: amrcurrent.h:95
pin_name_t scl
Definition: amrcurrent.h:114
void amrcurent_generic_read(amrcurent_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void amrcurent_default_cfg(amrcurent_t *ctx)
Click Default Configuration function.
pin_name_t an
Definition: amrcurrent.h:119
uint8_t slave_address
Definition: amrcurrent.h:103
void amrcurent_generic_write(amrcurent_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
digital_out_t voc
Definition: amrcurrent.h:90
AMRCURENT_RETVAL amrcurent_init(amrcurent_t *ctx, amrcurent_cfg_t *cfg)
Initialization function.
digital_in_t an
Definition: amrcurrent.h:94
#define AMRCURENT_RETVAL
Definition: amrcurrent.h:62
void amrcurrent_set_rst_pin_state(amrcurent_t *ctx, uint8_t pin_state)
Sets state of the reset pin.
uint32_t i2c_speed
Definition: amrcurrent.h:125
void amrcurent_cfg_setup(amrcurent_cfg_t *cfg)
Config Object Initialization function.
i2c_master_t i2c
Definition: amrcurrent.h:99
uint8_t amrcurrent_get_int_pin_state(amrcurent_t *ctx)
Gets state of the FLTB pin on int.
pin_name_t flt
Definition: amrcurrent.h:121
uint8_t i2c_address
Definition: amrcurrent.h:126
uint16_t amrcurrent_read_value(amrcurent_t *ctx)
Reads ADC current data.
Click configuration structure definition.
Definition: amrcurrent.h:110