driver/KeyboardioHID: make cpplint happy

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

@ -137,11 +137,11 @@ bool BootKeyboard_::setup(USBSetup& setup) {
if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) { if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) {
if (request == HID_GET_REPORT) { if (request == HID_GET_REPORT) {
// TODO: HID_GetReport(); // TODO(anyone): HID_GetReport();
return true; return true;
} }
if (request == HID_GET_PROTOCOL) { if (request == HID_GET_PROTOCOL) {
// TODO improve // TODO(anyone) improve
#ifdef __AVR__ #ifdef __AVR__
UEDATX = protocol; UEDATX = protocol;
#endif #endif
@ -151,7 +151,7 @@ bool BootKeyboard_::setup(USBSetup& setup) {
return true; return true;
} }
if (request == HID_GET_IDLE) { if (request == HID_GET_IDLE) {
// TODO improve // TODO(anyone) improve
#ifdef __AVR__ #ifdef __AVR__
UEDATX = idle; UEDATX = idle;
#endif #endif
@ -187,10 +187,8 @@ bool BootKeyboard_::setup(USBSetup& setup) {
USB_RecvControl(&leds, length); USB_RecvControl(&leds, length);
return true; return true;
} }
} } else { // Input (set HID report)
if (setup.wValueH == HID_REPORT_TYPE_INPUT) {
// Input (set HID report)
else if (setup.wValueH == HID_REPORT_TYPE_INPUT) {
if (length == sizeof(_keyReport)) { if (length == sizeof(_keyReport)) {
USB_RecvControl(&_keyReport, length); USB_RecvControl(&_keyReport, length);
return true; return true;
@ -198,6 +196,7 @@ bool BootKeyboard_::setup(USBSetup& setup) {
} }
} }
} }
}
return false; return false;
} }

@ -132,15 +132,15 @@ bool HID_::setup(USBSetup& setup) {
if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) { if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) {
if (request == HID_GET_REPORT) { if (request == HID_GET_REPORT) {
// TODO: HID_GetReport(); // TODO(anyone): HID_GetReport();
return true; return true;
} }
if (request == HID_GET_PROTOCOL) { if (request == HID_GET_PROTOCOL) {
// TODO: Send8(protocol); // TODO(anyone): Send8(protocol);
return true; return true;
} }
if (request == HID_GET_IDLE) { if (request == HID_GET_IDLE) {
// TODO: Send8(idle); // TODO(anyone): Send8(idle);
} }
} }

