summaryrefslogtreecommitdiff
path: root/src/device/usbd.c
diff options
context:
space:
mode:
authorhathach <[email protected]>2026-03-06 17:22:38 +0700
committerhathach <[email protected]>2026-03-06 17:22:38 +0700
commit73cd53129529f2dce70072953bfd50ec9dc6b8ea (patch)
treee4fcc75febdc1af7f56973fed061bd2a671f48a2 /src/device/usbd.c
parent988b18a40a4276eb731c80bc4cec3bf5750523f9 (diff)
replace printer_to_hid example with printer_to_cdc example
fix printer GET_DEVICE_ID request weird wIndex (interface high, alt low)
Diffstat (limited to 'src/device/usbd.c')
-rw-r--r--src/device/usbd.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c
index 8d5f94313..42903576c 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -836,7 +836,9 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
#if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL
if (TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type && p_request->bRequest <= TUSB_REQ_SYNCH_FRAME) {
TU_LOG_USBD(" %s", tu_str_std_request[p_request->bRequest]);
- if (TUSB_REQ_GET_DESCRIPTOR != p_request->bRequest) TU_LOG_USBD("\r\n");
+ if (TUSB_REQ_GET_DESCRIPTOR != p_request->bRequest) {
+ TU_LOG_USBD("\r\n");
+ }
}
#endif
@@ -972,7 +974,25 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
//------------- Class/Interface Specific Request -------------//
case TUSB_REQ_RCPT_INTERFACE: {
- uint8_t const itf = tu_u16_low(p_request->wIndex);
+ uint8_t itf;
+ #if CFG_TUD_PRINTER
+ // Printer GET_DEVICE_ID has a weird wIndex = interface (high) | alt (low)
+ // attempt to interpret this as a printer request if matched
+ if (TUSB_REQ_TYPE_CLASS == p_request->bmRequestType_bit.type &&
+ TUSB_DIR_IN == p_request->bmRequestType_bit.direction &&
+ TUSB_PRINTER_REQUEST_GET_DEVICE_ID == p_request->bRequest) {
+ itf = tu_u16_high(p_request->wIndex);
+ if (itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv)) {
+ const usbd_class_driver_t * driver = get_driver(_usbd_dev.itf2drv[itf]);
+ if (driver != NULL && driver->control_xfer_cb == printerd_control_xfer_cb) {
+ if (invoke_class_control(rhport, driver, p_request)) {
+ return true;
+ }
+ }
+ }
+ }
+ #endif
+ itf = tu_u16_low(p_request->wIndex);
TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
usbd_class_driver_t const * driver = get_driver(_usbd_dev.itf2drv[itf]);