sxkbd

Firmware for RP2040-based corne split keyboard
git clone https://git.sinitax.com/sinitax/sxkbd
Log | Files | Refs | Submodules | README | LICENSE | sfeed.txt

commit 4995cfc61e7d2d0c05cf493959456b5bc9a74f19
parent 8e8c972cbec56d8de31847981149cde4a8fc16cd
Author: Louis Burda <quent.burda@gmail.com>
Date:   Sun, 18 Dec 2022 14:53:27 +0100

Rename matrix to keymat and refactor key matrix access

Diffstat:
MCMakeLists.txt | 2+-
Msrc/board.h | 10----------
Msrc/hid.c | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
Msrc/hid.h | 9++++++++-
Msrc/keymap.c | 120+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Msrc/keymap.h | 3+++
Asrc/keymat.c | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/keymat.h | 20++++++++++++++++++++
Msrc/keysym.h | 15++++++++++++++-
Msrc/keysym_de.h | 3+++
Msrc/main.c | 102+++++++++----------------------------------------------------------------------
Dsrc/matrix.c | 86-------------------------------------------------------------------------------
Dsrc/matrix.h | 20--------------------
Msrc/split.c | 45++++++++++++++++++---------------------------
Msrc/usb_descriptors.c | 2+-
15 files changed, 360 insertions(+), 269 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -21,7 +21,7 @@ target_sources(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/split.c ${CMAKE_CURRENT_SOURCE_DIR}/src/ws2812.c ${CMAKE_CURRENT_SOURCE_DIR}/src/led.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/matrix.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/keymat.c ${CMAKE_CURRENT_SOURCE_DIR}/src/keymap.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_stdio.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c diff --git a/src/board.h b/src/board.h @@ -2,13 +2,3 @@ #include <stdint.h> -#define REPORT_ID_MIN REPORT_ID_KEYBOARD -enum { - REPORT_ID_KEYBOARD = 1, - REPORT_ID_MOUSE, - REPORT_ID_CONSUMER_CONTROL, - REPORT_ID_MAX -}; - -extern const uint32_t **keymap_layers; - diff --git a/src/hid.c b/src/hid.c @@ -1,10 +1,11 @@ #include "hid.h" #include "split.h" -#include "matrix.h" +#include "keymat.h" #include "keysym.h" #include "keymap.h" -#include <pico/types.h> +#include "bsp/board.h" +#include "pico/types.h" void hid_init(void) @@ -12,15 +13,6 @@ hid_init(void) } -inline uint -layer_index(uint x, uint y) -{ - if (y < KEY_ROWS) - return y * KEY_COLS + x; - else - return y * KEY_COLS + (KEY_COLS - 1 - x); -} - bool hid_gen_report(uint8_t *report) { @@ -30,12 +22,12 @@ hid_gen_report(uint8_t *report) keycnt = 0; for (y = 0; y < KEY_ROWS * 2; y++) { for (x = 0; x < KEY_COLS; x++) { - if (!state_matrix[y * KEY_COLS + x]) + if (!keymat[y][x]) continue; if (keycnt >= 6) break; DEBUG("PRESS %i %", x, y); - p = layer_index(x, y); - report[keycnt] = TO_CODE(keymap_layers_de[0][p]); + p = y * KEY_COLS + x; + report[keycnt] = TO_CODE(keymap_layers[0][p]); keycnt++; } } @@ -43,9 +35,91 @@ hid_gen_report(uint8_t *report) return keycnt > 0; } +bool +send_keyboard_report(void) +{ + static bool cleared = true; + uint8_t report[6] = { 0 }; + bool any; + + any = hid_gen_report(report); + + if (any) { + tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, report); + cleared = false; + return true; + } else if (!cleared) { + tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, NULL); + cleared = true; + return true; + } + + return false; +} + +bool +send_mouse_report(bool state) +{ + if (state) { + tud_hid_mouse_report(REPORT_ID_MOUSE, 0, 10, 10, 0, 0); + return true; + } + + return false; +} + +bool +send_consumer_control_report(bool state) +{ + static bool cleared = true; + uint16_t report; + + if (state) { + report = HID_USAGE_CONSUMER_VOLUME_DECREMENT; + tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &report, 2); + cleared = false; + return true; + } else if (!cleared) { + report = 0; + tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &report, 2); + cleared = true; + return true; + } + + return false; +} + +bool +send_hid_report(int id) +{ + if (!tud_hid_ready()) return false; + + switch (id) { + case REPORT_ID_KEYBOARD: + return send_keyboard_report(); + case REPORT_ID_MOUSE: + return send_mouse_report(false); + case REPORT_ID_CONSUMER_CONTROL: + return send_consumer_control_report(false); + } + + return false; +} + void -hid_task(void) +tud_hid_report_complete_cb(uint8_t instance, + uint8_t const *report, uint8_t len) { + uint8_t id; - /* assemble hid report */ + for (id = report[0] + 1; id < REPORT_ID_MAX; id++) { + if (send_hid_report(id)) + break; + } +} + +void +hid_task(void) +{ + send_hid_report(REPORT_ID_MIN); } diff --git a/src/hid.h b/src/hid.h @@ -3,6 +3,13 @@ #include <stdbool.h> #include <stdint.h> +#define REPORT_ID_MIN REPORT_ID_KEYBOARD +enum { + REPORT_ID_KEYBOARD = 1, + REPORT_ID_MOUSE, + REPORT_ID_CONSUMER_CONTROL, + REPORT_ID_MAX +}; + void hid_init(void); -bool hid_gen_report(uint8_t *keycode); void hid_task(void); diff --git a/src/keymap.c b/src/keymap.c @@ -1,5 +1,6 @@ #include "keymap.h" #include "keycode.h" +#include "keysym.h" #include "keysym_de.h" #include "board.h" #include "util.h" @@ -18,29 +19,118 @@ K21, K22, K23, K24, K25, K26, \ K31, K32, K33, K34, K35, K36, \ 0x0, 0x0, 0x0, K44, K45, K46, \ - K51, K52, K53, K54, K55, K56, \ - K61, K62, K63, K64, K65, K66, \ - K71, K72, K73, K74, K75, K76, \ - K81, K82, K83, 0x0, 0x0, 0x0, \ + K56, K55, K54, K53, K52, K51, \ + K66, K65, K64, K63, K62, K61, \ + K76, K75, K74, K73, K72, K71, \ + 0x0, 0x0, 0x0, K83, K82, K81, \ } enum { - BA /* BASE */ + BASE, /* base */ + QUIK, /* symbols + nav */ + QUIX, /* quick xtras */ + SHRT, /* shortcuts */ + LCTL, /* left ctrl */ + NUMS, /* numbers */ + SPEC, /* specials */ + META, /* functions */ }; static const uint32_t layer_base_de[] = KEYMAP( - _______, DE_Q , DE_W , DE_F , DE_P , DE_B , - _______, DE_A , DE_R , DE_S , DE_T , DE_G , - _______, DE_Z , DE_X , DE_C , DE_D , DE_V , - KC_LGUI, KC_LALT, _______, - - DE_J , DE_L , DE_U , DE_Y , DE_QUOT, _______, - DE_M , DE_N , DE_E , DE_I , DE_O , _______, - DE_K , DE_H , DE_COMM, DE_DOT , DE_MINS, _______, - _______, KC_SPC , KC_LCTL + KC_ESC , DE_Q , DE_W , DE_F , DE_P , DE_B , + SW(QUIK), DE_A , DE_R , DE_S , DE_T , DE_G , + KC_LSFT , DE_Z , DE_X , DE_C , DE_D , DE_V , + KC_LGUI , KC_LALT , SW(SHRT), + + DE_J , DE_L , DE_U , DE_Y , DE_QUOT , DE_PLUS , + DE_M , DE_N , DE_E , DE_I , DE_O , SW(SPEC), + DE_K , DE_H , DE_COMM , DE_DOT , DE_MINS , XXXXXXX , + SW(NUMS), KC_SPC , KC_LCTL +); + +static const uint32_t layer_quik_de[] = KEYMAP( + SW(META), KC_PGDN , KC_PGUP , KC_UP , DE_DLR , DE_QUOT , + _______ , _______ , KC_LEFT , KC_DOWN , KC_RGHT , DE_EXLM , + _______ , _______ , DE_PIPE , DE_LESS , DE_GRTR , DE_BSLS , + _______ , _______ , CS(BASE), + + DE_TILD , DE_LPRN , DE_RPRN , DE_DQUO , DE_GRV , DE_QUES , + KC_BSPC , KC_ENT , DE_SLSH , DE_SCLN , DE_ASTR , DE_CIRC , + DE_PERC , DE_AMPR , DE_MINS , DE_PLUS , DE_EQL , _______ , + KC_TAB , _______ , SW(QUIX) +); + +static const uint32_t layer_quix_de[] = KEYMAP( + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , + + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ +); + +static const uint32_t layer_shrt_de[] = KEYMAP( + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , + + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ +); + +static const uint32_t layer_nums_de[] = KEYMAP( + _______ , DE_1 , DE_2 , DE_3 , DE_4 , DE_5 , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , + + _______ , DE_6 , DE_7 , DE_8 , DE_9 , DE_0 , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ +); + +static const uint32_t layer_spec_de[] = KEYMAP( + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , + + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ +); + +static const uint32_t layer_meta_de[] = KEYMAP( + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , + + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ , _______ , _______ , _______ , + _______ , _______ , _______ ); const uint32_t *keymap_layers_de[] = { - [BA] = layer_base_de + [BASE] = layer_base_de, + [QUIK] = layer_quik_de, + [QUIX] = layer_quix_de, + [SHRT] = layer_shrt_de, + [NUMS] = layer_nums_de, + [SPEC] = layer_spec_de, + [META] = layer_meta_de + }; const uint32_t keymap_layers_de_count = ARRLEN(keymap_layers_de); + +const uint32_t **keymap_layers = keymap_layers_de; +uint32_t keymap_layers_count = keymap_layers_de_count; diff --git a/src/keymap.h b/src/keymap.h @@ -4,3 +4,6 @@ extern const uint32_t *keymap_layers_de[]; extern const uint32_t keymap_layers_de_count; + +extern const uint32_t **keymap_layers; +extern uint32_t keymap_layers_count; diff --git a/src/keymat.c b/src/keymat.c @@ -0,0 +1,86 @@ +#include "keymat.h" + +#include "keymap.h" +#include "split.h" +#include "pico/types.h" +#include "hardware/gpio.h" +#include "hardware/timer.h" + +#include <string.h> + +static const uint keymat_row_pins[] = { 4, 5, 6, 7 }; +static const uint keymat_col_pins[] = { 29, 28, 27, 26, 22, 20 }; +static_assert(ARRLEN(keymat_row_pins) == KEY_ROWS); +static_assert(ARRLEN(keymat_col_pins) == KEY_COLS); + +bool keymat_prev[KEY_ROWS * 2][KEY_COLS]; +bool keymat[KEY_ROWS * 2][KEY_COLS]; + +void +keymat_init(void) +{ + uint x, y; + + for (x = 0; x < KEY_COLS; x++) { + gpio_init(keymat_col_pins[x]); + gpio_set_dir(keymat_col_pins[x], GPIO_IN); + gpio_pull_up(keymat_col_pins[x]); + } + + for (y = 0; y < KEY_ROWS; y++) { + gpio_init(keymat_row_pins[y]); + gpio_set_dir(keymat_row_pins[y], GPIO_OUT); + } +} + +void +keymat_scan(void) +{ + bool (*keymat_half)[KEY_COLS]; + uint x, y; + + memcpy(keymat_prev, keymat, sizeof(keymat)); + + keymat_half = KEYMAT_HALF(SPLIT_SIDE); + for (y = 0; y < KEY_ROWS; y++) { + gpio_put(keymat_row_pins[y], 0); + busy_wait_us(5); + for (x = 0; x < KEY_COLS; x++) + keymat_half[y][x] = !gpio_get(keymat_col_pins[x]); + gpio_put(keymat_row_pins[y], 1); + busy_wait_us(5); + } +} + +uint32_t +keymat_encode_half(int side) +{ + bool (*keymat_half)[KEY_COLS]; + uint32_t mask; + uint x, y; + + mask = 0; + keymat_half = KEYMAT_HALF(side); + for (y = 0; y < KEY_ROWS; y++) { + for (x = 0; x < KEY_COLS; x++) { + if (keymat_half[y][x]) + mask |= 1 << (y * KEY_COLS + x); + } + } + + return mask; +} + +void +keymat_decode_half(int side, uint32_t mask) +{ + bool (*keymat_half)[KEY_COLS]; + uint x, y; + + keymat_half = KEYMAT_HALF(side); + for (y = 0; y < KEY_ROWS; y++) { + for (x = 0; x < KEY_COLS; x++) { + keymat_half[y][x] = (mask >> (y * KEY_COLS + x)) & 1; + } + } +} diff --git a/src/keymat.h b/src/keymat.h @@ -0,0 +1,20 @@ +#pragma once + +#include "util.h" + +#include <stdint.h> + +#define KEY_ROWS 4 +#define KEY_COLS 6 +#define KEY_COUNT (KEY_ROWS * KEY_COLS) + +#define KEYMAT_HALF(side) ((side) == LEFT ? &keymat[0] : &keymat[KEY_ROWS]) + +void keymat_init(void); +void keymat_scan(void); +uint32_t keymat_encode_half(int side); +void keymat_decode_half(int side, uint32_t); + +extern bool keymat_prev[KEY_ROWS * 2][KEY_COLS]; +extern bool keymat[KEY_ROWS * 2][KEY_COLS]; + diff --git a/src/keysym.h b/src/keysym.h @@ -3,6 +3,9 @@ #define XXXXXXX KC_NO #define _______ KC_TRNS +#define MASK(hi, lo) ((1 << hi) - (1 << lo)) + +#define IS_CODE(x) (!((x) & MASK(B_MAX, 8))) #define IS_CTRL(x) ((x) & (1 << B_CTRL)) #define IS_SHIFT(x) ((x) & (1 << B_SHIFT)) #define IS_ALT(x) ((x) & (1 << B_ALT)) @@ -10,6 +13,7 @@ #define IS_RIGHT(x) ((x) & (1 << B_RIGHT)) #define IS_TOGGLE(x) ((x) & (1 << B_TOGGLE)) #define IS_SWITCH(x) ((x) & (1 << B_SWITCH)) +#define IS_MODSWT(x) ((x) & (1 << B_MODSWT)) #define TO_CODE(x) ((x) & 0xFF) #define TO_LAYER(x) ((x) & 0xFF) @@ -35,13 +39,22 @@ #define A(x) LALT(x) #define G(x) LGUI(x) +#define SW(x) ((x) | (1 << B_SWITCH)) +#define TO(x) ((x) | (1 << B_TOGGLE)) +#define MO(x) ((x) | (1 << B_MODSWT)) + +#define CS(x) C(MO(x)) +#define GS(x) G(MO(x)) + enum { B_CTRL = 8, B_SHIFT, B_ALT, B_GUI, - R_RIGHT, + B_RIGHT, B_TOGGLE, B_SWITCH, + B_MODSWT, + B_MAX }; diff --git a/src/keysym_de.h b/src/keysym_de.h @@ -115,6 +115,9 @@ #define DE_COLN S(DE_DOT) // : #define DE_UNDS S(DE_MINS) // _ +/* alternate names */ +#define DE_LESS DE_LABK +#define DE_GRTR S(DE_LABK) /* AltGr symbols * ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ diff --git a/src/main.c b/src/main.c @@ -1,6 +1,6 @@ #include "board.h" #include "usb_stdio.h" -#include "matrix.h" +#include "keymat.h" #include "keysym.h" #include "split.h" #include "led.h" @@ -22,29 +22,32 @@ #include <stdio.h> #include <string.h> -bool send_hid_report(int id); void cdc_task(void); -const uint32_t **keymap_layers = keymap_layers_de; - int main(void) { + uint32_t start, stop; + board_init(); tud_init(BOARD_TUD_RHPORT); usb_stdio_init(); led_init(); - matrix_init(); + keymat_init(); split_init(); - //hid_init(); + hid_init(); + start = board_millis(); while (true) { tud_task(); cdc_task(); led_task(); split_task(); - //hid_task(); - send_hid_report(REPORT_ID_MIN); + hid_task(); + + stop = board_millis(); + DEBUG("Main loop: %i ms", stop - start); + start = stop; } return 0; @@ -107,89 +110,6 @@ tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, } void -tud_hid_report_complete_cb(uint8_t instance, - uint8_t const *report, uint8_t len) -{ - uint8_t id; - - for (id = report[0] + 1; id < REPORT_ID_MAX; id++) { - if (send_hid_report(id)) - break; - } -} - -bool -send_keyboard_report(void) -{ - static bool cleared = true; - uint8_t report[6] = { 0 }; - bool any; - - any = hid_gen_report(report); - - if (any) { - tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, report); - cleared = false; - return true; - } else if (!cleared) { - tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, NULL); - cleared = true; - return true; - } - - return false; -} - -bool -send_mouse_report(bool state) -{ - if (state) { - tud_hid_mouse_report(REPORT_ID_MOUSE, 0, 10, 10, 0, 0); - return true; - } - - return false; -} - -bool -send_consumer_control_report(bool state) -{ - static bool cleared = true; - uint16_t report; - - if (state) { - report = HID_USAGE_CONSUMER_VOLUME_DECREMENT; - tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &report, 2); - cleared = false; - return true; - } else if (!cleared) { - report = 0; - tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &report, 2); - cleared = true; - return true; - } - - return false; -} - -bool -send_hid_report(int id) -{ - if (!tud_hid_ready()) return false; - - switch (id) { - case REPORT_ID_KEYBOARD: - return send_keyboard_report(); - case REPORT_ID_MOUSE: - return send_mouse_report(false); - case REPORT_ID_CONSUMER_CONTROL: - return send_consumer_control_report(false); - } - - return false; -} - -void process_cmd(char *cmd) { char *arg, *tok; diff --git a/src/matrix.c b/src/matrix.c @@ -1,86 +0,0 @@ -#include "keymap.h" - -#include "matrix.h" -#include "split.h" -#include "pico/types.h" -#include "hardware/gpio.h" -#include "hardware/timer.h" - -#include <string.h> - -static const uint matrix_row_pins[] = { 4, 5, 6, 7 }; -static const uint matrix_col_pins[] = { 29, 28, 27, 26, 22, 20 }; -static_assert(ARRLEN(matrix_row_pins) == KEY_ROWS); -static_assert(ARRLEN(matrix_col_pins) == KEY_COLS); - -bool prev_state_matrix[KEY_COUNT * 2]; -bool state_matrix[KEY_COUNT * 2]; - -void -matrix_init(void) -{ - uint x, y; - - for (x = 0; x < KEY_COLS; x++) { - gpio_init(matrix_col_pins[x]); - gpio_set_dir(matrix_col_pins[x], GPIO_IN); - gpio_pull_up(matrix_col_pins[x]); - } - - for (y = 0; y < KEY_ROWS; y++) { - gpio_init(matrix_row_pins[y]); - gpio_set_dir(matrix_row_pins[y], GPIO_OUT); - } -} - -void -scan_matrix(void) -{ - bool pressed; - uint x, y, p; - - memcpy(prev_state_matrix, state_matrix, sizeof(state_matrix)); - - for (y = 0; y < KEY_ROWS; y++) { - gpio_put(matrix_row_pins[y], 0); - busy_wait_us(5); - for (x = 0; x < KEY_COLS; x++) { - pressed = !gpio_get(matrix_col_pins[x]); - p = MAT_OFFSET(SPLIT_SIDE) + y * KEY_COLS + x; - state_matrix[p] = pressed; - } - gpio_put(matrix_row_pins[y], 1); - busy_wait_us(5); - } -} - -uint32_t -matrix_encode_half(int side) -{ - uint32_t mask; - uint x, y, p; - - mask = 0; - for (y = 0; y < KEY_ROWS; y++) { - for (x = 0; x < KEY_COLS; x++) { - p = MAT_OFFSET(side) + y * KEY_COLS + x; - if (state_matrix[p]) - mask |= 1 << (y * KEY_COLS + x); - } - } - - return mask; -} - -void -matrix_decode_half(int side, uint32_t mask) -{ - uint x, y, p; - - for (y = 0; y < KEY_ROWS; y++) { - for (x = 0; x < KEY_COLS; x++) { - p = MAT_OFFSET(side) + y * KEY_COLS + x; - state_matrix[p] = (mask >> (y * KEY_COLS + x)) & 1; - } - } -} diff --git a/src/matrix.h b/src/matrix.h @@ -1,20 +0,0 @@ -#pragma once - -#include "util.h" - -#include <stdint.h> - -#define KEY_ROWS 4 -#define KEY_COLS 6 -#define KEY_COUNT (KEY_ROWS * KEY_COLS) - -#define MAT_OFFSET(side) ((side) == LEFT ? 0 : KEY_COUNT) - -void matrix_init(void); -void scan_matrix(void); -uint32_t matrix_encode_half(int side); -void matrix_decode_half(int side, uint32_t); - -extern bool prev_state_matrix[KEY_COUNT * 2]; -extern bool state_matrix[KEY_COUNT * 2]; - diff --git a/src/split.c b/src/split.c @@ -1,12 +1,11 @@ -#include "hardware/regs/io_bank0.h" -#include "hardware/structs/padsbank0.h" -#include "uart_rx.pio.h" -#include "uart_tx.pio.h" - #include "split.h" #include "util.h" -#include "matrix.h" +#include "keymat.h" +#include "uart_rx.pio.h" +#include "uart_tx.pio.h" +#include "hardware/regs/io_bank0.h" +#include "hardware/structs/padsbank0.h" #include "hardware/pio.h" #include "hardware/irq.h" #include "hardware/gpio.h" @@ -35,8 +34,8 @@ #endif enum { - CMD_SCAN_MATRIX_REQ = 0xA0, - CMD_SCAN_MATRIX_RESP, + CMD_SCAN_KEYMAT_REQ = 0xA0, + CMD_SCAN_KEYMAT_RESP, CMD_STDIO_PUTS }; @@ -217,19 +216,17 @@ handle_cmd(uint8_t cmd) { uint8_t buf[128]; - DEBUG("Got command %i", cmd); - switch (cmd) { - case CMD_SCAN_MATRIX_REQ: + case CMD_SCAN_KEYMAT_REQ: if (SPLIT_ROLE != SLAVE) { - WARN("Got SCAN_MATRIX_REQ as master"); + WARN("Got SCAN_KEYMAT_REQ as master"); break; } scan_pending = true; return; - case CMD_SCAN_MATRIX_RESP: + case CMD_SCAN_KEYMAT_RESP: if (SPLIT_ROLE != MASTER) { - WARN("Got SCAN_MATRIX_RESP as slave"); + WARN("Got SCAN_KEYMAT_RESP as slave"); break; } if (uart_recv((uint8_t *) &halfmat, 4) != 4) @@ -271,17 +268,11 @@ split_task(void) uint32_t start_ms; uint8_t cmd; - //if (!uart_await_tx(20)) - // return; - //DEBUG("Sending"); - //uart_tx_byte(CMD_SCAN_MATRIX_RESP); - //return; - if (SPLIT_ROLE == MASTER) { scan_pending = true; - cmd = CMD_SCAN_MATRIX_REQ; + cmd = CMD_SCAN_KEYMAT_REQ; ASSERT(uart_send(&cmd, 1) == 1); - scan_matrix(); /* scan our side in parallel */ + keymat_scan(); /* scan our side in parallel */ start_ms = board_millis(); while (scan_pending && board_millis() < start_ms + 20) { if (!pio_sm_is_rx_fifo_empty(pio0, uart_rx_sm)) @@ -292,7 +283,7 @@ split_task(void) WARN("Slave matrix scan timeout"); } else { DEBUG("Slave matrix scan success"); - matrix_decode_half(SPLIT_OPP(SPLIT_SIDE), halfmat); + keymat_decode_half(SPLIT_OPP(SPLIT_SIDE), halfmat); } scan_pending = false; } else { @@ -303,11 +294,11 @@ split_task(void) tud_task(); } if (scan_pending) { - scan_matrix(); - cmd = CMD_SCAN_MATRIX_RESP; - DEBUG("Sending SCAN_MATRIX_RESP %i", cmd); + keymat_scan(); + cmd = CMD_SCAN_KEYMAT_RESP; + DEBUG("Sending SCAN_KEYMAT_RESP %i", cmd); ASSERT(uart_send(&cmd, 1) == 1); - halfmat = matrix_encode_half(SPLIT_SIDE); + halfmat = keymat_encode_half(SPLIT_SIDE); ASSERT(uart_send((uint8_t *) &halfmat, 4) == 4); scan_pending = false; } diff --git a/src/usb_descriptors.c b/src/usb_descriptors.c @@ -1,4 +1,4 @@ -#include "board.h" +#include "hid.h" #include "class/hid/hid_device.h" #include "tusb.h"