Pete Johanson
4 years ago
12 changed files with 155 additions and 324 deletions
@ -1,5 +0,0 @@
@@ -1,5 +0,0 @@
|
||||
|
||||
#include <dt-bindings/zmk/keys.h> |
||||
|
||||
#define CC_RAIS ZC_CSTM(1) |
||||
#define CC_LOWR ZC_CSTM(2) |
@ -1,34 +0,0 @@
@@ -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; |
||||
}; |
@ -1,88 +0,0 @@
@@ -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); |
||||
}; |
Loading…
Reference in new issue