Skip to content

Commit

Permalink
Compatibility with Arduino's core HID / Mouse / Keyboard libraries
Browse files Browse the repository at this point in the history
The following collisions resolved:

hid.h -> usbhid.h
hid.cpp -> usbhid.cpp
HID -> USBHID
HID_BOOT_PROTOCOL -> USB_HID_BOOT_PROTOCOL
HID_PROTOCOL_NONE -> USB_HID_PROTOCOL_NONE
HID_PROTOCOL_KEYBOARD -> USB_HID_PROTOCOL_KEYBOARD
HID_PROTOCOL_MOUSE -> USB_HID_PROTOCOL_MOUSE

As a result, it's possible to use the library together with Arduino's bundled HID / Mouse / Keyboard libraries (Leonardo, Micro, or Due).

https://www.arduino.cc/en/Reference/MouseKeyboard
  • Loading branch information
pavelfatin committed Jan 16, 2016
1 parent f90ba2c commit 969eabb
Show file tree
Hide file tree
Showing 33 changed files with 84 additions and 84 deletions.
2 changes: 1 addition & 1 deletion BTD.h
Expand Up @@ -19,7 +19,7 @@
#define _btd_h_

#include "Usb.h"
#include "hid.h"
#include "usbhid.h"

//PID and VID of the Sony PS3 devices
#define PS3_VID 0x054C // Sony Corporation
Expand Down
10 changes: 5 additions & 5 deletions BTHID.cpp
Expand Up @@ -22,7 +22,7 @@

