Skip to content

Commit

Permalink
Merge pull request #436 from cyberman54/development
Browse files Browse the repository at this point in the history
T-BEAM v1.0 ON/OFF button function added
  • Loading branch information
cyberman54 authored Sep 9, 2019
2 parents bf8027e + ff6fce0 commit 130f1cd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
3 changes: 1 addition & 2 deletions include/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@

#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);
uint16_t read_voltage(void);
void calibrate_voltage(void);
uint8_t getBattLevel(void);


#endif
40 changes: 32 additions & 8 deletions src/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,45 @@ 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
} else
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
Expand All @@ -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
Expand Down

0 comments on commit 130f1cd

Please sign in to comment.