hid-tools: how to reply to output report?

Filipe Laíns lains at riseup.net
Sat Apr 9 16:30:51 UTC 2022


On Sat, 2022-04-09 at 16:19 +0200, Silvan Jegen wrote:
> Hi
> 
> Not sure this is the right list to ask but I have a question regarding
> the hid-tools code at https://gitlab.freedesktop.org/libevdev/hid-tools.
> 
> To familiarise myself with USB HID development (out of personal interest)
> I thought I would try add tests for the hid-nintendo kernel driver there. You
> can find the (non-working) code at the link below.
> 
> https://git.sr.ht/~shugyousha/hid-tools
> 
> I am currently stuck trying to get the uhid device setup for testing. Here
> is the relevant error:
> 
> ______ ERROR at setup of TestNintendoSwitchProControllerUSB.test_buttons _______
> 
> self = <tests.test_nintendo.TestNintendoSwitchProControllerUSB object at 0x7f02dc730970>
> new_uhdev = <hidtools.device.nintendo_gamepad.NintendoSwitchProControllerUSB object at 0x7f02dc785f90>
> request = <SubRequest 'context' for <Function test_buttons>>
> 
>     @pytest.fixture(autouse=True)
>     def context(self, new_uhdev, request):
>         try:
>             with HIDTestUdevRule.instance():
>                 with new_uhdev as self.uhdev:
>                     skip_cond = request.node.get_closest_marker('skip_if_uhdev')
>                     if skip_cond:
>                         test, message, *rest = skip_cond.args
>     
>                         if test(self.uhdev):
>                             pytest.skip(message)
>     
>                     self.uhdev.create_kernel_device()
>                     now = time.time()
>                     while not self.uhdev.is_ready() and time.time() - now < 5:
>                         self.uhdev.dispatch(10)
> >                   assert self.uhdev.get_evdev() is not None
> E                   AssertionError
> 
> 
> My current assumption is that this is due to the hid-nintendo driver
> failing to initialise the uhid "nintendo switch pro controller" I am
> creating for testing. I get the following errors from the driver.
> 
> [  211.681416] nintendo 0003:057E:2009.0006: failed reading SPI flash; ret=-110
> [  211.681423] nintendo 0003:057E:2009.0006: Failed to read left stick cal, using dflts; e=-110
> [  213.707716] nintendo 0003:057E:2009.0006: failed reading SPI flash; ret=-110
> [  213.707723] nintendo 0003:057E:2009.0006: Failed to read right stick cal, using dflts; e=-110
> [  215.734417] nintendo 0003:057E:2009.0006: failed reading SPI flash; ret=-110
> [  215.734424] nintendo 0003:057E:2009.0006: using factory cal for IMU
> [  217.761734] nintendo 0003:057E:2009.0006: failed reading SPI flash; ret=-110
> [  217.761741] nintendo 0003:057E:2009.0006: Failed to read IMU cal, using defaults; ret=-110
> [  217.761743] nintendo 0003:057E:2009.0006: Unable to read IMU calibration data
> [  219.787994] nintendo 0003:057E:2009.0006: Failed to set report mode; ret=-110
> [  219.788161] nintendo 0003:057E:2009.0006: probe - fail = -110
> [  219.788172] nintendo: probe of 0003:057E:2009.0006 failed with error -110
> 
> From what I can tell, the hid-nintendo driver is sending an USB HID
> output report[0] to the uhid driver and then expects to get a certain
> input report back that never arrives, resulting in the timeout error
> -110[1]. The reason for the timeout (I think) is that  my uhid device
> doesn't send the report back that the hid-nintendo driver expects. The
> timeout causes a failure in probe, which I assume results in the input
> nodes not being created for my uhid device (this is the reason for the
> AssertionError above).
> 
> Does somebody know how can I send the expected reply to the output report
> from my uhid device back to the hid-nintendo driver?
> 
> Any pointers are highly appreciated!
> 
> 
> Cheers,
> 
> Silvan
> 
> [0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/hid/hid-nintendo.c?h=v5.17#n2216
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/hid/hid-nintendo.c?h=v5.17#n591

Hi Silvan,

You probably want set the output_report[0] callback to handle the report the
driver sent, and will probably need to use call_input_event[1] to send data back
to the driver there.

[0] https://gitlab.freedesktop.org/libevdev/hid-tools/-/blob/master/hidtools/uhid.py#L488
[1] https://gitlab.freedesktop.org/libevdev/hid-tools/-/blob/master/hidtools/uhid.py#L307

Cheers,
Filipe Laíns
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <https://lists.freedesktop.org/archives/input-tools/attachments/20220409/30cc0aaa/attachment.sig>


More information about the Input-tools mailing list