@@ -39,9 +39,9 @@ int HID_::getInterface(uint8_t* interfaceCount)
39
39
return USB_SendControl (0 , &hidInterface, sizeof (hidInterface));
40
40
}
41
41
42
- // Since this function is not exposed in USBCore API, had to replicate here.
42
+ // Since this function is not exposed in USBCore API, had to replicate here.
43
43
static bool USB_SendStringDescriptor (const char * string_P, u8 string_len, uint8_t flags) {
44
-
44
+
45
45
u8 c[2 ] = {(u8 )(2 + string_len * 2 ), 3 };
46
46
47
47
USB_SendControl (0 ,&c,2 );
@@ -60,12 +60,12 @@ static bool USB_SendStringDescriptor(const char* string_P, u8 string_len, uint8_
60
60
61
61
int HID_::getDescriptor (USBSetup& setup)
62
62
{
63
-
63
+
64
64
u8 t = setup.wValueH ;
65
-
65
+
66
66
// HID-specific strings
67
67
if (USB_STRING_DESCRIPTOR_TYPE == t) {
68
-
68
+
69
69
// we place all strings in the 0xFF00-0xFFFE range
70
70
HIDReport* rep = GetFeature (0xFF00 | setup.wValueL );
71
71
if (rep) {
@@ -75,7 +75,7 @@ int HID_::getDescriptor(USBSetup& setup)
75
75
return 0 ;
76
76
}
77
77
}
78
-
78
+
79
79
// Check if this is a HID Class Descriptor request
80
80
if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0 ; }
81
81
if (HID_REPORT_DESCRIPTOR_TYPE != t) { return 0 ; }
@@ -91,11 +91,11 @@ int HID_::getDescriptor(USBSetup& setup)
91
91
return -1 ;
92
92
total += res;
93
93
}
94
-
94
+
95
95
// Reset the protocol on reenumeration. Normally the host should not assume the state of the protocol
96
96
// due to the USB specs, but Windows and Linux just assumes its in report mode.
97
97
protocol = HID_REPORT_PROTOCOL;
98
-
98
+
99
99
return total;
100
100
}
101
101
@@ -108,9 +108,9 @@ uint8_t HID_::getShortName(char *name)
108
108
return strlen_P (serial);
109
109
}
110
110
else {
111
-
111
+
112
112
// default serial number
113
-
113
+
114
114
name[0 ] = ' H' ;
115
115
name[1 ] = ' I' ;
116
116
name[2 ] = ' D' ;
@@ -153,7 +153,7 @@ int HID_::SetFeature(uint16_t id, const void* data, int len)
153
153
}
154
154
155
155
}
156
-
156
+
157
157
reportCount++;
158
158
return reportCount;
159
159
}
@@ -194,31 +194,31 @@ HIDReport* HID_::GetFeature(uint16_t id)
194
194
}
195
195
196
196
bool HID_::setup (USBSetup& setup)
197
- {
197
+ {
198
198
if (pluggedInterface != setup.wIndex ) {
199
199
return false ;
200
200
}
201
201
202
202
uint8_t request = setup.bRequest ;
203
203
uint8_t requestType = setup.bmRequestType ;
204
-
204
+
205
205
if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE)
206
- {
206
+ {
207
207
if (request == HID_GET_REPORT) {
208
208
209
209
if (setup.wValueH == HID_REPORT_TYPE_FEATURE)
210
210
{
211
211
212
212
HIDReport* current = GetFeature (setup.wValueL );
213
- if (current){
213
+ if (current){
214
214
if (USB_SendControl (0 , &(current->id ), 1 )>0 &&
215
215
USB_SendControl (0 , current->data , current->length )>0 )
216
216
return true ;
217
217
}
218
218
219
219
return false ;
220
-
221
- }
220
+
221
+ }
222
222
return true ;
223
223
}
224
224
if (request == HID_GET_PROTOCOL) {
@@ -231,7 +231,7 @@ bool HID_::setup(USBSetup& setup)
231
231
}
232
232
233
233
if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE)
234
- {
234
+ {
235
235
if (request == HID_SET_PROTOCOL) {
236
236
// The USB Host tells us if we are in boot or report mode.
237
237
// This only works with a real boot compatible device.
@@ -248,15 +248,15 @@ bool HID_::setup(USBSetup& setup)
248
248
{
249
249
250
250
HIDReport* current = GetFeature (setup.wValueL );
251
- if (!current) return false ;
252
- if (setup.wLength != current->length + 1 ) return false ;
253
- uint8_t * data = new uint8_t [setup.wLength ];
254
- USB_RecvControl (data, setup.wLength );
255
- if (*data != current->id ) return false ;
256
- memcpy ((uint8_t *)current->data , data+1 , current->length );
257
- delete[] data;
251
+ if (!current) return false ;
252
+ if (setup.wLength != current->length + 1 ) return false ;
253
+ uint8_t * data = new uint8_t [setup.wLength ];
254
+ USB_RecvControl (data, setup.wLength );
255
+ if (*data != current->id ) return false ;
256
+ memcpy ((uint8_t *)current->data , data+1 , current->length );
257
+ delete[] data;
258
258
return true ;
259
-
259
+
260
260
}
261
261
262
262
}
0 commit comments