Skip to content

Commit 94cc8fc

Browse files
committed
Merge branch 'doc/tinyusb' into 'master'
TinyUSB documentation See merge request espressif/esp-idf!8862
2 parents 4c4b25f + c863b4c commit 94cc8fc

File tree

11 files changed

+195
-36
lines changed

11 files changed

+195
-36
lines changed

components/soc/soc/esp32s2/include/soc/soc_caps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
#define SOC_CPU_CORES_NUM 1
1010
#define SOC_SUPPORTS_SECURE_DL_MODE 1
1111
#define SOC_RISCV_COPROC_SUPPORTED 1
12+
#define SOC_USB_SUPPORTED 1

components/tinyusb/additions/include/tinyusb.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ extern "C" {
7171
* @brief Configuration structure of the tinyUSB core
7272
*/
7373
typedef struct {
74-
tusb_desc_device_t *descriptor;
75-
char **string_descriptor;
76-
bool external_phy;
74+
tusb_desc_device_t *descriptor; /*!< Pointer to a device descriptor */
75+
char **string_descriptor; /*!< Pointer to an array of string descriptors */
76+
bool external_phy; /*!< Should USB use an external PHY */
7777
} tinyusb_config_t;
7878

7979
esp_err_t tinyusb_driver_install(const tinyusb_config_t *config);

components/tinyusb/additions/include/tusb_cdc_acm.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@ typedef enum{
4040
* @brief Data provided to the input of the `callback_rx_wanted_char` callback
4141
*/
4242
typedef struct {
43-
char wanted_char;
43+
char wanted_char; /*!< Wanted character */
4444
} cdcacm_event_rx_wanted_char_data_t;
4545

4646
/**
4747
* @brief Data provided to the input of the `callback_line_state_changed` callback
4848
*/
4949
typedef struct {
50-
bool dtr;
51-
bool rts;
50+
bool dtr; /*!< Data Terminal Ready (DTR) line state */
51+
bool rts; /*!< Request To Send (RTS) line state */
5252
} cdcacm_event_line_state_changed_data_t;
5353

5454
/**
5555
* @brief Data provided to the input of the `line_coding_changed` callback
5656
*/
5757
typedef struct {
58-
cdc_line_coding_t const *p_line_coding;
58+
cdc_line_coding_t const *p_line_coding; /*!< New line coding value */
5959
} cdcacm_event_line_coding_changed_data_t;
6060

6161
/**
@@ -72,7 +72,7 @@ typedef enum {
7272
* @brief Describes an event passing to the input of a callbacks
7373
*/
7474
typedef struct {
75-
cdcacm_event_type_t type;
75+
cdcacm_event_type_t type; /*!< Event type */
7676
union {
7777
cdcacm_event_rx_wanted_char_data_t rx_wanted_char_data;
7878
cdcacm_event_line_state_changed_data_t line_state_changed_data;

components/tinyusb/additions/include/tusb_tasks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern "C" {
3333
esp_err_t tusb_run_task(void);
3434

3535
/**
36-
* @brief Stops a FreeRTOS task with @ref tusb_device_task
36+
* @brief Stops a FreeRTOS task
3737
*
3838
* @return ESP_OK or ESP_FAIL
3939
*/

docs/Doxyfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ PROJECT_NAME = "ESP32 Programming Guide"
2121
## and used to include in API reference documentation
2222

2323
INPUT = \
24+
## TinyUSB
25+
$(IDF_PATH)/components/tinyusb/additions/include/tinyusb.h \
26+
$(IDF_PATH)/components/tinyusb/additions/include/tinyusb_types.h \
27+
$(IDF_PATH)/components/tinyusb/additions/include/tusb_cdc_acm.h \
28+
$(IDF_PATH)/components/tinyusb/additions/include/tusb_config.h \
29+
$(IDF_PATH)/components/tinyusb/additions/include/tusb_console.h \
30+
$(IDF_PATH)/components/tinyusb/additions/include/tusb_tasks.h \
31+
$(IDF_PATH)/components/tinyusb/additions/include/vfs_tinyusb.h \
2432
##
2533
## Wi-Fi - API Reference
2634
##
@@ -260,7 +268,7 @@ INPUT = \
260268
## NOTE: for line below header_file.inc is not used
261269
$(IDF_PATH)/components/ulp/include/$(IDF_TARGET)/ulp.h \
262270
$(IDF_PATH)/components/ulp/include/esp32s2/ulp_riscv.h \
263-
$(IDF_PATH)/components/ulp/include/ulp_common.h \
271+
$(IDF_PATH)/components/ulp/include/ulp_common.h \
264272
##
265273
## Application Level Tracing - API Reference
266274
##

docs/_static/usb-board-connection.png

93.3 KB
Loading

docs/conf_common.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@
150150
'api-guides/unit-tests-legacy.rst',
151151
'get-started-legacy/**']
152152

153+
USB_DOCS = ['api-reference/peripherals/usb.rst']
154+
153155
ESP32_DOCS = ['api-guides/ulp_instruction_set.rst',
154156
'api-reference/system/himem.rst',
155157
'api-guides/RF_calibration.rst',
@@ -168,13 +170,15 @@
168170
'api-reference/peripherals/ds.rst',
169171
'api-reference/peripherals/spi_slave_hd.rst',
170172
'api-reference/peripherals/temp_sensor.rst',
171-
'api-reference/system/async_memcpy.rst']
173+
'api-reference/system/async_memcpy.rst',
174+
'api-reference/peripherals/usb.rst']
172175

173176
# format: {tag needed to include: documents to included}, tags are parsed from sdkconfig and peripheral_caps.h headers
174177
conditional_include_dict = {'SOC_BT_SUPPORTED':BT_DOCS,
175178
'SOC_SDMMC_HOST_SUPPORTED':SDMMC_DOCS,
176179
'SOC_SDIO_SLAVE_SUPPORTED':SDIO_SLAVE_DOCS,
177180
'SOC_MCPWM_SUPPORTED':MCPWM_DOCS,
181+
'SOC_USB_SUPPORTED':USB_DOCS,
178182
'esp32':ESP32_DOCS,
179183
'esp32s2':ESP32S2_DOCS}
180184

docs/en/api-reference/peripherals/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Peripherals API
3232
Touch Sensor <touch_pad>
3333
TWAI <twai>
3434
UART <uart>
35+
:SOC_USB_SUPPORTED: USB <usb>
3536

3637

3738
Code examples for this API section are provided in the :example:`peripherals` directory of ESP-IDF examples.
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
2+
USB Driver
3+
==========
4+
5+
Overview
6+
--------
7+
8+
The driver allows users to use {IDF_TARGET_NAME} chips to develop USB devices on top the TinyUSB stack. TinyUSB is integrating with ESP-IDF to provide USB features of the framework. Using this driver the chip works as a composite device supporting to represent several USB devices simultaneously. Currently, only the communications device class (CDC) type of the device with the ACM (Abstract Control Model) subclass is supported.
9+
10+
11+
Features
12+
--------
13+
14+
- Configuration of device and string USB descriptors
15+
- USB Serial Device (CDC-ACM)
16+
- Input and output through USB Serial Device
17+
18+
19+
Hardware USB Connection
20+
-----------------------
21+
22+
- Any board with the {IDF_TARGET_NAME} chip with USB connectors or with exposed USB's D+ and D- (DATA+/DATA-) pins.
23+
24+
If the board has no USB connector but has the pins, connect pins directly to the host (e.g. with do-it-yourself cable from any USB connection cable). For example, connect GPIO19/20 to D-/D+ respectively for an ESP32-S2 board:
25+
26+
27+
.. figure:: ../../../_static/usb-board-connection.png
28+
:align: center
29+
:alt: Connection of a board to a host ESP32-S2
30+
:figclass: align-center
31+
32+
Driver Structure
33+
----------------
34+
35+
As the basis is used the TinyUSB stack.
36+
37+
On top of it the driver implements:
38+
39+
- Customization of USB descriptors
40+
- Serial device support
41+
- Redirecting of standard streams through the Serial device
42+
- Encapsulated driver's task servicing the TinyuSB
43+
44+
45+
46+
Configuration
47+
-------------
48+
49+
Via Menuconfig options you can specify:
50+
51+
- Several of descriptor's parameters (see: Descriptors Configuration bellow)
52+
- USB Serial low-level Configuration
53+
- The verbosity of the TinyUSB's log
54+
- Disable the TinyUSB main task (for the custom implementation)
55+
56+
57+
Descriptors Configuration
58+
^^^^^^^^^^^^^^^^^^^^^^^^^
59+
60+
The driver's descriptors are provided by the :cpp:type:`tinyusb_config_t` structure's :cpp:member:`descriptor` and :cpp:member:`string_descriptor` members. Therefore, users should initialize :cpp:type:`tinyusb_config_t` to their desired descriptor before calling :cpp:func:`tinyusb_driver_install` to install driver.
61+
62+
However, the driver also provides a default descriptor. The driver can be installed with the default descriptor by setting the :cpp:member:`descriptor` and :cpp:member:`string_descriptor` members of :cpp:type:`tinyusb_config_t` to `NULL` before calling :cpp:func:`tinyusb_driver_install`. The driver's default descriptor is specified using Menuconfig, where the following fields should be configured:
63+
64+
- PID
65+
- VID
66+
- bcdDevice
67+
- Manufacturer
68+
- Product name
69+
- Name of CDC device if it is On
70+
- Serial number
71+
72+
If you want to use own descriptors with extended modification, you can define them during the driver installation process
73+
74+
75+
Install Driver
76+
--------------
77+
To initialize the driver, users should call :cpp:func:`tinyusb_driver_install`. The driver's configuration is specified in a :cpp:type:`tinyusb_config_t` structure that is passed as an argument to :cpp:func:`tinyusb_driver_install`.
78+
79+
Note that the :cpp:type:`tinyusb_config_t` structure can be zero initialized (e.g. ``tinyusb_config_t tusb_cfg = { 0 }``) or partially (as shown below). For any member that is initialized to `0` or `NULL`, the driver will use its default configuration values for that member (see example below)
80+
81+
.. code-block:: c
82+
83+
tinyusb_config_t partial_init = {
84+
.descriptor = NULL; //Uses default descriptor specified in Menuconfig
85+
.string_descriptor = NULL; //Uses default string specified in Menuconfig
86+
.external_phy = false;
87+
}
88+
89+
USB Serial Device (CDC-ACM)
90+
---------------------------
91+
92+
If the CDC option is enabled in Menuconfig, the USB Serial Device could be initialized with :cpp:func:`tusb_cdc_acm_init` according to the settings from :cpp:type:`tinyusb_config_cdcacm_t` (see example below).
93+
94+
.. code-block:: c
95+
96+
tinyusb_config_cdcacm_t amc_cfg = {
97+
.usb_dev = TINYUSB_USBDEV_0,
98+
.cdc_port = TINYUSB_CDC_ACM_0,
99+
.rx_unread_buf_sz = 64,
100+
.callback_rx = NULL,
101+
.callback_rx_wanted_char = NULL,
102+
.callback_line_state_changed = NULL,
103+
.callback_line_coding_changed = NULL
104+
};
105+
tusb_cdc_acm_init(&amc_cfg);
106+
107+
To specify callbacks you can either set the pointer to your :cpp:type:`tusb_cdcacm_callback_t` function in the configuration structure or call :cpp:func:`tinyusb_cdcacm_register_callback` after initialization.
108+
109+
USB Serial Console
110+
^^^^^^^^^^^^^^^^^^
111+
112+
The driver allows to redirect all standard application strings (stdin/out/err) to the USB Serial Device and return them to UART using :cpp:func:`esp_tusb_init_console`/:cpp:func:`esp_tusb_deinit_console` functions.
113+
114+
115+
Application Examples
116+
--------------------
117+
118+
The table below describes the code examples available in the directory :example:`peripherals/usb/`.
119+
120+
.. list-table::
121+
:widths: 35 65
122+
:header-rows: 1
123+
124+
* - Code Example
125+
- Description
126+
* - :example:`peripherals/usb/tusb_console`
127+
- How to set up {IDF_TARGET_NAME} chip to get log output via Serial Device connection
128+
* - :example:`peripherals/usb/tusb_sample_descriptor`
129+
- How to set up {IDF_TARGET_NAME} chip to work as a Generic USB Device with a user-defined descriptor
130+
* - :example:`peripherals/usb/tusb_serial_device`
131+
- How to set up {IDF_TARGET_NAME} chip to work as a USB Serial Device
132+
133+
134+
API Reference
135+
-------------
136+
137+
.. include-build-file:: inc/tinyusb.inc
138+
.. include-build-file:: inc/tinyusb_types.inc
139+
.. include-build-file:: inc/tusb_cdc_acm.inc
140+
.. include-build-file:: inc/tusb_console.inc
141+
.. include-build-file:: inc/tusb_tasks.inc
142+
.. include-build-file:: inc/vfs_tinyusb.inc
143+

docs/zh_CN/api-reference/peripherals/index.rst

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,32 @@
44
:link_to_translation:`en:[English]`
55

66
.. toctree::
7-
:maxdepth: 1
7+
:maxdepth: 1
88

9-
ADC <adc>
10-
DAC <dac>
11-
GPIO (包括 RTC 低功耗 I/O) <gpio>
12-
:esp32s2: HMAC <hmac>
13-
:esp32s2: Digital Signature <ds>
14-
I2C <i2c>
15-
I2S <i2s>
16-
LED Control <ledc>
17-
:SOC_MCPWM_SUPPORTED: MCPWM <mcpwm>
18-
Pulse Counter <pcnt>
19-
Remote Control <rmt>
20-
:SOC_SDMMC_HOST_SUPPORTED: SDMMC Host <sdmmc_host>
21-
SD SPI Host <sdspi_host>
22-
:SOC_SDIO_SLAVE_SUPPORTED: SDIO Slave <sdio_slave>
23-
Sigma-delta Modulation <sigmadelta>
24-
SPI Master <spi_master>
25-
SPI Slave <spi_slave>
26-
:esp32: Secure Element <secure_element>
27-
:esp32s2: SPI Slave 半双工 (half duplex) <spi_slave_hd>
28-
:esp32s2: Temp sensor <temp_sensor>
29-
Timer <timer>
30-
Touch Sensor <touch_pad>
31-
TWAI <twai>
32-
UART <uart>
9+
ADC <adc>
10+
DAC <dac>
11+
GPIO (包括 RTC 低功耗 I/O) <gpio>
12+
:esp32s2: HMAC <hmac>
13+
:esp32s2: Digital Signature <ds>
14+
I2C <i2c>
15+
I2S <i2s>
16+
LED Control <ledc>
17+
:SOC_MCPWM_SUPPORTED: MCPWM <mcpwm>
18+
Pulse Counter <pcnt>
19+
Remote Control <rmt>
20+
:SOC_SDMMC_HOST_SUPPORTED: SDMMC Host <sdmmc_host>
21+
SD SPI Host <sdspi_host>
22+
:SOC_SDIO_SLAVE_SUPPORTED: SDIO Slave <sdio_slave>
23+
Sigma-delta Modulation <sigmadelta>
24+
SPI Master <spi_master>
25+
SPI Slave <spi_slave>
26+
:esp32: Secure Element <secure_element>
27+
:esp32s2: SPI Slave 半双工 (half duplex) <spi_slave_hd>
28+
:esp32s2: Temp sensor <temp_sensor>
29+
Timer <timer>
30+
Touch Sensor <touch_pad>
31+
TWAI <twai>
32+
UART <uart>
33+
:SOC_USB_SUPPORTED: USB <usb>
3334

3435
本部分的 API 示例代码存放在 ESP-IDF 示例项目的 :example:`peripherals` 目录下。
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. include:: ../../../en/api-reference/peripherals/usb.rst

0 commit comments

Comments
 (0)