From f2c750cdf9d3c0d8a7bcadcd9d35bf9c6c982364 Mon Sep 17 00:00:00 2001 From: Robert Csordas Date: Mon, 14 Nov 2016 22:41:39 +0100 Subject: [PATCH] Refactoring --- right/src/keyboard_layout.c | 82 +++++++++++++++++++++++++++++- right/src/keyboard_layout.h | 50 +----------------- right/src/usb_interface_keyboard.c | 32 +----------- 3 files changed, 85 insertions(+), 79 deletions(-) diff --git a/right/src/keyboard_layout.c b/right/src/keyboard_layout.c index 915ccca..6f5f5ee 100644 --- a/right/src/keyboard_layout.c +++ b/right/src/keyboard_layout.c @@ -1,3 +1,83 @@ #include "keyboard_layout.h" -uint8_t keyMasks[LAYOUT_KEY_COUNT]; +static uint8_t keyMasks[LAYOUT_KEY_COUNT]; + +static inline __attribute__((always_inline)) uint8_t getKeycode(KEYBOARD_LAYOUT(layout), uint8_t keyId, uint8_t modifierState) +{ + if (keyId=USB_KEYBOARD_MAX_KEYS) { + break; + } + + if (rightKeyStates[keyId]) { + uint8_t code=getKeycode(layout, keyId, modifierState); + if (code) { + report->scancodes[scancodeIdx++] = code; + } + } + } + + for (uint8_t keyId=0; keyId=USB_KEYBOARD_MAX_KEYS) { + break; + } + + if (leftKeyStates[keyId]) { + uint8_t code=getKeycode(layout, LAYOUT_LEFT_OFFSET+keyId, modifierState); + if (code) { + report->scancodes[scancodeIdx++] = code; + } + } + } +} diff --git a/right/src/keyboard_layout.h b/right/src/keyboard_layout.h index 9b2e9ae..91a2ffe 100644 --- a/right/src/keyboard_layout.h +++ b/right/src/keyboard_layout.h @@ -3,6 +3,7 @@ #include #include "lufa/HIDClassCommon.h" +#include "usb_composite_device.h" /** * Keyboard layout is a 2D array of scan codes. @@ -35,53 +36,6 @@ #define MODIFIER_MOD_PRESSED 1 #define MODIFIER_FN_PRESSED 2 -extern uint8_t keyMasks[LAYOUT_KEY_COUNT]; - - -static inline __attribute__((always_inline)) uint8_t getKeycode(KEYBOARD_LAYOUT(layout), uint8_t keyId, uint8_t modifierState) -{ - if (keyId=USB_KEYBOARD_MAX_KEYS) { - break; - } - - if (keyMatrix.keyStates[keyId]) { - uint8_t code=getKeycode(defaultKeyboardLayout, keyId, modifierState); - if (code) { - UsbKeyboardReport[newLayout].scancodes[scancodeIdx++] = code; - } - } - } - - for (uint8_t keyId=0; keyId=USB_KEYBOARD_MAX_KEYS) { - break; - } - - if (leftKeyStates[keyId]) { - uint8_t code=getKeycode(defaultKeyboardLayout, LAYOUT_LEFT_OFFSET+keyId, modifierState); - if (code) { - UsbKeyboardReport[newLayout].scancodes[scancodeIdx++] = code; - } - } - } + fillKeyboardReport(&UsbKeyboardReport[newLayout], leftKeyStates, keyMatrix.keyStates, defaultKeyboardLayout); //Change to the new layout in atomic operation (int copy). Even if //the copy is not atomic itself, only single bit changes. So it can