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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define BATTBOOST_REG_STATUS 0x00
60 #define BATTBOOST_REG_CHENERGY_3 0x01
61 #define BATTBOOST_REG_CHENERGY_2 0x02
62 #define BATTBOOST_REG_CHENERGY_1 0x03
63 #define BATTBOOST_REG_CHENERGY_0 0x04
64 #define BATTBOOST_REG_VCAP 0x05
65 #define BATTBOOST_REG_VCHEND 0x06
66 #define BATTBOOST_REG_PROFILE_MSB 0x07
67 #define BATTBOOST_REG_COMMAND 0x08
68 #define BATTBOOST_REG_SET1 0x09
69 #define BATTBOOST_REG_SET2 0x0A
70 #define BATTBOOST_REG_SET3 0x0B
71 #define BATTBOOST_REG_SET4 0x0C
72 #define BATTBOOST_REG_SET5 0x0D
73  // battboost_reg
75 
90 #define BATTBOOST_STATUS_LOWBAT 0x80
91 #define BATTBOOST_STATUS_EW 0x40
92 #define BATTBOOST_STATUS_ALRM 0x20
93 #define BATTBOOST_STATUS_RDY 0x01
94 
99 #define BATTBOOST_VCAP_BIT_MASK 0x1F
100 
105 #define BATTBOOST_VCHEND_BIT_MASK 0x1F
106 
111 #define BATTBOOST_SET2_VMIN_2_4V 2.4f
112 #define BATTBOOST_SET2_VMIN_2_6V 2.6f
113 #define BATTBOOST_SET2_VMIN_2_8V 2.8f
114 #define BATTBOOST_SET2_VMIN_3_0V 3.0f
115 #define BATTBOOST_SET2_VMIN_3_2V 3.2f
116 #define BATTBOOST_SET2_VMIN_BIT_MASK 0xF8
117 #define BATTBOOST_SET2_ICH_BIT_MASK 0x1F
118 #define BATTBOOST_SET2_SET_VDH_VBT 0x10
119 
124 #define BATTBOOST_SET3_VEW_2_4V 0
125 #define BATTBOOST_SET3_VEW_2_6V 1
126 #define BATTBOOST_SET3_VEW_2_8V 2
127 #define BATTBOOST_SET3_VEW_3_0V 3
128 #define BATTBOOST_SET3_VEW_3_2V 4
129 #define BATTBOOST_SET3_VEW_3_4V 5
130 #define BATTBOOST_SET3_VEW_3_6V 6
131 #define BATTBOOST_SET3_VEW_3_84V 7
132 #define BATTBOOST_SET3_VEW_4_1V 8
133 #define BATTBOOST_SET3_VEW_4_3V 9
134 #define BATTBOOST_SET3_VEW_BIT_MASK 0x0F
135 #define BATTBOOST_SET3_EEW_DISABLE 0
136 #define BATTBOOST_SET3_EEW_ENABLE 1
137 
142 #define BATTBOOST_SET5_OPT_MARG_MIN 0
143 #define BATTBOOST_SET5_OPT_MARG_NORMAL 1
144 #define BATTBOOST_SET5_OPT_MARG_SAFE 2
145 #define BATTBOOST_SET5_OPT_MARG_EXTRA_SAFE 3
146 
151 #define BATTBOOST_SET4_VCAPMAX_4_95V 0
152 #define BATTBOOST_SET4_VCAPMAX_5_54V 1
153 #define BATTBOOST_SET4_VCAPMAX_BIT_MASK 0xEF
154 
155 
160 #define BATTBOOST_CMD_PROF_0_FIXED_MODE 0
161 #define BATTBOOST_CMD_PROF_BIT_MASK 0xFC
162 #define BATTBOOST_CMD_BIT_MASK 0x0F
163 #define BATTBOOST_PROF_MSB_BIT_MASK 0x03
164 #define BATTBOOST_PROF_BIT_MASK 0xF0
165 
170 #define BATTBOOST_OP_MODE_STANDBY 0
171 #define BATTBOOST_OP_MODE_STBY_BIT_MASK 0x06
172 #define BATTBOOST_OP_MODE_CHARGE 1
173 #define BATTBOOST_OP_MODE_CHG_BIT_MASK 0xF0
174 #define BATTBOOST_OP_MODE_SET_CHARGE 0x02
175 #define BATTBOOST_OP_MODE_ACTIVE 2
176 #define BATTBOOST_OP_MODE_SET_ACT_ACTIVE 0x04
177 
182 #define BATTBOOST_CMD_RESET_BIT_MASK 0x08
183 
188 #define BATTBOOST_CMD_AUTOMODE_ENABLE 0x80
189 
194 #define BATTBOOST_SET1_VSET_1_8V 1.8f
195 #define BATTBOOST_SET1_VSET_2_0V 2.0f
196 #define BATTBOOST_SET1_VSET_2_2V 2.2f
197 #define BATTBOOST_SET1_VSET_2_4V 2.4f
198 #define BATTBOOST_SET1_VSET_2_5V 2.5f
199 #define BATTBOOST_SET1_VSET_2_6V 2.6f
200 #define BATTBOOST_SET1_VSET_2_7V 2.7f
201 #define BATTBOOST_SET1_VSET_2_8V 2.8f
202 #define BATTBOOST_SET1_VSET_2_9V 2.9f
203 #define BATTBOOST_SET1_VSET_3_0V 3.0f
204 #define BATTBOOST_SET1_VSET_3_1V 3.1f
205 #define BATTBOOST_SET1_VSET_3_2V 3.2f
206 #define BATTBOOST_SET1_VSET_3_3V 3.3f
207 #define BATTBOOST_SET1_VSET_3_4V 3.4f
208 #define BATTBOOST_SET1_VSET_3_5V 3.5f
209 #define BATTBOOST_SET1_VSET_3_6V 3.6f
210 #define BATTBOOST_SET1_VSET_BIT_MASK 0xF0
211 #define BATTBOOST_SET1_VFIX_BIT_MASK 0x0F
212 
217 #define BATTBOOST_CONDITION_STOP 0
218 #define BATTBOOST_CONDITION_START 1
219 
224 #define BATTBOOST_STATUS_NOT_READY 0
225 #define BATTBOOST_STATUS_READY 1
226 
232 #define BATTBOOST_DEVICE_ADDRESS_0 0x2E
233 #define BATTBOOST_DEVICE_ADDRESS_1 0x2F
234  // battboost_set
236 
251 #define BATTBOOST_MAP_MIKROBUS( cfg, mikrobus ) \
252  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
253  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
254  cfg.on = MIKROBUS( mikrobus, MIKROBUS_RST ); \
255  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
256  // battboost_map // battboost
259 
264 typedef struct
265 {
266  // Output pins
267  digital_out_t on;
269  // Input pins
270  digital_in_t rdy;
272  // Modules
273  i2c_master_t i2c;
275  // I2C slave address
276  uint8_t slave_address;
278 } battboost_t;
279 
284 typedef struct
285 {
286  pin_name_t scl;
287  pin_name_t sda;
289  pin_name_t on;
290  pin_name_t rdy;
292  uint32_t i2c_speed;
293  uint8_t i2c_address;
296 
301 typedef enum
302 {
304  BATTBOOST_ERROR = -1
305 
307 
312 typedef enum
313 {
327 
329 
334 typedef enum
335 {
341 
343 
360 
375 
389 
404 err_t battboost_generic_write ( battboost_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
405 
420 err_t battboost_generic_read ( battboost_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
421 
437 err_t battboost_get_status ( battboost_t *ctx, uint8_t *status );
438 
452 err_t battboost_get_chenergy ( battboost_t *ctx, uint32_t *chenergy );
453 
467 err_t battboost_get_vcap ( battboost_t *ctx, float *vcap );
468 
482 err_t battboost_get_vchend ( battboost_t *ctx, uint8_t *vchend );
483 
497 err_t battboost_set_prof ( battboost_t *ctx, uint8_t prof );
498 
512 err_t battboost_get_prof ( battboost_t *ctx, uint8_t *prof );
513 
527 err_t battboost_set_op_mode ( battboost_t *ctx, uint8_t op_mode );
528 
542 
556 
570 err_t battboost_set_vset ( battboost_t *ctx, float vset );
571 
587 
601 err_t battboost_set_vmin ( battboost_t *ctx, float vmin );
602 
618 
633 
648 
663 err_t battboost_set_vew ( battboost_t *ctx, uint8_t vew, uint8_t eew );
664 
678 err_t battboost_set_vcapmax ( battboost_t *ctx, uint8_t vcapmax );
679 
693 err_t battboost_set_opt_marg ( battboost_t *ctx, uint8_t opt_marg );
694 
708 void battboost_set_on_pin_state ( battboost_t *ctx, uint8_t start );
709 
722 
723 #ifdef __cplusplus
724 }
725 #endif
726 #endif // BATTBOOST_H
727  // battboost
729 
730 // ------------------------------------------------------------------------ END
battboost_t::on
digital_out_t on
Definition: battboost.h:267
battboost_cfg_t::scl
pin_name_t scl
Definition: battboost.h:286
BATTBOOST_ICH_4_MA
@ BATTBOOST_ICH_4_MA
Definition: battboost.h:337
battboost_get_status
err_t battboost_get_status(battboost_t *ctx, uint8_t *status)
BATT Boost gets the status function.
battboost_generic_write
err_t battboost_generic_write(battboost_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
BATT Boost I2C writing function.
battboost_cfg_t::on
pin_name_t on
Definition: battboost.h:289
battboost_get_chenergy
err_t battboost_get_chenergy(battboost_t *ctx, uint32_t *chenergy)
BATT Boost gets the charge cycle count function.
battboost_set_op_mode
err_t battboost_set_op_mode(battboost_t *ctx, uint8_t op_mode)
BATT Boost sets the operating mode function.
battboost_set_vew
err_t battboost_set_vew(battboost_t *ctx, uint8_t vew, uint8_t eew)
BATT Boost sets the early warning voltage function.
battboost_cfg_t::i2c_address
uint8_t i2c_address
Definition: battboost.h:293
battboost_set_automode
err_t battboost_set_automode(battboost_t *ctx)
BATT Boost sets the auto mode function.
battboost_set_vset
err_t battboost_set_vset(battboost_t *ctx, float vset)
BATT Boost sets the output voltage function.
BATTBOOST_ICH_16_MA
@ BATTBOOST_ICH_16_MA
Definition: battboost.h:339
battboost_cfg_t::sda
pin_name_t sda
Definition: battboost.h:287
battboost_return_value_t
battboost_return_value_t
BATT Boost Click return value data.
Definition: battboost.h:302
battboost_reset_optimizer
err_t battboost_reset_optimizer(battboost_t *ctx)
BATT Boost reset optimizer result function.
BATTBOOST_ICH_50_MA
@ BATTBOOST_ICH_50_MA
Definition: battboost.h:340
battboost_cfg_t
BATT Boost Click configuration object.
Definition: battboost.h:285
BATTBOOST_VFIX_2_60V
@ BATTBOOST_VFIX_2_60V
Definition: battboost.h:314
battboost_cfg_t::rdy
pin_name_t rdy
Definition: battboost.h:290
BATTBOOST_VFIX_4_55V
@ BATTBOOST_VFIX_4_55V
Definition: battboost.h:321
battboost_default_cfg
err_t battboost_default_cfg(battboost_t *ctx)
BATT Boost default configuration function.
battboost_t::slave_address
uint8_t slave_address
Definition: battboost.h:276
BATTBOOST_VFIX_5_34V
@ BATTBOOST_VFIX_5_34V
Definition: battboost.h:325
BATTBOOST_OK
@ BATTBOOST_OK
Definition: battboost.h:303
battboost_t
BATT Boost Click context object.
Definition: battboost.h:265
battboost_set_vmin
err_t battboost_set_vmin(battboost_t *ctx, float vmin)
BATT Boost sets the input threshold voltage function.
battboost_get_prof
err_t battboost_get_prof(battboost_t *ctx, uint8_t *prof)
BATT Boost gets optimizer profile number function.
battboost_ich_t
battboost_ich_t
BATT Boost Click capacitor charge current.
Definition: battboost.h:335
battboost_get_vchend
err_t battboost_get_vchend(battboost_t *ctx, uint8_t *vchend)
BATT Boost gets the target charge voltage function.
battboost_generic_read
err_t battboost_generic_read(battboost_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
BATT Boost I2C reading function.
battboost_set_opt_marg
err_t battboost_set_opt_marg(battboost_t *ctx, uint8_t opt_marg)
BATT Boost sets the optimization margin voltage function.
BATTBOOST_VFIX_4_95V
@ BATTBOOST_VFIX_4_95V
Definition: battboost.h:323
BATTBOOST_VFIX_4_10V
@ BATTBOOST_VFIX_4_10V
Definition: battboost.h:319
battboost_cfg_setup
void battboost_cfg_setup(battboost_cfg_t *cfg)
BATT Boost configuration object setup function.
BATTBOOST_ICH_2_MA
@ BATTBOOST_ICH_2_MA
Definition: battboost.h:336
BATTBOOST_VFIX_5_54V
@ BATTBOOST_VFIX_5_54V
Definition: battboost.h:326
battboost_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: battboost.h:292
BATTBOOST_ERROR
@ BATTBOOST_ERROR
Definition: battboost.h:304
BATTBOOST_ICH_8_MA
@ BATTBOOST_ICH_8_MA
Definition: battboost.h:338
battboost_get_vcap
err_t battboost_get_vcap(battboost_t *ctx, float *vcap)
BATT Boost gets the storage capacitor voltage status function.
battboost_get_ready
uint8_t battboost_get_ready(battboost_t *ctx)
BATT Boost gets ready state function.
battboost_high_impedance_mode
err_t battboost_high_impedance_mode(battboost_t *ctx)
BATT Boost sets the high-impedance mode function.
battboost_t::rdy
digital_in_t rdy
Definition: battboost.h:270
BATTBOOST_VFIX_3_57V
@ BATTBOOST_VFIX_3_57V
Definition: battboost.h:317
BATTBOOST_VFIX_3_84V
@ BATTBOOST_VFIX_3_84V
Definition: battboost.h:318
battboost_init
err_t battboost_init(battboost_t *ctx, battboost_cfg_t *cfg)
BATT Boost initialization function.
battboost_vfix_t
battboost_vfix_t
BATT Boost Click capacitor end-of-charge voltage.
Definition: battboost.h:313
BATTBOOST_VFIX_3_27V
@ BATTBOOST_VFIX_3_27V
Definition: battboost.h:316
battboost_set_on_pin_state
void battboost_set_on_pin_state(battboost_t *ctx, uint8_t start)
BATT Boost sets the ON pin state function.
BATTBOOST_VFIX_4_76V
@ BATTBOOST_VFIX_4_76V
Definition: battboost.h:322
BATTBOOST_VFIX_5_16V
@ BATTBOOST_VFIX_5_16V
Definition: battboost.h:324
BATTBOOST_VFIX_2_95V
@ BATTBOOST_VFIX_2_95V
Definition: battboost.h:315
battboost_set_ich
err_t battboost_set_ich(battboost_t *ctx, battboost_ich_t ich)
BATT Boost sets the charge current function.
battboost_set_vfix
err_t battboost_set_vfix(battboost_t *ctx, battboost_vfix_t vfix)
BATT Boost sets the end-of-charge voltage function.
BATTBOOST_VFIX_4_33V
@ BATTBOOST_VFIX_4_33V
Definition: battboost.h:320
battboost_vdh_vbt_mode
err_t battboost_vdh_vbt_mode(battboost_t *ctx)
BATT Boost sets the Vvdh Vvbt mode function.
battboost_set_vcapmax
err_t battboost_set_vcapmax(battboost_t *ctx, uint8_t vcapmax)
BATT Boost sets the capacitor maximum storage voltage function.
battboost_set_prof
err_t battboost_set_prof(battboost_t *ctx, uint8_t prof)
BATT Boost sets optimizer profile number function.
battboost_t::i2c
i2c_master_t i2c
Definition: battboost.h:273