battboost 2.1.0.0
battboost.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 BATTBOOST_H
29#define BATTBOOST_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 BATTBOOST_REG_STATUS 0x00
74#define BATTBOOST_REG_CHENERGY_3 0x01
75#define BATTBOOST_REG_CHENERGY_2 0x02
76#define BATTBOOST_REG_CHENERGY_1 0x03
77#define BATTBOOST_REG_CHENERGY_0 0x04
78#define BATTBOOST_REG_VCAP 0x05
79#define BATTBOOST_REG_VCHEND 0x06
80#define BATTBOOST_REG_PROFILE_MSB 0x07
81#define BATTBOOST_REG_COMMAND 0x08
82#define BATTBOOST_REG_SET1 0x09
83#define BATTBOOST_REG_SET2 0x0A
84#define BATTBOOST_REG_SET3 0x0B
85#define BATTBOOST_REG_SET4 0x0C
86#define BATTBOOST_REG_SET5 0x0D
87
88 // battboost_reg
89
104#define BATTBOOST_STATUS_LOWBAT 0x80
105#define BATTBOOST_STATUS_EW 0x40
106#define BATTBOOST_STATUS_ALRM 0x20
107#define BATTBOOST_STATUS_RDY 0x01
108
113#define BATTBOOST_VCAP_BIT_MASK 0x1F
114
119#define BATTBOOST_VCHEND_BIT_MASK 0x1F
120
125#define BATTBOOST_SET2_VMIN_2_4V 2.4f
126#define BATTBOOST_SET2_VMIN_2_6V 2.6f
127#define BATTBOOST_SET2_VMIN_2_8V 2.8f
128#define BATTBOOST_SET2_VMIN_3_0V 3.0f
129#define BATTBOOST_SET2_VMIN_3_2V 3.2f
130#define BATTBOOST_SET2_VMIN_BIT_MASK 0xF8
131#define BATTBOOST_SET2_ICH_BIT_MASK 0x1F
132#define BATTBOOST_SET2_SET_VDH_VBT 0x10
133
138#define BATTBOOST_SET3_VEW_2_4V 0
139#define BATTBOOST_SET3_VEW_2_6V 1
140#define BATTBOOST_SET3_VEW_2_8V 2
141#define BATTBOOST_SET3_VEW_3_0V 3
142#define BATTBOOST_SET3_VEW_3_2V 4
143#define BATTBOOST_SET3_VEW_3_4V 5
144#define BATTBOOST_SET3_VEW_3_6V 6
145#define BATTBOOST_SET3_VEW_3_84V 7
146#define BATTBOOST_SET3_VEW_4_1V 8
147#define BATTBOOST_SET3_VEW_4_3V 9
148#define BATTBOOST_SET3_VEW_BIT_MASK 0x0F
149#define BATTBOOST_SET3_EEW_DISABLE 0
150#define BATTBOOST_SET3_EEW_ENABLE 1
151
156#define BATTBOOST_SET5_OPT_MARG_MIN 0
157#define BATTBOOST_SET5_OPT_MARG_NORMAL 1
158#define BATTBOOST_SET5_OPT_MARG_SAFE 2
159#define BATTBOOST_SET5_OPT_MARG_EXTRA_SAFE 3
160
165#define BATTBOOST_SET4_VCAPMAX_4_95V 0
166#define BATTBOOST_SET4_VCAPMAX_5_54V 1
167#define BATTBOOST_SET4_VCAPMAX_BIT_MASK 0xEF
168
169
174#define BATTBOOST_CMD_PROF_0_FIXED_MODE 0
175#define BATTBOOST_CMD_PROF_BIT_MASK 0xFC
176#define BATTBOOST_CMD_BIT_MASK 0x0F
177#define BATTBOOST_PROF_MSB_BIT_MASK 0x03
178#define BATTBOOST_PROF_BIT_MASK 0xF0
179
184#define BATTBOOST_OP_MODE_STANDBY 0
185#define BATTBOOST_OP_MODE_STBY_BIT_MASK 0x06
186#define BATTBOOST_OP_MODE_CHARGE 1
187#define BATTBOOST_OP_MODE_CHG_BIT_MASK 0xF0
188#define BATTBOOST_OP_MODE_SET_CHARGE 0x02
189#define BATTBOOST_OP_MODE_ACTIVE 2
190#define BATTBOOST_OP_MODE_SET_ACT_ACTIVE 0x04
191
196#define BATTBOOST_CMD_RESET_BIT_MASK 0x08
197
202#define BATTBOOST_CMD_AUTOMODE_ENABLE 0x80
203
208#define BATTBOOST_SET1_VSET_1_8V 1.8f
209#define BATTBOOST_SET1_VSET_2_0V 2.0f
210#define BATTBOOST_SET1_VSET_2_2V 2.2f
211#define BATTBOOST_SET1_VSET_2_4V 2.4f
212#define BATTBOOST_SET1_VSET_2_5V 2.5f
213#define BATTBOOST_SET1_VSET_2_6V 2.6f
214#define BATTBOOST_SET1_VSET_2_7V 2.7f
215#define BATTBOOST_SET1_VSET_2_8V 2.8f
216#define BATTBOOST_SET1_VSET_2_9V 2.9f
217#define BATTBOOST_SET1_VSET_3_0V 3.0f
218#define BATTBOOST_SET1_VSET_3_1V 3.1f
219#define BATTBOOST_SET1_VSET_3_2V 3.2f
220#define BATTBOOST_SET1_VSET_3_3V 3.3f
221#define BATTBOOST_SET1_VSET_3_4V 3.4f
222#define BATTBOOST_SET1_VSET_3_5V 3.5f
223#define BATTBOOST_SET1_VSET_3_6V 3.6f
224#define BATTBOOST_SET1_VSET_BIT_MASK 0xF0
225#define BATTBOOST_SET1_VFIX_BIT_MASK 0x0F
226
231#define BATTBOOST_CONDITION_STOP 0
232#define BATTBOOST_CONDITION_START 1
233
238#define BATTBOOST_STATUS_NOT_READY 0
239#define BATTBOOST_STATUS_READY 1
240
246#define BATTBOOST_DEVICE_ADDRESS_0 0x2E
247#define BATTBOOST_DEVICE_ADDRESS_1 0x2F
248
249 // battboost_set
250
265#define BATTBOOST_MAP_MIKROBUS( cfg, mikrobus ) \
266 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
267 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
268 cfg.on = MIKROBUS( mikrobus, MIKROBUS_RST ); \
269 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
270
271 // battboost_map
272 // battboost
273
278typedef struct
279{
280 // Output pins
281 digital_out_t on;
283 // Input pins
284 digital_in_t rdy;
286 // Modules
287 i2c_master_t i2c;
289 // I2C slave address
293
298typedef struct
299{
300 pin_name_t scl;
301 pin_name_t sda;
303 pin_name_t on;
304 pin_name_t rdy;
306 uint32_t i2c_speed;
307 uint8_t i2c_address;
310
321
343
357
374
389
403
418err_t battboost_generic_write ( battboost_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
419
434err_t battboost_generic_read ( battboost_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
435
451err_t battboost_get_status ( battboost_t *ctx, uint8_t *status );
452
466err_t battboost_get_chenergy ( battboost_t *ctx, uint32_t *chenergy );
467
481err_t battboost_get_vcap ( battboost_t *ctx, float *vcap );
482
496err_t battboost_get_vchend ( battboost_t *ctx, uint8_t *vchend );
497
511err_t battboost_set_prof ( battboost_t *ctx, uint8_t prof );
512
526err_t battboost_get_prof ( battboost_t *ctx, uint8_t *prof );
527
541err_t battboost_set_op_mode ( battboost_t *ctx, uint8_t op_mode );
542
556
570
584err_t battboost_set_vset ( battboost_t *ctx, float vset );
585
601
615err_t battboost_set_vmin ( battboost_t *ctx, float vmin );
616
632
647
662
677err_t battboost_set_vew ( battboost_t *ctx, uint8_t vew, uint8_t eew );
678
692err_t battboost_set_vcapmax ( battboost_t *ctx, uint8_t vcapmax );
693
707err_t battboost_set_opt_marg ( battboost_t *ctx, uint8_t opt_marg );
708
722void battboost_set_on_pin_state ( battboost_t *ctx, uint8_t start );
723
736
737#ifdef __cplusplus
738}
739#endif
740#endif // BATTBOOST_H
741
742 // battboost
743
744// ------------------------------------------------------------------------ END
battboost_vfix_t
BATT Boost Click capacitor end-of-charge voltage.
Definition battboost.h:327
@ BATTBOOST_VFIX_3_27V
Definition battboost.h:330
@ BATTBOOST_VFIX_4_55V
Definition battboost.h:335
@ BATTBOOST_VFIX_3_84V
Definition battboost.h:332
@ BATTBOOST_VFIX_3_57V
Definition battboost.h:331
@ BATTBOOST_VFIX_2_60V
Definition battboost.h:328
@ BATTBOOST_VFIX_5_34V
Definition battboost.h:339
@ BATTBOOST_VFIX_4_10V
Definition battboost.h:333
@ BATTBOOST_VFIX_4_33V
Definition battboost.h:334
@ BATTBOOST_VFIX_5_16V
Definition battboost.h:338
@ BATTBOOST_VFIX_2_95V
Definition battboost.h:329
@ BATTBOOST_VFIX_4_95V
Definition battboost.h:337
@ BATTBOOST_VFIX_4_76V
Definition battboost.h:336
@ BATTBOOST_VFIX_5_54V
Definition battboost.h:340
battboost_ich_t
BATT Boost Click capacitor charge current.
Definition battboost.h:349
@ BATTBOOST_ICH_50_MA
Definition battboost.h:354
@ BATTBOOST_ICH_8_MA
Definition battboost.h:352
@ BATTBOOST_ICH_2_MA
Definition battboost.h:350
@ BATTBOOST_ICH_4_MA
Definition battboost.h:351
@ BATTBOOST_ICH_16_MA
Definition battboost.h:353
battboost_return_value_t
BATT Boost Click return value data.
Definition battboost.h:316
@ BATTBOOST_OK
Definition battboost.h:317
@ BATTBOOST_ERROR
Definition battboost.h:318
err_t battboost_generic_write(battboost_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
BATT Boost I2C writing function.
err_t battboost_reset_optimizer(battboost_t *ctx)
BATT Boost reset optimizer result function.
err_t battboost_set_vcapmax(battboost_t *ctx, uint8_t vcapmax)
BATT Boost sets the capacitor maximum storage voltage function.
err_t battboost_generic_read(battboost_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
BATT Boost I2C reading function.
err_t battboost_set_ich(battboost_t *ctx, battboost_ich_t ich)
BATT Boost sets the charge current function.
err_t battboost_get_vcap(battboost_t *ctx, float *vcap)
BATT Boost gets the storage capacitor voltage status function.
err_t battboost_high_impedance_mode(battboost_t *ctx)
BATT Boost sets the high-impedance mode function.
err_t battboost_set_op_mode(battboost_t *ctx, uint8_t op_mode)
BATT Boost sets the operating mode function.
err_t battboost_init(battboost_t *ctx, battboost_cfg_t *cfg)
BATT Boost initialization function.
err_t battboost_get_vchend(battboost_t *ctx, uint8_t *vchend)
BATT Boost gets the target charge voltage function.
void battboost_set_on_pin_state(battboost_t *ctx, uint8_t start)
BATT Boost sets the ON pin state function.
err_t battboost_set_vfix(battboost_t *ctx, battboost_vfix_t vfix)
BATT Boost sets the end-of-charge voltage function.
err_t battboost_get_status(battboost_t *ctx, uint8_t *status)
BATT Boost gets the status function.
err_t battboost_set_vew(battboost_t *ctx, uint8_t vew, uint8_t eew)
BATT Boost sets the early warning voltage function.
err_t battboost_set_opt_marg(battboost_t *ctx, uint8_t opt_marg)
BATT Boost sets the optimization margin voltage function.
err_t battboost_set_automode(battboost_t *ctx)
BATT Boost sets the auto mode function.
err_t battboost_set_prof(battboost_t *ctx, uint8_t prof)
BATT Boost sets optimizer profile number function.
err_t battboost_default_cfg(battboost_t *ctx)
BATT Boost default configuration function.
err_t battboost_set_vmin(battboost_t *ctx, float vmin)
BATT Boost sets the input threshold voltage function.
void battboost_cfg_setup(battboost_cfg_t *cfg)
BATT Boost configuration object setup function.
err_t battboost_get_chenergy(battboost_t *ctx, uint32_t *chenergy)
BATT Boost gets the charge cycle count function.
err_t battboost_set_vset(battboost_t *ctx, float vset)
BATT Boost sets the output voltage function.
uint8_t battboost_get_ready(battboost_t *ctx)
BATT Boost gets ready state function.
err_t battboost_vdh_vbt_mode(battboost_t *ctx)
BATT Boost sets the Vvdh Vvbt mode function.
err_t battboost_get_prof(battboost_t *ctx, uint8_t *prof)
BATT Boost gets optimizer profile number function.
BATT Boost Click configuration object.
Definition battboost.h:299
uint32_t i2c_speed
Definition battboost.h:306
pin_name_t on
Definition battboost.h:303
pin_name_t scl
Definition battboost.h:300
pin_name_t rdy
Definition battboost.h:304
pin_name_t sda
Definition battboost.h:301
uint8_t i2c_address
Definition battboost.h:307
BATT Boost Click context object.
Definition battboost.h:279
digital_out_t on
Definition battboost.h:281
i2c_master_t i2c
Definition battboost.h:287
uint8_t slave_address
Definition battboost.h:290
digital_in_t rdy
Definition battboost.h:284