USB HID device feature reports #17410
Unanswered
jef41
asked this question in
Libraries & Drivers
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I think I have added functionality to the USB drivers packages to respond to USB HID feature report requests, please help me sense check.
I am in the process of building a DC-DC 12V UPS with a USB interface. The smart/USB part is to be handled by a RP2040/Pico board operating as a HID Power Deivce. The examples at:
https://github.com/micropython/micropython-lib/tree/master/micropython/usb
have got me a good way along the way, but in its present form these packages do not support Feature reports (in contrast to Input or Output reports). I believe I have correctly implemented responses to Get Feature reports. In general my approach seems to work, Windows, Ubuntu, macOS recognise the device as a UPS, if I change the USB vendor & product ID (to a vendor supported by Synology) a Synology NAS recognises the device as a UPS. I would like to ask if anyone here has any opinion or suggestions for improvement on how I have implemented this, or even if I am going about this the wrong way entirely. I still count myself as pretty new to MicroPython, so any suggestions or pointers on style or approach would be really helpful.
I created a class UPSHIDInterface(HIDInterface) and in that class, from HIDInterface I have overridden this (abbreviated) section:
to trap and pass the get feature report request and pass to a handler method in the UPSHIDInterface class:
that handler then matches the requested report and returns relevant data:
I also wanted to add an additional string descriptor which stores a string description of the type of battery present in the UPS (I could have repurposed the configuration_str or interface_str, but that seems a little too hacky/easy). So I also override the usb.device.hid.desc_cfg method adding a few lines after interface_str:
I modified the class to accept the additional parameter and again, this seems to work, but I am not sure if there is a better place to add the additional string(s). My codebase is quite messy at the moment as I am still figuring things out, but if it helps for more context:
https://gist.github.com/jef41/d3179510a7537c7b7fc704585b0a5561
Apologies if there is a lot to digest here, I have taken a deep dive into a new topic and fear I may be making things overly complex. If anyone has any feedback I'd be pleased to hear it, thanks
Beta Was this translation helpful? Give feedback.
All reactions