Browse Source

Basic keymap mapping.

xmkb
Pete Johanson 5 years ago
parent
commit
7b4394b3e7
  1. 21
      src/keymap.h
  2. 4
      src/kscan.c

21
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

4
src/kscan.c

@ -11,6 +11,8 @@
LOG_MODULE_REGISTER(zmk_kscan, CONFIG_ZMK_KSCAN_LOG_LEVEL); 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_PRESSED 0
#define ZMK_KSCAN_EVENT_STATE_RELEASED 1 #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) { while(k_msgq_get(&zmk_kscan_msgq, &ev, K_NO_WAIT) == 0) {
bool pressed = (ev.state == ZMK_KSCAN_EVENT_STATE_PRESSED); 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")); printk("Row: %d, col: %d, pressed: %s\n", ev.row, ev.column, (pressed ? "true" : "false"));
} }
} }

Loading…
Cancel
Save