Use FIFO size as condition.
This commit is contained in:
40
src/class/vendor/vendor_device.c
vendored
40
src/class/vendor/vendor_device.c
vendored
@@ -43,24 +43,24 @@ typedef struct
|
||||
uint8_t ep_out;
|
||||
|
||||
/*------------- From this point, data is not cleared by bus reset -------------*/
|
||||
#if CFG_TUD_VENDOR_USE_RX_FIFO
|
||||
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
|
||||
tu_fifo_t rx_ff;
|
||||
#endif
|
||||
#if CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
|
||||
tu_fifo_t tx_ff;
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_VENDOR_USE_RX_FIFO
|
||||
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
|
||||
uint8_t rx_ff_buf[CFG_TUD_VENDOR_RX_BUFSIZE];
|
||||
#endif
|
||||
#if CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
|
||||
uint8_t tx_ff_buf[CFG_TUD_VENDOR_TX_BUFSIZE];
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_VENDOR_USE_RX_FIFO
|
||||
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
|
||||
OSAL_MUTEX_DEF(rx_ff_mutex);
|
||||
#endif
|
||||
#if CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
|
||||
OSAL_MUTEX_DEF(tx_ff_mutex);
|
||||
#endif
|
||||
|
||||
@@ -79,7 +79,7 @@ bool tud_vendor_n_mounted (uint8_t itf)
|
||||
return _vendord_itf[itf].ep_in && _vendord_itf[itf].ep_out;
|
||||
}
|
||||
|
||||
#if CFG_TUD_VENDOR_USE_RX_FIFO
|
||||
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
|
||||
uint32_t tud_vendor_n_available (uint8_t itf)
|
||||
{
|
||||
return tu_fifo_count(&_vendord_itf[itf].rx_ff);
|
||||
@@ -94,7 +94,7 @@ bool tud_vendor_n_peek(uint8_t itf, uint8_t* u8)
|
||||
//--------------------------------------------------------------------+
|
||||
// Read API
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUD_VENDOR_USE_RX_FIFO
|
||||
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
|
||||
static void _prep_out_transaction (vendord_interface_t* p_itf)
|
||||
{
|
||||
uint8_t const rhport = 0;
|
||||
@@ -136,7 +136,7 @@ void tud_vendor_n_read_flush (uint8_t itf)
|
||||
//--------------------------------------------------------------------+
|
||||
uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize)
|
||||
{
|
||||
#if CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
|
||||
vendord_interface_t* p_itf = &_vendord_itf[itf];
|
||||
uint16_t ret = tu_fifo_write_n(&p_itf->tx_ff, buffer, (uint16_t) bufsize);
|
||||
|
||||
@@ -161,7 +161,7 @@ uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
|
||||
uint32_t tud_vendor_n_write_flush (uint8_t itf)
|
||||
{
|
||||
vendord_interface_t* p_itf = &_vendord_itf[itf];
|
||||
@@ -208,15 +208,15 @@ void vendord_init(void)
|
||||
|
||||
for(uint8_t i=0; i<CFG_TUD_VENDOR; i++)
|
||||
{
|
||||
#if CFG_TUD_VENDOR_USE_RX_FIFO || CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0 || CFG_TUD_VENDOR_TX_BUFSIZE > 0
|
||||
vendord_interface_t* p_itf = &_vendord_itf[i];
|
||||
#endif
|
||||
// config fifo
|
||||
#if CFG_TUD_VENDOR_USE_RX_FIFO
|
||||
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
|
||||
tu_fifo_config(&p_itf->rx_ff, p_itf->rx_ff_buf, CFG_TUD_VENDOR_RX_BUFSIZE, 1, false);
|
||||
tu_fifo_config_mutex(&p_itf->rx_ff, NULL, osal_mutex_create(&p_itf->rx_ff_mutex));
|
||||
#endif
|
||||
#if CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
|
||||
tu_fifo_config(&p_itf->tx_ff, p_itf->tx_ff_buf, CFG_TUD_VENDOR_TX_BUFSIZE, 1, false);
|
||||
tu_fifo_config_mutex(&p_itf->tx_ff, osal_mutex_create(&p_itf->tx_ff_mutex), NULL);
|
||||
#endif
|
||||
@@ -232,10 +232,10 @@ void vendord_reset(uint8_t rhport)
|
||||
vendord_interface_t* p_itf = &_vendord_itf[i];
|
||||
|
||||
tu_memclr(p_itf, ITF_MEM_RESET_SIZE);
|
||||
#if CFG_TUD_VENDOR_USE_RX_FIFO
|
||||
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
|
||||
tu_fifo_clear(&p_itf->rx_ff);
|
||||
#endif
|
||||
#if CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
|
||||
tu_fifo_clear(&p_itf->tx_ff);
|
||||
#endif
|
||||
}
|
||||
@@ -275,7 +275,7 @@ uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, ui
|
||||
p_desc += desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t);
|
||||
|
||||
// Prepare for incoming data
|
||||
#if CFG_TUD_VENDOR_USE_RX_FIFO
|
||||
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
|
||||
_prep_out_transaction(p_vendor);
|
||||
#else
|
||||
if ( !usbd_edpt_xfer(rhport, p_vendor->ep_out, p_vendor->epout_buf, CFG_TUD_VENDOR_EPSIZE) )
|
||||
@@ -285,7 +285,7 @@ uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, ui
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
|
||||
tud_vendor_n_write_flush((uint8_t)(p_vendor - _vendord_itf));
|
||||
#endif
|
||||
}
|
||||
@@ -310,14 +310,14 @@ bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
|
||||
|
||||
if ( ep_addr == p_itf->ep_out )
|
||||
{
|
||||
#if CFG_TUD_VENDOR_USE_RX_FIFO
|
||||
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
|
||||
// Receive new data
|
||||
tu_fifo_write_n(&p_itf->rx_ff, p_itf->epout_buf, (uint16_t) xferred_bytes);
|
||||
#endif
|
||||
|
||||
// Invoked callback if any
|
||||
if (tud_vendor_rx_cb) tud_vendor_rx_cb(itf, p_itf->epout_buf, (uint16_t) xferred_bytes);
|
||||
#if CFG_TUD_VENDOR_USE_RX_FIFO
|
||||
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
|
||||
_prep_out_transaction(p_itf);
|
||||
#else
|
||||
TU_ASSERT(usbd_edpt_xfer(rhport, p_itf->ep_out, p_itf->epout_buf, CFG_TUD_VENDOR_EPSIZE));
|
||||
@@ -326,7 +326,7 @@ bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
|
||||
else if ( ep_addr == p_itf->ep_in )
|
||||
{
|
||||
if (tud_vendor_tx_cb) tud_vendor_tx_cb(itf, (uint16_t) xferred_bytes);
|
||||
#if CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
|
||||
// Send complete, try to send more if possible
|
||||
tud_vendor_n_write_flush(itf);
|
||||
#endif
|
||||
|
||||
24
src/class/vendor/vendor_device.h
vendored
24
src/class/vendor/vendor_device.h
vendored
@@ -33,12 +33,14 @@
|
||||
#define CFG_TUD_VENDOR_EPSIZE 64
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_VENDOR_USE_RX_FIFO
|
||||
#define CFG_TUD_VENDOR_USE_RX_FIFO 1
|
||||
/* RX FIFO can be disabled by setting this value to 0, related API will also be disabled */
|
||||
#ifndef CFG_TUD_VENDOR_RX_BUFSIZE
|
||||
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#define CFG_TUD_VENDOR_USE_TX_FIFO 1
|
||||
/* TX FIFO can be disabled by setting this value to 0, related API will also be disabled */
|
||||
#ifndef CFG_TUD_VENDOR_TX_BUFSIZE
|
||||
#define CFG_TUD_VENDOR_TX_BUFSIZE 64
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -50,7 +52,7 @@
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_vendor_n_mounted (uint8_t itf);
|
||||
|
||||
#if CFG_TUD_VENDOR_USE_RX_FIFO
|
||||
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
|
||||
uint32_t tud_vendor_n_available (uint8_t itf);
|
||||
uint32_t tud_vendor_n_read (uint8_t itf, void* buffer, uint32_t bufsize);
|
||||
bool tud_vendor_n_peek (uint8_t itf, uint8_t* ui8);
|
||||
@@ -58,13 +60,13 @@ void tud_vendor_n_read_flush (uint8_t itf);
|
||||
#endif
|
||||
|
||||
uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize);
|
||||
#if CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
|
||||
uint32_t tud_vendor_n_write_flush (uint8_t itf);
|
||||
uint32_t tud_vendor_n_write_available (uint8_t itf);
|
||||
#endif
|
||||
static inline uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str);
|
||||
|
||||
#if CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
|
||||
// backward compatible
|
||||
#define tud_vendor_n_flush(itf) tud_vendor_n_write_flush(itf)
|
||||
#endif
|
||||
@@ -73,7 +75,7 @@ static inline uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str);
|
||||
// Application API (Single Port)
|
||||
//--------------------------------------------------------------------+
|
||||
static inline bool tud_vendor_mounted (void);
|
||||
#if CFG_TUD_VENDOR_USE_RX_FIFO
|
||||
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
|
||||
static inline uint32_t tud_vendor_available (void);
|
||||
static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize);
|
||||
static inline bool tud_vendor_peek (uint8_t* ui8);
|
||||
@@ -81,7 +83,7 @@ static inline void tud_vendor_read_flush (void);
|
||||
#endif
|
||||
static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize);
|
||||
static inline uint32_t tud_vendor_write_str (char const* str);
|
||||
#if CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
|
||||
static inline uint32_t tud_vendor_write_available (void);
|
||||
static inline uint32_t tud_vendor_write_flush (void);
|
||||
|
||||
@@ -111,7 +113,7 @@ static inline bool tud_vendor_mounted (void)
|
||||
return tud_vendor_n_mounted(0);
|
||||
}
|
||||
|
||||
#if CFG_TUD_VENDOR_USE_RX_FIFO
|
||||
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
|
||||
static inline uint32_t tud_vendor_available (void)
|
||||
{
|
||||
return tud_vendor_n_available(0);
|
||||
@@ -143,7 +145,7 @@ static inline uint32_t tud_vendor_write_str (char const* str)
|
||||
return tud_vendor_n_write_str(0, str);
|
||||
}
|
||||
|
||||
#if CFG_TUD_VENDOR_USE_TX_FIFO
|
||||
#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
|
||||
static inline uint32_t tud_vendor_write_flush (void)
|
||||
{
|
||||
return tud_vendor_n_write_flush(0);
|
||||
|
||||
Reference in New Issue
Block a user