You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The C usermod stays _usbif. Applications should not import it.
Package internals (native_usb.py, native_midi.py, uac_audio.py) may still import _usbif. Examples, README snippets, and the public usbif docs must go through usbif.auto.host() / usbif.auto.device() / usbif.auto.open_midi().
This is a surface cleanup, not a structural merge: MicroPython cannot register the C module as usbif while a frozen Python package also occupies that name.
Related: #8 is the costume-name gap this plan has to fix first (Device.FUNCTIONS / NativeDevice._BITS omit video).
Plan
Work is in this repo. The C module stays _usbif.
flowchart LR
examples["examples and apps"] --> auto["usbif.auto"]
auto --> native["usbif.native_usb"]
auto --> midi["usbif.native_midi"]
examples --> uac_audio["usbif.uac_audio"]
examples --> parsers["usbif.uac / usbif.uvc parsers"]
native --> cmod["_usbif C usermod"]
midi --> cmod
uac_audio --> cmod
Loading
Rule
_usbif is imported only inside lib/usbif/ (native_usb.py, native_midi.py, uac_audio.py). Everything else goes through usbif.auto.host() / usbif.auto.device() / usbif.auto.open_midi().
uac.py and uvc.py stay portable descriptor parsers with no_usbif import — they already run on CPython in the conformance suite. Device/host streaming for those classes lands on NativeDevice / NativeHost, next to the wrappers that already exist (NativeDevice.functions, NativeHost.start, uac_audio for hosted PCM).
Facade: expand NativeDevice and NativeHost
lib/usbif/native_usb.py already has _require() and the lifecycle. Add thin passthroughs; do not invent a second API.
Fix the costume gap first.NativeDevice._BITS and Device.FUNCTIONS omit video (FN_VIDEO = 32). usbif_webcam.py cannot move off _usbif.FN_VIDEO until "uvc": 32 is added in native_usb.py and "uvc" is added to FUNCTIONS in lib/usbif/__init__.py. That is #8.
NativeDevice (board as peripheral) — passthroughs named without the C dev_ / class prefix where the object already is the device:
Lift the duplicated MSC partition.USBPartition is copy-pasted in examples/usb_drive_mount.py and examples/usb_drive_log.py. Move it to native_usb.py as MscPartition calling NativeHost.msc_read / msc_write.
Examples: import usbif, never _usbif
Twelve files under examples/ import _usbif today. Rewrite each to usbif.auto plus the new methods. Typical shapes:
uac_pump.py / README snippet: dev.uac_volume(), dev.uac_read(), dev.uac_pump_start(...) instead of _usbif.uac_*.
costume_selftest.py: iterate name combinations from dev.functions_available() and call dev.desc_check(); drop FN_* bitmasks.
Leave src/mod_usbif.c and historical findings text that name the C module alone. Update only application-facing docs: root README.md (the import usbif.auto, _usbif snippet) and lib/usbif/README.md.
Guardrail
Add tests/test_no_usbif_leak.py: walk examples/ and lib/usbif/README.md (and the root README example block) and fail if import _usbif or from _usbif appears. Allow _usbif only under lib/usbif/native_usb.py, native_midi.py, and uac_audio.py.
CPython unit test: constructing NativeDevice / NativeHost and calling a wrapped method without the C module raises ImportError (the existing _require() path).
python -m flake8 on the touched Python. On-device proof is a later board run of the rewritten examples; this change is a rename of the Python surface, not of USB behaviour.
Out of scope
Renaming the C module to usbif
Implementing Host/Device in C
Merging desktop backends into the usermod
Rewriting docs/phase0-findings.md evidence that recorded _usbif on the REPL
The C usermod stays
_usbif. Applications should not import it.Package internals (
native_usb.py,native_midi.py,uac_audio.py) may stillimport _usbif. Examples, README snippets, and the publicusbifdocs must go throughusbif.auto.host()/usbif.auto.device()/usbif.auto.open_midi().This is a surface cleanup, not a structural merge: MicroPython cannot register the C module as
usbifwhile a frozen Python package also occupies that name.Related: #8 is the costume-name gap this plan has to fix first (
Device.FUNCTIONS/NativeDevice._BITSomit video).Plan
Work is in this repo. The C module stays
_usbif.Rule
_usbifis imported only insidelib/usbif/(native_usb.py,native_midi.py,uac_audio.py). Everything else goes throughusbif.auto.host()/usbif.auto.device()/usbif.auto.open_midi().uac.pyanduvc.pystay portable descriptor parsers with no_usbifimport — they already run on CPython in the conformance suite. Device/host streaming for those classes lands onNativeDevice/NativeHost, next to the wrappers that already exist (NativeDevice.functions,NativeHost.start,uac_audiofor hosted PCM).Facade: expand NativeDevice and NativeHost
lib/usbif/native_usb.pyalready has_require()and the lifecycle. Add thin passthroughs; do not invent a second API.Fix the costume gap first.
NativeDevice._BITSandDevice.FUNCTIONSomit video (FN_VIDEO = 32).usbif_webcam.pycannot move off_usbif.FN_VIDEOuntil"uvc": 32is added innative_usb.pyand"uvc"is added toFUNCTIONSinlib/usbif/__init__.py. That is #8.NativeDevice (board as peripheral) — passthroughs named without the C
dev_/ class prefix where the object already is the device:state(),reinit(),pid(),desc_check(),builtin_desc_cfg()msc_attach,msc_attach_blockdev,msc_detach,msc_status,msc_buffer,msc_bd_statshid_send,hid_leds;HID_KEYBOARD/HID_MOUSEas class attributesuac_enable,uac_pump_start,uac_pump_stop,uac_pump_stats,uac_available,uac_volume,uac_read,uac_statsuvc_format,uvc_reset,uvc_streaming,uvc_ready,uvc_submit,uvc_statsMIDI device I/O is already
usbif.auto.open_midi("dev:midi"). Do not add a secondmidi_readon NativeDevice.NativeHost (board drives peripherals):
start/stop/devices/poll/capabilitiesdesc(id),stats(),port_cycle(),intr_dump()msc_open/info/read/write/close/diag/provokeuvc_negotiate/open/read_frame/frame_ready/stats/closecdc_open/read/write/closehid_open/read/closeHost MIDI stays
usbif.auto.open_midi("host:<id>"). Host UAC stayslib/usbif/uac_audio.py.Lift the duplicated MSC partition.
USBPartitionis copy-pasted inexamples/usb_drive_mount.pyandexamples/usb_drive_log.py. Move it tonative_usb.pyasMscPartitioncallingNativeHost.msc_read/msc_write.Examples:
import usbif, never_usbifTwelve files under
examples/import_usbiftoday. Rewrite each tousbif.autoplus the new methods. Typical shapes:Device costume (webcam, sd_drive, midi_device_in, costume_selftest):
Device MIDI (harmonizer, harmonizer_ui, midi_device_in, midi_latency):
Host (uvc_display, midi_host, usb_drive_*):
uac_pump.py/ README snippet:dev.uac_volume(),dev.uac_read(),dev.uac_pump_start(...)instead of_usbif.uac_*.costume_selftest.py: iterate name combinations fromdev.functions_available()and calldev.desc_check(); dropFN_*bitmasks.Leave
src/mod_usbif.cand historical findings text that name the C module alone. Update only application-facing docs: rootREADME.md(theimport usbif.auto, _usbifsnippet) andlib/usbif/README.md.Guardrail
Add
tests/test_no_usbif_leak.py: walkexamples/andlib/usbif/README.md(and the root README example block) and fail ifimport _usbiforfrom _usbifappears. Allow_usbifonly underlib/usbif/native_usb.py,native_midi.py, anduac_audio.py.CPython unit test: constructing
NativeDevice/NativeHostand calling a wrapped method without the C module raisesImportError(the existing_require()path).python -m flake8on the touched Python. On-device proof is a later board run of the rewritten examples; this change is a rename of the Python surface, not of USB behaviour.Out of scope
usbifdocs/phase0-findings.mdevidence that recorded_usbifon the REPLTodos
uvctoNativeDevice._BITSandDevice.FUNCTIONS(Portable Device.functions() omits video (FN_VIDEO exists in C) #8)NativeDevice/NativeHost; liftMscPartitionusbif.auto/Native*test_no_usbif_leak.pyand ImportError coverage for wrapped methods