Browse Source

Clean up after refactor, better HID constants.

xmkb
Pete Johanson 4 years ago
parent
commit
ec663310c1
  1. 1
      app/CMakeLists.txt
  2. 25
      app/boards/native_posix.overlay
  3. 11
      app/boards/shields/kyria/keymap/keymap.overlay
  4. 5
      app/boards/shields/kyria/keymaps/default/include/keymap.h
  5. 34
      app/boards/shields/kyria/keymaps/default/keymap.c
  6. 28
      app/boards/shields/petejohanson_proton_handwire/keymap/keymap.overlay
  7. 4
      app/dts/bindings/zmk,layers.yaml
  8. 233
      app/include/dt-bindings/zmk/keys.h
  9. 2
      app/include/zmk/hid.h
  10. 4
      app/src/ble.c
  11. 88
      app/src/handlers.c
  12. 42
      app/src/hid.c

1
app/CMakeLists.txt

@ -46,5 +46,4 @@ target_sources_ifdef(CONFIG_ZMK_USB app PRIVATE src/usb_hid.c)
target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/hog.c) target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/hog.c)
target_sources(app PRIVATE src/endpoints.c) target_sources(app PRIVATE src/endpoints.c)
target_sources(app PRIVATE src/main.c) target_sources(app PRIVATE src/main.c)
target_sources(app PRIVATE src/handlers.c)

25
app/boards/native_posix.overlay

@ -54,39 +54,26 @@
default: layer_0 { default: layer_0 {
label = "DEFAULT"; label = "DEFAULT";
keys =
<
KC_A MT(MOD_LSFT, KC_B) KC_C KC_D
KC_E KC_F KC_G KC_H
>;
bindings = < bindings = <
&kp 5 &mo 1 &kp 10 &kp 11 &kp B &mo A &kp C &kp E
&kp 1 &kp 2 &kp 4 &kp 89>; &kp D &kp G &kp F &kp Q>;
}; };
lower: layer_1 { lower: layer_1 {
label = "LOWER"; label = "LOWER";
keys = <
KC_A KC_B KC_C KC_D
KC_E KC_F KC_G KC_H
>;
bindings = < bindings = <
&kp 20 &trans &kp 18 &kp 19 &kp N &trans &kp O &kp Q
&kp 21 &kp 22 &kp 24 &kp 49>; &kp L &kp J &kp P &kp K>;
}; };
raise: layer_2 { raise: layer_2 {
label = "RAISE"; label = "RAISE";
keys = <
KC_E KC_F KC_G KC_H
KC_A KC_B KC_C KC_D
>;
bindings = < bindings = <
&kp 5 &kp 0 &kp 10 &kp 11 &kp W &kp U &kp I &kp N
&kp 1 &kp 2 &kp 4 &kp 89>; &kp X &kp M &kp C &kp B>;
}; };
}; };
}; };

11
app/boards/shields/kyria/keymaps/default/keymap.overlay → app/boards/shields/kyria/keymap/keymap.overlay

@ -1,7 +1,6 @@
#include <behaviors.dtsi> #include <behaviors.dtsi>
#include <dt-bindings/zmk/keys.h> #include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/matrix-transform.h> #include <dt-bindings/zmk/matrix-transform.h>
#include <keymap.h>
/ { / {
chosen { chosen {
@ -24,11 +23,11 @@
// | <- | A | S | D | F | G | | H | J | K | L | ; | ' | // | <- | A | S | D | F | G | | H | J | K | L | ; | ' |
// | SHIFT | Z | X | C | V | B | L SHIFT | L SHIFT | | L SHIFT | L SHIFT | N | M | , | . | / | - | // | SHIFT | Z | X | C | V | B | L SHIFT | L SHIFT | | L SHIFT | L SHIFT | N | M | , | . | / | - |
// | GUI | DEL | RET | SPACE | ESC | | RET | SPACE | TAB | BSPC | R-ALT | // | GUI | DEL | RET | SPACE | ESC | | RET | SPACE | TAB | BSPC | R-ALT |
keys = < bindings = <
KC_ESC KC_Q KC_W KC_E KC_R KC_T KC_Y KC_U KC_I KC_O KC_P KC_PIPE &kp ESC &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp 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 &kp BKSP &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN &kp 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 &kp LSFT &kp Z &kp X &kp C &kp V &kp B &kp LSFT &kp LSFT &kp LSFT &kp LSFT &kp N &kp M &kp CMMA &kp DOT &kp BSLH &kp MINUS
KC_LGUI KC_DEL KC_RET KC_SPC KC_ESC KC_RET KC_SPC KC_TAB KC_BKSP KC_RALT &kp LGUI &kp DEL &kp RET &kp SPC &kp ESC &kp RET &kp SPC &kp TAB &kp BKSP &kp RALT
>; >;
}; };
}; };

