@@ -34,47 +34,44 @@ int HID_::getInterface(uint8_t* interfaceCount)
34
34
D_INTERFACE (pluggedInterface, 2 , USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE),
35
35
D_HIDREPORT (descriptorSize),
36
36
D_ENDPOINT (USB_ENDPOINT_IN (HID_TX), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x14 ),
37
- D_ENDPOINT (USB_ENDPOINT_OUT (HID_RX), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x0A )
37
+ D_ENDPOINT (USB_ENDPOINT_OUT (HID_RX), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x0A )
38
38
};
39
39
return USB_SendControl (0 , &hidInterface, sizeof (hidInterface));
40
40
}
41
41
42
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
+ u8 c[2 ] = {(u8 )(2 + string_len * 2 ), 3 };
44
45
45
- u8 c[ 2 ] = {( u8 )( 2 + string_len * 2 ), 3 } ;
46
+ USB_SendControl ( 0 ,&c, 2 ) ;
46
47
47
- USB_SendControl (0 ,&c,2 );
48
-
49
- bool pgm = flags & TRANSFER_PGM;
50
- for (u8 i = 0 ; i < string_len; i++) {
51
- c[0 ] = pgm ? pgm_read_byte (&string_P[i]) : string_P[i];
52
- c[1 ] = 0 ;
53
- int r = USB_SendControl (0 ,&c,2 );
54
- if (!r) {
55
- return false ;
56
- }
57
- }
58
- return true ;
48
+ bool pgm = flags & TRANSFER_PGM;
49
+ for (u8 i = 0 ; i < string_len; i++) {
50
+ c[0 ] = pgm ? pgm_read_byte (&string_P[i]) : string_P[i];
51
+ c[1 ] = 0 ;
52
+ int r = USB_SendControl (0 ,&c,2 );
53
+ if (!r) {
54
+ return false ;
55
+ }
56
+ }
57
+ return true ;
59
58
}
60
59
61
60
int HID_::getDescriptor (USBSetup& setup)
62
61
{
63
-
64
- u8 t = setup.wValueH ;
65
-
66
- // HID-specific strings
67
- if (USB_STRING_DESCRIPTOR_TYPE == t) {
68
-
69
- // we place all strings in the 0xFF00-0xFFFE range
70
- HIDReport* rep = GetFeature (0xFF00 | setup.wValueL );
71
- if (rep) {
72
- return USB_SendStringDescriptor ((char *)rep->data , strlen_P ((char *)rep->data ), TRANSFER_PGM);
73
- }
74
- else {
75
- return 0 ;
76
- }
62
+ u8 t = setup.wValueH ;
63
+
64
+ // HID-specific strings
65
+ if (USB_STRING_DESCRIPTOR_TYPE == t) {
66
+ // we place all strings in the 0xFF00-0xFFFE range
67
+ HIDReport* rep = GetFeature (0xFF00 | setup.wValueL );
68
+ if (rep) {
69
+ return USB_SendStringDescriptor ((char *)rep->data , strlen_P ((char *)rep->data ), TRANSFER_PGM);
77
70
}
71
+ else {
72
+ return 0 ;
73
+ }
74
+ }
78
75
79
76
// Check if this is a HID Class Descriptor request
80
77
if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0 ; }
@@ -108,15 +105,13 @@ uint8_t HID_::getShortName(char *name)
108
105
return strlen_P (serial);
109
106
}
110
107
else {
111
-
112
108
// default serial number
113
-
114
- name[0 ] = ' H' ;
115
- name[1 ] = ' I' ;
116
- name[2 ] = ' D' ;
117
- name[3 ] = ' A' + (descriptorSize & 0x0F );
118
- name[4 ] = ' A' + ((descriptorSize >> 4 ) & 0x0F );
119
- return 5 ;
109
+ name[0 ] = ' H' ;
110
+ name[1 ] = ' I' ;
111
+ name[2 ] = ' D' ;
112
+ name[3 ] = ' A' + (descriptorSize & 0x0F );
113
+ name[4 ] = ' A' + ((descriptorSize >> 4 ) & 0x0F );
114
+ return 5 ;
120
115
}
121
116
}
122
117
@@ -151,7 +146,6 @@ int HID_::SetFeature(uint16_t id, const void* data, int len)
151
146
break ;
152
147
}
153
148
}
154
-
155
149
}
156
150
157
151
reportCount++;
@@ -205,20 +199,17 @@ bool HID_::setup(USBSetup& setup)
205
199
if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE)
206
200
{
207
201
if (request == HID_GET_REPORT) {
202
+ if (setup.wValueH == HID_REPORT_TYPE_FEATURE)
203
+ {
204
+ HIDReport* current = GetFeature (setup.wValueL );
205
+ if (current){
206
+ if (USB_SendControl (0 , &(current->id ), 1 )>0 &&
207
+ USB_SendControl (0 , current->data , current->length )>0 )
208
+ return true ;
209
+ }
208
210
209
- if (setup.wValueH == HID_REPORT_TYPE_FEATURE)
210
- {
211
-
212
- HIDReport* current = GetFeature (setup.wValueL );
213
- if (current){
214
- if (USB_SendControl (0 , &(current->id ), 1 )>0 &&
215
- USB_SendControl (0 , current->data , current->length )>0 )
216
- return true ;
217
- }
218
-
219
- return false ;
220
-
221
- }
211
+ return false ;
212
+ }
222
213
return true ;
223
214
}
224
215
if (request == HID_GET_PROTOCOL) {
@@ -244,21 +235,19 @@ bool HID_::setup(USBSetup& setup)
244
235
}
245
236
if (request == HID_SET_REPORT)
246
237
{
247
- if (setup.wValueH == HID_REPORT_TYPE_FEATURE)
248
- {
249
-
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;
258
- return true ;
259
-
260
- }
261
-
238
+ if (setup.wValueH == HID_REPORT_TYPE_FEATURE)
239
+ {
240
+
241
+ HIDReport* current = GetFeature (setup.wValueL );
242
+ if (!current) return false ;
243
+ if (setup.wLength != current->length + 1 ) return false ;
244
+ uint8_t * data = new uint8_t [setup.wLength ];
245
+ USB_RecvControl (data, setup.wLength );
246
+ if (*data != current->id ) return false ;
247
+ memcpy ((uint8_t *)current->data , data+1 , current->length );
248
+ delete[] data;
249
+ return true ;
250
+ }
262
251
}
263
252
}
264
253
0 commit comments