Skip to content

Commit

Permalink
Merge pull request #911 from thierer/vendor_class_zero_length_transfer
Browse files Browse the repository at this point in the history
Enable empty transfers for tud_vendor_n_write()
  • Loading branch information
HiFiPhile authored May 9, 2024
2 parents ba6babf + 2b9e537 commit 63e64f3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/class/vendor/vendor_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

typedef struct
{
uint8_t itf_num;
Expand Down Expand Up @@ -273,7 +275,6 @@ uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, ui

bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
{
(void) rhport;
(void) result;

uint8_t itf = 0;
Expand All @@ -300,7 +301,18 @@ bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
{
if (tud_vendor_tx_cb) tud_vendor_tx_cb(itf, (uint16_t) xferred_bytes);
// Send complete, try to send more if possible
tud_vendor_n_write_flush(itf);
if ( 0 == tud_vendor_n_write_flush(itf) )
{
// If there is no data left, a ZLP should be sent if
// xferred_bytes is multiple of EP Packet size and not zero
if ( !tu_fifo_count(&p_itf->tx_ff) && xferred_bytes && (0 == (xferred_bytes & (BULK_PACKET_SIZE-1))) )
{
if ( usbd_edpt_claim(rhport, p_itf->ep_in) )
{
usbd_edpt_xfer(rhport, p_itf->ep_in, NULL, 0);
}
}
}
}

return true;
Expand Down

0 comments on commit 63e64f3

Please sign in to comment.