77
88#include <stdint.h>
99#include "esp_err.h"
10+ #include "freertos/FreeRTOS.h"
1011#include "usb/usb_host.h"
1112#include "iot_usbh_cdc_type.h"
13+
1214#ifdef __cplusplus
1315extern "C" {
1416#endif
@@ -95,8 +97,8 @@ typedef struct usbh_cdc_config {
9597 uint16_t pid ; /*!< Product ID: If set, the `vid` parameter must be configured
9698 If not set, it will default to opening the first connected device */
9799 int itf_num ; /*!< interface numbers */
98- size_t rx_buffer_size ; /*!< Size of the receive buffer, default is 1024 bytes if set to 0 */
99- size_t tx_buffer_size ; /*!< Size of the transmit buffer, default is 1024 bytes if set to 0 */
100+ size_t rx_buffer_size ; /*!< Size of the receive ringbuffer size, if set to 0, not use ringbuffer */
101+ size_t tx_buffer_size ; /*!< Size of the transmit ringbuffer size, if set to 0, not use ringbuffer */
100102 usbh_cdc_event_callbacks_t cbs ; /*!< Event callbacks for the CDC device */
101103} usbh_cdc_device_config_t ;
102104
@@ -205,9 +207,12 @@ esp_err_t usbh_cdc_send_custom_request(usbh_cdc_handle_t cdc_handle, uint8_t bmR
205207/**
206208 * @brief Write data to the USB CDC device
207209 *
208- * This function writes data to the specified USB CDC device by pushing the data into the output ring buffer.
210+ * With internal ring buffer, this function writes data to the specified USB CDC device by pushing the data into the output ring buffer.
209211 * If the buffer is full or the device is not connected, the write will fail.
210212 *
213+ * Without internal ring buffer, this function writes data to the specified USB CDC device by sending data directly to the device.
214+ * Please set the ticks_to_wait for blocking write.
215+ *
211216 * @param[in] cdc_handle The CDC device handle
212217 * @param[in] buf Pointer to the data buffer to write
213218 * @param[in] length Pointer to the length of data to write. On success, it remains unchanged, otherwise set to 0.
@@ -223,9 +228,12 @@ esp_err_t usbh_cdc_write_bytes(usbh_cdc_handle_t cdc_handle, const uint8_t *buf,
223228/**
224229 * @brief Read data from the USB CDC device
225230 *
226- * This function reads data from the specified USB CDC device by popping data from the input ring buffer.
231+ * With internal ring buffer, this function reads data from the specified USB CDC device by popping data from the input ring buffer.
227232 * If no data is available or the device is not connected, the read will fail.
228233 *
234+ * Without internal ring buffer, this function reads data from the specified USB CDC device by receiving data directly from the device. You can call this function in the recv_data callback function.
235+ * Please set ticks_to_wait to zero for non-blocking read.
236+ *
229237 * @param[in] cdc_handle The CDC device handle
230238 * @param[out] buf Pointer to the buffer where the read data will be stored
231239 * @param[inout] length Pointer to the length of data to read. On success, it is updated with the actual bytes read.
@@ -237,18 +245,21 @@ esp_err_t usbh_cdc_write_bytes(usbh_cdc_handle_t cdc_handle, const uint8_t *buf,
237245 * - ESP_ERR_INVALID_ARG: Invalid argument (NULL handle, buffer, or length)
238246 * - ESP_ERR_INVALID_STATE: Device is not connected
239247 */
240- esp_err_t usbh_cdc_read_bytes (usbh_cdc_handle_t cdc_handle , const uint8_t * buf , size_t * length , TickType_t ticks_to_wait );
248+ esp_err_t usbh_cdc_read_bytes (usbh_cdc_handle_t cdc_handle , uint8_t * buf , size_t * length , TickType_t ticks_to_wait );
241249
242250/**
243251 * @brief Flush the receive buffer of the USB CDC device
244252 *
245253 * This function clears the receive buffer, discarding any data currently in the buffer.
246254 *
255+ * Not supported for no internal ring buffer mode.
256+ *
247257 * @param[in] cdc_handle The CDC device handle
248258 *
249259 * @return
250260 * - ESP_OK: Receive buffer flushed successfully
251261 * - ESP_ERR_INVALID_ARG: Invalid CDC handle provided
262+ * - ESP_ERR_NOT_SUPPORTED: Not supported for no internal ring buffer mode
252263 */
253264esp_err_t usbh_cdc_flush_rx_buffer (usbh_cdc_handle_t cdc_handle );
254265
@@ -257,11 +268,14 @@ esp_err_t usbh_cdc_flush_rx_buffer(usbh_cdc_handle_t cdc_handle);
257268 *
258269 * This function clears the transmit buffer, discarding any data currently in the buffer.
259270 *
271+ * Not supported for no internal ring buffer mode.
272+ *
260273 * @param[in] cdc_handle The CDC device handle
261274 *
262275 * @return
263276 * - ESP_OK: Transmit buffer flushed successfully
264277 * - ESP_ERR_INVALID_ARG: Invalid CDC handle provided
278+ * - ESP_ERR_NOT_SUPPORTED: Not supported for no internal ring buffer mode
265279 */
266280esp_err_t usbh_cdc_flush_tx_buffer (usbh_cdc_handle_t cdc_handle );
267281
@@ -270,6 +284,8 @@ esp_err_t usbh_cdc_flush_tx_buffer(usbh_cdc_handle_t cdc_handle);
270284 *
271285 * This function retrieves the current size of the receive buffer in bytes.
272286 *
287+ * For no internal ring buffer, you can call this function in the recv_data callback function.
288+ *
273289 * @param[in] cdc_handle The CDC device handle
274290 * @param[out] size Pointer to store the size of the receive buffer
275291 *
0 commit comments