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

feat(epicardium): Properly implement power button behavior


Closes #14.  @schneider:  You can adjust the timings
in epicardium/modules/modules.h ;)

Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 18ec7649
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
void vSerialTask(void *pvParameters); void vSerialTask(void *pvParameters);
/* ---------- PMIC --------------------------------------------------------- */ /* ---------- PMIC --------------------------------------------------------- */
/* In 1/10s */
#define PMIC_PRESS_SLEEP 20
#define PMIC_PRESS_POWEROFF 40
void vPmicTask(void *pvParameters); void vPmicTask(void *pvParameters);
#endif /* MODULES_H */ #endif /* MODULES_H */
......
...@@ -25,30 +25,46 @@ void pmic_interrupt_callback(void *_) ...@@ -25,30 +25,46 @@ void pmic_interrupt_callback(void *_)
void vPmicTask(void *pvParameters) void vPmicTask(void *pvParameters)
{ {
int count = 0;
portTickType delay = portMAX_DELAY;
pmic_task_id = xTaskGetCurrentTaskHandle(); pmic_task_id = xTaskGetCurrentTaskHandle();
while (1) { 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(); uint8_t int_flag = MAX77650_getINT_GLBL();
if (int_flag & MAX77650_INT_nEN_F) { if (int_flag & MAX77650_INT_nEN_F) {
/* Button was pressed */ /* Button was pressed */
printf("pmic: Button pressed!\n"); count = 0;
delay = portTICK_PERIOD_MS * 100;
} }
if (int_flag & MAX77650_INT_nEN_R) { if (int_flag & MAX77650_INT_nEN_R) {
/* Button was pressed */ /* Button was pressed */
printf("pmic: Button released!\n"); if (count < PMIC_PRESS_SLEEP) {
printf("pmic: Reset\n");
printf("Resetting ...\n"); /*
/* * Give the UART fifo time to clear.
* Give the UART fifo time to clear. * TODO: Do this properly
* TODO: Do this properly */
*/ for (int i = 0; i < 0x1000000; i++) {
for (int i = 0; i < 0x1000000; i++) { __asm volatile("nop");
__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 */ /* TODO: Remove when all interrupts are handled */
...@@ -57,5 +73,9 @@ void vPmicTask(void *pvParameters) ...@@ -57,5 +73,9 @@ void vPmicTask(void *pvParameters)
"* Unhandled PMIC Interrupt: %x\n", "* Unhandled PMIC Interrupt: %x\n",
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