tinyusb icon indicating copy to clipboard operation
tinyusb copied to clipboard

Hid micro parser rc1

Open fruit-bat opened this issue 3 years ago • 9 comments

For your consideration.

Introduces a micro HID report description parser and provides an example of its use by mapping HID joystick reports. Combined with Ryzee119's mulit-hub modifications it works on an RP2040. Sorry, but it's not tested on any other architectures. On the RP2040, it works nicely with a hub hosting several joysticks.

I've tried to keep the existing tinyusb API the same but made some additions in hid_ri.h and hid_rip.h

The joystick demonstration is added to the the cdc_msc_hid example.

I have added a bunch of ceedling tests, including some for the new example code.

I've not worked on USB code before so sorry I have made mistakes or misinterpreted the spec. Most of code comes from a read through of hid1_11 spec.

I hope this helpful :-)

fruit-bat

fruit-bat avatar Feb 19 '22 22:02 fruit-bat

Closed accidentally.

fruit-bat avatar Feb 24 '22 04:02 fruit-bat

Hopefully all the tests will pass now (I've build and tried them on a 64bit environment). Also, I've removed the #include that seemed to upset some of the non-rp2040 builds. Thanks, fruit-bat

fruit-bat avatar Feb 26 '22 16:02 fruit-bat

Hihi, sorry for super late response, I have buried in work ever since the TET holiday. I will check this out as soon as I could

hathach avatar Mar 06 '22 03:03 hathach

No worries and thanks for running the builds. I think I can see what is causing the problems... I will make some changes get back to you.

fruit-bat avatar Mar 06 '22 22:03 fruit-bat

Should be ready for another run.

[I'm developing on a Raspberry Pi and I'm not sure how to get rx-elf-gcc setup... so some of the builds may still be a bit hit and miss - sorry - and hope this is ok!]

fruit-bat avatar Mar 07 '22 19:03 fruit-bat

[I'm developing on a Raspberry Pi and I'm not sure how to get rx-elf-gcc setup... so some of the builds may still be a bit hit and miss - sorry - and hope this is ok!]

I tried to compile with rx-elf-gcc. Some errors were reported shown below. Of course, it is OK by adding two options -Wno-error=unused-parameter and -Wno-error=format= for the errors to CFLAGS in examples/host/cdc_msc_hid/Makefile.

C:/tinyusb/examples/host/cdc_msc_hid/src/hid_app.c:52:46: error: unused parameter 'info' [-Werror=unused-parameter]
 void handle_kbd_report(tusb_hid_host_info_t* info, const uint8_t* report, uint8_t report_length, uint8_t report_id)
                        ~~~~~~~~~~~~~~~~~~~~~~^~~~
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_app.c: In function 'handle_mouse_report':
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_app.c:59:48: error: unused parameter 'info' [-Werror=unused-parameter]
 void handle_mouse_report(tusb_hid_host_info_t* info, const uint8_t* report, uint8_t report_length, uint8_t report_id)
                          ~~~~~~~~~~~~~~~~~~~~~~^~~~
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_app.c: In function 'handle_gamepad_report':
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_app.c:86:50: error: unused parameter 'info' [-Werror=unused-parameter]
 void handle_gamepad_report(tusb_hid_host_info_t* info, const uint8_t* report, uint8_t report_length, uint8_t report_id)
                            ~~~~~~~~~~~~~~~~~~~~~~^~~~
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_host_joy.c: In function 'tuh_hid_joystick_process_axis':
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_host_joy.c:131:11: error: unused parameter 'instance' [-Werror=unused-parameter]
   uint8_t instance,
   ~~~~~~~~^~~~~~~~
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_host_joy.c: In function 'tuh_hid_joystick_process_usages':
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_host_joy.c:154:39: error: format '%u' expects argument of type 'unsigned in
', but argument 2 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
     printf("no usage - skipping bits %u \n", jdata->report_size * jdata->report_count);
                                      ~^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                      %lu
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_host_joy.c: In function 'tusb_hid_print_simple_joysick_report':
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_host_joy.c:266:61: error: format '%d' expects argument of type 'int', but argument 5 has type 'int32_t' {aka 'long int'} [-Werror=format=]
     printf("dev_addr=%3d, instance=%3d, report_id=%3d, x1=%4d, y1=%4d, x2=%4d, y2=%4d, hat=%01X, buttons=%04X\n",
                                                           ~~^
                                                           %4ld
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_host_joy.c:270:7:
       simple_joystick->values.x1,
       ~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_host_joy.c: In function 'tusb_hid_print_simple_joysick_report':
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_host_joy.c:266:95: error: format '%X' expects argument of type 'unsigned in
', but argument 9 has type 'int32_t' {aka 'long int'} [-Werror=format=]
     printf("dev_addr=%3d, instance=%3d, report_id=%3d, x1=%4d, y1=%4d, x2=%4d, y2=%4d, hat=%01X, buttons=%04X\n",
                                                                                            ~~~^
                                                                                            %01lX
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_host_joy.c:274:7:
       simple_joystick->values.hat,
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_host_joy.c: In function 'tusb_hid_print_simple_joysick_report':
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_host_joy.c:266:109: error: format '%X' expects argument of type 'unsigned int', but argument 10 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
     printf("dev_addr=%3d, instance=%3d, report_id=%3d, x1=%4d, y1=%4d, x2=%4d, y2=%4d, hat=%01X, buttons=%04X\n",
                                                                                                          ~~~^
                                                                                                          %04lX
C:/tinyusb/examples/host/cdc_msc_hid/src/hid_host_joy.c:275:7:
       simple_joystick->values.buttons);
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

kkitayam avatar Mar 08 '22 15:03 kkitayam

Many thanks both. I tweaked my compile settings to be fussier, which I think will get rid of the problems highlighted by kkitayam.

I now get a nice clean run of

python3 tools/build_family.py rp2040

Ready for another try when you get time. Thanks for your patience.

fruit-bat avatar Mar 09 '22 22:03 fruit-bat

Please don't run the build yet, I seem to be having some problems with the ceedling tests.

fruit-bat avatar Mar 10 '22 08:03 fruit-bat

Almost certain to work this time 🤔. Ready for another try... Thanks!

fruit-bat avatar Mar 11 '22 21:03 fruit-bat