mirror of
https://github.com/hathach/tinyusb.git
synced 2026-03-14 19:44:44 +00:00
refactor(config): separate endpoint buffer sizes into RX and TX definitions for clarity and flexibility
This commit is contained in:
@ -104,9 +104,9 @@
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
// Leave it as default size (512 for HS, 64 for FS) unless your host application
|
||||
// is able to send ZLP (Zero Length Packet) to terminate transfer !
|
||||
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
// Only increase RX_EPSIZE if your host driver/application support zero-length packet (ZLP)
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -104,9 +104,9 @@
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
// Leave it as default size (512 for HS, 64 for FS) unless your host application
|
||||
// is able to send ZLP (Zero Length Packet) to terminate transfer !
|
||||
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
// Only increase RX_EPSIZE if your host driver/application support zero-length packet (ZLP)
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// MSC Buffer size of Device Mass storage
|
||||
#define CFG_TUD_MSC_EP_BUFSIZE 512
|
||||
|
||||
@ -111,9 +111,9 @@
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
// Leave it as default size (512 for HS, 64 for FS) unless your host application
|
||||
// is able to send ZLP (Zero Length Packet) to terminate transfer !
|
||||
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
// Only increase RX_EPSIZE if your host driver/application support zero-length packet (ZLP)
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// MSC Buffer size of Device Mass storage
|
||||
#define CFG_TUD_MSC_EP_BUFSIZE 512
|
||||
|
||||
@ -160,9 +160,9 @@ extern "C" {
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
// Leave it as default size (512 for HS, 64 for FS) unless your host application
|
||||
// is able to send ZLP (Zero Length Packet) to terminate transfer !
|
||||
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
// Only increase RX_EPSIZE if your host driver/application support zero-length packet (ZLP)
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -103,12 +103,14 @@ extern "C" {
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size
|
||||
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// Printer buffer sizes
|
||||
#define CFG_TUD_PRINTER_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_PRINTER_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_PRINTER_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_PRINTER_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_PRINTER_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -130,7 +130,8 @@ extern "C" {
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// HOST CONFIGURATION
|
||||
|
||||
@ -115,7 +115,8 @@
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// HOST CONFIGURATION
|
||||
|
||||
@ -115,7 +115,8 @@
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 256)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// HOST CONFIGURATION
|
||||
|
||||
@ -63,10 +63,10 @@ typedef struct {
|
||||
#define ITF_MEM_RESET_SIZE offsetof(cdcd_interface_t, line_coding)
|
||||
|
||||
// Skip local EP buffer if dedicated hw FIFO is supported
|
||||
#if CFG_TUD_EDPT_DEDICATED_HWFIFO == 0
|
||||
#if CFG_TUD_EDPT_DEDICATED_HWFIFO == 0
|
||||
typedef struct {
|
||||
TUD_EPBUF_DEF(epout, CFG_TUD_CDC_EP_BUFSIZE);
|
||||
TUD_EPBUF_DEF(epin, CFG_TUD_CDC_EP_BUFSIZE);
|
||||
TUD_EPBUF_DEF(epout, CFG_TUD_CDC_RX_EPSIZE);
|
||||
TUD_EPBUF_DEF(epin, CFG_TUD_CDC_TX_EPSIZE);
|
||||
|
||||
#if CFG_TUD_CDC_NOTIFY
|
||||
TUD_EPBUF_TYPE_DEF(cdc_notify_msg_t, epnotify);
|
||||
@ -74,7 +74,7 @@ typedef struct {
|
||||
} cdcd_epbuf_t;
|
||||
|
||||
CFG_TUD_MEM_SECTION static cdcd_epbuf_t _cdcd_epbuf[CFG_TUD_CDC];
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Weak stubs: invoked if no strong implementation is available
|
||||
@ -347,7 +347,7 @@ uint16_t cdcd_open(uint8_t rhport, const tusb_desc_interface_t* itf_desc, uint16
|
||||
TU_ASSERT(usbd_edpt_open(rhport, desc_ep), 0);
|
||||
if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
|
||||
tu_edpt_stream_t *stream_tx = &p_cdc->tx_stream;
|
||||
tu_edpt_stream_open(stream_tx, rhport, desc_ep, CFG_TUD_CDC_EP_BUFSIZE);
|
||||
tu_edpt_stream_open(stream_tx, rhport, desc_ep, CFG_TUD_CDC_TX_EPSIZE);
|
||||
if (_cdcd_cfg.tx_persistent) {
|
||||
tu_edpt_stream_write_xfer(stream_tx); // flush pending data
|
||||
} else {
|
||||
@ -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_EP_BUFSIZE : tu_edpt_packet_size(desc_ep));
|
||||
_cdcd_cfg.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);
|
||||
}
|
||||
@ -511,7 +511,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
||||
}
|
||||
|
||||
// Data sent to host, we continue to fetch from tx fifo to send.
|
||||
// Note: This will cause incorrect baudrate set in line coding. Though maybe the baudrate is not really important !
|
||||
// Note: This will cause incorrect baudrate set in line coding. Though maybe the baudrate is not really important!
|
||||
if (ep_addr == stream_tx->ep_addr) {
|
||||
tud_cdc_tx_complete_cb(itf); // invoke callback to possibly refill tx fifo
|
||||
|
||||
|
||||
@ -29,6 +29,10 @@
|
||||
|
||||
#include "cdc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Class Driver Configuration
|
||||
//--------------------------------------------------------------------+
|
||||
@ -37,46 +41,49 @@
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_CDC_TX_BUFSIZE
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE TUD_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_CDC_RX_BUFSIZE
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE TUD_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
|
||||
#if !defined(CFG_TUD_CDC_EP_BUFSIZE) && defined(CFG_TUD_CDC_EPSIZE)
|
||||
#warning CFG_TUD_CDC_EPSIZE is renamed to CFG_TUD_CDC_EP_BUFSIZE, please update to use the new name
|
||||
#define CFG_TUD_CDC_EP_BUFSIZE CFG_TUD_CDC_EPSIZE
|
||||
// EP_BUFSIZE is separated to RX_EPSIZE and TX_EPSIZE
|
||||
#ifndef CFG_TUD_CDC_RX_EPSIZE
|
||||
#ifdef CFG_TUD_CDC_EP_BUFSIZE
|
||||
#define CFG_TUD_CDC_RX_EPSIZE CFG_TUD_CDC_EP_BUFSIZE
|
||||
#else
|
||||
#define CFG_TUD_CDC_RX_EPSIZE TUD_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_CDC_EP_BUFSIZE
|
||||
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#ifndef CFG_TUD_CDC_TX_EPSIZE
|
||||
#ifdef CFG_TUD_CDC_EP_BUFSIZE
|
||||
#define CFG_TUD_CDC_TX_EPSIZE CFG_TUD_CDC_EP_BUFSIZE
|
||||
#else
|
||||
#define CFG_TUD_CDC_TX_EPSIZE TUD_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#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
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Driver Configuration
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
bool rx_persistent : 1; // keep rx fifo data even with bus reset or disconnect
|
||||
bool tx_persistent : 1; // keep tx fifo data even with reset or disconnect
|
||||
bool tx_overwritabe_if_not_connected : 1; // if not connected, tx fifo can be overwritten
|
||||
bool rx_need_zlp : 1; // requires host support ZLP, allow transfer more than one packet in a single transfer, better throughput.
|
||||
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;
|
||||
TU_VERIFY_STATIC(sizeof(tud_cdc_configure_t) == 1, "size is not correct");
|
||||
|
||||
#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
|
||||
|
||||
// Configure CDC driver behavior
|
||||
bool tud_cdc_configure(const tud_cdc_configure_t* driver_cfg);
|
||||
|
||||
@ -39,22 +39,22 @@ extern "C" {
|
||||
|
||||
// RX FIFO size
|
||||
#ifndef CFG_TUH_CDC_RX_BUFSIZE
|
||||
#define CFG_TUH_CDC_RX_BUFSIZE TUH_EPSIZE_BULK_MPS
|
||||
#define CFG_TUH_CDC_RX_BUFSIZE TUH_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
|
||||
// RX Endpoint size
|
||||
#ifndef CFG_TUH_CDC_RX_EPSIZE
|
||||
#define CFG_TUH_CDC_RX_EPSIZE TUH_EPSIZE_BULK_MPS
|
||||
#define CFG_TUH_CDC_RX_EPSIZE TUH_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
|
||||
// TX FIFO size
|
||||
#ifndef CFG_TUH_CDC_TX_BUFSIZE
|
||||
#define CFG_TUH_CDC_TX_BUFSIZE TUH_EPSIZE_BULK_MPS
|
||||
#define CFG_TUH_CDC_TX_BUFSIZE TUH_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
|
||||
// TX Endpoint size
|
||||
#ifndef CFG_TUH_CDC_TX_EPSIZE
|
||||
#define CFG_TUH_CDC_TX_EPSIZE TUH_EPSIZE_BULK_MPS
|
||||
#define CFG_TUH_CDC_TX_EPSIZE TUH_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
@ -74,8 +74,8 @@ static midid_interface_t _midid_itf[CFG_TUD_MIDI];
|
||||
#if CFG_TUD_EDPT_DEDICATED_HWFIFO == 0
|
||||
// Endpoint Transfer buffer: not used if dedicated hw FIFO is available
|
||||
typedef struct {
|
||||
TUD_EPBUF_DEF(epin, CFG_TUD_MIDI_EP_BUFSIZE);
|
||||
TUD_EPBUF_DEF(epout, CFG_TUD_MIDI_EP_BUFSIZE);
|
||||
TUD_EPBUF_DEF(epin, CFG_TUD_MIDI_TX_EPSIZE);
|
||||
TUD_EPBUF_DEF(epout, CFG_TUD_MIDI_RX_EPSIZE);
|
||||
} midid_epbuf_t;
|
||||
|
||||
CFG_TUD_MEM_SECTION static midid_epbuf_t _midid_epbuf[CFG_TUD_MIDI];
|
||||
@ -510,7 +510,7 @@ uint16_t midid_open(uint8_t rhport, const tusb_desc_interface_t *desc_itf, uint1
|
||||
|
||||
if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) {
|
||||
tu_edpt_stream_t *stream_tx = &p_midi->ep_stream.tx;
|
||||
tu_edpt_stream_open(stream_tx, rhport, desc_ep, CFG_TUD_MIDI_EP_BUFSIZE);
|
||||
tu_edpt_stream_open(stream_tx, rhport, desc_ep, CFG_TUD_MIDI_TX_EPSIZE);
|
||||
tu_edpt_stream_clear(stream_tx);
|
||||
} else {
|
||||
tu_edpt_stream_t *stream_rx = &p_midi->ep_stream.rx;
|
||||
|
||||
@ -34,13 +34,20 @@
|
||||
// Class Driver Configuration
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#if !defined(CFG_TUD_MIDI_EP_BUFSIZE) && defined(CFG_TUD_MIDI_EPSIZE)
|
||||
#warning CFG_TUD_MIDI_EPSIZE is renamed to CFG_TUD_MIDI_EP_BUFSIZE, please update to use the new name
|
||||
#define CFG_TUD_MIDI_EP_BUFSIZE CFG_TUD_MIDI_EPSIZE
|
||||
#ifndef CFG_TUD_MIDI_RX_EPSIZE
|
||||
#ifdef CFG_TUD_MIDI_EP_BUFSIZE
|
||||
#define CFG_TUD_MIDI_RX_EPSIZE CFG_TUD_MIDI_EP_BUFSIZE
|
||||
#else
|
||||
#define CFG_TUD_MIDI_RX_EPSIZE TUD_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_MIDI_EP_BUFSIZE
|
||||
#define CFG_TUD_MIDI_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#ifndef CFG_TUD_MIDI_TX_EPSIZE
|
||||
#ifdef CFG_TUD_MIDI_EP_BUFSIZE
|
||||
#define CFG_TUD_MIDI_TX_EPSIZE CFG_TUD_MIDI_EP_BUFSIZE
|
||||
#else
|
||||
#define CFG_TUD_MIDI_TX_EPSIZE TUD_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -83,8 +83,8 @@ typedef struct {
|
||||
}midih_interface_t;
|
||||
|
||||
typedef struct {
|
||||
TUH_EPBUF_DEF(tx, TUH_EPSIZE_BULK_MPS);
|
||||
TUH_EPBUF_DEF(rx, TUH_EPSIZE_BULK_MPS);
|
||||
TUH_EPBUF_DEF(tx, TUH_EPSIZE_BULK_MAX);
|
||||
TUH_EPBUF_DEF(rx, TUH_EPSIZE_BULK_MAX);
|
||||
} midih_epbuf_t;
|
||||
|
||||
static midih_interface_t _midi_host[CFG_TUH_MIDI];
|
||||
|
||||
@ -38,15 +38,15 @@ extern "C" {
|
||||
// Class Driver Configuration
|
||||
//--------------------------------------------------------------------+
|
||||
#ifndef CFG_TUH_MIDI_RX_BUFSIZE
|
||||
#define CFG_TUH_MIDI_RX_BUFSIZE TUH_EPSIZE_BULK_MPS
|
||||
#define CFG_TUH_MIDI_RX_BUFSIZE TUH_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUH_MIDI_TX_BUFSIZE
|
||||
#define CFG_TUH_MIDI_TX_BUFSIZE TUH_EPSIZE_BULK_MPS
|
||||
#define CFG_TUH_MIDI_TX_BUFSIZE TUH_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUH_MIDI_EP_BUFSIZE
|
||||
#define CFG_TUH_MIDI_EP_BUFSIZE TUH_EPSIZE_BULK_MPS
|
||||
#define CFG_TUH_MIDI_EP_BUFSIZE TUH_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
|
||||
// Enable the MIDI stream read/write API. Some library can work with raw USB MIDI packet
|
||||
|
||||
@ -53,8 +53,8 @@ typedef struct {
|
||||
|
||||
#if CFG_TUD_EDPT_DEDICATED_HWFIFO == 0
|
||||
typedef struct {
|
||||
TUD_EPBUF_DEF(epout, CFG_TUD_PRINTER_EP_BUFSIZE);
|
||||
TUD_EPBUF_DEF(epin, CFG_TUD_PRINTER_EP_BUFSIZE);
|
||||
TUD_EPBUF_DEF(epout, CFG_TUD_PRINTER_RX_EPSIZE);
|
||||
TUD_EPBUF_DEF(epin, CFG_TUD_PRINTER_TX_EPSIZE);
|
||||
} printer_epbuf_t;
|
||||
|
||||
CFG_TUD_MEM_SECTION static printer_epbuf_t _printer_epbuf[CFG_TUD_PRINTER];
|
||||
@ -173,12 +173,10 @@ void printerd_init(void) {
|
||||
#endif
|
||||
|
||||
tu_edpt_stream_init(&p->rx_stream, false, false, false,
|
||||
p->rx_ff_buf, CFG_TUD_PRINTER_RX_BUFSIZE,
|
||||
epout_buf, CFG_TUD_PRINTER_EP_BUFSIZE);
|
||||
p->rx_ff_buf, CFG_TUD_PRINTER_RX_BUFSIZE, epout_buf);
|
||||
|
||||
tu_edpt_stream_init(&p->tx_stream, false, true, true,
|
||||
p->tx_ff_buf, CFG_TUD_PRINTER_TX_BUFSIZE,
|
||||
epin_buf, CFG_TUD_PRINTER_EP_BUFSIZE);
|
||||
p->tx_ff_buf, CFG_TUD_PRINTER_TX_BUFSIZE, epin_buf);
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,12 +224,14 @@ uint16_t printerd_open(uint8_t rhport, const tusb_desc_interface_t *itf_desc, ui
|
||||
TU_ASSERT(usbd_edpt_open(rhport, desc_ep), 0);
|
||||
|
||||
if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
|
||||
tu_edpt_stream_open(&p->tx_stream, rhport, desc_ep);
|
||||
tu_edpt_stream_clear(&p->tx_stream);
|
||||
tu_edpt_stream_t *stream_tx = &p->tx_stream;
|
||||
tu_edpt_stream_open(stream_tx, rhport, desc_ep, CFG_TUD_PRINTER_TX_EPSIZE);
|
||||
tu_edpt_stream_clear(stream_tx);
|
||||
} else {
|
||||
tu_edpt_stream_open(&p->rx_stream, rhport, desc_ep);
|
||||
tu_edpt_stream_clear(&p->rx_stream);
|
||||
TU_ASSERT(tu_edpt_stream_read_xfer(&p->rx_stream) > 0, 0);
|
||||
tu_edpt_stream_t *stream_rx = &p->rx_stream;
|
||||
tu_edpt_stream_open(stream_rx, rhport, desc_ep, tu_edpt_packet_size(desc_ep));
|
||||
tu_edpt_stream_clear(stream_rx);
|
||||
TU_ASSERT(tu_edpt_stream_read_xfer(stream_rx) > 0, 0);
|
||||
}
|
||||
|
||||
drv_len += sizeof(tusb_desc_endpoint_t);
|
||||
|
||||
@ -27,12 +27,23 @@
|
||||
#ifndef TUSB_PRINTER_DEVICE_H_
|
||||
#define TUSB_PRINTER_DEVICE_H_
|
||||
|
||||
#include "printer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "printer.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Configuration
|
||||
//--------------------------------------------------------------------+
|
||||
#ifndef CFG_TUD_PRINTER_RX_EPSIZE
|
||||
#define CFG_TUD_PRINTER_RX_EPSIZE TUD_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_PRINTER_TX_EPSIZE
|
||||
#define CFG_TUD_PRINTER_TX_EPSIZE TUD_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Multiple Ports) i.e. CFG_TUD_PRINTER > 1
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
18
src/class/vendor/vendor_device.c
vendored
18
src/class/vendor/vendor_device.c
vendored
@ -61,15 +61,15 @@ typedef struct {
|
||||
|
||||
static vendord_interface_t _vendord_itf[CFG_TUD_VENDOR];
|
||||
|
||||
// Skip local EP buffer if dedicated hw FIFO is supported or no fifo mode
|
||||
#if CFG_TUD_EDPT_DEDICATED_HWFIFO == 0 || !CFG_TUD_VENDOR_TXRX_BUFFERED
|
||||
// Skip local EP buffer if dedicated hw FIFO is supported or no fifo mode
|
||||
#if CFG_TUD_EDPT_DEDICATED_HWFIFO == 0 || !CFG_TUD_VENDOR_TXRX_BUFFERED
|
||||
typedef struct {
|
||||
TUD_EPBUF_DEF(epout, CFG_TUD_VENDOR_EPSIZE);
|
||||
TUD_EPBUF_DEF(epin, CFG_TUD_VENDOR_EPSIZE);
|
||||
TUD_EPBUF_DEF(epout, CFG_TUD_VENDOR_RX_EPSIZE);
|
||||
TUD_EPBUF_DEF(epin, CFG_TUD_VENDOR_TX_EPSIZE);
|
||||
} vendord_epbuf_t;
|
||||
|
||||
CFG_TUD_MEM_SECTION static vendord_epbuf_t _vendord_epbuf[CFG_TUD_VENDOR];
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static tud_vendor_configure_t _vendord_cfg = CFG_TUD_VENDOR_CONFIGURE_DEFAULT();
|
||||
|
||||
@ -167,7 +167,7 @@ uint32_t tud_vendor_n_write(uint8_t idx, const void *buffer, uint32_t bufsize) {
|
||||
#else
|
||||
// non-fifo mode: direct transfer
|
||||
TU_VERIFY(usbd_edpt_claim(p_itf->rhport, p_itf->ep_in), 0);
|
||||
const uint32_t xact_len = tu_min32(bufsize, CFG_TUD_VENDOR_EPSIZE);
|
||||
const uint32_t xact_len = tu_min32(bufsize, CFG_TUD_VENDOR_TX_EPSIZE);
|
||||
memcpy(_vendord_epbuf[idx].epin, buffer, xact_len);
|
||||
TU_ASSERT(usbd_edpt_xfer(p_itf->rhport, p_itf->ep_in, _vendord_epbuf[idx].epin, (uint16_t)xact_len, false), 0);
|
||||
return xact_len;
|
||||
@ -184,7 +184,7 @@ uint32_t tud_vendor_n_write_available(uint8_t idx) {
|
||||
#else
|
||||
// Non-FIFO mode
|
||||
TU_VERIFY(p_itf->ep_in > 0, 0); // must be opened
|
||||
return usbd_edpt_busy(p_itf->rhport, p_itf->ep_in) ? 0 : CFG_TUD_VENDOR_EPSIZE;
|
||||
return usbd_edpt_busy(p_itf->rhport, p_itf->ep_in) ? 0 : CFG_TUD_VENDOR_TX_EPSIZE;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -307,13 +307,13 @@ 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_EPSIZE : tu_edpt_packet_size(desc_ep);
|
||||
uint16_t rx_xfer_len = _vendord_cfg.rx_need_zlp ? CFG_TUD_VENDOR_RX_EPSIZE : tu_edpt_packet_size(desc_ep);
|
||||
|
||||
#if CFG_TUD_VENDOR_TXRX_BUFFERED
|
||||
// open endpoint stream
|
||||
if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
|
||||
tu_edpt_stream_t *tx_stream = &p_vendor->tx_stream;
|
||||
tu_edpt_stream_open(tx_stream, rhport, desc_ep, CFG_TUD_VENDOR_EPSIZE);
|
||||
tu_edpt_stream_open(tx_stream, rhport, desc_ep, CFG_TUD_VENDOR_TX_EPSIZE);
|
||||
tu_edpt_stream_write_xfer(tx_stream); // flush pending data
|
||||
} else {
|
||||
tu_edpt_stream_t *rx_stream = &p_vendor->rx_stream;
|
||||
|
||||
16
src/class/vendor/vendor_device.h
vendored
16
src/class/vendor/vendor_device.h
vendored
@ -36,8 +36,20 @@ extern "C" {
|
||||
//--------------------------------------------------------------------+
|
||||
// Configuration
|
||||
//--------------------------------------------------------------------+
|
||||
#ifndef CFG_TUD_VENDOR_EPSIZE
|
||||
#define CFG_TUD_VENDOR_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#ifndef CFG_TUD_VENDOR_RX_EPSIZE
|
||||
#ifdef CFG_TUD_VENDOR_EPSIZE
|
||||
#define CFG_TUD_VENDOR_RX_EPSIZE CFG_TUD_VENDOR_EPSIZE
|
||||
#else
|
||||
#define CFG_TUD_VENDOR_RX_EPSIZE TUD_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_VENDOR_TX_EPSIZE
|
||||
#ifdef CFG_TUD_VENDOR_EPSIZE
|
||||
#define CFG_TUD_VENDOR_TX_EPSIZE CFG_TUD_VENDOR_EPSIZE
|
||||
#else
|
||||
#define CFG_TUD_VENDOR_TX_EPSIZE TUD_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// RX FIFO can be disabled by setting this value to 0
|
||||
|
||||
@ -115,6 +115,10 @@ enum {
|
||||
TUSB_EPSIZE_ISO_HS_MAX = 1024,
|
||||
};
|
||||
|
||||
// Endpoint Bulk size depending on host/device max speed
|
||||
#define TUD_EPSIZE_BULK_MAX (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define TUH_EPSIZE_BULK_MAX (TUH_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
/// Isochronous Endpoint Attributes
|
||||
typedef enum {
|
||||
TUSB_ISO_EP_ATT_NO_SYNC = 0x00,
|
||||
|
||||
@ -41,8 +41,7 @@
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Endpoint Bulk size depending on host mx speed
|
||||
#define TUH_EPSIZE_BULK_MPS (TUH_OPT_HIGH_SPEED ? TUSB_EPSIZE_BULK_HS : TUSB_EPSIZE_BULK_FS)
|
||||
|
||||
|
||||
// forward declaration
|
||||
struct tuh_xfer_s;
|
||||
|
||||
@ -102,7 +102,8 @@
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// MSC Buffer size of Device Mass storage
|
||||
#define CFG_TUD_MSC_EP_BUFSIZE 512
|
||||
|
||||
@ -102,7 +102,8 @@
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// MSC Buffer size of Device Mass storage
|
||||
#define CFG_TUD_MSC_EP_BUFSIZE 512
|
||||
|
||||
@ -107,7 +107,8 @@
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// CDC Endpoint transfer buffer size, more is faster
|
||||
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_RX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_EPSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
// MSC Buffer size of Device Mass storage
|
||||
#define CFG_TUD_MSC_EP_BUFSIZE 512
|
||||
|
||||
Reference in New Issue
Block a user