ttwrplus: implemented the platform_pwrButtonStatus() function.
The platform_pwrButtonStatus() function returns false (shutdown) in case of a long press of the power button.
This commit is contained in:
parent
21895ae304
commit
6f567cc38d
|
|
@ -113,7 +113,7 @@ keyboard_t kbd_getKeys()
|
||||||
* The power key is only connected to the PMU and its state is detected through
|
* The power key is only connected to the PMU and its state is detected through
|
||||||
* the PMU interrupts.
|
* the PMU interrupts.
|
||||||
*/
|
*/
|
||||||
if (pmu_pwrOnBtnStatus())
|
if (pmu_pwrBtnStatus() == 1)
|
||||||
{
|
{
|
||||||
// Update the volume only once when key is pressed
|
// Update the volume only once when key is pressed
|
||||||
if (!(keys & KEY_VOLUP) && volume_level < 246)
|
if (!(keys & KEY_VOLUP) && volume_level < 246)
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,7 @@ void platform_init()
|
||||||
|
|
||||||
void platform_terminate()
|
void platform_terminate()
|
||||||
{
|
{
|
||||||
|
pmu_terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t platform_getVbat()
|
uint16_t platform_getVbat()
|
||||||
|
|
@ -153,6 +154,11 @@ bool platform_getPttStatus()
|
||||||
|
|
||||||
bool platform_pwrButtonStatus()
|
bool platform_pwrButtonStatus()
|
||||||
{
|
{
|
||||||
|
// Long press of the power on button triggers a shutdown
|
||||||
|
uint8_t btnStatus = pmu_pwrBtnStatus();
|
||||||
|
if(btnStatus == 2)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@
|
||||||
static const struct device *const i2c_dev = DEVICE_DT_GET(I2C_DEV_NODE);
|
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 const struct gpio_dt_spec pmu_irq = GPIO_DT_SPEC_GET(PMU_IRQ_NODE, gpios);
|
||||||
static XPowersPMU PMU;
|
static XPowersPMU PMU;
|
||||||
static bool pwrOnPressed = false;
|
static uint8_t pwrOnPressed = 0;
|
||||||
|
|
||||||
|
|
||||||
static int pmu_registerReadByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data,
|
static int pmu_registerReadByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data,
|
||||||
|
|
@ -313,6 +313,13 @@ void pmu_init()
|
||||||
printk("Setting Charge Target Voltage : %d\n", tableVoltage[val]);
|
printk("Setting Charge Target Voltage : %d\n", tableVoltage[val]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pmu_terminate()
|
||||||
|
{
|
||||||
|
PMU.disableDC3(); // Turn off baseband power
|
||||||
|
PMU.disableALDO4(); // Turn off GPS power
|
||||||
|
PMU.shutdown(); // General shutdown
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t pmu_getVbat()
|
uint16_t pmu_getVbat()
|
||||||
{
|
{
|
||||||
return PMU.isBatteryConnect() ? PMU.getBattVoltage() : 0;
|
return PMU.isBatteryConnect() ? PMU.getBattVoltage() : 0;
|
||||||
|
|
@ -345,18 +352,15 @@ void pmu_handleIRQ()
|
||||||
|
|
||||||
// Power on key rising edge
|
// Power on key rising edge
|
||||||
if((irqStatus & XPOWERS_AXP2101_PKEY_POSITIVE_IRQ) != 0)
|
if((irqStatus & XPOWERS_AXP2101_PKEY_POSITIVE_IRQ) != 0)
|
||||||
pwrOnPressed = false;
|
pwrOnPressed = 0;
|
||||||
|
|
||||||
// Power on key falling edge
|
// Power on key falling edge
|
||||||
if((irqStatus & XPOWERS_AXP2101_PKEY_NEGATIVE_IRQ) != 0)
|
if((irqStatus & XPOWERS_AXP2101_PKEY_NEGATIVE_IRQ) != 0)
|
||||||
pwrOnPressed = true;
|
pwrOnPressed = 1;
|
||||||
|
|
||||||
// Power key long press
|
// Power key long press
|
||||||
if ((irqStatus & XPOWERS_AXP2101_PKEY_LONG_IRQ) != 0)
|
if ((irqStatus & XPOWERS_AXP2101_PKEY_LONG_IRQ) != 0)
|
||||||
{
|
pwrOnPressed = 2;
|
||||||
// TODO Shutdown radio, set platform_pwrButtonStatus to false
|
|
||||||
PMU.shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Charger start IRQ
|
// Charger start IRQ
|
||||||
if((irqStatus & XPOWERS_AXP2101_BAT_CHG_START_IRQ) != 0)
|
if((irqStatus & XPOWERS_AXP2101_BAT_CHG_START_IRQ) != 0)
|
||||||
|
|
@ -370,7 +374,7 @@ void pmu_handleIRQ()
|
||||||
PMU.setChargingLedMode(XPOWERS_CHG_LED_BLINK_1HZ);
|
PMU.setChargingLedMode(XPOWERS_CHG_LED_BLINK_1HZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pmu_pwrOnBtnStatus()
|
uint8_t pmu_pwrBtnStatus()
|
||||||
{
|
{
|
||||||
return pwrOnPressed;
|
return pwrOnPressed;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,16 +20,59 @@
|
||||||
#ifndef PMU_H
|
#ifndef PMU_H
|
||||||
#define PMU_H
|
#define PMU_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initalise the AXP2101 power management unit and power on the main power
|
||||||
|
* supply rails.
|
||||||
|
*/
|
||||||
void pmu_init();
|
void pmu_init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shutdown the AXP2101 and remove power from all the power supply rails.
|
||||||
|
* Calling this function shuts down the device.
|
||||||
|
*/
|
||||||
|
void pmu_terminate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current battery voltage.
|
||||||
|
*
|
||||||
|
* @return battery voltage in mV.
|
||||||
|
*/
|
||||||
uint16_t pmu_getVbat();
|
uint16_t pmu_getVbat();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Control the baseband power supply rail.
|
||||||
|
*
|
||||||
|
* @param enable: set to true to enable the baseband power supply.
|
||||||
|
*/
|
||||||
void pmu_setBasebandPower(bool enable);
|
void pmu_setBasebandPower(bool enable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Control the GPS power supply rail.
|
||||||
|
*
|
||||||
|
* @param enable: set to true to enable the GPS power supply.
|
||||||
|
*/
|
||||||
void pmu_setGPSPower(bool enable);
|
void pmu_setGPSPower(bool enable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the AXP2101 IRQ flags.
|
||||||
|
* This function has to be called periodically.
|
||||||
|
*/
|
||||||
void pmu_handleIRQ();
|
void pmu_handleIRQ();
|
||||||
bool pmu_pwrOnBtnStatus();
|
|
||||||
|
/**
|
||||||
|
* Get the current status of the power button input.
|
||||||
|
* The function returns zero if the button is released, one if is pressed and
|
||||||
|
* two in case of long press.
|
||||||
|
*
|
||||||
|
* @return current status of the power button.
|
||||||
|
*/
|
||||||
|
uint8_t pmu_pwrBtnStatus();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue