roll-back on some post review code

This commit is contained in:
silvinor 2025-05-06 08:56:48 +10:00
parent ef8a97659a
commit ce69ee413e
4 changed files with 195 additions and 123 deletions

View File

@ -7,7 +7,7 @@
/* generated and tested on https://joric.github.io/qle/ */ /* generated and tested on https://joric.github.io/qle/ */
// clang-format off // clang-format off
static const unsigned char PROGMEM font[] = { static const unsigned char PROGMEM font[] = {
0xFF, 0x81, 0x81, 0x81, 0x81, 0xFF, 0xFF, 0x81, 0x81, 0x81, 0xFF, 0x00,
0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x00, 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x00,
0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x00, 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x00,
0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x00, 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x00,
@ -39,96 +39,99 @@ static const unsigned char PROGMEM font[] = {
0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 0x00, 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 0x00,
0x30, 0x38, 0x3E, 0x38, 0x30, 0x00, 0x30, 0x38, 0x3E, 0x38, 0x30, 0x00,
0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // by @lexus2k form here down
0x00, 0x00, 0x00, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sp
0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, 0x2F, 0x00, 0x00, 0x00,
0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00,
0x00, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00,
0x00, 0x23, 0x13, 0x08, 0x64, 0x62, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00,
0x00, 0x36, 0x49, 0x55, 0x22, 0x50, 0x23, 0x13, 0x08, 0x64, 0x62, 0x00,
0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x36, 0x49, 0x55, 0x22, 0x50, 0x00,
0x00, 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x41, 0x22, 0x1C, 0x00, 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00,
0x00, 0x14, 0x08, 0x3E, 0x08, 0x14, 0x00, 0x41, 0x22, 0x1C, 0x00, 0x00,
0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x14, 0x08, 0x3E, 0x08, 0x14, 0x00,
0x00, 0x00, 0x00, 0xA0, 0x60, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00,
0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0xA0, 0x60, 0x00, 0x00,
0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00,
0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00,
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00,
0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00,
0x00, 0x42, 0x61, 0x51, 0x49, 0x46, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00,
0x00, 0x21, 0x41, 0x45, 0x4B, 0x31, 0x42, 0x61, 0x51, 0x49, 0x46, 0x00,
0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x21, 0x41, 0x45, 0x4B, 0x31, 0x00,
0x00, 0x27, 0x45, 0x45, 0x45, 0x39, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00,
0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30, 0x27, 0x45, 0x45, 0x45, 0x39, 0x00,
0x00, 0x01, 0x71, 0x09, 0x05, 0x03, 0x3C, 0x4A, 0x49, 0x49, 0x30, 0x00,
0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x01, 0x71, 0x09, 0x05, 0x03, 0x00,
0x00, 0x06, 0x49, 0x49, 0x29, 0x1E, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00,
0x00, 0x00, 0x36, 0x36, 0x00, 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E, 0x00,
0x00, 0x00, 0x56, 0x36, 0x00, 0x00, 0x00, 0x36, 0x36, 0x00, 0x00, 0x00,
0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x56, 0x36, 0x00, 0x00, 0x00,
0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00,
0x00, 0x00, 0x41, 0x22, 0x14, 0x08, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00,
0x00, 0x02, 0x01, 0x51, 0x09, 0x06, 0x00, 0x41, 0x22, 0x14, 0x08, 0x00,
0x00, 0x32, 0x49, 0x59, 0x51, 0x3E, 0x02, 0x01, 0x51, 0x09, 0x06, 0x00,
0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,
0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x32, 0x49, 0x59, 0x51, 0x3E, 0x00,
0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00,
0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00,
0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00,
0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x7F, 0x41, 0x41, 0x22, 0x1C, 0x00,
0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00,
0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00,
0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A, 0x00,
0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00,
0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00,
0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00,
0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00,
0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00,
0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x7F, 0x02, 0x0C, 0x02, 0x7F, 0x00,
0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00,
0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00,
0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00,
0x00, 0x46, 0x49, 0x49, 0x49, 0x31, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00,
0x00, 0x01, 0x01, 0x7F, 0x01, 0x01, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00,
0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x46, 0x49, 0x49, 0x49, 0x31, 0x00,
0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x01, 0x01, 0x7F, 0x01, 0x01, 0x00,
0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00,
0x00, 0x63, 0x14, 0x08, 0x14, 0x63, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00,
0x00, 0x07, 0x08, 0x70, 0x08, 0x07, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00,
0x00, 0x61, 0x51, 0x49, 0x45, 0x43, 0x63, 0x14, 0x08, 0x14, 0x63, 0x00,
0x00, 0x00, 0x7F, 0x41, 0x41, 0x00, 0x07, 0x08, 0x70, 0x08, 0x07, 0x00,
0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x61, 0x51, 0x49, 0x45, 0x43, 0x00,
0x00, 0x00, 0x41, 0x41, 0x7F, 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00, 0x00,
0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00,
0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x41, 0x41, 0x7F, 0x00, 0x00,
0x00, 0x00, 0x01, 0x02, 0x04, 0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00,
0x00, 0x20, 0x54, 0x54, 0x54, 0x78, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00,
0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,
0x00, 0x38, 0x44, 0x44, 0x44, 0x20, 0x00, 0x01, 0x02, 0x04, 0x00, 0x00,
0x00, 0x38, 0x44, 0x44, 0x48, 0x7F, 0x20, 0x54, 0x54, 0x54, 0x78, 0x00,
0x00, 0x38, 0x54, 0x54, 0x54, 0x18, 0x7F, 0x48, 0x44, 0x44, 0x38, 0x00,
0x00, 0x08, 0x7E, 0x09, 0x01, 0x02, 0x38, 0x44, 0x44, 0x44, 0x20, 0x00,
0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C, 0x38, 0x44, 0x44, 0x48, 0x7F, 0x00,
0x00, 0x7F, 0x08, 0x04, 0x04, 0x78, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00,
0x00, 0x00, 0x44, 0x7D, 0x40, 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02, 0x00,
0x00, 0x40, 0x80, 0x84, 0x7D, 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C, 0x00,
0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00,
0x00, 0x00, 0x41, 0x7F, 0x40, 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00, 0x00,
0x00, 0x7C, 0x04, 0x18, 0x04, 0x78, 0x40, 0x80, 0x84, 0x7D, 0x00, 0x00,
0x00, 0x7C, 0x08, 0x04, 0x04, 0x78, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00,
0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, 0x41, 0x7F, 0x40, 0x00, 0x00,
0x00, 0xFC, 0x24, 0x24, 0x24, 0x18, 0x7C, 0x04, 0x18, 0x04, 0x78, 0x00,
0x00, 0x18, 0x24, 0x24, 0x18, 0xFC, 0x7C, 0x08, 0x04, 0x04, 0x78, 0x00,
0x00, 0x7C, 0x08, 0x04, 0x04, 0x08, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00,
0x00, 0x48, 0x54, 0x54, 0x54, 0x20, 0xFC, 0x24, 0x24, 0x24, 0x18, 0x00,
0x00, 0x04, 0x3F, 0x44, 0x40, 0x20, 0x18, 0x24, 0x24, 0x18, 0xFC, 0x00,
0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x7C, 0x08, 0x04, 0x04, 0x08, 0x00,
0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x48, 0x54, 0x54, 0x54, 0x20, 0x00,
0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x04, 0x3F, 0x44, 0x40, 0x20, 0x00,
0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x00,
0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00,
0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00,
0x44, 0x28, 0x10, 0x28, 0x44, 0x00,
0x1C, 0xA0, 0xA0, 0xA0, 0x7C, 0x00,
0x00, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,
0x00, 0x00, 0x08, 0x77, 0x00, 0x00, 0x00, 0x00, 0x08, 0x77, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00,

View File

@ -32,8 +32,6 @@
"layouts": { "layouts": {
"LAYOUT": { "LAYOUT": {
"layout": [ "layout": [
{"label": "", "matrix": [5, 0], "x": 2, "y": 0},
{"label": "", "matrix": [5, 1], "x": 3, "y": 0},
{"label": "Num Lock", "matrix": [0, 0], "x": 0, "y": 1}, {"label": "Num Lock", "matrix": [0, 0], "x": 0, "y": 1},
{"label": "/", "matrix": [0, 1], "x": 1, "y": 1}, {"label": "/", "matrix": [0, 1], "x": 1, "y": 1},
{"label": "*", "matrix": [0, 2], "x": 2, "y": 1}, {"label": "*", "matrix": [0, 2], "x": 2, "y": 1},
@ -50,7 +48,9 @@
{"label": "3", "matrix": [3, 2], "x": 2, "y": 4}, {"label": "3", "matrix": [3, 2], "x": 2, "y": 4},
{"label": "Enter", "matrix": [3, 3], "x": 3, "y": 4, "h": 2}, {"label": "Enter", "matrix": [3, 3], "x": 3, "y": 4, "h": 2},
{"label": "0", "matrix": [4, 0], "x": 0, "y": 5, "w": 2}, {"label": "0", "matrix": [4, 0], "x": 0, "y": 5, "w": 2},
{"label": ".", "matrix": [4, 2], "x": 2, "y": 5} {"label": ".", "matrix": [4, 2], "x": 2, "y": 5},
{"label": "", "matrix": [5, 0], "x": 2, "y": 0},
{"label": "", "matrix": [5, 1], "x": 3, "y": 0},
] ]
} }
} }

View File

@ -6,59 +6,104 @@
* This file is mostly a copy of `matrix.c` from the QMK core, however * This file is mostly a copy of `matrix.c` from the QMK core, however
* it assumes the matrix is always COL2ROW and that the KB has BOTH * it assumes the matrix is always COL2ROW and that the KB has BOTH
* matrix and direct pins. * matrix and direct pins.
*
* For direct pins define * For direct pins define
* `DIRECT_PINS_CUSTOM` * `DIRECT_PINS_CUSTOM`
* This stucture must exactly match the MATRIX_ROWS / MATRIX_COLS matrix. * This stucture must exactly match the MATRIX_ROWS / MATRIX_COLS matrix.
* *
* !! : The ROW that supports direct pins __must__ have the row set to NO_PIN in the matrix array. * NB!!: The ROW that supports direct pins **must** have the row set
*/ * to NO_PIN in the matrix array.
*/
#include "matrix.h" #include "matrix.h"
#include "debounce.h" #include "debounce.h"
#include "atomic_util.h" #include "atomic_util.h"
#include <string.h> // For memset, memcmp & memcpy #include <string.h>
#include "wait.h" #include "wait.h"
#include "print.h"
#ifndef DEBOUNCE
# define DEBOUNCE 5
#endif
#ifndef MATRIX_INPUT_PRESSED_STATE #ifndef MATRIX_INPUT_PRESSED_STATE
# define MATRIX_INPUT_PRESSED_STATE 0 # define MATRIX_INPUT_PRESSED_STATE 0
#endif #endif
#ifndef MATRIX_IO_DELAY
# define MATRIX_IO_DELAY 30
#endif
static pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; static pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
static pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; static pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
// define DIRECT_PINS_CUSTOM in `config.h` // define DIRECT_PINS_CUSTOM in `config.h`
// !! : Must match the MATRIX_ROWS / MATRIX_COLS matrix structure // ** NB: ** must match the MATRIX_ROWS / MATRIX_COLS matrix structure
static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS_CUSTOM; static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS_CUSTOM;
/* matrix state(1:on, 0:off) */ /* matrix state(1:on, 0:off) */
matrix_row_t raw_matrix[MATRIX_ROWS]; matrix_row_t raw_matrix[MATRIX_ROWS];
matrix_row_t matrix[MATRIX_ROWS];
static inline void gpio_atomic_set_pin_output_low(pin_t pin) { __attribute__((weak)) void matrix_init_user(void) {}
__attribute__((weak)) void matrix_init_kb(void) {
matrix_init_user();
}
__attribute__((weak)) void matrix_scan_user(void) {}
__attribute__((weak)) void matrix_scan_kb(void) {
matrix_scan_user();
}
#define print_matrix_header() print("\nr/c 01234567\n")
#define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
__attribute__((weak)) void matrix_output_select_delay(void) {
waitInputPinDelay();
}
__attribute__((weak)) void matrix_output_unselect_delay(uint8_t line, bool key_pressed) {
wait_us(MATRIX_IO_DELAY);
}
static inline void setPinOutput_writeLow(pin_t pin) {
ATOMIC_BLOCK_FORCEON { ATOMIC_BLOCK_FORCEON {
gpio_set_pin_output(pin); setPinOutput(pin);
gpio_write_pin_low(pin); writePinLow(pin);
} }
} }
static inline void gpio_atomic_set_pin_input_high(pin_t pin) { static inline void setPinInputHigh_atomic(pin_t pin) {
ATOMIC_BLOCK_FORCEON { ATOMIC_BLOCK_FORCEON {
gpio_set_pin_input_high(pin); setPinInputHigh(pin);
} }
} }
static inline uint8_t gpio_read_matrix_pin(pin_t pin) { static inline uint8_t readMatrixPin(pin_t pin) {
if (pin != NO_PIN) { if (pin != NO_PIN) {
return (gpio_read_pin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1; return (readPin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1;
} else { } else {
return 1; return 1;
} }
} }
void matrix_print(void) {
print_matrix_header();
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
print_hex8(row);
print(": ");
print_matrix_row(row);
print("\n");
}
}
static bool select_row(uint8_t row) { static bool select_row(uint8_t row) {
pin_t pin = row_pins[row]; pin_t pin = row_pins[row];
if (pin != NO_PIN) { if (pin != NO_PIN) {
gpio_atomic_set_pin_output_low(pin); setPinOutput_writeLow(pin);
return true; return true;
} }
return false; return false;
@ -67,7 +112,7 @@ static bool select_row(uint8_t row) {
static void unselect_row(uint8_t row) { static void unselect_row(uint8_t row) {
pin_t pin = row_pins[row]; pin_t pin = row_pins[row];
if (pin != NO_PIN) { if (pin != NO_PIN) {
gpio_atomic_set_pin_input_high(pin); setPinInputHigh_atomic(pin);
} }
} }
@ -81,7 +126,7 @@ void matrix_init_pins__matrix(void) {
unselect_rows(); unselect_rows();
for (uint8_t x = 0; x < MATRIX_COLS; x++) { for (uint8_t x = 0; x < MATRIX_COLS; x++) {
if (col_pins[x] != NO_PIN) { if (col_pins[x] != NO_PIN) {
gpio_atomic_set_pin_input_high(col_pins[x]); setPinInputHigh_atomic(col_pins[x]);
} }
} }
} }
@ -91,19 +136,42 @@ void matrix_init_pins__direct(void) {
for (int col = 0; col < MATRIX_COLS; col++) { for (int col = 0; col < MATRIX_COLS; col++) {
pin_t pin = direct_pins[row][col]; pin_t pin = direct_pins[row][col];
if (pin != NO_PIN) { if (pin != NO_PIN) {
gpio_atomic_set_pin_input_high(pin); setPinInputHigh(pin);
} }
} }
} }
} }
void matrix_init_custom(void) { inline uint8_t matrix_rows(void) {
return MATRIX_ROWS;
}
inline uint8_t matrix_cols(void) {
return MATRIX_COLS;
}
void matrix_init(void) {
// initialize key pins // initialize key pins
matrix_init_pins__matrix(); matrix_init_pins__matrix();
matrix_init_pins__direct(); matrix_init_pins__direct();
// initialize matrix state: all keys off // initialize matrix state: all keys off
memset(raw_matrix, 0, sizeof(raw_matrix)); memset(raw_matrix, 0, sizeof(raw_matrix));
memset(matrix, 0, sizeof(matrix));
// Unless hardware debouncing - Init the configured debounce routine
debounce_init(MATRIX_ROWS);
// This *must* be called for correct keyboard behavior
matrix_init_kb();
}
inline bool matrix_is_on(uint8_t row, uint8_t col) {
return (matrix[row] & ((matrix_row_t)1 << col));
}
inline matrix_row_t matrix_get_row(uint8_t row) {
return matrix[row];
} }
void matrix_read_cols_on_row__matrix(matrix_row_t current_matrix[], uint8_t current_row) { void matrix_read_cols_on_row__matrix(matrix_row_t current_matrix[], uint8_t current_row) {
@ -118,7 +186,7 @@ void matrix_read_cols_on_row__matrix(matrix_row_t current_matrix[], uint8_t curr
// For each col... // For each col...
matrix_row_t row_shifter = MATRIX_ROW_SHIFTER; matrix_row_t row_shifter = MATRIX_ROW_SHIFTER;
for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) { for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) {
uint8_t pin_state = gpio_read_matrix_pin(col_pins[col_index]); uint8_t pin_state = readMatrixPin(col_pins[col_index]);
// Populate the matrix row with the state of the col pin // Populate the matrix row with the state of the col pin
current_row_value |= pin_state ? 0 : row_shifter; current_row_value |= pin_state ? 0 : row_shifter;
@ -140,7 +208,7 @@ void matrix_read_cols_on_row__direct(matrix_row_t current_matrix[], uint8_t curr
for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) { for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) {
pin_t pin = direct_pins[current_row][col_index]; pin_t pin = direct_pins[current_row][col_index];
if (NO_PIN != pin) { if (NO_PIN != pin) {
current_row_value |= gpio_read_matrix_pin(pin) ? 0 : row_shifter; current_row_value |= readMatrixPin(pin) ? 0 : row_shifter;
} }
} }
@ -148,23 +216,24 @@ void matrix_read_cols_on_row__direct(matrix_row_t current_matrix[], uint8_t curr
current_matrix[current_row] = current_row_value; current_matrix[current_row] = current_row_value;
} }
bool matrix_scan_custom(matrix_row_t current_matrix[]) { uint8_t matrix_scan(void) {
bool matrix_has_changed = false; matrix_row_t curr_matrix[MATRIX_ROWS] = {0};
// Matrix keys: Set row, read cols // Matrix keys: Set row, read cols
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
// if the row is a NO_PIN then assume it's on a direct pins matrix, else assume COL2ROW matrix // if the row is a NO_PIN then assume it's on a direct pins matrix, else assume COL2ROW matrix
if (NO_PIN != row_pins[current_row]) { if (NO_PIN != row_pins[current_row]) {
matrix_read_cols_on_row__matrix(current_matrix, current_row); matrix_read_cols_on_row__matrix(curr_matrix, current_row);
} else { } else {
matrix_read_cols_on_row__direct(current_matrix, current_row); matrix_read_cols_on_row__direct(curr_matrix, current_row);
} }
} }
matrix_has_changed = memcmp(raw_matrix, current_matrix, MATRIX_ROWS) != 0; bool changed = memcmp(raw_matrix, curr_matrix, sizeof(curr_matrix)) != 0;
if (matrix_has_changed) { if (changed) memcpy(raw_matrix, curr_matrix, sizeof(curr_matrix));
memcpy(raw_matrix, current_matrix, MATRIX_ROWS);
}
return matrix_has_changed; changed = debounce(raw_matrix, matrix, MATRIX_ROWS, changed);
matrix_scan_kb();
return (uint8_t)changed;
} }

View File

@ -1,7 +1,7 @@
# Copyright 2023 binepad (@binepad) # Copyright 2023 binepad (@binepad)
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
CUSTOM_MATRIX = lite CUSTOM_MATRIX = yes
SRC += matrix.c \ SRC += matrix.c \
candypad_oled.c candypad_oled.c