Reenumerate dynamically with different descriptors? #3242
-
Hello, here's what I'd like to achieve and am wondering if it's at all possible with TinyUSB. Typically, I want to implement a USB device with one or several interfaces, and I'd like to dynamically (triggered by some user action) activate one of the interfaces. For instance, say the device supports a vendor interface, and depending on user action, I'd like to have it expose a MSC interface. So, the vendor interface would always be available, but the MSC one, only based on user action, so, dynamically. I suppose from a USB standpoint, the only way of doing this would be to force reenumeration with descriptors for vendor + MSC interface, and then force reenumeration with descriptors for vendor only when the MSC interface is no longer needed. Problem with TinyUSB is that its configuration, as far as know, is entirely static, so we can force reenumeration, but we can't have several sets of descriptors. If anyone has any idea how this could be achieved, that'd be great. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Hi,
As far as I understand, you can make |
Beta Was this translation helpful? Give feedback.
-
you can try https://github.com/hathach/tinyusb/tree/master/examples/device/dynamic_configuration |
Beta Was this translation helpful? Give feedback.
-
Thanks guys, I didn't think of that, but now it appears obvious. Now for forcing reenumeration from the device side, I suppose I can call tud_deinit() and tud_init() again? Anything to be careful about, doing so? (Like possible dangling states?) |
Beta Was this translation helpful? Give feedback.
-
I can confirm that it works beautifully so far. I have put a fixed delay (200 ms) between the call to tud_deinit() and tud_init(). Not sure if that's really necessary? |
Beta Was this translation helpful? Give feedback.
Hi,
As far as I understand, you can make
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
return whatever you want, as long as it is of typeuint8_t const *
?