Skip to content

Commit 0ee6248

Browse files
sandeepmistrycmaglie
authored andcommitted
Replace utoa + toupper with custom loop
1 parent 61b060c commit 0ee6248

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

cores/arduino/USB/USBCore.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,12 @@ uint32_t USBDeviceClass::sendConfiguration(uint32_t maxlen)
177177
return true;
178178
}
179179

180-
static void utox(uint32_t val, char* s) {
181-
// lead zero pad
182-
for (uint32_t i = 0x10000000; i > 1; i = i >> 4) {
183-
if (val < i) {
184-
*s++ = '0';
185-
}
186-
}
187-
188-
// convert value to hex string
189-
utoa(val, s, 16);
180+
static void utox8(uint32_t val, char* s) {
181+
for (int i = 0; i < 8; i++) {
182+
int d = val & 0XF;
183+
val = (val >> 4);
190184

191-
// make string uppercase
192-
while (s && *s) {
193-
*s = toupper(*s);
194-
s++;
185+
s[7 - i] = d > 9 ? 'A' + d - 10 : '0' + d;
195186
}
196187
}
197188

@@ -246,10 +237,10 @@ bool USBDeviceClass::sendDescriptor(USBSetup &setup)
246237
#define SERIAL_NUMBER_WORD_3 *(volatile uint32_t*)(0x0080A048)
247238

248239
char name[ISERIAL_MAX_LEN];
249-
utox(SERIAL_NUMBER_WORD_0, &name[0]);
250-
utox(SERIAL_NUMBER_WORD_1, &name[8]);
251-
utox(SERIAL_NUMBER_WORD_2, &name[16]);
252-
utox(SERIAL_NUMBER_WORD_3, &name[24]);
240+
utox8(SERIAL_NUMBER_WORD_0, &name[0]);
241+
utox8(SERIAL_NUMBER_WORD_1, &name[8]);
242+
utox8(SERIAL_NUMBER_WORD_2, &name[16]);
243+
utox8(SERIAL_NUMBER_WORD_3, &name[24]);
253244

254245
PluggableUSB().getShortName(&name[32]);
255246
return sendStringDescriptor((uint8_t*)name, setup.wLength);

0 commit comments

Comments
 (0)