esp-idf/examples/peripherals/usb/device/tusb_hid
Peter Marcisovsky 1302fd70ba ci: Add esp32s3 runner for usb device example tests
- CI USB device tests are run on esp32s3
    - usb_host env_marker removed - not used anymore
    - failing usb_device_ncm test fixed
2024-02-29 15:10:18 +01:00
..
main refactor(usb/examples): Depend on new esp_driver_gpio 2024-01-18 07:28:06 +01:00
CMakeLists.txt change(usb/examples): Trim the USB example builds 2023-10-10 10:28:47 +02:00
pytest_usb_device_hid.py ci: Add esp32s3 runner for usb device example tests 2024-02-29 15:10:18 +01:00
README.md feat(esp32p4): Add USB-OTG support for ESP32-P4 2024-01-30 15:07:11 +01:00
sdkconfig.defaults tinyusb: Use TinyUSB from component registry 2022-11-02 08:24:43 +01:00

Supported Targets ESP32-P4 ESP32-S2 ESP32-S3

TinyUSB Human Interface Device Example

(See the README.md file in the upper level 'examples' directory for more information about examples.)

Human interface devices (HID) are one of the most common USB devices, it is implemented in various devices such as keyboards, mice, game controllers, sensors and alphanumeric display devices. In this example, we implement USB keyboard and mouse. Upon connection to USB host (PC), the example application will sent 'key a/A pressed & released' events and move mouse in a square trajectory. To send these HID reports again, press the BOOT button, that is present on most ESP development boards (GPIO0).

As a USB stack, a TinyUSB component is used.

How to use example

Hardware Required

Any ESP board that have USB-OTG supported.

Pin Assignment

Note: In case your board doesn't have micro-USB connector connected to USB-OTG peripheral, you may have to DIY a cable and connect D+ and D- to the pins listed below.

See common pin assignments for USB Device examples from upper level.

Boot signal (GPIO0) is used to send HID reports to USB host.

Build and Flash

Build the project and flash it to the board, then run monitor tool to view serial output:

idf.py -p PORT flash monitor

(Replace PORT with the name of the serial port to use.)

(To exit the serial monitor, type Ctrl-].)

See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

Example Output

After the flashing you should see the output at idf monitor:

I (290) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (310) example: USB initialization
I (310) tusb_desc:
┌─────────────────────────────────┐
│  USB Device Descriptor Summary  │
├───────────────────┬─────────────┤
│bDeviceClass       │ 0           │
├───────────────────┼─────────────┤
│bDeviceSubClass    │ 0           │
├───────────────────┼─────────────┤
│bDeviceProtocol    │ 0           │
├───────────────────┼─────────────┤
│bMaxPacketSize0    │ 64          │
├───────────────────┼─────────────┤
│idVendor           │ 0x303a      │
├───────────────────┼─────────────┤
│idProduct          │ 0x4004      │
├───────────────────┼─────────────┤
│bcdDevice          │ 0x100       │
├───────────────────┼─────────────┤
│iManufacturer      │ 0x1         │
├───────────────────┼─────────────┤
│iProduct           │ 0x2         │
├───────────────────┼─────────────┤
│iSerialNumber      │ 0x3         │
├───────────────────┼─────────────┤
│bNumConfigurations │ 0x1         │
└───────────────────┴─────────────┘
I (480) TinyUSB: TinyUSB Driver installed
I (480) example: USB initialization DONE
I (2490) example: Sending Keyboard report
I (3040) example: Sending Mouse report