Skip to content

Commit ea894b1

Browse files
cmagliesandeepmistry
authored andcommitted
Fixed USB sendStringDescriptor
1 parent fe4747b commit ea894b1

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

cores/arduino/USB/USBCore.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,18 @@ bool USBDeviceClass::sendStringDescriptor(const uint8_t *string, uint8_t maxlen)
9090
if (maxlen < 2)
9191
return false;
9292

93-
uint16_t buff[maxlen/2];
94-
int l = 1;
93+
uint8_t buffer[maxlen];
94+
buffer[0] = 0x03;
95+
buffer[1] = strlen(string) * 2 + 2;
9596

96-
maxlen -= 2;
97-
while (*string && maxlen>0)
98-
{
99-
buff[l++] = (uint8_t)(*string++);
100-
maxlen -= 2;
97+
uint8_t i;
98+
for (i = 2; i < maxlen && *string; i++) {
99+
buffer[i++] = *string++;
100+
if (i == maxlen) break;
101+
buffer[i] = 0;
101102
}
102-
buff[0] = (3<<8) | (l*2);
103103

104-
return USBDevice.sendControl((uint8_t*)buff, l*2);
104+
return USBDevice.sendControl(buffer, i);
105105
}
106106

107107
bool _dry_run = false;

0 commit comments

Comments
 (0)