From affc256ca21657b4b809624a34285f372404eb54 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Fri, 23 Aug 2019 14:28:25 +0800 Subject: [PATCH 1/2] add delay to cap button improve reliability --- targets/stm32l432/src/device.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/targets/stm32l432/src/device.c b/targets/stm32l432/src/device.c index 8c5f679..65bfdb4 100644 --- a/targets/stm32l432/src/device.c +++ b/targets/stm32l432/src/device.c @@ -55,7 +55,14 @@ static int is_physical_button_pressed() static int is_touch_button_pressed() { - return tsc_read_button(0) || tsc_read_button(1); + int is_pressed = (tsc_read_button(0) || tsc_read_button(1)); + if (is_pressed) + { + // delay for debounce, and longer than polling timer period. + delay(95); + return (tsc_read_button(0) || tsc_read_button(1)); + } + return is_pressed; } int (*IS_BUTTON_PRESSED)() = is_physical_button_pressed; @@ -66,7 +73,7 @@ static void edge_detect_touch_button() uint8_t current_touch = 0; if (is_touch_button_pressed == IS_BUTTON_PRESSED) { - current_touch = IS_BUTTON_PRESSED(); + current_touch = (tsc_read_button(0) || tsc_read_button(1)); // 1 sample per 25 ms if ((millis() - __last_button_bounce_time) > 25) @@ -153,7 +160,6 @@ void device_set_status(uint32_t status) int device_is_button_pressed() { - return IS_BUTTON_PRESSED(); } From 8e192f236310330ed5b0d0278652cc03452491e2 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Fri, 23 Aug 2019 14:31:03 +0800 Subject: [PATCH 2/2] do not delay bootloader --- targets/stm32l432/src/device.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/targets/stm32l432/src/device.c b/targets/stm32l432/src/device.c index 65bfdb4..e6f14e3 100644 --- a/targets/stm32l432/src/device.c +++ b/targets/stm32l432/src/device.c @@ -56,12 +56,14 @@ static int is_physical_button_pressed() static int is_touch_button_pressed() { int is_pressed = (tsc_read_button(0) || tsc_read_button(1)); +#ifndef IS_BOOTLOADER if (is_pressed) { // delay for debounce, and longer than polling timer period. delay(95); return (tsc_read_button(0) || tsc_read_button(1)); } +#endif return is_pressed; }