5
app/boards/shields/kyria/keymaps/default/include/keymap.h

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

34
app/boards/shields/kyria/keymaps/default/keymap.c

@ -1,34 +0,0 @@
#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;
};

28
app/boards/shields/petejohanson_proton_handwire/keymap/keymap.overlay

@ -17,36 +17,26 @@
default: layer_0 { default: layer_0 {
label = "DEFAULT"; label = "DEFAULT";
keys =
<
KC_A MT(MOD_LSFT, KC_B)
CC_RAIS CC_LOWR
>;
bindings = < bindings = <
&reset &kp 0 &reset &kp A
&kp 1 &kp 2>; &kp B &kp C>;
}; };
lower: layer_1 { lower: layer_1 {
label = "LOWER"; label = "LOWER";
keys = <
KC_MPLY KC_MNXT
ZC_TRNS ZC_TRNS
>;
bindings = < bindings = <
&reset &kp 0 &reset &kp D
&kp 1 &kp 2>; &kp F &kp E>;
}; };
raise: layer_2 { raise: layer_2 {
label = "RAISE"; label = "RAISE";
keys = <
KC_C KC_D
ZC_TRNS ZC_TRNS
>;
bindings = < bindings = <
&reset &kp 0 &reset &kp I
&kp 1 &kp 2>; &kp G &kp H>;
}; };
}; };
}; };

4
app/dts/bindings/zmk,layers.yaml

@ -9,7 +9,7 @@ child-binding:
properties: properties:
label: label:
type: string type: string
keys: required: true
type: array
bindings: bindings:
type: phandle-array type: phandle-array
required: true

233
app/include/dt-bindings/zmk/keys.h

