summaryrefslogtreecommitdiff
path: root/src/tusb.c
diff options
context:
space:
mode:
authorZixun LI <[email protected]>2025-11-27 12:01:33 +0100
committerZixun LI <[email protected]>2025-11-27 12:01:33 +0100
commit2e8d193c732bb211ebff8badff16a84775db42ff (patch)
tree9a3410e65711df25559524b760447ff68fdd316a /src/tusb.c
parentb997ec725812d2f6a573610ba0dd817f271eddea (diff)
parent5ef55bfa30d6f8cf175b3d327f621c76aae7b138 (diff)
Merge remote-tracking branch 'tinyusb/master' into hcd_fsdev
Signed-off-by: Zixun LI <[email protected]>
Diffstat (limited to 'src/tusb.c')
-rw-r--r--src/tusb.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/tusb.c b/src/tusb.c
index 3852da76b..c589e105e 100644
--- a/src/tusb.c
+++ b/src/tusb.c
@@ -387,8 +387,12 @@ TU_ATTR_ALWAYS_INLINE static inline bool stream_xfer(uint8_t hwid, tu_edpt_strea
#endif
} else {
#if CFG_TUD_ENABLED
- return usbd_edpt_xfer(hwid, s->ep_addr, count ? s->ep_buf : NULL, count, false);
- #endif
+ if (s->ep_buf == NULL) {
+ return usbd_edpt_xfer_fifo(hwid, s->ep_addr, &s->ff, count, false);
+ } else {
+ return usbd_edpt_xfer(hwid, s->ep_addr, count ? s->ep_buf : NULL, count, false);
+ }
+ #endif
}
return false;
}
@@ -419,12 +423,17 @@ bool tu_edpt_stream_write_zlp_if_needed(uint8_t hwid, tu_edpt_stream_t* s, uint3
}
uint32_t tu_edpt_stream_write_xfer(uint8_t hwid, tu_edpt_stream_t* s) {
- // skip if no data
- TU_VERIFY(tu_fifo_count(&s->ff) > 0, 0);
+ const uint16_t ff_count = tu_fifo_count(&s->ff);
+ TU_VERIFY(ff_count > 0, 0); // skip if no data
TU_VERIFY(stream_claim(hwid, s), 0);
// Pull data from FIFO -> EP buf
- const uint16_t count = tu_fifo_read_n(&s->ff, s->ep_buf, s->ep_bufsize);
+ uint16_t count;
+ if (s->ep_buf == NULL) {
+ count = ff_count;
+ } else {
+ count = tu_fifo_read_n(&s->ff, s->ep_buf, s->ep_bufsize);
+ }
if (count > 0) {
TU_ASSERT(stream_xfer(hwid, s, count), 0);
@@ -441,7 +450,8 @@ uint32_t tu_edpt_stream_write(uint8_t hwid, tu_edpt_stream_t *s, const void *buf
TU_VERIFY(bufsize > 0); // TODO support ZLP
if (0 == tu_fifo_depth(&s->ff)) {
- // no fifo for buffered
+ // non-fifo mode, ep_buf must be valid
+ TU_VERIFY(s->ep_buf != NULL, 0);
TU_VERIFY(stream_claim(hwid, s), 0);
const uint32_t xact_len = tu_min32(bufsize, s->ep_bufsize);
memcpy(s->ep_buf, buffer, xact_len);
@@ -464,6 +474,7 @@ uint32_t tu_edpt_stream_write_available(uint8_t hwid, tu_edpt_stream_t* s) {
if (tu_fifo_depth(&s->ff) > 0) {
return (uint32_t) tu_fifo_remaining(&s->ff);
} else {
+ // non-fifo mode
bool is_busy = true;
if (s->is_host) {
#if CFG_TUH_ENABLED
@@ -483,7 +494,7 @@ uint32_t tu_edpt_stream_write_available(uint8_t hwid, tu_edpt_stream_t* s) {
//--------------------------------------------------------------------+
uint32_t tu_edpt_stream_read_xfer(uint8_t hwid, tu_edpt_stream_t* s) {
if (0 == tu_fifo_depth(&s->ff)) {
- // no fifo for buffered
+ // non-fifo mode
TU_VERIFY(stream_claim(hwid, s), 0);
TU_ASSERT(stream_xfer(hwid, s, s->ep_bufsize), 0);
return s->ep_bufsize;
@@ -517,7 +528,15 @@ uint32_t tu_edpt_stream_read_xfer(uint8_t hwid, tu_edpt_stream_t* s) {
}
uint32_t tu_edpt_stream_read(uint8_t hwid, tu_edpt_stream_t* s, void* buffer, uint32_t bufsize) {
- const uint32_t num_read = tu_fifo_read_n(&s->ff, buffer, (uint16_t)bufsize);
+ uint32_t num_read;
+ if (tu_fifo_depth(&s->ff) > 0) {
+ num_read = tu_fifo_read_n(&s->ff, buffer, (uint16_t)bufsize);
+ } else {
+ // non-fifo mode
+ memcpy(buffer, s->ep_buf, bufsize);
+ num_read = bufsize;
+ }
+
tu_edpt_stream_read_xfer(hwid, s);
return num_read;
}