From d3c52d1c97e1928b0390e8eecf1ffa2379e2c13f Mon Sep 17 00:00:00 2001 From: Rahix <rahix@rahix.de> Date: Thu, 15 Aug 2019 14:11:42 +0200 Subject: [PATCH] feat(pmic): Implement proper reset behavior Pressing the power button will now excert the following behavior: - `<400 ms`: Return back to menu - `<1 s`: Reset card10 - `>1 s`: Poweroff Signed-off-by: Rahix <rahix@rahix.de> --- epicardium/modules/pmic.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/epicardium/modules/pmic.c b/epicardium/modules/pmic.c index 9e5c9b624..492545bb3 100644 --- a/epicardium/modules/pmic.c +++ b/epicardium/modules/pmic.c @@ -27,19 +27,21 @@ void pmic_interrupt_callback(void *_) void vPmicTask(void *pvParameters) { - int count = 0; - portTickType delay = portMAX_DELAY; - pmic_task_id = xTaskGetCurrentTaskHandle(); + pmic_task_id = xTaskGetCurrentTaskHandle(); - while (1) { - ulTaskNotifyTake(pdTRUE, delay); + TickType_t button_start_tick = 0; - if (count == PMIC_PRESS_SLEEP) { - LOG_ERR("pmic", "Sleep [[ Unimplemented ]]"); + while (1) { + if (button_start_tick == 0) { + ulTaskNotifyTake(pdTRUE, portMAX_DELAY); + } else { + ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(100)); } - if (count == PMIC_PRESS_POWEROFF) { - LOG_INFO("pmic", "Poweroff"); + TickType_t duration = xTaskGetTickCount() - button_start_tick; + + if (button_start_tick != 0 && duration > pdMS_TO_TICKS(1000)) { + LOG_WARN("pmic", "Poweroff"); MAX77650_setSFT_RST(0x2); } @@ -47,17 +49,17 @@ void vPmicTask(void *pvParameters) if (int_flag & MAX77650_INT_nEN_F) { /* Button was pressed */ - count = 0; - delay = portTICK_PERIOD_MS * 100; + button_start_tick = xTaskGetTickCount(); } if (int_flag & MAX77650_INT_nEN_R) { - /* Button was pressed */ - if (count < PMIC_PRESS_SLEEP) { + /* Button was released */ + button_start_tick = 0; + if (duration < pdMS_TO_TICKS(400)) { + return_to_menu(); + } else { + LOG_WARN("pmic", "Resetting ..."); card10_reset(); } - - count = 0; - delay = portMAX_DELAY; } /* TODO: Remove when all interrupts are handled */ @@ -68,9 +70,5 @@ void vPmicTask(void *pvParameters) int_flag ); } - - if (delay != portMAX_DELAY) { - count += 1; - } } } -- GitLab