Format imported KeyboardioHID code with clang-format

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
f/driver/keyboardiohid
Michael Richters 3 years ago
parent eb94f08c35
commit 04fba96786
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -19,18 +19,13 @@
#include "kaleidoscope/device/virtual/Virtual.h" #include "kaleidoscope/device/virtual/Virtual.h"
// From Arduino:
#include <EEPROM.h> // for EEPROMClass, EERef #include <EEPROM.h> // for EEPROMClass, EERef
// From KeyboardioHID:
#include <HIDReportObserver.h> // for HIDReportObserver
// From system:
#include <stdint.h> // for uint8_t, uint16_t #include <stdint.h> // for uint8_t, uint16_t
#include <stdlib.h> // for exit, size_t #include <stdlib.h> // for exit, size_t
#include <virtual_io.h> // for getLineOfInput, isInte... #include <virtual_io.h> // for getLineOfInput, isInte...
#include <sstream> // for operator<<, string #include <sstream> // for operator<<, string
#include <string> // for operator==, char_traits #include <string> // for operator==, char_traits
// From Kaleidoscope:
#include "kaleidoscope/KeyAddr.h" // for MatrixAddr, MatrixAddr... #include "kaleidoscope/KeyAddr.h" // for MatrixAddr, MatrixAddr...
#include "kaleidoscope/device/virtual/DefaultHIDReportConsumer.h" // for DefaultHIDReportConsumer #include "kaleidoscope/device/virtual/DefaultHIDReportConsumer.h" // for DefaultHIDReportConsumer
#include "kaleidoscope/device/virtual/Logging.h" // for log_error, logging #include "kaleidoscope/device/virtual/Logging.h" // for log_error, logging