@ -1,122 +1,117 @@
#pragma once #pragma once
#define KC_A 0x04 #define A 0x04
#define KC_B 0x05 #define B 0x05
#define KC_C 0x06 #define C 0x06
#define KC_D 0x07 #define D 0x07
#define KC_E 0x08 #define E 0x08
#define KC_F 0x09 #define F 0x09
#define KC_G 0x0A #define G 0x0A
#define KC_H 0x0B #define H 0x0B
#define KC_I 0x0C #define I 0x0C
#define KC_J 0x0D #define J 0x0D
#define KC_K 0x0E #define K 0x0E
#define KC_L 0x0F #define L 0x0F
#define KC_M 0x10 #define M 0x10
#define KC_N 0x11 #define N 0x11
#define KC_O 0x12 #define O 0x12
#define KC_P 0x13 #define P 0x13
#define KC_Q 0x14 #define Q 0x14
#define KC_R 0x15 #define R 0x15
#define KC_S 0x16 #define S 0x16
#define KC_T 0x17 #define T 0x17
#define KC_U 0x18 #define U 0x18
#define KC_V 0x19 #define V 0x19
#define KC_W 0x1A #define W 0x1A
#define KC_X 0x1B #define X 0x1B
#define KC_Y 0x1C #define Y 0x1C
#define KC_Z 0x1D #define Z 0x1D
#define KC_1 0x1E #define NUM_1 0x1E
#define KC_2 0x1F #define NUM_2 0x1F
#define KC_3 0x20 #define NUM_3 0x20
#define KC_4 0x21 #define NUM_4 0x21
#define KC_5 0x22 #define NUM_5 0x22
#define KC_6 0x23 #define NUM_6 0x23
#define KC_7 0x24 #define NUM_7 0x24
#define KC_8 0x25 #define NUM_8 0x25
#define KC_9 0x26 #define NUM_9 0x26
#define KC_0 0x27 #define NUM_0 0x27
#define KC_RET 0x28 #define RET 0x28
#define KC_ESC 0x29 #define ESC 0x29
#define KC_DEL 0x2A #define DEL 0x2A
#define KC_BKSP KC_DEL #define BKSP DEL
#define KC_TAB 0x2B #define TAB 0x2B
#define KC_SPC 0x2C #define SPC 0x2C
#define KC_MIN 0x2D #define MINUS 0x2D
#define KC_EQL 0x2E #define EQL 0x2E
#define KC_LBKT 0x2F #define LBKT 0x2F
#define KC_RBKT 0x30 #define RBKT 0x30
#define KC_FSLH 0x31 #define FSLH 0x31
#define KC_SCLN 0x33 #define SCLN 0x33
#define KC_QUOT 0x34 #define QUOT 0x34
#define KC_GRAV 0x35 #define GRAV 0x35
#define KC_CMMA 0x36 #define CMMA 0x36
#define KC_DOT 0x37 #define DOT 0x37
#define KC_BSLH 0x38 #define BSLH 0x38
#define KC_CLCK 0x39 #define CLCK 0x39
#define KC_F1 0x3A #define F1 0x3A
#define KC_F2 0x3B #define F2 0x3B
#define KC_RARW 0x4F #define RARW 0x4F
#define KC_LARW 0x50 #define LARW 0x50
#define KC_DARW 0x51 #define DARW 0x51
#define KC_UARW 0x52 #define UARW 0x52
#define KC_KDIV 0x54 #define KDIV 0x54
#define KC_KMLT 0x55 #define KMLT 0x55
#define KC_KMIN 0x56 #define KMIN 0x56
#define KC_KPLS 0x57 #define KPLS 0x57
#define KC_APP 0x65 #define GUI 0x65
#define KC_CURU 0xB4 #define CURU 0xB4
#define KC_LPRN 0xB6 #define LPRN 0xB6
#define KC_RPRN 0xB7 #define RPRN 0xB7
#define KC_LCUR 0xB8 #define LCUR 0xB8
#define KC_RCUR 0xB9 #define RCUR 0xB9
#define KC_CRRT 0xC3 #define CRRT 0xC3
#define KC_PRCT 0xC4 #define PRCT 0xC4
#define KC_LABT 0xC5 #define LABT 0xC5
#define KC_RABT 0xC6 #define RABT 0xC6
#define KC_AMPS 0xC7 #define AMPS 0xC7
#define KC_PIPE 0xC9 #define PIPE 0xC9
#define KC_COLN 0xCB #define COLN 0xCB
#define KC_HASH 0xCC #define HASH 0xCC
#define KC_KSPC 0xCD #define KSPC 0xCD
#define KC_ATSN 0xCE #define ATSN 0xCE
#define KC_BANG 0xCF #define BANG 0xCF
#define KC_LCTL 0xE0 #define LCTL 0xE0
#define KC_LSFT 0xE1 #define LSFT 0xE1
#define KC_LALT 0xE2 #define LALT 0xE2
#define KC_LGUI 0xE3 #define LGUI 0xE3
#define KC_RCTL 0xE4 #define RCTL 0xE4
#define KC_RSFT 0xE5 #define RSFT 0xE5
#define KC_RALT 0xE6 #define RALT 0xE6
#define KC_RGUI 0xE7 #define RGUI 0xE7
#define KC_VOLU 0x80 #define VOLU 0x80
#define KC_VOLD 0x81 #define VOLD 0x81
/* The following are select consumer page usages */ /* The following are select consumer page usages */
#define KC_MNXT 0x100 #define MNXT 0x100
#define KC_MPRV 0x101 #define MPRV 0x101
#define KC_MSTP 0x102 #define MSTP 0x102
#define KC_MJCT 0x103 #define MJCT 0x103
#define KC_MPLY 0x104 #define MPLY 0x104
#define KC_MMUT 0x105 #define MMUT 0x105
#define KC_MVLU 0x106 #define MVLU 0x106
#define KC_MVLD 0x107 #define MVLD 0x107
#define ZC_TRNS (0xFFFF)
#define ZC_NO (0xFFFF - 1)
#define ZC_CSTM(n) (0xFFF + n)
#define MOD_LCTL (1 << 0x00) #define MOD_LCTL (1 << 0x00)
#define MOD_LSFT (1 << 0x01) #define MOD_LSFT (1 << 0x01)
@ -127,16 +122,4 @@
#define MOD_RALT (1 << 0x06) #define MOD_RALT (1 << 0x06)
#define MOD_RGUI (1 << 0x07) #define MOD_RGUI (1 << 0x07)
#define ZK_ACTION(k) (k >> 24)
#define _ACTION(a) (a << 24)
#define _ACTION_MODS(m) (m << 16)
#define ZK_KEY(a) (a & 0xFFFF)
#define ZK_MODS(a) ((a >> 16) & 0xFF)
#define ZK_IS_CONSUMER(k) (ZK_KEY(k) >= 0x100) #define ZK_IS_CONSUMER(k) (ZK_KEY(k) >= 0x100)
#define ZMK_ACTION_KEY 0x01
#define ZMK_ACTION_MOD_TAP 0x01
#define ZMK_ACTION_ONE_SHOT 0x02
#define MT(mods, kc) (_ACTION(ZMK_ACTION_MOD_TAP) + _ACTION_MODS(mods) + kc)

