charger6  2.0.0.0
charger6.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 CHARGER6_H
29 #define CHARGER6_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 CHARGER6_REGISTER_00 0x00
60 #define CHARGER6_REGISTER_01 0x01
61 #define CHARGER6_REGISTER_02 0x02
62 #define CHARGER6_REGISTER_03 0x03
63 #define CHARGER6_REGISTER_04 0x04
64 #define CHARGER6_REGISTER_05 0x05
65 #define CHARGER6_REGISTER_06 0x06
66 #define CHARGER6_REGISTER_07 0x07
67 #define CHARGER6_REGISTER_08 0x08
68 #define CHARGER6_REGISTER_09 0x09
69 #define CHARGER6_REGISTER_0A 0x0A
70 #define CHARGER6_REGISTER_0B 0x0B
71  // charger6_reg
73 
89 #define CHARGER6_PSEL_SW_MANUAL 0x00
90 #define CHARGER6_PSEL_500_mA 0x01
91  // pwr_sel
93 
109 #define CHARGER6_SYS_MIN_VTG_2600mV 2600
110 #define CHARGER6_SYS_MIN_VTG_2800mV 2800
111 #define CHARGER6_SYS_MIN_VTG_3000mV 3000
112 #define CHARGER6_SYS_MIN_VTG_3200mV 3200
113 #define CHARGER6_SYS_MIN_VTG_3400mV 3400
114 #define CHARGER6_SYS_MIN_VTG_3500mV 3500
115 #define CHARGER6_SYS_MIN_VTG_3600mV 3600
116 #define CHARGER6_SYS_MIN_VTG_3700mV 3700
117  // sys_min_voltage
119 
135 #define CHARGER6_TOPOFF_TIMER_DISABLE 0
136 #define CHARGER6_TOPOFF_TIMER_15_MINUTES 15
137 #define CHARGER6_TOPOFF_TIMER_30_MINUTES 30
138 #define CHARGER6_TOPOFF_TIMER_45_MINUTES 45
139  // top_off_time
141 
162 #define CHARGER6_R00_EN_HIZ_DISABLE 0x00
163 #define CHARGER6_R00_EN_HIZ_ENABLE 0x80
164 #define CHARGER6_R00_EN_ICHG_MON_ENABLE 0x00
165 #define CHARGER6_R00_EN_ICHG_MON_DISABLE_STAT 0x60
166 #define CHARGER6_R00_IINDPM_1600mA 0x10
167 #define CHARGER6_R00_IINDPM_800mA 0x08
168 #define CHARGER6_R00_IINDPM_400mA 0x04
169 #define CHARGER6_R00_IINDPM_200mA 0x02
170 #define CHARGER6_R00_IINDPM_100mA 0x01
171 
177 #define CHARGER6_R01_PFM_ENABLE 0x00
178 #define CHARGER6_R01_PFM_DISABLE 0x80
179 #define CHARGER6_R01_WD_RST_NORMAL 0x00
180 #define CHARGER6_R01_WD_RST_RESET 0x40
181 #define CHARGER6_R01_OTG_DISABLE 0x00
182 #define CHARGER6_R01_OTG_ENABLE 0x20
183 #define CHARGER6_R01_CHARGE_DISABLE 0x00
184 #define CHARGER6_R01_CHARGE_ENABLE 0x10
185 #define CHARGER6_R01_SYS_MIN_2600mV 0x00
186 #define CHARGER6_R01_SYS_MIN_2800mV 0x02
187 #define CHARGER6_R01_SYS_MIN_3000mV 0x04
188 #define CHARGER6_R01_SYS_MIN_3200mV 0x06
189 #define CHARGER6_R01_SYS_MIN_3400mV 0x08
190 #define CHARGER6_R01_SYS_MIN_3500mV 0x0A
191 #define CHARGER6_R01_SYS_MIN_3600mV 0x0C
192 #define CHARGER6_R01_SYS_MIN_3700mV 0x0E
193 #define CHARGER6_R01_MIN_VBAT_SEL_2800mV 0x00
194 #define CHARGER6_R01_MIN_VBAT_SEL_2500mV 0x01
195 
201 #define CHARGER6_R02_BOOST_LIM_500mA 0x00
202 #define CHARGER6_R02_BOOST_LIM_1200mA 0x80
203 #define CHARGER6_R02_Q1_FULLON_BETTER_ACCURACY 0x00
204 #define CHARGER6_R02_Q1_FULLON_BETTER_EFFICIENCY 0x40
205 #define CHARGER6_R02_ICHG_1920mA 0x20
206 #define CHARGER6_R02_ICHG_960mA 0x10
207 #define CHARGER6_R02_ICHG_480mA 0x08
208 #define CHARGER6_R02_ICHG_240mA 0x04
209 #define CHARGER6_R02_ICHG_120mA 0x02
210 #define CHARGER6_R02_ICHG_60mA 0x01
211 
217 #define CHARGER6_R03_IPRECHG_480mA 0x80
218 #define CHARGER6_R03_IPRECHG_240mA 0x40
219 #define CHARGER6_R03_IPRECHG_120mA 0x20
220 #define CHARGER6_R03_IPRECHG_60mA 0x10
221 #define CHARGER6_R03_ITERM_480mA 0x08
222 #define CHARGER6_R03_ITERM_240mA 0x04
223 #define CHARGER6_R03_ITERM_120mA 0x02
224 #define CHARGER6_R03_ITERM_60mA 0x01
225 
231 #define CHARGER6_R04_VREG_512mV 0x80
232 #define CHARGER6_R04_VREG_256mV 0x40
233 #define CHARGER6_R04_VREG_128mV 0x20
234 #define CHARGER6_R04_VREG_64mV 0x10
235 #define CHARGER6_R04_VREG_32mV 0x08
236 #define CHARGER6_R04_TOPOFF_TIMER_DISABLED 0x00
237 #define CHARGER6_R04_TOPOFF_TIMER_15_MIN 0x02
238 #define CHARGER6_R04_TOPOFF_TIMER_30_MIN 0x04
239 #define CHARGER6_R04_TOPOFF_TIMER_45_MIN 0x06
240 #define CHARGER6_R04_VRECHG_100mV 0x00
241 #define CHARGER6_R04_VRECHG_200mV 0x01
242 
248 #define CHARGER6_R05_TERMINATION_DISABLE 0x00
249 #define CHARGER6_R05_TERMINATION_ENABLE 0x80
250 #define CHARGER6_R05_WATCHDOG_DISABLE 0x00
251 #define CHARGER6_R05_WATCHDOG_TIMER_40_SEC 0x10
252 #define CHARGER6_R05_WATCHDOG_TIMER_80_SEC 0x20
253 #define CHARGER6_R05_WATCHDOG_TIMER_160_SEC 0x30
254 #define CHARGER6_R05_TIMER_DISABLE 0x00
255 #define CHARGER6_R05_TIMER_ENABLE 0x08
256 #define CHARGER6_R05_CHG_TIMER_5_HOURS 0x00
257 #define CHARGER6_R05_CHG_TIMER_10_HOURS 0x04
258 #define CHARGER6_R05_TREG_90_C 0x00
259 #define CHARGER6_R05_TREG_110_C 0x02
260 #define CHARGER6_R05_JEITA_ISET_50 0x00
261 #define CHARGER6_R05_JEITA_ISET_20 0x01
262 
268 #define CHARGER6_R06_OVP_TSH_5500mV 0x00
269 #define CHARGER6_R06_OVP_TSH_6500mV 0x40
270 #define CHARGER6_R06_OVP_TSH_10500mV 0x80
271 #define CHARGER6_R06_OVP_TSH_14000mV 0xC0
272 #define CHARGER6_R06_BOOSTV_4850mV 0x00
273 #define CHARGER6_R06_BOOSTV_5000mV 0x10
274 #define CHARGER6_R06_BOOSTV_5150mV 0x20
275 #define CHARGER6_R06_BOOSTV_5300mV 0x30
276 #define CHARGER6_R06_VINDPM_800mV 0x08
277 #define CHARGER6_R06_VINDPM_400mV 0x04
278 #define CHARGER6_R06_VINDPM_200mV 0x02
279 #define CHARGER6_R06_VINDPM_100mV 0x01
280 
286 #define CHARGER6_R07_NOT_IN_INPUT_CURRENT_LIMIT 0x00
287 #define CHARGER6_R07_FORCE_INPUT_CURRENT_LIMIT 0x80
288 #define CHARGER6_R07_TMR2X_DISABLE 0x00
289 #define CHARGER6_R07_TMR2X_ENABLE 0x40
290 #define CHARGER6_R07_BATFET_ALLOW_Q4_TURN_ON 0x00
291 #define CHARGER6_R07_BATFET_TURN_OFF_Q4 0x20
292 #define CHARGER6_R07_JEITA_VSET_TO_4100mV 0x00
293 #define CHARGER6_R07_JEITA_VSET_TO_VREG 0x10
294 #define CHARGER6_R07_BATFET_IMMEDIATELY 0x00
295 #define CHARGER6_R07_BATFET_AFTER_10_SEC 0x08
296 #define CHARGER6_R07_BATFET_RST_DISABLE 0x00
297 #define CHARGER6_R07_BATFET_RST_ENABLE 0x04
298 #define CHARGER6_R07_VDPM_BAT_TRACK_DISABLE 0x00
299 #define CHARGER6_R07_VDPM_BAT_TRACK_VBAT_PLUS_200mV 0x01
300 #define CHARGER6_R07_VDPM_BAT_TRACK_VBAT_PLUS_250mV 0x02
301 #define CHARGER6_R07_VDPM_BAT_TRACK_VBAT_PLUS_300mV 0x03
302 
308 #define CHARGER6_R08_VBUS_BIT_MASK 0xE0
309 #define CHARGER6_R08_VBUS_STAT_NO_INPUT 0x00
310 #define CHARGER6_R08_VBUS_STAT_USB_HOST_SDP 0x20
311 #define CHARGER6_R08_VBUS_STAT_ADAPTER_2_4_A 0x40
312 #define CHARGER6_R08_VBUS_OTG 0xE0
313 #define CHARGER6_R08_CHRG_STAT_BIT_MASK 0x18
314 #define CHARGER6_R08_CHRG_STAT_NOT_CHARGING 0x00
315 #define CHARGER6_R08_CHRG_STAT_PRE_CHARGE 0x08
316 #define CHARGER6_R08_CHRG_STAT_FAST_CHARGING 0x10
317 #define CHARGER6_R08_CHRG_STAT_CHARGE_TERMINATION 0x18
318 #define CHARGER6_R08_PG_STAT_BIT_MASK 0x04
319 #define CHARGER6_R08_PG_STAT_POWER_NOT_GOOD 0x00
320 #define CHARGER6_R08_PG_STAT_POWER_GOOD 0x04
321 #define CHARGER6_R08_THERM_STAT_BIT_MASK 0x02
322 #define CHARGER6_R08_THERM_STAT_NOT_mAl 0x00
323 #define CHARGER6_R08_THERM_STAT_mAl 0x02
324 #define CHARGER6_R08_VSYS_BIT_MASK 0x01
325 #define CHARGER6_R08_VSYS_STAT_NOT 0x00
326 #define CHARGER6_R08_VSYS_STAT_VSYSM 0x01
327 
333 #define CHARGER6_R09_WATCHDOG_FAULT_BIT_MASK 0x80
334 #define CHARGER6_R09_WATCHDOG_FAULT_NORMAL 0x00
335 #define CHARGER6_R09_WATCHDOG_FAULT_TIMER_EXPIRATION 0x80
336 #define CHARGER6_R09_BOOST_FAULT_BIT_MASK 0x40
337 #define CHARGER6_R09_BOOST_FAULT_NORMAL 0x00
338 #define CHARGER6_R09_BOOST_FAULT_VBUS_OVERLOADED 0x40
339 #define CHARGER6_R09_CHRG_FAULT_BIT_MASK 0x30
340 #define CHARGER6_R09_CHRG_FAULT_NORMAL 0x00
341 #define CHARGER6_R09_CHRG_FAULT_INPUT_FAULT 0x10
342 #define CHARGER6_R09_CHRG_FAULT_THERMAL_SHUTDOWN 0x20
343 #define CHARGER6_R09_CHRG_FAULT_CHG_SAFETY_TIMER_EXP 0x30
344 #define CHARGER6_R09_BAT_FAULT_BIT_MASK 0x08
345 #define CHARGER6_R09_BAT_FAULT_NORMAL 0x00
346 #define CHARGER6_R09_BAT_FAULT_BATOVP 0x08
347 #define CHARGER6_R09_NTC_FAULT_BIT_MASK 0x07
348 #define CHARGER6_R09_NTC_FAULT_NORMAL 0x00
349 #define CHARGER6_R09_NTC_FAULT_WARM 0x02
350 #define CHARGER6_R09_NTC_FAULT_COOL 0x03
351 #define CHARGER6_R09_NTC_FAULT_COLD 0x05
352 #define CHARGER6_R09_NTC_FAULT_HOT 0x06
353 
359 #define CHARGER6_R0A_VBUS_GD_BIT_MASK 0x80
360 #define CHARGER6_R0A_VBUS_GD_NOT_VBUS 0x00
361 #define CHARGER6_R0A_VBUS_GD_VBUS_ATTACHED 0x80
362 #define CHARGER6_R0A_VBUS_GD_VINDPM_BIT_MASK 0x40
363 #define CHARGER6_R0A_VBUS_GD_NOT_IN_VINDPM 0x00
364 #define CHARGER6_R0A_VBUS_GD_IN_VINDPM 0x40
365 #define CHARGER6_R0A_VBUS_GD_IINDPM_BIT_MASK 0x20
366 #define CHARGER6_R0A_VBUS_GD_NOT_IN_IINDPM 0x00
367 #define CHARGER6_R0A_VBUS_GD_IN_IINDPM 0x20
368 #define CHARGER6_R0A_TOP_OFF_BIT_MASK 0x08
369 #define CHARGER6_R0A_TOP_OFF_TIMER_NOT_COUNTING 0x00
370 #define CHARGER6_R0A_TOP_OFF_TIMER_COUNTING 0x08
371 #define CHARGER6_R0A_ACOV_STAT_BIT_MASK 0x04
372 #define CHARGER6_R0A_ACOV_STAT_NOT_IN_ACOV 0x00
373 #define CHARGER6_R0A_ACOV_STAT_IN_ACOV 0x04
374 #define CHARGER6_R0A_VINDPM_INT_MASK_ALLOW 0x00
375 #define CHARGER6_R0A_VINDPM_INT_MASK_MASK 0x02
376 #define CHARGER6_R0A_IINDPM_INT_MASK_ALLOW 0x00
377 #define CHARGER6_R0A_IINDPM_INT_MASK_MASK 0x01
378 
384 #define CHARGER6_R0B_DEV_ID_BIT_MASK 0x78
385 #define CHARGER6_R0B_DEV_REV_BIT_MASK 0x03
386 
387 
393 #define CHARGER6_SET_DEV_ADDR 0x6B
394  // charger6_set
396 
411 #define CHARGER6_MAP_MIKROBUS( cfg, mikrobus ) \
412  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
413  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
414  cfg.ce = MIKROBUS( mikrobus, MIKROBUS_CS ); \
415  cfg.qon = MIKROBUS( mikrobus, MIKROBUS_RST ); \
416  cfg.psel = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
417  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
418  // charger6_map // charger6
421 
426 typedef struct
427 {
428  // Output pins
429 
430  digital_out_t ce;
431  digital_out_t qon;
432  digital_out_t psel;
434  // Input pins
435 
436  digital_in_t int_pin;
438  // Modules
439 
440  i2c_master_t i2c;
442  // I2C slave address
443 
444  uint8_t slave_address;
446 } charger6_t;
447 
452 typedef struct
453 {
454  pin_name_t scl;
455  pin_name_t sda;
457  pin_name_t ce;
458  pin_name_t qon;
459  pin_name_t psel;
460  pin_name_t int_pin;
462  uint32_t i2c_speed;
463  uint8_t i2c_address;
466 
471 typedef struct
472 {
473  uint8_t vbus_stat;
474  uint8_t chrg_stat;
475  uint8_t pg_stat;
476  uint8_t therm_stat;
477  uint8_t vsys_stat;
478  uint8_t watchdog_fault;
479  uint8_t boost_fault;
480  uint8_t chrg_fault;
481  uint8_t bat_fault;
482  uint8_t ntc_fault;
483  uint8_t vbus_gd;
484  uint8_t vindpm_stat;
485  uint8_t iindpm_stat;
486  uint8_t topoff_active;
487  uint8_t acov_stat;
488  uint8_t vindpm_int;
489  uint8_t iindpm_int;
490  uint8_t dev_id;
491  uint8_t dev_rev;
492 }
494 
499 typedef enum
500 {
502  CHARGER6_ERROR = -1
503 
505 
523 void charger6_cfg_setup ( charger6_cfg_t *cfg );
524 
541 err_t charger6_init ( charger6_t *ctx, charger6_cfg_t *cfg );
542 
558 err_t charger6_default_cfg ( charger6_t *ctx );
559 
577 err_t charger6_generic_write ( charger6_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
578 
596 err_t charger6_generic_read ( charger6_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
597 
613 
629 
649 void charger6_power_source_selection ( charger6_t *ctx, uint8_t pwr_sel );
650 
672 err_t charger6_set_input_current_limit ( charger6_t *ctx, uint16_t current_limit );
673 
692 err_t charger6_set_system_minimum_voltage ( charger6_t *ctx, uint16_t sys_min_voltage );
693 
713 
735 err_t charger6_set_fast_charge_current ( charger6_t *ctx, uint16_t fast_chg_current );
736 
753 
772 err_t charger6_set_precharge_current ( charger6_t *ctx, uint16_t precharge_current );
773 
792 err_t charger6_set_termination_current ( charger6_t *ctx, uint16_t termination_current );
793 
812 err_t charger6_set_charge_voltage ( charger6_t *ctx, uint16_t charge_voltage );
813 
836 err_t charger6_set_top_off_timer ( charger6_t *ctx, uint8_t top_off_time );
837 
853 uint8_t charger6_check_interrupt ( charger6_t *ctx );
854 
870 void charger6_hw_reset ( charger6_t *ctx );
871 
872 #ifdef __cplusplus
873 }
874 #endif
875 #endif // CHARGER6_H
876  // charger6
878 
879 // ------------------------------------------------------------------------ END
charger6_default_cfg
err_t charger6_default_cfg(charger6_t *ctx)
Charger 6 default configuration function.
charger6_cfg_t
Charger 6 Click configuration object.
Definition: charger6.h:451
charger6_status_t
Charger 6 Click data status structure definition.
Definition: charger6.h:470
charger6_get_status
err_t charger6_get_status(charger6_t *ctx, charger6_status_t *chg_status)
Charger 6 get status function.
charger6_set_termination_current
err_t charger6_set_termination_current(charger6_t *ctx, uint16_t termination_current)
Charger 6 set termination current function.
charger6_cfg_setup
void charger6_cfg_setup(charger6_cfg_t *cfg)
Charger 6 configuration object setup function.
charger6_check_interrupt
uint8_t charger6_check_interrupt(charger6_t *ctx)
Charger 6 check interrupt function.
charger6_power_source_selection
void charger6_power_source_selection(charger6_t *ctx, uint8_t pwr_sel)
Charger 6 power source selection function.
charger6_set_input_current_limit
err_t charger6_set_input_current_limit(charger6_t *ctx, uint16_t current_limit)
Charger 6 set input current limit function.
chg_status
charger6_status_t chg_status
Definition: main.c:36
charger6_get_fast_charge_current
uint16_t charger6_get_fast_charge_current(charger6_t *ctx)
Charger 6 get fast charge current function.
charger6_hw_reset
void charger6_hw_reset(charger6_t *ctx)
Charger 6 hw reset function.
CHARGER6_ERROR
Definition: charger6.h:501
charger6_disable_battery_charging
void charger6_disable_battery_charging(charger6_t *ctx)
Charger 6 charge disable function.
charger6_set_fast_charge_current
err_t charger6_set_fast_charge_current(charger6_t *ctx, uint16_t fast_chg_current)
Charger 6 set fast charge current function.
charger6_set_precharge_current
err_t charger6_set_precharge_current(charger6_t *ctx, uint16_t precharge_current)
Charger 6 set precharge current function.
charger6_enable_battery_charging
void charger6_enable_battery_charging(charger6_t *ctx)
Charger 6 charge enable function.
CHARGER6_OK
Definition: charger6.h:500
charger6_t
Charger 6 Click context object.
Definition: charger6.h:425
charger6_set_charge_voltage
err_t charger6_set_charge_voltage(charger6_t *ctx, uint16_t charge_voltage)
Charger 6 set charge voltage function.
charger6_return_value_t
charger6_return_value_t
Charger 6 Click return value data.
Definition: charger6.h:498
charger6_set_top_off_timer
err_t charger6_set_top_off_timer(charger6_t *ctx, uint8_t top_off_time)
Charger 6 set top OFF timer function.
charger6_generic_write
err_t charger6_generic_write(charger6_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Charger 6 I2C writing function.
charger6_set_system_minimum_voltage
err_t charger6_set_system_minimum_voltage(charger6_t *ctx, uint16_t sys_min_voltage)
Charger 6 set system minimum voltage function.
charger6_init
err_t charger6_init(charger6_t *ctx, charger6_cfg_t *cfg)
Charger 6 initialization function.
charger6_generic_read
err_t charger6_generic_read(charger6_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Charger 6 I2C reading function.