BTHID::BTHID(BTD *p, bool pair, const char *pin) :
BluetoothService(p), // Pointer to USB class instance - mandatory
protocolMode(HID_BOOT_PROTOCOL) {
protocolMode(USB_HID_BOOT_PROTOCOL) {
for(uint8_t i = 0; i < NUM_PARSERS; i++)
pRptParser[i] = NULL;

Expand Down Expand Up @@ -192,12 +192,12 @@ void BTHID::ACLData(uint8_t* l2capinbuf) {
switch(l2capinbuf[9]) {
case 0x01: // Keyboard or Joystick events
if(pRptParser[KEYBOARD_PARSER_ID])
pRptParser[KEYBOARD_PARSER_ID]->Parse(reinterpret_cast<HID *>(this), 0, (uint8_t)(length - 2), &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance
pRptParser[KEYBOARD_PARSER_ID]->Parse(reinterpret_cast<USBHID *>(this), 0, (uint8_t)(length - 2), &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance
break;

case 0x02: // Mouse events
if(pRptParser[MOUSE_PARSER_ID])
pRptParser[MOUSE_PARSER_ID]->Parse(reinterpret_cast<HID *>(this), 0, (uint8_t)(length - 2), &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance
pRptParser[MOUSE_PARSER_ID]->Parse(reinterpret_cast<USBHID *>(this), 0, (uint8_t)(length - 2), &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance
break;
#ifdef EXTRADEBUG
default:
Expand Down Expand Up @@ -380,11 +380,11 @@ void BTHID::setProtocol() {
Notify(PSTR("\r\nSet protocol mode: "), 0x80);
D_PrintHex<uint8_t > (protocolMode, 0x80);
#endif
if (protocolMode != HID_BOOT_PROTOCOL && protocolMode != HID_RPT_PROTOCOL) {
if (protocolMode != USB_HID_BOOT_PROTOCOL && protocolMode != HID_RPT_PROTOCOL) {
#ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nNot a valid protocol mode. Using Boot protocol instead."), 0x80);
#endif
protocolMode = HID_BOOT_PROTOCOL; // Use Boot Protocol by default
protocolMode = USB_HID_BOOT_PROTOCOL; // Use Boot Protocol by default
}
uint8_t command = 0x70 | protocolMode; // Set Protocol, see Bluetooth HID specs page 33
pBtd->L2CAP_Command(hci_handle, &command, 1, control_scid[0], control_scid[1]);
Expand Down
2 changes: 1 addition & 1 deletion BTHID.h
Expand Up @@ -67,7 +67,7 @@ class BTHID : public BluetoothService {

/**
* Set HID protocol mode.
* @param mode HID protocol to use. Either HID_BOOT_PROTOCOL or HID_RPT_PROTOCOL.
* @param mode HID protocol to use. Either USB_HID_BOOT_PROTOCOL or HID_RPT_PROTOCOL.
*/
void setProtocolMode(uint8_t mode) {
protocolMode = mode;
Expand Down
2 changes: 1 addition & 1 deletion PS3USB.h
Expand Up @@ -19,7 +19,7 @@
#define _ps3usb_h_

#include "Usb.h"
#include "hid.h"
#include "usbhid.h"
#include "PS3Enums.h"

/* PS3 data taken from descriptors */
Expand Down
2 changes: 1 addition & 1 deletion PS4USB.h
Expand Up @@ -64,7 +64,7 @@ class PS4USB : public HIDUniversal, public PS4Parser {
* @param len The length of the incoming data.
* @param buf Pointer to the data buffer.
*/
virtual void ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
virtual void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
if (HIDUniversal::VID == PS4_VID && HIDUniversal::PID == PS4_PID)
PS4Parser::Parse(len, buf);
};
Expand Down
2 changes: 1 addition & 1 deletion PSBuzz.cpp
Expand Up @@ -20,7 +20,7 @@
// To enable serial debugging see "settings.h"
//#define PRINTREPORT // Uncomment to print the report send by the PS Buzz Controllers

void PSBuzz::ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
void PSBuzz::ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
if (HIDUniversal::VID == PSBUZZ_VID && HIDUniversal::PID == PSBUZZ_PID && len > 2 && buf) {
#ifdef PRINTREPORT
Notify(PSTR("\r\n"), 0x80);
Expand Down
2 changes: 1 addition & 1 deletion PSBuzz.h
Expand Up @@ -143,7 +143,7 @@ class PSBuzz : public HIDUniversal {
* @param len The length of the incoming data.
* @param buf Pointer to the data buffer.
*/
void ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);

/**
* Called when a device is successfully initialized.
Expand Down
2 changes: 1 addition & 1 deletion XBOXOLD.h
Expand Up @@ -19,7 +19,7 @@
#define _xboxold_h_

#include "Usb.h"
#include "hid.h"
#include "usbhid.h"
#include "controllerEnums.h"

/* Data Xbox taken from descriptors */
Expand Down
2 changes: 1 addition & 1 deletion XBOXUSB.h
Expand Up @@ -19,7 +19,7 @@
#define _xboxusb_h_

#include "Usb.h"
#include "hid.h"
#include "usbhid.h"
#include "xboxEnums.h"

/* Data Xbox 360 taken from descriptors */
Expand Down
2 changes: 1 addition & 1 deletion examples/Bluetooth/BTHID/BTHID.ino
Expand Up @@ -45,7 +45,7 @@ void setup() {

// If "Boot Protocol Mode" does not work, then try "Report Protocol Mode"
// If that does not work either, then uncomment PRINTREPORT in BTHID.cpp to see the raw report
bthid.setProtocolMode(HID_BOOT_PROTOCOL); // Boot Protocol Mode
bthid.setProtocolMode(USB_HID_BOOT_PROTOCOL); // Boot Protocol Mode
//bthid.setProtocolMode(HID_RPT_PROTOCOL); // Report Protocol Mode

Serial.print(F("\r\nHID Bluetooth Library Started"));
Expand Down
4 changes: 2 additions & 2 deletions examples/Bluetooth/BTHID/KeyboardParser.h
Expand Up @@ -3,7 +3,7 @@

class KbdRptParser : public KeyboardReportParser {
protected:
virtual uint8_t HandleLockingKeys(HID *hid, uint8_t key);
virtual uint8_t HandleLockingKeys(USBHID *hid, uint8_t key);
virtual void OnControlKeysChanged(uint8_t before, uint8_t after);
virtual void OnKeyDown(uint8_t mod, uint8_t key);
virtual void OnKeyUp(uint8_t mod, uint8_t key);
Expand All @@ -13,7 +13,7 @@ class KbdRptParser : public KeyboardReportParser {
void PrintKey(uint8_t mod, uint8_t key);
};

uint8_t KbdRptParser::HandleLockingKeys(HID *hid, uint8_t key) {
uint8_t KbdRptParser::HandleLockingKeys(USBHID *hid, uint8_t key) {
uint8_t old_keys = kbdLockingKeys.bLeds;

switch (key) {
Expand Down
2 changes: 1 addition & 1 deletion examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino
Expand Up @@ -98,7 +98,7 @@ void KbdRptParser::OnKeyPressed(uint8_t key)

USB Usb;
//USBHub Hub(&Usb);
HIDBoot<HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);

uint32_t next_time;

Expand Down
6 changes: 3 additions & 3 deletions examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino
Expand Up @@ -141,9 +141,9 @@ void KbdRptParser::OnKeyPressed(uint8_t key)
USB Usb;
USBHub Hub(&Usb);

HIDBoot < HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE > HidComposite(&Usb);
HIDBoot<HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
HIDBoot<HID_PROTOCOL_MOUSE> HidMouse(&Usb);
HIDBoot < USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE > HidComposite(&Usb);
HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
HIDBoot<USB_HID_PROTOCOL_MOUSE> HidMouse(&Usb);

//uint32_t next_time;

Expand Down
2 changes: 1 addition & 1 deletion examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino
Expand Up @@ -52,7 +52,7 @@ void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi)

USB Usb;
USBHub Hub(&Usb);
HIDBoot<HID_PROTOCOL_MOUSE> HidMouse(&Usb);
HIDBoot<USB_HID_PROTOCOL_MOUSE> HidMouse(&Usb);

uint32_t next_time;

Expand Down
2 changes: 1 addition & 1 deletion examples/HID/USBHIDJoystick/USBHIDJoystick.ino
@@ -1,4 +1,4 @@
#include <hid.h>
#include <usbhid.h>
#include <hiduniversal.h>
#include <usbhub.h>

Expand Down
2 changes: 1 addition & 1 deletion examples/HID/USBHIDJoystick/hidjoystickrptparser.cpp
Expand Up @@ -8,7 +8,7 @@ oldButtons(0) {
oldPad[i] = 0xD;
}

void JoystickReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
bool match = true;

// Checking if there are changes in report since the method was last called
Expand Down
4 changes: 2 additions & 2 deletions examples/HID/USBHIDJoystick/hidjoystickrptparser.h
@@ -1,7 +1,7 @@
#if !defined(__HIDJOYSTICKRPTPARSER_H__)
#define __HIDJOYSTICKRPTPARSER_H__

#include <hid.h>
#include <usbhid.h>

struct GamePadEventData {
uint8_t X, Y, Z1, Z2, Rz;
Expand All @@ -27,7 +27,7 @@ class JoystickReportParser : public HIDReportParser {
public:
JoystickReportParser(JoystickEvents *evt);

virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
};

#endif // __HIDJOYSTICKRPTPARSER_H__
2 changes: 1 addition & 1 deletion examples/HID/USBHID_desc/USBHID_desc.ino
@@ -1,4 +1,4 @@
#include <hid.h>
#include <usbhid.h>
#include <hiduniversal.h>
#include <hidescriptorparser.h>
#include <usbhub.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/HID/le3dp/le3dp.ino
@@ -1,6 +1,6 @@
/* Simplified Logitech Extreme 3D Pro Joystick Report Parser */

#include <hid.h>
#include <usbhid.h>
#include <hiduniversal.h>
#include <usbhub.h>

Expand Down
2 changes: 1 addition & 1 deletion examples/HID/le3dp/le3dp_rptparser.cpp
Expand Up @@ -4,7 +4,7 @@ JoystickReportParser::JoystickReportParser(JoystickEvents *evt) :
joyEvents(evt)
{}

void JoystickReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
{
bool match = true;

Expand Down
4 changes: 2 additions & 2 deletions examples/HID/le3dp/le3dp_rptparser.h
@@ -1,7 +1,7 @@
#if !defined(__HIDJOYSTICKRPTPARSER_H__)
#define __HIDJOYSTICKRPTPARSER_H__

#include <hid.h>
#include <usbhid.h>

struct GamePadEventData
{
Expand Down Expand Up @@ -36,7 +36,7 @@ class JoystickReportParser : public HIDReportParser
public:
JoystickReportParser(JoystickEvents *evt);

virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
};

#endif // __HIDJOYSTICKRPTPARSER_H__
2 changes: 1 addition & 1 deletion examples/HID/scale/scale.ino
@@ -1,7 +1,7 @@
/* Digital Scale Output. Written for Stamps.com Model 510 */
/* 5lb Digital Scale; any HID scale with Usage page 0x8d should work */

#include <hid.h>
#include <usbhid.h>
#include <hiduniversal.h>
#include <usbhub.h>

Expand Down
2 changes: 1 addition & 1 deletion examples/HID/scale/scale_rptparser.cpp
Expand Up @@ -24,7 +24,7 @@ ScaleReportParser::ScaleReportParser(ScaleEvents *evt) :
scaleEvents(evt)
{}

void ScaleReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
void ScaleReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
{
bool match = true;

Expand Down
4 changes: 2 additions & 2 deletions examples/HID/scale/scale_rptparser.h
Expand Up @@ -2,7 +2,7 @@
#define __SCALERPTPARSER_H__

#include <max_LCD.h>
#include <hid.h>
#include <usbhid.h>

/* Scale status constants */
#define REPORT_FAULT 0x01
Expand Down Expand Up @@ -49,7 +49,7 @@ class ScaleReportParser : public HIDReportParser
public:
ScaleReportParser(ScaleEvents *evt);

virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
};

#endif // __SCALERPTPARSER_H__
2 changes: 1 addition & 1 deletion examples/adk/adk_barcode/adk_barcode.ino
Expand Up @@ -14,7 +14,7 @@
USB Usb;
USBHub Hub1(&Usb);
USBHub Hub2(&Usb);
HIDBoot<HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);

ADK adk(&Usb,"Circuits@Home, ltd.",
"USB Host Shield",
Expand Down
4 changes: 2 additions & 2 deletions hidboot.cpp
Expand Up @@ -16,7 +16,7 @@ e-mail : support@circuitsathome.com
*/
#include "hidboot.h"

void MouseReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
void MouseReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
MOUSEINFO *pmi = (MOUSEINFO*)buf;
// Future:
// bool event;
Expand Down Expand Up @@ -124,7 +124,7 @@ void MouseReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *bu

};

void KeyboardReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
void KeyboardReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
// On error - return
if (buf[2] == 1)
return;
Expand Down

0 comments on commit 969eabb

Please sign in to comment.