@ -94,7 +94,7 @@ class HID_ : public PluggableUSBModule {
void AppendDescriptor(HIDSubDescriptor* node); void AppendDescriptor(HIDSubDescriptor* node);
uint8_t getLEDs(void) { uint8_t getLEDs(void) {
return setReportData.leds; return setReportData.leds;
}; }
protected: protected:
// Implementation of the PluggableUSBModule // Implementation of the PluggableUSBModule

@ -124,24 +124,21 @@ int Keyboard_::sendReport(void) {
lastKeyReport.modifiers = keyReport.modifiers; lastKeyReport.modifiers = keyReport.modifiers;
int returnCode = HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, &lastKeyReport, sizeof(lastKeyReport)); int returnCode = HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, &lastKeyReport, sizeof(lastKeyReport));
lastKeyReport.modifiers = last_mods; lastKeyReport.modifiers = last_mods;
} } else {
// If modifiers are being turned off, then we send the new report with the previous modifiers. // If modifiers are being turned off, then we send the new report with the previous modifiers.
// We need to do this, at least on Linux 4.17 + Wayland. // We need to do this, at least on Linux 4.17 + Wayland.
// Jesse has observed that sending Shift + 3 key up events in the same report // Jesse has observed that sending Shift + 3 key up events in the same report
// will sometimes result in a spurious '3' rather than '#', especially when the keys // will sometimes result in a spurious '3' rather than '#', especially when the keys
// had been held for a while // had been held for a while
else if (( (lastKeyReport.modifiers ^ keyReport.modifiers) & lastKeyReport.modifiers)
if (( (lastKeyReport.modifiers ^ keyReport.modifiers) & lastKeyReport.modifiers)
&& (memcmp(lastKeyReport.keys,keyReport.keys, sizeof(keyReport.keys)))) { && (memcmp(lastKeyReport.keys,keyReport.keys, sizeof(keyReport.keys)))) {
uint8_t mods = keyReport.modifiers; uint8_t mods = keyReport.modifiers;
keyReport.modifiers = lastKeyReport.modifiers; keyReport.modifiers = lastKeyReport.modifiers;
int returnCode = HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, &keyReport, sizeof(lastKeyReport)); int returnCode = HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, &keyReport, sizeof(lastKeyReport));
keyReport.modifiers = mods; keyReport.modifiers = mods;
} }
}
int returnCode = sendReportUnchecked(); int returnCode = sendReportUnchecked();
if (returnCode > 0) if (returnCode > 0)
@ -218,15 +215,14 @@ size_t Keyboard_::press(uint8_t k) {
uint8_t bit = 1 << (uint8_t(k) % 8); uint8_t bit = 1 << (uint8_t(k) % 8);
keyReport.keys[k / 8] |= bit; keyReport.keys[k / 8] |= bit;
return 1; return 1;
} } else { // It's a modifier key
if (k >= HID_KEYBOARD_FIRST_MODIFIER && k <= HID_KEYBOARD_LAST_MODIFIER) {
// It's a modifier key
else if (k >= HID_KEYBOARD_FIRST_MODIFIER && k <= HID_KEYBOARD_LAST_MODIFIER) {
// Convert key into bitfield (0 - 7) // Convert key into bitfield (0 - 7)
k = k - HID_KEYBOARD_FIRST_MODIFIER; k = k - HID_KEYBOARD_FIRST_MODIFIER;
keyReport.modifiers |= (1 << k); keyReport.modifiers |= (1 << k);
return 1; return 1;
} }
}
// No empty/pressed key was found // No empty/pressed key was found
return 0; return 0;
@ -238,15 +234,14 @@ size_t Keyboard_::release(uint8_t k) {
uint8_t bit = 1 << (k % 8); uint8_t bit = 1 << (k % 8);
keyReport.keys[k / 8] &= ~bit; keyReport.keys[k / 8] &= ~bit;
return 1; return 1;
} } else { // It's a modifier key
if (k >= HID_KEYBOARD_FIRST_MODIFIER && k <= HID_KEYBOARD_LAST_MODIFIER) {
// It's a modifier key
else if (k >= HID_KEYBOARD_FIRST_MODIFIER && k <= HID_KEYBOARD_LAST_MODIFIER) {
// Convert key into bitfield (0 - 7) // Convert key into bitfield (0 - 7)
k = k - HID_KEYBOARD_FIRST_MODIFIER; k = k - HID_KEYBOARD_FIRST_MODIFIER;
keyReport.modifiers &= ~(1 << k); keyReport.modifiers &= ~(1 << k);
return 1; return 1;
} }
}
// No empty/pressed key was found // No empty/pressed key was found
return 0; return 0;

@ -64,7 +64,7 @@ class Keyboard_ {
uint8_t getLEDs() { uint8_t getLEDs() {
return HID().getLEDs(); return HID().getLEDs();
}; }
HID_KeyboardReport_Data_t keyReport; HID_KeyboardReport_Data_t keyReport;
HID_KeyboardReport_Data_t lastKeyReport; HID_KeyboardReport_Data_t lastKeyReport;

@ -27,7 +27,7 @@ THE SOFTWARE.
#include "../DescriptorPrimitives.h" #include "../DescriptorPrimitives.h"
static const uint8_t _hidMultiReportDescriptorSystem[] PROGMEM = { static const uint8_t _hidMultiReportDescriptorSystem[] PROGMEM = {
//TODO limit to system keys only? //TODO(anyone): limit to system keys only?
/* System Control (Power Down, Sleep, Wakeup, ...) */ /* System Control (Power Down, Sleep, Wakeup, ...) */
D_USAGE_PAGE, D_PAGE_GENERIC_DESKTOP, /* USAGE_PAGE (Generic Desktop) */ D_USAGE_PAGE, D_PAGE_GENERIC_DESKTOP, /* USAGE_PAGE (Generic Desktop) */
D_USAGE, 0x80, /* USAGE (System Control) */ D_USAGE, 0x80, /* USAGE (System Control) */

@ -84,11 +84,11 @@ bool SingleAbsoluteMouse_::setup(USBSetup& setup) {
if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) { if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) {
if (request == HID_GET_REPORT) { if (request == HID_GET_REPORT) {
// TODO: HID_GetReport(); // TODO(anyone): HID_GetReport();
return true; return true;
} }
if (request == HID_GET_PROTOCOL) { if (request == HID_GET_PROTOCOL) {
// TODO: Send8(protocol); // TODO(anyone): Send8(protocol);
return true; return true;
} }
} }

@ -48,6 +48,6 @@ class SingleAbsoluteMouse_ : public PluggableUSBModule, public AbsoluteMouseAPI
uint8_t protocol; uint8_t protocol;
uint8_t idle; uint8_t idle;
virtual inline void sendReport(void* data, int length) override; inline void sendReport(void* data, int length) override;
}; };
extern SingleAbsoluteMouse_ SingleAbsoluteMouse; extern SingleAbsoluteMouse_ SingleAbsoluteMouse;

Loading…
Cancel
Save