mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 04:53:34 +08:00
tap:Use board power button notification API
This adds the board power button notification registration and shutdown API points.
This commit is contained in:
committed by
Lorenz Meier
parent
109db75881
commit
211837c73b
@@ -67,6 +67,35 @@ extern void led_off(int led);
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
static int default_power_button_state_notification(board_power_button_state_notification_e request)
|
||||||
|
{
|
||||||
|
// syslog(0,"%d\n", request);
|
||||||
|
return PWR_BUTTON_RESPONSE_SHUT_DOWN_NOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static power_button_state_notification_t power_state_notification = default_power_button_state_notification;
|
||||||
|
|
||||||
|
int board_register_power_state_notification_cb(power_button_state_notification_t cb)
|
||||||
|
{
|
||||||
|
power_state_notification = cb;
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void board_shutdown()
|
||||||
|
{
|
||||||
|
stm32_pwr_enablebkp(true);
|
||||||
|
/* XXX wow, this is evil - write a magic number into backup register zero */
|
||||||
|
*(uint32_t *)0x40002850 = 0xdeaddead;
|
||||||
|
stm32_pwr_enablebkp(false);
|
||||||
|
up_mdelay(50);
|
||||||
|
up_systemreset();
|
||||||
|
|
||||||
|
while (1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static int board_button_irq(int irq, FAR void *context)
|
static int board_button_irq(int irq, FAR void *context)
|
||||||
{
|
{
|
||||||
static struct timespec time_down;
|
static struct timespec time_down;
|
||||||
@@ -74,11 +103,13 @@ static int board_button_irq(int irq, FAR void *context)
|
|||||||
if (board_pwr_button_down()) {
|
if (board_pwr_button_down()) {
|
||||||
|
|
||||||
led_on(BOARD_LED_RED);
|
led_on(BOARD_LED_RED);
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &time_down);
|
clock_gettime(CLOCK_REALTIME, &time_down);
|
||||||
|
power_state_notification(PWR_BUTTON_DOWN);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
power_state_notification(PWR_BUTTON_UP);
|
||||||
|
|
||||||
led_off(BOARD_LED_RED);
|
led_off(BOARD_LED_RED);
|
||||||
|
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
@@ -93,15 +124,13 @@ static int board_button_irq(int irq, FAR void *context)
|
|||||||
|
|
||||||
led_on(BOARD_LED_BLUE);
|
led_on(BOARD_LED_BLUE);
|
||||||
|
|
||||||
up_mdelay(200);
|
if (power_state_notification(PWR_BUTTON_REQUEST_SHUT_DOWN) == PWR_BUTTON_RESPONSE_SHUT_DOWN_NOW) {
|
||||||
stm32_pwr_enablebkp(true);
|
up_mdelay(200);
|
||||||
/* XXX wow, this is evil - write a magic number into backup register zero */
|
board_shutdown();
|
||||||
*(uint32_t *)0x40002850 = 0xdeaddead;
|
}
|
||||||
stm32_pwr_enablebkp(false);
|
|
||||||
up_mdelay(50);
|
|
||||||
up_systemreset();
|
|
||||||
|
|
||||||
while (1);
|
} else {
|
||||||
|
power_state_notification(PWR_BUTTON_IDEL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user