Closed
Description
cost: may use more stack
Most (all?) usb string descriptors use ASCII, but are stored as uint16_t[]
, and on metro m0 express these total 273 elements. If we "compress" them (store 8-bit values) we save half of that (546->273 bytes).
Tag the string pointers with the low bit to distinguish them; when requested, decompress them to a stack buffer, something like (untested)
if ((intptr_t)desc_str & 1) {
desc_str = (uint8_t*)((intptr_t)desc_str - 1);
uint8_t desc_sz = desc_str[0];
uint16_t desc_buf[desc_sc/2];
buf[0] = desc_sz | 0x300;
for(int i=1; i<desc_sz/2; i++) {
desc_buf[i] = desc_str[i];
}
This depends on it being OK for the buffer to not be static--I don't know if when tud_control_xfer
returns, the buffer is "done with" or not.
This might work out or not, just writing it up in case someone wants to look into it further or in case of further need. It might need changes in tinyusb, or we might be able to do it inside tud_descriptor_string_cb
, not sure.