From 44cf63794489312f147049f29c9f7a72ea7cad41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Fri, 3 Jan 2020 18:11:02 +0100 Subject: [PATCH] hacky but working. wheel channel 1 uses 100n + 1k external PU for debounce now --- main/gui.c | 72 ++++++++++++++++++--------------- main/knob.c | 113 ++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 127 insertions(+), 58 deletions(-) diff --git a/main/gui.c b/main/gui.c index bbdb6e5..c0f0d58 100644 --- a/main/gui.c +++ b/main/gui.c @@ -11,6 +11,8 @@ void gui_init() { printf("GUI init\n"); LCD_setup(); + LCD_setContrast(60); + LCD_clearDisplay(0); LCD_setStr("Hello World", 0, 0, 1); LCD_updateDisplay(); @@ -21,50 +23,54 @@ void gui_init() { static void __attribute__((noreturn)) gui_thread(void *arg) { uint32_t pos = 20; + bool btn = 0; #define NMAX 60 while (1) { - uint32_t value; + uint32_t value = 0; xTaskNotifyWait(0, ULONG_MAX, &value, portMAX_DELAY); - printf("Knob event 0x%02x ", value); +// printf("Knob event 0x%02x ", value); if (value & 0b1000) { - printf("PUSH "); - } - if (value & 0b100) { - printf("RELS "); +// printf("PUSH "); + btn = 1; + } else if (value & 0b100) { + btn = 0; } - if ((value & 0b11) == 0b11) { - printf("BNCE "); - } else { - if (value & 0b01) { - printf("FWD "); - if (pos == NMAX) { - pos = 0; - } - else { - pos += 1; - } + if (value & 0b01) { +// printf("FWD "); + if (pos == NMAX) { + pos = 0; } - if (value & 0b10) { - printf("BACK "); - if (pos == 0) { - pos = NMAX; - } - else { - pos--; - } + else { + pos += 1; } } - printf(">"); - for (int i=0; i"); +// for (int i=0; i pdMS_TO_TICKS(DEBOUNCE_WHEEL_MS)) { + // negedge + negedge_time = time; +// gpio_set_level(sigPin1, 0); + } } else { // posedge - if (time - negedge_time > pdMS_TO_TICKS(DEBOUNCE_WHEEL_MS)) { + if ((time - negedge_time) > pdMS_TO_TICKS(DEBOUNCE_WHEEL_MS)) { + posedge_time = time; if (b) { dir = -1; } else { dir = 1; } - } else { - // reset the timer - negedge_time = time; +// gpio_set_level(sigPin1, 1); } } - - - - - #if 0 const uint32_t inputs = gpio_input_get(); bool a = 0 == (inputs & (1 << wheelPin1)); // neg = active @@ -272,20 +302,53 @@ static void handle_wheel(void *arg) { } } -static void handle_pushbtn(void *arg) { - static uint32_t negedge_time = 0; +static void __attribute__((noreturn)) debounce_service(void *arg) { + bool push_state = 0; + uint32_t push_change_time = 0; - const uint32_t inputs = gpio_input_get(); - BaseType_t higherWoken = 0; - bool pushed = (inputs & (1 << pushPin)) == 0; + while (1) { +// uint32_t value = 0; +// xTaskNotifyWait(0, ULONG_MAX, &value, pdMS_TO_TICKS(1)); + vTaskDelay(pdMS_TO_TICKS(1)); - const uint32_t time = xTaskGetTickCount(); - if (pushed) { - negedge_time = time; - } else { - if (time - negedge_time > pdMS_TO_TICKS(DEBOUNCE_BTN_MS)) { - xTaskNotifyFromISR(hGuiThread, pushed ? 0b1000 : 0b0100, eSetBits, &higherWoken); + uint32_t now = xTaskGetTickCount(); + + const uint32_t inputs = gpio_input_get(); + bool pushed = (inputs & (1 << pushPin)) == 0; + + if (pushed) { // event "PUSHED" + if (!push_state) { + if (push_change_time == 0) { + push_change_time = now; + } + } else { + push_change_time = 0; + } + } + else { // event "RELEASED" + if (push_state) { + if (push_change_time == 0) { + push_change_time = now; + } + } else { + push_change_time = 0; + } + } + + if ((push_change_time != 0) && (now - push_change_time > pdMS_TO_TICKS(DEBOUNCE_BTN_MS))) { + push_state = !push_state; + BaseType_t higherWoken = 0; + xTaskNotifyFromISR(hGuiThread, 0b100<