summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2025-11-27 23:07:31 +0700
committerhathach <[email protected]>2025-11-27 23:24:00 +0700
commit6e9e9ce9d19d6aa30c69c6e6c82d09dde619f391 (patch)
treee9f94209538f155544d3432496729c47f1350ef0 /src
parent1465a9b5bc64e39d9051b281ffc1f13b5cb6ad9e (diff)
add CFG_TUD_VENDOR_RX_MANUAL_XFER per suggestion
Diffstat (limited to 'src')
-rw-r--r--src/class/vendor/vendor_device.c13
-rw-r--r--src/class/vendor/vendor_device.h51
2 files changed, 54 insertions, 10 deletions
diff --git a/src/class/vendor/vendor_device.c b/src/class/vendor/vendor_device.c
index d468bd0ba..62e183465 100644
--- a/src/class/vendor/vendor_device.c
+++ b/src/class/vendor/vendor_device.c
@@ -136,6 +136,15 @@ void tud_vendor_n_read_flush(uint8_t idx) {
}
#endif
+#if CFG_TUD_VENDOR_RX_MANUAL_XFER
+bool tud_vendor_n_read_xfer(uint8_t idx) {
+ TU_VERIFY(idx < CFG_TUD_VENDOR);
+ vendord_interface_t *p_itf = &_vendord_itf[idx];
+ return tu_edpt_stream_read_xfer(p_itf->rhport, &p_itf->stream.rx);
+}
+#endif
+
+
//--------------------------------------------------------------------+
// Write API
//--------------------------------------------------------------------+
@@ -274,7 +283,9 @@ uint16_t vendord_open(uint8_t rhport, const tusb_desc_interface_t *desc_itf, uin
tu_edpt_stream_t *stream_rx = &p_vendor->stream.rx;
if (stream_rx->ep_addr == 0) {
tu_edpt_stream_open(stream_rx, desc_ep);
+ #if CFG_TUD_VENDOR_RX_MANUAL_XFER == 0
TU_ASSERT(tu_edpt_stream_read_xfer(rhport, stream_rx) > 0, 0); // prepare for incoming data
+ #endif
}
}
}
@@ -302,7 +313,9 @@ bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
tud_vendor_rx_cb(idx, NULL, 0);
#endif
+ #if CFG_TUD_VENDOR_RX_MANUAL_XFER == 0
tu_edpt_stream_read_xfer(rhport, &p_vendor->stream.rx); // prepare next data
+ #endif
} else if (ep_addr == p_vendor->stream.tx.ep_addr) {
// Send complete
tud_vendor_tx_cb(idx, (uint16_t)xferred_bytes);
diff --git a/src/class/vendor/vendor_device.h b/src/class/vendor/vendor_device.h
index daf9c19cf..764d99070 100644
--- a/src/class/vendor/vendor_device.h
+++ b/src/class/vendor/vendor_device.h
@@ -27,8 +27,15 @@
#ifndef TUSB_VENDOR_DEVICE_H_
#define TUSB_VENDOR_DEVICE_H_
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include "common/tusb_common.h"
+//--------------------------------------------------------------------+
+// Configuration
+//--------------------------------------------------------------------+
#ifndef CFG_TUD_VENDOR_EPSIZE
#define CFG_TUD_VENDOR_EPSIZE 64
#endif
@@ -43,30 +50,53 @@
#define CFG_TUD_VENDOR_TX_BUFSIZE 64
#endif
-#ifdef __cplusplus
-extern "C" {
+// Application will manually schedule RX transfer. This can be useful when using with non-fifo (buffered) mode
+// i.e. CFG_TUD_VENDOR_RX_BUFSIZE = 0
+#ifndef CFG_TUD_VENDOR_RX_MANUAL_XFER
+ #define CFG_TUD_VENDOR_RX_MANUAL_XFER 0
#endif
//--------------------------------------------------------------------+
// Application API (Multiple Interfaces) i.e CFG_TUD_VENDOR > 1
//--------------------------------------------------------------------+
-bool tud_vendor_n_mounted(uint8_t idx);
+
+// Return whether the vendor interface is mounted
+bool tud_vendor_n_mounted(uint8_t idx);
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
+// Return number of available bytes for reading
uint32_t tud_vendor_n_available(uint8_t idx);
-bool tud_vendor_n_peek(uint8_t idx, uint8_t *ui8);
+
+// Peek a byte from RX buffer
+bool tud_vendor_n_peek(uint8_t idx, uint8_t *ui8);
+
+// Read from RX FIFO
uint32_t tud_vendor_n_read(uint8_t idx, void *buffer, uint32_t bufsize);
+
+// Discard count bytes in RX FIFO
uint32_t tud_vendor_n_read_discard(uint8_t idx, uint32_t count);
-void tud_vendor_n_read_flush(uint8_t idx);
+
+// Flush (clear) RX FIFO
+void tud_vendor_n_read_flush(uint8_t idx);
+#endif
+
+#if CFG_TUD_VENDOR_RX_MANUAL_XFER
+// Start a new RX transfer to fill the RX FIFO, return false if previous transfer is still ongoing
+bool tud_vendor_n_read_xfer(uint8_t idx);
#endif
+// Write to TX FIFO. This can be buffered and not sent immediately unless buffered bytes >= USB endpoint size
uint32_t tud_vendor_n_write(uint8_t idx, const void *buffer, uint32_t bufsize);
#if CFG_TUD_VENDOR_TX_BUFSIZE > 0
+// Force sending buffered data, return number of bytes sent
uint32_t tud_vendor_n_write_flush(uint8_t idx);
+
+// Return number of bytes available for writing in TX FIFO
uint32_t tud_vendor_n_write_available(uint8_t idx);
#endif
+// Write a null-terminated string to TX FIFO
TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_vendor_n_write_str(uint8_t idx, const char *str) {
return tud_vendor_n_write(idx, str, strlen(str));
}
@@ -103,6 +133,12 @@ TU_ATTR_ALWAYS_INLINE static inline void tud_vendor_read_flush(void) {
}
#endif
+#if CFG_TUD_VENDOR_RX_MANUAL_XFER
+TU_ATTR_ALWAYS_INLINE static inline bool tud_vendor_read_xfer(void) {
+ return tud_vendor_n_read_xfer(0);
+}
+#endif
+
TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_vendor_write(const void *buffer, uint32_t bufsize) {
return tud_vendor_n_write(0, buffer, bufsize);
}
@@ -137,11 +173,6 @@ void tud_vendor_rx_cb(uint8_t idx, const uint8_t *buffer, uint32_t bufsize);
void tud_vendor_tx_cb(uint8_t idx, uint32_t sent_bytes);
//--------------------------------------------------------------------+
-// Inline Functions
-//--------------------------------------------------------------------+
-
-
-//--------------------------------------------------------------------+
// Internal Class Driver API
//--------------------------------------------------------------------+
void vendord_init(void);