charge current control added
This commit is contained in:
parent
b2254540c2
commit
62d28c54b6
@ -18,6 +18,22 @@
|
||||
#define BAT_MIN_VOLTAGE 3100 // millivolts
|
||||
#endif
|
||||
|
||||
#ifndef PMU_CHG_CUTOFF
|
||||
#ifdef HAS_PMU
|
||||
#define PMU_CHG_CUTOFF AXP202_TARGET_VOL_4_2V
|
||||
#elif defined HAS_IP5306
|
||||
#define PMU_CHG_CUTOFF 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef PMU_CHG_CURRENT
|
||||
#ifdef HAS_PMU
|
||||
#define PMU_CHG_CURRENT AXP1XX_CHARGE_CUR_450MA
|
||||
#elif defined HAS_IP5306
|
||||
#define PMU_CHG_CURRENT 2
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef uint8_t (*mapFn_t)(uint16_t, uint16_t, uint16_t);
|
||||
|
||||
uint16_t read_voltage(void);
|
||||
@ -37,10 +53,14 @@ void AXP192_showstatus(void);
|
||||
#endif // HAS_PMU
|
||||
|
||||
#ifdef HAS_IP5306
|
||||
void IP5306_init(void);
|
||||
void printIP5306Stats(void);
|
||||
uint8_t IP5306_GetPowerSource(void);
|
||||
uint8_t IP5306_GetBatteryLevel(void);
|
||||
uint8_t IP5306_GetBatteryFull(void);
|
||||
void IP5306_SetChargerEnabled(uint8_t v);
|
||||
void IP5306_SetChargeCutoffVoltage(uint8_t v);
|
||||
void IP5306_SetEndChargeCurrentDetection(uint8_t v);
|
||||
#endif
|
||||
|
||||
// The following map functions were taken from
|
||||
|
@ -185,8 +185,13 @@ void setup() {
|
||||
digitalWrite(EXT_POWER_SW, EXT_POWER_ON);
|
||||
strcat_P(features, " VEXT");
|
||||
#endif
|
||||
|
||||
#if defined HAS_PMU || defined HAS_IP5306
|
||||
#ifdef HAS_PMU
|
||||
AXP192_init();
|
||||
#elif defined HAS_IP5306
|
||||
IP5306_init();
|
||||
#endif
|
||||
strcat_P(features, " PMU");
|
||||
#endif
|
||||
|
||||
|
@ -143,10 +143,10 @@ void AXP192_init(void) {
|
||||
pmu.clearIRQ();
|
||||
#endif // PMU_INT
|
||||
|
||||
// set charge current according to user setting if we have
|
||||
#ifdef PMU_CHGC
|
||||
pmu.setChargeControlCur(PMU_CHGC);
|
||||
pmu.setChargingTargetVoltage(AXP202_TARGET_VOL_4_2V);
|
||||
// set charging parameterss according to user settings if we have (see power.h)
|
||||
#ifdef PMU_CHARGE_CURRENT
|
||||
pmu.setChargeControlCur(PMU_CHARGE_CURRENT);
|
||||
pmu.setChargingTargetVoltage(PMU_CHARGE_CUTOFF);
|
||||
pmu.enableChargeing(true);
|
||||
#endif
|
||||
|
||||
@ -299,6 +299,20 @@ uint8_t IP5306_GetBatteryLevel(void) {
|
||||
return IP5306_LEDS2PCT(state);
|
||||
}
|
||||
|
||||
void IP5306_SetChargerEnabled(uint8_t v) {
|
||||
ip5306_set_bits(IP5306_REG_SYS_0, 4, 1, v); // 0:dis,*1:en
|
||||
}
|
||||
|
||||
void IP5306_SetChargeCutoffVoltage(uint8_t v) {
|
||||
ip5306_set_bits(IP5306_REG_CHG_2, 2, 2,
|
||||
v); //*0:4.2V, 1:4.3V, 2:4.35V, 3:4.4V
|
||||
}
|
||||
|
||||
void IP5306_SetEndChargeCurrentDetection(uint8_t v) {
|
||||
ip5306_set_bits(IP5306_REG_CHG_1, 6, 2,
|
||||
v); // 0:200mA, 1:400mA, *2:500mA, 3:600mA
|
||||
}
|
||||
|
||||
void printIP5306Stats(void) {
|
||||
bool usb = IP5306_GetPowerSource();
|
||||
bool full = IP5306_GetBatteryFull();
|
||||
@ -309,4 +323,10 @@ void printIP5306Stats(void) {
|
||||
full ? "CHARGED" : (usb ? "CHARGING" : "DISCHARGING"), level);
|
||||
}
|
||||
|
||||
void IP5306_init(void) {
|
||||
IP5306_SetChargerEnabled(1);
|
||||
IP5306_SetChargeCutoffVoltage(PMU_CHG_CUTOFF);
|
||||
IP5306_SetEndChargeCurrentDetection(PMU_CHG_CURRENT);
|
||||
}
|
||||
|
||||
#endif // HAS_IP5306
|
Loading…
Reference in New Issue
Block a user