powerbank2  2.0.0.0
powerbank2.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 POWERBANK2_H
36 #define POWERBANK2_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 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define POWERBANK2_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
70 
76 #define POWERBANK2_RETVAL uint8_t
77 
78 #define POWERBANK2_OK 0x00
79 #define POWERBANK2_INIT_ERROR 0xFF
80 
86 #define POWERBANK2_SLAVE_ADR 0x4D
87 
93 #define POWERBANK2_RESOLUTION 4096
94 #define POWERBANK2_12_BIT_DATA 0x0FFF
95  // End group macro
98 // --------------------------------------------------------------- PUBLIC TYPES
107 typedef struct
108 {
109  // Modules
110 
111  i2c_master_t i2c;
112 
113  // ctx variable
114 
115  uint8_t slave_address;
116 
117 } powerbank2_t;
118 
122 typedef struct
123 {
124  // Communication gpio pins
125 
126  pin_name_t scl;
127  pin_name_t sda;
128 
129 
130  // static variable
131 
132  uint32_t i2c_speed;
133  uint8_t i2c_address;
134 
136  // End types group
138 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
139 
145 #ifdef __cplusplus
146 extern "C"{
147 #endif
148 
158 
167 
178 void powerbank2_generic_write ( powerbank2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
179 
189 void powerbank2_read ( powerbank2_t *ctx, uint16_t *result );
190 
201 uint16_t powerbank2_read_voltage ( powerbank2_t *ctx, uint16_t v_ref );
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 #endif // _POWERBANK2_H_
207  // End public_function group
210 
211 // ------------------------------------------------------------------------- END
powerbank2_cfg_t::i2c_address
uint8_t i2c_address
Definition: powerbank2.h:133
powerbank2_t::slave_address
uint8_t slave_address
Definition: powerbank2.h:115
powerbank2_generic_write
void powerbank2_generic_write(powerbank2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
powerbank2_cfg_t::sda
pin_name_t sda
Definition: powerbank2.h:127
POWERBANK2_RETVAL
#define POWERBANK2_RETVAL
Definition: powerbank2.h:76
powerbank2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: powerbank2.h:132
powerbank2_cfg_t
Click configuration structure definition.
Definition: powerbank2.h:123
powerbank2_t
Click ctx object definition.
Definition: powerbank2.h:108
powerbank2_t::i2c
i2c_master_t i2c
Definition: powerbank2.h:111
powerbank2_init
POWERBANK2_RETVAL powerbank2_init(powerbank2_t *ctx, powerbank2_cfg_t *cfg)
Initialization function.
powerbank2_cfg_t::scl
pin_name_t scl
Definition: powerbank2.h:126
powerbank2_read_voltage
uint16_t powerbank2_read_voltage(powerbank2_t *ctx, uint16_t v_ref)
Read voltage function.
powerbank2_read
void powerbank2_read(powerbank2_t *ctx, uint16_t *result)
Read function.
powerbank2_cfg_setup
void powerbank2_cfg_setup(powerbank2_cfg_t *cfg)
Config Object Initialization function.