@@ -44,13 +44,8 @@ const char devDescriptor[] =
44
44
USB_PID_HIGH , // idProduct H
45
45
0x00 , // bcdDevice L, here matching SAM-BA version
46
46
0x02 , // bcdDevice H
47
- #if 0 // TODO: pending validation
48
47
STRING_INDEX_MANUFACTURER , // iManufacturer
49
48
STRING_INDEX_PRODUCT , // iProduct
50
- #else
51
- 0x00 , // iManufacturer
52
- 0x00 , // iProduct
53
- #endif // 0
54
49
0x00 , // SerialNumber, should be based on product unique ID
55
50
0x01 // bNumConfigs
56
51
};
@@ -195,47 +190,40 @@ void sam_ba_usb_CDC_Enumerate(P_USB_CDC pCdc)
195
190
/* Return Device Descriptor */
196
191
USB_Write (pCdc -> pUsb , devDescriptor , SAM_BA_MIN (sizeof (devDescriptor ), wLength ), USB_EP_CTRL );
197
192
}
198
- else
193
+ else if ( wValue >> 8 == STD_GET_DESCRIPTOR_CONFIGURATION )
199
194
{
200
- if ( wValue >> 8 == STD_GET_DESCRIPTOR_CONFIGURATION )
201
- {
202
- /* Return Configuration Descriptor */
203
- USB_Write ( pCdc -> pUsb , cfgDescriptor , SAM_BA_MIN ( sizeof ( cfgDescriptor ), wLength ), USB_EP_CTRL );
204
- }
205
- else
195
+ /* Return Configuration Descriptor */
196
+ USB_Write ( pCdc -> pUsb , cfgDescriptor , SAM_BA_MIN ( sizeof ( cfgDescriptor ), wLength ), USB_EP_CTRL );
197
+ }
198
+ else if ( wValue >> 8 == STD_GET_DESCRIPTOR_STRING )
199
+ {
200
+ switch ( wValue & 0xff )
206
201
{
207
- #if 0 // TODO: pending validation
208
- if (wValue >>8 == STD_GET_DESCRIPTOR_STRING )
209
- {
210
- switch ( wValue & 0xff )
211
- {
212
- case STRING_INDEX_LANGUAGES :
213
- uint16_t STRING_LANGUAGE [2 ] = { (STD_GET_DESCRIPTOR_STRING <<8 ) | 4 , 0x0409 };
214
-
215
- USB_Write (pCdc -> pUsb , (const char * )STRING_LANGUAGE , SAM_BA_MIN (sizeof (STRING_LANGUAGE ), wLength ), USB_EP_CTRL );
216
- break ;
217
-
218
- case STRING_INDEX_MANUFACTURER :
219
- USB_SendString (pCdc -> pUsb , STRING_MANUFACTURER , strlen (STRING_MANUFACTURER ), wLength );
220
- break ;
221
-
222
- case STRING_INDEX_PRODUCT :
223
- USB_SendString (pCdc -> pUsb , STRING_PRODUCT , strlen (STRING_PRODUCT ), wLength );
224
- break ;
225
- default :
226
- /* Stall the request */
227
- USB_SendStall (pUsb , true);
228
- break ;
229
- }
202
+ case STRING_INDEX_LANGUAGES : {
203
+ uint16_t STRING_LANGUAGE [2 ] = { (STD_GET_DESCRIPTOR_STRING <<8 ) | 4 , 0x0409 };
204
+
205
+ USB_Write (pCdc -> pUsb , (const char * )STRING_LANGUAGE , SAM_BA_MIN (sizeof (STRING_LANGUAGE ), wLength ), USB_EP_CTRL );
230
206
}
231
- else
232
- #endif // 0
233
- {
207
+ break ;
208
+
209
+ case STRING_INDEX_MANUFACTURER :
210
+ USB_SendString (pCdc -> pUsb , STRING_MANUFACTURER , wLength );
211
+ break ;
212
+
213
+ case STRING_INDEX_PRODUCT :
214
+ USB_SendString (pCdc -> pUsb , STRING_PRODUCT , wLength );
215
+ break ;
216
+ default :
234
217
/* Stall the request */
235
218
USB_SendStall (pUsb , true);
236
- }
219
+ break ;
237
220
}
238
221
}
222
+ else
223
+ {
224
+ /* Stall the request */
225
+ USB_SendStall (pUsb , true);
226
+ }
239
227
break ;
240
228
241
229
case STD_SET_ADDRESS :
@@ -430,27 +418,24 @@ P_USB_CDC usb_init(void)
430
418
return & sam_ba_cdc ;
431
419
}
432
420
433
- #if 0 // TODO: pending validation
434
421
/*----------------------------------------------------------------------------
435
422
* \brief Send a USB descriptor string.
436
423
*
437
424
* The input string is plain ASCII but is sent out as UTF-16 with the correct 2-byte prefix.
438
425
*/
439
- uint32_t USB_SendString (Usb * pUsb , const char * ascii_string , uint8_t length , uint8_t maxLength )
426
+ uint32_t USB_SendString (Usb * pUsb , const char * ascii_string , uint8_t maxLength )
440
427
{
441
428
uint8_t string_descriptor [255 ]; // Max USB-allowed string length
442
429
uint16_t * unicode_string = (uint16_t * )(string_descriptor + 2 ); // point on 3 bytes of descriptor
430
+ int resulting_length ;
443
431
444
- int resulting_length = 1 ;
432
+ string_descriptor [0 ] = (strlen (ascii_string )<<1 ) + 2 ;
433
+ string_descriptor [1 ] = STD_GET_DESCRIPTOR_STRING ;
445
434
446
- for ( ; * ascii_string && (length >= 0 ) && ( resulting_length < ( maxLength >>1 )) ; ascii_string ++ , length -- , resulting_length ++ )
435
+ for ( resulting_length = 1 ; * ascii_string && (resulting_length < maxLength >>1 ) ; resulting_length ++ )
447
436
{
448
- * unicode_string ++ = (uint16_t )(* ascii_string );
437
+ * unicode_string ++ = (uint16_t )(* ascii_string ++ );
449
438
}
450
439
451
- string_descriptor [0 ] = (resulting_length <<1 );
452
- string_descriptor [1 ] = STD_GET_DESCRIPTOR_STRING ;
453
-
454
- return USB_Write (pUsb , (const char * )unicode_string , resulting_length , USB_EP_CTRL );
440
+ return USB_Write (pUsb , (const char * )string_descriptor , resulting_length <<1 , USB_EP_CTRL );
455
441
}
456
- #endif // 0
0 commit comments