Skip to content

Commit 3d0bdc7

Browse files
committed
docs(iot_cdc): update iot_cdc en docs
1 parent a643b4c commit 3d0bdc7

File tree

1 file changed

+40
-29
lines changed

1 file changed

+40
-29
lines changed

docs/en/usb/usb_host/usb_host_iot_usbh_cdc.rst

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
USB Host CDC
1+
USB Host CDC
22
=====================
33

44
:link_to_translation:`zh_CN:[中文]`
@@ -8,41 +8,52 @@ The ``iot_usbh_cdc`` component implements a simple version of the USB host CDC d
88
User Guide
99
---------------
1010

11-
1. Using ``usbh_cdc_driver_install`` to configure, user can simply configure the bulk endpoint address and the size of the internal ringbuffer, user can also configure the hot plug related callback function ``conn_callback`` ``disconn_callback``.
11+
1. Use ``usbh_cdc_driver_install`` to configure the USB CDC driver. Users can set up the driver and initialize the USB Host Driver protocol stack internally by setting the ``skip_init_usb_host_driver`` option.
1212

1313
.. code:: c
1414
15-
/* install usbh cdc driver with bulk endpoint configs and size of internal ringbuffer */
16-
static usbh_cdc_config_t config = {
17-
/* use default endpoint descriptor with user address */
18-
.bulk_in_ep_addr = EXAMPLE_BULK_IN_EP_ADDR,
19-
.bulk_out_ep_addr = EXAMPLE_BULK_OUT_EP_ADDR,
20-
.rx_buffer_size = IN_RINGBUF_SIZE,
21-
.tx_buffer_size = OUT_RINGBUF_SIZE,
22-
.conn_callback = usb_connect_callback,
23-
.disconn_callback = usb_disconnect_callback,
15+
/* Install the USB CDC driver and initialize the USB Host Driver protocol stack internally */
16+
usbh_cdc_driver_config_t config = {
17+
.driver_task_stack_size = 1024 * 4,
18+
.driver_task_priority = 5,
19+
.xCoreID = 0,
20+
.skip_init_usb_host_driver = false,
21+
.new_dev_cb = cdc_new_dev_cb,
2422
};
25-
/* if user want to use multiple interfaces, can configure like this */
26-
#if (EXAMPLE_BULK_ITF_NUM > 1)
27-
config.itf_num = 2;
28-
config.bulk_in_ep_addrs[1] = EXAMPLE_BULK_IN1_EP_ADDR;
29-
config.bulk_out_ep_addrs[1] = EXAMPLE_BULK_OUT1_EP_ADDR;
30-
config.rx_buffer_sizes[1] = IN_RINGBUF_SIZE;
31-
config.tx_buffer_sizes[1] = OUT_RINGBUF_SIZE;
32-
#endif
3323
34-
/* install USB host CDC driver */
35-
usbh_cdc_driver_install(&config);
24+
2. Use ``usbh_cdc_create`` to configure the interface number (``itf_num``) and the size of the internal ring buffer. Additionally, users can configure hot-plug callbacks such as ``connect``, ``disconnect``, and ``recv_data``:
25+
26+
.. code:: c
27+
28+
/* Install the USB Host CDC driver and configure bulk endpoint addresses and internal ring buffer size */
29+
usbh_cdc_device_config_t dev_config = {
30+
.vid = 0,
31+
.pid = 0,
32+
.itf_num = 1,
33+
/* Set to 0 to use default values */
34+
.rx_buffer_size = 0,
35+
.tx_buffer_size = 0,
36+
.cbs = {
37+
.connect = cdc_connect_cb,
38+
.disconnect = cdc_disconnect_cb,
39+
.user_data = NULL
40+
},
41+
};
3642
37-
/* Waiting for USB device connected */
38-
usbh_cdc_wait_connect(portMAX_DELAY);
43+
usbh_cdc_handle_t handle = NULL;
44+
usbh_cdc_create(&dev_config, &handle);
45+
/* If multiple interfaces are required, configure them like this */
46+
#if (EXAMPLE_BULK_ITF_NUM > 1)
47+
config.itf_num = 3;
48+
usbh_cdc_handle_t handle2 = NULL;
49+
usbh_cdc_create(&dev_config, &handle2);
50+
#endif
3951
40-
2. After the driver initialization, the internal state machine will automatically handle the hot plug of the USB.
41-
3. ``usbh_cdc_wait_connect`` can be used to block task until USB CDC Device is connected or timeout.
42-
4. After successfully connected, the host will automatically receive USB data from CDC device to the internal ``ringbuffer``, user can poll ``usbh_cdc_get_buffered_data_len`` to read buffered data size or register a receive callback to get notified when data is ready. Then ``usbh_cdc_read_bytes`` can be used to read buffered data out.
43-
5. ``usbh_cdc_write_bytes`` can be used to send data to USB Device. The data is first written to the internal transmit ``ringbuffer``,then will be sent out during USB bus free.
44-
6. ``usbh_cdc_driver_delete`` can uninstall the USB driver completely to release all resources.
45-
7. If config multiple CDC interfaces, each interface contains an IN and OUT endpoint. Users can communicate with the specified interfaces using ``usbh_cdc_itf_read_bytes`` and ``usbh_cdc_itf_write_bytes``.
52+
3. After the driver is initialized, the internal state machine will automatically handle USB hot-plug events.
53+
4. Once successfully connected, the host will automatically receive USB data from the CDC device into an internal ``ringbuffer``. Users can poll the buffer size using ``usbh_cdc_get_rx_buffer_size`` or register a callback to get notified when data is ready. Data can then be read using ``usbh_cdc_read_bytes``.
54+
5. ``usbh_cdc_write_bytes`` can be used to send data to the USB device. The data is first written to an internal transmission ``ringbuffer`` and then sent over the USB bus when it is idle.
55+
6. ``usbh_cdc_delete`` can be used to delete the USB CDC device and release the associated ring buffer and other resources.
56+
7. ``usbh_cdc_driver_uninstall`` can completely uninstall the USB driver and release all resources.
4657

4758
Examples
4859
-------------------------------

0 commit comments

Comments
 (0)