@ -82,7 +82,8 @@ static const uint8_t BOOT_KEYBOARD_EP_SIZE = USB_EP_SIZE;
#endif #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 #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 #else
@ -96,8 +97,7 @@ int BootKeyboard_::getInterface(uint8_t* interfaceCount) {
HIDDescriptor hidInterface = { HIDDescriptor hidInterface = {
D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_BOOT_INTERFACE, HID_PROTOCOL_KEYBOARD), D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_BOOT_INTERFACE, HID_PROTOCOL_KEYBOARD),
D_HIDREPORT(sizeof(boot_keyboard_hid_descriptor_)), 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)); return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
} }
@ -138,7 +138,6 @@ void BootKeyboard_::end() {
} }
bool BootKeyboard_::setup(USBSetup &setup) { bool BootKeyboard_::setup(USBSetup &setup) {
if (pluggedInterface != setup.wIndex) { if (pluggedInterface != setup.wIndex) {
return false; return false;
@ -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 true if the modifer key passed in will be sent during this key report
* Returns false in all other cases * Returns false in all other cases
* */ * */

@ -88,7 +88,6 @@ THE SOFTWARE.
#define D_BUFFERED_BYTES 0b10000000 #define D_BUFFERED_BYTES 0b10000000
// Collection types // Collection types

@ -150,7 +150,6 @@ constexpr uint16_t EP_TYPE_INTERRUPT_OUT(uint8_t buffer_size) {
} }
#else #else
#error "Unsupported architecture" #error "Unsupported architecture"

@ -28,12 +28,9 @@ THE SOFTWARE.
class HIDReportObserver { class HIDReportObserver {
public: public:
typedef void (*SendReportHook)(uint8_t id, const void *data, int len, int result);
typedef void(*SendReportHook)(uint8_t id, const void* data, static void observeReport(uint8_t id, const void *data, int len, int result) {
int len, int result);
static void observeReport(uint8_t id, const void* data,
int len, int result) {
if (send_report_hook_) { if (send_report_hook_) {
(*send_report_hook_)(id, data, len, result); (*send_report_hook_)(id, data, len, result);
} }
@ -50,6 +47,5 @@ class HIDReportObserver {
} }
private: private:
static SendReportHook send_report_hook_; static SendReportHook send_report_hook_;
}; };

@ -33,8 +33,7 @@ int HID_::getInterface(uint8_t* interfaceCount) {
HIDDescriptor hidInterface = { HIDDescriptor hidInterface = {
D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE), D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE),
D_HIDREPORT(descriptorSize), 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)); return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
} }
@ -71,7 +70,8 @@ int HID_::getDescriptor(USBSetup& setup) {
} }
__attribute__((weak)) __attribute__((weak))
uint8_t HID_::getShortName(char *name) { uint8_t
HID_::getShortName(char *name) {
name[0] = 'k'; name[0] = 'k';
name[1] = 'b'; name[1] = 'b';
name[2] = 'i'; name[2] = 'i';
@ -195,9 +195,12 @@ bool HID_::setup(USBSetup& setup) {
return false; return false;
} }
HID_::HID_() : PluggableUSBModule(1, 1, epType), HID_::HID_()
rootNode(NULL), descriptorSize(0), : PluggableUSBModule(1, 1, epType),
protocol(HID_REPORT_PROTOCOL), idle(1) { rootNode(NULL),
descriptorSize(0),
protocol(HID_REPORT_PROTOCOL),
idle(1) {
setReportData.reportId = 0; setReportData.reportId = 0;
setReportData.leds = 0; setReportData.leds = 0;

@ -81,7 +81,8 @@ typedef struct {
class HIDSubDescriptor { class HIDSubDescriptor {
public: public:
HIDSubDescriptor *next = NULL; 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; const uint16_t length;
@ -89,7 +90,6 @@ class HIDSubDescriptor {
class HID_ : public PluggableUSBModule { class HID_ : public PluggableUSBModule {
public: public:
HID_(); HID_();
int begin(); int begin();
int SendReport(uint8_t id, const void *data, int len); int SendReport(uint8_t id, const void *data, int len);
@ -106,6 +106,7 @@ class HID_ : public PluggableUSBModule {
uint8_t getShortName(char *name); 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: private:
EPTYPE_DESCRIPTOR_SIZE epType[1]; EPTYPE_DESCRIPTOR_SIZE epType[1];
@ -125,6 +126,7 @@ class HID_ : public PluggableUSBModule {
// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use // 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

@ -119,6 +119,7 @@ class Gamepad_ {
void dPad2(int8_t d); void dPad2(int8_t d);
void sendReport(void *data, int length); void sendReport(void *data, int length);
protected: protected:
HID_GamepadReport_Data_t report_; HID_GamepadReport_Data_t report_;
}; };

@ -98,7 +98,8 @@ void Keyboard_::end() {
int Keyboard_::sendReportUnchecked() { int Keyboard_::sendReportUnchecked() {
return HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, 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: // Sending the current HID report to the host:

@ -53,5 +53,4 @@ class SystemControl_ {
}; };
extern SystemControl_ SystemControl; extern SystemControl_ SystemControl;

@ -46,8 +46,8 @@ static const uint8_t SINGLE_ABSOLUTEMOUSE_EP_SIZE = USB_EP_SIZE;
#endif #endif
SingleAbsoluteMouse_::SingleAbsoluteMouse_()
SingleAbsoluteMouse_::SingleAbsoluteMouse_() : PluggableUSBModule(1, 1, epType), protocol(HID_REPORT_PROTOCOL), idle(1) { : PluggableUSBModule(1, 1, epType), protocol(HID_REPORT_PROTOCOL), idle(1) {
#ifdef ARCH_HAS_CONFIGURABLE_EP_SIZES #ifdef ARCH_HAS_CONFIGURABLE_EP_SIZES
epType[0] = EP_TYPE_INTERRUPT_IN(SINGLE_ABSOLUTEMOUSE_EP_SIZE); epType[0] = EP_TYPE_INTERRUPT_IN(SINGLE_ABSOLUTEMOUSE_EP_SIZE);
@ -63,8 +63,7 @@ int SingleAbsoluteMouse_::getInterface(uint8_t* interfaceCount) {
HIDDescriptor hidInterface = { HIDDescriptor hidInterface = {
D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE), D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE),
D_HIDREPORT(sizeof(_hidSingleReportDescriptorAbsoluteMouse)), 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)); return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
} }

Loading…
Cancel
Save