Merge pull request #435 from cyberman54/development
T-Beam V10 (AXP192 PMU) enhanced power functions
This commit is contained in:
commit
bf8027efcf
@ -10,12 +10,14 @@
|
|||||||
#define UNMASK_IRQ 0x040
|
#define UNMASK_IRQ 0x040
|
||||||
#define BME_IRQ 0x080
|
#define BME_IRQ 0x080
|
||||||
#define MATRIX_DISPLAY_IRQ 0x100
|
#define MATRIX_DISPLAY_IRQ 0x100
|
||||||
|
#define PMU_IRQ 0x200
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "cyclic.h"
|
#include "cyclic.h"
|
||||||
#include "senddata.h"
|
#include "senddata.h"
|
||||||
#include "timekeeper.h"
|
#include "timekeeper.h"
|
||||||
#include "bmesensor.h"
|
#include "bmesensor.h"
|
||||||
|
#include "power.h"
|
||||||
|
|
||||||
void irqHandler(void *pvParameters);
|
void irqHandler(void *pvParameters);
|
||||||
void mask_user_IRQ();
|
void mask_user_IRQ();
|
||||||
@ -33,5 +35,9 @@ void IRAM_ATTR MatrixDisplayIRQ();
|
|||||||
void IRAM_ATTR ButtonIRQ();
|
void IRAM_ATTR ButtonIRQ();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_PMU
|
||||||
|
void IRAM_ATTR PMUIRQ();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -11,11 +11,14 @@
|
|||||||
|
|
||||||
#ifdef HAS_PMU
|
#ifdef HAS_PMU
|
||||||
#include <axp20x.h>
|
#include <axp20x.h>
|
||||||
|
extern AXP20X_Class pmu; // Make axp instance globally availabe
|
||||||
|
void pover_event_IRQ(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void AXP192_init(void);
|
void AXP192_init(void);
|
||||||
uint16_t read_voltage(void);
|
uint16_t read_voltage(void);
|
||||||
void calibrate_voltage(void);
|
void calibrate_voltage(void);
|
||||||
uint8_t getBattLevel (void);
|
uint8_t getBattLevel(void);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -63,6 +63,12 @@ void irqHandler(void *pvParameters) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// do we have a power event?
|
||||||
|
#if (HAS_PMU)
|
||||||
|
if (InterruptStatus & PMU_IRQ)
|
||||||
|
pover_event_IRQ();
|
||||||
|
#endif
|
||||||
|
|
||||||
// is time to send the payload?
|
// is time to send the payload?
|
||||||
if (InterruptStatus & SENDCYCLE_IRQ)
|
if (InterruptStatus & SENDCYCLE_IRQ)
|
||||||
sendData();
|
sendData();
|
||||||
@ -106,6 +112,18 @@ void IRAM_ATTR ButtonIRQ() {
|
|||||||
}
|
}
|
||||||
#endif
|
#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 mask_user_IRQ() { xTaskNotify(irqHandlerTask, MASK_IRQ, eSetBits); }
|
||||||
|
|
||||||
void unmask_user_IRQ() { xTaskNotify(irqHandlerTask, UNMASK_IRQ, eSetBits); }
|
void unmask_user_IRQ() { xTaskNotify(irqHandlerTask, UNMASK_IRQ, eSetBits); }
|
@ -9,6 +9,43 @@ static const char TAG[] = __FILE__;
|
|||||||
|
|
||||||
AXP20X_Class pmu;
|
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) {
|
void AXP192_init(void) {
|
||||||
|
|
||||||
// block i2c bus access
|
// block i2c bus access
|
||||||
@ -27,25 +64,17 @@ void AXP192_init(void) {
|
|||||||
pmu.setChgLEDMode(AXP20X_LED_LOW_LEVEL);
|
pmu.setChgLEDMode(AXP20X_LED_LOW_LEVEL);
|
||||||
pmu.adc1Enable(AXP202_BATT_CUR_ADC1, 1);
|
pmu.adc1Enable(AXP202_BATT_CUR_ADC1, 1);
|
||||||
|
|
||||||
/*
|
// I2C access of AXP202X library currently is not mutexable
|
||||||
// I2C access of AXP202X library currently is not mutexable
|
// so we need to disable AXP interrupts
|
||||||
// so we need to disable AXP interrupts
|
|
||||||
|
|
||||||
|
#ifdef PMU_INT
|
||||||
#ifdef PMU_INT
|
pinMode(PMU_INT, INPUT_PULLUP);
|
||||||
pinMode(PMU_INT, INPUT_PULLUP);
|
attachInterrupt(digitalPinToInterrupt(PMU_INT), PMUIRQ, FALLING);
|
||||||
attachInterrupt(digitalPinToInterrupt(PMU_INT),
|
pmu.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ |
|
||||||
[] {
|
AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ,
|
||||||
ESP_LOGI(TAG, "Power source changed");
|
1);
|
||||||
// put your code here
|
pmu.clearIRQ();
|
||||||
},
|
#endif // PMU_INT
|
||||||
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.");
|
ESP_LOGI(TAG, "AXP192 PMU initialized.");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user