Skip to content

Commit

Permalink
tap:Use board power button notification API
Browse files Browse the repository at this point in the history
  This adds the board power button notification registration
  and shutdown API points.
  • Loading branch information
David Sidrane committed Apr 13, 2017
1 parent f7de34f commit afe42b1
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions src/drivers/boards/tap-v1/tap_pwr.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,49 @@ 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;

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;
Expand All @@ -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);
}
}

Expand Down

0 comments on commit afe42b1

Please sign in to comment.