mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
feat(usb/host): Modifiy usb_host_lib example
This commit is contained in:
committed by
Roman Leonov
parent
e62df280e0
commit
8046784118
@@ -5,19 +5,21 @@
|
||||
|
||||
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
||||
|
||||
This example demonstrates the basic usage of the [USB Host Library API](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/peripherals/usb_host.html) by implementing a pseudo class driver and a Host Library daemon task. The example does the following:
|
||||
This example demonstrates the basic usage of the [USB Host Library API](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/peripherals/usb_host.html) by implementing a pseudo class driver and a Host Library task. The example does the following:
|
||||
|
||||
1. Install Host Library and register a client
|
||||
2. Waits for a device connection
|
||||
3. Prints the device's information (such as device/configuration/string descriptors)
|
||||
4. Waits for the device to disconnect
|
||||
5. Deregister the client and uninstall the Host Library
|
||||
5. Repeats steps 2 to 4 until a user pressess a button, which quits the `app`
|
||||
6. If the button has been pressed, while a USB device is still connected, the user will be prompted to remove the device and push the button again to quit the `app`
|
||||
7. Deregister the client, uninstall the Host Library and quit the `app`
|
||||
|
||||
The example demonstrates the following aspects of the USB Host Library API:
|
||||
|
||||
- How to use the Library API to:
|
||||
- Install and uninstall the USB Host Library
|
||||
- Run the library event handler function a daemon task
|
||||
- Run the library event handler function and usb host library task
|
||||
- How to handle library events
|
||||
- How to use the Client API from a client task to:
|
||||
- Register and deregister a client of the USB Host Library
|
||||
@@ -30,7 +32,7 @@ The example demonstrates the following aspects of the USB Host Library API:
|
||||
|
||||
### Hardware Required
|
||||
|
||||
An ESP board that supports USB-OTG. The example uses the ESP's internal USB PHY, however the internal USB PHY's pins will need to be connected to a USB port (i.e., a USB breakout board) as follows:
|
||||
An ESP board that has a push button and supports USB-OTG. The example uses the ESP's internal USB PHY, however the internal USB PHY's pins will need to be connected to a USB port (i.e., a USB breakout board) as follows:
|
||||
|
||||
- GND and 5V signals of the ESP board to the GND and 5V lines of the USB port
|
||||
- GPIO 19 to D-
|
||||
@@ -43,6 +45,7 @@ idf.py menuconfig
|
||||
```
|
||||
|
||||
* The USB Host Stack has a maximum supported transfer size for control transfer during device enumeration. This size is specified via the USB_HOST_CONTROL_TRANSFER_MAX_SIZE configuration option and has a default value of 256 bytes. Therefore, if devices with length config/string descriptors are used, users may want to increase the size of this configuration.
|
||||
* Push button GPIO selection
|
||||
|
||||
### Build and Flash
|
||||
|
||||
@@ -61,14 +64,17 @@ See the Getting Started Guide for full steps to configure and use ESP-IDF to bui
|
||||
## Example Output
|
||||
|
||||
```
|
||||
I (261) cpu_start: Starting scheduler on PRO CPU.
|
||||
I (267) DAEMON: Installing USB Host Library
|
||||
I (297) CLASS: Registering Client
|
||||
I (5067) CLASS: Opening device at address 1
|
||||
I (5067) CLASS: Getting device information
|
||||
I (5067) CLASS: Full speed
|
||||
I (5067) CLASS: bConfigurationValue 1
|
||||
I (5067) CLASS: Getting device descriptor
|
||||
I (305) main_task: Started on CPU0
|
||||
I (315) main_task: Calling app_main()
|
||||
I (315) USB host lib: USB host library example
|
||||
I (315) gpio: GPIO[0]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:2
|
||||
I (325) USB host lib: Installing USB Host Library
|
||||
I (365) CLASS: Registering Client
|
||||
I (745) CLASS: Opening device at address 1
|
||||
I (745) CLASS: Getting device information
|
||||
I (745) CLASS: Full speed
|
||||
I (745) CLASS: bConfigurationValue 1
|
||||
I (745) CLASS: Getting device descriptor
|
||||
*** Device descriptor ***
|
||||
bLength 18
|
||||
bDescriptorType 1
|
||||
@@ -84,7 +90,7 @@ iManufacturer 1
|
||||
iProduct 2
|
||||
iSerialNumber 3
|
||||
bNumConfigurations 1
|
||||
I (5097) CLASS: Getting config descriptor
|
||||
I (775) CLASS: Getting config descriptor
|
||||
*** Configuration descriptor ***
|
||||
bLength 9
|
||||
bDescriptorType 2
|
||||
@@ -153,12 +159,20 @@ bMaxPower 500mA
|
||||
bmAttributes 0x2 BULK
|
||||
wMaxPacketSize 64
|
||||
bInterval 1
|
||||
I (5227) CLASS: Getting Manufacturer string descriptor
|
||||
I (855) CLASS: Getting Manufacturer string descriptor
|
||||
Espressif
|
||||
I (5237) CLASS: Getting Product string descriptor
|
||||
I (855) CLASS: Getting Product string descriptor
|
||||
USB JTAG/serial debug unit
|
||||
I (5247) CLASS: Getting Serial Number string descriptor
|
||||
I (865) CLASS: Getting Serial Number string descriptor
|
||||
7C:DF:A1:E0:10:50
|
||||
W (2855) USB host lib: To shutdown example, remove all USB devices and press button again.
|
||||
E (6135) USBH: Device 1 gone
|
||||
I (9545) CLASS: Deregistering Client
|
||||
I (9545) USB host lib: No more clients
|
||||
I (9545) USB host lib: All devices marked as free
|
||||
I (9545) USB host lib: No more clients and devices
|
||||
I (9645) USB host lib: End of the example
|
||||
I (9645) main_task: Returned from app_main()
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
Reference in New Issue
Block a user