diff options
author | Pete Johanson <peter@peterjohanson.com> | 2020-05-01 23:37:37 -0400 |
---|---|---|
committer | Pete Johanson <peter@peterjohanson.com> | 2020-05-01 23:37:37 -0400 |
commit | 7b4394b3e775e4be06dd80a3f967b0c28ba74d14 (patch) | |
tree | 7cfb43db3a065b604871cd7c0d18396f157c1679 | |
parent | 523e7f702faa8b08ae2d61b979868d2d02ed4ecc (diff) |
Basic keymap mapping.
-rw-r--r-- | src/keymap.h | 21 | ||||
-rw-r--r-- | src/kscan.c | 4 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/keymap.h b/src/keymap.h new file mode 100644 index 0000000..4456d08 --- /dev/null +++ b/src/keymap.h @@ -0,0 +1,21 @@ +#ifndef ZMK_KEYMAP_H +#define ZMK_KEYMAP_H + +#include <devicetree.h> +#include <usb/usb_device.h> +#include <usb/class/usb_hid.h> + +// TODO: Pull these in fro a kscan_gpio.h file from Zephyr! +// +#define MATRIX_NODE_ID DT_PATH(kscan) +#define MATRIX_ROWS DT_PROP_LEN(MATRIX_NODE_ID,row_gpios) +#define MATRIX_COLS DT_PROP_LEN(MATRIX_NODE_ID,col_gpios) + +enum hid_kbd_code keymap[MATRIX_ROWS][MATRIX_COLS] = { + { HID_KEY_A, HID_KEY_B }, + { HID_KEY_C, HID_KEY_D } +}; + +#define zmk_keymap_keycode_from_position(row, column) keymap[row][column] + +#endif diff --git a/src/kscan.c b/src/kscan.c index 268fac0..0239e76 100644 --- a/src/kscan.c +++ b/src/kscan.c @@ -11,6 +11,8 @@ LOG_MODULE_REGISTER(zmk_kscan, CONFIG_ZMK_KSCAN_LOG_LEVEL); +#include "keymap.h" + #define ZMK_KSCAN_EVENT_STATE_PRESSED 0 #define ZMK_KSCAN_EVENT_STATE_RELEASED 1 @@ -45,6 +47,8 @@ void zmk_kscan_process_msgq(struct k_work *item) 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); printk("Row: %d, col: %d, pressed: %s\n", ev.row, ev.column, (pressed ? "true" : "false")); } } |