I'm using micropython on the TiLDA-Mk3 -- https://badge.emfcamp.org/wiki/TiLDA_MK3
Currently, the USB HID interface only has an IN endpoint, so your HID device can only send data to the host, and can't receive data from the host. I'm interested in adding support for a USB HID OUT endpoint as well as IN.
There was a bit of discussion about this in the PR that allowed HID customization: https://github.com/micropython/micropython/pull/955
There is also an issue for this, but it quickly descended into a discussion about screen/picocom instead: https://github.com/micropython/micropython/issues/1217
Is there any kind of plan for this at the moment? I don't want to implement this, issue a PR, and discover it's not the right shape for the project.
My idea was basically to copy the basic receive interface of the pyb.USB_VCP() class, and implement it in much the same was as stmhal/usbd_cdc_interface.c for receiving over the VCP. It may also require changing the interface of the pyb.usb_mode() method because it currently assumes there's only one endpoint (what if you have a different maximum packet size or polling interval for IN vs OUT?)
I'm working on a branch here: https://github.com/philandstuff/micropy ... t-endpoint
My use case is that I'm interested in creating a FIDO U2F token from my TiLDA-Mk3. U2F uses the HID interface but requires bidirectional communication for the cryptographic challenge and response.
USB HID OUT endpoint implementation
Re: USB HID OUT endpoint implementation
I was just implementing the same stuff today and went almost exactly the same path. Luckily I found your changes before I re-implemented them all. I took your changes, added a small fix on top and created a pull request: https://github.com/micropython/micropython/pull/2448
Re: USB HID OUT endpoint implementation
Merged to master in https://github.com/micropython/micropyt ... 21f017db29 and previous 3 commits. Thanks Philip!
Re: USB HID OUT endpoint implementation
Did you manage to get a repl over HID?
just curious because it would enable complete driver-less OS support (no more inf files etc)
just curious because it would enable complete driver-less OS support (no more inf files etc)
Re: USB HID OUT endpoint implementation
I've gotten a REPL while HID mode is enabled, similar to having REPL when USB mass storage is enabled.
But that runs the REPL using usb-serial and not "over HID". What exactly do you mean by "REPL over HID"?
But that runs the REPL using usb-serial and not "over HID". What exactly do you mean by "REPL over HID"?
Re: USB HID OUT endpoint implementation
I meant routing the HID IN/OUT endpoints as in-/output for the REPL (instead of using the VCP). It would replace the VCP functionality (there wouldn't be a COM port anymore).
Pro:
- no INF file necessary (only a problem on windows systems), so no driver mess/maintenace for these platforms
Con:
- No visible COM port (in device manager), tool support
- HID can be a bit tricky (OS dependant, python support)
Using pyserial, it's quite easy to write a custom url handler (see http://pyserial.readthedocs.io/en/lates ... dlers.html).
You would then open the port with "serial_for_url" instead of "serial" (which is good practise anyway).
As an example, the url can have a form like "hid://<vid:pid>". In the implementation of this custom url handler, you'd need to handle/buffer the 64 Bytes packets rx/tx from the HID device. Examples of this can be found in the pyserial github repo.
I did this before with another microcontroller and it's just fun not to worry about distributing drivers. Plug & play - on every OS. Maybe that justifies the effort it needs...
Pro:
- no INF file necessary (only a problem on windows systems), so no driver mess/maintenace for these platforms
Con:
- No visible COM port (in device manager), tool support
- HID can be a bit tricky (OS dependant, python support)
Using pyserial, it's quite easy to write a custom url handler (see http://pyserial.readthedocs.io/en/lates ... dlers.html).
You would then open the port with "serial_for_url" instead of "serial" (which is good practise anyway).
As an example, the url can have a form like "hid://<vid:pid>". In the implementation of this custom url handler, you'd need to handle/buffer the 64 Bytes packets rx/tx from the HID device. Examples of this can be found in the pyserial github repo.
I did this before with another microcontroller and it's just fun not to worry about distributing drivers. Plug & play - on every OS. Maybe that justifies the effort it needs...
Re: USB HID OUT endpoint implementation
Thanks for the explanation. That does sound cool.