charge current control added

This commit is contained in:
Klaus K Wilting 2020-05-09 22:48:29 +02:00
parent b2254540c2
commit 62d28c54b6
3 changed files with 49 additions and 4 deletions

View File

@ -18,6 +18,22 @@
#define BAT_MIN_VOLTAGE 3100 // millivolts #define BAT_MIN_VOLTAGE 3100 // millivolts
#endif #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); typedef uint8_t (*mapFn_t)(uint16_t, uint16_t, uint16_t);
uint16_t read_voltage(void); uint16_t read_voltage(void);
@ -37,10 +53,14 @@ void AXP192_showstatus(void);
#endif // HAS_PMU #endif // HAS_PMU
#ifdef HAS_IP5306 #ifdef HAS_IP5306
void IP5306_init(void);
void printIP5306Stats(void); void printIP5306Stats(void);
uint8_t IP5306_GetPowerSource(void); uint8_t IP5306_GetPowerSource(void);
uint8_t IP5306_GetBatteryLevel(void); uint8_t IP5306_GetBatteryLevel(void);
uint8_t IP5306_GetBatteryFull(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 #endif
// The following map functions were taken from // The following map functions were taken from

View File

@ -185,8 +185,13 @@ void setup() {
digitalWrite(EXT_POWER_SW, EXT_POWER_ON); digitalWrite(EXT_POWER_SW, EXT_POWER_ON);
strcat_P(features, " VEXT"); strcat_P(features, " VEXT");
#endif #endif
#if defined HAS_PMU || defined HAS_IP5306
#ifdef HAS_PMU #ifdef HAS_PMU
AXP192_init(); AXP192_init();
#elif defined HAS_IP5306
IP5306_init();
#endif
strcat_P(features, " PMU"); strcat_P(features, " PMU");
#endif #endif

View File

@ -143,10 +143,10 @@ void AXP192_init(void) {
pmu.clearIRQ(); pmu.clearIRQ();
#endif // PMU_INT #endif // PMU_INT
// set charge current according to user setting if we have // set charging parameterss according to user settings if we have (see power.h)
#ifdef PMU_CHGC #ifdef PMU_CHARGE_CURRENT
pmu.setChargeControlCur(PMU_CHGC); pmu.setChargeControlCur(PMU_CHARGE_CURRENT);
pmu.setChargingTargetVoltage(AXP202_TARGET_VOL_4_2V); pmu.setChargingTargetVoltage(PMU_CHARGE_CUTOFF);
pmu.enableChargeing(true); pmu.enableChargeing(true);
#endif #endif
@ -299,6 +299,20 @@ uint8_t IP5306_GetBatteryLevel(void) {
return IP5306_LEDS2PCT(state); 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) { void printIP5306Stats(void) {
bool usb = IP5306_GetPowerSource(); bool usb = IP5306_GetPowerSource();
bool full = IP5306_GetBatteryFull(); bool full = IP5306_GetBatteryFull();
@ -309,4 +323,10 @@ void printIP5306Stats(void) {
full ? "CHARGED" : (usb ? "CHARGING" : "DISCHARGING"), level); 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 #endif // HAS_IP5306