From 0090098141d933e8841bafe58ee64ac78ea8c484 Mon Sep 17 00:00:00 2001 From: tmk Date: Sun, 5 Mar 2023 14:30:51 +0900 Subject: [PATCH] lufa: Fix system/consumer report in Boot mouse Cannot send system/consumer report while mouse is set in boot protocol. Mouse, system and consumer report shares one interface using different report IDs. In boot protocol only mouse can report without report ID. If a report ID is sent while in boot protocol it will be recognized as mosue button state incorrectly by host. A user reported that Mac ejects disc drive at startup when using NeXT converter. Keeping mouse button pressed while bootup forces Mac to eject disc. --- tmk_core/protocol/lufa/lufa.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index d71ab98d..ec78e49a 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -488,7 +488,6 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearStatusStage(); keyboard_protocol = (USB_ControlRequest.wValue & 0xFF); - clear_keyboard(); #ifdef TMK_LUFA_DEBUG xprintf("[P%d %04X]", USB_ControlRequest.wIndex, USB_ControlRequest.wValue); #endif @@ -500,7 +499,9 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearStatusStage(); mouse_protocol = (USB_ControlRequest.wValue & 0xFF); - clear_keyboard(); +#ifdef TMK_LUFA_DEBUG + xprintf("[P%d %04X]", USB_ControlRequest.wIndex, USB_ControlRequest.wValue); +#endif } #endif } @@ -632,6 +633,12 @@ static void send_system(uint16_t data) if (USB_DeviceState != DEVICE_STATE_Configured) return; +#ifdef MOUSE_ENABLE + // Not send while mouse is set to Boot Protocol + if (mouse_protocol == 0) + return; +#endif + report_extra_t r = { .report_id = REPORT_ID_SYSTEM }; if (data < SYSTEM_POWER_DOWN) { r.usage = 0; @@ -657,6 +664,12 @@ static void send_consumer(uint16_t data) if (USB_DeviceState != DEVICE_STATE_Configured) return; +#ifdef MOUSE_ENABLE + // Not send while mouse is set to Boot Protocol + if (mouse_protocol == 0) + return; +#endif + report_extra_t r = { .report_id = REPORT_ID_CONSUMER, .usage = data