diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | hid/.gitignore | 1 | ||||
-rw-r--r-- | hid/Makefile | 5 | ||||
-rw-r--r-- | hid/lib/drivers-stm32/README.md | 18 | ||||
-rw-r--r-- | hid/lib/drivers-stm32/backup-register.h | 48 | ||||
-rw-r--r-- | hid/lib/drivers-stm32/factory.cpp | 81 | ||||
-rw-r--r-- | hid/lib/drivers-stm32/usb/hid-wrapper-stm32.h | 81 | ||||
-rw-r--r-- | hid/lib/drivers-stm32/usb/keyboard-stm32.h | 86 | ||||
-rw-r--r-- | hid/lib/drivers-stm32/usb/keycode.h | 526 | ||||
-rw-r--r-- | hid/lib/drivers-stm32/usb/keymap.h | 139 | ||||
-rw-r--r-- | hid/lib/drivers-stm32/usb/keymap.h.mako | 35 | ||||
-rw-r--r-- | hid/lib/drivers-stm32/usb/mouse-absolute-stm32.h | 76 | ||||
-rw-r--r-- | hid/lib/drivers-stm32/usb/mouse-relative-stm32.h | 76 | ||||
-rw-r--r-- | hid/lib/drivers/mouse.h | 5 | ||||
-rw-r--r-- | hid/patch.py | 21 | ||||
-rw-r--r-- | hid/patches/platformio-stm32f1-no-serial-usb.patch | 11 | ||||
-rw-r--r-- | hid/platformio-stm32.ini | 52 | ||||
-rw-r--r-- | hid/src/main.cpp | 1 |
18 files changed, 1254 insertions, 9 deletions
@@ -209,6 +209,7 @@ keymap: testenv && ./genmap.py keymap.csv kvmd/keyboard/mappings.py.mako kvmd/keyboard/mappings.py \ && ./genmap.py keymap.csv hid/lib/drivers-avr/usb/keymap.h.mako hid/lib/drivers-avr/usb/keymap.h \ && ./genmap.py keymap.csv hid/lib/drivers-avr/ps2/keymap.h.mako hid/lib/drivers-avr/ps2/keymap.h \ + && ./genmap.py keymap.csv hid/lib/drivers-stm32/usb/keymap.h.mako hid/lib/drivers-stm32/usb/keymap.h \ " diff --git a/hid/.gitignore b/hid/.gitignore index 0828bf8f..816b2920 100644 --- a/hid/.gitignore +++ b/hid/.gitignore @@ -2,3 +2,4 @@ /.current /.vscode/ /.config +/platformio.ini diff --git a/hid/Makefile b/hid/Makefile index 4f671ca3..4efc42b4 100644 --- a/hid/Makefile +++ b/hid/Makefile @@ -4,6 +4,9 @@ spi: make _build E=spi C=avr aum: make _build E=aum C=avr +stm32: + platformio run --environment patch --project-conf platformio-stm32.ini + make _build E=serial C=stm32 _build: rm -f .current .config platformio run --environment $(E) --project-conf platformio-$(C).ini @@ -11,7 +14,7 @@ _build: echo -n $(C) > .config # Added to easy test all builds -_build_all: aum spi serial +_build_all: aum spi serial stm32 rm -f .current .config install: upload diff --git a/hid/lib/drivers-stm32/README.md b/hid/lib/drivers-stm32/README.md new file mode 100644 index 00000000..03fc4eec --- /dev/null +++ b/hid/lib/drivers-stm32/README.md @@ -0,0 +1,18 @@ +This is WIP. Use AVR version as reference. + +TODO: +- [x] Serial communication +- [x] USB keyboard +- [x] USB keyboard - add scroll status +- [x] USB keyboard - key sending +- [x] USB keyboard - test key mapping +- [x] Persistent storage +- [ ] SPI communication +- [ ] PS2 keyboard +- [x] USB absolute mouse +- [x] USB absolute mouse - add whele +- [x] USB relative mouse +- [x] USB relative mouse - add whele +- [ ] USB mouses - up down button +- [ ] WIN98 USB mouse +- [x] undefine SERIAL_USB diff --git a/hid/lib/drivers-stm32/backup-register.h b/hid/lib/drivers-stm32/backup-register.h new file mode 100644 index 00000000..10ab442b --- /dev/null +++ b/hid/lib/drivers-stm32/backup-register.h @@ -0,0 +1,48 @@ +/***************************************************************************** +# # +# KVMD - The main PiKVM daemon. # +# # +# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> # +# # +# 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/>. # +# # +*****************************************************************************/ + +#include "storage.h" +#include <stm32f1_rtc.h> + +namespace DRIVERS { + struct BackupRegister : public Storage { + BackupRegister() : Storage(NON_VOLATILE_STORAGE) { + _rtc.enableClockInterface(); + } + + void readBlock(void *dest, const void *src, size_t size) override { + uint8_t* _dest = reinterpret_cast<uint8_t*>(dest); + for(size_t i = 0; i < size; ++i) { + _dest[i] = _rtc.getBackupRegister(reinterpret_cast<uintptr_t>(src) + i + 1); + } + } + + void updateBlock(const void *src, void *dest, size_t size) override { + const uint8_t* _src = reinterpret_cast<const uint8_t*>(src); + for(size_t i = 0; i < size; ++i) { + _rtc.setBackupRegister(reinterpret_cast<uintptr_t>(dest) + i + 1, _src[i]); + } + } + + private: + STM32F1_RTC _rtc; + }; +} diff --git a/hid/lib/drivers-stm32/factory.cpp b/hid/lib/drivers-stm32/factory.cpp new file mode 100644 index 00000000..4cf96f03 --- /dev/null +++ b/hid/lib/drivers-stm32/factory.cpp @@ -0,0 +1,81 @@ +/***************************************************************************** +# # +# KVMD - The main PiKVM daemon. # +# # +# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> # +# # +# 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/>. # +# # +*****************************************************************************/ + +#include "factory.h" +#include "usb/keyboard-stm32.h" +#include "usb/hid-wrapper-stm32.h" +#include "usb/mouse-absolute-stm32.h" +#include "usb/mouse-relative-stm32.h" +#include "backup-register.h" + +#ifndef __STM32F1__ +# error "Only STM32F1 is supported" +#endif +#ifdef SERIAL_USB +# error "Disable random USB enumeration" +#endif + +namespace DRIVERS +{ +#if 0 + USBCompositeSerial _serial; + HidWrapper _hidWrapper(&_serial); +#else + HidWrapper _hidWrapper; +#endif + + Keyboard *Factory::makeKeyboard(type _type) { + switch (_type) { +# ifdef HID_WITH_USB + case USB_KEYBOARD: + return new UsbKeyboard(_hidWrapper); +# endif + default: + return new Keyboard(DUMMY); + } + } + + Mouse *Factory::makeMouse(type _type) { + switch(_type) { +# ifdef HID_WITH_USB + case USB_MOUSE_ABSOLUTE: + return new UsbMouseAbsolute(_hidWrapper); + case USB_MOUSE_RELATIVE: + return new UsbMouseRelative(_hidWrapper); +# endif + default: + return new Mouse(DRIVERS::DUMMY); + } + } + + Storage* Factory::makeStorage(type _type) { + switch (_type) { +# ifdef HID_DYNAMIC + case NON_VOLATILE_STORAGE: + return new BackupRegister(); +# endif + default: + return new Storage(DRIVERS::DUMMY); + } + } +} + + diff --git a/hid/lib/drivers-stm32/usb/hid-wrapper-stm32.h b/hid/lib/drivers-stm32/usb/hid-wrapper-stm32.h new file mode 100644 index 00000000..10bd29ef --- /dev/null +++ b/hid/lib/drivers-stm32/usb/hid-wrapper-stm32.h @@ -0,0 +1,81 @@ +/***************************************************************************** +# # +# KVMD - The main PiKVM daemon. # +# # +# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> # +# # +# 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 <USBComposite.h> + +namespace DRIVERS { + + class HidWrapper { + public: + HidWrapper(USBCompositeSerial* _serial = nullptr) : _serial(_serial) {} + + void begin() { + if(_init) + return; + _init = true; + + _report_descriptor_length = 0; + for(uint8 i = 0; i<_count; ++i) { + _report_descriptor_length += _descriptors_size[i]; + } + + _report_descriptor = new uint8[_report_descriptor_length]; + + uint16_t index = 0; + for(uint8 i = 0; i<_count; ++i) { + memcpy(_report_descriptor + index, _report_descriptors[i], _descriptors_size[i]); + index += _descriptors_size[i]; + } + + if(_serial) { + usbHid.begin(*_serial, _report_descriptor, _report_descriptor_length); + } else { + usbHid.begin(_report_descriptor, _report_descriptor_length); + } + } + + void addReportDescriptor(const uint8_t* report_descriptor, uint16_t report_descriptor_length) { + _report_descriptors[_count] = report_descriptor; + _descriptors_size[_count] = report_descriptor_length; + ++_count; + } + + USBCompositeSerial* serial() { + return _serial; + } + + USBHID usbHid; + + private: + USBCompositeSerial* _serial; + bool _init = false; + + static constexpr uint8_t MAX_USB_DESCRIPTORS = 2; + const uint8_t* _report_descriptors[MAX_USB_DESCRIPTORS]; + uint8_t _descriptors_size[MAX_USB_DESCRIPTORS]; + + uint8_t _count = 0; + uint8_t* _report_descriptor; + uint16_t _report_descriptor_length; + }; +} diff --git a/hid/lib/drivers-stm32/usb/keyboard-stm32.h b/hid/lib/drivers-stm32/usb/keyboard-stm32.h new file mode 100644 index 00000000..b788be19 --- /dev/null +++ b/hid/lib/drivers-stm32/usb/keyboard-stm32.h @@ -0,0 +1,86 @@ +/***************************************************************************** +# # +# KVMD - The main PiKVM daemon. # +# # +# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> # +# # +# 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 "keyboard.h" +#include "hid-wrapper-stm32.h" +#include <USBComposite.h> +#include "keymap.h" +#include "tools.h" + +namespace DRIVERS { + + const uint8_t reportDescriptionKeyboard[] = { + HID_KEYBOARD_REPORT_DESCRIPTOR(), + }; + + class UsbKeyboard : public Keyboard { + public: + UsbKeyboard(HidWrapper& _hidWrapper) : Keyboard(USB_KEYBOARD), + _hidWrapper(_hidWrapper), _keyboard(_hidWrapper.usbHid) { + _hidWrapper.addReportDescriptor(reportDescriptionKeyboard, sizeof(reportDescriptionKeyboard)); + } + + void begin() override { + _hidWrapper.begin(); + _keyboard.begin(); + } + + void clear() override { + _keyboard.releaseAll(); + } + + void sendKey(uint8_t code, bool state) override { + uint16_t usb_code = keymapUsb(code); + if (usb_code == KEY_ERROR_UNDEFINED) { + return; + } + + if(usb_code >= KEY_LEFT_CTRL && usb_code <= KEY_RIGHT_WINDOWS) { + usb_code = usb_code - KEY_LEFT_CTRL + 0x80; + } else { + usb_code += KEY_HID_OFFSET; + } + + state ? _keyboard.press(usb_code) : _keyboard.release(usb_code); + } + + bool isOffline() override { + return USBComposite == false; + } + + KeyboardLedsState getLeds() override { + uint8 leds = _keyboard.getLEDs(); + KeyboardLedsState result = { + .caps = leds & 0b00000010, + .scroll = leds & 0b00000100, + .num = leds & 0b00000001, + }; + return result; + } + + private: + HidWrapper& _hidWrapper; + HIDKeyboard _keyboard; + static constexpr uint8 KEY_ERROR_UNDEFINED = 3; + }; +} diff --git a/hid/lib/drivers-stm32/usb/keycode.h b/hid/lib/drivers-stm32/usb/keycode.h new file mode 100644 index 00000000..865ac096 --- /dev/null +++ b/hid/lib/drivers-stm32/usb/keycode.h @@ -0,0 +1,526 @@ +/***************************************************************************** +# # +# KVMD - The main PiKVM daemon. # +# # +# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> # +# # +# 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, +}; diff --git a/hid/lib/drivers-stm32/usb/keymap.h b/hid/lib/drivers-stm32/usb/keymap.h new file mode 100644 index 00000000..9f5015b3 --- /dev/null +++ b/hid/lib/drivers-stm32/usb/keymap.h @@ -0,0 +1,139 @@ +/***************************************************************************** +# # +# KVMD - The main PiKVM daemon. # +# # +# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> # +# # +# 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 "keycode.h" + + +KeyboardKeycode keymapUsb(uint8_t code) { + switch (code) { + case 1: return KEY_A; + case 2: return KEY_B; + case 3: return KEY_C; + case 4: return KEY_D; + case 5: return KEY_E; + case 6: return KEY_F; + case 7: return KEY_G; + case 8: return KEY_H; + case 9: return KEY_I; + case 10: return KEY_J; + case 11: return KEY_K; + case 12: return KEY_L; + case 13: return KEY_M; + case 14: return KEY_N; + case 15: return KEY_O; + case 16: return KEY_P; + case 17: return KEY_Q; + case 18: return KEY_R; + case 19: return KEY_S; + case 20: return KEY_T; + case 21: return KEY_U; + case 22: return KEY_V; + case 23: return KEY_W; + case 24: return KEY_X; + case 25: return KEY_Y; + case 26: return KEY_Z; + case 27: return KEY_1; + case 28: return KEY_2; + case 29: return KEY_3; + case 30: return KEY_4; + case 31: return KEY_5; + case 32: return KEY_6; + case 33: return KEY_7; + case 34: return KEY_8; + case 35: return KEY_9; + case 36: return KEY_0; + case 37: return KEY_ENTER; + case 38: return KEY_ESC; + case 39: return KEY_BACKSPACE; + case 40: return KEY_TAB; + case 41: return KEY_SPACE; + case 42: return KEY_MINUS; + case 43: return KEY_EQUAL; + case 44: return KEY_LEFT_BRACE; + case 45: return KEY_RIGHT_BRACE; + case 46: return KEY_BACKSLASH; + case 47: return KEY_SEMICOLON; + case 48: return KEY_QUOTE; + case 49: return KEY_TILDE; + case 50: return KEY_COMMA; + case 51: return KEY_PERIOD; + case 52: return KEY_SLASH; + case 53: return KEY_CAPS_LOCK; + case 54: return KEY_F1; + case 55: return KEY_F2; + case 56: return KEY_F3; + case 57: return KEY_F4; + case 58: return KEY_F5; + case 59: return KEY_F6; + case 60: return KEY_F7; + case 61: return KEY_F8; + case 62: return KEY_F9; + case 63: return KEY_F10; + case 64: return KEY_F11; + case 65: return KEY_F12; + case 66: return KEY_PRINT; + case 67: return KEY_INSERT; + case 68: return KEY_HOME; + case 69: return KEY_PAGE_UP; + case 70: return KEY_DELETE; + case 71: return KEY_END; + case 72: return KEY_PAGE_DOWN; + case 73: return KEY_RIGHT_ARROW; + case 74: return KEY_LEFT_ARROW; + case 75: return KEY_DOWN_ARROW; + case 76: return KEY_UP_ARROW; + case 77: return KEY_LEFT_CTRL; + case 78: return KEY_LEFT_SHIFT; + case 79: return KEY_LEFT_ALT; + case 80: return KEY_LEFT_GUI; + case 81: return KEY_RIGHT_CTRL; + case 82: return KEY_RIGHT_SHIFT; + case 83: return KEY_RIGHT_ALT; + case 84: return KEY_RIGHT_GUI; + case 85: return KEY_PAUSE; + case 86: return KEY_SCROLL_LOCK; + case 87: return KEY_NUM_LOCK; + case 88: return KEY_MENU; + case 89: return KEYPAD_DIVIDE; + case 90: return KEYPAD_MULTIPLY; + case 91: return KEYPAD_SUBTRACT; + case 92: return KEYPAD_ADD; + case 93: return KEYPAD_ENTER; + case 94: return KEYPAD_1; + case 95: return KEYPAD_2; + case 96: return KEYPAD_3; + case 97: return KEYPAD_4; + case 98: return KEYPAD_5; + case 99: return KEYPAD_6; + case 100: return KEYPAD_7; + case 101: return KEYPAD_8; + case 102: return KEYPAD_9; + case 103: return KEYPAD_0; + case 104: return KEYPAD_DOT; + case 105: return KEY_POWER; + case 106: return KEY_NON_US; + case 107: return KEY_INTERNATIONAL3; + default: return KEY_ERROR_UNDEFINED; + } +} diff --git a/hid/lib/drivers-stm32/usb/keymap.h.mako b/hid/lib/drivers-stm32/usb/keymap.h.mako new file mode 100644 index 00000000..82fd9b08 --- /dev/null +++ b/hid/lib/drivers-stm32/usb/keymap.h.mako @@ -0,0 +1,35 @@ +/***************************************************************************** +# # +# KVMD - The main PiKVM daemon. # +# # +# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> # +# # +# 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 "keycode.h" + +<%! import operator %> +KeyboardKeycode keymapUsb(uint8_t code) { + switch (code) { +% for km in sorted(keymap, key=operator.attrgetter("mcu_code")): + case ${km.mcu_code}: return ${km.arduino_name}; +% endfor + default: return KEY_ERROR_UNDEFINED; + } +} diff --git a/hid/lib/drivers-stm32/usb/mouse-absolute-stm32.h b/hid/lib/drivers-stm32/usb/mouse-absolute-stm32.h new file mode 100644 index 00000000..7188921d --- /dev/null +++ b/hid/lib/drivers-stm32/usb/mouse-absolute-stm32.h @@ -0,0 +1,76 @@ +/***************************************************************************** +# # +# KVMD - The main PiKVM daemon. # +# # +# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> # +# # +# 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 "mouse.h" +#include "hid-wrapper-stm32.h" +#include <USBComposite.h> + +namespace DRIVERS { + + const uint8_t reportDescriptionMouseAbsolute[] = { + HID_ABS_MOUSE_REPORT_DESCRIPTOR() + }; + + class UsbMouseAbsolute : public Mouse { + public: + UsbMouseAbsolute(HidWrapper& _hidWrapper) : Mouse(USB_MOUSE_ABSOLUTE), + _hidWrapper(_hidWrapper), _mouse(_hidWrapper.usbHid) { + _hidWrapper.addReportDescriptor(reportDescriptionMouseAbsolute, sizeof(reportDescriptionMouseAbsolute)); + } + + void begin() override { + _hidWrapper.begin(); + } + + void clear() override { + _mouse.release(0xff); + } + + void sendButtons ( + bool left_select, bool left_state, + bool right_select, bool right_state, + bool middle_select, bool middle_state, + bool up_select, bool up_state, + 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); + if(middle_select) middle_state ? _mouse.press(MOUSE_MIDDLE) : _mouse.release(MOUSE_MIDDLE); + } + + void sendMove(int x, int y) override { + _mouse.move(x, y); + } + + void sendWheel(int delta_y) override { + _mouse.move(0, 0, delta_y); + } + + bool isOffline() override { + return USBComposite == false; + } + + private: + HidWrapper& _hidWrapper; + HIDAbsMouse _mouse; + }; +} diff --git a/hid/lib/drivers-stm32/usb/mouse-relative-stm32.h b/hid/lib/drivers-stm32/usb/mouse-relative-stm32.h new file mode 100644 index 00000000..76e3e974 --- /dev/null +++ b/hid/lib/drivers-stm32/usb/mouse-relative-stm32.h @@ -0,0 +1,76 @@ +/***************************************************************************** +# # +# KVMD - The main PiKVM daemon. # +# # +# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> # +# # +# 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 "mouse.h" +#include "hid-wrapper-stm32.h" +#include <USBComposite.h> + +namespace DRIVERS { + + const uint8_t reportDescriptionMouseRelative[] = { + HID_MOUSE_REPORT_DESCRIPTOR() + }; + + class UsbMouseRelative : public Mouse { + public: + UsbMouseRelative(HidWrapper& _hidWrapper) : Mouse(USB_MOUSE_RELATIVE), + _hidWrapper(_hidWrapper), _mouse(_hidWrapper.usbHid) { + _hidWrapper.addReportDescriptor(reportDescriptionMouseRelative, sizeof(reportDescriptionMouseRelative)); + } + + void begin() override { + _hidWrapper.begin(); + } + + void clear() override { + _mouse.release(0xff); + } + + void sendButtons ( + bool left_select, bool left_state, + bool right_select, bool right_state, + bool middle_select, bool middle_state, + bool up_select, bool up_state, + 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); + if(middle_select) middle_state ? _mouse.press(MOUSE_MIDDLE) : _mouse.release(MOUSE_MIDDLE); + } + + void sendRelative(int x, int y) override { + _mouse.move(x, y); + } + + void sendWheel(int delta_y) override { + _mouse.move(0, 0, delta_y); + } + + bool isOffline() override { + return USBComposite == false; + } + + private: + HidWrapper& _hidWrapper; + HIDMouse _mouse; + }; +} diff --git a/hid/lib/drivers/mouse.h b/hid/lib/drivers/mouse.h index 446fabfe..e0f4b151 100644 --- a/hid/lib/drivers/mouse.h +++ b/hid/lib/drivers/mouse.h @@ -31,6 +31,10 @@ namespace DRIVERS { struct Mouse : public Driver { using Driver::Driver; virtual void begin() {} + + /** + * Release all keys + */ virtual void clear() {} virtual void sendButtons( bool left_select, bool left_state, @@ -42,5 +46,6 @@ namespace DRIVERS { virtual void sendRelative(int x, int y) {} virtual void sendWheel(int delta_y) {} virtual bool isOffline() { return false; } + virtual void periodic() {} }; } diff --git a/hid/patch.py b/hid/patch.py index 3bc73de0..c7674759 100644 --- a/hid/patch.py +++ b/hid/patch.py @@ -34,11 +34,16 @@ def _patch(path: str, patch_path: str) -> None: # ===== -_patch(_get_pkg_path("framework-arduino-avr"), "patches/arduino-main-no-usb.patch") -_patch(_get_pkg_path("framework-arduino-avr"), "patches/arduino-optional-cdc.patch") -_patch(_get_pkg_path("framework-arduino-avr"), "patches/arduino-get-plugged-endpoint.patch") - -_libs = _get_libs() -_patch(_libs["HID-Project"], "patches/hid-shut-up.patch") -_patch(_libs["HID-Project"], "patches/hid-no-singletones.patch") -_patch(_libs["HID-Project"], "patches/hid-win98.patch") +if env.GetProjectOption("platform") == "ststm32": + _patch(_get_pkg_path("framework-arduinoststm32-maple"), "patches/platformio-stm32f1-no-serial-usb.patch") +elif env.GetProjectOption("platform") == "atmelavr": + _patch(_get_pkg_path("framework-arduino-avr"), "patches/arduino-main-no-usb.patch") + _patch(_get_pkg_path("framework-arduino-avr"), "patches/arduino-optional-cdc.patch") + _patch(_get_pkg_path("framework-arduino-avr"), "patches/arduino-get-plugged-endpoint.patch") + + _libs = _get_libs() + _patch(_libs["HID-Project"], "patches/hid-shut-up.patch") + _patch(_libs["HID-Project"], "patches/hid-no-singletones.patch") + _patch(_libs["HID-Project"], "patches/hid-win98.patch") +else: + assert(False) diff --git a/hid/patches/platformio-stm32f1-no-serial-usb.patch b/hid/patches/platformio-stm32f1-no-serial-usb.patch new file mode 100644 index 00000000..547db168 --- /dev/null +++ b/hid/patches/platformio-stm32f1-no-serial-usb.patch @@ -0,0 +1,11 @@ +--- aaa/tools/platformio-build-stm32f1.py 2022-07-16 18:54:42.536695468 +0200
++++ bbb/tools/platformio-build-stm32f1.py 2022-07-16 19:03:10.988056751 +0200
+@@ -121,7 +121,7 @@
+ env.Append(
+ CPPDEFINES=[
+ ("CONFIG_MAPLE_MINI_NO_DISABLE_DEBUG", 1),
+- "SERIAL_USB"
++ # "SERIAL_USB"
+ ])
+
+ is_generic = board.startswith("generic") or board == "hytiny_stm32f103t"
diff --git a/hid/platformio-stm32.ini b/hid/platformio-stm32.ini new file mode 100644 index 00000000..94fd44d4 --- /dev/null +++ b/hid/platformio-stm32.ini @@ -0,0 +1,52 @@ +# http://docs.platformio.org/page/projectconf.html +[platformio] +core_dir = ./.platformio/ + +[env] +framework = arduino +platform = ststm32 +board = genericSTM32F103C8 +board_build.core = maple +extra_scripts = + post:patch.py + +[_common] +lib_deps = + git+https://github.com/ZulNs/STM32F1_RTC#v1.1.0 + git+https://github.com/arpruss/USBComposite_stm32f1#3c58f97eb006ee9cd1fb4fd55ac4faeeaead0974 + drivers-stm32 +build_flags = +# ----- The default config with dynamic switching ----- + -DHID_DYNAMIC + -DHID_WITH_USB + -DHID_SET_USB_KBD + -DHID_SET_USB_MOUSE_ABS + +[_serial] +extends = + _common +build_flags = + ${_common.build_flags} + -DCMD_SERIAL=Serial1 + -DCMD_SERIAL_SPEED=115200 + -DCMD_SERIAL_TIMEOUT=100000 +# ===== Serial ===== +[env:serial] +extends = + _serial +upload_flags = -c set CPUTAPID 0x2ba01477 +debug_tool= stlink +debug_build_flags = -Og -ggdb3 -g3 +debug_server = + .platformio/packages/tool-openocd/bin/openocd + -s .platformio/packages/tool-openocd/scripts + -f interface/stlink.cfg + -c "transport select hla_swd" + -c "set CPUTAPID 0x2ba01477" + -f target/stm32f1x.cfg + -c "reset_config none" +; build_type = debug +[env:patch] +; platformio-stm32f1-no-serial-usb.patch requires to running build again +; fake target was added to avoid error during first build +src_filter = -<src/> diff --git a/hid/src/main.cpp b/hid/src/main.cpp index 7a7b83db..5e01c6ed 100644 --- a/hid/src/main.cpp +++ b/hid/src/main.cpp @@ -229,6 +229,7 @@ void loop() { # endif _out.kbd->periodic(); + _out.mouse->periodic(); # ifdef CMD_SERIAL static unsigned long last = micros(); |