mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-19 06:40:45 +00:00
enable cdc auto flush on write()
if there is enough data in the fifo
This commit is contained in:
parent
67ac40b98d
commit
6fcd540cb6
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
[](https://github.com/hathach/tinyusb/actions) [](https://opensource.org/licenses/MIT) [](https://scan.coverity.com/projects/tinyusb)
|
[](https://github.com/hathach/tinyusb/actions) [](https://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
TinyUSB is an open-source cross-platform USB Host/Device stack for embedded system, designed to be memory-safe with no dynamic allocation and thread-safe with all interrupt events are deferred then handled in the non-ISR task function.
|
TinyUSB is an open-source cross-platform USB Host/Device stack for embedded system, designed to be memory-safe with no dynamic allocation and thread-safe with all interrupt events are deferred then handled in the non-ISR task function.
|
||||||
|
|
||||||
|
@ -34,6 +34,11 @@
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// MACRO CONSTANT TYPEDEF
|
// MACRO CONSTANT TYPEDEF
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
BULK_PACKET_SIZE = (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t itf_num;
|
uint8_t itf_num;
|
||||||
@ -160,13 +165,11 @@ uint32_t tud_cdc_n_write(uint8_t itf, void const* buffer, uint32_t bufsize)
|
|||||||
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
|
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
|
||||||
uint16_t ret = tu_fifo_write_n(&p_cdc->tx_ff, buffer, bufsize);
|
uint16_t ret = tu_fifo_write_n(&p_cdc->tx_ff, buffer, bufsize);
|
||||||
|
|
||||||
#if 0 // TODO issue with circuitpython's REPL
|
// flush if queue more than packet size
|
||||||
// flush if queue more than endpoint size
|
if ( tu_fifo_count(&p_cdc->tx_ff) >= BULK_PACKET_SIZE )
|
||||||
if ( tu_fifo_count(&p_cdc->tx_ff) >= CFG_TUD_CDC_EP_BUFSIZE )
|
|
||||||
{
|
{
|
||||||
tud_cdc_n_write_flush(itf);
|
tud_cdc_n_write_flush(itf);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -250,8 +253,8 @@ void cdcd_reset(uint8_t rhport)
|
|||||||
uint16_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len)
|
uint16_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len)
|
||||||
{
|
{
|
||||||
// Only support ACM subclass
|
// Only support ACM subclass
|
||||||
TU_VERIFY ( TUSB_CLASS_CDC == itf_desc->bInterfaceClass &&
|
TU_VERIFY( TUSB_CLASS_CDC == itf_desc->bInterfaceClass &&
|
||||||
CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL == itf_desc->bInterfaceSubClass, 0);
|
CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL == itf_desc->bInterfaceSubClass, 0);
|
||||||
|
|
||||||
// Note: 0xFF can be used with RNDIS
|
// Note: 0xFF can be used with RNDIS
|
||||||
TU_VERIFY(tu_within(CDC_COMM_PROTOCOL_NONE, itf_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA), 0);
|
TU_VERIFY(tu_within(CDC_COMM_PROTOCOL_NONE, itf_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA), 0);
|
||||||
@ -446,9 +449,8 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
|||||||
if ( 0 == tud_cdc_n_write_flush(itf) )
|
if ( 0 == tud_cdc_n_write_flush(itf) )
|
||||||
{
|
{
|
||||||
// If there is no data left, a ZLP should be sent if
|
// If there is no data left, a ZLP should be sent if
|
||||||
// xferred_bytes is multiple of EP size and not zero
|
// xferred_bytes is multiple of EP Packet size and not zero
|
||||||
// FIXME CFG_TUD_CDC_EP_BUFSIZE is not Endpoint packet size
|
if ( !tu_fifo_count(&p_cdc->tx_ff) && xferred_bytes && (0 == (xferred_bytes & (BULK_PACKET_SIZE-1))) )
|
||||||
if ( !tu_fifo_count(&p_cdc->tx_ff) && xferred_bytes && (0 == (xferred_bytes % CFG_TUD_CDC_EP_BUFSIZE)) )
|
|
||||||
{
|
{
|
||||||
if ( usbd_edpt_claim(rhport, p_cdc->ep_in) )
|
if ( usbd_edpt_claim(rhport, p_cdc->ep_in) )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user