mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Set string descriptor length to the string length + 2, and send up to wLength bytes
This commit is contained in:
parent
c3d2bbdb86
commit
aeec344b21
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user