← index #17048PR #16356
Related · high · value 1.156
QUERY · ISSUE

machine.USBDevice support for vendor requests

openby emardopened 2025-03-30updated 2025-04-19
enhancementshared

Description

Is there possible to have some USB callback that would handle USB vendor specific requests?
I tried to develop but I'm stuck here, USB_REQ_TYPE_CLASS works but USB_REQ_TYPE_VENDOR
doesn't. If I can recompile micropython with this enabled, tell me how should I somehow
enable CFG_TUD_VENDOR and in what file for ESP32S3 SPIRAM OCT should I edit to enable this

currently practical problem is described here for example

if stage == 1: # SETUP
# BUG USB_REQ_TYPE_VENDOR requests don't work
if bmRequestType == USB_DIR_OUT | USB_REQ_TYPE_CLASS | USB_REQ_RECIP_DEVICE:
#if bmRequestType == USB_DIR_OUT | USB_REQ_TYPE_VENDOR | USB_REQ_RECIP_DEVICE:
# Data coming from host, prepare to receive it.
return memoryview(usb_buf)[:wLength]

Code Size

No response

Implementation

I hope the MicroPython maintainers or community will implement this feature

Code of Conduct

Yes, I agree

CANDIDATE · PULL REQUEST

esp32: Enable support for machine.USBDevice.

mergedby sebromeroopened 2024-12-04updated 2024-12-16
port-esp32

Summary

Recently support for machine.USBDevice was kindly added to the ESP32 port. However it's not currently enabled in the runtime yet by default.
After discussing it (#15564) I followed the recipe of @TomFahey and the suggestions of @andrewleech to enable the USB runtime support support the same way it's been added e.g. to the RP2 port.

Testing

I tested it on an Arduino Nano ESP32 board by emulating a HID keyboard. In fact I had a whole class of students testing it and it worked beautifully.

Trade-offs and Alternatives

I'm not sure how this affects the binary size but I would expect a minimal increase.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied