88
99extern uint8 CODE usbConfigurationDescriptor [];
1010
11- void usbStandardDeviceRequestHandler ();
11+ static void usbStandardDeviceRequestHandler ();
1212
1313#define CONTROL_TRANSFER_STATE_NONE 0
1414#define CONTROL_TRANSFER_STATE_WRITE 1
@@ -223,6 +223,12 @@ void usbPoll()
223223
224224 USBINDEX = 0 ; // Select EP0 again because the functions above might have changed USBINDEX.
225225
226+ // Modify the count so that we don't send more data than the host requested.
227+ if (controlTransferBytesLeft > usbSetupPacket .wLength )
228+ {
229+ controlTransferBytesLeft = usbSetupPacket .wLength ;
230+ }
231+
226232 // Prepare for the first transaction after the SETUP packet.
227233 if (controlTransferState == CONTROL_TRANSFER_STATE_NONE )
228234 {
@@ -336,7 +342,11 @@ static void usbStandardDeviceRequestHandler()
336342 {
337343 if ((usbSetupPacket .wValue & 0xFF ) >= usbStringDescriptorCount )
338344 {
339- // Invalid string index.
345+ // This is either an invalid string index or it is 0xEE,
346+ // which is defined by Microsoft OS Descriptors 1.0.
347+ // This library provides no features for handling such requests,
348+ // but we call the user's callback in case they want to.
349+ usbCallbackClassDescriptorHandler ();
340350 return ;
341351 }
342352
@@ -358,14 +368,6 @@ static void usbStandardDeviceRequestHandler()
358368 }
359369 }
360370
361- // Modify the count so that we don't send more data than the host requested.
362- // We MUST use the local variable wLength instead of usbSetupPacket.wLength because
363- // USB_SETUP_PACKET may have been over-written by the serial number handler.
364- if (controlTransferBytesLeft > usbSetupPacket .wLength )
365- {
366- controlTransferBytesLeft = usbSetupPacket .wLength ;
367- }
368-
369371 controlTransferState = CONTROL_TRANSFER_STATE_READ ;
370372 return ;
371373 }
0 commit comments