Skip to content
Snippets Groups Projects
Commit 211837c7 authored by David Sidrane's avatar David Sidrane Committed by Lorenz Meier
Browse files

tap:Use board power button notification API

  This adds the board power button notification registration
  and shutdown API points.
parent 109db758
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment