summaryrefslogtreecommitdiff
path: root/src/class/printer/printer_device.h
diff options
context:
space:
mode:
authorhathach <[email protected]>2026-03-06 16:06:42 +0700
committerhathach <[email protected]>2026-03-06 16:06:42 +0700
commit988b18a40a4276eb731c80bc4cec3bf5750523f9 (patch)
treedfe79c7d7504a18dcb7ee95d1b3792e5f5b24931 /src/class/printer/printer_device.h
parent5838c7f09dda8921fe6f350871211f8bd5a97208 (diff)
add full read/write() API, use edpt stream for printer class
Diffstat (limited to 'src/class/printer/printer_device.h')
-rw-r--r--src/class/printer/printer_device.h55
1 files changed, 53 insertions, 2 deletions
diff --git a/src/class/printer/printer_device.h b/src/class/printer/printer_device.h
index aeff1ffc5..a6b7052cb 100644
--- a/src/class/printer/printer_device.h
+++ b/src/class/printer/printer_device.h
@@ -38,23 +38,74 @@ extern "C" {
//--------------------------------------------------------------------+
// Get the number of bytes available for reading
-uint32_t tud_printer_n_available(uint8_t itf);
+uint32_t tud_printer_n_read_available(uint8_t itf);
// Read received bytes
uint32_t tud_printer_n_read(uint8_t itf, void *buffer, uint32_t bufsize);
+// Get the number of bytes available for writing
+uint32_t tud_printer_n_write_available(uint8_t itf);
+
// Clear the received FIFO
void tud_printer_n_read_flush(uint8_t itf);
// Get a byte from FIFO without removing it
bool tud_printer_n_peek(uint8_t itf, uint8_t *ui8);
+// Write data to host
+uint32_t tud_printer_n_write(uint8_t itf, const void *buffer, uint32_t bufsize);
+
+// Force sending data in the TX FIFO
+uint32_t tud_printer_n_write_flush(uint8_t itf);
+
+// Clear the transmit FIFO
+bool tud_printer_n_write_clear(uint8_t itf);
+
+//--------------------------------------------------------------------+
+// Application API (Single Port)
+//--------------------------------------------------------------------+
+
+TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_printer_read_available(void) {
+ return tud_printer_n_read_available(0);
+}
+
+TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_printer_write_available(void) {
+ return tud_printer_n_write_available(0);
+}
+
+TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_printer_read(void *buffer, uint32_t bufsize) {
+ return tud_printer_n_read(0, buffer, bufsize);
+}
+
+TU_ATTR_ALWAYS_INLINE static inline void tud_printer_read_flush(void) {
+ tud_printer_n_read_flush(0);
+}
+
+TU_ATTR_ALWAYS_INLINE static inline bool tud_printer_peek(uint8_t *ui8) {
+ return tud_printer_n_peek(0, ui8);
+}
+
+TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_printer_write(const void *buffer, uint32_t bufsize) {
+ return tud_printer_n_write(0, buffer, bufsize);
+}
+
+TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_printer_write_flush(void) {
+ return tud_printer_n_write_flush(0);
+}
+
+TU_ATTR_ALWAYS_INLINE static inline bool tud_printer_write_clear(void) {
+ return tud_printer_n_write_clear(0);
+}
+
//--------------------------------------------------------------------+
// Application Callback API (weak is optional)
//--------------------------------------------------------------------+
// Invoked when received new data
-void tud_printer_rx_cb(uint8_t itf, size_t n);
+void tud_printer_rx_cb(uint8_t itf);
+
+// Invoked when last write transfer is completed
+void tud_printer_tx_complete_cb(uint8_t itf);
// Invoked when host requests device ID string (IEEE 1284).
// Application returns pointer to device ID buffer (must remain valid until transfer completes).