From 9770116594b60306bb0e460bf9caee56c52faeb1 Mon Sep 17 00:00:00 2001 From: Rahix <rahix@rahix.de> Date: Thu, 11 Jul 2019 15:22:03 +0200 Subject: [PATCH] feat(epicardium): Properly implement power button behavior Closes #14. @schneider: You can adjust the timings in epicardium/modules/modules.h ;) Signed-off-by: Rahix <rahix@rahix.de> --- epicardium/modules/modules.h | 3 +++ epicardium/modules/pmic.c | 44 ++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/epicardium/modules/modules.h b/epicardium/modules/modules.h index 5a0742737..a66d8285c 100644 --- a/epicardium/modules/modules.h +++ b/epicardium/modules/modules.h @@ -6,6 +6,9 @@ void vSerialTask(void *pvParameters); /* ---------- PMIC --------------------------------------------------------- */ +/* In 1/10s */ +#define PMIC_PRESS_SLEEP 20 +#define PMIC_PRESS_POWEROFF 40 void vPmicTask(void *pvParameters); #endif /* MODULES_H */ diff --git a/epicardium/modules/pmic.c b/epicardium/modules/pmic.c index 41618cdae..4e786f645 100644 --- a/epicardium/modules/pmic.c +++ b/epicardium/modules/pmic.c @@ -25,30 +25,46 @@ void pmic_interrupt_callback(void *_) void vPmicTask(void *pvParameters) { + int count = 0; + portTickType delay = portMAX_DELAY; pmic_task_id = xTaskGetCurrentTaskHandle(); while (1) { - ulTaskNotifyTake(pdTRUE, portMAX_DELAY); + ulTaskNotifyTake(pdTRUE, delay); + + if (count == PMIC_PRESS_SLEEP) { + printf("pmic: Sleep\n" + "[[ Unimplemented ]]\n"); + } + + if (count == PMIC_PRESS_POWEROFF) { + printf("pmic: Poweroff\n" + "[[ Unimplemented ]]\n"); + } uint8_t int_flag = MAX77650_getINT_GLBL(); if (int_flag & MAX77650_INT_nEN_F) { /* Button was pressed */ - printf("pmic: Button pressed!\n"); + count = 0; + delay = portTICK_PERIOD_MS * 100; } if (int_flag & MAX77650_INT_nEN_R) { /* Button was pressed */ - printf("pmic: Button released!\n"); - - printf("Resetting ...\n"); - /* - * Give the UART fifo time to clear. - * TODO: Do this properly - */ - for (int i = 0; i < 0x1000000; i++) { - __asm volatile("nop"); + if (count < PMIC_PRESS_SLEEP) { + printf("pmic: Reset\n"); + /* + * Give the UART fifo time to clear. + * TODO: Do this properly + */ + for (int i = 0; i < 0x1000000; i++) { + __asm volatile("nop"); + } + MXC_GCR->rstr0 = MXC_F_GCR_RSTR0_SYSTEM; } - MXC_GCR->rstr0 = MXC_F_GCR_RSTR0_SYSTEM; + + count = 0; + delay = portMAX_DELAY; } /* TODO: Remove when all interrupts are handled */ @@ -57,5 +73,9 @@ void vPmicTask(void *pvParameters) "* Unhandled PMIC Interrupt: %x\n", int_flag); } + + if (delay != portMAX_DELAY) { + count += 1; + } } } -- GitLab