Skip to content

Commit 63e64f3

Browse files
authored
Merge pull request #911 from thierer/vendor_class_zero_length_transfer
Enable empty transfers for tud_vendor_n_write()
2 parents ba6babf + 2b9e537 commit 63e64f3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/class/vendor/vendor_device.c

+14-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
//--------------------------------------------------------------------+
3737
// MACRO CONSTANT TYPEDEF
3838
//--------------------------------------------------------------------+
39+
#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
40+
3941
typedef struct
4042
{
4143
uint8_t itf_num;
@@ -273,7 +275,6 @@ uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, ui
273275

274276
bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
275277
{
276-
(void) rhport;
277278
(void) result;
278279

279280
uint8_t itf = 0;
@@ -300,7 +301,18 @@ bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
300301
{
301302
if (tud_vendor_tx_cb) tud_vendor_tx_cb(itf, (uint16_t) xferred_bytes);
302303
// Send complete, try to send more if possible
303-
tud_vendor_n_write_flush(itf);
304+
if ( 0 == tud_vendor_n_write_flush(itf) )
305+
{
306+
// If there is no data left, a ZLP should be sent if
307+
// xferred_bytes is multiple of EP Packet size and not zero
308+
if ( !tu_fifo_count(&p_itf->tx_ff) && xferred_bytes && (0 == (xferred_bytes & (BULK_PACKET_SIZE-1))) )
309+
{
310+
if ( usbd_edpt_claim(rhport, p_itf->ep_in) )
311+
{
312+
usbd_edpt_xfer(rhport, p_itf->ep_in, NULL, 0);
313+
}
314+
}
315+
}
304316
}
305317

306318
return true;

0 commit comments

Comments
 (0)