@@ -242,6 +242,41 @@ bool stream_claim(tu_edpt_stream_t* s)
242
242
return false;
243
243
}
244
244
245
+ TU_ATTR_ALWAYS_INLINE static inline
246
+ bool stream_xfer (tu_edpt_stream_t * s , uint16_t count )
247
+ {
248
+ if (s -> is_host )
249
+ {
250
+ #if CFG_TUH_ENABLED
251
+ return usbh_edpt_xfer (s -> daddr , s -> ep_addr , count ? s -> ep_buf : NULL , count );
252
+ #endif
253
+ }else
254
+ {
255
+ #if CFG_TUD_ENABLED
256
+ return usbd_edpt_xfer (s -> rhport , s -> ep_addr , cont ? s -> ep_buf : NULL , count );
257
+ #endif
258
+ }
259
+
260
+ return false;
261
+ }
262
+
263
+ TU_ATTR_ALWAYS_INLINE static inline
264
+ bool stream_release (tu_edpt_stream_t * s )
265
+ {
266
+ if (s -> is_host )
267
+ {
268
+ #if CFG_TUH_ENABLED
269
+ return usbh_edpt_release (s -> daddr , s -> ep_addr );
270
+ #endif
271
+ }else
272
+ {
273
+ #if CFG_TUD_ENABLED
274
+ return usbd_edpt_release (s -> rhport , s -> ep_addr );
275
+ #endif
276
+ }
277
+
278
+ return false;
279
+ }
245
280
246
281
//--------------------------------------------------------------------+
247
282
// Stream Write
@@ -253,7 +288,7 @@ bool tu_edpt_stream_write_zlp_if_needed(tu_edpt_stream_t* s, uint32_t last_xferr
253
288
TU_VERIFY ( !tu_fifo_count (& s -> ff ) && last_xferred_bytes && (0 == (last_xferred_bytes & (s -> ep_packetsize - 1 ))) );
254
289
255
290
TU_VERIFY ( stream_claim (s ) );
256
- TU_ASSERT ( usbh_edpt_xfer ( s -> daddr , s -> ep_addr , NULL , 0 ) );
291
+ TU_ASSERT ( stream_xfer ( s , 0 ) );
257
292
258
293
return true;
259
294
}
@@ -271,16 +306,13 @@ uint32_t tu_edpt_stream_write_xfer(tu_edpt_stream_t* s)
271
306
272
307
if ( count )
273
308
{
274
- //TU_ASSERT( usbd_edpt_xfer(rhport, p_cdc->ep_in, p_cdc->epin_buf, count), 0 );
275
- TU_ASSERT ( usbh_edpt_xfer (s -> daddr , s -> ep_addr , s -> ep_buf , count ), 0 );
309
+ TU_ASSERT ( stream_xfer (s , count ), 0 );
276
310
return count ;
277
311
}else
278
312
{
279
313
// Release endpoint since we don't make any transfer
280
314
// Note: data is dropped if terminal is not connected
281
- //usbd_edpt_release(rhport, p_cdc->ep_in);
282
-
283
- usbh_edpt_release (s -> daddr , s -> ep_addr );
315
+ stream_release (s );
284
316
return 0 ;
285
317
}
286
318
}
@@ -327,32 +359,13 @@ uint32_t tu_edpt_stream_read_xfer(tu_edpt_stream_t* s)
327
359
uint16_t count = (uint16_t ) (available & ~(s -> ep_packetsize - 1 ));
328
360
count = tu_min16 (count , s -> ep_bufsize );
329
361
330
- if (s -> is_host )
331
- {
332
- #if CFG_TUH_ENABLED
333
- TU_ASSERT ( usbh_edpt_xfer (s -> daddr , s -> ep_addr , s -> ep_buf , count ), 0 );
334
- #endif
335
- }else
336
- {
337
- #if CFG_TUD_ENABLED
338
- TU_ASSERT ( usbd_edpt_xfer (s -> rhport , s -> ep_addr , s -> ep_buf , count ), 0 );
339
- #endif
340
- }
362
+ TU_ASSERT ( stream_xfer (s , count ), 0 );
363
+
341
364
return count ;
342
365
}else
343
366
{
344
367
// Release endpoint since we don't make any transfer
345
- if (s -> is_host )
346
- {
347
- #if CFG_TUH_ENABLED
348
- usbh_edpt_release (s -> daddr , s -> ep_addr );
349
- #endif
350
- }else
351
- {
352
- #if CFG_TUD_ENABLED
353
- usbd_edpt_release (s -> rhport , s -> ep_addr );
354
- #endif
355
- }
368
+ stream_release (s );
356
369
357
370
return 0 ;
358
371
}
0 commit comments