experiment with axp192 power management

1.2-legacy
geeksville 2020-02-16 16:03:16 -08:00
rodzic 0453ffbfd7
commit f34c29a323
2 zmienionych plików z 42 dodań i 6 usunięć

Wyświetl plik

@ -204,7 +204,7 @@ void MeshService::handleToRadio(std::string s)
void MeshService::sendToMesh(MeshPacket *p)
{
nodeDB.updateFrom(*p); // update our local DB for this packet
nodeDB.updateFrom(*p); // update our local DB for this packet (because phone might have sent position packets etc...)
assert(radio.send(p) == pdTRUE);
}

Wyświetl plik

@ -269,6 +269,25 @@ void axp192Init()
DEBUG_MSG("DCDC3: %s\n", axp.isDCDC3Enable() ? "ENABLE" : "DISABLE");
DEBUG_MSG("Exten: %s\n", axp.isExtenEnable() ? "ENABLE" : "DISABLE");
#if 0
// cribbing from https://github.com/m5stack/M5StickC/blob/master/src/AXP192.cpp to fix charger to be more like 300ms.
// I finally found an english datasheet. Will look at this later - but suffice it to say the default code from TTGO has 'issues'
axp.adc1Enable(0xff, 1); // turn on all adcs
uint8_t val = 0xc2;
axp._writeByte(0x33, 1, &val); // Bat charge voltage to 4.2, Current 280mA
val = 0b11110010;
// Set ADC sample rate to 200hz
// axp._writeByte(0x84, 1, &val);
// Not connected
//val = 0xfc;
//axp._writeByte(AXP202_VHTF_CHGSET, 1, &val); // Set temperature protection
//not used
//val = 0x46;
//axp._writeByte(AXP202_OFF_CTL, 1, &val); // enable bat detection
#endif
axp.debugCharging();
#ifdef PMU_IRQ
@ -393,7 +412,6 @@ void setup()
enableModemSleep();
}
uint32_t ledBlinker()
{
static bool ledOn;
@ -410,12 +428,29 @@ uint32_t ledBlinker()
axp.setChgLEDMode(ledOn ? AXP20X_LED_LOW_LEVEL : AXP20X_LED_OFF);
}
// have a very sparse duty cycle of LED being on
return ledOn ? 2 : 1000;
// have a very sparse duty cycle of LED being on, unless charging, then blink 0.5Hz square wave rate to indicate that
return isCharging ? 1000 : (ledOn ? 2 : 1000);
}
Periodic ledPeriodic(ledBlinker);
#if 0
// Turn off for now
uint32_t axpReads()
{
axp.debugCharging();
DEBUG_MSG("vbus current %f\n", axp.getVbusCurrent());
DEBUG_MSG("charge current %f\n", axp.getBattChargeCurrent());
DEBUG_MSG("bat voltage %f\n", axp.getBattVoltage());
DEBUG_MSG("batt pct %d\n", axp.getBattPercentage());
return 30 * 1000;
}
Periodic axpDebugOutput(axpReads);
#endif
void loop()
{
uint32_t msecstosleep = 1000 * 30; // How long can we sleep before we again need to service the main loop?
@ -424,9 +459,9 @@ void loop()
msecstosleep = min(screen_loop(), msecstosleep);
service.loop();
ledPeriodic.loop();
// axpDebugOutput.loop();
loopBLE();
#ifdef T_BEAM_V10
if (axp192_found)
{
@ -487,7 +522,8 @@ void loop()
#ifdef MINWAKE_MSECS
// Don't deepsleep if we have USB power or if the user as pressed a button recently
if (millis() - lastPressMs > MINWAKE_MSECS && !isUSBPowered)
// !isUSBPowered <- doesn't work yet because the axp192 isn't letting the battery fully charge when we are awake - FIXME
if (millis() - lastPressMs > MINWAKE_MSECS)
{
sleep();
}