2
app/include/zmk/hid.h

@ -9,7 +9,7 @@
#define COLLECTION_REPORT 0x03 #define COLLECTION_REPORT 0x03
#define ZMK_HID_MAX_KEYCODE KC_APP #define ZMK_HID_MAX_KEYCODE GUI
static const u8_t zmk_hid_report_desc[] = { static const u8_t zmk_hid_report_desc[] = {
/* USAGE_PAGE (Generic Desktop) */ /* USAGE_PAGE (Generic Desktop) */

4
app/src/ble.c

@ -168,12 +168,12 @@ bool zmk_ble_handle_key_user(struct zmk_key_event *key_event)
return true; return true;
} }
if (key < KC_1 || key > KC_0) if (key < NUM_1 || key > NUM_0)
{ {
return true; return true;
} }
u32_t val = (key == KC_0) ? 0 : (key - KC_1 + 1); u32_t val = (key == NUM_0) ? 0 : (key - NUM_1 + 1);
passkey_entries[passkey_digit++] = val; passkey_entries[passkey_digit++] = val;

88
app/src/handlers.c

@ -1,88 +0,0 @@
#include <zmk/ble.h>
#include <zmk/handlers.h>
#include <zmk/endpoints.h>
#include <zmk/hid.h>
#include <zmk/matrix.h>
#ifdef CONFIG_ZMK_ACTION_MOD_TAP
u16_t action_effect_pending = 0;
#endif
__attribute__((weak)) bool zmk_handle_key_user(struct zmk_key_event *key_event)
{
return true;
};
bool zmk_handle_action(zmk_action action, struct zmk_key_event *key_event)
{
zmk_mod mods = ZK_MODS(key_event->key);
u8_t flattened_index = (key_event->row * ZMK_MATRIX_COLS) + key_event->column;
switch (action)
{
#ifdef CONFIG_ZMK_ACTION_MOD_TAP
case ZMK_ACTION_MOD_TAP:
if (key_event->pressed)
{
WRITE_BIT(action_effect_pending, flattened_index, true);
zmk_hid_register_mods(mods);
}
else
{
zmk_hid_unregister_mods(mods);
if (action_effect_pending & BIT(flattened_index))
{
struct zmk_key_event non_mod_event =
{
.row = key_event->row,
.column = key_event->column,
.key = ZK_KEY(key_event->key),
.pressed = true};
zmk_handle_key(non_mod_event);
// A small sleep is needed to ensure device layer sends initial
// key, before we send the release.
k_msleep(10);
non_mod_event.pressed = false;
zmk_handle_key(non_mod_event);
}
else
{
// Since not sending a keycode, at least send the report w/ the mod removed
zmk_endpoints_send_report(Keypad);
}
}
break;
#endif
}
return false;
};
void zmk_handle_key(struct zmk_key_event key_event)
{
zmk_action action = ZK_ACTION(key_event.key);
if (!zmk_handle_key_user(&key_event))
{
return;
}
if (action && !zmk_handle_action(action, &key_event))
{
return;
}
#ifdef CONFIG_ZMK_ACTION_MOD_TAP
action_effect_pending = 0;
#endif
#ifdef CONFIG_ZMK_BLE
/* Used for intercepting key presses when doing passkey verification */
if (!zmk_ble_handle_key_user(&key_event))
{
return;
}
#endif /* CONFIG_ZMK_BLE */
zmk_endpoints_send_key_event(key_event);
};

