cnlohr / rv003usb

CH32V003 RISC-V Pure Software USB Controller
MIT License
436 stars 43 forks source link

fix composite_hid descriptor and add re-enumeration delay #42

Closed xsrf closed 7 months ago

xsrf commented 7 months ago

The composite_hid descriptor didn't work properly on Windows (Keyboard worked, but Mouse didn't). With this change it works on Windows, Linux and MacOS.
Also added a delay between SystemInit() and usb_setup() to ensure re-enumeration after bootloader or reset. This works because the D- Pull-Up is disabled in that period. With a hardwired pullup one would need D- to be pulled low actively to achieve the same.

xsrf commented 7 months ago

Actually USB Spec only require a SE0 for 2.5µs (TDDIS) to detect a disconnect and SystemInit() followed by usb_setup() already creates a ~200µs long SE0. However, I had problems with my USB hub disabling the port when my device switched from bootloader to keyboard and adding a delay in between fixed it 🤔 but now I'm not sure if the cause was something else. @cnlohr Let me know if you think this delay() is actually misleading here and I'll remove it from the PR