T-Beam V10 (AXP192 PMU) enhanced power functions
This commit is contained in:
parent
edc510adf2
commit
50c6ba2837
@ -10,12 +10,14 @@
|
||||
#define UNMASK_IRQ 0x040
|
||||
#define BME_IRQ 0x080
|
||||
#define MATRIX_DISPLAY_IRQ 0x100
|
||||
#define PMU_IRQ 0x200
|
||||
|
||||
#include "globals.h"
|
||||
#include "cyclic.h"
|
||||
#include "senddata.h"
|
||||
#include "timekeeper.h"
|
||||
#include "bmesensor.h"
|
||||
#include "power.h"
|
||||
|
||||
void irqHandler(void *pvParameters);
|
||||
void mask_user_IRQ();
|
||||
@ -33,5 +35,9 @@ void IRAM_ATTR MatrixDisplayIRQ();
|
||||
void IRAM_ATTR ButtonIRQ();
|
||||
#endif
|
||||
|
||||
#ifdef HAS_PMU
|
||||
void IRAM_ATTR PMUIRQ();
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -11,6 +11,8 @@
|
||||
|
||||
#ifdef HAS_PMU
|
||||
#include <axp20x.h>
|
||||
extern AXP20X_Class pmu; // Make axp instance globally availabe
|
||||
void pover_event_IRQ(void);
|
||||
#endif
|
||||
|
||||
void AXP192_init(void);
|
||||
@ -18,4 +20,5 @@ uint16_t read_voltage(void);
|
||||
void calibrate_voltage(void);
|
||||
uint8_t getBattLevel(void);
|
||||
|
||||
|
||||
#endif
|
@ -63,6 +63,12 @@ void irqHandler(void *pvParameters) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// do we have a power event?
|
||||
#if (HAS_PMU)
|
||||
if (InterruptStatus & PMU_IRQ)
|
||||
pover_event_IRQ();
|
||||
#endif
|
||||
|
||||
// is time to send the payload?
|
||||
if (InterruptStatus & SENDCYCLE_IRQ)
|
||||
sendData();
|
||||
@ -106,6 +112,18 @@ void IRAM_ATTR ButtonIRQ() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAS_PMU
|
||||
void IRAM_ATTR PMUIRQ() {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
|
||||
xTaskNotifyFromISR(irqHandlerTask, PMU_IRQ, eSetBits,
|
||||
&xHigherPriorityTaskWoken);
|
||||
|
||||
if (xHigherPriorityTaskWoken)
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
#endif
|
||||
|
||||
void mask_user_IRQ() { xTaskNotify(irqHandlerTask, MASK_IRQ, eSetBits); }
|
||||
|
||||
void unmask_user_IRQ() { xTaskNotify(irqHandlerTask, UNMASK_IRQ, eSetBits); }
|
@ -9,6 +9,43 @@ static const char TAG[] = __FILE__;
|
||||
|
||||
AXP20X_Class pmu;
|
||||
|
||||
void pover_event_IRQ(void) {
|
||||
// block i2c bus access
|
||||
if (I2C_MUTEX_LOCK()) {
|
||||
pmu.readIRQ();
|
||||
// put your power event handler code here
|
||||
|
||||
if (pmu.isVbusOverVoltageIRQ())
|
||||
ESP_LOGI(TAG, "USB voltage too high.");
|
||||
if (pmu.isVbusPlugInIRQ())
|
||||
ESP_LOGI(TAG, "USB plugged.");
|
||||
if (pmu.isVbusRemoveIRQ())
|
||||
ESP_LOGI(TAG, "USB unplugged.");
|
||||
|
||||
if (pmu.isBattPlugInIRQ())
|
||||
ESP_LOGI(TAG, "Battery is connected.");
|
||||
if (pmu.isBattRemoveIRQ())
|
||||
ESP_LOGI(TAG, "Battery was removed.");
|
||||
if (pmu.isChargingIRQ())
|
||||
ESP_LOGI(TAG, "Battery is charging.");
|
||||
if (pmu.isChargingDoneIRQ())
|
||||
ESP_LOGI(TAG, "Battery charging done.");
|
||||
if (pmu.isBattTempLowIRQ())
|
||||
ESP_LOGI(TAG, "Battery high temperature.");
|
||||
if (pmu.isBattTempHighIRQ())
|
||||
ESP_LOGI(TAG, "Battery low temperature.");
|
||||
|
||||
if (pmu.isPEKShortPressIRQ())
|
||||
ESP_LOGI(TAG, "Power Button short pressed.");
|
||||
if (pmu.isPEKLongtPressIRQ())
|
||||
ESP_LOGI(TAG, "Power Button long pressed.");
|
||||
|
||||
pmu.clearIRQ();
|
||||
I2C_MUTEX_UNLOCK(); // release i2c bus access
|
||||
} else
|
||||
ESP_LOGI(TAG, "Unknown PMU event.");
|
||||
}
|
||||
|
||||
void AXP192_init(void) {
|
||||
|
||||
// block i2c bus access
|
||||
@ -27,25 +64,17 @@ void AXP192_init(void) {
|
||||
pmu.setChgLEDMode(AXP20X_LED_LOW_LEVEL);
|
||||
pmu.adc1Enable(AXP202_BATT_CUR_ADC1, 1);
|
||||
|
||||
/*
|
||||
// I2C access of AXP202X library currently is not mutexable
|
||||
// so we need to disable AXP interrupts
|
||||
|
||||
|
||||
#ifdef PMU_INT
|
||||
pinMode(PMU_INT, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(PMU_INT),
|
||||
[] {
|
||||
ESP_LOGI(TAG, "Power source changed");
|
||||
// put your code here
|
||||
},
|
||||
FALLING);
|
||||
attachInterrupt(digitalPinToInterrupt(PMU_INT), PMUIRQ, FALLING);
|
||||
pmu.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ |
|
||||
AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ,
|
||||
1);
|
||||
pmu.clearIRQ();
|
||||
#endif // PMU_INT
|
||||
*/
|
||||
|
||||
ESP_LOGI(TAG, "AXP192 PMU initialized.");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user