lufa: Fix keyboard protocol on bus reset #763

Keyboard can be set as Boot protocol by BIOS/UEFI/GRUB
then bus reset occurs before OS boots up.
OS(at least Windows10,11/Ubuntu23.04) expects device works
on Report protocol. Note that OS does not send SetProtocol(Report) here.

Device state should be initialized properly on bus reset.

https://github.com/tmk/tmk_keyboard/issues/763
This commit is contained in:
tmk 2023-07-05 19:03:49 +09:00
parent 9e67abe551
commit d9c100ecf7

View file

@ -41,6 +41,7 @@
#include "host_driver.h"
#include "keyboard.h"
#include "action.h"
#include "action_util.h"
#include "led.h"
#include "sendchar.h"
#include "ringbuf.h"
@ -73,7 +74,7 @@ uint8_t keyboard_idle = 0;
/* 0: Boot Protocol, 1: Report Protocol(default) */
uint8_t keyboard_protocol = 1;
static uint8_t keyboard_led_stats = 0;
static report_keyboard_t keyboard_report_sent;
static report_keyboard_t keyboard_report_sent = (report_keyboard_t){};
#endif
#ifdef MOUSE_ENABLE
@ -305,6 +306,19 @@ void EVENT_USB_Device_Reset(void)
#ifdef TMK_LUFA_DEBUG
print("[R]");
#endif
// reset to initial state: protocol to Report(default)
#ifndef NO_KEYBOARD
keyboard_protocol = 1;
keyboard_idle = 0;
keyboard_led_stats = 0;
keyboard_report_sent = (report_keyboard_t){};
// keyboard_report keys/bits part is not compatible between Boot and Report protocol
clear_keys();
#endif
#ifdef MOUSE_ENABLE
mouse_protocol = 1;
#endif
}
void EVENT_USB_Device_Suspend()