charger17  2.1.0.0
charger17.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 CHARGER17_H
29 #define CHARGER17_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 CHARGER17_REG_OTG_CONFIG 0x00
70 #define CHARGER17_REG_TOP 0x01
71 #define CHARGER17_REG_FUNCTION 0x02
72 #define CHARGER17_REG_IBUS 0x03
73 #define CHARGER17_REG_VBUS 0x04
74 #define CHARGER17_REG_PRECHG 0x05
75 #define CHARGER17_REG_REGU 0x06
76 #define CHARGER17_REG_VCHG 0x07
77 #define CHARGER17_REG_ICHG 0x08
78 #define CHARGER17_REG_CHG_TIMER 0x09
79 #define CHARGER17_REG_EOC 0x0A
80 #define CHARGER17_REG_INFO 0x0B
81 #define CHARGER17_REG_JEITA 0x0C
82 #define CHARGER17_REG_PUMP_EXP 0x0D
83 #define CHARGER17_REG_DPDM_DET 0x0E
84 #define CHARGER17_REG_IC_STATUS 0x0F
85 #define CHARGER17_REG_STAT0 0x10
86 #define CHARGER17_REG_STAT1 0x11
87 #define CHARGER17_REG_STAT2 0x12
88 #define CHARGER17_REG_STAT3 0x13
89 #define CHARGER17_REG_IRQ0 0x20
90 #define CHARGER17_REG_IRQ1 0x21
91 #define CHARGER17_REG_IRQ2 0x22
92 #define CHARGER17_REG_IRQ3 0x23
93 #define CHARGER17_REG_MASK0 0x30
94 #define CHARGER17_REG_MASK1 0x31
95 #define CHARGER17_REG_MASK2 0x32
96 #define CHARGER17_REG_MASK3 0x33
97  // charger17_reg
99 
114 #define CHARGER17_OTG_CV_4p85V 0x00
115 #define CHARGER17_OTG_CV_5V 0x40
116 #define CHARGER17_OTG_CV_5p15V 0x80
117 #define CHARGER17_OTG_CV_5p3V 0xC0
118 #define CHARGER17_OTG_CV_MASK 0xC0
119 #define CHARGER17_OTG_LBP_2p8V 0x00
120 #define CHARGER17_OTG_LBP_2p5V 0x02
121 #define CHARGER17_OTG_LBP_MASK 0x02
122 #define CHARGER17_OTG_CC_0p5A 0x00
123 #define CHARGER17_OTG_CC_1p2A 0x01
124 #define CHARGER17_OTG_CC_MASK 0x01
125 
130 #define CHARGER17_TOP_QON_RST_EN 0x80
131 #define CHARGER17_TOP_STAT_EN 0x40
132 #define CHARGER17_TOP_DIS_I2C_TO 0x08
133 #define CHARGER17_TOP_WDT_CNT_RST 0x04
134 #define CHARGER17_TOP_WDT_DISABLE 0x00
135 #define CHARGER17_TOP_WDT_40S 0x01
136 #define CHARGER17_TOP_WDT_80S 0x02
137 #define CHARGER17_TOP_WDT_160S 0x03
138 #define CHARGER17_TOP_WDT_MASK 0x03
139 
144 #define CHARGER17_FUNCTION_BATFET_DIS 0x80
145 #define CHARGER17_FUNCTION_BATFET_DIS_DLY_12S 0x40
146 #define CHARGER17_FUNCTION_HZ 0x20
147 #define CHARGER17_FUNCTION_BUCK_PFM_DIS 0x08
148 #define CHARGER17_FUNCTION_UUG_FULLON 0x04
149 #define CHARGER17_FUNCTION_OTG_EN 0x02
150 #define CHARGER17_FUNCTION_CHG_EN 0x01
151 
156 #define CHARGER17_IBUS_AICC_EN 0x80
157 #define CHARGER17_IBUS_AUTO_AICR 0x40
158 #define CHARGER17_IBUS_IAICR(x) ( ( uint8_t ) ( x / 50 ) & 0x3F ) // valid values 50mA to 3200mA
159 
164 #define CHARGER17_VBUS_VAC_OVP_5p8V 0x00
165 #define CHARGER17_VBUS_VAC_OVP_6p5V 0x40
166 #define CHARGER17_VBUS_VAC_OVP_10p9V 0x80
167 #define CHARGER17_VBUS_VAC_OVP_14V 0xC0
168 #define CHARGER17_VBUS_VAC_OVP_MASK 0xC0
169 #define CHARGER17_VBUS_VMIVR_BAT_TRACK_4300mV 0x00
170 #define CHARGER17_VBUS_VMIVR_BAT_TRACK_VBAT_200 0x10
171 #define CHARGER17_VBUS_VMIVR_BAT_TRACK_VBAT_250 0x20
172 #define CHARGER17_VBUS_VMIVR_BAT_TRACK_VBAT_350 0x30
173 #define CHARGER17_VBUS_VMIVR_BAT_TRACK_MASK 0x30
174 #define CHARGER17_VBUS_VMIVR(x) ( ( uint8_t ) ( ( x - 3900 ) / 100 ) & 0x0F ) // valid values 3900mV to 5400mV
175 
180 #define CHARGER17_PRECHG_V(x) ( ( ( uint8_t ) ( ( x - 2700 ) / 100 ) & 0x07 ) << 4 ) // valid values 2700mV to 3400mV
181 #define CHARGER17_PRECHG_I(x) ( ( uint8_t ) ( ( x - 50 ) / 50 ) & 0x0F ) // valid values 50mA to 800mA
182 
187 #define CHARGER17_REGU_THREG_100_DEGC 0x00
188 #define CHARGER17_REGU_THREG_120_DEGC 0x40
189 #define CHARGER17_REGU_THREG_MASK 0x40
190 #define CHARGER17_REGU_VSYS_MIN(x) ( ( uint8_t ) ( ( x - 2600 ) / 100 ) & 0x0F ) // valid values 2600mV to 4100mV
191 
196 #define CHARGER17_VCHG_VPRE_CHG_100mV 0x00
197 #define CHARGER17_VCHG_VPRE_CHG_200mV 0x80
198 #define CHARGER17_VCHG_VPRE_CHG_MASK 0x80
199 #define CHARGER17_VCHG_VBAT_REG(x) ( ( uint8_t ) ( ( x - 3900 ) / 10 ) & 0x7F ) // valid values 3900mV to 4700mV
200 
205 #define CHARGER17_ICHG_REG(x) ( ( uint8_t ) ( x / 50 ) & 0x3F ) // valid values 0mA to 3150mV
206 
211 #define CHARGER17_CHG_TIMER_CHG_SAFE_TMR_EN 0x80
212 #define CHARGER17_CHG_TIMER_CHG_SAFE_TMR_2XT 0x40
213 #define CHARGER17_CHG_TIMER_CHG_SAFE_TMR_5HR 0x00
214 #define CHARGER17_CHG_TIMER_CHG_SAFE_TMR_10HR 0x10
215 #define CHARGER17_CHG_TIMER_CHG_SAFE_TMR_15HR 0x20
216 #define CHARGER17_CHG_TIMER_CHG_SAFE_TMR_20HR 0x30
217 #define CHARGER17_CHG_TIMER_MASK 0x30
218 
223 #define CHARGER17_EOC_IEOC_CHG(x) ( ( ( uint8_t ) ( ( x - 50 ) / 50 ) & 0x0F ) << 4 ) // valid values 50mA to 800mA
224 #define CHARGER17_EOC_BG_CHG_TMR_0MIN 0x00
225 #define CHARGER17_EOC_BG_CHG_TMR_15MIN 0x04
226 #define CHARGER17_EOC_BG_CHG_TMR_30MIN 0x08
227 #define CHARGER17_EOC_BG_CHG_TMR_45MIN 0x0C
228 #define CHARGER17_EOC_BG_CHG_TMR_MASK 0x0C
229 #define CHARGER17_EOC_TE 0x02
230 #define CHARGER17_EOC_RST 0x01
231 
236 #define CHARGER17_INFO_REG_RST 0x80
237 #define CHARGER17_INFO_DEVICE_ID 0x68
238 #define CHARGER17_INFO_DEVICE_ID_MASK 0x78
239 #define CHARGER17_INFO_DEVICE_RE_MASK 0x07
240 
245 #define CHARGER17_JEITA_EN 0x80
246 #define CHARGER17_JEITA_COLD 0x40
247 #define CHARGER17_JEITA_COOL_ISET_50PCT 0x00
248 #define CHARGER17_JEITA_COOL_ISET_25PCT 0x20
249 #define CHARGER17_JEITA_COOL_ISET_MASK 0x20
250 #define CHARGER17_JEITA_COOL_VSET_4p1V 0x00
251 #define CHARGER17_JEITA_COOL_VSET_VBAT_REG 0x10
252 #define CHARGER17_JEITA_COOL_VSET_MASK 0x10
253 #define CHARGER17_JEITA_WARM_ISET_50PCT 0x00
254 #define CHARGER17_JEITA_WARM_ISET_ICHG_REG 0x08
255 #define CHARGER17_JEITA_WARM_ISET_MASK 0x08
256 #define CHARGER17_JEITA_WARM_VSET_4p1V 0x00
257 #define CHARGER17_JEITA_WARM_VSET_VBAT_REG 0x04
258 #define CHARGER17_JEITA_WARM_VSET_MASK 0x04
259 #define CHARGER17_JEITA_HOT 0x02
260 
265 #define CHARGER17_PUMP_EXP_PE_EN 0x80
266 #define CHARGER17_PUMP_EXP_PE_SEL_PE10 0x00
267 #define CHARGER17_PUMP_EXP_PE_SEL_PE20 0x40
268 #define CHARGER17_PUMP_EXP_PE_SEL_MASK 0x40
269 #define CHARGER17_PUMP_EXP_PE10_INC_VDOWN 0x00
270 #define CHARGER17_PUMP_EXP_PE10_INC_VUP 0x20
271 #define CHARGER17_PUMP_EXP_PE10_INC_MASK 0x20
272 #define CHARGER17_PUMP_EXP_PE_EN 0x80
273 #define CHARGER17_PUMP_EXP_PE_EN 0x80
274 #define CHARGER17_PUMP_EXP_PE20_CODE(x) ( ( uint8_t ) ( ( ( float ) x - 5.5 ) / 0.5 ) & 0x1F ) // valid values 5.5V to 20V
275 #define CHARGER17_PUMP_EXP_PE20_CODE_SELF_TEST 0x1E
276 #define CHARGER17_PUMP_EXP_PE20_CODE_DIS_DROP 0x1F
277 
282 #define CHARGER17_DPDM_DET_BC12_EN 0x80
283 #define CHARGER17_DPDM_DET_DCDT_SEL_DIS 0x00
284 #define CHARGER17_DPDM_DET_DCDT_SEL_300mS 0x20
285 #define CHARGER17_DPDM_DET_DCDT_SEL_600mS 0x40
286 #define CHARGER17_DPDM_DET_DCDT_SEL_WAIT_DATA 0x60
287 #define CHARGER17_DPDM_DET_DCDT_SEL_MASK 0x60
288 #define CHARGER17_DPDM_DET_SPEC_TA_EN 0x10
289 #define CHARGER17_DPDM_DET_DCP_DP_OPT 0x01
290 
295 #define CHARGER17_PORT_STAT_VBUS_DEV_1 0x80
296 #define CHARGER17_PORT_STAT_VBUS_DEV_2 0x90
297 #define CHARGER17_PORT_STAT_VBUS_DEV_3 0xA0
298 #define CHARGER17_PORT_STAT_VBUS_DEV_4 0xB0
299 #define CHARGER17_PORT_STAT_VBUS_UNKNOWN 0xC0
300 #define CHARGER17_PORT_STAT_VBUS_SDP 0xD0
301 #define CHARGER17_PORT_STAT_VBUS_CDP 0xE0
302 #define CHARGER17_PORT_STAT_VBUS_DCP 0xF0
303 #define CHARGER17_PORT_STAT_BIT_MASK 0xF0
304 #define CHARGER17_IC_STAT_HZ_SLEEP 0x00
305 #define CHARGER17_IC_STAT_VBUS_READY 0x01
306 #define CHARGER17_IC_STAT_TRICKLE_CHG 0x02
307 #define CHARGER17_IC_STAT_PRE_CHG 0x03
308 #define CHARGER17_IC_STAT_FAST_CHG 0x04
309 #define CHARGER17_IC_STAT_IEOC_CHG 0x05
310 #define CHARGER17_IC_STAT_BACK_GROUND_CHG 0x06
311 #define CHARGER17_IC_STAT_CHG_DONE 0x07
312 #define CHARGER17_IC_STAT_CHG_FAULT 0x08
313 #define CHARGER17_IC_STAT_OTG 0x0F
314 #define CHARGER17_IC_STAT_BIT_MASK 0x0F
315 
320 #define CHARGER17_STAT0_VBUS_GD 0x80
321 #define CHARGER17_STAT0_CHG_RDY 0x40
322 #define CHARGER17_STAT0_IEOC 0x20
323 #define CHARGER17_STAT0_BG_CHG 0x10
324 #define CHARGER17_STAT0_CHG_DONE 0x08
325 #define CHARGER17_STAT0_BC12_DONE 0x01
326 
331 #define CHARGER17_STAT1_CHG_MIVR 0x80
332 #define CHARGER17_STAT1_CHG_AICR 0x40
333 #define CHARGER17_STAT1_CHG_THREG 0x20
334 #define CHARGER17_STAT1_CHG_BUSUV 0x10
335 #define CHARGER17_STAT1_CHG_TOUT 0x08
336 #define CHARGER17_STAT1_CHG_SYSOV 0x04
337 #define CHARGER17_STAT1_CHG_BATOV 0x02
338 
343 #define CHARGER17_STAT2_JEITA_HOT 0x80
344 #define CHARGER17_STAT2_JEITA_WARM 0x40
345 #define CHARGER17_STAT2_JEITA_COOL 0x20
346 #define CHARGER17_STAT2_JEITA_COLD 0x10
347 #define CHARGER17_STAT2_SYS_MIN 0x02
348 
353 #define CHARGER17_STAT3_OTP 0x80
354 #define CHARGER17_STAT3_VAC_OV 0x40
355 #define CHARGER17_STAT3_WDT 0x20
356 #define CHARGER17_STAT3_OTG_CC 0x04
357 
363 #define CHARGER17_DEVICE_ADDRESS 0x53
364  // charger17_set
366 
381 #define CHARGER17_MAP_MIKROBUS( cfg, mikrobus ) \
382  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
383  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
384  cfg.ce = MIKROBUS( mikrobus, MIKROBUS_CS ); \
385  cfg.qon = MIKROBUS( mikrobus, MIKROBUS_RST ); \
386  cfg.psel = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
387  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
388  // charger17_map // charger17
391 
396 typedef struct
397 {
398  // Output pins
399  digital_out_t ce;
400  digital_out_t qon;
401  digital_out_t psel;
403  // Input pins
404  digital_in_t int_pin;
406  // Modules
407  i2c_master_t i2c;
409  // I2C slave address
410  uint8_t slave_address;
412 } charger17_t;
413 
418 typedef struct
419 {
420  pin_name_t scl;
421  pin_name_t sda;
423  pin_name_t ce;
424  pin_name_t qon;
425  pin_name_t psel;
426  pin_name_t int_pin;
428  uint32_t i2c_speed;
429  uint8_t i2c_address;
432 
437 typedef enum
438 {
440  CHARGER17_ERROR = -1
441 
443 
460 
475 
489 
504 err_t charger17_generic_write ( charger17_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
505 
520 err_t charger17_generic_read ( charger17_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
521 
534 err_t charger17_write_register ( charger17_t *ctx, uint8_t reg, uint8_t data_in );
535 
548 err_t charger17_read_register ( charger17_t *ctx, uint8_t reg, uint8_t *data_out );
549 
561 
571 void charger17_set_qon_pin ( charger17_t *ctx, uint8_t state );
572 
582 
592 
602 
612 
622 
623 #ifdef __cplusplus
624 }
625 #endif
626 #endif // CHARGER17_H
627  // charger17
629 
630 // ------------------------------------------------------------------------ END
charger17_check_communication
err_t charger17_check_communication(charger17_t *ctx)
Charger 17 check communication function.
charger17_t::int_pin
digital_in_t int_pin
Definition: charger17.h:404
charger17_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: charger17.h:428
charger17_get_int_pin
uint8_t charger17_get_int_pin(charger17_t *ctx)
Charger 17 get int pin function.
charger17_return_value_t
charger17_return_value_t
Charger 17 Click return value data.
Definition: charger17.h:438
charger17_t::i2c
i2c_master_t i2c
Definition: charger17.h:407
charger17_t::ce
digital_out_t ce
Definition: charger17.h:399
charger17_cfg_t::psel
pin_name_t psel
Definition: charger17.h:425
charger17_default_cfg
err_t charger17_default_cfg(charger17_t *ctx)
Charger 17 default configuration function.
CHARGER17_OK
@ CHARGER17_OK
Definition: charger17.h:439
charger17_enable_charging
void charger17_enable_charging(charger17_t *ctx)
Charger 17 enable charging function.
charger17_cfg_t::sda
pin_name_t sda
Definition: charger17.h:421
charger17_set_qon_pin
void charger17_set_qon_pin(charger17_t *ctx, uint8_t state)
Charger 17 set qon pin function.
charger17_generic_write
err_t charger17_generic_write(charger17_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Charger 17 I2C writing function.
charger17_read_register
err_t charger17_read_register(charger17_t *ctx, uint8_t reg, uint8_t *data_out)
Charger 17 read register function.
charger17_t::slave_address
uint8_t slave_address
Definition: charger17.h:410
charger17_set_psel_500mA
void charger17_set_psel_500mA(charger17_t *ctx)
Charger 17 set psel 500mA function.
charger17_init
err_t charger17_init(charger17_t *ctx, charger17_cfg_t *cfg)
Charger 17 initialization function.
charger17_t
Charger 17 Click context object.
Definition: charger17.h:397
charger17_set_psel_2400mA
void charger17_set_psel_2400mA(charger17_t *ctx)
Charger 17 set psel 2400mA function.
charger17_cfg_t::qon
pin_name_t qon
Definition: charger17.h:424
charger17_disable_charging
void charger17_disable_charging(charger17_t *ctx)
Charger 17 disable charging function.
charger17_cfg_t::scl
pin_name_t scl
Definition: charger17.h:420
CHARGER17_ERROR
@ CHARGER17_ERROR
Definition: charger17.h:440
charger17_cfg_t::ce
pin_name_t ce
Definition: charger17.h:423
charger17_t::psel
digital_out_t psel
Definition: charger17.h:401
charger17_write_register
err_t charger17_write_register(charger17_t *ctx, uint8_t reg, uint8_t data_in)
Charger 17 write register function.
charger17_cfg_t::i2c_address
uint8_t i2c_address
Definition: charger17.h:429
charger17_t::qon
digital_out_t qon
Definition: charger17.h:400
charger17_cfg_t::int_pin
pin_name_t int_pin
Definition: charger17.h:426
charger17_generic_read
err_t charger17_generic_read(charger17_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Charger 17 I2C reading function.
charger17_cfg_t
Charger 17 Click configuration object.
Definition: charger17.h:419
charger17_cfg_setup
void charger17_cfg_setup(charger17_cfg_t *cfg)
Charger 17 configuration object setup function.