#raw HID

1 messages · Page 1 of 1 (latest)

inner night
#

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.

waxen bluff
#

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.

inner night
waxen bluff
inner night
#

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

inner night
#

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

waxen bluff
#

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.

waxen bluff
inner night
#

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.

waxen bluff
#

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

waxen bluff
#

I know what the problem is and am consulting with the TinyUSB author.

waxen bluff
#

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.

inner night
#

Thanks, i'm blocked on a project by this currently so a workaround would be appreciated, but also can wait a few days

waxen bluff
#

i am working on a heuristic to detect the case when the report ID might be 0 and there is a matching device

inner night
waxen bluff
#

i will be afk for an hour or so.

inner night
#

cool I can try flashing it later today

waxen bluff
inner night
inner night
#

@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?

waxen bluff
waxen bluff
#

beta.1 is now out

inner night
# waxen bluff 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?

waxen bluff
#

they should; I only tested just the raw device (I should have tested both). The main point is that the raw device has a report ID of zero, which means no report ID.

#

that is I just tested one device with usb_hid.enable()