Initial work on keymap transforms for non-standard matrixes.

* Allows "gaps" for keyboards like Kyra.
* Allows keyboards with matrixes that don't map the logical key
  locations to have normal looking keymaps when defined.
This commit is contained in:
Pete Johanson
2020-06-15 17:03:34 -04:00
parent 0712dadd29
commit 1751470785
12 changed files with 1028 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
if SHIELD_KYRIA
config ZMK_KEYBOARD_NAME
default "Kyria"
endif

View File

@@ -0,0 +1,5 @@
# Copyright (c) 2020 Pete Johanson
# SPDX-License-Identifier: MIT
config SHIELD_KYRIA
def_bool $(shields_list_contains,kyria)

View File

@@ -0,0 +1,5 @@
#include <dt-bindings/zmk/keys.h>
#define CC_RAIS ZC_CSTM(1)
#define CC_LOWR ZC_CSTM(2)

View File

@@ -0,0 +1,34 @@
#include <zmk/keys.h>
#include <zmk/keymap.h>
#include <keymap.h>
bool zmk_handle_key_user(struct zmk_key_event *key_event)
{
switch (key_event->key)
{
case CC_LOWR:
if (key_event->pressed)
{
zmk_keymap_layer_activate(1);
}
else
{
zmk_keymap_layer_deactivate(1);
}
return false;
case CC_RAIS:
if (key_event->pressed)
{
zmk_keymap_layer_activate(2);
}
else
{
zmk_keymap_layer_deactivate(2);
}
return false;
}
return true;
};

View File

@@ -0,0 +1,50 @@
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/keymap-transform.h>
#include <keymap.h>
/ {
chosen {
zmk,keymap = &keymap0;
};
keymap0: keymap {
compatible = "zmk,keymap";
label ="Default Kyria Keymap";
layers = <&default>;
transform = <&default_transform>;
};
default_transform: keymap_transform_0 {
compatible = "zmk,keymap-transform";
map = <
IDENTITY_ROW(0, 6) OFFSET_ROW(6, 0, 6)
IDENTITY_ROW(1, 6) OFFSET_ROW(6, 1, 6)
IDENTITY_ROW(2, 8) OFFSET_ROW(8, 2, 8)
OFFSET_ROW(3, 3, 5) OFFSET_ROW(8, 3, 5)
>;
};
five_column_transform: keymap_transform_1 {
compatible = "zmk,keymap-transform";
map = <
IDENTITY_ROW(0, 5) OFFSET_ROW(5, 0, 5)
IDENTITY_ROW(1, 5) OFFSET_ROW(6, 1, 5)
IDENTITY_ROW(2, 7) OFFSET_ROW(7, 2, 7)
OFFSET_ROW(2, 3, 5) OFFSET_ROW(7, 3, 5)
>;
};
layers {
compatible = "zmk,layers";
default: layer_0 {
label = "DEFAULT";
keys = <
KC_ESC KC_Q KC_W KC_E KC_R KC_T KC_Y KC_U KC_I KC_O KC_P KC_PIPE
KC_BKSP KC_A KC_S KC_D KC_F KC_G KC_H KC_J KC_K KC_L KC_SCLN KC_QUOT
KC_LSFT KC_Z KC_X KC_C KC_V KC_B KC_LSFT KC_LSFT KC_LSFT KC_LSFT KC_N KC_M KC_CMMA KC_DOT KC_BSLH KC_MIN
KC_LGUI KC_DEL KC_RET KC_SPC KC_ESC KC_RET KC_SPC KC_TAB KC_BKSP KC_RALT
>;
};
};
};

View File

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 2020 Pete Johanson
*
* SPDX-License-Identifier: MIT
*/
/ {
chosen {
zmk,kscan = &kscan0;
};
kscan0: kscan_comp {
compatible = "zmk,kscan-composite";
label = "KSCAN_COMP";
rows = <4>;
columns = <16>;
left {
kscan = <&kscan_left>;
};
right {
kscan = <&kscan_right>;
// TODO: Actually put this in the kscan driver, so it can report
// HID events directly to host if plugged in directly.
column-offset = <8>;
};
};
kscan_left: kscan_left {
compatible = "gpio-kscan";
label = "KSCAN_LEFT";
diode-direction = "row2col";
row-gpios = <&pro_micro_pins 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
col-gpios = <&pro_micro_pins 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 16 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 18 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 19 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 20 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 21 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
};
kscan_right: kscan_right {
compatible = "gpio-kscan";
label = "KSCAN_RIGHT";
diode-direction = "row2col";
row-gpios = <&pro_micro_pins 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
col-gpios = <&pro_micro_pins 21 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 20 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 19 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 18 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 16 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_pins 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
};
// TODO: Encoder node(s)
// TODO: OLED node
// TODO: RGB node(s)
};