From 04fba96786ad11cffba03dbf639ed6981fcc8733 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Mon, 28 Mar 2022 17:51:33 -0500 Subject: [PATCH] Format imported KeyboardioHID code with clang-format Signed-off-by: Michael Richters --- src/kaleidoscope/device/virtual/Virtual.cpp | 5 - .../usb/BootKeyboard/BootKeyboard.cpp | 28 ++-- .../usb/BootKeyboard/BootKeyboard.h | 6 +- .../hid/keyboardio/usb/DescriptorPrimitives.h | 131 +++++++++--------- .../usb/DeviceAPIs/AbsoluteMouseAPI.h | 2 +- .../driver/hid/keyboardio/usb/HID-Settings.h | 9 +- .../driver/hid/keyboardio/usb/HIDAliases.h | 6 +- .../hid/keyboardio/usb/HIDReportObserver.h | 10 +- .../driver/hid/keyboardio/usb/HID_.cpp | 35 ++--- .../driver/hid/keyboardio/usb/HID_.h | 72 +++++----- .../driver/hid/keyboardio/usb/MouseButtons.h | 10 +- .../usb/MultiReport/AbsoluteMouse.cpp | 2 +- .../usb/MultiReport/AbsoluteMouse.h | 2 +- .../keyboardio/usb/MultiReport/Gamepad.cpp | 2 +- .../hid/keyboardio/usb/MultiReport/Gamepad.h | 35 ++--- .../keyboardio/usb/MultiReport/Keyboard.cpp | 3 +- .../hid/keyboardio/usb/MultiReport/Keyboard.h | 4 +- .../hid/keyboardio/usb/MultiReport/Mouse.cpp | 4 +- .../hid/keyboardio/usb/MultiReport/Mouse.h | 6 +- .../usb/MultiReport/SystemControl.cpp | 2 +- .../usb/MultiReport/SystemControl.h | 3 +- .../usb/SingleReport/SingleAbsoluteMouse.cpp | 19 ++- .../usb/SingleReport/SingleAbsoluteMouse.h | 8 +- .../driver/hid/keyboardio/usb/arch/samd.cpp | 4 +- 24 files changed, 200 insertions(+), 208 deletions(-) diff --git a/src/kaleidoscope/device/virtual/Virtual.cpp b/src/kaleidoscope/device/virtual/Virtual.cpp index 62d6b186..6b4fa8fc 100644 --- a/src/kaleidoscope/device/virtual/Virtual.cpp +++ b/src/kaleidoscope/device/virtual/Virtual.cpp @@ -19,18 +19,13 @@ #include "kaleidoscope/device/virtual/Virtual.h" -// From Arduino: #include // for EEPROMClass, EERef -// From KeyboardioHID: -#include // for HIDReportObserver -// From system: #include // for uint8_t, uint16_t #include // for exit, size_t #include // for getLineOfInput, isInte... #include // for operator<<, string #include // for operator==, char_traits -// From Kaleidoscope: #include "kaleidoscope/KeyAddr.h" // for MatrixAddr, MatrixAddr... #include "kaleidoscope/device/virtual/DefaultHIDReportConsumer.h" // for DefaultHIDReportConsumer #include "kaleidoscope/device/virtual/Logging.h" // for log_error, logging diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/BootKeyboard/BootKeyboard.cpp b/src/kaleidoscope/driver/hid/keyboardio/usb/BootKeyboard/BootKeyboard.cpp index efeeefcf..29618258 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/BootKeyboard/BootKeyboard.cpp +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/BootKeyboard/BootKeyboard.cpp @@ -82,26 +82,26 @@ static const uint8_t BOOT_KEYBOARD_EP_SIZE = USB_EP_SIZE; #endif -BootKeyboard_::BootKeyboard_(uint8_t protocol_) : PluggableUSBModule(1, 1, epType), default_protocol(protocol_), protocol(protocol_), idle(1), leds(0) { +BootKeyboard_::BootKeyboard_(uint8_t protocol_) + : PluggableUSBModule(1, 1, epType), default_protocol(protocol_), protocol(protocol_), idle(1), leds(0) { #ifdef ARCH_HAS_CONFIGURABLE_EP_SIZES - epType[0] = EP_TYPE_INTERRUPT_IN(BOOT_KEYBOARD_EP_SIZE); // This is an 8 byte report, so ask for an 8 byte buffer, so reports aren't split + epType[0] = EP_TYPE_INTERRUPT_IN(BOOT_KEYBOARD_EP_SIZE); // This is an 8 byte report, so ask for an 8 byte buffer, so reports aren't split #else epType[0] = EP_TYPE_INTERRUPT_IN; #endif PluggableUSB().plug(this); } -int BootKeyboard_::getInterface(uint8_t* interfaceCount) { - *interfaceCount += 1; // uses 1 +int BootKeyboard_::getInterface(uint8_t *interfaceCount) { + *interfaceCount += 1; // uses 1 HIDDescriptor hidInterface = { D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_BOOT_INTERFACE, HID_PROTOCOL_KEYBOARD), D_HIDREPORT(sizeof(boot_keyboard_hid_descriptor_)), - D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, BOOT_KEYBOARD_EP_SIZE, 0x01) - }; + D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, BOOT_KEYBOARD_EP_SIZE, 0x01)}; return USB_SendControl(0, &hidInterface, sizeof(hidInterface)); } -int BootKeyboard_::getDescriptor(USBSetup& setup) { +int BootKeyboard_::getDescriptor(USBSetup &setup) { // Check if this is a HID Class Descriptor request if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0; @@ -138,13 +138,12 @@ void BootKeyboard_::end() { } - -bool BootKeyboard_::setup(USBSetup& setup) { +bool BootKeyboard_::setup(USBSetup &setup) { if (pluggedInterface != setup.wIndex) { return false; } - uint8_t request = setup.bRequest; + uint8_t request = setup.bRequest; uint8_t requestType = setup.bmRequestType; if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) { @@ -267,10 +266,10 @@ size_t BootKeyboard_::press(uint8_t k) { // Add k to the key report only if it's not already present // and if there is an empty slot. for (uint8_t i = 0; i < sizeof(report_.keycodes); i++) { - if (report_.keycodes[i] != k) { // is k already in list? - if (0 == report_.keycodes[i]) { // have we found an empty slot? + if (report_.keycodes[i] != k) { // is k already in list? + if (0 == report_.keycodes[i]) { // have we found an empty slot? report_.keycodes[i] = k; - done = 1; + done = 1; break; } } else { @@ -316,7 +315,7 @@ size_t BootKeyboard_::release(uint8_t k) { while (current < sizeof(report_.keycodes)) { if (report_.keycodes[current]) { - uint8_t tmp = report_.keycodes[nextpos]; + uint8_t tmp = report_.keycodes[nextpos]; report_.keycodes[nextpos] = report_.keycodes[current]; report_.keycodes[current] = tmp; ++nextpos; @@ -359,7 +358,6 @@ bool BootKeyboard_::wasKeyPressed(uint8_t k) { } - /* Returns true if the modifer key passed in will be sent during this key report * Returns false in all other cases * */ diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/BootKeyboard/BootKeyboard.h b/src/kaleidoscope/driver/hid/keyboardio/usb/BootKeyboard/BootKeyboard.h index c7fddb7d..b139cdde 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/BootKeyboard/BootKeyboard.h +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/BootKeyboard/BootKeyboard.h @@ -71,9 +71,9 @@ class BootKeyboard_ : public PluggableUSBModule { HID_BootKeyboardReport_Data_t report_, last_report_; // Implementation of the PUSBListNode - int getInterface(uint8_t* interfaceCount); - int getDescriptor(USBSetup& setup); - bool setup(USBSetup& setup); + int getInterface(uint8_t *interfaceCount); + int getDescriptor(USBSetup &setup); + bool setup(USBSetup &setup); EPTYPE_DESCRIPTOR_SIZE epType[1]; uint8_t protocol; diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/DescriptorPrimitives.h b/src/kaleidoscope/driver/hid/keyboardio/usb/DescriptorPrimitives.h index 857dd84b..b018384d 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/DescriptorPrimitives.h +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/DescriptorPrimitives.h @@ -25,121 +25,120 @@ THE SOFTWARE. #pragma once -#define D_MULTIBYTE(n) (n + 0x01) +#define D_MULTIBYTE(n) (n + 0x01) -#define D_USAGE_PAGE 0x05 -#define D_USAGE 0x09 +#define D_USAGE_PAGE 0x05 +#define D_USAGE 0x09 -#define D_REPORT_ID 0x85 +#define D_REPORT_ID 0x85 -#define D_USAGE_MINIMUM 0x19 -#define D_USAGE_MAXIMUM 0x29 +#define D_USAGE_MINIMUM 0x19 +#define D_USAGE_MAXIMUM 0x29 -#define D_LOGICAL_MINIMUM 0x15 -#define D_LOGICAL_MAXIMUM 0x25 +#define D_LOGICAL_MINIMUM 0x15 +#define D_LOGICAL_MAXIMUM 0x25 #define D_PHYSICAL_MINIMUM 0x35 #define D_PHYSICAL_MAXIMUM 0x45 -#define D_REPORT_SIZE 0x75 -#define D_REPORT_COUNT 0x95 +#define D_REPORT_SIZE 0x75 +#define D_REPORT_COUNT 0x95 -#define D_PUSH 0xa4 -#define D_POP 0xb4 +#define D_PUSH 0xa4 +#define D_POP 0xb4 // USB HID DCD 1.11 section 6.2.2.4 - Main items // // each of these are the type description + 0x01 for a single byte item -#define D_INPUT 0x81 -#define D_OUTPUT 0x91 -#define D_FEATURE 0xb1 -#define D_COLLECTION 0xa1 +#define D_INPUT 0x81 +#define D_OUTPUT 0x91 +#define D_FEATURE 0xb1 +#define D_COLLECTION 0xa1 #define D_END_COLLECTION 0xc0 // The bits that make up inputs, outputs and features // Bit 0 -#define D_DATA 0b00000000 -#define D_CONSTANT 0b00000001 +#define D_DATA 0b00000000 +#define D_CONSTANT 0b00000001 // Bit 1 -#define D_ARRAY 0b00000000 -#define D_VARIABLE 0b00000010 +#define D_ARRAY 0b00000000 +#define D_VARIABLE 0b00000010 // Bit 2 -#define D_ABSOLUTE 0b00000000 -#define D_RELATIVE 0b00000100 +#define D_ABSOLUTE 0b00000000 +#define D_RELATIVE 0b00000100 // Bit 3 -#define D_NO_WRAP 0b00000000 -#define D_WRAP 0b00001000 +#define D_NO_WRAP 0b00000000 +#define D_WRAP 0b00001000 // Bit 4 -#define D_LINEAR 0b00000000 -#define D_NON_LINEAR 0b00010000 +#define D_LINEAR 0b00000000 +#define D_NON_LINEAR 0b00010000 // Bit 5 -#define D_PREFERRED_STATE 0b00000000 -#define D_NO_PREFERRED 0b00100000 +#define D_PREFERRED_STATE 0b00000000 +#define D_NO_PREFERRED 0b00100000 // Bit 6 -#define D_NO_NULL_POSITION 0b00000000 -#define D_NULL_STATE 0b01000000 +#define D_NO_NULL_POSITION 0b00000000 +#define D_NULL_STATE 0b01000000 // Bit 7 -#define D_NON_VOLATILE 0b00000000 -#define D_VOLATILE 0b01000000 +#define D_NON_VOLATILE 0b00000000 +#define D_VOLATILE 0b01000000 // Bit 8 -#define D_BIT_FIELD 0b00000000 -#define D_BUFFERED_BYTES 0b10000000 - +#define D_BIT_FIELD 0b00000000 +#define D_BUFFERED_BYTES 0b10000000 // Collection types -#define D_PHYSICAL 0x00 // (group of axes) -#define D_APPLICATION 0x01 // (mouse, keyboard) -#define D_LOGICAL 0x02 // (interrelated data) -#define D_REPORT 0x03 -#define D_NAMED_ARRAY 0x04 -#define D_USAGE_SWITCH 0x05 -#define D_USAGE_MODIFIER 0x06 +#define D_PHYSICAL 0x00 // (group of axes) +#define D_APPLICATION 0x01 // (mouse, keyboard) +#define D_LOGICAL 0x02 // (interrelated data) +#define D_REPORT 0x03 +#define D_NAMED_ARRAY 0x04 +#define D_USAGE_SWITCH 0x05 +#define D_USAGE_MODIFIER 0x06 // 0x07-0x7f - Reserved // 0x80-0xff - Vendor define #define D_PAGE_GENERIC_DESKTOP 0x01 -#define D_PAGE_SIMULATION 0x02 -#define D_PAGE_VR 0x03 -#define D_PAGE_SPORT 0x04 -#define D_PAGE_GAME 0x05 -#define D_PAGE_GENERIC_DEVICE 0x06 -#define D_PAGE_KEYBOARD 0x07 -#define D_PAGE_LEDS 0x08 -#define D_PAGE_BUTTON 0x09 -#define D_PAGE_ORDINAL 0x0A -#define D_PAGE_TELEPHONY 0x0B -#define D_PAGE_CONSUMER 0x0C -#define D_PAGE_DIGITIZER 0x0D -#define D_PAGE_RESERVED 0x0E -#define D_PAGE_PID 0x0F -#define D_PAGE_UNICODE 0x10 +#define D_PAGE_SIMULATION 0x02 +#define D_PAGE_VR 0x03 +#define D_PAGE_SPORT 0x04 +#define D_PAGE_GAME 0x05 +#define D_PAGE_GENERIC_DEVICE 0x06 +#define D_PAGE_KEYBOARD 0x07 +#define D_PAGE_LEDS 0x08 +#define D_PAGE_BUTTON 0x09 +#define D_PAGE_ORDINAL 0x0A +#define D_PAGE_TELEPHONY 0x0B +#define D_PAGE_CONSUMER 0x0C +#define D_PAGE_DIGITIZER 0x0D +#define D_PAGE_RESERVED 0x0E +#define D_PAGE_PID 0x0F +#define D_PAGE_UNICODE 0x10 // 0x11-13 RESERVED #define D_PAGE_ALPHANUMERIC_DISPLAY 0x14 -#define D_PAGE_MEDICAL_INSTRUMENTS 0x40 +#define D_PAGE_MEDICAL_INSTRUMENTS 0x40 // 0x80-83 MONITOR // 0x84-87 POWER #define D_PAGE_BAR_CODE_SCANNER 0x8C -#define D_PAGE_SCALE 0x8D -#define D_PAGE_MSR 0x8E +#define D_PAGE_SCALE 0x8D +#define D_PAGE_MSR 0x8E // 0x8F RESERVED POINT OF SALE #define D_PAGE_CAMERA_CONTROL 0x90 -#define D_PAGE_ARCADE 0x91 +#define D_PAGE_ARCADE 0x91 // Generic Desktop Usages HUT Section 4 p27 #define D_USAGE_POINTER 0x01 -#define D_USAGE_MOUSE 0x02 +#define D_USAGE_MOUSE 0x02 // 0x03 is reserved -#define D_USAGE_JOYSTICK 0x04 -#define D_USAGE_GAMEPAD 0x05 -#define D_USAGE_KEYBOARD 0x06 -#define D_USAGE_KEYPAD 0x07 +#define D_USAGE_JOYSTICK 0x04 +#define D_USAGE_GAMEPAD 0x05 +#define D_USAGE_KEYBOARD 0x06 +#define D_USAGE_KEYPAD 0x07 #define D_USAGE_MULITAXIS 0x08 diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/DeviceAPIs/AbsoluteMouseAPI.h b/src/kaleidoscope/driver/hid/keyboardio/usb/DeviceAPIs/AbsoluteMouseAPI.h index 0bce2256..ab978735 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/DeviceAPIs/AbsoluteMouseAPI.h +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/DeviceAPIs/AbsoluteMouseAPI.h @@ -93,7 +93,7 @@ class AbsoluteMouseAPI { inline bool isPressed(uint8_t b = MOUSE_LEFT); // Sending is public in the base class for advanced users. - virtual void sendReport(void* data, int length) {} + virtual void sendReport(void *data, int length) {} protected: uint16_t x_axis_; diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/HID-Settings.h b/src/kaleidoscope/driver/hid/keyboardio/usb/HID-Settings.h index 603e2660..3622397a 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/HID-Settings.h +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/HID-Settings.h @@ -122,11 +122,11 @@ void USB_PackMessages(bool pack); #define USB_Send USBDevice.send #define USB_Flush USBDevice.flush -int USB_SendControl(void* y, uint8_t z); -int USB_SendControl(uint8_t x, const void* y, uint8_t z); +int USB_SendControl(void *y, uint8_t z); +int USB_SendControl(uint8_t x, const void *y, uint8_t z); -#define TRANSFER_PGM 0 -#define TRANSFER_RELEASE 0 +#define TRANSFER_PGM 0 +#define TRANSFER_RELEASE 0 #elif defined(ARDUINO_ARCH_GD32) @@ -150,7 +150,6 @@ constexpr uint16_t EP_TYPE_INTERRUPT_OUT(uint8_t buffer_size) { } - #else #error "Unsupported architecture" diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/HIDAliases.h b/src/kaleidoscope/driver/hid/keyboardio/usb/HIDAliases.h index 99ee8388..52b08e69 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/HIDAliases.h +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/HIDAliases.h @@ -27,7 +27,7 @@ THE SOFTWARE. #include "kaleidoscope/HIDTables.h" -#define HID_FIRST_KEY HID_KEYBOARD_NO_EVENT -#define HID_LAST_KEY HID_KEYPAD_HEXADECIMAL +#define HID_FIRST_KEY HID_KEYBOARD_NO_EVENT +#define HID_LAST_KEY HID_KEYPAD_HEXADECIMAL #define HID_KEYBOARD_FIRST_MODIFIER HID_KEYBOARD_LEFT_CONTROL -#define HID_KEYBOARD_LAST_MODIFIER HID_KEYBOARD_RIGHT_GUI +#define HID_KEYBOARD_LAST_MODIFIER HID_KEYBOARD_RIGHT_GUI diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/HIDReportObserver.h b/src/kaleidoscope/driver/hid/keyboardio/usb/HIDReportObserver.h index 23de6991..60c62a8d 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/HIDReportObserver.h +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/HIDReportObserver.h @@ -28,12 +28,9 @@ THE SOFTWARE. class HIDReportObserver { public: + typedef void (*SendReportHook)(uint8_t id, const void *data, int len, int result); - typedef void(*SendReportHook)(uint8_t id, const void* data, - int len, int result); - - static void observeReport(uint8_t id, const void* data, - int len, int result) { + static void observeReport(uint8_t id, const void *data, int len, int result) { if (send_report_hook_) { (*send_report_hook_)(id, data, len, result); } @@ -45,11 +42,10 @@ class HIDReportObserver { static SendReportHook resetHook(SendReportHook new_hook) { auto previous_hook = send_report_hook_; - send_report_hook_ = new_hook; + send_report_hook_ = new_hook; return previous_hook; } private: - static SendReportHook send_report_hook_; }; diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/HID_.cpp b/src/kaleidoscope/driver/hid/keyboardio/usb/HID_.cpp index 71e9e938..93062799 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/HID_.cpp +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/HID_.cpp @@ -23,22 +23,21 @@ #if defined(USBCON) -HID_& HID() { +HID_ &HID() { static HID_ obj; return obj; } -int HID_::getInterface(uint8_t* interfaceCount) { - *interfaceCount += 1; // uses 1 +int HID_::getInterface(uint8_t *interfaceCount) { + *interfaceCount += 1; // uses 1 HIDDescriptor hidInterface = { D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE), D_HIDREPORT(descriptorSize), - D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) - }; + D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01)}; return USB_SendControl(0, &hidInterface, sizeof(hidInterface)); } -int HID_::getDescriptor(USBSetup& setup) { +int HID_::getDescriptor(USBSetup &setup) { // Check if this is a HID Class Descriptor request if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0; @@ -53,7 +52,7 @@ int HID_::getDescriptor(USBSetup& setup) { } int total = 0; - HIDSubDescriptor* node; + HIDSubDescriptor *node; USB_PackMessages(true); for (node = rootNode; node; node = node->next) { int res = USB_SendControl(TRANSFER_PGM, node->data, node->length); @@ -71,7 +70,8 @@ int HID_::getDescriptor(USBSetup& setup) { } __attribute__((weak)) -uint8_t HID_::getShortName(char *name) { +uint8_t +HID_::getShortName(char *name) { name[0] = 'k'; name[1] = 'b'; name[2] = 'i'; @@ -94,13 +94,13 @@ void HID_::AppendDescriptor(HIDSubDescriptor *node) { descriptorSize += node->length; } -int HID_::SendReport(uint8_t id, const void* data, int len) { +int HID_::SendReport(uint8_t id, const void *data, int len) { auto result = SendReport_(id, data, len); HIDReportObserver::observeReport(id, data, len, result); return result; } -int HID_::SendReport_(uint8_t id, const void* data, int len) { +int HID_::SendReport_(uint8_t id, const void *data, int len) { /* On SAMD, we need to send the whole report in one batch; sending the id, and * the report itself separately does not work, the report never arrives. Due * to this, we merge the two into a single buffer, and send that. @@ -122,12 +122,12 @@ int HID_::SendReport_(uint8_t id, const void* data, int len) { #endif } -bool HID_::setup(USBSetup& setup) { +bool HID_::setup(USBSetup &setup) { if (pluggedInterface != setup.wIndex) { return false; } - uint8_t request = setup.bRequest; + uint8_t request = setup.bRequest; uint8_t requestType = setup.bmRequestType; if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) { @@ -195,11 +195,14 @@ bool HID_::setup(USBSetup& setup) { return false; } -HID_::HID_() : PluggableUSBModule(1, 1, epType), - rootNode(NULL), descriptorSize(0), - protocol(HID_REPORT_PROTOCOL), idle(1) { +HID_::HID_() + : PluggableUSBModule(1, 1, epType), + rootNode(NULL), + descriptorSize(0), + protocol(HID_REPORT_PROTOCOL), + idle(1) { setReportData.reportId = 0; - setReportData.leds = 0; + setReportData.leds = 0; #ifdef ARCH_HAS_CONFIGURABLE_EP_SIZES epType[0] = EP_TYPE_INTERRUPT_IN(USB_EP_SIZE); diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/HID_.h b/src/kaleidoscope/driver/hid/keyboardio/usb/HID_.h index 48a87f7e..d687b7b8 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/HID_.h +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/HID_.h @@ -28,30 +28,30 @@ // HID 'Driver' // ------------ -#define HID_GET_REPORT 0x01 -#define HID_GET_IDLE 0x02 -#define HID_GET_PROTOCOL 0x03 -#define HID_SET_REPORT 0x09 -#define HID_SET_IDLE 0x0A -#define HID_SET_PROTOCOL 0x0B +#define HID_GET_REPORT 0x01 +#define HID_GET_IDLE 0x02 +#define HID_GET_PROTOCOL 0x03 +#define HID_SET_REPORT 0x09 +#define HID_SET_IDLE 0x0A +#define HID_SET_PROTOCOL 0x0B -#define HID_HID_DESCRIPTOR_TYPE 0x21 -#define HID_REPORT_DESCRIPTOR_TYPE 0x22 -#define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 +#define HID_HID_DESCRIPTOR_TYPE 0x21 +#define HID_REPORT_DESCRIPTOR_TYPE 0x22 +#define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 // HID subclass HID1.11 Page 8 4.2 Subclass -#define HID_SUBCLASS_NONE 0 +#define HID_SUBCLASS_NONE 0 #define HID_SUBCLASS_BOOT_INTERFACE 1 // HID Keyboard/Mouse bios compatible protocols HID1.11 Page 9 4.3 Protocols -#define HID_PROTOCOL_NONE 0 +#define HID_PROTOCOL_NONE 0 #define HID_PROTOCOL_KEYBOARD 1 -#define HID_PROTOCOL_MOUSE 2 +#define HID_PROTOCOL_MOUSE 2 // Normal or bios protocol (Keyboard/Mouse) HID1.11 Page 54 7.2.5 Get_Protocol Request // "protocol" variable is used for this purpose. -#define HID_BOOT_PROTOCOL 0 -#define HID_REPORT_PROTOCOL 1 +#define HID_BOOT_PROTOCOL 0 +#define HID_REPORT_PROTOCOL 1 // HID Request Type HID1.11 Page 51 7.2.1 Get_Report Request #define HID_REPORT_TYPE_INPUT 1 @@ -60,56 +60,57 @@ #pragma pack(push, 1) typedef struct { - uint8_t len; // 9 - uint8_t dtype; // 0x21 + uint8_t len; // 9 + uint8_t dtype; // 0x21 uint8_t addr; - uint8_t versionL; // 0x101 - uint8_t versionH; // 0x101 + uint8_t versionL; // 0x101 + uint8_t versionH; // 0x101 uint8_t country; - uint8_t desctype; // 0x22 report + uint8_t desctype; // 0x22 report uint8_t descLenL; uint8_t descLenH; } HIDDescDescriptor; typedef struct { InterfaceDescriptor hid; - HIDDescDescriptor desc; - EndpointDescriptor in; + HIDDescDescriptor desc; + EndpointDescriptor in; } HIDDescriptor; #pragma pack(pop) class HIDSubDescriptor { public: HIDSubDescriptor *next = NULL; - HIDSubDescriptor(const void *d, const uint16_t l) : data(d), length(l) { } + HIDSubDescriptor(const void *d, const uint16_t l) + : data(d), length(l) {} - const void* data; + const void *data; const uint16_t length; }; class HID_ : public PluggableUSBModule { public: - HID_(); int begin(); - int SendReport(uint8_t id, const void* data, int len); - void AppendDescriptor(HIDSubDescriptor* node); + int SendReport(uint8_t id, const void *data, int len); + void AppendDescriptor(HIDSubDescriptor *node); uint8_t getLEDs() { return setReportData.leds; } protected: // Implementation of the PluggableUSBModule - int getInterface(uint8_t* interfaceCount); - int getDescriptor(USBSetup& setup); - bool setup(USBSetup& setup); - uint8_t getShortName(char* name); + int getInterface(uint8_t *interfaceCount); + int getDescriptor(USBSetup &setup); + bool setup(USBSetup &setup); + uint8_t getShortName(char *name); + + int SendReport_(uint8_t id, const void *data, int len); - int SendReport_(uint8_t id, const void* data, int len); private: EPTYPE_DESCRIPTOR_SIZE epType[1]; - HIDSubDescriptor* rootNode; + HIDSubDescriptor *rootNode; uint16_t descriptorSize; uint8_t protocol; @@ -123,8 +124,9 @@ class HID_ : public PluggableUSBModule { // Replacement for global singleton. // This function prevents static-initialization-order-fiasco // https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use -HID_& HID(); +HID_ &HID(); -#define D_HIDREPORT(length) { 9, 0x21, 0x01, 0x01, 0, 1, 0x22, lowByte(length), highByte(length) } +#define D_HIDREPORT(length) \ + { 9, 0x21, 0x01, 0x01, 0, 1, 0x22, lowByte(length), highByte(length) } -#endif // USBCON +#endif // USBCON diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/MouseButtons.h b/src/kaleidoscope/driver/hid/keyboardio/usb/MouseButtons.h index ac94137a..fc0f2c0a 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/MouseButtons.h +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/MouseButtons.h @@ -25,11 +25,11 @@ THE SOFTWARE. #pragma once -#define MOUSE_LEFT (1 << 0) -#define MOUSE_RIGHT (1 << 1) -#define MOUSE_MIDDLE (1 << 2) -#define MOUSE_PREV (1 << 3) -#define MOUSE_NEXT (1 << 4) +#define MOUSE_LEFT (1 << 0) +#define MOUSE_RIGHT (1 << 1) +#define MOUSE_MIDDLE (1 << 2) +#define MOUSE_PREV (1 << 3) +#define MOUSE_NEXT (1 << 4) // actually this mouse report has 8 buttons (for smaller descriptor) // but the last 3 wont do anything from what I tested #define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE | MOUSE_PREV | MOUSE_NEXT) diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/AbsoluteMouse.cpp b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/AbsoluteMouse.cpp index 4c8b9f99..4b1aa8c0 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/AbsoluteMouse.cpp +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/AbsoluteMouse.cpp @@ -49,7 +49,7 @@ AbsoluteMouse_::AbsoluteMouse_() { } -void AbsoluteMouse_::sendReport(void* data, int length) { +void AbsoluteMouse_::sendReport(void *data, int length) { HID().SendReport(HID_REPORTID_MOUSE_ABSOLUTE, data, length); } diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/AbsoluteMouse.h b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/AbsoluteMouse.h index a1794046..1861e0ec 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/AbsoluteMouse.h +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/AbsoluteMouse.h @@ -37,7 +37,7 @@ class AbsoluteMouse_ : public AbsoluteMouseAPI { protected: // Sending is public in the base class for advanced users. - virtual void sendReport(void* data, int length); + virtual void sendReport(void *data, int length); }; extern AbsoluteMouse_ AbsoluteMouse; diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Gamepad.cpp b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Gamepad.cpp index 63d23a85..622b3ab3 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Gamepad.cpp +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Gamepad.cpp @@ -144,7 +144,7 @@ void Gamepad_::dPad2(int8_t d) { report_.dPad2 = d; } -void Gamepad_::sendReport(void* data, int length) { +void Gamepad_::sendReport(void *data, int length) { HID().SendReport(HID_REPORTID_GAMEPAD, data, length); } diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Gamepad.h b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Gamepad.h index ed06eac1..6330969a 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Gamepad.h +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Gamepad.h @@ -31,15 +31,15 @@ THE SOFTWARE. #include "kaleidoscope/driver/hid/keyboardio/usb/HID-Settings.h" // Dpad directions -#define GAMEPAD_DPAD_CENTERED 0 -#define GAMEPAD_DPAD_UP 1 -#define GAMEPAD_DPAD_UP_RIGHT 2 -#define GAMEPAD_DPAD_RIGHT 3 +#define GAMEPAD_DPAD_CENTERED 0 +#define GAMEPAD_DPAD_UP 1 +#define GAMEPAD_DPAD_UP_RIGHT 2 +#define GAMEPAD_DPAD_RIGHT 3 #define GAMEPAD_DPAD_DOWN_RIGHT 4 -#define GAMEPAD_DPAD_DOWN 5 -#define GAMEPAD_DPAD_DOWN_LEFT 6 -#define GAMEPAD_DPAD_LEFT 7 -#define GAMEPAD_DPAD_UP_LEFT 8 +#define GAMEPAD_DPAD_DOWN 5 +#define GAMEPAD_DPAD_DOWN_LEFT 6 +#define GAMEPAD_DPAD_LEFT 7 +#define GAMEPAD_DPAD_UP_LEFT 8 typedef union { @@ -83,17 +83,17 @@ typedef union { uint8_t button31 : 1; uint8_t button32 : 1; - int16_t xAxis; - int16_t yAxis; + int16_t xAxis; + int16_t yAxis; - int16_t rxAxis; - int16_t ryAxis; + int16_t rxAxis; + int16_t ryAxis; - int8_t zAxis; - int8_t rzAxis; + int8_t zAxis; + int8_t rzAxis; - uint8_t dPad1 : 4; - uint8_t dPad2 : 4; + uint8_t dPad1 : 4; + uint8_t dPad2 : 4; }; } HID_GamepadReport_Data_t; @@ -118,7 +118,8 @@ class Gamepad_ { void dPad1(int8_t d); void dPad2(int8_t d); - void sendReport(void* data, int length); + void sendReport(void *data, int length); + protected: HID_GamepadReport_Data_t report_; }; diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Keyboard.cpp b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Keyboard.cpp index 2e5bdb94..81ca54d4 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Keyboard.cpp +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Keyboard.cpp @@ -98,7 +98,8 @@ void Keyboard_::end() { int Keyboard_::sendReportUnchecked() { return HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, - &last_report_, sizeof(last_report_)); + &last_report_, + sizeof(last_report_)); } // Sending the current HID report to the host: diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Keyboard.h b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Keyboard.h index c85e7244..c040d922 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Keyboard.h +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Keyboard.h @@ -39,7 +39,7 @@ typedef union { // Modifiers + keymap struct { uint8_t modifiers; - uint8_t keys[KEY_BYTES ]; + uint8_t keys[KEY_BYTES]; }; uint8_t allkeys[1 + KEY_BYTES]; } HID_KeyboardReport_Data_t; @@ -53,7 +53,7 @@ class Keyboard_ { size_t press(uint8_t k); size_t release(uint8_t k); - void releaseAll(); + void releaseAll(); int sendReport(); bool isKeyPressed(uint8_t k); diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Mouse.cpp b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Mouse.cpp index 34e74952..bc9c46a1 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Mouse.cpp +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Mouse.cpp @@ -101,8 +101,8 @@ void Mouse_::click(uint8_t b) { } void Mouse_::move(int8_t x, int8_t y, int8_t v_wheel, int8_t h_wheel) { - report_.xAxis = x; - report_.yAxis = y; + report_.xAxis = x; + report_.yAxis = y; report_.vWheel = v_wheel; report_.hWheel = h_wheel; } diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Mouse.h b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Mouse.h index 14b009c1..e140a5cc 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Mouse.h +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/Mouse.h @@ -53,9 +53,9 @@ class Mouse_ { // but also calls `sendReport()` at least twice. void click(uint8_t b = MOUSE_LEFT); void move(int8_t x, int8_t y, int8_t v_wheel = 0, int8_t h_wheel = 0); - void press(uint8_t b = MOUSE_LEFT); // press LEFT by default - void release(uint8_t b = MOUSE_LEFT); // release LEFT by default - bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default + void press(uint8_t b = MOUSE_LEFT); // press LEFT by default + void release(uint8_t b = MOUSE_LEFT); // release LEFT by default + bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default /** getReport returns the current report. * diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/SystemControl.cpp b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/SystemControl.cpp index ee3b65a0..cffa1d17 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/SystemControl.cpp +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/SystemControl.cpp @@ -92,7 +92,7 @@ void SystemControl_::press(uint8_t s) { } -void SystemControl_::sendReport(void* data, int length) { +void SystemControl_::sendReport(void *data, int length) { HID().SendReport(HID_REPORTID_SYSTEMCONTROL, data, length); } diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/SystemControl.h b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/SystemControl.h index a03de4da..5464ea4b 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/SystemControl.h +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/MultiReport/SystemControl.h @@ -45,7 +45,7 @@ class SystemControl_ { void press(uint8_t s); void release(); void releaseAll(); - void sendReport(void* data, int length); + void sendReport(void *data, int length); SystemControl_(); @@ -53,5 +53,4 @@ class SystemControl_ { }; - extern SystemControl_ SystemControl; diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/SingleReport/SingleAbsoluteMouse.cpp b/src/kaleidoscope/driver/hid/keyboardio/usb/SingleReport/SingleAbsoluteMouse.cpp index 48eb89ff..82ecf003 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/SingleReport/SingleAbsoluteMouse.cpp +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/SingleReport/SingleAbsoluteMouse.cpp @@ -46,8 +46,8 @@ static const uint8_t SINGLE_ABSOLUTEMOUSE_EP_SIZE = USB_EP_SIZE; #endif - -SingleAbsoluteMouse_::SingleAbsoluteMouse_() : PluggableUSBModule(1, 1, epType), protocol(HID_REPORT_PROTOCOL), idle(1) { +SingleAbsoluteMouse_::SingleAbsoluteMouse_() + : PluggableUSBModule(1, 1, epType), protocol(HID_REPORT_PROTOCOL), idle(1) { #ifdef ARCH_HAS_CONFIGURABLE_EP_SIZES epType[0] = EP_TYPE_INTERRUPT_IN(SINGLE_ABSOLUTEMOUSE_EP_SIZE); @@ -58,17 +58,16 @@ SingleAbsoluteMouse_::SingleAbsoluteMouse_() : PluggableUSBModule(1, 1, epType), PluggableUSB().plug(this); } -int SingleAbsoluteMouse_::getInterface(uint8_t* interfaceCount) { - *interfaceCount += 1; // uses 1 +int SingleAbsoluteMouse_::getInterface(uint8_t *interfaceCount) { + *interfaceCount += 1; // uses 1 HIDDescriptor hidInterface = { D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE), D_HIDREPORT(sizeof(_hidSingleReportDescriptorAbsoluteMouse)), - D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, SINGLE_ABSOLUTEMOUSE_EP_SIZE, 0x01) - }; + D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, SINGLE_ABSOLUTEMOUSE_EP_SIZE, 0x01)}; return USB_SendControl(0, &hidInterface, sizeof(hidInterface)); } -int SingleAbsoluteMouse_::getDescriptor(USBSetup& setup) { +int SingleAbsoluteMouse_::getDescriptor(USBSetup &setup) { // Check if this is a HID Class Descriptor request if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0; @@ -89,12 +88,12 @@ int SingleAbsoluteMouse_::getDescriptor(USBSetup& setup) { return USB_SendControl(TRANSFER_PGM, _hidSingleReportDescriptorAbsoluteMouse, sizeof(_hidSingleReportDescriptorAbsoluteMouse)); } -bool SingleAbsoluteMouse_::setup(USBSetup& setup) { +bool SingleAbsoluteMouse_::setup(USBSetup &setup) { if (pluggedInterface != setup.wIndex) { return false; } - uint8_t request = setup.bRequest; + uint8_t request = setup.bRequest; uint8_t requestType = setup.bmRequestType; if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) { @@ -124,7 +123,7 @@ bool SingleAbsoluteMouse_::setup(USBSetup& setup) { return false; } -void SingleAbsoluteMouse_::sendReport(void* data, int length) { +void SingleAbsoluteMouse_::sendReport(void *data, int length) { auto result = USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, length); HIDReportObserver::observeReport(HID_REPORTID_MOUSE_ABSOLUTE, data, length, result); } diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/SingleReport/SingleAbsoluteMouse.h b/src/kaleidoscope/driver/hid/keyboardio/usb/SingleReport/SingleAbsoluteMouse.h index dc2e3975..ca21c293 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/SingleReport/SingleAbsoluteMouse.h +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/SingleReport/SingleAbsoluteMouse.h @@ -40,14 +40,14 @@ class SingleAbsoluteMouse_ : public PluggableUSBModule, public AbsoluteMouseAPI protected: // Implementation of the PUSBListNode - int getInterface(uint8_t* interfaceCount); - int getDescriptor(USBSetup& setup); - bool setup(USBSetup& setup); + int getInterface(uint8_t *interfaceCount); + int getDescriptor(USBSetup &setup); + bool setup(USBSetup &setup); EPTYPE_DESCRIPTOR_SIZE epType[1]; uint8_t protocol; uint8_t idle; - inline void sendReport(void* data, int length) override; + inline void sendReport(void *data, int length) override; }; extern SingleAbsoluteMouse_ SingleAbsoluteMouse; diff --git a/src/kaleidoscope/driver/hid/keyboardio/usb/arch/samd.cpp b/src/kaleidoscope/driver/hid/keyboardio/usb/arch/samd.cpp index 6d79ad1b..5f073009 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/usb/arch/samd.cpp +++ b/src/kaleidoscope/driver/hid/keyboardio/usb/arch/samd.cpp @@ -2,11 +2,11 @@ #ifdef ARDUINO_ARCH_SAMD -int USB_SendControl(void* b, unsigned char c) { +int USB_SendControl(void *b, unsigned char c) { USBDevice.sendControl(b, c); } -int USB_SendControl(uint8_t a, const void* b, uint8_t c) { +int USB_SendControl(uint8_t a, const void *b, uint8_t c) { USBDevice.sendControl(b, c); }