From 5dc171218cb54e13cecda29b02683e62c47a1437 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 29 Sep 2020 10:15:54 -0600 Subject: [PATCH] Implement keyboard keycode reading using raw hid --- .../launch_test/keymaps/default/keymap.c | 3 +- keyboards/system76/launch_test/launch_test.c | 34 ++++++++++++++++++- keyboards/system76/launch_test/launch_test.h | 3 ++ keyboards/system76/launch_test/rules.mk | 7 ++-- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/keyboards/system76/launch_test/keymaps/default/keymap.c b/keyboards/system76/launch_test/keymaps/default/keymap.c index d96f1e98016..7426688899e 100644 --- a/keyboards/system76/launch_test/keymaps/default/keymap.c +++ b/keyboards/system76/launch_test/keymaps/default/keymap.c @@ -1,7 +1,6 @@ #include QMK_KEYBOARD_H -const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - +const uint16_t PROGMEM keymaps[MATRIX_LAYERS][MATRIX_ROWS][MATRIX_COLS] = { [0] = LAYOUT( RGB_TOG, RGB_RMOD, RGB_MOD, RGB_HUD, RGB_HUI, RGB_SAD, RGB_SAI, RGB_VAD, RGB_VAI, RGB_M_P, RESET, KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0 diff --git a/keyboards/system76/launch_test/launch_test.c b/keyboards/system76/launch_test/launch_test.c index b45ae623532..4eb56fe9a68 100644 --- a/keyboards/system76/launch_test/launch_test.c +++ b/keyboards/system76/launch_test/launch_test.c @@ -1,5 +1,5 @@ - #include "launch_test.h" +#include "raw_hid.h" void keyboard_post_init_user(void) { // Customise these values to desired behaviour @@ -8,3 +8,35 @@ void keyboard_post_init_user(void) { debug_keyboard=true; //debug_mouse=true; } + +static bool keymap_get(uint8_t layer, uint8_t output, uint8_t input, uint16_t *value) { + if (layer < MATRIX_LAYERS) { + if (output < MATRIX_ROWS) { + if (input < MATRIX_COLS) { + *value = keymap_key_to_keycode(layer, (keypos_t){.row = output, .col = input}); + return true; + } + } + } + return false; +} + +void raw_hid_receive(uint8_t *data, uint8_t length) { + // Error response by default, set to success by commands + data[1] = 1; + + switch (data[0]) { + case 9: // KEYMAP_GET + { + uint16_t value = 0; + if (keymap_get(data[2], data[3], data[4], &value)) { + data[5] = (uint8_t)value; + data[6] = (uint8_t)(value >> 8); + data[1] = 0; + } + } + break; + } + + raw_hid_send(data, length); +} diff --git a/keyboards/system76/launch_test/launch_test.h b/keyboards/system76/launch_test/launch_test.h index bf57051630e..945e112ead0 100644 --- a/keyboards/system76/launch_test/launch_test.h +++ b/keyboards/system76/launch_test/launch_test.h @@ -3,6 +3,9 @@ #include "quantum.h" +//TODO: determine this automatically +#define MATRIX_LAYERS 1 + #define ___ KC_NO #define LAYOUT( \ diff --git a/keyboards/system76/launch_test/rules.mk b/keyboards/system76/launch_test/rules.mk index b022446f842..6d58b38cc15 100644 --- a/keyboards/system76/launch_test/rules.mk +++ b/keyboards/system76/launch_test/rules.mk @@ -17,10 +17,11 @@ BOOTLOADER = atmel-dfu # Build Options # comment out to disable the options. # -BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) +BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) MOUSEKEY_ENABLE = no # Mouse keys(+4700) -EXTRAKEY_ENABLE = yes # Audio control and System control(+450) -CONSOLE_ENABLE = yes # Console for debug(+400) +EXTRAKEY_ENABLE = no # Audio control and System control(+450) +CONSOLE_ENABLE = no # Console for debug(+400) COMMAND_ENABLE = no # Commands for debug and configuration NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work +RAW_ENABLE = yes # Enable RAW HID commands (used by keyboard configurator) RGBLIGHT_ENABLE = yes