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"
// From Arduino:
#include <EEPROM.h> // for EEPROMClass, EERef
// From KeyboardioHID:
#include <HIDReportObserver.h> // for HIDReportObserver
// From system:
#include <stdint.h> // for uint8_t, uint16_t
#include <stdlib.h> // for exit, size_t
#include <virtual_io.h> // for getLineOfInput, isInte...
#include <sstream> // for operator<<, string
#include <string> // 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

@ -82,7 +82,8 @@ 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
#else
@ -91,17 +92,16 @@ BootKeyboard_::BootKeyboard_(uint8_t protocol_) : PluggableUSBModule(1, 1, epTyp
PluggableUSB().plug(this);
}
int BootKeyboard_::getInterface(uint8_t* interfaceCount) {
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,8 +138,7 @@ void BootKeyboard_::end() {
}
bool BootKeyboard_::setup(USBSetup& setup) {
bool BootKeyboard_::setup(USBSetup &setup) {
if (pluggedInterface != setup.wIndex) {
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 false in all other cases
* */

@ -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;

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

@ -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_;

@ -122,8 +122,8 @@ 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
@ -150,7 +150,6 @@ constexpr uint16_t EP_TYPE_INTERRUPT_OUT(uint8_t buffer_size) {
}
#else
#error "Unsupported architecture"

@ -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);
}
@ -50,6 +47,5 @@ class HIDReportObserver {
}
private:
static SendReportHook send_report_hook_;
};

@ -23,22 +23,21 @@
#if defined(USBCON)
HID_& HID() {
HID_ &HID() {
static HID_ obj;
return obj;
}
int HID_::getInterface(uint8_t* interfaceCount) {
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,7 +122,7 @@ 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;
}
@ -195,9 +195,12 @@ 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;

@ -81,35 +81,36 @@ typedef struct {
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

@ -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);
}

@ -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;

@ -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);
}

@ -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_;
};

@ -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:

@ -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;

@ -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);
}

@ -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;

@ -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) {
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,7 +88,7 @@ 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;
}
@ -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);
}

@ -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;

@ -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);
}

Loading…
Cancel
Save