summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRémi Berthoz <[email protected]>2026-01-07 17:04:48 +0100
committerRémi Berthoz <[email protected]>2026-01-07 17:36:01 +0100
commit0e5241aa83c52792959ad8a2ef0535a3759530a7 (patch)
tree9ca0493aa275f540041deddd6cec3371f62797a6 /src
parent158fe86b55ee4704b57ad07a95ceb546b82534af (diff)
Adjust printer device class to 0.20.0 and fix compilation warnings
Diffstat (limited to 'src')
-rw-r--r--src/class/printer/printer.h9
-rw-r--r--src/class/printer/printer_device.c13
-rw-r--r--src/device/usbd.h13
-rw-r--r--src/tusb.h4
4 files changed, 29 insertions, 10 deletions
diff --git a/src/class/printer/printer.h b/src/class/printer/printer.h
index 27e95b997..c9ed3cebc 100644
--- a/src/class/printer/printer.h
+++ b/src/class/printer/printer.h
@@ -30,19 +30,18 @@
#include "common/tusb_common.h"
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
/// Printer Class Specific Control Request
-typedef enum
-{
+typedef enum {
PRINTER_REQ_CONTROL_GET_DEVICE_ID = 0x01, ///< Get device ID
PRINTER_REQ_CONTROL_GET_PORT_STATUS = 0x02, ///< Get port status
PRINTER_REQ_CONTROL_SOFT_RESET = 0x03, ///< Soft reset
-}printer_request_enum_t;
+} printer_request_enum_t;
#ifdef __cplusplus
- }
+}
#endif
#endif /* _TUSB_PRINTER_H__ */
diff --git a/src/class/printer/printer_device.c b/src/class/printer/printer_device.c
index efeae100f..76151949b 100644
--- a/src/class/printer/printer_device.c
+++ b/src/class/printer/printer_device.c
@@ -96,7 +96,7 @@ static bool _prep_out_transaction(uint8_t itf) {
available = tu_fifo_remaining(&p_printer->rx_ff);
if (available >= CFG_TUD_PRINTER_EP_BUFSIZE) {
- return usbd_edpt_xfer(rhport, p_printer->ep_out, p_epbuf->epout, CFG_TUD_PRINTER_EP_BUFSIZE);
+ return usbd_edpt_xfer(rhport, p_printer->ep_out, p_epbuf->epout, CFG_TUD_PRINTER_EP_BUFSIZE, false);
} else {
// Release endpoint since we don't make any transfer
usbd_edpt_release(rhport, p_printer->ep_out);
@@ -189,7 +189,7 @@ void printerd_reset(uint8_t rhport) {
for (uint8_t i = 0; i < CFG_TUD_PRINTER; i++) {
printer_interface_t *p_printer = &_printer_itf[i];
- tu_memclr(p_printer, sizeof(p_printer));
+ tu_memclr(p_printer, sizeof(&p_printer));
if (!_printer_fifo_cfg.rx_persistent) {
tu_fifo_clear(&p_printer->rx_ff);
}
@@ -202,6 +202,7 @@ void printerd_reset(uint8_t rhport) {
}
uint16_t printerd_open(uint8_t rhport, const tusb_desc_interface_t *itf_desc, uint16_t max_len) {
+ (void)max_len;
TU_VERIFY(TUSB_CLASS_PRINTER == itf_desc->bInterfaceClass, 0);
// Identify available interface to open
@@ -257,13 +258,13 @@ bool printerd_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_
break;
case PRINTER_REQ_CONTROL_GET_PORT_STATUS:
if (stage == CONTROL_STAGE_SETUP) {
- static uint8_t port_status = (0 << 3) | (1 << 1) | (1 << 2); // ~Paper empty + Selected + NoError
+ static uint8_t port_status = 0b00011000; // paper not empty, selected, no error
return tud_control_xfer(rhport, request, &port_status, sizeof(port_status));
}
break;
case PRINTER_REQ_CONTROL_SOFT_RESET:
if (stage == CONTROL_STAGE_SETUP) {
- return false; // what to do ?
+ return false; // TODO: reset buffers, reset Bulk In and Out endpoints, clear stall conditions
}
break;
default:
@@ -276,6 +277,8 @@ bool printerd_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_
}
bool printerd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
+ (void)rhport;
+ (void)result;
uint8_t itf;
printer_interface_t *p_printer;
@@ -293,7 +296,7 @@ bool printerd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uin
if (ep_addr == p_printer->ep_out) {
tu_fifo_write_n(&p_printer->rx_ff, p_epbuf->epout, (uint16_t)xferred_bytes);
// invoke receive callback (if there is still data)
- if (tud_printer_rx_cb && !tu_fifo_empty(&p_printer->rx_ff)) {
+ if (!tu_fifo_empty(&p_printer->rx_ff)) {
tud_printer_rx_cb(itf, xferred_bytes);
}
// prepare for OUT transaction
diff --git a/src/device/usbd.h b/src/device/usbd.h
index 3b296feea..d473aea2a 100644
--- a/src/device/usbd.h
+++ b/src/device/usbd.h
@@ -292,6 +292,19 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
/* Endpoint In */\
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
+//--------------------------------------------------------------------+
+// Printer Descriptor Templates
+//--------------------------------------------------------------------+
+
+#define TUD_PRINTER_DESC_LEN (9 + 7 + 7) // one interface, two endpoints
+
+#define TUD_PRINTER_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
+ /* Interface */\
+ 9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_PRINTER, 1, 2, _stridx,\
+ /* Endpoint Out */\
+ 7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
+ /* Endpoint In */\
+ 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
//--------------------------------------------------------------------+
// MTP Descriptor Templates
diff --git a/src/tusb.h b/src/tusb.h
index 256a239e7..1f4d4b73a 100644
--- a/src/tusb.h
+++ b/src/tusb.h
@@ -88,6 +88,10 @@
#include "class/msc/msc_device.h"
#endif
+ #if CFG_TUD_PRINTER
+ #include "class/printer/printer_device.h"
+ #endif
+
#if CFG_TUD_MTP
#include "class/mtp/mtp_device.h"
#endif