diff options
Diffstat (limited to 'keyboards/handwired/xealous')
-rw-r--r-- | keyboards/handwired/xealous/debounce.c | 63 | ||||
-rw-r--r-- | keyboards/handwired/xealous/rules.mk | 10 |
2 files changed, 69 insertions, 4 deletions
diff --git a/keyboards/handwired/xealous/debounce.c b/keyboards/handwired/xealous/debounce.c new file mode 100644 index 0000000000..65a99f27f2 --- /dev/null +++ b/keyboards/handwired/xealous/debounce.c @@ -0,0 +1,63 @@ +#include <string.h> +#include "config.h" +#include "matrix.h" +#include "timer.h" +#include "quantum.h" + +#ifndef DEBOUNCING_DELAY +# define DEBOUNCING_DELAY 5 +#endif + +//Debouncing counters +typedef uint8_t debounce_counter_t; +#define DEBOUNCE_COUNTER_MODULO 250 +#define DEBOUNCE_COUNTER_INACTIVE 251 + +static debounce_counter_t *debounce_counters; + +void debounce_init(uint8_t num_rows) +{ + debounce_counters = malloc(num_rows*MATRIX_COLS); + memset(debounce_counters, DEBOUNCE_COUNTER_INACTIVE, num_rows*MATRIX_COLS); +} + +void update_debounce_counters(uint8_t num_rows, uint8_t current_time) +{ + for (uint8_t row = 0; row < num_rows; row++) + { + for (uint8_t col = 0; col < MATRIX_COLS; col++) + { + if (debounce_counters[row*MATRIX_COLS + col] != DEBOUNCE_COUNTER_INACTIVE) + { + if (TIMER_DIFF(current_time, debounce_counters[row*MATRIX_COLS + col], DEBOUNCE_COUNTER_MODULO) >= DEBOUNCING_DELAY) { + debounce_counters[row*MATRIX_COLS + col] = DEBOUNCE_COUNTER_INACTIVE; + } + } + } + } +} + +void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) +{ + for (uint8_t row = 0; row < num_rows; row++) + { + matrix_row_t delta = raw[row] ^ cooked[row]; + + for (uint8_t col = 0; col < MATRIX_COLS; col++) + { + if (debounce_counters[row*MATRIX_COLS + col] == DEBOUNCE_COUNTER_INACTIVE && (delta & (1<<col))) + { + debounce_counters[row*MATRIX_COLS + col] = current_time; + cooked[row] ^= (1 << col); + } + } + } +} + +void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) +{ + uint8_t current_time = timer_read() % DEBOUNCE_COUNTER_MODULO; + + update_debounce_counters(num_rows, current_time); + transfer_matrix_values(raw, cooked, num_rows, current_time); +}
\ No newline at end of file diff --git a/keyboards/handwired/xealous/rules.mk b/keyboards/handwired/xealous/rules.mk index eebd11d86e..07e1c875e6 100644 --- a/keyboards/handwired/xealous/rules.mk +++ b/keyboards/handwired/xealous/rules.mk @@ -1,4 +1,5 @@ -SRC += matrix_scanrate.c matrix.c +#SRC += matrix_scanrate.c matrix.c +SRC += debounce.c # MCU name MCU = atmega32u4 @@ -37,7 +38,7 @@ F_USB = $(F_CPU) # Bootloader # This definition is optional, and if your keyboard supports multiple bootloaders of -# different sizes, comment this out, and the correct address will be loaded +# different sizes, comment this out, and the correct address will be loaded # automatically (+60). See bootloader.mk for all options. BOOTLOADER = caterina @@ -59,14 +60,15 @@ MIDI_ENABLE = no # MIDI controls AUDIO_ENABLE = yes # Audio output on port C6 UNICODE_ENABLE = no # Unicode BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID -RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. +RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. SPLIT_KEYBOARD = yes # Use shared split_common code SUBPROJECT_rev1 = yes # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend -CUSTOM_MATRIX = yes +CUSTOM_MATRIX = no +CUSTOM_DEBOUNCE = yes LAYOUTS = split60 |