Skip to content
Snippets Groups Projects
Verified Commit d3c52d1c authored by rahix's avatar rahix
Browse files

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: default avatarRahix <rahix@rahix.de>
parent 0f75b615
No related branches found
No related tags found
No related merge requests found
...@@ -27,19 +27,21 @@ void pmic_interrupt_callback(void *_) ...@@ -27,19 +27,21 @@ void pmic_interrupt_callback(void *_)
void vPmicTask(void *pvParameters) void vPmicTask(void *pvParameters)
{ {
int count = 0; pmic_task_id = xTaskGetCurrentTaskHandle();
portTickType delay = portMAX_DELAY;
pmic_task_id = xTaskGetCurrentTaskHandle();
while (1) { TickType_t button_start_tick = 0;
ulTaskNotifyTake(pdTRUE, delay);
if (count == PMIC_PRESS_SLEEP) { while (1) {
LOG_ERR("pmic", "Sleep [[ Unimplemented ]]"); if (button_start_tick == 0) {
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
} else {
ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(100));
} }
if (count == PMIC_PRESS_POWEROFF) { TickType_t duration = xTaskGetTickCount() - button_start_tick;
LOG_INFO("pmic", "Poweroff");
if (button_start_tick != 0 && duration > pdMS_TO_TICKS(1000)) {
LOG_WARN("pmic", "Poweroff");
MAX77650_setSFT_RST(0x2); MAX77650_setSFT_RST(0x2);
} }
...@@ -47,17 +49,17 @@ void vPmicTask(void *pvParameters) ...@@ -47,17 +49,17 @@ void vPmicTask(void *pvParameters)
if (int_flag & MAX77650_INT_nEN_F) { if (int_flag & MAX77650_INT_nEN_F) {
/* Button was pressed */ /* Button was pressed */
count = 0; button_start_tick = xTaskGetTickCount();
delay = portTICK_PERIOD_MS * 100;
} }
if (int_flag & MAX77650_INT_nEN_R) { if (int_flag & MAX77650_INT_nEN_R) {
/* Button was pressed */ /* Button was released */
if (count < PMIC_PRESS_SLEEP) { button_start_tick = 0;
if (duration < pdMS_TO_TICKS(400)) {
return_to_menu();
} else {
LOG_WARN("pmic", "Resetting ...");
card10_reset(); card10_reset();
} }
count = 0;
delay = portMAX_DELAY;
} }
/* TODO: Remove when all interrupts are handled */ /* TODO: Remove when all interrupts are handled */
...@@ -68,9 +70,5 @@ void vPmicTask(void *pvParameters) ...@@ -68,9 +70,5 @@ void vPmicTask(void *pvParameters)
int_flag int_flag
); );
} }
if (delay != portMAX_DELAY) {
count += 1;
}
} }
} }
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