commit 8e60c68eac5dbe749c80d1b42160ad1f7de42200
parent 4995cfc61e7d2d0c05cf493959456b5bc9a74f19
Author: Louis Burda <quent.burda@gmail.com>
Date: Sun, 18 Dec 2022 18:12:21 +0100
Added layer switching and debouncing
Diffstat:
9 files changed, 315 insertions(+), 170 deletions(-)
diff --git a/src/hid.c b/src/hid.c
@@ -1,56 +1,201 @@
#include "hid.h"
+#include "keycode.h"
#include "split.h"
#include "keymat.h"
#include "keysym.h"
#include "keymap.h"
+#include "hardware/timer.h"
#include "bsp/board.h"
#include "pico/types.h"
+#include <string.h>
+
+struct layerkey {
+ uint layer;
+ uint key;
+};
+
+static uint32_t keysyms[KEY_ROWS][KEY_COLS] = { 0 };
+
+static struct layerkey active_stack[16] = { 0 };
+static uint active_top = 0;
+
+static uint8_t hid_report_prev[6] = { 0 };
+static uint8_t hid_report[6] = { 0 };
+static uint hid_report_len = 0;
+
+static uint64_t bounce_mat[KEY_ROWS][KEY_COLS] = { 0 };
+
+static bool seen_mat[KEY_ROWS][KEY_COLS];
+
+static void active_pop(uint layer);
+static void active_push(uint layer, uint key);
+
void
-hid_init(void)
+active_pop(uint layer)
+{
+ uint i;
+
+ for (i = layer + 1; i <= active_top; i++)
+ active_stack[i-1] = active_stack[i];
+ if (layer <= active_top)
+ active_top--;
+}
+
+void
+active_push(uint layer, uint key)
+{
+ if (active_top == ARRLEN(active_stack) - 1) {
+ WARN("Active stack overflow");
+ return;
+ }
+ active_top += 1;
+ active_stack[active_top].layer = layer;
+ active_stack[active_top].key = key;
+}
+
+void
+add_keycode(uint8_t keycode)
+{
+ if (hid_report_len >= 6) {
+ WARN("HID report overflow");
+ return;
+ }
+
+ hid_report[hid_report_len] = keycode;
+ hid_report_len++;
+}
+
+void
+handle_keypress(uint x, uint y)
+{
+ uint32_t ksym;
+ int i;
+
+ if (!keymat_prev[y][x]) {
+ for (i = (int) active_top; i >= 0; i--) {
+ ksym = keymap_layers[active_stack[i].layer][y][x];
+ if (ksym == KC_NO) return;
+ if (ksym != KC_TRNS)
+ break;
+ }
+ if (i < 0) return;
+ keysyms[y][x] = ksym;
+
+ if (IS_SWITCH(keysyms[y][x])) {
+ INFO("LAYER %u", TO_LAYER(keysyms[y][x]));
+ active_push(TO_LAYER(ksym), y * KEY_COLS + x);
+ for (i = 0; i <= (int) active_top; i++) {
+ INFO("%i. ACTIVE %u %u", i,
+ active_stack[i].layer, active_stack[i].key);
+ }
+ }
+ }
+
+ if (!seen_mat[y][x]) {
+ if (IS_CTRL(keysyms[y][x])) {
+ if (IS_RIGHT(keysyms[y][x])) {
+ add_keycode(KC_RIGHT_CTRL);
+ } else {
+ add_keycode(KC_LEFT_CTRL);
+ }
+ }
+
+ if (IS_SHIFT(keysyms[y][x])) {
+ if (IS_RIGHT(keysyms[y][x])) {
+ add_keycode(KC_RIGHT_SHIFT);
+ } else {
+ add_keycode(KC_LEFT_SHIFT);
+ }
+ }
+
+ if (IS_ALT(keysyms[y][x])) {
+ if (IS_RIGHT(keysyms[y][x])) {
+ add_keycode(KC_RIGHT_ALT);
+ } else {
+ add_keycode(KC_LEFT_ALT);
+ }
+ }
+
+ if (IS_GUI(keysyms[y][x])) {
+ if (IS_RIGHT(keysyms[y][x])) {
+ add_keycode(KC_RIGHT_GUI);
+ } else {
+ add_keycode(KC_LEFT_GUI);
+ }
+ }
+
+ if (IS_CODE(keysyms[y][x])) {
+ add_keycode(TO_CODE(keysyms[y][x]));
+ INFO("CODE %u %u", active_top, keysyms[y][x]);
+ }
+
+ seen_mat[y][x] = true;
+ }
+}
+
+void
+handle_keyrelease(uint x, uint y)
{
-
+ uint i;
+
+ if (keymat_prev[y][x]) {
+ for (i = 1; i <= active_top; i++) {
+ if (active_stack[i].key == y * KEY_COLS + x) {
+ active_pop(i);
+ break;
+ }
+ }
+ }
}
bool
-hid_gen_report(uint8_t *report)
+update_report(void)
{
- int keycnt;
- uint x, y, p;
+ uint64_t now_us;
+ uint keycnt;
+ uint x, y;
keycnt = 0;
- for (y = 0; y < KEY_ROWS * 2; y++) {
+ now_us = time_us_64();
+ for (y = 0; y < KEY_ROWS; y++) {
for (x = 0; x < KEY_COLS; x++) {
- if (!keymat[y][x])
- continue;
- if (keycnt >= 6) break;
- DEBUG("PRESS %i %", x, y);
- p = y * KEY_COLS + x;
- report[keycnt] = TO_CODE(keymap_layers[0][p]);
- keycnt++;
+ if (keymat[y][x] != keymat_prev[y][x]) {
+ if (bounce_mat[y][x] > now_us - 25000) {
+ WARN("Bouncing prevented %i vs %i",
+ keymat[y][x], keymat_prev[y][x]);
+ keymat[y][x] = keymat_prev[y][x];
+ } else {
+ bounce_mat[y][x] = now_us;
+ }
+ }
+
+ if (keymat[y][x]) {
+ handle_keypress(x, y);
+ } else {
+ handle_keyrelease(x, y);
+ }
}
}
return keycnt > 0;
}
+void
+hid_init(void)
+{
+}
+
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;
+ uint i;
+ if (memcmp(hid_report, hid_report_prev, sizeof(hid_report))) {
+ for (i = 0; i < 6; i++)
+ INFO("REPORT %u: %u", i, hid_report[i]);
+ tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, hid_report);
+ memcpy(hid_report_prev, hid_report, sizeof(hid_report));
return true;
}
@@ -92,8 +237,6 @@ send_consumer_control_report(bool state)
bool
send_hid_report(int id)
{
- if (!tud_hid_ready()) return false;
-
switch (id) {
case REPORT_ID_KEYBOARD:
return send_keyboard_report();
@@ -121,5 +264,11 @@ tud_hid_report_complete_cb(uint8_t instance,
void
hid_task(void)
{
- send_hid_report(REPORT_ID_MIN);
+ update_report();
+ if (tud_hid_ready()) {
+ send_hid_report(REPORT_ID_MIN);
+ memset(hid_report, 0, sizeof(hid_report));
+ memset(seen_mat, 0, sizeof(seen_mat));
+ hid_report_len = 0;
+ }
}
diff --git a/src/keycode.h b/src/keycode.h
@@ -1,6 +1,8 @@
#pragma once
+
/*
- * Keycodes based on HID Keyboard/Keypad Usage Page (0x07) plus media keys from Generic Desktop Page (0x01) and Consumer Page (0x0C)
+ * Keycodes based on HID Keyboard/Keypad Usage Page (0x07) plus media keys
+ * from Generic Desktop Page (0x01) and Consumer Page (0x0C)
*
* See https://web.archive.org/web/20060218214400/http://www.usb.org/developers/devclass_docs/Hut1_12.pdf
* or http://www.usb.org/developers/hidpage/Hut1_12v2.pdf (older)
@@ -21,25 +23,6 @@
#define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT)
#define IS_MOUSEKEY_ACCEL(code) (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2)
-#define MOD_BIT(code) (1 << MOD_INDEX(code))
-#define MOD_INDEX(code) ((code)&0x07)
-
-#define MOD_MASK_CTRL (MOD_BIT(KC_LEFT_CTRL) | MOD_BIT(KC_RIGHT_CTRL))
-#define MOD_MASK_SHIFT (MOD_BIT(KC_LEFT_SHIFT) | MOD_BIT(KC_RIGHT_SHIFT))
-#define MOD_MASK_ALT (MOD_BIT(KC_LEFT_ALT) | MOD_BIT(KC_RIGHT_ALT))
-#define MOD_MASK_GUI (MOD_BIT(KC_LEFT_GUI) | MOD_BIT(KC_RIGHT_GUI))
-#define MOD_MASK_CS (MOD_MASK_CTRL | MOD_MASK_SHIFT)
-#define MOD_MASK_CA (MOD_MASK_CTRL | MOD_MASK_ALT)
-#define MOD_MASK_CG (MOD_MASK_CTRL | MOD_MASK_GUI)
-#define MOD_MASK_SA (MOD_MASK_SHIFT | MOD_MASK_ALT)
-#define MOD_MASK_SG (MOD_MASK_SHIFT | MOD_MASK_GUI)
-#define MOD_MASK_AG (MOD_MASK_ALT | MOD_MASK_GUI)
-#define MOD_MASK_CSA (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT)
-#define MOD_MASK_CSG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_GUI)
-#define MOD_MASK_CAG (MOD_MASK_CTRL | MOD_MASK_ALT | MOD_MASK_GUI)
-#define MOD_MASK_SAG (MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI)
-#define MOD_MASK_CSAG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI)
-
/* Short names for ease of definition of keymap */
/* Transparent */
diff --git a/src/keymap.c b/src/keymap.c
@@ -15,16 +15,100 @@
K71, K72, K73, K74, K75, K76, \
K81, K82, K83 \
) { \
- K11, K12, K13, K14, K15, K16, \
- K21, K22, K23, K24, K25, K26, \
- K31, K32, K33, K34, K35, K36, \
- 0x0, 0x0, 0x0, K44, K45, K46, \
- K56, K55, K54, K53, K52, K51, \
- K66, K65, K64, K63, K62, K61, \
- K76, K75, K74, K73, K72, K71, \
- 0x0, 0x0, 0x0, K83, K82, K81, \
+ { K11, K12, K13, K14, K15, K16 }, \
+ { K21, K22, K23, K24, K25, K26 }, \
+ { K31, K32, K33, K34, K35, K36 }, \
+ { 0x0, 0x0, 0x0, K44, K45, K46 }, \
+ { K56, K55, K54, K53, K52, K51 }, \
+ { K66, K65, K64, K63, K62, K61 }, \
+ { K76, K75, K74, K73, K72, K71 }, \
+ { 0x0, 0x0, 0x0, K83, K82, K81 } \
}
+#define LAYER_BASE_DE KEYMAP( \
+ 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 \
+)
+
+#define 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) \
+)
+
+#define LAYER_QUIX_DE KEYMAP( \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , DE_LCBR , _______ , DE_RCBR , _______ , \
+ _______ , _______ , _______ , DE_LBRC , DE_RBRC , _______ , \
+ _______ , _______ , _______ , \
+ \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ \
+)
+
+#define LAYER_SHRT_DE KEYMAP( \
+ _______ , G(KC_1) , G(KC_2) , G(KC_3) , G(KC_4) , G(KC_5) , \
+ _______ , A(KC_1) , A(KC_2) , A(KC_3) , A(KC_4) , A(KC_5) , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , \
+ \
+ _______ , G(KC_6) , G(KC_7) , G(KC_8) , G(KC_9) , G(KC_0) , \
+ _______ , A(KC_6) , A(KC_7) , A(KC_8) , A(KC_9) , A(KC_0) , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ \
+)
+
+#define LAYER_NUMS_DE KEYMAP( \
+ _______ , DE_1 , DE_2 , DE_3 , DE_4 , DE_5 , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , \
+ \
+ DE_6 , DE_7 , DE_8 , DE_9 , DE_0 , _______ , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ \
+)
+
+#define LAYER_SPEC_DE KEYMAP( \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , \
+ \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ \
+)
+
+#define LAYER_META_DE KEYMAP( \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , \
+ \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , _______ \
+)
+
enum {
BASE, /* base */
QUIK, /* symbols + nav */
@@ -36,101 +120,17 @@ enum {
META, /* functions */
};
-static const uint32_t layer_base_de[] = KEYMAP(
- 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[] = {
- [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[][KEY_ROWS][KEY_COLS] = {
+ [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;
+const uint32_t (*keymap_layers)[KEY_ROWS][KEY_COLS] = keymap_layers_de;
uint32_t keymap_layers_count = keymap_layers_de_count;
diff --git a/src/keymap.h b/src/keymap.h
@@ -1,9 +1,11 @@
#pragma once
+#include "keymat.h"
+
#include <stdint.h>
-extern const uint32_t *keymap_layers_de[];
+extern const uint32_t keymap_layers_de[][KEY_ROWS][KEY_COLS];
extern const uint32_t keymap_layers_de_count;
-extern const uint32_t **keymap_layers;
+extern const uint32_t (*keymap_layers)[KEY_ROWS][KEY_COLS];
extern uint32_t keymap_layers_count;
diff --git a/src/keymat.c b/src/keymat.c
@@ -10,11 +10,11 @@
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_row_pins) == KEY_ROWS_HALF);
static_assert(ARRLEN(keymat_col_pins) == KEY_COLS);
-bool keymat_prev[KEY_ROWS * 2][KEY_COLS];
-bool keymat[KEY_ROWS * 2][KEY_COLS];
+bool keymat_prev[KEY_ROWS][KEY_COLS];
+bool keymat[KEY_ROWS][KEY_COLS];
void
keymat_init(void)
@@ -27,22 +27,26 @@ keymat_init(void)
gpio_pull_up(keymat_col_pins[x]);
}
- for (y = 0; y < KEY_ROWS; y++) {
+ for (y = 0; y < KEY_ROWS_HALF; y++) {
gpio_init(keymat_row_pins[y]);
gpio_set_dir(keymat_row_pins[y], GPIO_OUT);
}
}
void
+keymat_next(void)
+{
+ memcpy(keymat_prev, keymat, sizeof(keymat));
+}
+
+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++) {
+ for (y = 0; y < KEY_ROWS_HALF; y++) {
gpio_put(keymat_row_pins[y], 0);
busy_wait_us(5);
for (x = 0; x < KEY_COLS; x++)
@@ -61,7 +65,7 @@ keymat_encode_half(int side)
mask = 0;
keymat_half = KEYMAT_HALF(side);
- for (y = 0; y < KEY_ROWS; y++) {
+ for (y = 0; y < KEY_ROWS_HALF; y++) {
for (x = 0; x < KEY_COLS; x++) {
if (keymat_half[y][x])
mask |= 1 << (y * KEY_COLS + x);
@@ -78,7 +82,7 @@ keymat_decode_half(int side, uint32_t mask)
uint x, y;
keymat_half = KEYMAT_HALF(side);
- for (y = 0; y < KEY_ROWS; y++) {
+ for (y = 0; y < KEY_ROWS_HALF; 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
@@ -4,17 +4,19 @@
#include <stdint.h>
-#define KEY_ROWS 4
+#define KEY_ROWS_HALF 4
+#define KEY_ROWS (KEY_ROWS_HALF * 2)
#define KEY_COLS 6
#define KEY_COUNT (KEY_ROWS * KEY_COLS)
-#define KEYMAT_HALF(side) ((side) == LEFT ? &keymat[0] : &keymat[KEY_ROWS])
+#define KEYMAT_HALF(side) ((side) == LEFT ? &keymat[0] : &keymat[KEY_ROWS_HALF])
void keymat_init(void);
+void keymat_next(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];
+extern bool keymat_prev[KEY_ROWS][KEY_COLS];
+extern bool keymat[KEY_ROWS][KEY_COLS];
diff --git a/src/keysym.h b/src/keysym.h
@@ -1,11 +1,13 @@
#pragma once
+#include "keycode.h"
+
#define XXXXXXX KC_NO
#define _______ KC_TRNS
-#define MASK(hi, lo) ((1 << hi) - (1 << lo))
+#define MASK(hi, lo) ((1 << (hi)) - (1 << (lo)))
-#define IS_CODE(x) (!((x) & MASK(B_MAX, 8)))
+#define IS_CODE(x) (!((x) & MASK(B_MODMAX+1, B_MODMIN)))
#define IS_CTRL(x) ((x) & (1 << B_CTRL))
#define IS_SHIFT(x) ((x) & (1 << B_SHIFT))
#define IS_ALT(x) ((x) & (1 << B_ALT))
@@ -46,6 +48,9 @@
#define CS(x) C(MO(x))
#define GS(x) G(MO(x))
+#define B_MODMIN B_TOGGLE
+#define B_MODMAX B_MODSWT
+
enum {
B_CTRL = 8,
B_SHIFT,
@@ -55,6 +60,5 @@ enum {
B_TOGGLE,
B_SWITCH,
B_MODSWT,
- B_MAX
};
diff --git a/src/split.c b/src/split.c
@@ -23,7 +23,7 @@
#include <stdint.h>
#define UART_TIMEOUT 20
-#define UART_BAUD 9600
+#define UART_BAUD 115200
#if SPLIT_SIDE == LEFT
#define UART_TX_PIN 0
@@ -272,6 +272,7 @@ split_task(void)
scan_pending = true;
cmd = CMD_SCAN_KEYMAT_REQ;
ASSERT(uart_send(&cmd, 1) == 1);
+ keymat_next();
keymat_scan(); /* scan our side in parallel */
start_ms = board_millis();
while (scan_pending && board_millis() < start_ms + 20) {
diff --git a/src/util.c b/src/util.c
@@ -11,7 +11,7 @@
#include <stdio.h>
-int loglevel = LOG_DEBUG;
+int loglevel = LOG_INFO;
static void
__attribute__((format(printf, 1, 0)))