USB HID Support on Pico! #38
Replies: 80 comments
-
Posted at 2015-05-29 by @gfwilliams Just to add, the keyboard stuff is shamefully ripped off the Teensy 3 USB library - there must be a better source of USB report descriptors, but I can't find one :( |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-29 by @gfwilliams Just to add, at the moment this will only work if you power the pico from a battery, and then plug into USB after. It's an easy fix, I just forgot to do it before posting this |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-29 by @allObjects Great to see this coming along and to be here now! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-30 by the1laz Awesome news, looking forward to getting my Pico to try this on! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-04 by Stev That's pretty neat. Since I am missing the critical USB know-how: we have to enter some kind of HID mode which then will be reset when plugged in without power from the battery, or is this just another USB channel in parallel to the serial port? Can this already be revoked in software or is the current way to toggle it by having it started up before plugging (HID settings active) or not (pure console mode)? As I said, no idea on the "mode" model right now, but eager to try out. Great addition to the Pico's dongle form factor. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-04 by @gfwilliams With USB, when you plug a device in it's 'enumerated' - the host computer asks it what it is and what it can do. So to tell the PC it's a mouse, Espruino has to know to do that at the time it's plugged in. When HID is enabled, Espruino actually enumerates as a HID device and a COM port, so you can still communicate with it just like before - including changing the USB HID code on the fly. Only if you want to change what it enumerates as, you have to unplug and re-plug it. I've already tweaked the code so that Espruino can appear as a USB HID device even when it's plugged straight in without a battery, but there are some really strange compilation issues. Sometimes it works fine, and sometimes it only receives the first 2 characters of anything you send it - so right now it's not something I can release! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-04 by Stev Ok, that would be cool. Though the hick-ups seem to get closer to "on every char" :) "While you're at it"(TM), is there a way to have an absolute pointer device, too. Don't know if that's a mode/param of the mouse mode or a separate one. Cheers |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-04 by @gfwilliams :) Looks like it's as easy as googling for it: https://forums.obdev.at/viewtopic.php?t=2559 In case the link goes down:
... but yes, I'll try and remember to put that in as another module. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-04 by Stev Hoped it would be more work :) To make up for that: What's b (or first array param) in sendUSBHID() in the mouse example (or the general content of that data stream array for certain HID modes)? Or just: can this be zero for the absolute pointing device as well? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-04 by @gfwilliams Yes, it can be zero - it's just whether buttons are pressed or not. I'll put definitions in the modules, but it's 1=left, 2=right, 4=middle - a bit like dealing with low-level GUI events tends to be :) I think at some point the modules will need a bit of tidying - for instance making sure you can actually As a fun aside, you can now do something like this:
I'll post a link to the latest version in a bit |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-04 by @gfwilliams Ok, updated firmware is here now USB HID documentation and examples at http://www.espruino.com/USB |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-04 by Stev Ah, so good. Especially with the module and tablet. This build still needs external Battery or just the save()? Nice link at the end. Lots of tinkering options :) As a backchannel, eg for a software on the host, reporting certain state values, can one grab and use the console's serial port on the Espruino side for that so that data sent to the USB modem dev on the host would end up in some serial buffer on the Pico? I remember switching console from back then, but I don't know if that's still possible. I could of course set vars via the console via JS, but it would nice to define limited protocol on the board side. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-04 by Stev The tablet example keeps logging me out of my Mac :) Probably kills's the UI. The kb example triggers the context menu. Haven't looked at that module, though, yet. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-04 by Stev Hm, lost my prepared comment in the editor ;/ Again... I changed the report descriptor in the USBTablet module to signed values (0xFF, 0x7f) for the logical maximum and changed the send function accordingly. Which seems to work. However I see some offset of my monitors origin (about 2500..2600 logical units) for top and left, resulting in a clipped circle. This only occurs on one of our Macs, on another with less clipping, on another without (just the vertical values are clipped due to the difference in height vs width in pixels). Just to make clear that this might not be the fault of the Pico when it occurs. Might be some kind of touch pad or multi monitor setup that triggers that. Can't say. However, the physical minimum/maximum value only seem to be information on the theoretical input device behind it. They don't seem to have any effect (like a movable and scalable value window, as one might expect). At least on the mac without any tablet driver they seem not to be taken into account. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-05 by @gfwilliams
Just
Yes, you just need to move the console out the way and then you can do what you want:
Ok, I'll update the module. Very interesting that a plug in device can crash the UI! :o As you say, I doubt the clipping/offset is anything Pico-related - the data sent from the Pico obviously doesn't have anything done to it (it works fine on Linux), so I wonder whether your Macs have some kind of 'calibration' that's applied? Very strange about the keyboard example and the context menu - I actually tried that on a Mac and it worked great.
Interesting - so it's just the logical values? To be honest I didn't read it properly and assumed they were X and Y. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-08-03 by @gfwilliams Yeah, I'll try and fix that problem today hopefully. My guess is it's to do with the changes to RAM size rather than anything specifically to do with USB HID. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-05-20 by @yerpj Hi, Does anyone managed to get the VCP+HID class enumeration on Windows? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-05-20 by @gfwilliams When HID is enabled, it is a composite device already... The issue seems to be that Windows still seems to require an 'inf' file for it (much like it does for normal VCP devices). All other OSes (Mac, Linux, Android) seem happy with it as-is. Usually that inf file is in the ST driver pack that you have to install before you start using Espruino - but it only mentions VCP - not the HID stuff at all. The only solution I'd found to get it working driverless on Windows appeared to be for me to add the option to disable the virtual COM port and have just the HID device - but that means trying to develop HID stuff on Windows would be a nightmare, so it wasn't desperately high priority. But if you can figure out some way of tweaking the descriptor such that it does actually work then I'd be very happy to include it :) I guess if you found a VCP+HID composite device that does work without drivers then we could compare the descriptors and see what was different? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-05-20 by @yerpj OK I had a look at the different descriptors (Device desc, Config desc, Interface desc, Endpoint desc, ...) as well as the stmcdc.INF, and it appears that I am completely lost. I can't figure out if 2 configuration descriptors are used (one for each interface) or if only one configuration descriptor is used, thus enclosing both interfaces. I am not familiar enough with that USB stuff to pretend I will find a solution, but I read this (old) post where they managed to enumerate a VCP/HID device with an STM32. I will continue to try to understand all that stuff anyway. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-05-23 by @gfwilliams You could compare with what's here: https://github.com/espruino/Espruino/blob/master/targetlibs/stm32usb/usbd_cdc_hid.c#L181 But it seems like there might be some USB debug tools for Windows, and those might be the best place to start? They might give some clue as to what Windows thinks is wrong. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-05-24 by DrAzzy
Do we have a way to get a telnet terminal on a wifi connected Espruino yet? That's a solution (for certain values of solution). Or setConsole and a TTL serial adapter... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-05-24 by @gfwilliams Yes, a USB-TTL adaptor would work fine - it defaults to B6/B7 when USB isn't connected anyway, no there's not even a need for You can implement telnet over WiFi with a few lines of JS, it's just not built-in yet (as the existing WiFi driver uses a JS library, so would have problems if you wanted to totally reset Espruino). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-06-04 by @yerpj It seems that on Windows, if there is more than one interface descriptor within a configuration descriptor, the latter should include a IAD (Interface Association Descriptor).
I don't see any IAD in usbd_cdc_hid.c. Maybe this could do the trick in order to allow windows to enumerate this CDC-HID config. That said, I don't know if IAD are recognized in Linux and macOS I am exploring USB enumeration with STM32F4DISCO. I will give feedback here in case of positive results. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-06-04 by @yerpj I just found a working example of dual CDC (2 COM ports) on a stm32F103 HERE. This example may help. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-06-04 by @yerpj I also found a tool from Texas Instruments, helping to generate composite descriptors as well as corresponding .INF files. Unfortunately, this tool is focused on MSP430, but the generated descriptors are written as C structures, so they may be of any help for comparing with current descriptors for CDC-HID in Espruino. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-06-06 by @gfwilliams Thanks - that's interesting... It could well be an IAD is needed. Maybe with the TI tool (or an example for ST) we can compare the descriptors that are generated. It might just be that a few extra bytes need adding to that descriptor to get it working. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-09-26 by Eugen Hi |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-09-26 by @gfwilliams Hi, I'm afraid there haven't been any changes with it recently. If you're able to figure out what it is about the descriptor that windows doesn't like (there might be some USB debug tools?) then I'm more than happy to make the relevant changes as well :) Also, Zadig might be worth a try? It's possible it'll be able to force the driver installation. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2023-06-10 by Potados Hi! I'm looking for a solution to make the pico a dedicated USB HID keyboard. I'm currently working on an environment where serial communication(including VCP) is blocked(also prohibited), so the pico needs to pretend to be a just a keyboard, without VCP capability.
Developing being a nightmare is not a problem for me. Is there a way to achieve it? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2023-06-12 by @gfwilliams Right now to manage it you'd have to build your own version of Espruino with the descriptor offering just HID and not CDC. The relevant bit of code is https://github.com/espruino/Espruino/blob/master/targetlibs/stm32usb/usbd_cdc_hid.c#L191C1-L321 and you'd have to cut the CDC bit out so it looked a bit more like https://github.com/STMicroelectronics/STM32CubeF7/blob/master/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c#L135C37-L186 Building itself is not too hard - in fact as long as GitHub actions are enabled, when you fork the Espruino repo and make a change the firmware is built automatically! Or for local dev see https://github.com/espruino/Espruino/blob/master/README_Building.md |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-29 by @gfwilliams
I've finally managed to add USB HID support on the Pico. An experimental binary for it should be here in an hour or two.
It's taken most of last and this week to work my way around ST's USB drivers, and they now don't bare much relation to the originals at all :(
So... How do you use it?
I'll make these all into libraries when it's ready for a proper release, but it's quite usable even now :)
Beta Was this translation helpful? Give feedback.
All reactions