aboutsummaryrefslogtreecommitdiff
path: root/libraries/HID
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/HID')
-rw-r--r--libraries/HID/HID.cpp38
-rw-r--r--libraries/HID/HID.h57
2 files changed, 54 insertions, 41 deletions
diff --git a/libraries/HID/HID.cpp b/libraries/HID/HID.cpp
index e36601f..118d0c5 100644
--- a/libraries/HID/HID.cpp
+++ b/libraries/HID/HID.cpp
@@ -27,33 +27,33 @@ HID_ HID;
//================================================================================
// HID Interface
-HIDDescriptor _hidInterface;
+HIDDescriptor HID_::hidInterface;
-static HIDDescriptorListNode* rootNode = NULL;
-static uint16_t sizeof_hidReportDescriptor = 0;
-static uint8_t modules_count = 0;
-static uint8_t epType[] = { EP_TYPE_INTERRUPT_IN };
+HIDDescriptorListNode* HID_::rootNode = NULL;
+uint16_t HID_::sizeof_hidReportDescriptor = 0;
+uint8_t HID_::modules_count = 0;
+uint8_t HID_::epType[] = { EP_TYPE_INTERRUPT_IN };
//================================================================================
//================================================================================
// Driver
-uint8_t _hid_protocol = 1;
-uint8_t _hid_idle = 1;
+uint8_t HID_::protocol = 1;
+uint8_t HID_::idle = 1;
-int HID_GetInterface(uint8_t* interfaceNum)
+int HID_::GetInterface(uint8_t* interfaceNum)
{
interfaceNum[0] += 1; // uses 1
- _hidInterface =
+ hidInterface =
{
D_INTERFACE(HID.interface(), 1, 3, 0, 0),
D_HIDREPORT(sizeof_hidReportDescriptor),
D_ENDPOINT(USB_ENDPOINT_IN(HID.endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01)
};
- return USB_SendControl(0,&_hidInterface,sizeof(_hidInterface));
+ return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
}
-int HID_GetDescriptor(int8_t t)
+int HID_::GetDescriptor(int8_t t)
{
if (HID_REPORT_DESCRIPTOR_TYPE == t) {
HIDDescriptorListNode* current = rootNode;
@@ -89,7 +89,7 @@ void HID_::SendReport(uint8_t id, const void* data, int len)
USB_Send(HID.endpoint() | TRANSFER_RELEASE,data,len);
}
-bool HID_Setup(USBSetup& setup, uint8_t i)
+bool HID_::Setup(USBSetup& setup, uint8_t i)
{
if (HID.interface() != i) {
return false;
@@ -100,12 +100,12 @@ bool HID_Setup(USBSetup& setup, uint8_t i)
{
if (HID_GET_REPORT == r)
{
- //HID_GetReport();
+ //HID_GetReport();
return true;
}
if (HID_GET_PROTOCOL == r)
{
- //Send8(_hid_protocol); // TODO
+ //Send8(protocol); // TODO
return true;
}
}
@@ -114,13 +114,13 @@ bool HID_Setup(USBSetup& setup, uint8_t i)
{
if (HID_SET_PROTOCOL == r)
{
- _hid_protocol = setup.wValueL;
+ protocol = setup.wValueL;
return true;
}
if (HID_SET_IDLE == r)
{
- _hid_idle = setup.wValueL;
+ idle = setup.wValueL;
return true;
}
}
@@ -130,9 +130,9 @@ bool HID_Setup(USBSetup& setup, uint8_t i)
HID_::HID_(void)
{
- setup = &HID_Setup;
- getInterface = &HID_GetInterface;
- getDescriptor = &HID_GetDescriptor;
+ setup = HID_::Setup;
+ getInterface = HID_::GetInterface;
+ getDescriptor = HID_::GetDescriptor;
numEndpoints = 1;
numInterfaces = 1;
endpointType = epType;
diff --git a/libraries/HID/HID.h b/libraries/HID/HID.h
index d0fe265..cb1125e 100644
--- a/libraries/HID/HID.h
+++ b/libraries/HID/HID.h
@@ -30,10 +30,8 @@
#define _USING_HID
-//================================================================================
-//================================================================================
-// HID 'Driver'
-
+// HID 'Driver'
+// ------------
#define HID_GET_REPORT 0x01
#define HID_GET_IDLE 0x02
#define HID_GET_PROTOCOL 0x03
@@ -45,24 +43,6 @@
#define HID_REPORT_DESCRIPTOR_TYPE 0x22
#define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23
-class HIDDescriptorListNode {
-public:
- HIDDescriptorListNode *next = NULL;
- HIDDescriptorListNode(const void *d, const uint16_t l) : data(d), length(l) { }
-
- const void* data;
- uint16_t length;
-};
-
-class HID_ : public PUSBListNode
-{
-public:
- HID_(void);
- int begin(void);
- void SendReport(uint8_t id, const void* data, int len);
- void AppendDescriptor(HIDDescriptorListNode* node);
-};
-
typedef struct
{
uint8_t len; // 9
@@ -83,6 +63,39 @@ typedef struct
EndpointDescriptor in;
} HIDDescriptor;
+class HIDDescriptorListNode {
+public:
+ HIDDescriptorListNode *next = NULL;
+ HIDDescriptorListNode(const void *d, const uint16_t l) : data(d), length(l) { }
+
+ const void* data;
+ uint16_t length;
+};
+
+class HID_ : public PUSBListNode
+{
+public:
+ HID_(void);
+ int begin(void);
+ void SendReport(uint8_t id, const void* data, int len);
+ void AppendDescriptor(HIDDescriptorListNode* node);
+
+private:
+ static int GetInterface(uint8_t* interfaceNum);
+ static int GetDescriptor(int8_t t);
+ static bool Setup(USBSetup& setup, uint8_t i);
+
+ static HIDDescriptor hidInterface;
+
+ static HIDDescriptorListNode* rootNode;
+ static uint16_t sizeof_hidReportDescriptor;
+ static uint8_t modules_count;
+ static uint8_t epType[];
+
+ static uint8_t protocol;
+ static uint8_t idle;
+};
+
#define D_HIDREPORT(_descriptorLength) \
{ 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength & 0xFF, _descriptorLength >> 8 }