Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

host_hid mouse data displaced #442

Closed
dshadoff opened this issue May 24, 2021 · 63 comments
Closed

host_hid mouse data displaced #442

dshadoff opened this issue May 24, 2021 · 63 comments
Labels
Milestone

Comments

@dshadoff
Copy link
Contributor

dshadoff commented May 24, 2021

Some wired mice (such as the official Raspberry Pi mouse) work with the host_hid USB example code in pico-examples - in fact, it seems that at the moment, only wired mice are recognized (although this is not the issue I wish to report here).

At least some wired mice which have side buttons (i.e. back/forward) have displaced data:

  • button presses appear in the (hid_mouse_report_t).x element rather than (hid_mouse_report_t).button;
  • x movement appears in (hid_mouse_report_t).y rather than (hid_mouse_report_t).x .
  • (hid_mouse_report_t).button remains 1 (i.e. left button pressed)

(note: the mouse works fine on a RPi 400)

I am reporting this here as pico-sdk holds a non-current version of tinyusb, and it doesn't seem to be straightforward to test with the current tinyusb on pico hardware at the moment.

This may be solved with the newer version of tinyusb in pico-sdk 1.2.0 ... this issue can serve as a placeholder until that is available for test; if pico-sdk and tinyusb are in sync at that time (and if the issue is not yet resolved), I will be happy to report the issue upstream. I am also happy to gather any diagnostic information required (if the process is explained).

For the moment, the existence of a report may be helpful to other users, to indicate current known system limitations.

@kilograham
Copy link
Contributor

please try with tinyusb-0.10.0 branch of this repo

@kilograham kilograham added this to the none milestone May 31, 2021
@dhalbert
Copy link
Contributor

Tagging @hathach

@dshadoff
Copy link
Contributor Author

dshadoff commented Jun 1, 2021

Having some trouble actually testing this.

I tried this by re-cloning the pico-sdk branch tinyusb-0.10.0 (in the original pico-sdk location), followed by rebuilding pico-examples.

When I first ran "cmake -B build" in pico-examples, a CMake warning came back, requiring me to go to the pico-sdk repo and run "git submodule update --init", in order to build any tinyusb examples (which I did).

I am assuming that this checked out the correct version of raspberrypi/tinyusb into pico-sdk/lib/tinyusb, although I wasn't able to find the commit ID on the expected branches. (commit ID was a long number terminating in "934cd935")

The build failed during the build of the tinyusb sources, in usb/device/dev_audio_headset, so I'm wondering if perhaps the link in the pico-sdk/lib/tinyusb on the tinyusb-0.10.0 branch is not fetching an appropriate version of the tinyusb module...

@kilograham
Copy link
Contributor

ah - yeah, there isn't a checked in version o pico-examples to match tinyusb-0.10.0 (it has changed though)

you should be able to build from the examples/device directory in tinyusb though with PICO_SDK_PATH set.

@dshadoff
Copy link
Contributor Author

dshadoff commented Jun 1, 2021

To be clear, do you mean to:
cd (base)/pico-sdk/lib/tinyusb/examples/device
and then

cmake -B build
cd build
make

...Because this had problems during the cmake step:

CMake Error at cdc_msc_freertos/CMakeLists.txt:19 (message):
  Invalid FAMILY specified:


-- Configuring incomplete, errors occurred!

@kilograham
Copy link
Contributor

that's a weird error (that makes me think you don't have the latest pico-0.10.0 tinyusb code)

That said, you need to specify a FAMILY and a BOARD e.g.

@kilograham
Copy link
Contributor

cmake -DFAMILY=rp2040 -DBOARD=raspberry_pi_pico' -B build

you can use -DBOARD=pico_sdk too to just follow PICO_BOARD setting

@dshadoff
Copy link
Contributor Author

dshadoff commented Jun 1, 2021

That failed in a different way.

As for the version of the pico-0.10.0 tinyusb code, I cloned the tinyusb-0.10.0 branch of pico-sdk last night, and ran "git submodule update --init" which brought in whatever version was linked from lib/tinyusb in that branch... but I too was unclear whether it was the correct one.

Here is the most recent output:

Using PICO_SDK_PATH from environment ('/home/pi/devel/pico/pico-setup/pico/pico-sdk')
PICO_SDK_PATH is /home/pi/devel/pico/pico-setup/pico/pico-sdk
Defaulting PICO_PLATFORM to rp2040 since not specified.
Defaulting PICO platform compiler to pico_arm_gcc since not specified.
-- Defaulting build type to 'Release' since not specified.
PICO compiler is pico_arm_gcc
-- The C compiler identification is GNU 7.3.1
-- The CXX compiler identification is GNU 7.3.1
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/arm-none-eabi-gcc
PICO target board is pico.
Using board configuration from /home/pi/devel/pico/pico-setup/pico/pico-sdk/src/boards/include/boards/pico.h
-- Found Python3: /usr/bin/python3.7 (found version "3.7.3") found components: Interpreter 
CMake Warning at ../../../../src/rp2_common/tinyusb/CMakeLists.txt:14 (message):
  PICO_TINYUSB_PATH specified but content not present.


Using PICO_EXAMPLES_PATH from environment ('/home/pi/devel/pico/pico-setup/pico/pico-examples')
-- Configuring done
CMake Error at net_lwip_webserver/CMakeLists.txt:16 (add_executable):
  Cannot find source file:

    /home/pi/devel/pico/pico-setup/pico/pico-sdk/lib/tinyusb/lib/lwip/src/core/altcp.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx


-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

@dshadoff
Copy link
Contributor Author

dshadoff commented Jun 1, 2021

Actually I realized...
The example I was looking to use is found in host, not device (host hid mouse device, as per the issue title).
So building in examples/device would appear to be incorrect.

When building in examples/host, it also failed (but in a different way):
cmake was fine
But make failed:

Scanning dependencies of target raspberry_pi_pico-cdc_msc_hid
[ 20%] Building C object cdc_msc_hid/CMakeFiles/raspberry_pi_pico-cdc_msc_hid.dir/src/hid_app.c.obj
/home/pi/devel/pico/pico-setup/pico/pico-sdk/lib/tinyusb/examples/host/cdc_msc_hid/src/hid_app.c:26:10: fatal error: bsp/board.h: No such file or directory
 #include "bsp/board.h"
          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [cdc_msc_hid/CMakeFiles/raspberry_pi_pico-cdc_msc_hid.dir/build.make:63: cdc_msc_hid/CMakeFiles/raspberry_pi_pico-cdc_msc_hid.dir/src/hid_app.c.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:1631: cdc_msc_hid/CMakeFiles/raspberry_pi_pico-cdc_msc_hid.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

@kilograham
Copy link
Contributor

I don't think i realized you were building the standalone "tinyusb way" from within the tinyusb submodule of pico-sdk.
I assumed you were building from a standalone tinyusb depo pointing at a standalone pico-sdk via PICO_SDK_PATH

in any case, there pico-sdk->tinyusb did not have the latest submodule commit reference; i have updated

@dshadoff
Copy link
Contributor Author

dshadoff commented Jun 2, 2021

No, I had only been using the release version of pico-SDK, pico-examples, etc. until you asked me to test on a branch. I wouldn't feel comfortable opening an issue against anything but the release version.

I have good news/bad news to report:
First, I am now able to build the pico-sdk/lib/tinyusb/examples/host sources.

However, when I run the example - which should report mouse movements when I have a mouse plugged in - I get the following output with each of the mice I try - including the official Raspberry Pi mouse which worked fine on the release version (but didn't have forward/back buttons on the side).

----------------------------------------------------
TinyUSB Host Example
If you find any bugs or problems, feel free to open
an issue at https://github.com/hathach/tinyusb
----------------------------------------------------

This Host demo is configured to support:
  - RTOS = Raspberry Pi Pico SDK

*** PANIC ***

ep 0 in was already available

@hathach
Copy link
Contributor

hathach commented Jun 2, 2021

@dshadoff can you clone the upstream and cd to https://github.com/hathach/tinyusb/tree/master/examples/host/cdc_msc_hid then

make BOARD=raspberry_pi_pico all

then copy the uf2 to pico to test with.

@dshadoff
Copy link
Contributor Author

dshadoff commented Jun 2, 2021

OK, I interpreted that as:

cd (parent of pico-sdk)
git clone git://github.com/hathach/tinyusb
cd tinyusb/examples/host/cdc_msc_hid
make BOARD=raspberry_pi_pico all

This creates a separate tinyusb repository, adjacent to pico-sdk, and on the master git branch (which is more current than 0.10.0, as it had a commit as recently as 9 hours ago). Also, my pico-sdk is still on the tinyusb-0.10.0 branch.

Results are mostly good news:

The build went fine
The execution does not crash as my previous attempt did.

  1. Raspberry Pi official mouse works as well as the previous pico-sdk examples did.
  2. Logitech wireless mouse is still not recognized at all.
  3. The wired mouse with forward/back side buttons works better than the previous release, but still not completely correctly:
  • all 4 buttons now are recognized correctly and do not cause any confusing 'X' or 'Y' movements
  • 'X' movements appear fine, except that the 'Y' value is either "0" (for positive X movement) or "-1" (for negative X movement)
  • 'Y' movement is not reported in the report->Y, but rather in the wheel value
    So for some reason, this mouse appears as though it may be reporting 16-bit X and Y values ? In any case, it works fine on Windows and Linux machines...

@hathach
Copy link
Contributor

hathach commented Jun 2, 2021

sure there is a bug, now let test with the logitech mouse

  1. can you uoload its report descriptor as txt file. If you are in linux you could dump it with sudo usbhid-dump -d cafe | grep -v : | xxd -r -p | hidrd-convert -o spec replace cafe with logitech vid
  2. now run compile again with log enable (need to clean first)
make BOARD=raspberry_pi_pico clean
make BOARD=raspberry_pi_pico LOG=3 all

then post your log as txt file for analyzing.

you could also post the log with the 3) wired mouse fwd/bck not work right, but that would be later or better a separated issue.

@dshadoff
Copy link
Contributor Author

dshadoff commented Jun 2, 2021

What do you mean "logitech vid" ? How would I find that ?

Specifically, the difference in output between no USB devices plugged into the RPi400 and with only the Logitech unifying receiver plugged in, is the following (from usbhid-dump)... perhaps the logitech vid can be derived from this:

001:011:002:DESCRIPTOR         1622608876.558106
 06 00 FF 09 01 A1 01 85 10 95 06 75 08 15 00 26
 FF 00 09 01 81 00 09 01 91 00 C0 06 00 FF 09 02
 A1 01 85 11 95 13 75 08 15 00 26 FF 00 09 02 81
 00 09 02 91 00 C0 06 00 FF 09 04 A1 01 85 20 95
 0E 75 08 15 00 26 FF 00 09 41 81 00 09 41 91 00
 85 21 95 1F 09 42 81 00 09 42 91 00 C0

001:011:001:DESCRIPTOR         1622608876.565384
 05 01 09 02 A1 01 85 02 09 01 A1 00 95 10 75 01
 15 00 25 01 05 09 19 01 29 10 81 02 95 02 75 0C
 16 01 F8 26 FF 07 05 01 09 30 09 31 81 06 95 01
 75 08 15 81 25 7F 09 38 81 06 95 01 05 0C 0A 38
 02 81 06 C0 C0 05 0C 09 01 A1 01 85 03 95 02 75
 10 15 01 26 FF 02 19 01 2A FF 02 81 00 C0 05 01
 09 80 A1 01 85 04 95 01 75 02 15 01 25 03 09 82
 09 81 09 83 81 00 75 06 81 03 C0 06 BC FF 09 88
 A1 01 85 08 95 01 75 08 15 01 26 FF 00 19 01 29
 FF 81 00 C0

001:011:000:DESCRIPTOR         1622608876.569854
 05 01 09 06 A1 01 95 08 75 01 15 00 25 01 05 07
 19 E0 29 E7 81 02 81 03 95 05 05 08 19 01 29 05
 91 02 95 01 75 03 91 01 95 06 75 08 15 00 26 FF
 00 05 07 19 00 2A FF 00 81 00 C0

@dshadoff
Copy link
Contributor Author

dshadoff commented Jun 2, 2021

Here is the capture with Logitech unifying receiver.
The HID example initializes, but does not react to any mouse movement or clicking (with or without logging on), but there was some useful-looking log output of the initialization.

logitech_pico_log.txt

I've also captured the log from the other mouse (not attached), but I agree that Logitech is a higher-value fix. (The other mouse was only bought because Logitech fix didn't seem close).

