commit e4783bbcc4214416befceb53f6af9ebdfb35ba86
parent 8e60c68eac5dbe749c80d1b42160ad1f7de42200
Author: Louis Burda <quent.burda@gmail.com>
Date: Mon, 19 Dec 2022 00:33:54 +0100
Add more keys to keymap and add split role detection
Diffstat:
10 files changed, 73 insertions(+), 51 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -50,10 +50,10 @@ target_compile_options(pico_stdio INTERFACE
-Wno-unused-parameter
)
-target_compile_options(${PROJECT} PRIVATE
- "-DSPLIT_SIDE=${SPLIT_SIDE}"
- "-DSPLIT_ROLE=${SPLIT_ROLE}"
-)
+target_compile_options(${PROJECT} PRIVATE "-DSPLIT_SIDE=${SPLIT_SIDE}")
+if(DEFINED SPLIT_ROLE)
+target_compile_options(${PROJECT} PRIVATE "-DSPLIT_ROLE=${SPLIT_ROLE}")
+endif(DEFINED SPLIT_ROLE)
family_configure_target(${PROJECT})
family_add_default_example_warnings(${PROJECT})
diff --git a/Makefile b/Makefile
@@ -1,19 +1,21 @@
FAMILY ?= rp2040
PICO_SDK_PATH ?= lib/picosdk
+CMAKE_FLAGS = -DFAMILY=$(FAMILY) -DPICO_SDK_PATH=$(PICO_SDK_PATH)
+CMAKE_FLAGS_LEFT = $(CMAKE_FLAGS) -DSPLIT_SIDE=LEFT $(CMAKE_FLAGS_LEFT_EXTRA)
+CMAKE_FLAGS_RIGHT = $(CMAKE_FLAGS) -DSPLIT_SIDE=RIGHT $(CMAKE_FLAGS_RIGHT_EXTRA)
+
all: left right
clean:
rm -rf .build
left: | $(PICO_SDK_PATH) .build/left
- cmake -B .build/left -DFAMILY=$(FAMILY) -DPICO_SDK_PATH=$(PICO_SDK_PATH) \
- -DSPLIT_SIDE=LEFT -DSPLIT_ROLE=SLAVE
+ cmake -B .build/left $(CMAKE_FLAGS_LEFT)
make -C .build/left
right: | $(PICO_SDK_PATH) .build/right
- cmake -B .build/right -DFAMILY=$(FAMILY) -DPICO_SDK_PATH=$(PICO_SDK_PATH) \
- -DSPLIT_SIDE=RIGHT -DSPLIT_ROLE=MASTER
+ cmake -B .build/right $(CMAKE_FLAGS_RIGHT)
make -C .build/right
lib/picosdk:
diff --git a/src/hid.c b/src/hid.c
@@ -162,7 +162,7 @@ update_report(void)
for (y = 0; y < KEY_ROWS; y++) {
for (x = 0; x < KEY_COLS; x++) {
if (keymat[y][x] != keymat_prev[y][x]) {
- if (bounce_mat[y][x] > now_us - 25000) {
+ if (bounce_mat[y][x] > now_us - 50000) {
WARN("Bouncing prevented %i vs %i",
keymat[y][x], keymat_prev[y][x]);
keymat[y][x] = keymat_prev[y][x];
diff --git a/src/keycode.h b/src/keycode.h
@@ -13,9 +13,9 @@
#define IS_KEY(code) (KC_A <= (code) && (code) <= KC_EXSEL)
#define IS_MOD(code) (KC_LEFT_CTRL <= (code) && (code) <= KC_RIGHT_GUI)
-#define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF))
-#define IS_SYSTEM(code) (KC_PWR <= (code) && (code) <= KC_WAKE)
-#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_BRID)
+// #define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF))
+// #define IS_SYSTEM(code) (KC_PWR <= (code) && (code) <= KC_WAKE)
+// #define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_BRID)
#define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2)
#define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT)
diff --git a/src/keymap.c b/src/keymap.c
@@ -31,7 +31,7 @@
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_J , DE_L , DE_U , DE_Y , DE_HASH , DE_SS , \
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 \
@@ -64,7 +64,7 @@
#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_TAB),G(DE_DOT), A(DE_B) , A(DE_F) ,A(KC_SPC), \
_______ , _______ , _______ , \
\
_______ , G(KC_6) , G(KC_7) , G(KC_8) , G(KC_9) , G(KC_0) , \
@@ -75,7 +75,7 @@
#define LAYER_NUMS_DE KEYMAP( \
_______ , DE_1 , DE_2 , DE_3 , DE_4 , DE_5 , \
- _______ , _______ , _______ , _______ , _______ , _______ , \
+ KC_TAB , _______ , _______ , _______ , _______ , _______ , \
_______ , _______ , _______ , _______ , _______ , _______ , \
_______ , _______ , _______ , \
\
@@ -86,26 +86,26 @@
)
#define LAYER_SPEC_DE KEYMAP( \
- _______ , _______ , _______ , _______ , _______ , _______ , \
- _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , DE_AT , _______ , _______ , _______ , \
+ _______ , DE_ADIA , _______ , _______ , _______ , _______ , \
_______ , _______ , _______ , _______ , _______ , _______ , \
_______ , _______ , _______ , \
\
- _______ , _______ , _______ , _______ , _______ , _______ , \
- _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , _______ , DE_UDIA , DE_ACUT , _______ , KC_DEL , \
+ _______ , _______ , _______ , _______ , DE_ODIA , _______ , \
_______ , _______ , _______ , _______ , _______ , _______ , \
_______ , _______ , _______ \
)
#define LAYER_META_DE KEYMAP( \
+ _______ , SX(KVM1), SX(KVM2), _______ , _______ , _______ , \
_______ , _______ , _______ , _______ , _______ , _______ , \
- _______ , _______ , _______ , _______ , _______ , _______ , \
- _______ , _______ , _______ , _______ , _______ , _______ , \
+ KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , KC_F6 , \
_______ , _______ , _______ , \
\
- _______ , _______ , _______ , _______ , _______ , _______ , \
- _______ , _______ , _______ , _______ , _______ , _______ , \
- _______ , _______ , _______ , _______ , _______ , _______ , \
+ _______ , KC_VOLD , KC_VOLU , KC_MUTE , _______ , _______ , \
+ _______ , KC_MPRV , KC_MNXT , KC_MPLY , _______ , _______ , \
+ KC_F7 , KC_F8 , KC_F9 , KC_F10 , KC_F11 , KC_F12 , \
_______ , _______ , _______ \
)
@@ -120,6 +120,11 @@ enum {
META, /* functions */
};
+enum {
+ KVM1,
+ KVM2
+};
+
const uint32_t keymap_layers_de[][KEY_ROWS][KEY_COLS] = {
[BASE] = LAYER_BASE_DE,
[QUIK] = LAYER_QUIK_DE,
diff --git a/src/keysym.h b/src/keysym.h
@@ -5,17 +5,18 @@
#define XXXXXXX KC_NO
#define _______ KC_TRNS
-#define MASK(hi, lo) ((1 << (hi)) - (1 << (lo)))
+#define MASK(hi, lo) ((1U << (hi)) - (1U << (lo)))
-#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))
-#define IS_GUI(x) ((x) & (1 << B_GUI))
-#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 IS_CODE(x) (!((x) & ~MASK(B_TOGGLE, 0)))
+#define IS_CTRL(x) ((x) & (1 << B_CTRL))
+#define IS_SHIFT(x) ((x) & (1 << B_SHIFT))
+#define IS_ALT(x) ((x) & (1 << B_ALT))
+#define IS_GUI(x) ((x) & (1 << B_GUI))
+#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 IS_SPECIAL(x) ((x) & (1 << B_SPECIAL))
#define TO_CODE(x) ((x) & 0xFF)
#define TO_LAYER(x) ((x) & 0xFF)
@@ -29,6 +30,11 @@
#define RALT(x) (LALT(x) | (1 << B_RIGHT))
#define RGUI(x) (LGUI(x) | (1 << B_RIGHT))
+#define SW(x) ((x) | (1 << B_SWITCH))
+#define TO(x) ((x) | (1 << B_TOGGLE))
+#define MO(x) ((x) | (1 << B_MODSWT))
+#define SX(x) ((x) | (1 << B_SPECIAL))
+
#define LOPT(x) LALT(x)
#define LCMD(x) LGUI(x)
#define LWIN(x) LGUI(x)
@@ -41,16 +47,9 @@
#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))
-#define B_MODMIN B_TOGGLE
-#define B_MODMAX B_MODSWT
-
enum {
B_CTRL = 8,
B_SHIFT,
@@ -60,5 +59,6 @@ enum {
B_TOGGLE,
B_SWITCH,
B_MODSWT,
+ B_SPECIAL
};
diff --git a/src/main.c b/src/main.c
@@ -56,6 +56,9 @@ main(void)
void
tud_mount_cb(void)
{
+#ifndef SPLIT_ROLE
+ split_role = MASTER;
+#endif
led_rgb = WS2812_U32RGB(100, 0, 100);
led_mode = LED_ON;
led_reset = true;
@@ -73,6 +76,9 @@ tud_umount_cb(void)
void
tud_suspend_cb(bool remote_wakeup_en)
{
+#ifndef SPLIT_ROLE
+ split_role = SLAVE;
+#endif
led_rgb = WS2812_U32RGB(100, 100, 100);
led_mode = LED_ON;
led_reset = true;
diff --git a/src/split.c b/src/split.c
@@ -64,6 +64,8 @@ static uint uart_rx_sm_offset;
static uint32_t halfmat;
static bool scan_pending = false;
+int split_role;
+
void
uart_tx_sm_init(void)
{
@@ -218,14 +220,14 @@ handle_cmd(uint8_t cmd)
switch (cmd) {
case CMD_SCAN_KEYMAT_REQ:
- if (SPLIT_ROLE != SLAVE) {
+ if (split_role != SLAVE) {
WARN("Got SCAN_KEYMAT_REQ as master");
break;
}
scan_pending = true;
return;
case CMD_SCAN_KEYMAT_RESP:
- if (SPLIT_ROLE != MASTER) {
+ if (split_role != MASTER) {
WARN("Got SCAN_KEYMAT_RESP as slave");
break;
}
@@ -234,7 +236,7 @@ handle_cmd(uint8_t cmd)
scan_pending = false;
return;
case CMD_STDIO_PUTS:
- if (SPLIT_ROLE != MASTER) {
+ if (split_role != MASTER) {
WARN("Got STDIO_PUTS as slave");
break;
}
@@ -260,6 +262,11 @@ void
split_init(void)
{
uart_full_init();
+#ifdef SPLIT_ROLE
+ split_role = SPLIT_ROLE;
+#else
+ split_role = SLAVE;
+#endif
}
void
@@ -268,7 +275,7 @@ split_task(void)
uint32_t start_ms;
uint8_t cmd;
- if (SPLIT_ROLE == MASTER) {
+ if (split_role == MASTER) {
scan_pending = true;
cmd = CMD_SCAN_KEYMAT_REQ;
ASSERT(uart_send(&cmd, 1) == 1);
diff --git a/src/split.h b/src/split.h
@@ -10,3 +10,5 @@
void split_init(void);
void split_task(void);
+
+extern int split_role;
diff --git a/src/usb_descriptors.c b/src/usb_descriptors.c
@@ -113,10 +113,10 @@ tusb_desc_device_qualifier_t const desc_device_qualifier =
#endif
char const *string_desc_arr[] = {
- [0] = (const char[]) { 0x09, 0x04 }, /* Supported language is English */
- [1] = "TinyUSB", /* Manufacturer */
- [2] = "TinyUSB Device", /* Product */
- [3] = "123456", /* Serials, should use chip ID */
+ [0] = "\x09\x04\x09\x00", /* bCountryCode: Germany */
+ [1] = "TinyUSB", /* Manufacturer */
+ [2] = "TinyUSB Device", /* Product */
+ [3] = "123456", /* Serials, should use chip ID */
[4] = "SXKBD CDC",
[5] = "SXKBD HID"
};
@@ -162,8 +162,8 @@ tud_descriptor_string_cb(uint8_t index, uint16_t langid)
(void) langid;
if (index == 0) {
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
+ memcpy(&_desc_str[1], string_desc_arr[0], 4);
+ chr_count = 2;
} else {
if (index >= ARRLEN(string_desc_arr))
return NULL;