|
|
|
@ -13,17 +13,20 @@ LOG_MODULE_REGISTER(zmk_kscan, CONFIG_ZMK_KSCAN_LOG_LEVEL);
@@ -13,17 +13,20 @@ LOG_MODULE_REGISTER(zmk_kscan, CONFIG_ZMK_KSCAN_LOG_LEVEL);
|
|
|
|
|
|
|
|
|
|
#include "keymap.h" |
|
|
|
|
#include "usb_hid.h" |
|
|
|
|
#include "handlers.h" |
|
|
|
|
|
|
|
|
|
#define ZMK_KSCAN_EVENT_STATE_PRESSED 0 |
|
|
|
|
#define ZMK_KSCAN_EVENT_STATE_RELEASED 1 |
|
|
|
|
|
|
|
|
|
struct zmk_kscan_event { |
|
|
|
|
struct zmk_kscan_event |
|
|
|
|
{ |
|
|
|
|
u32_t row; |
|
|
|
|
u32_t column; |
|
|
|
|
u32_t state; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct zmk_kscan_msg_processor { |
|
|
|
|
struct zmk_kscan_msg_processor |
|
|
|
|
{ |
|
|
|
|
struct k_work work; |
|
|
|
|
} msg_processor; |
|
|
|
|
|
|
|
|
@ -34,8 +37,7 @@ static void zmk_kscan_callback(struct device *dev, u32_t row, u32_t column, bool
@@ -34,8 +37,7 @@ static void zmk_kscan_callback(struct device *dev, u32_t row, u32_t column, bool
|
|
|
|
|
struct zmk_kscan_event ev = { |
|
|
|
|
.row = row, |
|
|
|
|
.column = column, |
|
|
|
|
.state = (pressed ? ZMK_KSCAN_EVENT_STATE_PRESSED : ZMK_KSCAN_EVENT_STATE_RELEASED) |
|
|
|
|
}; |
|
|
|
|
.state = (pressed ? ZMK_KSCAN_EVENT_STATE_PRESSED : ZMK_KSCAN_EVENT_STATE_RELEASED)}; |
|
|
|
|
|
|
|
|
|
k_msgq_put(&zmk_kscan_msgq, &ev, K_NO_WAIT); |
|
|
|
|
k_work_submit(&msg_processor.work); |
|
|
|
@ -45,23 +47,22 @@ void zmk_kscan_process_msgq(struct k_work *item)
@@ -45,23 +47,22 @@ void zmk_kscan_process_msgq(struct k_work *item)
|
|
|
|
|
{ |
|
|
|
|
struct zmk_kscan_event ev; |
|
|
|
|
|
|
|
|
|
while(k_msgq_get(&zmk_kscan_msgq, &ev, K_NO_WAIT) == 0) { |
|
|
|
|
while (k_msgq_get(&zmk_kscan_msgq, &ev, K_NO_WAIT) == 0) |
|
|
|
|
{ |
|
|
|
|
bool pressed = (ev.state == ZMK_KSCAN_EVENT_STATE_PRESSED); |
|
|
|
|
// TODO: More than basic mapping, layers, etc.
|
|
|
|
|
enum hid_kbd_code code = zmk_keymap_keycode_from_position(ev.row, ev.column); |
|
|
|
|
LOG_DBG("Row: %d, col: %d, code: %d, pressed: %s\n", ev.row, ev.column, code, (pressed ? "true" : "false")); |
|
|
|
|
if (pressed) { |
|
|
|
|
zmk_usb_hid_press_key(code); |
|
|
|
|
} else { |
|
|
|
|
zmk_usb_hid_release_key(code); |
|
|
|
|
} |
|
|
|
|
zmk_key key = zmk_keymap_keycode_from_position(ev.row, ev.column); |
|
|
|
|
struct zmk_key_event kev = (struct zmk_key_event){.key = key, .pressed = pressed}; |
|
|
|
|
|
|
|
|
|
LOG_DBG("Row: %d, col: %d, key: %lld, pressed: %s\n", ev.row, ev.column, key, (pressed ? "true" : "false")); |
|
|
|
|
zmk_handle_key(kev); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int zmk_kscan_init(char *name) |
|
|
|
|
{ |
|
|
|
|
struct device *dev = device_get_binding(name); |
|
|
|
|
if (dev == NULL) { |
|
|
|
|
if (dev == NULL) |
|
|
|
|
{ |
|
|
|
|
LOG_ERR("Failed to get the KSCAN device"); |
|
|
|
|
return -EINVAL; |
|
|
|
|
} |
|
|
|
|