From 440c6d8ca8dae0c5767abc27b5d12a73e7068c4a Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 15 Dec 2016 18:30:51 +0100 Subject: [PATCH 1/3] Initial implementation of mouse actions This implements the mouse action handling. There is no acceleration while holding the mouse movement keys yet, though, that will be a separate step. Signed-off-by: Gergely Nagy --- right/src/keyboard_layout.c | 78 +++++++++++++++++++++++++++++++++ right/src/keyboard_layout.h | 2 + right/src/usb_interface_mouse.c | 19 ++++---- 3 files changed, 90 insertions(+), 9 deletions(-) diff --git a/right/src/keyboard_layout.c b/right/src/keyboard_layout.c index 4cabe19..352452c 100644 --- a/right/src/keyboard_layout.c +++ b/right/src/keyboard_layout.c @@ -1,6 +1,7 @@ #include "keyboard_layout.h" #include "led_display.h" #include "layer.h" +#include "usb_interface_mouse.h" static uint8_t keyMasks[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE]; @@ -85,12 +86,89 @@ bool handleKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report, co LedDisplay_SetLayerLed(ActiveLayer); return false; break; + case UHK_KEY_MOUSE: + fillMouseReport(key, prevKeyStates, currKeyStates, keyId); + return false; default: break; } return false; } + +#define MOUSE_WHEEL_SPEED 1 +#define MOUSE_WHEEL_DIVISOR 4 + +#define MOUSE_MAX_SPEED 10 +#define MOUSE_SPEED_ACCEL_DIVISOR 50 + +static uint8_t mouseWheelDivisorCounter = 0; +static uint8_t mouseSpeedAccelDivisorCounter = 0; +static uint8_t mouseSpeed = 3; +static bool wasPreviousMouseActionWheelAction = false; + +void HandleMouseKey(usb_mouse_report_t *report, uhk_key_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) +{ + bool isWheelAction; + + if (!key_is_pressed(prevKeyStates, currKeyStates, keyId)) + return; + + isWheelAction = !!(key.mouse.scrollActions) && !(key.mouse.moveActions) && !(key.mouse.buttonActions); + + if (isWheelAction && wasPreviousMouseActionWheelAction) { + mouseWheelDivisorCounter++; + } + + if (key.mouse.scrollActions) { + if (mouseWheelDivisorCounter == MOUSE_WHEEL_DIVISOR) { + mouseWheelDivisorCounter = 0; + if (key.mouse.scrollActions & UHK_MOUSE_SCROLL_UP) { + report->wheelX = 1; + } + if (key.mouse.scrollActions & UHK_MOUSE_SCROLL_DOWN) { + report->wheelX = -1; + } + } + } + + if (key.mouse.moveActions & UHK_MOUSE_ACCELERATE || key.mouse.moveActions & UHK_MOUSE_DECELERATE) { + mouseSpeedAccelDivisorCounter++; + + if (mouseSpeedAccelDivisorCounter == MOUSE_SPEED_ACCEL_DIVISOR) { + mouseSpeedAccelDivisorCounter = 0; + + if (key.mouse.moveActions & UHK_MOUSE_ACCELERATE) { + if (mouseSpeed < MOUSE_MAX_SPEED) { + mouseSpeed++; + } + } + if (key.mouse.moveActions & UHK_MOUSE_DECELERATE) { + if (mouseSpeed > 1) { + mouseSpeed--; + } + } + } + } else if (key.mouse.moveActions) { + if (key.mouse.moveActions & UHK_MOUSE_MOVE_LEFT) { + report->x = -mouseSpeed; + } + if (key.mouse.moveActions & UHK_MOUSE_MOVE_RIGHT) { + report->x = mouseSpeed; + } + if (key.mouse.moveActions & UHK_MOUSE_MOVE_UP) { + report->y = -mouseSpeed; + } + if (key.mouse.moveActions & UHK_MOUSE_MOVE_DOWN) { + report->y = mouseSpeed; + } + } + + report->buttons |= key.mouse.buttonActions; + + wasPreviousMouseActionWheelAction = isWheelAction; +} + void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates) { int scancodeIdx = 0; diff --git a/right/src/keyboard_layout.h b/right/src/keyboard_layout.h index 995efd8..b106b3f 100644 --- a/right/src/keyboard_layout.h +++ b/right/src/keyboard_layout.h @@ -101,5 +101,7 @@ extern uint8_t prevKeyStates[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE]; extern uhk_key_t CurrentKeymap[LAYER_COUNT][SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE]; void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates); +void HandleMouseKey(usb_mouse_report_t *report, uhk_key_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId); +extern void fillMouseReport(uhk_key_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId); #endif diff --git a/right/src/usb_interface_mouse.c b/right/src/usb_interface_mouse.c index e960799..54b17a6 100644 --- a/right/src/usb_interface_mouse.c +++ b/right/src/usb_interface_mouse.c @@ -3,6 +3,7 @@ #include "fsl_i2c.h" #include "i2c.h" #include "reset_button.h" +#include "keyboard_layout.h" static usb_device_endpoint_struct_t UsbMouseEndpoints[USB_MOUSE_ENDPOINT_COUNT] = {{ USB_MOUSE_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), @@ -38,23 +39,23 @@ usb_device_class_struct_t UsbMouseClass = { static usb_mouse_report_t UsbMouseReport; -static uint8_t scrollCounter = 0; static volatile usb_status_t UsbMouseAction(void) { + usb_status_t ret; + ret = USB_DeviceHidSend(UsbCompositeDevice.mouseHandle, USB_MOUSE_ENDPOINT_INDEX, + (uint8_t*)&UsbMouseReport, USB_MOUSE_REPORT_LENGTH); UsbMouseReport.buttons = 0; UsbMouseReport.x = 0; UsbMouseReport.y = 0; UsbMouseReport.wheelX = 0; UsbMouseReport.wheelY = 0; - if (RESET_BUTTON_IS_PRESSED) { - if (!(scrollCounter % 10)) { - UsbMouseReport.wheelX = -1; - } - } - scrollCounter++; - return USB_DeviceHidSend(UsbCompositeDevice.mouseHandle, USB_MOUSE_ENDPOINT_INDEX, - (uint8_t*)&UsbMouseReport, USB_MOUSE_REPORT_LENGTH); + return ret; +} + +void fillMouseReport(uhk_key_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) +{ + HandleMouseKey(&UsbMouseReport, key, prevKeyStates, currKeyStates, keyId); } usb_status_t UsbMouseCallback(class_handle_t handle, uint32_t event, void *param) From 39dd0df58cb9d6b46043e9184490e3086f0c4651 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 15 Dec 2016 18:32:28 +0100 Subject: [PATCH 2/3] Move keyboard event handling into action.c Since keyboard_layout.[ch] has gained more features, and handles more than just filling out the keyboard report, move it to action.[ch] instead. I see no sane way to separate the keyboard and mouse report filling, unless we want to loop over key states twice, hence them being in the same file. Signed-off-by: Gergely Nagy --- right/src/{keyboard_layout.c => action.c} | 35 +++--- right/src/action.h | 126 ++++++++++++++++------ right/src/default_layout.c | 2 +- right/src/keyboard_layout.h | 107 ------------------ right/src/module.h | 1 - right/src/usb_interface_keyboard.c | 4 +- right/src/usb_interface_mouse.c | 4 +- right/src/usb_interface_mouse.h | 2 + 8 files changed, 123 insertions(+), 158 deletions(-) rename right/src/{keyboard_layout.c => action.c} (77%) delete mode 100644 right/src/keyboard_layout.h diff --git a/right/src/keyboard_layout.c b/right/src/action.c similarity index 77% rename from right/src/keyboard_layout.c rename to right/src/action.c index 352452c..8702c2c 100644 --- a/right/src/keyboard_layout.c +++ b/right/src/action.c @@ -1,4 +1,4 @@ -#include "keyboard_layout.h" +#include "action.h" #include "led_display.h" #include "layer.h" #include "usb_interface_mouse.h" @@ -38,7 +38,7 @@ static void clearKeymasks(const uint8_t *leftKeyStates, const uint8_t *rightKeyS } } -bool pressKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report) { +static bool pressKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report) { if (key.type != UHK_KEY_SIMPLE) { return false; } @@ -57,19 +57,19 @@ bool pressKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report) { return true; } -bool key_toggled_on(const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) { +static bool key_toggled_on(const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) { return (!prevKeyStates[keyId]) && currKeyStates[keyId]; } -bool key_is_pressed(const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) { +static bool key_is_pressed(const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) { return currKeyStates[keyId]; } -bool key_toggled_off(const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) { +static bool key_toggled_off(const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) { return (!currKeyStates[keyId]) && prevKeyStates[keyId]; } -bool handleKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) { +static bool handleKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) { switch (key.type) { case UHK_KEY_SIMPLE: if (key_is_pressed(prevKeyStates, currKeyStates, keyId)) { @@ -86,9 +86,6 @@ bool handleKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report, co LedDisplay_SetLayerLed(ActiveLayer); return false; break; - case UHK_KEY_MOUSE: - fillMouseReport(key, prevKeyStates, currKeyStates, keyId); - return false; default: break; } @@ -107,7 +104,7 @@ static uint8_t mouseSpeedAccelDivisorCounter = 0; static uint8_t mouseSpeed = 3; static bool wasPreviousMouseActionWheelAction = false; -void HandleMouseKey(usb_mouse_report_t *report, uhk_key_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) +static void handleMouseKey(usb_mouse_report_t *report, uhk_key_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) { bool isWheelAction; @@ -169,7 +166,7 @@ void HandleMouseKey(usb_mouse_report_t *report, uhk_key_t key, const uint8_t *pr wasPreviousMouseActionWheelAction = isWheelAction; } -void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates) { +void HandleKeyboardEvents(usb_keyboard_report_t *keyboardReport, usb_mouse_report_t *mouseReport, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates) { int scancodeIdx = 0; clearKeymasks(leftKeyStates, rightKeyStates); @@ -181,8 +178,12 @@ void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeySta uhk_key_t code = getKeycode(SLOT_ID_RIGHT_KEYBOARD_HALF, keyId); - if (handleKey(code, scancodeIdx, report, prevKeyStates[SLOT_ID_RIGHT_KEYBOARD_HALF], rightKeyStates, keyId)) { - scancodeIdx++; + if (code.type == UHK_KEY_MOUSE) { + handleMouseKey(mouseReport, code, prevKeyStates[SLOT_ID_RIGHT_KEYBOARD_HALF], rightKeyStates, keyId); + } else { + if (handleKey(code, scancodeIdx, keyboardReport, prevKeyStates[SLOT_ID_RIGHT_KEYBOARD_HALF], rightKeyStates, keyId)) { + scancodeIdx++; + } } } @@ -193,8 +194,12 @@ void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeySta uhk_key_t code = getKeycode(SLOT_ID_LEFT_KEYBOARD_HALF, keyId); - if (handleKey(code, scancodeIdx, report, prevKeyStates[SLOT_ID_LEFT_KEYBOARD_HALF], leftKeyStates, keyId)) { - scancodeIdx++; + if (code.type == UHK_KEY_MOUSE) { + handleMouseKey(mouseReport, code, prevKeyStates[SLOT_ID_LEFT_KEYBOARD_HALF], leftKeyStates, keyId); + } else { + if (handleKey(code, scancodeIdx, keyboardReport, prevKeyStates[SLOT_ID_LEFT_KEYBOARD_HALF], leftKeyStates, keyId)) { + scancodeIdx++; + } } } diff --git a/right/src/action.h b/right/src/action.h index 934bfdc..df7441d 100644 --- a/right/src/action.h +++ b/right/src/action.h @@ -1,39 +1,105 @@ -#ifndef __ACTION_H__ -#define __ACTION_H__ +#ifndef __UHK_ACTION_H_ +#define __UHK_ACTION_H_ -// Macros: +#include +#include "lufa/HIDClassCommon.h" +#include "usb_composite_device.h" - // The value of action ID can be any valid HID_KEYBOARD_SC_* scancode constants of LUFA. - // Hence, ACTION_ID_* values must not conflict with any of the HID_KEYBOARD_SC_* constants. - #define ACTION_ID_NONE 0xFF - #define ACTION_ID_SWITCH_LAYER 0xFE - #define ACTION_ID_MOUSE 0xFD - #define ACTION_ID_SWITCH_KEYMAP 0xFC - #define ACTION_ID_PLAY_MACRO 0xFB +#include "module.h" - #define ACTION_ARG_NONE 0 +// Keyboard layout is a 2D array of scan codes. +// +// First dimension is the Key ID of a given key. Key IDs are the indices of the +// of the active keys of the key_matrix_t structure. In case of left half, an +// offset of 35 is added. +// +// For each Key ID, there are 4 different possible scan codes: +// - default, when no modifiers are pressed +// - mod layer +// - fn layer +// - mod+fn layer - #define ACTION_ARG_SWITCH_LAYER_MOD 0 - #define ACTION_ARG_SWITCH_LAYER_FN 1 - #define ACTION_ARG_SWITCH_LAYER_MOUSE 2 +#define KEY_STATE_COUNT (5*7) - #define ACTION_ARG_MOUSE_MOVE_UP 0 - #define ACTION_ARG_MOUSE_MOVE_DOWN 1 - #define ACTION_ARG_MOUSE_MOVE_LEFT 3 - #define ACTION_ARG_MOUSE_MOVE_RIGHT 4 - #define ACTION_ARG_MOUSE_CLICK_LEFT 5 - #define ACTION_ARG_MOUSE_CLICK_MIDDLE 6 - #define ACTION_ARG_MOUSE_CLICK_RIGHT 7 - #define ACTION_ARG_MOUSE_WHEEL_UP 8 - #define ACTION_ARG_MOUSE_WHEEL_DOWN 9 - #define ACTION_ARG_MOUSE_WHEEL_LEFT 10 - #define ACTION_ARG_MOUSE_WHEEL_RIGHT 11 +typedef enum { + UHK_KEY_NONE, + UHK_KEY_SIMPLE, + UHK_KEY_MOUSE, + UHK_KEY_LAYER, + UHK_KEY_LAYER_TOGGLE, + UHK_KEY_KEYMAP, + UHK_KEY_MACRO, + UHK_KEY_LPRESSMOD, + UHK_KEY_LPRESSLAYER, +} uhk_key_type_t; -// Typedefs: +enum { + UHK_MOUSE_BUTTON_LEFT = (1 << 0), + UHK_MOUSE_BUTTON_RIGHT = (1 << 1), + UHK_MOUSE_BUTTON_MIDDLE = (1 << 2), + UHK_MOUSE_BUTTON_4 = (1 << 3), + UHK_MOUSE_BUTTON_5 = (1 << 4), + UHK_MOUSE_BUTTON_6 = (1 << 5), +}; - typedef struct { - uint8_t id; - uint8_t arg; - } action_t; +enum { + UHK_MOUSE_MOVE_UP = (1 << 0), + UHK_MOUSE_MOVE_DOWN = (1 << 1), + UHK_MOUSE_MOVE_LEFT = (1 << 2), + UHK_MOUSE_MOVE_RIGHT = (1 << 3), + + UHK_MOUSE_ACCELERATE = (1 << 4), + UHK_MOUSE_DECELERATE = (1 << 5), +}; + +enum { + UHK_MOUSE_SCROLL_UP = (1 << 0), + UHK_MOUSE_SCROLL_DOWN = (1 << 1), + UHK_MOUSE_SCROLL_LEFT = (1 << 2), + UHK_MOUSE_SCROLL_RIGHT = (1 << 3), +}; + +typedef struct { + uint8_t type; + union { + struct { + uint8_t __unused_bits; + uint8_t mods; + uint8_t key; + } __attribute__ ((packed)) simple; + struct { + uint8_t buttonActions; // bitfield + uint8_t scrollActions; // bitfield + uint8_t moveActions; // bitfield + } __attribute__ ((packed)) mouse; + struct { + uint16_t __unused_bits; + uint8_t target; + } __attribute__ ((packed)) layer; + struct { + uint16_t __unused_bits; + uint8_t target; + } __attribute__ ((packed)) keymap; + struct { + uint8_t __unused_bits; + uint16_t index; + } __attribute__ ((packed)) macro; + struct { + uint8_t longPressMod; // single mod, or bitfield? + uint8_t mods; // for the alternate action + uint8_t key; + } __attribute__ ((packed)) longpressMod; + struct { + uint8_t longPressLayer; + uint8_t mods; + uint8_t key; + } __attribute__ ((packed)) longpressLayer; + }; +} __attribute__ ((packed)) uhk_key_t; + +extern uint8_t prevKeyStates[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE]; +extern uhk_key_t CurrentKeymap[LAYER_COUNT][SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE]; + +void HandleKeyboardEvents(usb_keyboard_report_t *keyboardReport, usb_mouse_report_t *mouseReport, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates); #endif diff --git a/right/src/default_layout.c b/right/src/default_layout.c index 4a150aa..ee6bd4d 100644 --- a/right/src/default_layout.c +++ b/right/src/default_layout.c @@ -1,4 +1,4 @@ -#include "keyboard_layout.h" +#include "action.h" uhk_key_t CurrentKeymap[LAYER_COUNT][SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE] = { // Layer 0 diff --git a/right/src/keyboard_layout.h b/right/src/keyboard_layout.h deleted file mode 100644 index b106b3f..0000000 --- a/right/src/keyboard_layout.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef KEYBOARD_LAYOUT_H_ -#define KEYBOARD_LAYOUT_H_ - -#include -#include "lufa/HIDClassCommon.h" -#include "usb_composite_device.h" - -#include "module.h" - -// Keyboard layout is a 2D array of scan codes. -// -// First dimension is the Key ID of a given key. Key IDs are the indices of the -// of the active keys of the key_matrix_t structure. In case of left half, an -// offset of 35 is added. -// -// For each Key ID, there are 4 different possible scan codes: -// - default, when no modifiers are pressed -// - mod layer -// - fn layer -// - mod+fn layer - -#define KEY_STATE_COUNT (5*7) - -typedef enum { - UHK_KEY_NONE, - UHK_KEY_SIMPLE, - UHK_KEY_MOUSE, - UHK_KEY_LAYER, - UHK_KEY_LAYER_TOGGLE, - UHK_KEY_KEYMAP, - UHK_KEY_MACRO, - UHK_KEY_LPRESSMOD, - UHK_KEY_LPRESSLAYER, -} uhk_key_type_t; - -enum { - UHK_MOUSE_BUTTON_LEFT = (1 << 0), - UHK_MOUSE_BUTTON_RIGHT = (1 << 1), - UHK_MOUSE_BUTTON_MIDDLE = (1 << 2), - UHK_MOUSE_BUTTON_4 = (1 << 3), - UHK_MOUSE_BUTTON_5 = (1 << 4), - UHK_MOUSE_BUTTON_6 = (1 << 5), -}; - -enum { - UHK_MOUSE_MOVE_UP = (1 << 0), - UHK_MOUSE_MOVE_DOWN = (1 << 1), - UHK_MOUSE_MOVE_LEFT = (1 << 2), - UHK_MOUSE_MOVE_RIGHT = (1 << 3), - - UHK_MOUSE_ACCELERATE = (1 << 4), - UHK_MOUSE_DECELERATE = (1 << 5), -}; - -enum { - UHK_MOUSE_SCROLL_UP = (1 << 0), - UHK_MOUSE_SCROLL_DOWN = (1 << 1), - UHK_MOUSE_SCROLL_LEFT = (1 << 2), - UHK_MOUSE_SCROLL_RIGHT = (1 << 3), -}; - -typedef struct { - uint8_t type; - union { - struct { - uint8_t __unused_bits; - uint8_t mods; - uint8_t key; - } __attribute__ ((packed)) simple; - struct { - uint8_t buttonActions; // bitfield - uint8_t scrollActions; // bitfield - uint8_t moveActions; // bitfield - } __attribute__ ((packed)) mouse; - struct { - uint16_t __unused_bits; - uint8_t target; - } __attribute__ ((packed)) layer; - struct { - uint16_t __unused_bits; - uint8_t target; - } __attribute__ ((packed)) keymap; - struct { - uint8_t __unused_bits; - uint16_t index; - } __attribute__ ((packed)) macro; - struct { - uint8_t longPressMod; // single mod, or bitfield? - uint8_t mods; // for the alternate action - uint8_t key; - } __attribute__ ((packed)) longpressMod; - struct { - uint8_t longPressLayer; - uint8_t mods; - uint8_t key; - } __attribute__ ((packed)) longpressLayer; - }; -} __attribute__ ((packed)) uhk_key_t; - -extern uint8_t prevKeyStates[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE]; -extern uhk_key_t CurrentKeymap[LAYER_COUNT][SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE]; - -void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates); -void HandleMouseKey(usb_mouse_report_t *report, uhk_key_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId); -extern void fillMouseReport(uhk_key_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId); - -#endif diff --git a/right/src/module.h b/right/src/module.h index 9e79620..5c58da5 100644 --- a/right/src/module.h +++ b/right/src/module.h @@ -3,7 +3,6 @@ // Includes: - #include "action.h" #include "layer.h" #include "slot.h" diff --git a/right/src/usb_interface_keyboard.c b/right/src/usb_interface_keyboard.c index efe3008..28a68b9 100644 --- a/right/src/usb_interface_keyboard.c +++ b/right/src/usb_interface_keyboard.c @@ -1,3 +1,4 @@ +#include "action.h" #include "fsl_port.h" #include "usb_api.h" #include "usb_composite_device.h" @@ -6,7 +7,6 @@ #include "fsl_i2c.h" #include "i2c.h" #include "i2c_addresses.h" -#include "keyboard_layout.h" static usb_device_endpoint_struct_t UsbKeyboardEndpoints[USB_KEYBOARD_ENDPOINT_COUNT] = {{ USB_KEYBOARD_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), @@ -100,7 +100,7 @@ void UsbKeyboadTask(){ readLeftKeys(leftKeyStates); - fillKeyboardReport(&UsbKeyboardReport[newLayout], leftKeyStates, keyMatrix.keyStates); + HandleKeyboardEvents(&UsbKeyboardReport[newLayout], &UsbMouseReport, leftKeyStates, keyMatrix.keyStates); // 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 diff --git a/right/src/usb_interface_mouse.c b/right/src/usb_interface_mouse.c index 54b17a6..263c4b1 100644 --- a/right/src/usb_interface_mouse.c +++ b/right/src/usb_interface_mouse.c @@ -3,7 +3,7 @@ #include "fsl_i2c.h" #include "i2c.h" #include "reset_button.h" -#include "keyboard_layout.h" +#include "action.h" static usb_device_endpoint_struct_t UsbMouseEndpoints[USB_MOUSE_ENDPOINT_COUNT] = {{ USB_MOUSE_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), @@ -37,7 +37,7 @@ usb_device_class_struct_t UsbMouseClass = { USB_DEVICE_CONFIGURATION_COUNT, }; -static usb_mouse_report_t UsbMouseReport; +usb_mouse_report_t UsbMouseReport; static volatile usb_status_t UsbMouseAction(void) { diff --git a/right/src/usb_interface_mouse.h b/right/src/usb_interface_mouse.h index ae5a32d..297e46b 100644 --- a/right/src/usb_interface_mouse.h +++ b/right/src/usb_interface_mouse.h @@ -38,4 +38,6 @@ extern usb_status_t UsbMouseSetConfiguration(class_handle_t handle, uint8_t configuration); extern usb_status_t UsbMouseSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting); + extern usb_mouse_report_t UsbMouseReport; + #endif From 5e48da5a7a21e1b1d49cadb987d60ab4db9a76e0 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 15 Dec 2016 18:37:30 +0100 Subject: [PATCH 3/3] Code cleanup Move a few defines from action.c to action.h. Signed-off-by: Gergely Nagy --- right/src/action.c | 7 ------- right/src/action.h | 6 ++++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/right/src/action.c b/right/src/action.c index 8702c2c..694d2f5 100644 --- a/right/src/action.c +++ b/right/src/action.c @@ -92,13 +92,6 @@ static bool handleKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *rep return false; } - -#define MOUSE_WHEEL_SPEED 1 -#define MOUSE_WHEEL_DIVISOR 4 - -#define MOUSE_MAX_SPEED 10 -#define MOUSE_SPEED_ACCEL_DIVISOR 50 - static uint8_t mouseWheelDivisorCounter = 0; static uint8_t mouseSpeedAccelDivisorCounter = 0; static uint8_t mouseSpeed = 3; diff --git a/right/src/action.h b/right/src/action.h index df7441d..823bd88 100644 --- a/right/src/action.h +++ b/right/src/action.h @@ -59,6 +59,12 @@ enum { UHK_MOUSE_SCROLL_RIGHT = (1 << 3), }; +#define MOUSE_WHEEL_SPEED 1 +#define MOUSE_WHEEL_DIVISOR 4 + +#define MOUSE_MAX_SPEED 10 +#define MOUSE_SPEED_ACCEL_DIVISOR 50 + typedef struct { uint8_t type; union {