#raw HID
1 messages · Page 1 of 1 (latest)
I have an RP2040-based board (the Adafruit MacroPad) and am trying to get bi-directional communication working over Raw HID.
So far, i've created a new usb_hid Device with the following descriptor (which I pulled from a TinyUSB example) in my boot.py:
RAWHID_REPORT_DESCRIPTOR = bytes((
0x06, 0x00, 0xFF, # Usage Page (Vendor Defined 0xFF00)
0x09, 0x01, # Usage (0x01)
0xA1, 0x01, # Collection (Application)
0x09, 0x02, # Usage (0x02)
0x15, 0x00, # Logical Minimum (0)
0x26, 0xFF, 0x00, # Logical Maximum (255)
0x75, 0x08, # Report Size (8)
0x95, 0x40, # Report Count (64)
0x81, 0x02, # Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x09, 0x03, # Usage (0x03)
0x15, 0x00, # Logical Minimum (0)
0x26, 0xFF, 0x00, # Logical Maximum (255)
0x75, 0x08, # Report Size (8)
0x95, 0x40, # Report Count (64)
0x91, 0x02, # Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0xC0, # End Collection
))
raw_hid = usb_hid.Device(
report_descriptor=RAWHID_REPORT_DESCRIPTOR,
usage_page=0xFF,
usage=0x01,
report_ids=(0,),
in_report_lengths=(64,),
out_report_lengths=(64,),
)
usb_hid.enable((raw_hid,))
And using the following program on my host machine (https://github.com/molejar/rawHID) I am successfully able to transmit OUT reports from my board to the host with the following code.py:
device = usb_hid.devices[0]
device.send_report(bytes(64))
And I successfully see the report in the rawHID program.
However, I can't seem to get the IN reports working (that is, reports sent from the host computer to the board).
With the following code.py:
device = usb_hid.devices[0]
while True:
report = device.get_last_received_report()
if report is not None:
print(report)
I get nothing printed when I send a report from the host. I have also tried explicitly specifying the report ID of 0 and still nothing.
Was wondering if anyone had some ideas? the documentation on Raw HID in CircuitPython is a bit sparse, so I could be doing something totally wrong (and I am rather new to HID).
Thanks in advance.
also, i'm about to step away for lunch so might not see replies here for an hour or two, but let me know if there's any other info I can provide.
OUT reports do work -- they are used for keyboard LEDs, and that works. I wrote the CircuitPython implementation. I don't remember how/if I tested raw HID. Your report descriptor seems to be ok at first glance. I would debug this by putting some debugging print statements in tud_hid_set_report_cb() in https://github.com/adafruit/circuitpython/blob/7dcec38ba0afb17f4502ecf786655744eb3e72c6/shared-module/usb_hid/Device.c#L294 to see if that gets called when you send, and if so, whether the length is right, etc. If you open an issue in https://github.com/adafruit/circuitpython and include your test programs on the host and CircuitPython side, I can take a look at this. Or if you feel up to building your own CircuitPython, you can do some initial debugging.
Thanks, I’ll try some further debugging on my end and open a GH issue if I’m still stuck.
What are you using on the host side to generate reports. Is it a test tool or library? I would be interested in seeing a test script if you have one
I’ve tried both https://github.com/molejar/rawHID which is a debugging tool, as well as a quick Golang script I wrote that uses https://pkg.go.dev/github.com/bearsh/hid
Both seem to think they’ve successfully sent the report to the board (at least, I get no errors and the Go library tells me it wrote 64 bytes), but I get nothing on the board side
Can send you the script I wrote in a few min
Fwiw ^ is a bit of a pain to compile, it used CGO so you’ll need a valid C compiler on your path to work.
I may give node HID a shot as well since it seems more well maintained
thanks, the molejar tool seems like the easiest for an initial trial. Not sure how soon I can get to this but I am interested in fixing it if it's broken.
On LInux https://github.com/todbot/hidapitester looks good; todbot is active here
ah yeah I think todbot's GH issue comment is what pointed me to the TinyUSB raw hid code actually. https://github.com/adafruit/circuitpython/issues/5197#issuecomment-955086563
I didn't initially create a GH issue for this because I wasn't sure if there was an actual CircuitPython bug or it was just me configuring things improperly. But happy to create a new issue for this if it's easier for tracking.
ok, I've duplicated the issue on Linux with hidapitester. I can read reports, but sent reports don't seem to be retrieved. I'll do some debugging
I know what the problem is and am consulting with the TinyUSB author.
The issue is known and is described here: https://github.com/hathach/tinyusb/issues/1095
I am investigating some workarounds; also the TinyUSB author is off for a few days, so I'll wait to consult when he's back.
Thanks, i'm blocked on a project by this currently so a workaround would be appreciated, but also can wait a few days
i am working on a heuristic to detect the case when the report ID might be 0 and there is a matching device
Ah yeah, I think for raw hid, if you don't specify a report ID (which I read is recommended for raw HID) then the ID might show up as 0 technically. Still don't fully understand why you can't use report ID's with raw HID, I was just going off of https://github.com/NicoHood/HID/blob/master/src/SingleReport/RawHID.h#L31-L32 mainly
I am not sure "raw" is actually special-cased, except in the sense that the driver on the host side does not try to parse what is coming in. "Raw" might be a term of usage.
Here is a test UF2 for the macropad that might work for you.
i will be afk for an hour or so.
cool I can try flashing it later today
https://github.com/adafruit/circuitpython/pull/7806, including some test programs
great, thank you for the quick turnaround here!
@waxen bluff I see the PR got merged, what's the release cycle like/when can I expect it to be in a circuitpython release?
It will be in beta.1, which will be out quite soon, but if you pick an "Absolute Newest" release, it will be in there now.
beta.1 is now out
Great I have some time this weekend to check it out. Just to double check, I can have one “raw hid” device alongside a traditional usb keyboard device enabled at once and they’ll behave independently correct?