Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update vender device to new control xfer cb starting in tinyusb 0.11.0 #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 52 additions & 49 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,65 +177,68 @@ void tud_resume_cb(void)
// WebUSB use vendor class
//--------------------------------------------------------------------+

// Invoked when received VENDOR control request
bool tud_vendor_control_request_cb(uint8_t rhport, tusb_control_request_t const * request)
// Invoked when a control transfer occurred on an interface of this class
// Driver response accordingly to the request and the transfer stage (setup/data/ack)
// return false to stall control endpoint (e.g unsupported request)
bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
{
switch (request->bRequest)
{
case VENDOR_REQUEST_WEBUSB:
// 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:
if ( request->wIndex == 7 )
{
// Get Microsoft OS 2.0 compatible descriptor
uint16_t total_len;
memcpy(&total_len, desc_ms_os_20+8, 2);
// nothing to do for DATA & ACK stage
if (stage != CONTROL_STAGE_SETUP) return true;

return tud_control_xfer(rhport, request, (void*) desc_ms_os_20, total_len);
}else
switch (request->bmRequestType_bit.type)
{
case TUSB_REQ_TYPE_VENDOR:
switch (request->bRequest)
{
return false;
case VENDOR_REQUEST_WEBUSB:
// 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:
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 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 )
{
board_led_write(true);
blink_interval_ms = BLINK_ALWAYS_ON;

// tud_vendor_write_str("\r\nTinyUSB WebUSB device example\r\n");
}else
case TUSB_REQ_TYPE_CLASS:
if (request->bRequest == 0x22)
{
blink_interval_ms = BLINK_MOUNTED;
// 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 )
{
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);
}
break;

// response with status OK
return tud_control_status(rhport, request);

default:
// stall unknown request
return false;
default: break;
}

return true;
}

// Invoked when DATA Stage of VENDOR's request is complete
bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_request_t const * request)
{
(void) rhport;
(void) request;

// nothing to do
return true;
// stall unknown request
return false;
}

void webserial_task(void)
Expand Down