battmon4 2.0.0.0
battmon4.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef BATTMON4_H
29#define BATTMON4_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define BATTMON4_REG_A 0x01
74#define BATTMON4_REG_B 0x02
75#define BATTMON4_REG_C 0x03
76#define BATTMON4_REG_D 0x04
77#define BATTMON4_REG_E 0x05
78#define BATTMON4_REG_F 0x06
79#define BATTMON4_REG_G 0x07
80#define BATTMON4_REG_H 0x08
81
82 // battmon4_reg
83
98#define BATTMON4_TEMPERATURE_LSB 0.784
99#define BATTMON4_TEMPERATURE_OFFSET 41.0
100#define BATTMON4_TEMPERATURE_RESOLUTION 0x00FF
101#define BATTMON4_VOLTAGE_LSB 1.465
102#define BATTMON4_VOLTAGE_RESOLUTION 0x0FFF
103
109#define BATTMON4_DEVICE_ADDRESS 0x64
110
111 // battmon4_set
112
127#define BATTMON4_MAP_MIKROBUS( cfg, mikrobus ) \
128 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
129 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
130 cfg.bok = MIKROBUS( mikrobus, MIKROBUS_AN ); \
131 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
132
133 // battmon4_map
134 // battmon4
135
140typedef struct
141{
142 // Input pins
143 digital_in_t bok;
144 digital_in_t int_pin;
146 // Modules
147 i2c_master_t i2c;
149 // I2C slave address
152} battmon4_t;
153
158typedef struct
159{
160 pin_name_t scl;
161 pin_name_t sda;
163 pin_name_t bok;
164 pin_name_t int_pin;
166 uint32_t i2c_speed;
167 uint8_t i2c_address;
170
175typedef enum
176{
178 BATTMON4_ERROR = -1
179
181
198
214
228err_t battmon4_write_register ( battmon4_t *ctx, uint8_t reg, uint16_t data_in );
229
243err_t battmon4_read_register ( battmon4_t *ctx, uint8_t reg, uint16_t *data_out );
244
257err_t battmon4_get_die_temperature ( battmon4_t *ctx, float *temperature );
258
272err_t battmon4_get_batt_in_voltage ( battmon4_t *ctx, float *v_ipeak_on, float *v_ipeak_off );
273
287err_t battmon4_get_batt_out_voltage ( battmon4_t *ctx, float *v_ipeak_on, float *v_ipeak_off );
288
298
308
309#ifdef __cplusplus
310}
311#endif
312#endif // BATTMON4_H
313
314 // battmon4
315
316// ------------------------------------------------------------------------ END
battmon4_return_value_t
BATT-MON 4 Click return value data.
Definition battmon4.h:176
@ BATTMON4_ERROR
Definition battmon4.h:178
@ BATTMON4_OK
Definition battmon4.h:177
uint8_t battmon4_get_int_pin(battmon4_t *ctx)
BATT-MON 4 get int pin function.
err_t battmon4_read_register(battmon4_t *ctx, uint8_t reg, uint16_t *data_out)
BATT-MON 4 read register function.
err_t battmon4_get_batt_in_voltage(battmon4_t *ctx, float *v_ipeak_on, float *v_ipeak_off)
BATT-MON 4 get batt in voltage function.
err_t battmon4_init(battmon4_t *ctx, battmon4_cfg_t *cfg)
BATT-MON 4 initialization function.
err_t battmon4_write_register(battmon4_t *ctx, uint8_t reg, uint16_t data_in)
BATT-MON 4 write register function.
void battmon4_cfg_setup(battmon4_cfg_t *cfg)
BATT-MON 4 configuration object setup function.
err_t battmon4_get_batt_out_voltage(battmon4_t *ctx, float *v_ipeak_on, float *v_ipeak_off)
BATT-MON 4 get batt out voltage function.
err_t battmon4_get_die_temperature(battmon4_t *ctx, float *temperature)
BATT-MON 4 get die temperature function.
uint8_t battmon4_get_bok_pin(battmon4_t *ctx)
BATT-MON 4 get bok pin function.
BATT-MON 4 Click configuration object.
Definition battmon4.h:159
uint32_t i2c_speed
Definition battmon4.h:166
pin_name_t scl
Definition battmon4.h:160
pin_name_t int_pin
Definition battmon4.h:164
pin_name_t bok
Definition battmon4.h:163
pin_name_t sda
Definition battmon4.h:161
uint8_t i2c_address
Definition battmon4.h:167
BATT-MON 4 Click context object.
Definition battmon4.h:141
digital_in_t bok
Definition battmon4.h:143
digital_in_t int_pin
Definition battmon4.h:144
i2c_master_t i2c
Definition battmon4.h:147
uint8_t slave_address
Definition battmon4.h:150