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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define BATTBOOST_REG_STATUS 0x00
70 #define BATTBOOST_REG_CHENERGY_3 0x01
71 #define BATTBOOST_REG_CHENERGY_2 0x02
72 #define BATTBOOST_REG_CHENERGY_1 0x03
73 #define BATTBOOST_REG_CHENERGY_0 0x04
74 #define BATTBOOST_REG_VCAP 0x05
75 #define BATTBOOST_REG_VCHEND 0x06
76 #define BATTBOOST_REG_PROFILE_MSB 0x07
77 #define BATTBOOST_REG_COMMAND 0x08
78 #define BATTBOOST_REG_SET1 0x09
79 #define BATTBOOST_REG_SET2 0x0A
80 #define BATTBOOST_REG_SET3 0x0B
81 #define BATTBOOST_REG_SET4 0x0C
82 #define BATTBOOST_REG_SET5 0x0D
83  // battboost_reg
85 
100 #define BATTBOOST_STATUS_LOWBAT 0x80
101 #define BATTBOOST_STATUS_EW 0x40
102 #define BATTBOOST_STATUS_ALRM 0x20
103 #define BATTBOOST_STATUS_RDY 0x01
104 
109 #define BATTBOOST_VCAP_BIT_MASK 0x1F
110 
115 #define BATTBOOST_VCHEND_BIT_MASK 0x1F
116 
121 #define BATTBOOST_SET2_VMIN_2_4V 2.4f
122 #define BATTBOOST_SET2_VMIN_2_6V 2.6f
123 #define BATTBOOST_SET2_VMIN_2_8V 2.8f
124 #define BATTBOOST_SET2_VMIN_3_0V 3.0f
125 #define BATTBOOST_SET2_VMIN_3_2V 3.2f
126 #define BATTBOOST_SET2_VMIN_BIT_MASK 0xF8
127 #define BATTBOOST_SET2_ICH_BIT_MASK 0x1F
128 #define BATTBOOST_SET2_SET_VDH_VBT 0x10
129 
134 #define BATTBOOST_SET3_VEW_2_4V 0
135 #define BATTBOOST_SET3_VEW_2_6V 1
136 #define BATTBOOST_SET3_VEW_2_8V 2
137 #define BATTBOOST_SET3_VEW_3_0V 3
138 #define BATTBOOST_SET3_VEW_3_2V 4
139 #define BATTBOOST_SET3_VEW_3_4V 5
140 #define BATTBOOST_SET3_VEW_3_6V 6
141 #define BATTBOOST_SET3_VEW_3_84V 7
142 #define BATTBOOST_SET3_VEW_4_1V 8
143 #define BATTBOOST_SET3_VEW_4_3V 9
144 #define BATTBOOST_SET3_VEW_BIT_MASK 0x0F
145 #define BATTBOOST_SET3_EEW_DISABLE 0
146 #define BATTBOOST_SET3_EEW_ENABLE 1
147 
152 #define BATTBOOST_SET5_OPT_MARG_MIN 0
153 #define BATTBOOST_SET5_OPT_MARG_NORMAL 1
154 #define BATTBOOST_SET5_OPT_MARG_SAFE 2
155 #define BATTBOOST_SET5_OPT_MARG_EXTRA_SAFE 3
156 
161 #define BATTBOOST_SET4_VCAPMAX_4_95V 0
162 #define BATTBOOST_SET4_VCAPMAX_5_54V 1
163 #define BATTBOOST_SET4_VCAPMAX_BIT_MASK 0xEF
164 
165 
170 #define BATTBOOST_CMD_PROF_0_FIXED_MODE 0
171 #define BATTBOOST_CMD_PROF_BIT_MASK 0xFC
172 #define BATTBOOST_CMD_BIT_MASK 0x0F
173 #define BATTBOOST_PROF_MSB_BIT_MASK 0x03
174 #define BATTBOOST_PROF_BIT_MASK 0xF0
175 
180 #define BATTBOOST_OP_MODE_STANDBY 0
181 #define BATTBOOST_OP_MODE_STBY_BIT_MASK 0x06
182 #define BATTBOOST_OP_MODE_CHARGE 1
183 #define BATTBOOST_OP_MODE_CHG_BIT_MASK 0xF0
184 #define BATTBOOST_OP_MODE_SET_CHARGE 0x02
185 #define BATTBOOST_OP_MODE_ACTIVE 2
186 #define BATTBOOST_OP_MODE_SET_ACT_ACTIVE 0x04
187 
192 #define BATTBOOST_CMD_RESET_BIT_MASK 0x08
193 
198 #define BATTBOOST_CMD_AUTOMODE_ENABLE 0x80
199 
204 #define BATTBOOST_SET1_VSET_1_8V 1.8f
205 #define BATTBOOST_SET1_VSET_2_0V 2.0f
206 #define BATTBOOST_SET1_VSET_2_2V 2.2f
207 #define BATTBOOST_SET1_VSET_2_4V 2.4f
208 #define BATTBOOST_SET1_VSET_2_5V 2.5f
209 #define BATTBOOST_SET1_VSET_2_6V 2.6f
210 #define BATTBOOST_SET1_VSET_2_7V 2.7f
211 #define BATTBOOST_SET1_VSET_2_8V 2.8f
212 #define BATTBOOST_SET1_VSET_2_9V 2.9f
213 #define BATTBOOST_SET1_VSET_3_0V 3.0f
214 #define BATTBOOST_SET1_VSET_3_1V 3.1f
215 #define BATTBOOST_SET1_VSET_3_2V 3.2f
216 #define BATTBOOST_SET1_VSET_3_3V 3.3f
217 #define BATTBOOST_SET1_VSET_3_4V 3.4f
218 #define BATTBOOST_SET1_VSET_3_5V 3.5f
219 #define BATTBOOST_SET1_VSET_3_6V 3.6f
220 #define BATTBOOST_SET1_VSET_BIT_MASK 0xF0
221 #define BATTBOOST_SET1_VFIX_BIT_MASK 0x0F
222 
227 #define BATTBOOST_CONDITION_STOP 0
228 #define BATTBOOST_CONDITION_START 1
229 
234 #define BATTBOOST_STATUS_NOT_READY 0
235 #define BATTBOOST_STATUS_READY 1
236 
242 #define BATTBOOST_DEVICE_ADDRESS_0 0x2E
243 #define BATTBOOST_DEVICE_ADDRESS_1 0x2F
244  // battboost_set
246 
261 #define BATTBOOST_MAP_MIKROBUS( cfg, mikrobus ) \
262  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
263  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
264  cfg.on = MIKROBUS( mikrobus, MIKROBUS_RST ); \
265  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
266  // battboost_map // battboost
269 
274 typedef struct
275 {
276  // Output pins
277  digital_out_t on;
279  // Input pins
280  digital_in_t rdy;
282  // Modules
283  i2c_master_t i2c;
285  // I2C slave address
286  uint8_t slave_address;
288 } battboost_t;
289 
294 typedef struct
295 {
296  pin_name_t scl;
297  pin_name_t sda;
299  pin_name_t on;
300  pin_name_t rdy;
302  uint32_t i2c_speed;
303  uint8_t i2c_address;
306 
311 typedef enum
312 {
314  BATTBOOST_ERROR = -1
315 
317 
322 typedef enum
323 {
337 
339 
344 typedef enum
345 {
351 
353 
370 
385 
399 
414 err_t battboost_generic_write ( battboost_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
415 
430 err_t battboost_generic_read ( battboost_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
431 
447 err_t battboost_get_status ( battboost_t *ctx, uint8_t *status );
448 
462 err_t battboost_get_chenergy ( battboost_t *ctx, uint32_t *chenergy );
463 
477 err_t battboost_get_vcap ( battboost_t *ctx, float *vcap );
478 
492 err_t battboost_get_vchend ( battboost_t *ctx, uint8_t *vchend );
493 
507 err_t battboost_set_prof ( battboost_t *ctx, uint8_t prof );
508 
522 err_t battboost_get_prof ( battboost_t *ctx, uint8_t *prof );
523 
537 err_t battboost_set_op_mode ( battboost_t *ctx, uint8_t op_mode );
538 
552 
566 
580 err_t battboost_set_vset ( battboost_t *ctx, float vset );
581 
597 
611 err_t battboost_set_vmin ( battboost_t *ctx, float vmin );
612 
628 
643 
658 
673 err_t battboost_set_vew ( battboost_t *ctx, uint8_t vew, uint8_t eew );
674 
688 err_t battboost_set_vcapmax ( battboost_t *ctx, uint8_t vcapmax );
689 
703 err_t battboost_set_opt_marg ( battboost_t *ctx, uint8_t opt_marg );
704 
718 void battboost_set_on_pin_state ( battboost_t *ctx, uint8_t start );
719 
732 
733 #ifdef __cplusplus
734 }
735 #endif
736 #endif // BATTBOOST_H
737  // battboost
739 
740 // ------------------------------------------------------------------------ END
battboost_t::on
digital_out_t on
Definition: battboost.h:277
battboost_cfg_t::scl
pin_name_t scl
Definition: battboost.h:296
BATTBOOST_ICH_4_MA
@ BATTBOOST_ICH_4_MA
Definition: battboost.h:347
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:299
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:303
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:349
battboost_cfg_t::sda
pin_name_t sda
Definition: battboost.h:297
battboost_return_value_t
battboost_return_value_t
BATT Boost Click return value data.
Definition: battboost.h:312
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:350
battboost_cfg_t
BATT Boost Click configuration object.
Definition: battboost.h:295
BATTBOOST_VFIX_2_60V
@ BATTBOOST_VFIX_2_60V
Definition: battboost.h:324
battboost_cfg_t::rdy
pin_name_t rdy
Definition: battboost.h:300
BATTBOOST_VFIX_4_55V
@ BATTBOOST_VFIX_4_55V
Definition: battboost.h:331
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:286
BATTBOOST_VFIX_5_34V
@ BATTBOOST_VFIX_5_34V
Definition: battboost.h:335
BATTBOOST_OK
@ BATTBOOST_OK
Definition: battboost.h:313
battboost_t
BATT Boost Click context object.
Definition: battboost.h:275
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:345
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:333
BATTBOOST_VFIX_4_10V
@ BATTBOOST_VFIX_4_10V
Definition: battboost.h:329
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:346
BATTBOOST_VFIX_5_54V
@ BATTBOOST_VFIX_5_54V
Definition: battboost.h:336
battboost_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: battboost.h:302
BATTBOOST_ERROR
@ BATTBOOST_ERROR
Definition: battboost.h:314
BATTBOOST_ICH_8_MA
@ BATTBOOST_ICH_8_MA
Definition: battboost.h:348
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:280
BATTBOOST_VFIX_3_57V
@ BATTBOOST_VFIX_3_57V
Definition: battboost.h:327
BATTBOOST_VFIX_3_84V
@ BATTBOOST_VFIX_3_84V
Definition: battboost.h:328
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:323
BATTBOOST_VFIX_3_27V
@ BATTBOOST_VFIX_3_27V
Definition: battboost.h:326
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:332
BATTBOOST_VFIX_5_16V
@ BATTBOOST_VFIX_5_16V
Definition: battboost.h:334
BATTBOOST_VFIX_2_95V
@ BATTBOOST_VFIX_2_95V
Definition: battboost.h:325
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:330
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:283