Merge pull request #711 from hathach/usbd-handle-set-interface

Usbd handle set interface
This commit is contained in:
Ha Thach 2021-03-10 12:10:52 +07:00 committed by GitHub
commit f9817da397
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 43 deletions

View File

@ -169,9 +169,11 @@ void tud_resume_cb(void)
bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
{
// nothing to with DATA & ACK stage
if (stage != CONTROL_STAGE_SETUP ) return true;
if (stage != CONTROL_STAGE_SETUP) return true;
if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_VENDOR) {
switch (request->bmRequestType_bit.type)
{
case TUSB_REQ_TYPE_VENDOR:
switch (request->bRequest)
{
case VENDOR_REQUEST_WEBUSB:
@ -192,18 +194,19 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
return false;
}
default:
return false;
default: break;
}
} else if (
request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS &&
request->bRequest == 0x22) {
// Webserial simulate the CDC_REQUEST_SET_CONTROL_LINE_STATE (0x22) to
// connect and disconnect.
break;
case TUSB_REQ_TYPE_CLASS:
if (request->bRequest == 0x22)
{
// Webserial simulate the CDC_REQUEST_SET_CONTROL_LINE_STATE (0x22) to connect and disconnect.
web_serial_connected = (request->wValue != 0);
// Always lit LED if connected
if ( web_serial_connected ) {
if ( web_serial_connected )
{
board_led_write(true);
blink_interval_ms = BLINK_ALWAYS_ON;
@ -216,6 +219,10 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
// response with status OK
return tud_control_status(rhport, request);
}
break;
default: break;
}
// stall unknown request
return false;

View File

@ -699,13 +699,21 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
// notable requests are: GET HID REPORT DESCRIPTOR, SET_INTERFACE, GET_INTERFACE
if ( !invoke_class_control(rhport, driver, p_request) )
{
// For GET_INTERFACE, it is mandatory to respond even if the class
// driver doesn't use alternate settings.
TU_VERIFY( TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type &&
TUSB_REQ_GET_INTERFACE == p_request->bRequest);
// For GET_INTERFACE and SET_INTERFACE, it is mandatory to respond even if the class
// driver doesn't use alternate settings or implement this
TU_VERIFY(TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type);
if (TUSB_REQ_GET_INTERFACE == p_request->bRequest)
{
uint8_t alternate = 0;
tud_control_xfer(rhport, p_request, &alternate, 1);
}else if (TUSB_REQ_SET_INTERFACE == p_request->bRequest)
{
tud_control_status(rhport, p_request);
} else
{
return false;
}
}
}
break;