From 8253b171b2263bb7a892480b9faff983c7f6226c Mon Sep 17 00:00:00 2001 From: Nicholas G Date: Thu, 18 Aug 2022 21:30:16 -0400 Subject: [PATCH] Renamed debounce algorithms --- src/debounce/constant_switch.c | 17 ----------------- src/debounce/debounce_include.h | 11 ++++++----- src/debounce/deferred.c | 18 ++++++++++++++++++ src/debounce/eager.c | 18 ++++++++++++++++++ src/debounce/minimum_hold.c | 16 ---------------- src/pico_game_controller.c | 7 ++++--- 6 files changed, 46 insertions(+), 41 deletions(-) delete mode 100644 src/debounce/constant_switch.c create mode 100644 src/debounce/deferred.c create mode 100644 src/debounce/eager.c delete mode 100644 src/debounce/minimum_hold.c diff --git a/src/debounce/constant_switch.c b/src/debounce/constant_switch.c deleted file mode 100644 index a06d79a..0000000 --- a/src/debounce/constant_switch.c +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Debouncing algorithm which waits for switch to output a constant n amount of time before outputting - * @author SpeedyPotato - **/ - -uint16_t constant_switch() { - uint16_t translate_buttons = 0; - for (int i = SW_GPIO_SIZE - 1; i >= 0; i--) { - if (!gpio_get(SW_GPIO[i]) && - time_us_64() - sw_timestamp[i] >= SW_DEBOUNCE_TIME_US) { - translate_buttons = (translate_buttons << 1) | 1; - } else { - translate_buttons <<= 1; - } - } - return translate_buttons; -} \ No newline at end of file diff --git a/src/debounce/debounce_include.h b/src/debounce/debounce_include.h index 1999583..2e66197 100644 --- a/src/debounce/debounce_include.h +++ b/src/debounce/debounce_include.h @@ -1,11 +1,12 @@ /** * Simple header file to include all files in the folder * @author SpeedyPotato - * - * To add a debounce mode, return a uint16_t representing the button states. These are saved in report.buttons as truth. - * Create debounce mode as desired and then add the #include here. + * + * To add a debounce mode, return a uint16_t representing the button states. + * These are saved in report.buttons as truth. Create debounce mode as desired + * and then add the #include here. **/ extern uint64_t sw_timestamp[SW_GPIO_SIZE]; -#include "constant_switch.c" -#include "minimum_hold.c" \ No newline at end of file +#include "deferred.c" +#include "eager.c" \ No newline at end of file diff --git a/src/debounce/deferred.c b/src/debounce/deferred.c new file mode 100644 index 0000000..9113255 --- /dev/null +++ b/src/debounce/deferred.c @@ -0,0 +1,18 @@ +/** + * Debouncing algorithm which waits for switch to output a constant n amount of + * time before outputting + * @author SpeedyPotato + **/ + +uint16_t debounce_deferred() { + uint16_t translate_buttons = 0; + for (int i = SW_GPIO_SIZE - 1; i >= 0; i--) { + if (!gpio_get(SW_GPIO[i]) && + time_us_64() - sw_timestamp[i] >= SW_DEBOUNCE_TIME_US) { + translate_buttons = (translate_buttons << 1) | 1; + } else { + translate_buttons <<= 1; + } + } + return translate_buttons; +} \ No newline at end of file diff --git a/src/debounce/eager.c b/src/debounce/eager.c new file mode 100644 index 0000000..bf0bec6 --- /dev/null +++ b/src/debounce/eager.c @@ -0,0 +1,18 @@ +/** + * Debouncing algorithm which sends a report immediately when a switch is + * triggered and holds it for n amount of time. + * @author SpeedyPotato + **/ + +uint16_t debounce_eager() { + uint16_t translate_buttons = 0; + for (int i = SW_GPIO_SIZE - 1; i >= 0; i--) { + if (time_us_64() - sw_timestamp[i] <= SW_DEBOUNCE_TIME_US || + !gpio_get(SW_GPIO[i])) { + translate_buttons = (translate_buttons << 1) | 1; + } else { + translate_buttons <<= 1; + } + } + return translate_buttons; +} \ No newline at end of file diff --git a/src/debounce/minimum_hold.c b/src/debounce/minimum_hold.c deleted file mode 100644 index a284cd0..0000000 --- a/src/debounce/minimum_hold.c +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Debouncing algorithm which sends a report immediately when a switch is triggered and holds it for n amount of time. - * @author SpeedyPotato - **/ - -uint16_t minimum_hold() { - uint16_t translate_buttons = 0; - for (int i = SW_GPIO_SIZE - 1; i >= 0; i--) { - if (time_us_64() - sw_timestamp[i] <= SW_DEBOUNCE_TIME_US || !gpio_get(SW_GPIO[i])) { - translate_buttons = (translate_buttons << 1) | 1; - } else { - translate_buttons <<= 1; - } - } - return translate_buttons; -} \ No newline at end of file diff --git a/src/pico_game_controller.c b/src/pico_game_controller.c index abd6bfa..f14fcec 100644 --- a/src/pico_game_controller.c +++ b/src/pico_game_controller.c @@ -19,9 +19,10 @@ #include "pico/stdlib.h" #include "tusb.h" #include "usb_descriptors.h" - -#include "rgb/rgb_include.h" +// clang-format off #include "debounce/debounce_include.h" +#include "rgb/rgb_include.h" +// clang-format on PIO pio, pio_1; uint32_t enc_val[ENC_GPIO_SIZE]; @@ -274,7 +275,7 @@ void init() { } // Debouncing Mode - debounce_mode = &minimum_hold; + debounce_mode = &debounce_eager; // Disable RGB if (gpio_get(SW_GPIO[8])) {