@hathach
Copy link
Contributor

hathach commented Jun 2, 2021

What do you mean "logitech vid" ? How would I find that ?

@dshadoff run lsusb will give you a list of your attached device to your PC. Then run

lsusb -v -d cafe:

to get the configuration descriptor of your logitech then following command to get the report descriptor in readable format

sudo usbhid-dump -d cafe | grep -v : | xxd -r -p | hidrd-convert -o spec

Both are required for further troubleshooting.

@dshadoff
Copy link
Contributor Author

dshadoff commented Jun 2, 2021

OK, lsusb provides the following:

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 04d9:0007 Holtek Semiconductor, Inc. 
Bus 001 Device 003: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

From the above, I am assuming that instead of "cafe", I should be using the "046d" portion of the Logitech device ID ?
The output from that is in this file:
lsusb-Logitech.txt

Running the final command I run into a problem, as "hidrd-convert" is not found on the Pi 400 I am using; where can I obtain it ?

@dshadoff
Copy link
Contributor Author

dshadoff commented Jun 2, 2021

Never mind, was able to locate it and get it with:
sudo apt-get install hidrd usbutils

The output is attached here:
hidrd-Logitech.txt

@v9938
Copy link

v9938 commented Jun 3, 2021

Hi hathach

I have the same problem.
tinyusb-0.10.1 didn't fix it.

I used the USB packet analyzer.
image

It seems that GET_DESCRIPTOR(DEVICE) did not receive the requested size.
I think it misjudged the length of the IN packet of Raspberry Pi Pico.

If there is anything we can do to help, please request it.

@dshadoff
Copy link
Contributor Author

dshadoff commented Jun 3, 2021

@v9938 To clarify, when you say "the same problem", are you referring to:
a) The original problem, where a wired mouse with side buttons has offset data in X/Y reports ? or
b) The issue where a wireless mouse (in my case, Logitech) does not process data at all (which @hathach asked for more information, roughly 36 hours ago) ?
These should probably be separate issues (but now that we're here, I'm not clear on how to split/splice them).
My original thought had been to wait for pico-sdk v1.2.0 to be released, and then go upstream to tinyusb, once they were roughly in sync.

@v9938
Copy link

v9938 commented Jun 3, 2021

Hi dshadoff
My answer ’B’.
I am trying to get this problem solved with pico-sdk branch tinyusb-0.10.1.

Of course, I can discuss it on another topic.
If possible, I would like to wait for hathach's judgment.

@dshadoff
Copy link
Contributor Author

dshadoff commented Jun 3, 2021

@kilograham and @hathach should decide how to proceed. I just wanted to clarify your comment.

@hathach
Copy link
Contributor

hathach commented Jun 4, 2021

@dshadoff thanks for the info, I am also able to reproduce the issue with one of my laying dongle and spent a couple hours troubleshooting it. It needs a bit of works, here is what I found so far.

Overall, since I want to implement double buffering at least for host in the near future, I feel that keep fixing the RP2040-E5 walkaround doesn't justify the effort. It is best to use implement double buffer to get in sync with hardware. Though I need a bit more time to separate the hcd and dcd endpoint transfer, since it is easy to mess up the device side just now. Better to do it in incremental step. I will update this topic whenever there is a new PRs for this.

image

@lurch
Copy link
Contributor

