stm32 hid cleanup

This commit is contained in:
Maxim Devaev 2022-07-22 09:14:49 +03:00
parent d3dbf19399
commit 3a9b433000
12 changed files with 206 additions and 720 deletions

View File

@ -44,7 +44,7 @@ update:
clean-all: clean clean-all: clean
rm -rf .platformio rm -rf .platformio
clean: clean:
rm -rf .pio .current .config rm -rf .pio .current .config platformio.ini
help: help:

View File

@ -22,8 +22,6 @@
#pragma once #pragma once
#include <HID-Project.h>
uint8_t keymapUsb(uint8_t code) { uint8_t keymapUsb(uint8_t code) {
switch (code) { switch (code) {

View File

@ -22,8 +22,6 @@
#pragma once #pragma once
#include <HID-Project.h>
<%! import operator %> <%! import operator %>
uint8_t keymapUsb(uint8_t code) { uint8_t keymapUsb(uint8_t code) {
switch (code) { switch (code) {

View File

@ -19,9 +19,14 @@
# # # #
*****************************************************************************/ *****************************************************************************/
#include "storage.h" # pragma once
#include <stm32f1_rtc.h> #include <stm32f1_rtc.h>
#include "storage.h"
namespace DRIVERS { namespace DRIVERS {
struct BackupRegister : public Storage { struct BackupRegister : public Storage {
BackupRegister() : Storage(NON_VOLATILE_STORAGE) { BackupRegister() : Storage(NON_VOLATILE_STORAGE) {
@ -29,16 +34,16 @@ namespace DRIVERS {
} }
void readBlock(void *dest, const void *src, size_t size) override { void readBlock(void *dest, const void *src, size_t size) override {
uint8_t* _dest = reinterpret_cast<uint8_t*>(dest); uint8_t *dest_ = reinterpret_cast<uint8_t*>(dest);
for(size_t i = 0; i < size; ++i) { for(size_t index = 0; index < size; ++index) {
_dest[i] = _rtc.getBackupRegister(reinterpret_cast<uintptr_t>(src) + i + 1); dest_[index] = _rtc.getBackupRegister(reinterpret_cast<uintptr_t>(src) + index + 1);
} }
} }
void updateBlock(const void *src, void *dest, size_t size) override { void updateBlock(const void *src, void *dest, size_t size) override {
const uint8_t* _src = reinterpret_cast<const uint8_t*>(src); const uint8_t *src_ = reinterpret_cast<const uint8_t*>(src);
for(size_t i = 0; i < size; ++i) { for(size_t index = 0; index < size; ++index) {
_rtc.setBackupRegister(reinterpret_cast<uintptr_t>(dest) + i + 1, _src[i]); _rtc.setBackupRegister(reinterpret_cast<uintptr_t>(dest) + index + 1, src_[index]);
} }
} }

View File

@ -19,6 +19,7 @@
# # # #
*****************************************************************************/ *****************************************************************************/
#include "factory.h" #include "factory.h"
#include "usb/keyboard-stm32.h" #include "usb/keyboard-stm32.h"
#include "usb/hid-wrapper-stm32.h" #include "usb/hid-wrapper-stm32.h"
@ -33,14 +34,9 @@
# error "Disable random USB enumeration" # error "Disable random USB enumeration"
#endif #endif
namespace DRIVERS
{ namespace DRIVERS {
#if 0
USBCompositeSerial _serial;
HidWrapper _hidWrapper(&_serial);
#else
HidWrapper _hidWrapper; HidWrapper _hidWrapper;
#endif
Keyboard *Factory::makeKeyboard(type _type) { Keyboard *Factory::makeKeyboard(type _type) {
switch (_type) { switch (_type) {
@ -77,5 +73,3 @@ namespace DRIVERS
} }
} }
} }

View File

@ -19,63 +19,54 @@
# # # #
*****************************************************************************/ *****************************************************************************/
#pragma once #pragma once
#include <USBComposite.h> #include <USBComposite.h>
namespace DRIVERS {
namespace DRIVERS {
class HidWrapper { class HidWrapper {
public: public:
HidWrapper(USBCompositeSerial* _serial = nullptr) : _serial(_serial) {}
void begin() { void begin() {
if(_init) if (_init) {
return; return;
}
_init = true; _init = true;
_report_descriptor_length = 0; _report_descriptor_length = 0;
for(uint8 i = 0; i<_count; ++i) { for (unsigned index = 0; index < _count; ++index) {
_report_descriptor_length += _descriptors_size[i]; _report_descriptor_length += _descriptors_size[index];
} }
_report_descriptor = new uint8[_report_descriptor_length]; _report_descriptor = new uint8[_report_descriptor_length];
uint16_t index = 0; size_t offset = 0;
for(uint8 i = 0; i<_count; ++i) { for (unsigned index = 0; index < _count; ++index) {
memcpy(_report_descriptor + index, _report_descriptors[i], _descriptors_size[i]); memcpy(_report_descriptor + offset, _report_descriptors[index], _descriptors_size[index]);
index += _descriptors_size[i]; offset += _descriptors_size[index];
} }
if(_serial) {
usbHid.begin(*_serial, _report_descriptor, _report_descriptor_length);
} else {
usbHid.begin(_report_descriptor, _report_descriptor_length); usbHid.begin(_report_descriptor, _report_descriptor_length);
} }
}
void addReportDescriptor(const uint8_t* report_descriptor, uint16_t report_descriptor_length) { void addReportDescriptor(const uint8_t *report_descriptor, uint16_t report_descriptor_length) {
_report_descriptors[_count] = report_descriptor; _report_descriptors[_count] = report_descriptor;
_descriptors_size[_count] = report_descriptor_length; _descriptors_size[_count] = report_descriptor_length;
++_count; ++_count;
} }
USBCompositeSerial* serial() {
return _serial;
}
USBHID usbHid; USBHID usbHid;
private: private:
USBCompositeSerial* _serial;
bool _init = false; bool _init = false;
static constexpr uint8_t MAX_USB_DESCRIPTORS = 2; static constexpr uint8_t MAX_USB_DESCRIPTORS = 2;
const uint8_t* _report_descriptors[MAX_USB_DESCRIPTORS]; const uint8_t *_report_descriptors[MAX_USB_DESCRIPTORS];
uint8_t _descriptors_size[MAX_USB_DESCRIPTORS]; uint8_t _descriptors_size[MAX_USB_DESCRIPTORS];
uint8_t _count = 0; uint8_t _count = 0;
uint8_t* _report_descriptor; uint8_t *_report_descriptor;
uint16_t _report_descriptor_length; uint16_t _report_descriptor_length;
}; };
} }

View File

@ -19,16 +19,18 @@
# # # #
*****************************************************************************/ *****************************************************************************/
#pragma once #pragma once
#include <USBComposite.h>
#include "tools.h"
#include "keyboard.h" #include "keyboard.h"
#include "hid-wrapper-stm32.h" #include "hid-wrapper-stm32.h"
#include <USBComposite.h>
#include "keymap.h" #include "keymap.h"
#include "tools.h"
namespace DRIVERS { namespace DRIVERS {
const uint8_t reportDescriptionKeyboard[] = { const uint8_t reportDescriptionKeyboard[] = {
HID_KEYBOARD_REPORT_DESCRIPTOR(), HID_KEYBOARD_REPORT_DESCRIPTOR(),
}; };
@ -51,25 +53,30 @@ namespace DRIVERS {
void sendKey(uint8_t code, bool state) override { void sendKey(uint8_t code, bool state) override {
uint16_t usb_code = keymapUsb(code); uint16_t usb_code = keymapUsb(code);
if (usb_code == KEY_ERROR_UNDEFINED) { if (usb_code == 0) {
return; return;
} }
if(usb_code >= KEY_LEFT_CTRL && usb_code <= KEY_RIGHT_WINDOWS) { // 0xE0 is a prefix from HID-Project keytable
usb_code = usb_code - KEY_LEFT_CTRL + 0x80; if (usb_code >= 0xE0 && usb_code <= 0xE7) {
usb_code = usb_code - 0xE0 + 0x80;
} else { } else {
usb_code += KEY_HID_OFFSET; usb_code += KEY_HID_OFFSET;
} }
state ? _keyboard.press(usb_code) : _keyboard.release(usb_code); if (state) {
_keyboard.press(usb_code);
} else {
_keyboard.release(usb_code);
}
} }
bool isOffline() override { bool isOffline() override {
return USBComposite == false; return (USBComposite == false);
} }
KeyboardLedsState getLeds() override { KeyboardLedsState getLeds() override {
uint8 leds = _keyboard.getLEDs(); uint8_t leds = _keyboard.getLEDs();
KeyboardLedsState result = { KeyboardLedsState result = {
.caps = leds & 0b00000010, .caps = leds & 0b00000010,
.scroll = leds & 0b00000100, .scroll = leds & 0b00000100,
@ -81,6 +88,5 @@ namespace DRIVERS {
private: private:
HidWrapper& _hidWrapper; HidWrapper& _hidWrapper;
HIDKeyboard _keyboard; HIDKeyboard _keyboard;
static constexpr uint8 KEY_ERROR_UNDEFINED = 3;
}; };
} }

View File

@ -1,526 +0,0 @@
/*****************************************************************************
# #
# KVMD - The main PiKVM daemon. #
# #
# Copyright (C) 2018-2022 Maxim Devaev <mdevaev@gmail.com> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
# #
*****************************************************************************/
#pragma once
#include <stdint.h>
#undef KEY_LEFT_CTRL
#undef KEY_LEFT_SHIFT
#undef KEY_LEFT_ALT
#undef KEY_LEFT_GUI
#undef KEY_RIGHT_CTRL
#undef KEY_RIGHT_SHIFT
#undef KEY_RIGHT_ALT
#undef KEY_RIGHT_GUI
#undef KEY_UP_ARROW
#undef KEY_DOWN_ARROW
#undef KEY_LEFT_ARROW
#undef KEY_RIGHT_ARROW
#undef KEY_BACKSPACE
#undef KEY_TAB
#undef KEY_RETURN
#undef KEY_ESC
#undef KEY_INSERT
#undef KEY_DELETE
#undef KEY_PAGE_UP
#undef KEY_PAGE_DOWN
#undef KEY_HOME
#undef KEY_END
#undef KEY_CAPS_LOCK
#undef KEY_F1
#undef KEY_F2
#undef KEY_F3
#undef KEY_F4
#undef KEY_F5
#undef KEY_F6
#undef KEY_F7
#undef KEY_F8
#undef KEY_F9
#undef KEY_F10
#undef KEY_F11
#undef KEY_F12
//https://github.com/NicoHood/HID/blob/master/src/KeyboardLayouts/ImprovedKeylayouts.h
// Hut1_12v2.pdf
enum KeyboardKeycode : uint8_t {
KEY_RESERVED = 0,
KEY_ERROR_ROLLOVER = 1,
KEY_POST_FAIL = 2,
KEY_ERROR_UNDEFINED = 3,
KEY_A = 4,
KEY_B = 5,
KEY_C = 6,
KEY_D = 7,
KEY_E = 8,
KEY_F = 9,
KEY_G = 10,
KEY_H = 11,
KEY_I = 12,
KEY_J = 13,
KEY_K = 14,
KEY_L = 15,
KEY_M = 16,
KEY_N = 17,
KEY_O = 18,
KEY_P = 19,
KEY_Q = 20,
KEY_R = 21,
KEY_S = 22,
KEY_T = 23,
KEY_U = 24,
KEY_V = 25,
KEY_W = 26,
KEY_X = 27,
KEY_Y = 28,
KEY_Z = 29,
KEY_1 = 30,
KEY_2 = 31,
KEY_3 = 32,
KEY_4 = 33,
KEY_5 = 34,
KEY_6 = 35,
KEY_7 = 36,
KEY_8 = 37,
KEY_9 = 38,
KEY_0 = 39,
KEY_ENTER = 40,
KEY_RETURN = 40, // Alias
KEY_ESC = 41,
KEY_BACKSPACE = 42,
KEY_TAB = 43,
KEY_SPACE = 44,
KEY_MINUS = 45,
KEY_EQUAL = 46,
KEY_LEFT_BRACE = 47,
KEY_RIGHT_BRACE = 48,
KEY_BACKSLASH = 49,
KEY_NON_US_NUM = 50,
KEY_SEMICOLON = 51,
KEY_QUOTE = 52,
KEY_TILDE = 53,
KEY_COMMA = 54,
KEY_PERIOD = 55,
KEY_SLASH = 56,
KEY_CAPS_LOCK = 0x39,
KEY_F1 = 0x3A,
KEY_F2 = 0x3B,
KEY_F3 = 0x3C,
KEY_F4 = 0x3D,
KEY_F5 = 0x3E,
KEY_F6 = 0x3F,
KEY_F7 = 0x40,
KEY_F8 = 0x41,
KEY_F9 = 0x42,
KEY_F10 = 0x43,
KEY_F11 = 0x44,
KEY_F12 = 0x45,
KEY_PRINT = 0x46,
KEY_PRINTSCREEN = 0x46, // Alias
KEY_SCROLL_LOCK = 0x47,
KEY_PAUSE = 0x48,
KEY_INSERT = 0x49,
KEY_HOME = 0x4A,
KEY_PAGE_UP = 0x4B,
KEY_DELETE = 0x4C,
KEY_END = 0x4D,
KEY_PAGE_DOWN = 0x4E,
KEY_RIGHT_ARROW = 0x4F,
KEY_LEFT_ARROW = 0x50,
KEY_DOWN_ARROW = 0x51,
KEY_UP_ARROW = 0x52,
KEY_RIGHT = 0x4F, // Alias
KEY_LEFT = 0x50, // Alias
KEY_DOWN = 0x51, // Alias
KEY_UP = 0x52, // Alias
KEY_NUM_LOCK = 0x53,
KEYPAD_DIVIDE = 0x54,
KEYPAD_MULTIPLY = 0x55,
KEYPAD_SUBTRACT = 0x56,
KEYPAD_ADD = 0x57,
KEYPAD_ENTER = 0x58,
KEYPAD_1 = 0x59,
KEYPAD_2 = 0x5A,
KEYPAD_3 = 0x5B,
KEYPAD_4 = 0x5C,
KEYPAD_5 = 0x5D,
KEYPAD_6 = 0x5E,
KEYPAD_7 = 0x5F,
KEYPAD_8 = 0x60,
KEYPAD_9 = 0x61,
KEYPAD_0 = 0x62,
KEYPAD_DOT = 0x63,
KEY_NON_US = 0x64,
KEY_APPLICATION = 0x65, // Context menu/right click
KEY_MENU = 0x65, // Alias
// Most of the following keys will only work with Linux or not at all.
// F13+ keys are mostly used for laptop functions like ECO key.
KEY_POWER = 0x66, // PowerOff (Ubuntu)
KEY_PAD_EQUALS = 0x67, // Dont confuse with KEYPAD_EQUAL_SIGN
KEY_F13 = 0x68, // Tools (Ubunutu)
KEY_F14 = 0x69, // Launch5 (Ubuntu)
KEY_F15 = 0x6A, // Launch6 (Ubuntu)
KEY_F16 = 0x6B, // Launch7 (Ubuntu)
KEY_F17 = 0x6C, // Launch8 (Ubuntu)
KEY_F18 = 0x6D, // Launch9 (Ubuntu)
KEY_F19 = 0x6E, // Disabled (Ubuntu)
KEY_F20 = 0x6F, // AudioMicMute (Ubuntu)
KEY_F21 = 0x70, // Touchpad toggle (Ubuntu)
KEY_F22 = 0x71, // TouchpadOn (Ubuntu)
KEY_F23 = 0x72, // TouchpadOff Ubuntu)
KEY_F24 = 0x73, // Disabled (Ubuntu)
KEY_EXECUTE = 0x74, // Open (Ubuntu)
KEY_HELP = 0x75, // Help (Ubuntu)
KEY_MENU2 = 0x76, // Disabled (Ubuntu)
KEY_SELECT = 0x77, // Disabled (Ubuntu)
KEY_STOP = 0x78, // Cancel (Ubuntu)
KEY_AGAIN = 0x79, // Redo (Ubuntu)
KEY_UNDO = 0x7A, // Undo (Ubuntu)
KEY_CUT = 0x7B, // Cut (Ubuntu)
KEY_COPY = 0x7C, // Copy (Ubuntu)
KEY_PASTE = 0x7D, // Paste (Ubuntu)
KEY_FIND = 0x7E, // Find (Ubuntu)
KEY_MUTE = 0x7F,
KEY_VOLUME_MUTE = 0x7F, // Alias
KEY_VOLUME_UP = 0x80,
KEY_VOLUME_DOWN = 0x81,
KEY_LOCKING_CAPS_LOCK = 0x82, // Disabled (Ubuntu)
KEY_LOCKING_NUM_LOCK = 0x83, // Disabled (Ubuntu)
KEY_LOCKING_SCROLL_LOCK = 0x84, // Disabled (Ubuntu)
KEYPAD_COMMA = 0x85, // .
KEYPAD_EQUAL_SIGN = 0x86, // Disabled (Ubuntu), Dont confuse with KEYPAD_EQUAL
KEY_INTERNATIONAL1 = 0x87, // Disabled (Ubuntu)
KEY_INTERNATIONAL2 = 0x88, // Hiragana Katakana (Ubuntu)
KEY_INTERNATIONAL3 = 0x89, // Disabled (Ubuntu)
KEY_INTERNATIONAL4 = 0x8A, // Henkan (Ubuntu)
KEY_INTERNATIONAL5 = 0x8B, // Muhenkan (Ubuntu)
KEY_INTERNATIONAL6 = 0x8C, // Disabled (Ubuntu)
KEY_INTERNATIONAL7 = 0x8D, // Disabled (Ubuntu)
KEY_INTERNATIONAL8 = 0x8E, // Disabled (Ubuntu)
KEY_INTERNATIONAL9 = 0x8F, // Disabled (Ubuntu)
KEY_LANG1 = 0x90, // Disabled (Ubuntu)
KEY_LANG2 = 0x91, // Disabled (Ubuntu)
KEY_LANG3 = 0x92, // Katana (Ubuntu)
KEY_LANG4 = 0x93, // Hiragana (Ubuntu)
KEY_LANG5 = 0x94, // Disabled (Ubuntu)
KEY_LANG6 = 0x95, // Disabled (Ubuntu)
KEY_LANG7 = 0x96, // Disabled (Ubuntu)
KEY_LANG8 = 0x97, // Disabled (Ubuntu)
KEY_LANG9 = 0x98, // Disabled (Ubuntu)
KEY_ALTERNATE_ERASE = 0x99, // Disabled (Ubuntu)
KEY_SYSREQ_ATTENTION = 0x9A, // Disabled (Ubuntu)
KEY_CANCEL = 0x9B, // Disabled (Ubuntu)
KEY_CLEAR = 0x9C, // Delete (Ubuntu)
KEY_PRIOR = 0x9D, // Disabled (Ubuntu)
KEY_RETURN2 = 0x9E, // Disabled (Ubuntu), Do not confuse this with KEY_ENTER
KEY_SEPARATOR = 0x9F, // Disabled (Ubuntu)
KEY_OUT = 0xA0, // Disabled (Ubuntu)
KEY_OPER = 0xA1, // Disabled (Ubuntu)
KEY_CLEAR_AGAIN = 0xA2, // Disabled (Ubuntu)
KEY_CRSEL_PROPS = 0xA3, // Disabled (Ubuntu)
KEY_EXSEL = 0xA4, // Disabled (Ubuntu)
KEY_PAD_00 = 0xB0, // Disabled (Ubuntu)
KEY_PAD_000 = 0xB1, // Disabled (Ubuntu)
KEY_THOUSANDS_SEPARATOR = 0xB2, // Disabled (Ubuntu)
KEY_DECIMAL_SEPARATOR = 0xB3, // Disabled (Ubuntu)
KEY_CURRENCY_UNIT = 0xB4, // Disabled (Ubuntu)
KEY_CURRENCY_SUB_UNIT = 0xB5, // Disabled (Ubuntu)
KEYPAD_LEFT_BRACE = 0xB6, // (
KEYPAD_RIGHT_BRACE = 0xB7, // )
KEYPAD_LEFT_CURLY_BRACE = 0xB8, // Disabled (Ubuntu)
KEYPAD_RIGHT_CURLY_BRACE = 0xB9, // Disabled (Ubuntu)
KEYPAD_TAB = 0xBA, // Disabled (Ubuntu)
KEYPAD_BACKSPACE = 0xBB, // Disabled (Ubuntu)
KEYPAD_A = 0xBC, // Disabled (Ubuntu)
KEYPAD_B = 0xBD, // Disabled (Ubuntu)
KEYPAD_C = 0xBE, // Disabled (Ubuntu)
KEYPAD_D = 0xBF, // Disabled (Ubuntu)
KEYPAD_E = 0xC0, // Disabled (Ubuntu)
KEYPAD_F = 0xC1, // Disabled (Ubuntu)
KEYPAD_XOR = 0xC2, // Disabled (Ubuntu)
KEYPAD_CARET = 0xC3, // Disabled (Ubuntu)
KEYPAD_PERCENT = 0xC4, // Disabled (Ubuntu)
KEYPAD_LESS_THAN = 0xC5, // Disabled (Ubuntu)
KEYPAD_GREATER_THAN = 0xC6, // Disabled (Ubuntu)
KEYPAD_AMPERSAND = 0xC7, // Disabled (Ubuntu)
KEYPAD_DOUBLEAMPERSAND = 0xC8, // Disabled (Ubuntu)
KEYPAD_PIPE = 0xC9, // Disabled (Ubuntu)
KEYPAD_DOUBLEPIPE = 0xCA, // Disabled (Ubuntu)
KEYPAD_COLON = 0xCB, // Disabled (Ubuntu)
KEYPAD_POUND_SIGN = 0xCC, // Disabled (Ubuntu)
KEYPAD_SPACE = 0xCD, // Disabled (Ubuntu)
KEYPAD_AT_SIGN = 0xCE, // Disabled (Ubuntu)
KEYPAD_EXCLAMATION_POINT = 0xCF, // Disabled (Ubuntu)
KEYPAD_MEMORY_STORE = 0xD0, // Disabled (Ubuntu)
KEYPAD_MEMORY_RECALL = 0xD1, // Disabled (Ubuntu)
KEYPAD_MEMORY_CLEAR = 0xD2, // Disabled (Ubuntu)
KEYPAD_MEMORY_ADD = 0xD3, // Disabled (Ubuntu)
KEYPAD_MEMORY_SUBTRACT = 0xD4, // Disabled (Ubuntu)
KEYPAD_MEMORY_MULTIPLY = 0xD5, // Disabled (Ubuntu)
KEYPAD_MEMORY_DIVIDE = 0xD6, // Disabled (Ubuntu)
KEYPAD_PLUS_MINUS = 0xD7, // Disabled (Ubuntu)
KEYPAD_CLEAR = 0xD8, // Delete (Ubuntu)
KEYPAD_CLEAR_ENTRY = 0xD9, // Disabled (Ubuntu)
KEYPAD_BINARY = 0xDA, // Disabled (Ubuntu)
KEYPAD_OCTAL = 0xDB, // Disabled (Ubuntu)
KEYPAD_DECIMAL = 0xDC, // Disabled (Ubuntu)
KEYPAD_HEXADECIMAL = 0xDD, // Disabled (Ubuntu)
KEY_LEFT_CTRL = 0xE0,
KEY_LEFT_SHIFT = 0xE1,
KEY_LEFT_ALT = 0xE2,
KEY_LEFT_GUI = 0xE3,
KEY_LEFT_WINDOWS = 0xE3, // Alias
KEY_RIGHT_CTRL = 0xE4,
KEY_RIGHT_SHIFT = 0xE5,
KEY_RIGHT_ALT = 0xE6,
KEY_RIGHT_GUI = 0xE7,
KEY_RIGHT_WINDOWS = 0xE7, // Alias
// Keyboard HID mappings
// Reserved (no_event_indicated)
HID_KEYBOARD_ERROR_ROLLOVER = 0x01,
HID_KEYBOARD_POST_FAIL = 0x02,
HID_KEYBOARD_ERROR_UNDEFINED = 0x03,
HID_KEYBOARD_A_AND_A = 0x04,
HID_KEYBOARD_B_AND_B = 0x05,
HID_KEYBOARD_C_AND_C = 0x06,
HID_KEYBOARD_D_AND_D = 0x07,
HID_KEYBOARD_E_AND_E = 0x08,
HID_KEYBOARD_F_AND_F = 0x09,
HID_KEYBOARD_G_AND_G = 0x0A,
HID_KEYBOARD_H_AND_H = 0x0B,
HID_KEYBOARD_I_AND_I = 0x0C,
HID_KEYBOARD_J_AND_J = 0x0D,
HID_KEYBOARD_K_AND_K = 0x0E,
HID_KEYBOARD_L_AND_L = 0x0F,
HID_KEYBOARD_M_AND_M = 0x10,
HID_KEYBOARD_N_AND_N = 0x11,
HID_KEYBOARD_O_AND_O = 0x12,
HID_KEYBOARD_P_AND_P = 0x13,
HID_KEYBOARD_Q_AND_Q = 0x14,
HID_KEYBOARD_R_AND_R = 0x15,
HID_KEYBOARD_S_AND_S = 0x16,
HID_KEYBOARD_T_AND_T = 0x17,
HID_KEYBOARD_U_AND_U = 0x18,
HID_KEYBOARD_V_AND_V = 0x19,
HID_KEYBOARD_W_AND_W = 0x1A,
HID_KEYBOARD_X_AND_X = 0x1B,
HID_KEYBOARD_Y_AND_Y = 0x1C,
HID_KEYBOARD_Z_AND_Z = 0x1D,
HID_KEYBOARD_1_AND_EXCLAMATION_POINT = 0x1E,
HID_KEYBOARD_2_AND_AT = 0x1F,
HID_KEYBOARD_3_AND_POUND = 0x20,
HID_KEYBOARD_4_AND_DOLLAR = 0x21,
HID_KEYBOARD_5_AND_PERCENT = 0x22,
HID_KEYBOARD_6_AND_CARAT = 0x23,
HID_KEYBOARD_7_AND_AMPERSAND = 0x24,
HID_KEYBOARD_8_AND_ASTERISK = 0x25,
HID_KEYBOARD_9_AND_LEFT_PAREN = 0x26,
HID_KEYBOARD_0_AND_RIGHT_PAREN = 0x27,
HID_KEYBOARD_ENTER = 0x28, // (MARKED AS ENTER_SLASH_RETURN)
HID_KEYBOARD_ESCAPE = 0x29,
HID_KEYBOARD_DELETE = 0x2A, // (BACKSPACE)
HID_KEYBOARD_TAB = 0x2B,
HID_KEYBOARD_SPACEBAR = 0x2C,
HID_KEYBOARD_MINUS_AND_UNDERSCORE = 0x2D, // (UNDERSCORE)
HID_KEYBOARD_EQUALS_AND_PLUS = 0x2E,
HID_KEYBOARD_LEFT_BRACKET_AND_LEFT_CURLY_BRACE = 0x2F,
HID_KEYBOARD_RIGHT_BRACKET_AND_RIGHT_CURLY_BRACE = 0x30,
HID_KEYBOARD_BACKSLASH_AND_PIPE = 0x31,
HID_KEYBOARD_NON_US_POUND_AND_TILDE = 0x32,
HID_KEYBOARD_SEMICOLON_AND_COLON = 0x33,
HID_KEYBOARD_QUOTE_AND_DOUBLEQUOTE = 0x34,
HID_KEYBOARD_GRAVE_ACCENT_AND_TILDE = 0x35,
HID_KEYBOARD_COMMA_AND_LESS_THAN = 0x36,
HID_KEYBOARD_PERIOD_AND_GREATER_THAN = 0x37,
HID_KEYBOARD_SLASH_AND_QUESTION_MARK = 0x38,
HID_KEYBOARD_CAPS_LOCK = 0x39,
HID_KEYBOARD_F1 = 0x3A,
HID_KEYBOARD_F2 = 0x3B,
HID_KEYBOARD_F3 = 0x3C,
HID_KEYBOARD_F4 = 0x3D,
HID_KEYBOARD_F5 = 0x3E,
HID_KEYBOARD_F6 = 0x3F,
HID_KEYBOARD_F7 = 0x40,
HID_KEYBOARD_F8 = 0x41,
HID_KEYBOARD_F9 = 0x42,
HID_KEYBOARD_F10 = 0x43,
HID_KEYBOARD_F11 = 0x44,
HID_KEYBOARD_F12 = 0x45,
HID_KEYBOARD_PRINTSCREEN = 0x46,
HID_KEYBOARD_SCROLL_LOCK = 0x47,
HID_KEYBOARD_PAUSE = 0x48,
HID_KEYBOARD_INSERT = 0x49,
HID_KEYBOARD_HOME = 0x4A,
HID_KEYBOARD_PAGE_UP = 0x4B,
HID_KEYBOARD_DELETE_FORWARD = 0x4C,
HID_KEYBOARD_END = 0x4D,
HID_KEYBOARD_PAGE_DOWN = 0x4E,
HID_KEYBOARD_RIGHTARROW = 0x4F,
HID_KEYBOARD_LEFTARROW = 0x50,
HID_KEYBOARD_DOWNARROW = 0x51,
HID_KEYBOARD_UPARROW = 0x52,
HID_KEYPAD_NUM_LOCK_AND_CLEAR = 0x53,
HID_KEYPAD_DIVIDE = 0x54,
HID_KEYPAD_MULTIPLY = 0x55,
HID_KEYPAD_SUBTRACT = 0x56,
HID_KEYPAD_ADD = 0x57,
HID_KEYPAD_ENTER = 0x58,
HID_KEYPAD_1_AND_END = 0x59,
HID_KEYPAD_2_AND_DOWN_ARROW = 0x5A,
HID_KEYPAD_3_AND_PAGE_DOWN = 0x5B,
HID_KEYPAD_4_AND_LEFT_ARROW = 0x5C,
HID_KEYPAD_5 = 0x5D,
HID_KEYPAD_6_AND_RIGHT_ARROW = 0x5E,
HID_KEYPAD_7_AND_HOME = 0x5F,
HID_KEYPAD_8_AND_UP_ARROW = 0x60,
HID_KEYPAD_9_AND_PAGE_UP = 0x61,
HID_KEYPAD_0_AND_INSERT = 0x62,
HID_KEYPAD_PERIOD_AND_DELETE = 0x63,
HID_KEYBOARD_NON_US_BACKSLASH_AND_PIPE = 0x64,
HID_KEYBOARD_APPLICATION = 0x65,
HID_KEYBOARD_POWER = 0x66,
HID_KEYPAD_EQUALS = 0x67,
HID_KEYBOARD_F13 = 0x68,
HID_KEYBOARD_F14 = 0x69,
HID_KEYBOARD_F15 = 0x6A,
HID_KEYBOARD_F16 = 0x6B,
HID_KEYBOARD_F17 = 0x6C,
HID_KEYBOARD_F18 = 0x6D,
HID_KEYBOARD_F19 = 0x6E,
HID_KEYBOARD_F20 = 0x6F,
HID_KEYBOARD_F21 = 0x70,
HID_KEYBOARD_F22 = 0x71,
HID_KEYBOARD_F23 = 0x72,
HID_KEYBOARD_F24 = 0x73,
HID_KEYBOARD_EXECUTE = 0x74,
HID_KEYBOARD_HELP = 0x75,
HID_KEYBOARD_MENU = 0x76,
HID_KEYBOARD_SELECT = 0x77,
HID_KEYBOARD_STOP = 0x78,
HID_KEYBOARD_AGAIN = 0x79,
HID_KEYBOARD_UNDO = 0x7A,
HID_KEYBOARD_CUT = 0x7B,
HID_KEYBOARD_COPY = 0x7C,
HID_KEYBOARD_PASTE = 0x7D,
HID_KEYBOARD_FIND = 0x7E,
HID_KEYBOARD_MUTE = 0x7F,
HID_KEYBOARD_VOLUME_UP = 0x80,
HID_KEYBOARD_VOLUME_DOWN = 0x81,
HID_KEYBOARD_LOCKING_CAPS_LOCK = 0x82,
HID_KEYBOARD_LOCKING_NUM_LOCK = 0x83,
HID_KEYBOARD_LOCKING_SCROLL_LOCK = 0x84,
HID_KEYPAD_COMMA = 0x85,
HID_KEYPAD_EQUAL_SIGN = 0x86,
HID_KEYBOARD_INTERNATIONAL1 = 0x87,
HID_KEYBOARD_INTERNATIONAL2 = 0x88,
HID_KEYBOARD_INTERNATIONAL3 = 0x89,
HID_KEYBOARD_INTERNATIONAL4 = 0x8A,
HID_KEYBOARD_INTERNATIONAL5 = 0x8B,
HID_KEYBOARD_INTERNATIONAL6 = 0x8C,
HID_KEYBOARD_INTERNATIONAL7 = 0x8D,
HID_KEYBOARD_INTERNATIONAL8 = 0x8E,
HID_KEYBOARD_INTERNATIONAL9 = 0x8F,
HID_KEYBOARD_LANG1 = 0x90,
HID_KEYBOARD_LANG2 = 0x91,
HID_KEYBOARD_LANG3 = 0x92,
HID_KEYBOARD_LANG4 = 0x93,
HID_KEYBOARD_LANG5 = 0x94,
HID_KEYBOARD_LANG6 = 0x95,
HID_KEYBOARD_LANG7 = 0x96,
HID_KEYBOARD_LANG8 = 0x97,
HID_KEYBOARD_LANG9 = 0x98,
HID_KEYBOARD_ALTERNATE_ERASE = 0x99,
HID_KEYBOARD_SYSREQ_SLASH_ATTENTION = 0x9A,
HID_KEYBOARD_CANCEL = 0x9B,
HID_KEYBOARD_CLEAR = 0x9C,
HID_KEYBOARD_PRIOR = 0x9D,
HID_KEYBOARD_RETURN = 0x9E,
HID_KEYBOARD_SEPARATOR = 0x9F,
HID_KEYBOARD_OUT = 0xA0,
HID_KEYBOARD_OPER = 0xA1,
HID_KEYBOARD_CLEAR_SLASH_AGAIN = 0xA2,
HID_KEYBOARD_CRSEL_SLASH_PROPS = 0xA3,
HID_KEYBOARD_EXSEL = 0xA4,
// Reserved 0xA5-AF
HID_KEYPAD_00 = 0xB0,
HID_KEYPAD_000 = 0xB1,
HID_THOUSANDS_SEPARATOR = 0xB2,
HID_DECIMAL_SEPARATOR = 0xB3,
HID_CURRENCY_UNIT = 0xB4,
HID_CURRENCY_SUBUNIT = 0xB5,
HID_KEYPAD_LEFT_PAREN = 0xB6,
HID_KEYPAD_RIGHT_PAREN = 0xB7,
HID_KEYPAD_LEFT_CURLY_BRACE = 0xB8,
HID_KEYPAD_RIGHT_CURLY_BRACE = 0xB9,
HID_KEYPAD_TAB = 0xBA,
HID_KEYPAD_BACKSPACE = 0xBB,
HID_KEYPAD_A = 0xBC,
HID_KEYPAD_B = 0xBD,
HID_KEYPAD_C = 0xBE,
HID_KEYPAD_D = 0xBF,
HID_KEYPAD_E = 0xC0,
HID_KEYPAD_F = 0xC1,
HID_KEYPAD_XOR = 0xC2,
HID_KEYPAD_CARAT = 0xC3,
HID_KEYPAD_PERCENT = 0xC4,
HID_KEYPAD_LESS_THAN = 0xC5,
HID_KEYPAD_GREATER_THAN = 0xC6,
HID_KEYPAD_AMPERSAND = 0xC7,
HID_KEYPAD_DOUBLEAMPERSAND = 0xC8,
HID_KEYPAD_PIPE = 0xC9,
HID_KEYPAD_DOUBLEPIPE = 0xCA,
HID_KEYPAD_COLON = 0xCB,
HID_KEYPAD_POUND_SIGN = 0xCC,
HID_KEYPAD_SPACE = 0xCD,
HID_KEYPAD_AT_SIGN = 0xCE,
HID_KEYPAD_EXCLAMATION_POINT = 0xCF,
HID_KEYPAD_MEMORY_STORE = 0xD0,
HID_KEYPAD_MEMORY_RECALL = 0xD1,
HID_KEYPAD_MEMORY_CLEAR = 0xD2,
HID_KEYPAD_MEMORY_ADD = 0xD3,
HID_KEYPAD_MEMORY_SUBTRACT = 0xD4,
HID_KEYPAD_MEMORY_MULTIPLY = 0xD5,
HID_KEYPAD_MEMORY_DIVIDE = 0xD6,
HID_KEYPAD_PLUS_SLASH_MINUS = 0xD7,
HID_KEYPAD_CLEAR = 0xD8,
HID_KEYPAD_CLEAR_ENTRY = 0xD9,
HID_KEYPAD_BINARY = 0xDA,
HID_KEYPAD_OCTAL = 0xDB,
HID_KEYPAD_DECIMAL = 0xDC,
HID_KEYPAD_HEXADECIMAL = 0xDD,
// 0xDE-0xDF - RESERVED
HID_KEYBOARD_LEFT_CONTROL = 0xE0,
HID_KEYBOARD_LEFT_SHIFT = 0xE1,
HID_KEYBOARD_LEFT_ALT = 0xE2,
HID_KEYBOARD_LEFT_GUI = 0xE3,
HID_KEYBOARD_RIGHT_CONTROL = 0xE4,
HID_KEYBOARD_RIGHT_SHIFT = 0xE5,
HID_KEYBOARD_RIGHT_ALT = 0xE6,
HID_KEYBOARD_RIGHT_GUI = 0xE7,
};

View File

@ -22,118 +22,116 @@
#pragma once #pragma once
#include "keycode.h"
uint8_t keymapUsb(uint8_t code) {
KeyboardKeycode keymapUsb(uint8_t code) {
switch (code) { switch (code) {
case 1: return KEY_A; case 1: return 4; // KeyA
case 2: return KEY_B; case 2: return 5; // KeyB
case 3: return KEY_C; case 3: return 6; // KeyC
case 4: return KEY_D; case 4: return 7; // KeyD
case 5: return KEY_E; case 5: return 8; // KeyE
case 6: return KEY_F; case 6: return 9; // KeyF
case 7: return KEY_G; case 7: return 10; // KeyG
case 8: return KEY_H; case 8: return 11; // KeyH
case 9: return KEY_I; case 9: return 12; // KeyI
case 10: return KEY_J; case 10: return 13; // KeyJ
case 11: return KEY_K; case 11: return 14; // KeyK
case 12: return KEY_L; case 12: return 15; // KeyL
case 13: return KEY_M; case 13: return 16; // KeyM
case 14: return KEY_N; case 14: return 17; // KeyN
case 15: return KEY_O; case 15: return 18; // KeyO
case 16: return KEY_P; case 16: return 19; // KeyP
case 17: return KEY_Q; case 17: return 20; // KeyQ
case 18: return KEY_R; case 18: return 21; // KeyR
case 19: return KEY_S; case 19: return 22; // KeyS
case 20: return KEY_T; case 20: return 23; // KeyT
case 21: return KEY_U; case 21: return 24; // KeyU
case 22: return KEY_V; case 22: return 25; // KeyV
case 23: return KEY_W; case 23: return 26; // KeyW
case 24: return KEY_X; case 24: return 27; // KeyX
case 25: return KEY_Y; case 25: return 28; // KeyY
case 26: return KEY_Z; case 26: return 29; // KeyZ
case 27: return KEY_1; case 27: return 30; // Digit1
case 28: return KEY_2; case 28: return 31; // Digit2
case 29: return KEY_3; case 29: return 32; // Digit3
case 30: return KEY_4; case 30: return 33; // Digit4
case 31: return KEY_5; case 31: return 34; // Digit5
case 32: return KEY_6; case 32: return 35; // Digit6
case 33: return KEY_7; case 33: return 36; // Digit7
case 34: return KEY_8; case 34: return 37; // Digit8
case 35: return KEY_9; case 35: return 38; // Digit9
case 36: return KEY_0; case 36: return 39; // Digit0
case 37: return KEY_ENTER; case 37: return 40; // Enter
case 38: return KEY_ESC; case 38: return 41; // Escape
case 39: return KEY_BACKSPACE; case 39: return 42; // Backspace
case 40: return KEY_TAB; case 40: return 43; // Tab
case 41: return KEY_SPACE; case 41: return 44; // Space
case 42: return KEY_MINUS; case 42: return 45; // Minus
case 43: return KEY_EQUAL; case 43: return 46; // Equal
case 44: return KEY_LEFT_BRACE; case 44: return 47; // BracketLeft
case 45: return KEY_RIGHT_BRACE; case 45: return 48; // BracketRight
case 46: return KEY_BACKSLASH; case 46: return 49; // Backslash
case 47: return KEY_SEMICOLON; case 47: return 51; // Semicolon
case 48: return KEY_QUOTE; case 48: return 52; // Quote
case 49: return KEY_TILDE; case 49: return 53; // Backquote
case 50: return KEY_COMMA; case 50: return 54; // Comma
case 51: return KEY_PERIOD; case 51: return 55; // Period
case 52: return KEY_SLASH; case 52: return 56; // Slash
case 53: return KEY_CAPS_LOCK; case 53: return 57; // CapsLock
case 54: return KEY_F1; case 54: return 58; // F1
case 55: return KEY_F2; case 55: return 59; // F2
case 56: return KEY_F3; case 56: return 60; // F3
case 57: return KEY_F4; case 57: return 61; // F4
case 58: return KEY_F5; case 58: return 62; // F5
case 59: return KEY_F6; case 59: return 63; // F6
case 60: return KEY_F7; case 60: return 64; // F7
case 61: return KEY_F8; case 61: return 65; // F8
case 62: return KEY_F9; case 62: return 66; // F9
case 63: return KEY_F10; case 63: return 67; // F10
case 64: return KEY_F11; case 64: return 68; // F11
case 65: return KEY_F12; case 65: return 69; // F12
case 66: return KEY_PRINT; case 66: return 70; // PrintScreen
case 67: return KEY_INSERT; case 67: return 73; // Insert
case 68: return KEY_HOME; case 68: return 74; // Home
case 69: return KEY_PAGE_UP; case 69: return 75; // PageUp
case 70: return KEY_DELETE; case 70: return 76; // Delete
case 71: return KEY_END; case 71: return 77; // End
case 72: return KEY_PAGE_DOWN; case 72: return 78; // PageDown
case 73: return KEY_RIGHT_ARROW; case 73: return 79; // ArrowRight
case 74: return KEY_LEFT_ARROW; case 74: return 80; // ArrowLeft
case 75: return KEY_DOWN_ARROW; case 75: return 81; // ArrowDown
case 76: return KEY_UP_ARROW; case 76: return 82; // ArrowUp
case 77: return KEY_LEFT_CTRL; case 77: return 224; // ControlLeft
case 78: return KEY_LEFT_SHIFT; case 78: return 225; // ShiftLeft
case 79: return KEY_LEFT_ALT; case 79: return 226; // AltLeft
case 80: return KEY_LEFT_GUI; case 80: return 227; // MetaLeft
case 81: return KEY_RIGHT_CTRL; case 81: return 228; // ControlRight
case 82: return KEY_RIGHT_SHIFT; case 82: return 229; // ShiftRight
case 83: return KEY_RIGHT_ALT; case 83: return 230; // AltRight
case 84: return KEY_RIGHT_GUI; case 84: return 231; // MetaRight
case 85: return KEY_PAUSE; case 85: return 72; // Pause
case 86: return KEY_SCROLL_LOCK; case 86: return 71; // ScrollLock
case 87: return KEY_NUM_LOCK; case 87: return 83; // NumLock
case 88: return KEY_MENU; case 88: return 101; // ContextMenu
case 89: return KEYPAD_DIVIDE; case 89: return 84; // NumpadDivide
case 90: return KEYPAD_MULTIPLY; case 90: return 85; // NumpadMultiply
case 91: return KEYPAD_SUBTRACT; case 91: return 86; // NumpadSubtract
case 92: return KEYPAD_ADD; case 92: return 87; // NumpadAdd
case 93: return KEYPAD_ENTER; case 93: return 88; // NumpadEnter
case 94: return KEYPAD_1; case 94: return 89; // Numpad1
case 95: return KEYPAD_2; case 95: return 90; // Numpad2
case 96: return KEYPAD_3; case 96: return 91; // Numpad3
case 97: return KEYPAD_4; case 97: return 92; // Numpad4
case 98: return KEYPAD_5; case 98: return 93; // Numpad5
case 99: return KEYPAD_6; case 99: return 94; // Numpad6
case 100: return KEYPAD_7; case 100: return 95; // Numpad7
case 101: return KEYPAD_8; case 101: return 96; // Numpad8
case 102: return KEYPAD_9; case 102: return 97; // Numpad9
case 103: return KEYPAD_0; case 103: return 98; // Numpad0
case 104: return KEYPAD_DOT; case 104: return 99; // NumpadDecimal
case 105: return KEY_POWER; case 105: return 102; // Power
case 106: return KEY_NON_US; case 106: return 100; // IntlBackslash
case 107: return KEY_INTERNATIONAL3; case 107: return 137; // IntlYen
default: return KEY_ERROR_UNDEFINED; default: return 0;
} }
} }

View File

@ -22,14 +22,16 @@
#pragma once #pragma once
#include "keycode.h"
<%! import operator %> <%! import operator %>
KeyboardKeycode keymapUsb(uint8_t code) { uint8_t keymapUsb(uint8_t code) {
switch (code) { switch (code) {
% for km in sorted(keymap, key=operator.attrgetter("mcu_code")): % for km in sorted(keymap, key=operator.attrgetter("mcu_code")):
case ${km.mcu_code}: return ${km.arduino_name}; % if km.usb_key.is_modifier:
case ${km.mcu_code}: return ${km.usb_key.arduino_modifier_code}; // ${km.web_name}
% else:
case ${km.mcu_code}: return ${km.usb_key.code}; // ${km.web_name}
% endif
% endfor % endfor
default: return KEY_ERROR_UNDEFINED; default: return 0;
} }
} }

View File

@ -19,14 +19,16 @@
# # # #
*****************************************************************************/ *****************************************************************************/
#pragma once #pragma once
#include <USBComposite.h>
#include "mouse.h" #include "mouse.h"
#include "hid-wrapper-stm32.h" #include "hid-wrapper-stm32.h"
#include <USBComposite.h>
namespace DRIVERS { namespace DRIVERS {
const uint8_t reportDescriptionMouseAbsolute[] = { const uint8_t reportDescriptionMouseAbsolute[] = {
HID_ABS_MOUSE_REPORT_DESCRIPTOR() HID_ABS_MOUSE_REPORT_DESCRIPTOR()
}; };
@ -43,7 +45,7 @@ namespace DRIVERS {
} }
void clear() override { void clear() override {
_mouse.release(0xff); _mouse.release(0xFF);
} }
void sendButtons ( void sendButtons (
@ -52,9 +54,17 @@ namespace DRIVERS {
bool middle_select, bool middle_state, bool middle_select, bool middle_state,
bool up_select, bool up_state, bool up_select, bool up_state,
bool down_select, bool down_state) override { bool down_select, bool down_state) override {
if(left_select) left_state ? _mouse.press(MOUSE_LEFT) : _mouse.release(MOUSE_LEFT);
if(right_select) right_state ? _mouse.press(MOUSE_RIGHT) : _mouse.release(MOUSE_RIGHT); # define SEND_BUTTON(x_low, x_up) { \
if(middle_select) middle_state ? _mouse.press(MOUSE_MIDDLE) : _mouse.release(MOUSE_MIDDLE); if (x_low##_select) { \
if (x_low##_state) _mouse.press(MOUSE_##x_up); \
else _mouse.release(MOUSE_##x_up); \
} \
}
SEND_BUTTON(left, LEFT);
SEND_BUTTON(right, RIGHT);
SEND_BUTTON(middle, MIDDLE);
# undef SEND_BUTTON
} }
void sendMove(int x, int y) override { void sendMove(int x, int y) override {
@ -66,7 +76,7 @@ namespace DRIVERS {
} }
bool isOffline() override { bool isOffline() override {
return USBComposite == false; return (USBComposite == false);
} }
private: private:

View File

@ -19,14 +19,16 @@
# # # #
*****************************************************************************/ *****************************************************************************/
#pragma once #pragma once
#include <USBComposite.h>
#include "mouse.h" #include "mouse.h"
#include "hid-wrapper-stm32.h" #include "hid-wrapper-stm32.h"
#include <USBComposite.h>
namespace DRIVERS { namespace DRIVERS {
const uint8_t reportDescriptionMouseRelative[] = { const uint8_t reportDescriptionMouseRelative[] = {
HID_MOUSE_REPORT_DESCRIPTOR() HID_MOUSE_REPORT_DESCRIPTOR()
}; };
@ -43,7 +45,7 @@ namespace DRIVERS {
} }
void clear() override { void clear() override {
_mouse.release(0xff); _mouse.release(0xFF);
} }
void sendButtons ( void sendButtons (
@ -52,9 +54,17 @@ namespace DRIVERS {
bool middle_select, bool middle_state, bool middle_select, bool middle_state,
bool up_select, bool up_state, bool up_select, bool up_state,
bool down_select, bool down_state) override { bool down_select, bool down_state) override {
if(left_select) left_state ? _mouse.press(MOUSE_LEFT) : _mouse.release(MOUSE_LEFT);
if(right_select) right_state ? _mouse.press(MOUSE_RIGHT) : _mouse.release(MOUSE_RIGHT); # define SEND_BUTTON(x_low, x_up) { \
if(middle_select) middle_state ? _mouse.press(MOUSE_MIDDLE) : _mouse.release(MOUSE_MIDDLE); if (x_low##_select) { \
if (x_low##_state) _mouse.press(MOUSE_##x_up); \
else _mouse.release(MOUSE_##x_up); \
} \
}
SEND_BUTTON(left, LEFT);
SEND_BUTTON(right, RIGHT);
SEND_BUTTON(middle, MIDDLE);
# undef SEND_BUTTON
} }
void sendRelative(int x, int y) override { void sendRelative(int x, int y) override {
@ -66,7 +76,7 @@ namespace DRIVERS {
} }
bool isOffline() override { bool isOffline() override {
return USBComposite == false; return (USBComposite == false);
} }
private: private: