Skip to content

Commit 2ac2a27

Browse files
committed
[PUSB] Moved static members inside HID_ class
This commit prepares for the next refactoring
1 parent 6ffd7e3 commit 2ac2a27

File tree

2 files changed

+54
-41
lines changed

2 files changed

+54
-41
lines changed

hardware/arduino/avr/libraries/HID/HID.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,33 @@ HID_ HID;
2727
//================================================================================
2828
// HID Interface
2929

30-
HIDDescriptor _hidInterface;
30+
HIDDescriptor HID_::hidInterface;
3131

32-
static HIDDescriptorListNode* rootNode = NULL;
33-
static uint16_t sizeof_hidReportDescriptor = 0;
34-
static uint8_t modules_count = 0;
35-
static uint8_t epType[] = { EP_TYPE_INTERRUPT_IN };
32+
HIDDescriptorListNode* HID_::rootNode = NULL;
33+
uint16_t HID_::sizeof_hidReportDescriptor = 0;
34+
uint8_t HID_::modules_count = 0;
35+
uint8_t HID_::epType[] = { EP_TYPE_INTERRUPT_IN };
3636

3737
//================================================================================
3838
//================================================================================
3939
// Driver
4040

41-
uint8_t _hid_protocol = 1;
42-
uint8_t _hid_idle = 1;
41+
uint8_t HID_::protocol = 1;
42+
uint8_t HID_::idle = 1;
4343

44-
int HID_GetInterface(uint8_t* interfaceNum)
44+
int HID_::GetInterface(uint8_t* interfaceNum)
4545
{
4646
interfaceNum[0] += 1; // uses 1
47-
_hidInterface =
47+
hidInterface =
4848
{
4949
D_INTERFACE(HID.interface(), 1, 3, 0, 0),
5050
D_HIDREPORT(sizeof_hidReportDescriptor),
5151
D_ENDPOINT(USB_ENDPOINT_IN(HID.endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01)
5252
};
53-
return USB_SendControl(0,&_hidInterface,sizeof(_hidInterface));
53+
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
5454
}
5555

56-
int HID_GetDescriptor(int8_t t)
56+
int HID_::GetDescriptor(int8_t t)
5757
{
5858
if (HID_REPORT_DESCRIPTOR_TYPE == t) {
5959
HIDDescriptorListNode* current = rootNode;
@@ -89,7 +89,7 @@ void HID_::SendReport(uint8_t id, const void* data, int len)
8989
USB_Send(HID.endpoint() | TRANSFER_RELEASE,data,len);
9090
}
9191

92-
bool HID_Setup(USBSetup& setup, uint8_t i)
92+
bool HID_::Setup(USBSetup& setup, uint8_t i)
9393
{
9494
if (HID.interface() != i) {
9595
return false;
@@ -100,12 +100,12 @@ bool HID_Setup(USBSetup& setup, uint8_t i)
100100
{
101101
if (HID_GET_REPORT == r)
102102
{
103-
//HID_GetReport();
103+
//HID_GetReport();
104104
return true;
105105
}
106106
if (HID_GET_PROTOCOL == r)
107107
{
108-
//Send8(_hid_protocol); // TODO
108+
//Send8(protocol); // TODO
109109
return true;
110110
}
111111
}
@@ -114,13 +114,13 @@ bool HID_Setup(USBSetup& setup, uint8_t i)
114114
{
115115
if (HID_SET_PROTOCOL == r)
116116
{
117-
_hid_protocol = setup.wValueL;
117+
protocol = setup.wValueL;
118118
return true;
119119
}
120120

121121
if (HID_SET_IDLE == r)
122122
{
123-
_hid_idle = setup.wValueL;
123+
idle = setup.wValueL;
124124
return true;
125125
}
126126
}
@@ -130,9 +130,9 @@ bool HID_Setup(USBSetup& setup, uint8_t i)
130130

131131
HID_::HID_(void)
132132
{
133-
setup = &HID_Setup;
134-
getInterface = &HID_GetInterface;
135-
getDescriptor = &HID_GetDescriptor;
133+
setup = HID_::Setup;
134+
getInterface = HID_::GetInterface;
135+
getDescriptor = HID_::GetDescriptor;
136136
numEndpoints = 1;
137137
numInterfaces = 1;
138138
endpointType = epType;

hardware/arduino/avr/libraries/HID/HID.h

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@
3030

3131
#define _USING_HID
3232

33-
//================================================================================
34-
//================================================================================
35-
// HID 'Driver'
36-
33+
// HID 'Driver'
34+
// ------------
3735
#define HID_GET_REPORT 0x01
3836
#define HID_GET_IDLE 0x02
3937
#define HID_GET_PROTOCOL 0x03
@@ -45,24 +43,6 @@
4543
#define HID_REPORT_DESCRIPTOR_TYPE 0x22
4644
#define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23
4745

48-
class HIDDescriptorListNode {
49-
public:
50-
HIDDescriptorListNode *next = NULL;
51-
HIDDescriptorListNode(const void *d, const uint16_t l) : data(d), length(l) { }
52-
53-
const void* data;
54-
uint16_t length;
55-
};
56-
57-
class HID_ : public PUSBListNode
58-
{
59-
public:
60-
HID_(void);
61-
int begin(void);
62-
void SendReport(uint8_t id, const void* data, int len);
63-
void AppendDescriptor(HIDDescriptorListNode* node);
64-
};
65-
6646
typedef struct
6747
{
6848
uint8_t len; // 9
@@ -83,6 +63,39 @@ typedef struct
8363
EndpointDescriptor in;
8464
} HIDDescriptor;
8565

66+
class HIDDescriptorListNode {
67+
public:
68+
HIDDescriptorListNode *next = NULL;
69+
HIDDescriptorListNode(const void *d, const uint16_t l) : data(d), length(l) { }
70+
71+
const void* data;
72+
uint16_t length;
73+
};
74+
75+
class HID_ : public PUSBListNode
76+
{
77+
public:
78+
HID_(void);
79+
int begin(void);
80+
void SendReport(uint8_t id, const void* data, int len);
81+
void AppendDescriptor(HIDDescriptorListNode* node);
82+
83+
private:
84+
static int GetInterface(uint8_t* interfaceNum);
85+
static int GetDescriptor(int8_t t);
86+
static bool Setup(USBSetup& setup, uint8_t i);
87+
88+
static HIDDescriptor hidInterface;
89+
90+
static HIDDescriptorListNode* rootNode;
91+
static uint16_t sizeof_hidReportDescriptor;
92+
static uint8_t modules_count;
93+
static uint8_t epType[];
94+
95+
static uint8_t protocol;
96+
static uint8_t idle;
97+
};
98+
8699
#define D_HIDREPORT(_descriptorLength) \
87100
{ 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength & 0xFF, _descriptorLength >> 8 }
88101

0 commit comments

Comments
 (0)