lurch commented Jun 4, 2021

Is raspberrypi/tinyusb#7 relevant here @hathach ? Or should that PR be closed already?

@hathach
Copy link
Contributor

hathach commented Jun 7, 2021

Is raspberrypi/tinyusb#7 relevant here @hathach ? Or should that PR be closed already?

You should ask the OP of that issue. The host is current has some bugs related to the E4 anyway, I will try to see if I could get it all resolved soon enough.

@dshadoff
Copy link
Contributor Author

dshadoff commented Jun 9, 2021

I know that you're looking at the wireless Logitech logs (and I hope progress is going well), but now I have also captured the details for the original wired 4-button mouse (where X and Y appear to be 16-bit values instead of 8-bit, so 'rpt->Y' contains a sign-extended MSB of X, and the actual Y value is in the 'rpt->wheel' data position):

lsusb says:
Bus 001 Device 005: ID 18f8:1286 [Maxxter]

The hidrd output for the device is here:
wired_4button_hidrd.txt

And the output from the special (LOG=3) build of the host example is here:
(For movements, I moved left, then right, then up, then down, then pressed left button, right button, back button, and forward button).
wired_4button_pico_log.txt

@hathach
Copy link
Contributor

hathach commented Jun 9, 2021

Thanks any data available in advance is good when I switch back to work on tinyusb (on other work just now).

@hathach
Copy link
Contributor

hathach commented Jun 13, 2021

I basically understand what you are asking me, but it seems I need deeper knowledge of how the library works. The example is certainly not showing how to do this. Where can I look for more information ?

The report representation format (which byte for which usage) is detailed in report descriptor. HID parser is very complicated (most complicated descriptor of USB), and TinyUSB basically cannot parse it all. It currently only provide a very simple parser to parse usage_page and usage of each report ID. For more than that, application have to parse it themself, the report descriptor is available with the tuh_hid_mount_cb()

For mouse and keyboard, we can actually use boot interface which guarantee to work on all mouse/keyboard. For boot support, I will do it later on when having time. If you want to understand more about HID, check out the USB HID specs, it is rather short and simple.

For now, I will wrap up my work here with the double buffered. Others are unrelated issue, and should be addressed separately.

@hathach
Copy link
Contributor

hathach commented Jun 17, 2021

@dshadoff I made another branch to force/set boot protocol for keyboard, mouse device here https://github.com/hathach/tinyusb/tree/more-hid-host (since double buffered branch is under review). This should solve your issue with mis-matched report with your logitech/wired mouse.

@v9938
Copy link

v9938 commented Jun 17, 2021

@dshadoff I immediately tested it.
It was an improvement over the previous version.
It was a case of three things.

  1. PANIC occurred
....
A device with address 1 is unmounted
HID device address = 1, instance = 0 is unmounted
HID device address = 1, instance = 1 is unmounted
HID device address = 1, instance = 2 is unmounted

*** PANIC ***

ep 0 in was already available
  1. RESET? occurred
....
A device with address 1 is mounted
----------------------------------------------------
TinyUSB Host Example
If you find any bugs or problems, feel free to open
an issue at https://github.com/hathach/tinyusb
----------------------------------------------------

This Host demo is configured to support:
  - RTOS = Raspberry Pi Pico SDK
----------------------------------------------------
TinyUSB Host Example
If you find any bugs or problems, feel free to open
an issue at https://github.com/hathach/tinyusb
----------------------------------------------------

This Host demo is configured to support:
  - RTOS = Raspberry Pi Pico SDK
----------------------------------------------------
TinyUSB Host Example
If you find any bugs or problems, feel free to open
an issue at https://github.com/hathach/tinyusb
----------------------------------------------------

This Host demo is configured to support:
  - RTOS = Raspberry Pi Pico SDK
HID device address = 1, instance = 0 is mounted
HID has 1 reports and interface protocol = Keyboard
HID device address = 1, instance = 1 is mounted
HID has 4 reports and interface protocol = Mouse
HID device address = 1, instance = 2 is mounted
HID device address = 1, instance = 0 is mounted
  1. usbh_edpt_xfer 386: ASSERT FAILED occurred
