mirror of
https://github.com/hathach/tinyusb.git
synced 2026-03-14 03:24:43 +00:00
refactor(vendor/cdc): add CFG_TUD_CDC_RX_NEED_ZLP and CFG_TUD_VENDOR_RX_NEED_ZLP
This commit is contained in:
@ -103,8 +103,8 @@
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
// Only increase RX_EPSIZE if your host driver/application support zero-length packet (ZLP)
|
||||
// CDC Endpoint transfer buffer size, default to max bulk packet size (HS 512, FS 64). Larger is faster.
|
||||
// Larger RX_EPSIZE requires CFG_TUD_CDC_RX_NEED_ZLP = 1 and host ZLP support
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
|
||||
@ -103,8 +103,8 @@
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
// Only increase RX_EPSIZE if your host driver/application support zero-length packet (ZLP)
|
||||
// CDC Endpoint transfer buffer size, default to max bulk packet size (HS 512, FS 64). Larger is faster.
|
||||
// Larger RX_EPSIZE requires CFG_TUD_CDC_RX_NEED_ZLP = 1 and host ZLP support
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
|
||||
@ -110,8 +110,8 @@
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
// Only increase RX_EPSIZE if your host driver/application support zero-length packet (ZLP)
|
||||
// CDC Endpoint transfer buffer size, default to max bulk packet size (HS 512, FS 64). Larger is faster.
|
||||
// Larger RX_EPSIZE requires CFG_TUD_CDC_RX_NEED_ZLP = 1 and host ZLP support
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
|
||||
@ -159,8 +159,8 @@ extern "C" {
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
// Only increase RX_EPSIZE if your host driver/application support zero-length packet (ZLP)
|
||||
// CDC Endpoint transfer buffer size, default to max bulk packet size (HS 512, FS 64). Larger is faster.
|
||||
// Larger RX_EPSIZE requires CFG_TUD_CDC_RX_NEED_ZLP = 1 and host ZLP support
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
|
||||
@ -102,7 +102,8 @@ extern "C" {
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size
|
||||
// CDC Endpoint transfer buffer size, default to max bulk packet size (HS 512, FS 64). Larger is faster.
|
||||
// Larger RX_EPSIZE requires CFG_TUD_CDC_RX_NEED_ZLP = 1 and host ZLP support
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
|
||||
@ -129,7 +129,8 @@ extern "C" {
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
// CDC Endpoint transfer buffer size, default to max bulk packet size (HS 512, FS 64). Larger is faster.
|
||||
// Larger RX_EPSIZE requires CFG_TUD_CDC_RX_NEED_ZLP = 1 and host ZLP support
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
|
||||
@ -114,7 +114,8 @@
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
// CDC Endpoint transfer buffer size, default to max bulk packet size (HS 512, FS 64). Larger is faster.
|
||||
// Larger RX_EPSIZE requires CFG_TUD_CDC_RX_NEED_ZLP = 1 and host ZLP support
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
|
||||
@ -114,7 +114,8 @@
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 256)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
// CDC Endpoint transfer buffer size, default to max bulk packet size (HS 512, FS 64). Larger is faster.
|
||||
// Larger RX_EPSIZE requires CFG_TUD_CDC_RX_NEED_ZLP = 1 and host ZLP support
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
|
||||
@ -356,7 +356,7 @@ uint16_t cdcd_open(uint8_t rhport, const tusb_desc_interface_t* itf_desc, uint16
|
||||
} else {
|
||||
tu_edpt_stream_t *stream_rx = &p_cdc->rx_stream;
|
||||
tu_edpt_stream_open(stream_rx, rhport, desc_ep,
|
||||
_cdcd_cfg.rx_need_zlp ? CFG_TUD_CDC_RX_EPSIZE : tu_edpt_packet_size(desc_ep));
|
||||
CFG_TUD_CDC_RX_NEED_ZLP ? CFG_TUD_CDC_RX_EPSIZE : tu_edpt_packet_size(desc_ep));
|
||||
if (!_cdcd_cfg.rx_persistent) {
|
||||
tu_edpt_stream_clear(stream_rx);
|
||||
}
|
||||
|
||||
@ -65,13 +65,17 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Enable multi-packet RX transfer with ZLP termination for better throughput. Requires host support for ZLP.
|
||||
#ifndef CFG_TUD_CDC_RX_NEED_ZLP
|
||||
#define CFG_TUD_CDC_RX_NEED_ZLP 0
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_CDC_CONFIGURE_DEFAULT
|
||||
#define CFG_TUD_CDC_CONFIGURE_DEFAULT() \
|
||||
{ \
|
||||
.rx_persistent = false, \
|
||||
.tx_persistent = false, \
|
||||
.tx_overwritabe_if_not_connected = true, \
|
||||
.rx_need_zlp = false \
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -82,7 +86,6 @@ typedef struct {
|
||||
bool rx_persistent; // keep rx fifo data even with bus reset or disconnect
|
||||
bool tx_persistent; // keep tx fifo data even with reset or disconnect
|
||||
bool tx_overwritabe_if_not_connected; // if not connected, tx fifo can be overwritten
|
||||
bool rx_need_zlp; // requires host support ZLP, allow transfer more than one packet in a single transfer, better throughput.
|
||||
} tud_cdc_configure_t;
|
||||
|
||||
// Configure CDC driver behavior
|
||||
|
||||
13
src/class/vendor/vendor_device.c
vendored
13
src/class/vendor/vendor_device.c
vendored
@ -71,8 +71,6 @@ typedef struct {
|
||||
CFG_TUD_MEM_SECTION static vendord_epbuf_t _vendord_epbuf[CFG_TUD_VENDOR];
|
||||
#endif
|
||||
|
||||
static tud_vendor_configure_t _vendord_cfg = CFG_TUD_VENDOR_CONFIGURE_DEFAULT();
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Weak stubs: invoked if no strong implementation is available
|
||||
//--------------------------------------------------------------------+
|
||||
@ -87,15 +85,6 @@ TU_ATTR_WEAK void tud_vendor_tx_cb(uint8_t idx, uint32_t sent_bytes) {
|
||||
(void) sent_bytes;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Application API
|
||||
//--------------------------------------------------------------------
|
||||
bool tud_vendor_configure(const tud_vendor_configure_t* driver_cfg) {
|
||||
TU_VERIFY(driver_cfg != NULL);
|
||||
_vendord_cfg = *driver_cfg;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tud_vendor_n_mounted(uint8_t idx) {
|
||||
TU_VERIFY(idx < CFG_TUD_VENDOR);
|
||||
vendord_interface_t *p_itf = &_vendord_itf[idx];
|
||||
@ -307,7 +296,7 @@ uint16_t vendord_open(uint8_t rhport, const tusb_desc_interface_t *desc_itf, uin
|
||||
const tusb_desc_endpoint_t* desc_ep = (const tusb_desc_endpoint_t*) p_desc;
|
||||
TU_ASSERT(usbd_edpt_open(rhport, desc_ep));
|
||||
|
||||
uint16_t rx_xfer_len = _vendord_cfg.rx_need_zlp ? CFG_TUD_VENDOR_RX_EPSIZE : tu_edpt_packet_size(desc_ep);
|
||||
uint16_t rx_xfer_len = CFG_TUD_VENDOR_RX_NEED_ZLP ? CFG_TUD_VENDOR_RX_EPSIZE : tu_edpt_packet_size(desc_ep);
|
||||
|
||||
#if CFG_TUD_VENDOR_TXRX_BUFFERED
|
||||
// open endpoint stream
|
||||
|
||||
19
src/class/vendor/vendor_device.h
vendored
19
src/class/vendor/vendor_device.h
vendored
@ -74,24 +74,11 @@ extern "C" {
|
||||
#define CFG_TUD_VENDOR_RX_MANUAL_XFER 0
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Driver Configuration
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
bool rx_need_zlp : 1; // requires host support ZLP, allow transfer more than one packet in a single transfer, better throughput.
|
||||
} tud_vendor_configure_t;
|
||||
TU_VERIFY_STATIC(sizeof(tud_vendor_configure_t) == 1, "size is not correct");
|
||||
|
||||
#ifndef CFG_TUD_VENDOR_CONFIGURE_DEFAULT
|
||||
#define CFG_TUD_VENDOR_CONFIGURE_DEFAULT() \
|
||||
{ \
|
||||
.rx_need_zlp = false, \
|
||||
}
|
||||
// Enable multi-packet RX transfer with ZLP termination for better throughput. Requires host support for ZLP.
|
||||
#ifndef CFG_TUD_VENDOR_RX_NEED_ZLP
|
||||
#define CFG_TUD_VENDOR_RX_NEED_ZLP 0
|
||||
#endif
|
||||
|
||||
// Configure CDC driver behavior
|
||||
bool tud_vendor_configure(const tud_vendor_configure_t* driver_cfg);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Multiple Interfaces) i.e CFG_TUD_VENDOR > 1
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
@ -101,7 +101,8 @@
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
// CDC Endpoint transfer buffer size, default to max bulk packet size (HS 512, FS 64). Larger is faster.
|
||||
// Larger RX_EPSIZE requires CFG_TUD_CDC_RX_NEED_ZLP = 1 and host ZLP support
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
|
||||
@ -101,7 +101,8 @@
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
// CDC Endpoint transfer buffer size, default to max bulk packet size (HS 512, FS 64). Larger is faster.
|
||||
// Larger RX_EPSIZE requires CFG_TUD_CDC_RX_NEED_ZLP = 1 and host ZLP support
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
|
||||
@ -106,7 +106,8 @@
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
// CDC Endpoint transfer buffer size, default to max bulk packet size (HS 512, FS 64). Larger is faster.
|
||||
// Larger RX_EPSIZE requires CFG_TUD_CDC_RX_NEED_ZLP = 1 and host ZLP support
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user