mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +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:
parent
109db75881
commit
211837c73b
@ -67,6 +67,35 @@ extern void led_off(int led);
|
||||
* 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 struct timespec time_down;
|
||||
@ -74,11 +103,13 @@ static int board_button_irq(int irq, FAR void *context)
|
||||
if (board_pwr_button_down()) {
|
||||
|
||||
led_on(BOARD_LED_RED);
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &time_down);
|
||||
power_state_notification(PWR_BUTTON_DOWN);
|
||||
|
||||
} else {
|
||||
|
||||
power_state_notification(PWR_BUTTON_UP);
|
||||
|
||||
led_off(BOARD_LED_RED);
|
||||
|
||||
struct timespec now;
|
||||
@ -93,15 +124,13 @@ static int board_button_irq(int irq, FAR void *context)
|
||||
|
||||
led_on(BOARD_LED_BLUE);
|
||||
|
||||
up_mdelay(200);
|
||||
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();
|
||||
if (power_state_notification(PWR_BUTTON_REQUEST_SHUT_DOWN) == PWR_BUTTON_RESPONSE_SHUT_DOWN_NOW) {
|
||||
up_mdelay(200);
|
||||
board_shutdown();
|
||||
}
|
||||
|
||||
while (1);
|
||||
} else {
|
||||
power_state_notification(PWR_BUTTON_IDEL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user