ESP32-S3 USB host interface to keyboard

username
Posts: 536
Joined: Thu May 03, 2018 1:18 pm

ESP32-S3 USB host interface to keyboard

Postby username » Sat Feb 26, 2022 7:30 am

I need to have the ESP32-S3 act as a USB host so I can plug a keyboard into it.
Thus far I have not been able to find out any information on how to do this.
Would someone please point me in the right direction.
The examples are quite limited for host applications.

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: ESP32-S3 USB host interface to keyboard

Postby ESP_Dazz » Mon Feb 28, 2022 9:58 am

Hi @username

ESP-IDF currently doesn't have support for Host Side HID class yet. We do have Host HID support planned, but I can't give you a definite timeline on when it will be supported (earliest possible is release v5.0).

If you need a quick way to talk to a particular Mouse/Keyboard specifically, you can probably try writing your own bare-bones HID class for now using the USB Host Library API.

We do have a HCD test case that reads some values from a mouse, but the enumeration and configuration of the device are hard coded

Jamawa
Posts: 16
Joined: Sun Aug 16, 2020 10:46 am

Re: ESP32-S3 USB host interface to keyboard

Postby Jamawa » Tue Mar 01, 2022 9:35 pm

If you want to know more of the details required to write your own code for this, have a look the book “USB by example” by John Hyde. Amongst others it explains how HID devices work on a driver level, USB descriptor’s, HID reports etc. I used this years ago to write HID and other devices.
Another writer which might be helpful here is Jan Axelson.
Both are well recommended.

Together with the ESP IDF examples I believe it is possible to write a keyboard client. Mind you, if any of the terms above are unfamiliar, you may want to think twice about doing this. If you’re not already slightly familiar with the USB protocol I advise against it.

username
Posts: 536
Joined: Thu May 03, 2018 1:18 pm

Re: ESP32-S3 USB host interface to keyboard

Postby username » Tue Mar 22, 2022 2:08 pm

Thanks guys for the info, every little bit helps.

I have not done anything USB related before, so I have to start my steep hill climb.
New hire at a company with PIC33 fanboys. Many products cant ship because we cannot get Microchip parts until 2023!!
I have converted most products over to ESP32, but there is one that uses a USB keyboard. So I have to give it a shot.
I just found out today that Teensy 4.1 has many host examples.
https://github.com/PaulStoffregen/USBHost_t36

I don't want to go with Teensy 4.1, but maybe their USB Host examples will shed some light. I sure hope Espressif starts making the same similar examples very soon.

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP32-S3 USB host interface to keyboard

Postby chegewara » Tue Mar 22, 2022 7:54 pm

https://github.com/tobozo/ESP32-USB-Sof ... y_USB_Test

and maybe some example how to start with USB host on S2/S3 (may be a bit outdated)

https://github.com/chegewara/esp32-usb-host

username
Posts: 536
Joined: Thu May 03, 2018 1:18 pm

Re: ESP32-S3 USB host interface to keyboard

Postby username » Wed Mar 23, 2022 2:24 am

Thanks, check it out tomorrow.

I tried the usb_host_lib example.
https://github.com/espressif/esp-idf/tr ... b_host_lib

When I plug the keyboard in I do get all its info.
I figured the hardest part is making the connection to the USB device. But since this example is doing that already, shouldn't it be easy just to get signaled when there is a key press ?

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP32-S3 USB host interface to keyboard

Postby chegewara » Wed Mar 23, 2022 2:58 am

username wrote:
Wed Mar 23, 2022 2:24 am
I figured the hardest part is making the connection to the USB device. But since this example is doing that already, shouldn't it be easy just to get signaled when there is a key press ?
Actually its the hardest part (in keyboard case not that hard). After connecting it is not that hard to get all info, its enough to use example as you said and it can be the same code for all USB devices.
From now you have to know configuration, endpoints etc. Then you have to claim interfaces/endpoints. Next thing is to start listening on all IN endpoints (1 in case of keyboard). And at the end you have to know received bytes meaning, which may be different for different keyboards, but usually it is 9 bytes, i think, with specific meanings.
In general there is a lot to learn before you start using USB unless you find device driver you like.

username
Posts: 536
Joined: Thu May 03, 2018 1:18 pm

Re: ESP32-S3 USB host interface to keyboard

Postby username » Wed Mar 23, 2022 3:19 am

okedoke. Thanks for the clarification.

username
Posts: 536
Joined: Thu May 03, 2018 1:18 pm

Re: ESP32-S3 USB host interface to keyboard

Postby username » Thu Mar 24, 2022 3:16 pm

FWIW, Using the Teensy 4.1 board with USBHost_t36 Lib and my USB keyboard and it worked great.
https://github.com/PaulStoffregen/USBHost_t36
Of course his functions are not the same as ours, so difficult for me to translate.

I have read the USB Host docs https://docs.espressif.com/projects/esp ... l#usb-host, and it was clear as mud to me. I have never been able to learn from API references alone. Examples are the way I learn.

So.... I have searched and searched and have not been able to find anyone using an ESP32-S3 as a host to a USB device other than a USB pendrive.

Has anyone come across anything ?
Espressif, do you have any ideas when you might start adding more host examples to examples/peripherals/usb/host/ folder ?

username
Posts: 536
Joined: Thu May 03, 2018 1:18 pm

Re: ESP32-S3 USB host interface to keyboard

Postby username » Sat Apr 02, 2022 5:18 am

I bought 3 books and going through them. Some things are getting clear but getting stuck on ESP-IDF order of things.

Thus far (if I understand the order)

#1) usb_host_install()
#2) usb_host_client_register()
#3) usb_host_device_open()
#4) usb_host_device_info()
#5) usb_host_get_device_descriptor()
#6) usb_host_get_active_config_descriptor()

Is my next step to use usb_host_interface_claim() ?

Who is online

Users browsing this forum: Baidu [Spider] and 376 guests