Skip to content

Commit 3ff38c9

Browse files
committed
revert vendor device, let wait for next release of esp32
1 parent 71a7df6 commit 3ff38c9

File tree

2 files changed

+31
-52
lines changed

2 files changed

+31
-52
lines changed

src/class/vendor/vendor_device.c

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,15 @@ static void _prep_out_transaction (vendord_interface_t* p_itf)
9191
{
9292
uint8_t const rhport = 0;
9393

94-
// claim endpoint
95-
TU_VERIFY(usbd_edpt_claim(rhport, p_itf->ep_out), );
94+
// skip if previous transfer not complete
95+
if ( usbd_edpt_busy(rhport, p_itf->ep_out) ) return;
9696

9797
// Prepare for incoming data but only allow what we can store in the ring buffer.
9898
uint16_t max_read = tu_fifo_remaining(&p_itf->rx_ff);
9999
if ( max_read >= CFG_TUD_VENDOR_EPSIZE )
100100
{
101101
usbd_edpt_xfer(rhport, p_itf->ep_out, p_itf->epout_buf, CFG_TUD_VENDOR_EPSIZE);
102102
}
103-
else
104-
{
105-
// Release endpoint since we don't make any transfer
106-
usbd_edpt_release(rhport, p_itf->ep_out);
107-
}
108103
}
109104

110105
uint32_t tud_vendor_n_read (uint8_t itf, void* buffer, uint32_t bufsize)
@@ -125,47 +120,37 @@ void tud_vendor_n_read_flush (uint8_t itf)
125120
//--------------------------------------------------------------------+
126121
// Write API
127122
//--------------------------------------------------------------------+
123+
static uint16_t maybe_transmit(vendord_interface_t* p_itf)
124+
{
125+
uint8_t const rhport = 0;
126+
127+
// skip if previous transfer not complete
128+
TU_VERIFY( !usbd_edpt_busy(rhport, p_itf->ep_in) );
129+
130+
uint16_t count = tu_fifo_read_n(&p_itf->tx_ff, p_itf->epin_buf, CFG_TUD_VENDOR_EPSIZE);
131+
if (count > 0)
132+
{
133+
TU_ASSERT( usbd_edpt_xfer(rhport, p_itf->ep_in, p_itf->epin_buf, count) );
134+
}
135+
return count;
136+
}
137+
128138
uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize)
129139
{
130140
vendord_interface_t* p_itf = &_vendord_itf[itf];
131141
uint16_t ret = tu_fifo_write_n(&p_itf->tx_ff, buffer, (uint16_t) bufsize);
132-
133-
// flush if queue more than packet size
134142
if (tu_fifo_count(&p_itf->tx_ff) >= CFG_TUD_VENDOR_EPSIZE) {
135-
tud_vendor_n_write_flush(itf);
143+
maybe_transmit(p_itf);
136144
}
137145
return ret;
138146
}
139147

140-
uint32_t tud_vendor_n_write_flush (uint8_t itf)
148+
uint32_t tud_vendor_n_flush (uint8_t itf)
141149
{
142150
vendord_interface_t* p_itf = &_vendord_itf[itf];
151+
uint32_t ret = maybe_transmit(p_itf);
143152

144-
// Skip if usb is not ready yet
145-
TU_VERIFY( tud_ready(), 0 );
146-
147-
// No data to send
148-
if ( !tu_fifo_count(&p_itf->tx_ff) ) return 0;
149-
150-
uint8_t const rhport = 0;
151-
152-
// Claim the endpoint
153-
TU_VERIFY( usbd_edpt_claim(rhport, p_itf->ep_in), 0 );
154-
155-
// Pull data from FIFO
156-
uint16_t const count = tu_fifo_read_n(&p_itf->tx_ff, p_itf->epin_buf, sizeof(p_itf->epin_buf));
157-
158-
if ( count )
159-
{
160-
TU_ASSERT( usbd_edpt_xfer(rhport, p_itf->ep_in, p_itf->epin_buf, count), 0 );
161-
return count;
162-
}else
163-
{
164-
// Release endpoint since we don't make any transfer
165-
// Note: data is dropped if terminal is not connected
166-
usbd_edpt_release(rhport, p_itf->ep_in);
167-
return 0;
168-
}
153+
return ret;
169154
}
170155

171156
uint32_t tud_vendor_n_write_available (uint8_t itf)
@@ -245,10 +230,10 @@ uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, ui
245230
// Prepare for incoming data
246231
if ( p_vendor->ep_out )
247232
{
248-
_prep_out_transaction(p_vendor);
233+
TU_ASSERT(usbd_edpt_xfer(rhport, p_vendor->ep_out, p_vendor->epout_buf, sizeof(p_vendor->epout_buf)), 0);
249234
}
250235

251-
if ( p_vendor->ep_in ) tud_vendor_n_write_flush((uint8_t)(p_vendor - _vendord_itf));
236+
if ( p_vendor->ep_in ) maybe_transmit(p_vendor);
252237
}
253238

254239
return (uint16_t) ((uintptr_t) p_desc - (uintptr_t) desc_itf);
@@ -283,7 +268,7 @@ bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
283268
{
284269
if (tud_vendor_tx_cb) tud_vendor_tx_cb(itf, (uint16_t) xferred_bytes);
285270
// Send complete, try to send more if possible
286-
tud_vendor_n_write_flush(itf);
271+
maybe_transmit(p_itf);
287272
}
288273

289274
return true;

src/class/vendor/vendor_device.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,10 @@ bool tud_vendor_n_peek (uint8_t itf, uint8_t* ui8);
4848
void tud_vendor_n_read_flush (uint8_t itf);
4949

5050
uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize);
51-
uint32_t tud_vendor_n_write_flush (uint8_t itf);
5251
uint32_t tud_vendor_n_write_available (uint8_t itf);
5352

5453
static inline uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str);
55-
56-
// backward compatible
57-
#define tud_vendor_n_flush(itf) tud_vendor_n_write_flush(itf)
54+
uint32_t tud_vendor_n_flush (uint8_t itf);
5855

5956
//--------------------------------------------------------------------+
6057
// Application API (Single Port)
@@ -67,10 +64,7 @@ static inline void tud_vendor_read_flush (void);
6764
static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize);
6865
static inline uint32_t tud_vendor_write_str (char const* str);
6966
static inline uint32_t tud_vendor_write_available (void);
70-
static inline uint32_t tud_vendor_write_flush (void);
71-
72-
// backward compatible
73-
#define tud_vendor_flush() tud_vendor_write_flush()
67+
static inline uint32_t tud_vendor_flush (void);
7468

7569
//--------------------------------------------------------------------+
7670
// Application Callback API (weak is optional)
@@ -120,11 +114,6 @@ static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize)
120114
return tud_vendor_n_write(0, buffer, bufsize);
121115
}
122116

123-
static inline uint32_t tud_vendor_write_flush (void)
124-
{
125-
return tud_vendor_n_write_flush(0);
126-
}
127-
128117
static inline uint32_t tud_vendor_write_str (char const* str)
129118
{
130119
return tud_vendor_n_write_str(0, str);
@@ -135,6 +124,11 @@ static inline uint32_t tud_vendor_write_available (void)
135124
return tud_vendor_n_write_available(0);
136125
}
137126

127+
static inline uint32_t tud_vendor_flush (void)
128+
{
129+
return tud_vendor_n_flush(0);
130+
}
131+
138132
//--------------------------------------------------------------------+
139133
// Internal Class Driver API
140134
//--------------------------------------------------------------------+

0 commit comments

Comments
 (0)