T-BEAM v1.0 ON/OFF button function added

This commit is contained in:
Verkehrsrot 2019-09-09 23:00:06 +02:00
parent 50c6ba2837
commit ff6fce0a1d
2 changed files with 33 additions and 10 deletions

View File

@ -11,8 +11,8 @@
#ifdef HAS_PMU
#include <axp20x.h>
extern AXP20X_Class pmu; // Make axp instance globally availabe
void pover_event_IRQ(void);
void AXP192_power(bool on);
#endif
void AXP192_init(void);
@ -20,5 +20,4 @@ uint16_t read_voltage(void);
void calibrate_voltage(void);
uint8_t getBattLevel(void);
#endif

View File

@ -35,10 +35,19 @@ void pover_event_IRQ(void) {
if (pmu.isBattTempHighIRQ())
ESP_LOGI(TAG, "Battery low temperature.");
if (pmu.isPEKShortPressIRQ())
// wake up
if (pmu.isPEKShortPressIRQ()) {
ESP_LOGI(TAG, "Power Button short pressed.");
if (pmu.isPEKLongtPressIRQ())
AXP192_power(true);
}
// enter sleep mode
if (pmu.isPEKLongtPressIRQ()) {
ESP_LOGI(TAG, "Power Button long pressed.");
AXP192_power(false);
delay(20);
esp_sleep_enable_ext1_wakeup(GPIO_SEL_38, ESP_EXT1_WAKEUP_ALL_LOW);
esp_deep_sleep_start();
}
pmu.clearIRQ();
I2C_MUTEX_UNLOCK(); // release i2c bus access
@ -46,6 +55,25 @@ void pover_event_IRQ(void) {
ESP_LOGI(TAG, "Unknown PMU event.");
}
void AXP192_power(bool on) {
if (on) {
pmu.setPowerOutPut(AXP192_LDO2, AXP202_ON);
pmu.setPowerOutPut(AXP192_LDO3, AXP202_ON);
pmu.setPowerOutPut(AXP192_DCDC2, AXP202_ON);
pmu.setPowerOutPut(AXP192_EXTEN, AXP202_ON);
pmu.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
pmu.setChgLEDMode(AXP20X_LED_LOW_LEVEL);
} else {
pmu.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
pmu.setPowerOutPut(AXP192_EXTEN, AXP202_OFF);
pmu.setPowerOutPut(AXP192_DCDC2, AXP202_OFF);
pmu.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
pmu.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
pmu.setChgLEDMode(AXP20X_LED_OFF);
}
}
void AXP192_init(void) {
// block i2c bus access
@ -55,14 +83,10 @@ void AXP192_init(void) {
ESP_LOGI(TAG, "AXP192 PMU initialization failed");
else {
pmu.setPowerOutPut(AXP192_LDO2, AXP202_ON);
pmu.setPowerOutPut(AXP192_LDO3, AXP202_ON);
pmu.setPowerOutPut(AXP192_DCDC2, AXP202_ON);
pmu.setPowerOutPut(AXP192_EXTEN, AXP202_ON);
pmu.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
// switch power on
pmu.setDCDC1Voltage(3300);
pmu.setChgLEDMode(AXP20X_LED_LOW_LEVEL);
pmu.adc1Enable(AXP202_BATT_CUR_ADC1, 1);
AXP192_power(true);
// I2C access of AXP202X library currently is not mutexable
// so we need to disable AXP interrupts