Skip to content

Commit

Permalink
lufa: Fix system/consumer report in Boot mouse
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tmk committed Mar 5, 2023
1 parent b5f2bfc commit 0090098
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tmk_core/protocol/lufa/lufa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 0090098

Please sign in to comment.