mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
Merge pull request #711 from hathach/usbd-handle-set-interface
Usbd handle set interface
This commit is contained in:
commit
f9817da397
@ -169,52 +169,59 @@ void tud_resume_cb(void)
|
|||||||
bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
|
bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
|
||||||
{
|
{
|
||||||
// nothing to with DATA & ACK stage
|
// 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)
|
||||||
switch (request->bRequest)
|
{
|
||||||
{
|
case TUSB_REQ_TYPE_VENDOR:
|
||||||
case VENDOR_REQUEST_WEBUSB:
|
switch (request->bRequest)
|
||||||
// match vendor request in BOS descriptor
|
{
|
||||||
// Get landing page url
|
case VENDOR_REQUEST_WEBUSB:
|
||||||
return tud_control_xfer(rhport, request, (void*) &desc_url, desc_url.bLength);
|
// match vendor request in BOS descriptor
|
||||||
|
// Get landing page url
|
||||||
|
return tud_control_xfer(rhport, request, (void*) &desc_url, desc_url.bLength);
|
||||||
|
|
||||||
case VENDOR_REQUEST_MICROSOFT:
|
case VENDOR_REQUEST_MICROSOFT:
|
||||||
if ( request->wIndex == 7 )
|
if ( request->wIndex == 7 )
|
||||||
|
{
|
||||||
|
// Get Microsoft OS 2.0 compatible descriptor
|
||||||
|
uint16_t total_len;
|
||||||
|
memcpy(&total_len, desc_ms_os_20+8, 2);
|
||||||
|
|
||||||
|
return tud_control_xfer(rhport, request, (void*) desc_ms_os_20, total_len);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
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 )
|
||||||
{
|
{
|
||||||
// Get Microsoft OS 2.0 compatible descriptor
|
board_led_write(true);
|
||||||
uint16_t total_len;
|
blink_interval_ms = BLINK_ALWAYS_ON;
|
||||||
memcpy(&total_len, desc_ms_os_20+8, 2);
|
|
||||||
|
|
||||||
return tud_control_xfer(rhport, request, (void*) desc_ms_os_20, total_len);
|
tud_vendor_write_str("\r\nTinyUSB WebUSB device example\r\n");
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
return false;
|
blink_interval_ms = BLINK_MOUNTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
// response with status OK
|
||||||
return false;
|
return tud_control_status(rhport, request);
|
||||||
}
|
}
|
||||||
} else if (
|
break;
|
||||||
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.
|
|
||||||
web_serial_connected = (request->wValue != 0);
|
|
||||||
|
|
||||||
// Always lit LED if connected
|
default: break;
|
||||||
if ( web_serial_connected ) {
|
|
||||||
board_led_write(true);
|
|
||||||
blink_interval_ms = BLINK_ALWAYS_ON;
|
|
||||||
|
|
||||||
tud_vendor_write_str("\r\nTinyUSB WebUSB device example\r\n");
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
blink_interval_ms = BLINK_MOUNTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
// response with status OK
|
|
||||||
return tud_control_status(rhport, request);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stall unknown request
|
// stall unknown request
|
||||||
|
@ -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
|
// notable requests are: GET HID REPORT DESCRIPTOR, SET_INTERFACE, GET_INTERFACE
|
||||||
if ( !invoke_class_control(rhport, driver, p_request) )
|
if ( !invoke_class_control(rhport, driver, p_request) )
|
||||||
{
|
{
|
||||||
// For GET_INTERFACE, it is mandatory to respond even if the class
|
// For GET_INTERFACE and SET_INTERFACE, it is mandatory to respond even if the class
|
||||||
// driver doesn't use alternate settings.
|
// driver doesn't use alternate settings or implement this
|
||||||
TU_VERIFY( TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type &&
|
TU_VERIFY(TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type);
|
||||||
TUSB_REQ_GET_INTERFACE == p_request->bRequest);
|
|
||||||
|
|
||||||
uint8_t alternate = 0;
|
if (TUSB_REQ_GET_INTERFACE == p_request->bRequest)
|
||||||
tud_control_xfer(rhport, p_request, &alternate, 1);
|
{
|
||||||
|
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;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user