Skip to content

Commit

Permalink
Merge pull request #48 from mndza/wicd-descriptors
Browse files Browse the repository at this point in the history
firmware: add WCID descriptors
  • Loading branch information
mossmann authored May 6, 2024
2 parents 5da715d + da58d8e commit 4554c56
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 20 deletions.
14 changes: 11 additions & 3 deletions firmware/src/boards/daisho/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,17 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index)
{
// Convert ASCII string into UTF-16

if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;

const char* str = string_desc_arr[index];
const char* str;
if (index == 0xee) {
// Microsoft OS 1.0 String Descriptor
str = "MSFT100\xee\x01";
} else {
if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) {
return NULL;
}

str = string_desc_arr[index];
}

// Cap at max char
chr_count = strlen(str);
Expand Down
39 changes: 23 additions & 16 deletions firmware/src/mcu/samd11/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ tusb_desc_device_t const desc_device =
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,

// Use Interface Association Descriptor (IAD) for CDC
// As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
.bDeviceClass = TUSB_CLASS_MISC,
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
.bDeviceProtocol = MISC_PROTOCOL_IAD,
// We use bDeviceClass = 0 to indicate that we're a composite device.
// Another option is to use the Interface Association Descriptor (IAD) method,
// but this requires extra descriptors.
.bDeviceClass = 0,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,

.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,

Expand Down Expand Up @@ -185,20 +186,26 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
// Otherwise, take the ASCII string provided and encode it as UTF-16.
else {

if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) {
return NULL;
}
const char* str;
if (index == 0xee) {
// Microsoft OS 1.0 String Descriptor
str = "MSFT100\xee\x01";
} else {
if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) {
return NULL;
}

const char* str = string_desc_arr[index];
str = string_desc_arr[index];
}

// Cap at max char
chr_count = strlen(str);
if ( chr_count > 31 ) chr_count = 31;
// Cap at max char
chr_count = strlen(str);
if ( chr_count > 31 ) chr_count = 31;

for(uint8_t i=0; i<chr_count; i++)
{
_desc_str[1+i] = str[i];
}
for(uint8_t i=0; i<chr_count; i++)
{
_desc_str[1+i] = str[i];
}
}

// first byte is length (including header), second byte is string type
Expand Down
40 changes: 39 additions & 1 deletion firmware/src/vendor.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,44 @@ enum {
//
// Self-test requests.
//
VENDOR_REQUEST_GET_RAIL_VOLTAGE = 0xe0
VENDOR_REQUEST_GET_RAIL_VOLTAGE = 0xe0,

//
// Microsoft WCID descriptor request
//
VENDOR_REQUEST_GET_MS_DESCRIPTOR = 0xee,
};

// Microsoft OS 1.0 descriptor
uint8_t desc_ms_os_10[] = {
// Header: length, bcdVersion, wIndex, bCount, reserved[7]
U32_TO_U8S_LE(0x0028),
U16_TO_U8S_LE(0x0100),
U16_TO_U8S_LE(0x0004),
0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

// Compatible ID: bFirstInterfaceNumber, reserved[1], compatibleID[8], subCompatibleID[8], reserved[6]
0x02,
0x01,
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};


/**
* Request Microsoft Windows Compatible ID descriptor.
*/
bool handle_get_ms_descriptor(uint8_t rhport, tusb_control_request_t const* request)
{
if (request->wIndex == 0x0004) {
return tud_control_xfer(rhport, request, desc_ms_os_10, sizeof(desc_ms_os_10));
} else {
return false;
}
}


/**
* Simple request that's used to identify the running firmware; mostly a sanity check.
Expand Down Expand Up @@ -181,6 +216,9 @@ static bool handle_vendor_request_setup(uint8_t rhport, tusb_control_request_t c
return handle_get_rail_voltage(rhport, request);
*/

case VENDOR_REQUEST_GET_MS_DESCRIPTOR:
return handle_get_ms_descriptor(rhport, request);

default:
return false;
}
Expand Down

0 comments on commit 4554c56

Please sign in to comment.