Compatibility with Arduino's core HID / Mouse / Keyboard libraries

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
This commit is contained in:
Pavel Fatin 2016-01-16 20:01:11 +01:00
parent f90ba2c16d
commit 969eabb8d7
33 changed files with 84 additions and 84 deletions

2
BTD.h
View file

@ -19,7 +19,7 @@
#define _btd_h_ #define _btd_h_
#include "Usb.h" #include "Usb.h"
#include "hid.h" #include "usbhid.h"
//PID and VID of the Sony PS3 devices //PID and VID of the Sony PS3 devices
#define PS3_VID 0x054C // Sony Corporation #define PS3_VID 0x054C // Sony Corporation

View file

@ -22,7 +22,7 @@
BTHID::BTHID(BTD *p, bool pair, const char *pin) : BTHID::BTHID(BTD *p, bool pair, const char *pin) :
BluetoothService(p), // Pointer to USB class instance - mandatory 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++) for(uint8_t i = 0; i < NUM_PARSERS; i++)
pRptParser[i] = NULL; pRptParser[i] = NULL;
@ -192,12 +192,12 @@ void BTHID::ACLData(uint8_t* l2capinbuf) {
switch(l2capinbuf[9]) { switch(l2capinbuf[9]) {
case 0x01: // Keyboard or Joystick events case 0x01: // Keyboard or Joystick events
if(pRptParser[KEYBOARD_PARSER_ID]) 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; break;
case 0x02: // Mouse events case 0x02: // Mouse events
if(pRptParser[MOUSE_PARSER_ID]) 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; break;
#ifdef EXTRADEBUG #ifdef EXTRADEBUG
default: default:
@ -380,11 +380,11 @@ void BTHID::setProtocol() {
Notify(PSTR("\r\nSet protocol mode: "), 0x80); Notify(PSTR("\r\nSet protocol mode: "), 0x80);
D_PrintHex<uint8_t > (protocolMode, 0x80); D_PrintHex<uint8_t > (protocolMode, 0x80);
#endif #endif
if (protocolMode != HID_BOOT_PROTOCOL && protocolMode != HID_RPT_PROTOCOL) { if (protocolMode != USB_HID_BOOT_PROTOCOL && protocolMode != HID_RPT_PROTOCOL) {
#ifdef DEBUG_USB_HOST #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nNot a valid protocol mode. Using Boot protocol instead."), 0x80); Notify(PSTR("\r\nNot a valid protocol mode. Using Boot protocol instead."), 0x80);
#endif #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 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]); pBtd->L2CAP_Command(hci_handle, &command, 1, control_scid[0], control_scid[1]);

View file

@ -67,7 +67,7 @@ public:
/** /**
* Set HID protocol mode. * 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) { void setProtocolMode(uint8_t mode) {
protocolMode = mode; protocolMode = mode;

View file

@ -19,7 +19,7 @@
#define _ps3usb_h_ #define _ps3usb_h_
#include "Usb.h" #include "Usb.h"
#include "hid.h" #include "usbhid.h"
#include "PS3Enums.h" #include "PS3Enums.h"
/* PS3 data taken from descriptors */ /* PS3 data taken from descriptors */

View file

@ -64,7 +64,7 @@ protected:
* @param len The length of the incoming data. * @param len The length of the incoming data.
* @param buf Pointer to the data buffer. * @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) if (HIDUniversal::VID == PS4_VID && HIDUniversal::PID == PS4_PID)
PS4Parser::Parse(len, buf); PS4Parser::Parse(len, buf);
}; };

View file

@ -20,7 +20,7 @@
// To enable serial debugging see "settings.h" // To enable serial debugging see "settings.h"
//#define PRINTREPORT // Uncomment to print the report send by the PS Buzz Controllers //#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) { if (HIDUniversal::VID == PSBUZZ_VID && HIDUniversal::PID == PSBUZZ_PID && len > 2 && buf) {
#ifdef PRINTREPORT #ifdef PRINTREPORT
Notify(PSTR("\r\n"), 0x80); Notify(PSTR("\r\n"), 0x80);

View file

@ -143,7 +143,7 @@ protected:
* @param len The length of the incoming data. * @param len The length of the incoming data.
* @param buf Pointer to the data buffer. * @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. * Called when a device is successfully initialized.

View file

@ -19,7 +19,7 @@
#define _xboxold_h_ #define _xboxold_h_
#include "Usb.h" #include "Usb.h"
#include "hid.h" #include "usbhid.h"
#include "controllerEnums.h" #include "controllerEnums.h"
/* Data Xbox taken from descriptors */ /* Data Xbox taken from descriptors */

View file

@ -19,7 +19,7 @@
#define _xboxusb_h_ #define _xboxusb_h_
#include "Usb.h" #include "Usb.h"
#include "hid.h" #include "usbhid.h"
#include "xboxEnums.h" #include "xboxEnums.h"
/* Data Xbox 360 taken from descriptors */ /* Data Xbox 360 taken from descriptors */

View file

@ -45,7 +45,7 @@ void setup() {
// If "Boot Protocol Mode" does not work, then try "Report Protocol Mode" // 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 // 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 //bthid.setProtocolMode(HID_RPT_PROTOCOL); // Report Protocol Mode
Serial.print(F("\r\nHID Bluetooth Library Started")); Serial.print(F("\r\nHID Bluetooth Library Started"));

View file

@ -3,7 +3,7 @@
class KbdRptParser : public KeyboardReportParser { class KbdRptParser : public KeyboardReportParser {
protected: 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 OnControlKeysChanged(uint8_t before, uint8_t after);
virtual void OnKeyDown(uint8_t mod, uint8_t key); virtual void OnKeyDown(uint8_t mod, uint8_t key);
virtual void OnKeyUp(uint8_t mod, uint8_t key); virtual void OnKeyUp(uint8_t mod, uint8_t key);
@ -13,7 +13,7 @@ class KbdRptParser : public KeyboardReportParser {
void PrintKey(uint8_t mod, uint8_t key); 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; uint8_t old_keys = kbdLockingKeys.bLeds;
switch (key) { switch (key) {

View file

@ -98,7 +98,7 @@ void KbdRptParser::OnKeyPressed(uint8_t key)
USB Usb; USB Usb;
//USBHub Hub(&Usb); //USBHub Hub(&Usb);
HIDBoot<HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb); HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
uint32_t next_time; uint32_t next_time;

View file

@ -141,9 +141,9 @@ void KbdRptParser::OnKeyPressed(uint8_t key)
USB Usb; USB Usb;
USBHub Hub(&Usb); USBHub Hub(&Usb);
HIDBoot < HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE > HidComposite(&Usb); HIDBoot < USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE > HidComposite(&Usb);
HIDBoot<HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb); HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
HIDBoot<HID_PROTOCOL_MOUSE> HidMouse(&Usb); HIDBoot<USB_HID_PROTOCOL_MOUSE> HidMouse(&Usb);
//uint32_t next_time; //uint32_t next_time;

View file

@ -52,7 +52,7 @@ void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi)
USB Usb; USB Usb;
USBHub Hub(&Usb); USBHub Hub(&Usb);
HIDBoot<HID_PROTOCOL_MOUSE> HidMouse(&Usb); HIDBoot<USB_HID_PROTOCOL_MOUSE> HidMouse(&Usb);
uint32_t next_time; uint32_t next_time;

View file

@ -1,4 +1,4 @@
#include <hid.h> #include <usbhid.h>
#include <hiduniversal.h> #include <hiduniversal.h>
#include <usbhub.h> #include <usbhub.h>

View file

@ -8,7 +8,7 @@ oldButtons(0) {
oldPad[i] = 0xD; 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; bool match = true;
// Checking if there are changes in report since the method was last called // Checking if there are changes in report since the method was last called

View file

@ -1,7 +1,7 @@
#if !defined(__HIDJOYSTICKRPTPARSER_H__) #if !defined(__HIDJOYSTICKRPTPARSER_H__)
#define __HIDJOYSTICKRPTPARSER_H__ #define __HIDJOYSTICKRPTPARSER_H__
#include <hid.h> #include <usbhid.h>
struct GamePadEventData { struct GamePadEventData {
uint8_t X, Y, Z1, Z2, Rz; uint8_t X, Y, Z1, Z2, Rz;
@ -27,7 +27,7 @@ class JoystickReportParser : public HIDReportParser {
public: public:
JoystickReportParser(JoystickEvents *evt); 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__ #endif // __HIDJOYSTICKRPTPARSER_H__

View file

@ -1,4 +1,4 @@
#include <hid.h> #include <usbhid.h>
#include <hiduniversal.h> #include <hiduniversal.h>
#include <hidescriptorparser.h> #include <hidescriptorparser.h>
#include <usbhub.h> #include <usbhub.h>

View file

@ -1,6 +1,6 @@
/* Simplified Logitech Extreme 3D Pro Joystick Report Parser */ /* Simplified Logitech Extreme 3D Pro Joystick Report Parser */
#include <hid.h> #include <usbhid.h>
#include <hiduniversal.h> #include <hiduniversal.h>
#include <usbhub.h> #include <usbhub.h>

View file

@ -4,7 +4,7 @@ JoystickReportParser::JoystickReportParser(JoystickEvents *evt) :
joyEvents(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; bool match = true;

View file

@ -1,7 +1,7 @@
#if !defined(__HIDJOYSTICKRPTPARSER_H__) #if !defined(__HIDJOYSTICKRPTPARSER_H__)
#define __HIDJOYSTICKRPTPARSER_H__ #define __HIDJOYSTICKRPTPARSER_H__
#include <hid.h> #include <usbhid.h>
struct GamePadEventData struct GamePadEventData
{ {
@ -36,7 +36,7 @@ class JoystickReportParser : public HIDReportParser
public: public:
JoystickReportParser(JoystickEvents *evt); 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__ #endif // __HIDJOYSTICKRPTPARSER_H__

View file

@ -1,7 +1,7 @@
/* Digital Scale Output. Written for Stamps.com Model 510 */ /* Digital Scale Output. Written for Stamps.com Model 510 */
/* 5lb Digital Scale; any HID scale with Usage page 0x8d should work */ /* 5lb Digital Scale; any HID scale with Usage page 0x8d should work */
#include <hid.h> #include <usbhid.h>
#include <hiduniversal.h> #include <hiduniversal.h>
#include <usbhub.h> #include <usbhub.h>

View file

@ -24,7 +24,7 @@ ScaleReportParser::ScaleReportParser(ScaleEvents *evt) :
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; bool match = true;

View file

@ -2,7 +2,7 @@
#define __SCALERPTPARSER_H__ #define __SCALERPTPARSER_H__
#include <max_LCD.h> #include <max_LCD.h>
#include <hid.h> #include <usbhid.h>
/* Scale status constants */ /* Scale status constants */
#define REPORT_FAULT 0x01 #define REPORT_FAULT 0x01
@ -49,7 +49,7 @@ class ScaleReportParser : public HIDReportParser
public: public:
ScaleReportParser(ScaleEvents *evt); 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__ #endif // __SCALERPTPARSER_H__

View file

@ -14,7 +14,7 @@
USB Usb; USB Usb;
USBHub Hub1(&Usb); USBHub Hub1(&Usb);
USBHub Hub2(&Usb); USBHub Hub2(&Usb);
HIDBoot<HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb); HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
ADK adk(&Usb,"Circuits@Home, ltd.", ADK adk(&Usb,"Circuits@Home, ltd.",
"USB Host Shield", "USB Host Shield",

View file

@ -16,7 +16,7 @@ e-mail : support@circuitsathome.com
*/ */
#include "hidboot.h" #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; MOUSEINFO *pmi = (MOUSEINFO*)buf;
// Future: // Future:
// bool event; // bool event;
@ -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 // On error - return
if (buf[2] == 1) if (buf[2] == 1)
return; return;

View file

@ -17,7 +17,7 @@ e-mail : support@circuitsathome.com
#if !defined(__HIDBOOT_H__) #if !defined(__HIDBOOT_H__)
#define __HIDBOOT_H__ #define __HIDBOOT_H__
#include "hid.h" #include "usbhid.h"
#define UHS_HID_BOOT_KEY_ZERO 0x27 #define UHS_HID_BOOT_KEY_ZERO 0x27
#define UHS_HID_BOOT_KEY_ENTER 0x28 #define UHS_HID_BOOT_KEY_ENTER 0x28
@ -29,9 +29,9 @@ e-mail : support@circuitsathome.com
#define UHS_HID_BOOT_KEY_PERIOD 0x63 #define UHS_HID_BOOT_KEY_PERIOD 0x63
// Don't worry, GCC will optimize the result to a final value. // Don't worry, GCC will optimize the result to a final value.
#define bitsEndpoints(p) ((((p) & HID_PROTOCOL_KEYBOARD)? 2 : 0) | (((p) & HID_PROTOCOL_MOUSE)? 1 : 0)) #define bitsEndpoints(p) ((((p) & USB_HID_PROTOCOL_KEYBOARD)? 2 : 0) | (((p) & USB_HID_PROTOCOL_MOUSE)? 1 : 0))
#define totalEndpoints(p) ((bitsEndpoints(p) == 3) ? 3 : 2) #define totalEndpoints(p) ((bitsEndpoints(p) == 3) ? 3 : 2)
#define epMUL(p) ((((p) & HID_PROTOCOL_KEYBOARD)? 1 : 0) + (((p) & HID_PROTOCOL_MOUSE)? 1 : 0)) #define epMUL(p) ((((p) & USB_HID_PROTOCOL_KEYBOARD)? 1 : 0) + (((p) & USB_HID_PROTOCOL_MOUSE)? 1 : 0))
// Already defined in hid.h // Already defined in hid.h
// #define HID_MAX_HID_CLASS_DESCRIPTORS 5 // #define HID_MAX_HID_CLASS_DESCRIPTORS 5
@ -56,7 +56,7 @@ class MouseReportParser : public HIDReportParser {
} prevState; } prevState;
public: public:
void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
protected: protected:
@ -144,11 +144,11 @@ public:
kbdLockingKeys.bLeds = 0; kbdLockingKeys.bLeds = 0;
}; };
void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
protected: protected:
virtual uint8_t HandleLockingKeys(HID* hid, uint8_t key) { virtual uint8_t HandleLockingKeys(USBHID* hid, uint8_t key) {
uint8_t old_keys = kbdLockingKeys.bLeds; uint8_t old_keys = kbdLockingKeys.bLeds;
switch(key) { switch(key) {
@ -198,7 +198,7 @@ protected:
}; };
template <const uint8_t BOOT_PROTOCOL> template <const uint8_t BOOT_PROTOCOL>
class HIDBoot : public HID //public USBDeviceConfig, public UsbConfigXtracter class HIDBoot : public USBHID //public USBDeviceConfig, public UsbConfigXtracter
{ {
EpInfo epInfo[totalEndpoints(BOOT_PROTOCOL)]; EpInfo epInfo[totalEndpoints(BOOT_PROTOCOL)];
HIDReportParser *pRptParser[epMUL(BOOT_PROTOCOL)]; HIDReportParser *pRptParser[epMUL(BOOT_PROTOCOL)];
@ -253,7 +253,7 @@ public:
template <const uint8_t BOOT_PROTOCOL> template <const uint8_t BOOT_PROTOCOL>
HIDBoot<BOOT_PROTOCOL>::HIDBoot(USB *p) : HIDBoot<BOOT_PROTOCOL>::HIDBoot(USB *p) :
HID(p), USBHID(p),
qNextPollTime(0), qNextPollTime(0),
bPollEnable(false) { bPollEnable(false) {
Initialize(); Initialize();
@ -381,12 +381,12 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
USBTRACE2("NC:", num_of_conf); USBTRACE2("NC:", num_of_conf);
// GCC will optimize unused stuff away. // GCC will optimize unused stuff away.
if((BOOT_PROTOCOL & (HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE)) == (HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE)) { if((BOOT_PROTOCOL & (USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE)) == (USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE)) {
USBTRACE("HID_PROTOCOL_KEYBOARD AND MOUSE\r\n"); USBTRACE("HID_PROTOCOL_KEYBOARD AND MOUSE\r\n");
ConfigDescParser< ConfigDescParser<
USB_CLASS_HID, USB_CLASS_HID,
HID_BOOT_INTF_SUBCLASS, HID_BOOT_INTF_SUBCLASS,
HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE, USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE,
CP_MASK_COMPARE_ALL > confDescrParser(this); CP_MASK_COMPARE_ALL > confDescrParser(this);
confDescrParser.SetOR(); // Use the OR variant. confDescrParser.SetOR(); // Use the OR variant.
for(uint8_t i = 0; i < num_of_conf; i++) { for(uint8_t i = 0; i < num_of_conf; i++) {
@ -396,13 +396,13 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
} }
} else { } else {
// GCC will optimize unused stuff away. // GCC will optimize unused stuff away.
if(BOOT_PROTOCOL & HID_PROTOCOL_KEYBOARD) { if(BOOT_PROTOCOL & USB_HID_PROTOCOL_KEYBOARD) {
USBTRACE("HID_PROTOCOL_KEYBOARD\r\n"); USBTRACE("HID_PROTOCOL_KEYBOARD\r\n");
for(uint8_t i = 0; i < num_of_conf; i++) { for(uint8_t i = 0; i < num_of_conf; i++) {
ConfigDescParser< ConfigDescParser<
USB_CLASS_HID, USB_CLASS_HID,
HID_BOOT_INTF_SUBCLASS, HID_BOOT_INTF_SUBCLASS,
HID_PROTOCOL_KEYBOARD, USB_HID_PROTOCOL_KEYBOARD,
CP_MASK_COMPARE_ALL> confDescrParserA(this); CP_MASK_COMPARE_ALL> confDescrParserA(this);
pUsb->getConfDescr(bAddress, 0, i, &confDescrParserA); pUsb->getConfDescr(bAddress, 0, i, &confDescrParserA);
@ -412,13 +412,13 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
} }
// GCC will optimize unused stuff away. // GCC will optimize unused stuff away.
if(BOOT_PROTOCOL & HID_PROTOCOL_MOUSE) { if(BOOT_PROTOCOL & USB_HID_PROTOCOL_MOUSE) {
USBTRACE("HID_PROTOCOL_MOUSE\r\n"); USBTRACE("HID_PROTOCOL_MOUSE\r\n");
for(uint8_t i = 0; i < num_of_conf; i++) { for(uint8_t i = 0; i < num_of_conf; i++) {
ConfigDescParser< ConfigDescParser<
USB_CLASS_HID, USB_CLASS_HID,
HID_BOOT_INTF_SUBCLASS, HID_BOOT_INTF_SUBCLASS,
HID_PROTOCOL_MOUSE, USB_HID_PROTOCOL_MOUSE,
CP_MASK_COMPARE_ALL> confDescrParserB(this); CP_MASK_COMPARE_ALL> confDescrParserB(this);
pUsb->getConfDescr(bAddress, 0, i, &confDescrParserB); pUsb->getConfDescr(bAddress, 0, i, &confDescrParserB);
@ -456,7 +456,7 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
// Yes, mouse wants SetProtocol and SetIdle too! // Yes, mouse wants SetProtocol and SetIdle too!
for(uint8_t i = 0; i < epMUL(BOOT_PROTOCOL); i++) { for(uint8_t i = 0; i < epMUL(BOOT_PROTOCOL); i++) {
USBTRACE2("\r\nInterface:", i); USBTRACE2("\r\nInterface:", i);
rcode = SetProtocol(i, HID_BOOT_PROTOCOL); rcode = SetProtocol(i, USB_HID_BOOT_PROTOCOL);
if(rcode) goto FailSetProtocol; if(rcode) goto FailSetProtocol;
USBTRACE2("PROTOCOL SET HID_BOOT rcode:", rcode); USBTRACE2("PROTOCOL SET HID_BOOT rcode:", rcode);
rcode = SetIdle(i, 0, 0); rcode = SetIdle(i, 0, 0);
@ -470,7 +470,7 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
// Get RPIPE and throw it away. // Get RPIPE and throw it away.
if(BOOT_PROTOCOL & HID_PROTOCOL_KEYBOARD) { if(BOOT_PROTOCOL & USB_HID_PROTOCOL_KEYBOARD) {
// Wake keyboard interface by twinkling up to 5 LEDs that are in the spec. // Wake keyboard interface by twinkling up to 5 LEDs that are in the spec.
// kana, compose, scroll, caps, num // kana, compose, scroll, caps, num
rcode = 0x20; // Reuse rcode. rcode = 0x20; // Reuse rcode.
@ -590,7 +590,7 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Poll() {
// Since keyboard and mice must report at least 3 bytes, we ignore the extra data. // Since keyboard and mice must report at least 3 bytes, we ignore the extra data.
if(!rcode && read > 2) { if(!rcode && read > 2) {
if(pRptParser[i]) if(pRptParser[i])
pRptParser[i]->Parse((HID*)this, 0, (uint8_t)read, buf); pRptParser[i]->Parse((USBHID*)this, 0, (uint8_t)read, buf);
#ifdef DEBUG_USB_HOST #ifdef DEBUG_USB_HOST
// We really don't care about errors and anomalies unless we are debugging. // We really don't care about errors and anomalies unless we are debugging.
} else { } else {

View file

@ -1578,7 +1578,7 @@ void ReportDescParser2::OnInputItem(uint8_t itm) {
E_Notify(PSTR("\r\n"), 0x80); E_Notify(PSTR("\r\n"), 0x80);
} }
void UniversalReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { void UniversalReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
ReportDescParser2 prs(len, buf); ReportDescParser2 prs(len, buf);
uint8_t ret = hid->GetReportDescr(0, &prs); uint8_t ret = hid->GetReportDescr(0, &prs);

View file

@ -17,7 +17,7 @@ e-mail : support@circuitsathome.com
#if !defined(__HIDDESCRIPTORPARSER_H__) #if !defined(__HIDDESCRIPTORPARSER_H__)
#define __HIDDESCRIPTORPARSER_H__ #define __HIDDESCRIPTORPARSER_H__
#include "hid.h" #include "usbhid.h"
class ReportDescParserBase : public USBReadParser { class ReportDescParserBase : public USBReadParser {
public: public:
@ -170,7 +170,7 @@ public:
class UniversalReportParser : public HIDReportParser { class UniversalReportParser : public HIDReportParser {
public: public:
// Method should be defined here if virtual. // Method should be defined here if virtual.
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 // __HIDDESCRIPTORPARSER_H__ #endif // __HIDDESCRIPTORPARSER_H__

View file

@ -18,7 +18,7 @@ e-mail : support@circuitsathome.com
#include "hiduniversal.h" #include "hiduniversal.h"
HIDUniversal::HIDUniversal(USB *p) : HIDUniversal::HIDUniversal(USB *p) :
HID(p), USBHID(p),
qNextPollTime(0), qNextPollTime(0),
pollInterval(0), pollInterval(0),
bPollEnable(false), bPollEnable(false),

View file

@ -18,10 +18,10 @@ e-mail : support@circuitsathome.com
#if !defined(__HIDUNIVERSAL_H__) #if !defined(__HIDUNIVERSAL_H__)
#define __HIDUNIVERSAL_H__ #define __HIDUNIVERSAL_H__
#include "hid.h" #include "usbhid.h"
//#include "hidescriptorparser.h" //#include "hidescriptorparser.h"
class HIDUniversal : public HID { class HIDUniversal : public USBHID {
struct ReportParser { struct ReportParser {
uint8_t rptId; uint8_t rptId;
@ -75,7 +75,7 @@ protected:
return 0; return 0;
}; };
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) {
return; return;
}; };

View file

@ -15,12 +15,12 @@ Web : http://www.circuitsathome.com
e-mail : support@circuitsathome.com e-mail : support@circuitsathome.com
*/ */
#include "hid.h" #include "usbhid.h"
//get HID report descriptor //get HID report descriptor
/* WRONG! Endpoint is _ALWAYS_ ZERO for HID! We want the _INTERFACE_ value here! /* WRONG! Endpoint is _ALWAYS_ ZERO for HID! We want the _INTERFACE_ value here!
uint8_t HID::GetReportDescr(uint8_t ep, USBReadParser *parser) { uint8_t USBHID::GetReportDescr(uint8_t ep, USBReadParser *parser) {
const uint8_t constBufLen = 64; const uint8_t constBufLen = 64;
uint8_t buf[constBufLen]; uint8_t buf[constBufLen];
@ -31,7 +31,7 @@ uint8_t HID::GetReportDescr(uint8_t ep, USBReadParser *parser) {
return rcode; return rcode;
} }
*/ */
uint8_t HID::GetReportDescr(uint16_t wIndex, USBReadParser *parser) { uint8_t USBHID::GetReportDescr(uint16_t wIndex, USBReadParser *parser) {
const uint8_t constBufLen = 64; const uint8_t constBufLen = 64;
uint8_t buf[constBufLen]; uint8_t buf[constBufLen];
@ -42,36 +42,36 @@ uint8_t HID::GetReportDescr(uint16_t wIndex, USBReadParser *parser) {
return rcode; return rcode;
} }
//uint8_t HID::getHidDescr( uint8_t ep, uint16_t nbytes, uint8_t* dataptr ) //uint8_t USBHID::getHidDescr( uint8_t ep, uint16_t nbytes, uint8_t* dataptr )
//{ //{
// return( pUsb->ctrlReq( bAddress, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, HID_DESCRIPTOR_HID, 0x0000, nbytes, dataptr )); // return( pUsb->ctrlReq( bAddress, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, HID_DESCRIPTOR_HID, 0x0000, nbytes, dataptr ));
//} //}
uint8_t HID::SetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr) { uint8_t USBHID::SetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr) {
return ( pUsb->ctrlReq(bAddress, ep, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL)); return ( pUsb->ctrlReq(bAddress, ep, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL));
} }
uint8_t HID::GetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr) { uint8_t USBHID::GetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr) {
return ( pUsb->ctrlReq(bAddress, ep, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL)); return ( pUsb->ctrlReq(bAddress, ep, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL));
} }
uint8_t HID::GetIdle(uint8_t iface, uint8_t reportID, uint8_t* dataptr) { uint8_t USBHID::GetIdle(uint8_t iface, uint8_t reportID, uint8_t* dataptr) {
return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_IN, HID_REQUEST_GET_IDLE, reportID, 0, iface, 0x0001, 0x0001, dataptr, NULL)); return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_IN, HID_REQUEST_GET_IDLE, reportID, 0, iface, 0x0001, 0x0001, dataptr, NULL));
} }
uint8_t HID::SetIdle(uint8_t iface, uint8_t reportID, uint8_t duration) { uint8_t USBHID::SetIdle(uint8_t iface, uint8_t reportID, uint8_t duration) {
return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_OUT, HID_REQUEST_SET_IDLE, reportID, duration, iface, 0x0000, 0x0000, NULL, NULL)); return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_OUT, HID_REQUEST_SET_IDLE, reportID, duration, iface, 0x0000, 0x0000, NULL, NULL));
} }
uint8_t HID::SetProtocol(uint8_t iface, uint8_t protocol) { uint8_t USBHID::SetProtocol(uint8_t iface, uint8_t protocol) {
return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_OUT, HID_REQUEST_SET_PROTOCOL, protocol, 0x00, iface, 0x0000, 0x0000, NULL, NULL)); return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_OUT, HID_REQUEST_SET_PROTOCOL, protocol, 0x00, iface, 0x0000, 0x0000, NULL, NULL));
} }
uint8_t HID::GetProtocol(uint8_t iface, uint8_t* dataptr) { uint8_t USBHID::GetProtocol(uint8_t iface, uint8_t* dataptr) {
return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_IN, HID_REQUEST_GET_PROTOCOL, 0x00, 0x00, iface, 0x0001, 0x0001, dataptr, NULL)); return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_IN, HID_REQUEST_GET_PROTOCOL, 0x00, 0x00, iface, 0x0001, 0x0001, dataptr, NULL));
} }
void HID::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) { void USBHID::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) {
Notify(PSTR("Endpoint descriptor:"), 0x80); Notify(PSTR("Endpoint descriptor:"), 0x80);
Notify(PSTR("\r\nLength:\t\t"), 0x80); Notify(PSTR("\r\nLength:\t\t"), 0x80);
D_PrintHex<uint8_t > (ep_ptr->bLength, 0x80); D_PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
@ -87,7 +87,7 @@ void HID::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) {
D_PrintHex<uint8_t > (ep_ptr->bInterval, 0x80); D_PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
} }
void HID::PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc) { void USBHID::PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc) {
Notify(PSTR("\r\n\r\nHID Descriptor:\r\n"), 0x80); Notify(PSTR("\r\n\r\nHID Descriptor:\r\n"), 0x80);
Notify(PSTR("bDescLength:\t\t"), 0x80); Notify(PSTR("bDescLength:\t\t"), 0x80);
D_PrintHex<uint8_t > (pDesc->bLength, 0x80); D_PrintHex<uint8_t > (pDesc->bLength, 0x80);

View file

@ -14,8 +14,8 @@ Circuits At Home, LTD
Web : http://www.circuitsathome.com Web : http://www.circuitsathome.com
e-mail : support@circuitsathome.com e-mail : support@circuitsathome.com
*/ */
#if !defined(__HID_H__) #if !defined(__USBHID_H__)
#define __HID_H__ #define __USBHID_H__
#include "Usb.h" #include "Usb.h"
#include "hidusagestr.h" #include "hidusagestr.h"
@ -79,7 +79,7 @@ e-mail : support@circuitsathome.com
#define HID_DESRIPTOR_PHY 0x23 #define HID_DESRIPTOR_PHY 0x23
/* Protocol Selection */ /* Protocol Selection */
#define HID_BOOT_PROTOCOL 0x00 #define USB_HID_BOOT_PROTOCOL 0x00
#define HID_RPT_PROTOCOL 0x01 #define HID_RPT_PROTOCOL 0x01
/* HID Interface Class Code */ /* HID Interface Class Code */
@ -89,9 +89,9 @@ e-mail : support@circuitsathome.com
#define HID_BOOT_INTF_SUBCLASS 0x01 #define HID_BOOT_INTF_SUBCLASS 0x01
/* HID Interface Class Protocol Codes */ /* HID Interface Class Protocol Codes */
#define HID_PROTOCOL_NONE 0x00 #define USB_HID_PROTOCOL_NONE 0x00
#define HID_PROTOCOL_KEYBOARD 0x01 #define USB_HID_PROTOCOL_KEYBOARD 0x01
#define HID_PROTOCOL_MOUSE 0x02 #define USB_HID_PROTOCOL_MOUSE 0x02
#define HID_ITEM_TYPE_MAIN 0 #define HID_ITEM_TYPE_MAIN 0
#define HID_ITEM_TYPE_GLOBAL 1 #define HID_ITEM_TYPE_GLOBAL 1
@ -133,14 +133,14 @@ struct MainItemIOFeature {
uint8_t bmIsVolatileOrNonVolatile : 1; uint8_t bmIsVolatileOrNonVolatile : 1;
}; };
class HID; class USBHID;
class HIDReportParser { class HIDReportParser {
public: public:
virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) = 0; virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) = 0;
}; };
class HID : public USBDeviceConfig, public UsbConfigXtracter { class USBHID : public USBDeviceConfig, public UsbConfigXtracter {
protected: protected:
USB *pUsb; // USB class instance pointer USB *pUsb; // USB class instance pointer
uint8_t bAddress; // address uint8_t bAddress; // address
@ -162,7 +162,7 @@ protected:
public: public:
HID(USB *pusb) : pUsb(pusb) { USBHID(USB *pusb) : pUsb(pusb) {
}; };
const USB* GetUsb() { const USB* GetUsb() {
@ -185,4 +185,4 @@ public:
uint8_t SetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr); uint8_t SetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr);
}; };
#endif // __HID_H__ #endif // __USBHID_H__