Skip to content
Merged
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
22 changes: 14 additions & 8 deletions hardware/arduino/sam/cores/arduino/USB/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,21 @@ int USBD_SendControl(uint8_t flags __attribute__ ((unused)), const void* d, uint
// plain ASCII string but is sent out as UTF-16 with the
// correct 2-byte prefix
static bool USB_SendStringDescriptor(const uint8_t *string, int wLength) {
uint16_t buff[64];
int l = 1;
wLength-=2;
while (*string && wLength>0) {
buff[l++] = (uint8_t)(*string++);
wLength-=2;
if (wLength < 2)
return false;

uint8_t buffer[wLength];
buffer[0] = strlen((const char*)string) * 2 + 2;
buffer[1] = 0x03;

uint8_t i;
for (i = 2; i < wLength && *string; i++) {
buffer[i++] = *string++;
if (i == wLength) break;
buffer[i] = 0;
}
buff[0] = (3<<8) | (l*2);
return USBD_SendControl(0, (uint8_t*)buff, l*2);

return USBD_SendControl(0, (uint8_t*)buffer, i);
}

// Does not timeout or cross fifo boundaries
Expand Down