@@ -257,9 +257,26 @@ bool tuh_vid_pid_get(uint8_t dev_addr, uint16_t* vid, uint16_t* pid)
257
257
return true;
258
258
}
259
259
260
+ tusb_speed_t tuh_speed_get (uint8_t dev_addr )
261
+ {
262
+ return (tusb_speed_t ) (dev_addr ? get_device (dev_addr )-> speed : _dev0 .speed );
263
+ }
260
264
261
- bool tuh_descriptor_get (uint8_t daddr , uint8_t type , uint8_t index ,
262
- void * buffer , uint16_t len , tuh_control_complete_cb_t complete_cb )
265
+ #if CFG_TUSB_OS == OPT_OS_NONE
266
+ void osal_task_delay (uint32_t msec )
267
+ {
268
+ (void ) msec ;
269
+
270
+ const uint32_t start = hcd_frame_number (TUH_OPT_RHPORT );
271
+ while ( ( hcd_frame_number (TUH_OPT_RHPORT ) - start ) < msec ) {}
272
+ }
273
+ #endif
274
+
275
+ //--------------------------------------------------------------------+
276
+ // Descriptors
277
+ //--------------------------------------------------------------------+
278
+
279
+ bool tuh_descriptor_get (uint8_t daddr , uint8_t type , uint8_t index , void * buffer , uint16_t len , tuh_control_complete_cb_t complete_cb )
263
280
{
264
281
tusb_control_request_t const request =
265
282
{
@@ -272,7 +289,7 @@ bool tuh_descriptor_get(uint8_t daddr, uint8_t type, uint8_t index,
272
289
.bRequest = TUSB_REQ_GET_DESCRIPTOR ,
273
290
.wValue = tu_htole16 ( TU_U16 (type , index ) ),
274
291
.wIndex = 0 ,
275
- .wLength = len
292
+ .wLength = tu_htole16 ( len )
276
293
};
277
294
278
295
TU_ASSERT ( tuh_control_xfer (daddr , & request , buffer , complete_cb ) );
@@ -290,6 +307,27 @@ bool tuh_descriptor_configuration_get(uint8_t daddr, uint8_t index, void* buffer
290
307
return tuh_descriptor_get (daddr , TUSB_DESC_CONFIGURATION , index , buffer , len , complete_cb );
291
308
}
292
309
310
+ bool tuh_descriptor_string_get (uint8_t daddr , uint16_t language_id , uint8_t index ,
311
+ void * buf , uint16_t len , tuh_control_complete_cb_t complete_cb )
312
+ {
313
+ tusb_control_request_t const request =
314
+ {
315
+ .bmRequestType_bit =
316
+ {
317
+ .recipient = TUSB_REQ_RCPT_DEVICE ,
318
+ .type = TUSB_REQ_TYPE_STANDARD ,
319
+ .direction = TUSB_DIR_IN
320
+ },
321
+ .bRequest = TUSB_REQ_GET_DESCRIPTOR ,
322
+ .wValue = tu_htole16 ( TU_U16 (TUSB_DESC_STRING , index ) ),
323
+ .wIndex = tu_htole16 (language_id ),
324
+ .wLength = tu_htole16 (len )
325
+ };
326
+
327
+ TU_ASSERT ( tuh_control_xfer (daddr , & request , buf , complete_cb ) );
328
+ return true;
329
+ }
330
+
293
331
uint8_t tuh_i_manufacturer_get (uint8_t dev_addr ) {
294
332
TU_VERIFY (tuh_mounted (dev_addr ));
295
333
usbh_device_t const * dev = get_device (dev_addr );
@@ -311,54 +349,26 @@ uint8_t tuh_i_product_get(uint8_t dev_addr) {
311
349
return dev -> i_product ;
312
350
}
313
351
314
- static tuh_complete_cb_t string_get_cb ;
315
-
316
- static bool string_get_complete (uint8_t dev_addr , tusb_control_request_t const * request , xfer_result_t result ) {
317
- (void ) dev_addr ;
318
- (void ) request ;
319
- if (string_get_cb != NULL ) {
320
- string_get_cb (result );
321
- }
322
- string_get_cb = NULL ;
323
- return true;
324
- }
325
-
326
- bool tuh_string_get (uint8_t dev_addr , uint8_t string_index , uint16_t * buf , size_t len , tuh_complete_cb_t complete_cb ) {
327
- if (string_get_cb != NULL ) {
328
- return false;
329
- }
352
+ bool tuh_configuration_set (uint8_t daddr , uint8_t config_num , tuh_control_complete_cb_t complete_cb )
353
+ {
354
+ TU_LOG2 ("Set Configuration = %d\r\n" , config_num );
330
355
tusb_control_request_t const request =
331
356
{
332
357
.bmRequestType_bit =
333
358
{
334
359
.recipient = TUSB_REQ_RCPT_DEVICE ,
335
360
.type = TUSB_REQ_TYPE_STANDARD ,
336
- .direction = TUSB_DIR_IN
361
+ .direction = TUSB_DIR_OUT
337
362
},
338
- .bRequest = TUSB_REQ_GET_DESCRIPTOR ,
339
- .wValue = TUSB_DESC_STRING << 8 | string_index ,
363
+ .bRequest = TUSB_REQ_SET_CONFIGURATION ,
364
+ .wValue = tu_htole16 ( config_num ) ,
340
365
.wIndex = 0 ,
341
- .wLength = len * sizeof ( uint16_t )
366
+ .wLength = 0
342
367
};
343
- string_get_cb = complete_cb ;
344
- TU_ASSERT ( tuh_control_xfer (dev_addr , & request , buf , string_get_complete ) );
345
- return true;
346
- }
347
-
348
- tusb_speed_t tuh_speed_get (uint8_t dev_addr )
349
- {
350
- return (tusb_speed_t ) (dev_addr ? get_device (dev_addr )-> speed : _dev0 .speed );
351
- }
352
-
353
- #if CFG_TUSB_OS == OPT_OS_NONE
354
- void osal_task_delay (uint32_t msec )
355
- {
356
- (void ) msec ;
357
368
358
- const uint32_t start = hcd_frame_number ( TUH_OPT_RHPORT );
359
- while ( ( hcd_frame_number ( TUH_OPT_RHPORT ) - start ) < msec ) {}
369
+ TU_ASSERT ( tuh_control_xfer ( daddr , & request , NULL , complete_cb ) );
370
+ return true;
360
371
}
361
- #endif
362
372
363
373
//--------------------------------------------------------------------+
364
374
// CLASS-USBD API (don't require to verify parameters)
@@ -903,7 +913,7 @@ static bool enum_request_set_addr(void)
903
913
.direction = TUSB_DIR_OUT
904
914
},
905
915
.bRequest = TUSB_REQ_SET_ADDRESS ,
906
- .wValue = new_addr ,
916
+ .wValue = tu_htole16 ( new_addr ) ,
907
917
.wIndex = 0 ,
908
918
.wLength = 0
909
919
};
@@ -954,8 +964,9 @@ static bool enum_get_device_desc_complete(uint8_t dev_addr, tusb_control_request
954
964
// if (tuh_attach_cb) tuh_attach_cb((tusb_desc_device_t*) _usbh_ctrl_buf);
955
965
956
966
// Get 9-byte for total length
967
+ uint8_t const config_idx = CONFIG_NUM - 1 ;
957
968
TU_LOG2 ("Get Configuration[0] Descriptor (9 bytes)\r\n" );
958
- TU_ASSERT ( tuh_descriptor_configuration_get (dev_addr , 0 , _usbh_ctrl_buf , 9 , enum_get_9byte_config_desc_complete ) );
969
+ TU_ASSERT ( tuh_descriptor_configuration_get (dev_addr , config_idx , _usbh_ctrl_buf , 9 , enum_get_9byte_config_desc_complete ) );
959
970
return true;
960
971
}
961
972
@@ -973,8 +984,9 @@ static bool enum_get_9byte_config_desc_complete(uint8_t dev_addr, tusb_control_r
973
984
TU_ASSERT (total_len <= CFG_TUH_ENUMERATION_BUFSIZE );
974
985
975
986
// Get full configuration descriptor
987
+ uint8_t const config_idx = CONFIG_NUM - 1 ;
976
988
TU_LOG2 ("Get Configuration[0] Descriptor\r\n" );
977
- TU_ASSERT ( tuh_descriptor_configuration_get (dev_addr , 0 , _usbh_ctrl_buf , total_len , enum_get_config_desc_complete ) );
989
+ TU_ASSERT ( tuh_descriptor_configuration_get (dev_addr , config_idx , _usbh_ctrl_buf , total_len , enum_get_config_desc_complete ) );
978
990
return true;
979
991
}
980
992
@@ -987,23 +999,7 @@ static bool enum_get_config_desc_complete(uint8_t dev_addr, tusb_control_request
987
999
// Driver open aren't allowed to make any usb transfer yet
988
1000
TU_ASSERT ( parse_configuration_descriptor (dev_addr , (tusb_desc_configuration_t * ) _usbh_ctrl_buf ) );
989
1001
990
- TU_LOG2 ("Set Configuration = %d\r\n" , CONFIG_NUM );
991
- tusb_control_request_t const new_request =
992
- {
993
- .bmRequestType_bit =
994
- {
995
- .recipient = TUSB_REQ_RCPT_DEVICE ,
996
- .type = TUSB_REQ_TYPE_STANDARD ,
997
- .direction = TUSB_DIR_OUT
998
- },
999
- .bRequest = TUSB_REQ_SET_CONFIGURATION ,
1000
- .wValue = CONFIG_NUM ,
1001
- .wIndex = 0 ,
1002
- .wLength = 0
1003
- };
1004
-
1005
- TU_ASSERT ( tuh_control_xfer (dev_addr , & new_request , NULL , enum_set_config_complete ) );
1006
-
1002
+ TU_ASSERT ( tuh_configuration_set (dev_addr , CONFIG_NUM , enum_set_config_complete ) );
1007
1003
return true;
1008
1004
}
1009
1005
0 commit comments