....
  - RTOS = Raspberry Pi Pico SDK
HID device address = 1, instance = 0 is mounted
HID has 1 reports and interface protocol = Keyboard
HID device address = 1, instance = 1 is mounted
HID has 4 reports and interface protocol = Mouse
HID device address = 1, instance = 2 is mounted
HID has 3 reports and interface protocol = None
A device with address 1 is mounted
A device with address 1 is unmounted
HID device address = 1, instance = 0 is unmounted
HID device address = 1, instance = 1 is unmounted
HID device address = 1, instance = 2 is unmounted
HID device address = 1, instance = 0 is mounted
HID has 1 reports and interface protocol = Keyboard
usbh_edpt_xfer 386: ASSERT FAILED
HID device address = 1, instance = 1 is mounted
HID has 4 reports and interface protocol = Mouse
usbh_edpt_xfer 386: ASSERT FAILED
HID device address = 1, instance = 2 is mounted
HID has 3 reports and interface protocol = None
usbh_edpt_xfer 386: ASSERT FAILED
A device with address 1 is mounted
A device with address 1 is unmounted
HID device address = 1, instance = 0 is unmounted
HID device address = 1, instance = 1 is unmounted
HID device address = 1, instance = 2 is unmounted

@hathach
Copy link
Contributor

hathach commented Jun 17, 2021

@v9938 can you provide the context for each case, which device you use to test, and what you have done to reproduce the issue and how often it happens. 1 and 2 loom like you have unstable power or usb connection

@v9938
Copy link

v9938 commented Jun 17, 2021

@hathach I re-tested it.
It seems to depend on the version of the Logicool Unifiy receiver.

Case1 PANIC occurred
Firmware version 024.007.00030
image

Case3: usbh_edpt_xfer 386: ASSERT FAILED occurred
Firmware version 012.010.00032
image

More information...
When each receiver was connected to a Windows PC, the USB packets were as follows
The max size of EP0 for GET_DESCRIPTOR(device) differs between Ver012 and Ver024.

@hathach
Copy link
Contributor

hathach commented Jun 17, 2021

@v9938 please put your log into its own txt and attached it instead of posting it here. Long log in the comment make it difficult follow the issue. Also please use above lsusb and hidrd to post your device configuration & hid descriptor. The log you post is not easy to read at all. If you are using windows try usbtreeview https://www.uwe-sieber.de/usbtreeview_e.html then post your device configuration and hid descriptor as attached txt.

@dshadoff
Copy link
Contributor Author

@hathach I tried with both of the mice, and the more-hid-host branch had problems; I have captured the logs.

Mouse 1: Maxxster (wired mouse with side buttons):

When connected, it did not appear to respond at all.
I am attaching the device descriptions you mentioned previously (vid, usbhid), a capture of output by normal build (NOLOG), and a capture with output from build with LOG=3 (LOG3):
maxxster_vid.txt
maxxster_usbhid_18f8.txt
maxxster_out_NOLOG.txt
maxxster_out_LOG3.txt

Mouse 2: Logitech (unifying receiver):

Connected, but "couldn't find report info" for any reports when the mouse moved.
I am attaching the device descriptions you mentioned previously (vid, usbhid), a capture of output by normal build (NOLOG), and a capture with output from build with LOG=3 (LOG3):
logitech_vid.txt
logitech_usbhid_046d.txt
logitech_out_NOLOG.txt
logitech_out_LOG3.txt

@v9938
Copy link

v9938 commented Jun 17, 2021

@hathach Thanks for the quick response.
I have attached logs from usbtreeview.

Firmware version 012.010.00032(Model No:C-U007)
Unifiying_012_010_00032.txt

Firmware version 024.007.00030(Model No:C-U008)
Unifiying_024_007_00030.txt

@hathach
Copy link
Contributor

hathach commented Jun 18, 2021