42
app/src/hid.c

@ -66,19 +66,19 @@ int zmk_hid_unregister_mods(zmk_mod_flags modifiers)
enum zmk_hid_report_changes zmk_hid_press_key(zmk_key code) enum zmk_hid_report_changes zmk_hid_press_key(zmk_key code)
{ {
if (code >= KC_LCTL && code <= KC_RGUI) if (code >= LCTL && code <= RGUI)
{ {
return zmk_hid_register_mod(code - KC_LCTL); return zmk_hid_register_mod(code - LCTL);
} }
if (ZK_IS_CONSUMER(code)) // if (ZK_IS_CONSUMER(code))
{ // {
LOG_DBG("Toggling a consumer key!"); // LOG_DBG("Toggling a consumer key!");
TOGGLE_CONSUMER(code, true); // TOGGLE_CONSUMER(code, true);
return Consumer; // return Consumer;
} // }
else // else
{ // {
if (code > ZMK_HID_MAX_KEYCODE) if (code > ZMK_HID_MAX_KEYCODE)
{ {
return -EINVAL; return -EINVAL;
@ -89,23 +89,23 @@ enum zmk_hid_report_changes zmk_hid_press_key(zmk_key code)
TOGGLE_KEY(code, true); TOGGLE_KEY(code, true);
return Keypad; return Keypad;
} // }
}; };
enum zmk_hid_report_changes zmk_hid_release_key(zmk_key code) enum zmk_hid_report_changes zmk_hid_release_key(zmk_key code)
{ {
if (code >= KC_LCTL && code <= KC_RGUI) if (code >= LCTL && code <= RGUI)
{ {
return zmk_hid_unregister_mod(code - KC_LCTL); return zmk_hid_unregister_mod(code - LCTL);
} }
if (ZK_IS_CONSUMER(code)) // if (ZK_IS_CONSUMER(code))
{ // {
TOGGLE_CONSUMER(code, false); // TOGGLE_CONSUMER(code, false);
return Consumer; // return Consumer;
} // }
else // else
{ // {
if (code > ZMK_HID_MAX_KEYCODE) if (code > ZMK_HID_MAX_KEYCODE)
{ {
return -EINVAL; return -EINVAL;
@ -116,7 +116,7 @@ enum zmk_hid_report_changes zmk_hid_release_key(zmk_key code)
TOGGLE_KEY(code, false); TOGGLE_KEY(code, false);
return Keypad; return Keypad;
} // }
}; };
struct zmk_hid_keypad_report *zmk_hid_get_keypad_report() struct zmk_hid_keypad_report *zmk_hid_get_keypad_report()

Loading…
Cancel
Save