micropython-lib
micropython-lib copied to clipboard
micropython/usb/usb-device/usb/device/core.py: Add alternate setting support plus a few fixes and improvements.
Summary
- Added
bAlternateSettingas argument toDescriptor.interface, because it is used for USB MIDI 2.0 - Fixed the loop reserving other string indexes used by built-in drivers
while len(strs) < builtin_driver.str_max:towhile len(strs) < builtin\_driver.str\_max - 1:(row 169) becausestr_maxequals to one more than the highest string descriptor index value used by any built-in descriptor according to the docs and added a comment that this loop is probably unnecessary or even wrong - Removed
import time(not used) - Removed unused/duplicate
_Device.configargumentconfig_str - Some code optimisations (in particular to the
Bufferclass)
Testing
- Tested with micropython/usb/examples/device/midi_example.py
- Tested the Buffer class with micropython/usb/usb-device/usb/device/tests/test_core_buffer.py
- Tested with a soon to be made public multi-port MIDI module draft which adds port names to
strs
Trade-offs and Alternatives
None
The updated version of core.py is used in this project, which also shows that it is working: https://github.com/orgs/micropython/discussions/17640