driver/keyboardioHID: astyle

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
f/driver/keyboardiohid-orig
Gergely Nagy 4 years ago committed by Jesse Vincent
parent 2c4a274cb3
commit 35b1fb239c
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -42,7 +42,7 @@ static const uint8_t _hidReportDescriptorKeyboard[] PROGMEM = {
D_LOGICAL_MAXIMUM, 0x1,
D_REPORT_SIZE, 0x1,
D_REPORT_COUNT, 0x8,
D_INPUT, (D_DATA|D_VARIABLE|D_ABSOLUTE),
D_INPUT, (D_DATA | D_VARIABLE | D_ABSOLUTE),
// Reserved byte
D_REPORT_COUNT, 0x1,
@ -55,7 +55,7 @@ static const uint8_t _hidReportDescriptorKeyboard[] PROGMEM = {
D_USAGE_PAGE, D_PAGE_LEDS,
D_USAGE_MINIMUM, 0x1,
D_USAGE_MAXIMUM, 0x5,
D_OUTPUT, (D_DATA|D_VARIABLE|D_ABSOLUTE),
D_OUTPUT, (D_DATA | D_VARIABLE | D_ABSOLUTE),
// Pad LEDs up to a byte
D_REPORT_COUNT, 0x1,
D_REPORT_SIZE, 0x3,
@ -69,7 +69,7 @@ static const uint8_t _hidReportDescriptorKeyboard[] PROGMEM = {
D_USAGE_PAGE, D_PAGE_KEYBOARD,
D_USAGE_MINIMUM, 0x0,
D_USAGE_MAXIMUM, 0xff,
D_INPUT, (D_DATA|D_ARRAY|D_ABSOLUTE),
D_INPUT, (D_DATA | D_ARRAY | D_ABSOLUTE),
D_END_COLLECTION
};

@ -112,7 +112,7 @@ int HID_::SendReport_(uint8_t id, const void* data, int len) {
uint8_t p[64];
p[0] = id;
memcpy(&p[1], data, len);
return USB_Send(pluggedEndpoint, p, len+1);
return USB_Send(pluggedEndpoint, p, len + 1);
#else
auto ret = USB_Send(pluggedEndpoint, &id, 1);
if (ret < 0) return ret;

@ -26,8 +26,7 @@ THE SOFTWARE.
#include <stdint.h>
class HIDReportObserver
{
class HIDReportObserver {
public:
typedef void(*SendReportHook)(uint8_t id, const void* data,
@ -35,12 +34,14 @@ class HIDReportObserver
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);
}
}
static SendReportHook currentHook() { return send_report_hook_; }
static SendReportHook currentHook() {
return send_report_hook_;
}
static SendReportHook resetHook(SendReportHook new_hook) {
auto previous_hook = send_report_hook_;

@ -40,7 +40,7 @@ static const uint8_t _hidMultiReportDescriptorGamepad[] PROGMEM = {
D_LOGICAL_MAXIMUM, 0x01, /* _LOGICAL_MAXIMUM (1) */
D_REPORT_SIZE, 0x01, /* REPORT_SIZE (1) */
D_REPORT_COUNT, 0x20, /* REPORT_COUNT (32) */
D_INPUT, (D_DATA|D_VARIABLE|D_ABSOLUTE), /* INPUT (Data,Var,Abs) */
D_INPUT, (D_DATA | D_VARIABLE | D_ABSOLUTE), /* INPUT (Data,Var,Abs) */
/* 4 16bit Axis */
D_USAGE_PAGE, D_PAGE_GENERIC_DESKTOP, /* USAGE_PAGE (Generic Desktop) */
D_COLLECTION, D_PHYSICAL, /* COLLECTION (Physical) */
@ -52,7 +52,7 @@ static const uint8_t _hidMultiReportDescriptorGamepad[] PROGMEM = {
D_MULTIBYTE(D_LOGICAL_MAXIMUM), 0xFF, 0x7F, /* _LOGICAL_MAXIMUM (32767) */
D_REPORT_SIZE, 0x10, /* REPORT_SIZE (16) */
D_REPORT_COUNT, 0x04, /* REPORT_COUNT (4) */
D_INPUT, (D_DATA|D_VARIABLE|D_ABSOLUTE), /* INPUT (Data,Var,Abs) */
D_INPUT, (D_DATA | D_VARIABLE | D_ABSOLUTE), /* INPUT (Data,Var,Abs) */
/* 2 8bit Axis */
D_USAGE, 0x32, /* USAGE (Z) */
D_USAGE, 0x35, /* USAGE (Rz) */
@ -60,7 +60,7 @@ static const uint8_t _hidMultiReportDescriptorGamepad[] PROGMEM = {
D_LOGICAL_MAXIMUM, 0x7F, /* _LOGICAL_MAXIMUM (127) */
D_REPORT_SIZE, 0x08, /* REPORT_SIZE (8) */
D_REPORT_COUNT, 0x02, /* REPORT_COUNT (2) */
D_INPUT, (D_DATA|D_VARIABLE|D_ABSOLUTE), /* INPUT (Data,Var,Abs) */
D_INPUT, (D_DATA | D_VARIABLE | D_ABSOLUTE), /* INPUT (Data,Var,Abs) */
D_END_COLLECTION, /* END_COLLECTION */
/* 2 Hat Switches */
@ -71,7 +71,7 @@ static const uint8_t _hidMultiReportDescriptorGamepad[] PROGMEM = {
D_LOGICAL_MAXIMUM, 0x08, /* _LOGICAL_MAXIMUM (8) */
D_REPORT_COUNT, 0x02, /* REPORT_COUNT (2) */
D_REPORT_SIZE, 0x04, /* REPORT_SIZE (4) */
D_INPUT, (D_DATA|D_VARIABLE|D_ABSOLUTE), /* INPUT (Data,Var,Abs) */
D_INPUT, (D_DATA | D_VARIABLE | D_ABSOLUTE), /* INPUT (Data,Var,Abs) */
D_END_COLLECTION /* END_COLLECTION */
};

@ -42,7 +42,7 @@ static const uint8_t _hidMultiReportDescriptorKeyboard[] PROGMEM = {
D_LOGICAL_MAXIMUM, 0x01,
D_REPORT_SIZE, 0x01,
D_REPORT_COUNT, 0x08,
D_INPUT, (D_DATA|D_VARIABLE|D_ABSOLUTE),
D_INPUT, (D_DATA | D_VARIABLE | D_ABSOLUTE),
/* 5 LEDs for num lock etc, 3 left for advanced, custom usage */
@ -67,7 +67,7 @@ static const uint8_t _hidMultiReportDescriptorKeyboard[] PROGMEM = {
D_LOGICAL_MAXIMUM, 0x01,
D_REPORT_SIZE, 0x01,
D_REPORT_COUNT, (HID_LAST_KEY - HID_KEYBOARD_A_AND_A),
D_INPUT, (D_DATA|D_VARIABLE|D_ABSOLUTE),
D_INPUT, (D_DATA | D_VARIABLE | D_ABSOLUTE),
// Padding (3 bits) to round up the report to byte boundary.
D_REPORT_SIZE, 0x03,
@ -118,8 +118,8 @@ int Keyboard_::sendReport(void) {
// If modifiers are being turned on at the same time as any change
// to the non-modifier keys in the report, then we send the previous
// report with the new modifiers
if ( ( (lastKeyReport.modifiers ^ keyReport.modifiers) & keyReport.modifiers)
&& (memcmp(lastKeyReport.keys,keyReport.keys, sizeof(keyReport.keys)))) {
if (((lastKeyReport.modifiers ^ keyReport.modifiers) & keyReport.modifiers)
&& (memcmp(lastKeyReport.keys, keyReport.keys, sizeof(keyReport.keys)))) {
uint8_t last_mods = lastKeyReport.modifiers;
lastKeyReport.modifiers = keyReport.modifiers;
int returnCode = HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, &lastKeyReport, sizeof(lastKeyReport));
@ -131,8 +131,8 @@ int Keyboard_::sendReport(void) {
// will sometimes result in a spurious '3' rather than '#', especially when the keys
// had been held for a while
if (( (lastKeyReport.modifiers ^ keyReport.modifiers) & lastKeyReport.modifiers)
&& (memcmp(lastKeyReport.keys,keyReport.keys, sizeof(keyReport.keys)))) {
if (((lastKeyReport.modifiers ^ keyReport.modifiers) & lastKeyReport.modifiers)
&& (memcmp(lastKeyReport.keys, keyReport.keys, sizeof(keyReport.keys)))) {
uint8_t mods = keyReport.modifiers;
keyReport.modifiers = lastKeyReport.modifiers;
int returnCode = HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, &keyReport, sizeof(lastKeyReport));
@ -191,7 +191,7 @@ boolean Keyboard_::wasAnyModifierActive() {
boolean Keyboard_::isKeyPressed(uint8_t k) {
if (k <= HID_LAST_KEY) {
uint8_t bit = 1 << (uint8_t(k) % 8);
return !! (keyReport.keys[k / 8] & bit);
return !!(keyReport.keys[k / 8] & bit);
}
return false;
}
@ -203,7 +203,7 @@ boolean Keyboard_::wasKeyPressed(uint8_t k) {
if (k <= HID_LAST_KEY) {
uint8_t bit = 1 << (uint8_t(k) % 8);
return !! (lastKeyReport.keys[k / 8] & bit);
return !!(lastKeyReport.keys[k / 8] & bit);
}
return false;
}

@ -41,7 +41,7 @@ static const uint8_t _hidMultiReportDescriptorMouse[] PROGMEM = {
D_LOGICAL_MAXIMUM, 0x01, // LOGICAL_MAXIMUM (1)
D_REPORT_COUNT, 0x08, // REPORT_COUNT (8)
D_REPORT_SIZE, 0x01, // REPORT_SIZE (1)
D_INPUT, (D_DATA|D_VARIABLE|D_ABSOLUTE), // INPUT (Data,Var,Abs)
D_INPUT, (D_DATA | D_VARIABLE | D_ABSOLUTE), // INPUT (Data,Var,Abs)
/* X, Y, Wheel */
D_USAGE_PAGE, D_PAGE_GENERIC_DESKTOP, // USAGE_PAGE (Generic Desktop)
@ -52,7 +52,7 @@ static const uint8_t _hidMultiReportDescriptorMouse[] PROGMEM = {
D_LOGICAL_MAXIMUM, 0x7f, // LOGICAL_MAXIMUM (127)
D_REPORT_SIZE, 0x08, // REPORT_SIZE (8)
D_REPORT_COUNT, 0x03, // REPORT_COUNT (3)
D_INPUT, (D_DATA|D_VARIABLE|D_RELATIVE), // INPUT (Data,Var,Rel)
D_INPUT, (D_DATA | D_VARIABLE | D_RELATIVE), // INPUT (Data,Var,Rel)
/* Horizontal wheel */
D_USAGE_PAGE, D_PAGE_CONSUMER, // USAGE_PAGE (Consumer)
@ -61,7 +61,7 @@ static const uint8_t _hidMultiReportDescriptorMouse[] PROGMEM = {
D_LOGICAL_MAXIMUM, 0x7f, // LOGICAL_MAXIMUM (127)
D_REPORT_SIZE, 0x08, // REPORT_SIZE (8)
D_REPORT_COUNT, 0x01, // REPORT_COUNT (1)
D_INPUT, (D_DATA|D_VARIABLE|D_RELATIVE), // INPUT (Data,Var,Rel)
D_INPUT, (D_DATA | D_VARIABLE | D_RELATIVE), // INPUT (Data,Var,Rel)
/* End */
D_END_COLLECTION // END_COLLECTION

@ -40,7 +40,7 @@ static const uint8_t _hidMultiReportDescriptorSystem[] PROGMEM = {
D_USAGE_MAXIMUM, 0xff, /* USAGE_MAXIMUM (System Menu Down) */
D_REPORT_COUNT, 0x01, /* REPORT_COUNT (1) */
D_REPORT_SIZE, 0x08, /* REPORT_SIZE (8) */
D_INPUT, (D_DATA|D_ARRAY|D_ABSOLUTE), /* INPUT (Data,Ary,Abs) */
D_INPUT, (D_DATA | D_ARRAY | D_ABSOLUTE), /* INPUT (Data,Ary,Abs) */
D_END_COLLECTION /* END_COLLECTION */
};

Loading…
Cancel
Save