ttwrplus: implemented PMU interrupts handling

TG-553
pull/193/head
Niccolò Izzo 2023-08-31 00:10:28 +02:00 zatwierdzone przez Silvano Seva
rodzic 2dabacebd8
commit ad1beffcf3
5 zmienionych plików z 79 dodań i 4 usunięć

Wyświetl plik

@ -40,6 +40,9 @@
#endif
#include <voicePrompts.h>
#if defined(PLATFORM_TTWRPLUS)
#include <pmu.h>
#endif
/* Mutex for concurrent access to RTX state variable */
pthread_mutex_t rtx_mutex;
@ -139,6 +142,10 @@ void *main_thread(void *arg)
{
time = getTick();
#if defined(PLATFORM_TTWRPLUS)
pmu_handleIRQ();
#endif
// Check if power off is requested
pthread_mutex_lock(&state_mutex);
if(platform_pwrButtonStatus() == false)

Wyświetl plik

@ -22,6 +22,7 @@
#include <interfaces/keyboard.h>
#include <interfaces/platform.h>
#include <hwconfig.h>
#include <pmu.h>
static const struct device *const buttons_dev = DEVICE_DT_GET(DT_NODELABEL(buttons));

Wyświetl plik

@ -17,8 +17,10 @@
* along with this program; if not, see <http://www.gnu.org/licenses/> *
***************************************************************************/
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/i2c.h>
#include <interfaces/delays.h>
#include <interfaces/keyboard.h>
#include <hwconfig.h>
#include "pmu.h"
@ -33,9 +35,12 @@
#error "Please set the correct I2C device"
#endif
#define PMU_IRQ_NODE DT_ALIAS(pmu_irq)
static const struct device *const i2c_dev = DEVICE_DT_GET(I2C_DEV_NODE);
static const struct gpio_dt_spec pmu_irq = GPIO_DT_SPEC_GET(PMU_IRQ_NODE, gpios);
static XPowersPMU PMU;
static bool pwrOnPressed = false;
static int pmu_registerReadByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data,
@ -73,6 +78,18 @@ void pmu_init()
printk("I2C config failed\n");
}
// Configure IRQ gpio
if(gpio_is_ready_dt(&pmu_irq) == false)
{
printk("PMU IRQ gpio is not ready\n");
}
int ret = gpio_pin_configure_dt(&pmu_irq, GPIO_INPUT);
if (ret != 0)
{
printk("Failed to configure PMU IRQ gpio\n");
}
bool result = PMU.begin(AXP2101_SLAVE_ADDRESS, pmu_registerReadByte,
pmu_registerWriteByte);
if (result == false)
@ -249,10 +266,11 @@ void pmu_init()
PMU.clearIrqStatus();
// Enable the required interrupt function
PMU.enableIRQ(
XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_BAT_REMOVE_IRQ | //BATTERY
XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_VBUS_REMOVE_IRQ | //VBUS
XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_LONG_IRQ | //POWER KEY
XPOWERS_AXP2101_BAT_CHG_DONE_IRQ | XPOWERS_AXP2101_BAT_CHG_START_IRQ //CHARGE
XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_BAT_REMOVE_IRQ | // BATTERY
XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_VBUS_REMOVE_IRQ | // VBUS
XPOWERS_AXP2101_PKEY_POSITIVE_IRQ | XPOWERS_AXP2101_PKEY_NEGATIVE_IRQ | // POWER KEY ON/OFF
XPOWERS_AXP2101_PKEY_LONG_IRQ | // POWER KEY LONG PRESS
XPOWERS_AXP2101_BAT_CHG_DONE_IRQ | XPOWERS_AXP2101_BAT_CHG_START_IRQ // CHARGE
);
// Set the precharge charging current
@ -315,3 +333,44 @@ void pmu_setGPSPower(bool enable)
else
PMU.disableALDO4();
}
void pmu_handleIRQ()
{
// Check if we got some interrupts
if(gpio_pin_get_dt(&pmu_irq) == 0)
return;
uint32_t irqStatus = PMU.getIrqStatus();
PMU.clearIrqStatus();
// Power on key rising edge
if((irqStatus & XPOWERS_AXP2101_PKEY_POSITIVE_IRQ) != 0)
pwrOnPressed = true;
// Power on key falling edge
if((irqStatus & XPOWERS_AXP2101_PKEY_NEGATIVE_IRQ) != 0)
pwrOnPressed = false;
// Power key long press
if ((irqStatus & XPOWERS_AXP2101_PKEY_LONG_IRQ) != 0)
{
// TODO Shutdown radio, set platform_pwrButtonStatus to false
PMU.shutdown();
}
// Charger start IRQ
if((irqStatus & XPOWERS_AXP2101_BAT_CHG_START_IRQ) != 0)
{
if(PMU.isBatteryConnect())
PMU.setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG);
}
// Battery remove IRQ
if((irqStatus & XPOWERS_AXP2101_BAT_REMOVE_IRQ) != 0)
PMU.setChargingLedMode(XPOWERS_CHG_LED_BLINK_1HZ);
}
bool pmu_pwrOnBtnStatus()
{
return pwrOnPressed;
}

Wyświetl plik

@ -28,6 +28,8 @@ void pmu_init();
uint16_t pmu_getVbat();
void pmu_setBasebandPower(bool enable);
void pmu_setGPSPower(bool enable);
void pmu_handleIRQ();
bool pmu_pwrOnBtnStatus();
#ifdef __cplusplus
}

Wyświetl plik

@ -22,6 +22,7 @@
radio-pwr = &radio_pwr;
radio-pdn = &radio_pdn;
radio-ptt = &radio_ptt;
pmu-irq = &pmu_irq;
qdec0 = &pcnt;
led0 = &ws2812c;
};
@ -51,6 +52,11 @@
gpios = <&gpio1 9 GPIO_ACTIVE_HIGH>;
label = "SA868S PTT on IO41";
};
pmu_irq: pmu_irq {
gpios = <&gpio0 4 GPIO_ACTIVE_LOW>;
label = "PMU IRQ Pin";
};
};
buttons: buttons {