@v9938 thanks for the configuration descriptor, I would also need the hid descriptor as well. I don't know how to that on windows. Maybe you should try to run usbtreeview with administrator mode to see if it could. Since we have the txt file now, could you remove your super long log in above post to make this issue easier to follow.

@dshadoff thank for the detail feedback, I will check this out later on.

@v9938
Copy link

v9938 commented Jun 19, 2021

@hathach It seems to be difficult to dump the raw data of HID descriptor on windows.
I have dumped the HID descriptor using usbhid-view.
If there is any other missing information, please reply.

HID descriptor version 012.010.00032(Model No:C-U007)
HIDdescriptor_for_C-U007.txt

HID descriptor version 024.007.00030(Model No:C-U008)
HIDdescriptor_for_C-U008.txt

@dshadoff
Copy link
Contributor Author

I looked again at this on the weekend (on the more-hid-host branch), also with a couple of other mice.

When compiled with LOG=1, the reports from Logitech (and also another wireless mouse) seemed to be providing correct data in the reports, and consistent with boot mouse format (i.e. buttons, x, y, scroll wheel - each 8-bit signed values).

The only problem in those cases was:
"Couldn't find the report info for this report !"
So if this issue can be corrected, it should work with most mice I think.

(However, the Maxxster appeared not to produce any reports... but I don't care as much about this mouse if the others are working)

@hathach
Copy link
Contributor

hathach commented Jun 21, 2021

thanks @v9938 and @dshadoff for providing more info and log, I am currently switched to other work. Will check this out again later on whenever possible.

@hathach
Copy link
Contributor

hathach commented Jun 28, 2021

@dshadoff @v9938 I have fixed an bug with host hid set protocol, and also update example to better use boot protocol. This should work with all keyboard/mouse with boot interface. Let me know if this would work for you.

@dshadoff
Copy link
Contributor Author

I tested with several mice - including the two mentioned earlier in this thread - and they all seemed to work, and to provide consistent results. Thank You !
I will be happy to close this issue when the code gets integrated into pico-sdk (until then, perhaps it can stay open in order to inform other users about status).

The only thing I noticed, was surrounding the disconnection and reconnection of mouse devices - but that appears to be the same as issue #483 opened by @v9938 , so it can be tracked there.

I will continue to test with a variety of other devices I have; if I find any issues, I will open separate issues for tracking.

@hathach
Copy link
Contributor

hathach commented Jun 29, 2021

thank for the feedback, look like I nailed it this time. For the release/update, it may take a bit of time, since I still want to do more tweak to host API but have been kept busy with other works.

@hathach
Copy link
Contributor

hathach commented Jun 30, 2021

@v9938 let me know if the new code fox issue with your devices

@v9938
Copy link

v9938 commented Jun 30, 2021

@hathach Sorry for the late feedback.
Unfortunately, there was no change in the behavior.
If there is anything I can do to help, please reply.

Model No:C-U007

HID device address = 1, instance = 0 is mounted
HID Interface Protocol = Keyboard
usbh_edpt_xfer 386: ASSERT FAILED
config_get_report_desc_complete 395: ASSERT FAILED

Model No:C-U008

*** PANIC ***

ep 0 in was already available

@hathach
Copy link
Contributor

hathach commented Jun 30, 2021

@v9938 thanks for your feedback, seem like there is still issue :( . Could you also attach both log with LOG=1 and LOG=3 for each of your device.

@v9938
Copy link

v9938 commented Jul 2, 2021

@hathach The LOG files are attached below.

Model No:C-U007
LOG=1 U007_LV1.log / LOG=3 U007_LV3.log , U007_LV3_case2.log

Model No:C-U008
LOG=1 U008_LV1.log / LOG=3 U008_LV3.log

@dshadoff
Copy link
Contributor Author

dshadoff commented Jul 2, 2021

@v9938 , these logs are related to the disconnect/reconnect issue, issue #483 ... shouldn't they be tracked there instead ?
I interpreted @hathach 's comments to be "do you see issues with the data - OTHER THAN those tracked in issue 483 ?"

@hathach
Copy link
Contributor

hathach commented Jul 4, 2021

indeed @v9938 this seems to be issue with connection, which can be either hardware and/or connection issue. To further troubleshoot it, I would suggest you to post picture of your hw set-up, also have shortest otg cable as possible etc... I don't see any abnormal connection issue with mine. I think people could then help you more with troubleshoot if it is hardware issue. I think my work here is done. Thanks both of you for testing out and giving feedback.

Update: more-host-hid pr is merged to master.

@v9938
Copy link

v9938 commented Jul 13, 2021

@hathach Sorry for the late response. There were several problems and it took a long time to prepare.
I have considered the possibility of my board being broken. I tried the same experiment again with a new pico board.
The result was no change :-(

The next picture shows the OTG cable. In both cables, the result was the same result.

The experimental setup was as shown in the next photo.

Maybe there is nothing wrong with the environment.

@hathach
Copy link
Contributor

hathach commented Jul 14, 2021

I am not good at hardware, here is my set up that work relatively well. I use another pico as picoprobe (above) also providing 5V to target (below) via pin 40.
IMG_1489

@dshadoff
Copy link
Contributor Author

dshadoff commented Nov 3, 2021

SDK version 1.3.0 release and the corresponding TinyUSB version are working fine for this.
I will close the issue now.

@dshadoff dshadoff closed this as completed Nov 3, 2021
@kilograham
Copy link
Contributor

cc @liamfraser

@dupontgu
Copy link

dupontgu commented Mar 8, 2023

Want to add my experience for anyone who is still facing this - I am seeing the exact same issue as the original post, but I think I figured out what my problem was (And I don't know if it was teased out in all the comments above).

I was mostly following this example, and there seems to be an edge case where tuh_hid_interface_protocol returns HID_ITF_PROTOCOL_MOUSE, even if the reports from that instance should be treated as "composite" reports. So in my case, process_mouse_report was getting run with the raw report, even though the first byte of that report was actually a report_id, NOT the start of the mouse data (As OP was seeing, the report ID was 0x01, making it seem like the mouse left button was always pressed). So I changed my callback to look like this (forgive the Google formatting), which checks the instance's report descriptor to see if we should expect a report_id to show up in the report. Not terribly efficient, seems to work? Constants pulled from the (HID usage tables)[https://usb.org/document-library/hid-usage-tables-14].

void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance,
                                uint8_t const* report, uint16_t len) {
  uint8_t itf_protocol = HID_ITF_PROTOCOL_NONE;
  uint8_t const* report_offset = report;

  if (hid_info[instance].report_count > 1) {
    // we know this is a composite report, so extract the id and start the reading the data one byte over
    report_offset = report + 1;
    uint8_t id = report[0];

    // find the tuh_hid_report_info_t that matches the id of the report we just received 
    for (size_t i = 0; i < hid_info[instance].report_count; i++) {
      tuh_hid_report_info_t info = hid_info[instance].report_info[i];
      if (info.report_id == id) {
        if (info.usage_page == GENERIC_DESKTOP_USAGE_PAGE) {
          if (info.usage == USAGE_MOUSE) {
            itf_protocol = HID_ITF_PROTOCOL_MOUSE;
          } else if (info.usage == USAGE_KEYBOARD) {
            itf_protocol = HID_ITF_PROTOCOL_KEYBOARD;
          }
        }
        // TODO handle other usage pages, Consume Control, etc?
        break;
      }
    }
  } else {
    itf_protocol = tuh_hid_interface_protocol(dev_addr, instance);
  }

  switch (itf_protocol) {
    case HID_ITF_PROTOCOL_KEYBOARD:
      process_kbd_report(dev_addr, (hid_keyboard_report_t const*)report_offset);
      break;

    case HID_ITF_PROTOCOL_MOUSE:
      process_mouse_report(dev_addr, (hid_mouse_report_t const*)report_offset);
      break;

    default:
      break;
  }
  //...
}

I am testing with a little portable keyboard/touchpad like this, and it appears to send mouse and Consumer Control data via the same "instance", so report_id's are used to distinguish between mouse reports and CC reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants