Make sure we do not try to send another report before the old one has finished sending
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
uint32_t UsbSystemKeyboardActionCounter;
|
||||
static usb_system_keyboard_report_t usbSystemKeyboardReports[2];
|
||||
usb_system_keyboard_report_t* ActiveUsbSystemKeyboardReport = usbSystemKeyboardReports;
|
||||
static volatile bool sendUsbSystemKeyboardReportCompleted = true;
|
||||
|
||||
usb_system_keyboard_report_t* GetInactiveUsbSystemKeyboardReport()
|
||||
{
|
||||
@@ -21,12 +22,17 @@ void ResetActiveUsbSystemKeyboardReport(void)
|
||||
|
||||
usb_status_t UsbSystemKeyboardAction(void)
|
||||
{
|
||||
if (!sendUsbSystemKeyboardReportCompleted)
|
||||
return kStatus_USB_Busy; // The previous report has not been sent yet
|
||||
|
||||
UsbSystemKeyboardActionCounter++;
|
||||
SwitchActiveUsbSystemKeyboardReport(); // Switch the active report
|
||||
usb_status_t usb_status = USB_DeviceHidSend(
|
||||
UsbCompositeDevice.systemKeyboardHandle, USB_SYSTEM_KEYBOARD_ENDPOINT_INDEX,
|
||||
(uint8_t*)ActiveUsbSystemKeyboardReport, USB_SYSTEM_KEYBOARD_REPORT_LENGTH);
|
||||
if (usb_status == kStatus_USB_Success)
|
||||
SwitchActiveUsbSystemKeyboardReport(); // Switch the active report if the data was sent successfully
|
||||
(uint8_t*)GetInactiveUsbSystemKeyboardReport(), USB_SYSTEM_KEYBOARD_REPORT_LENGTH);
|
||||
if (usb_status == kStatus_USB_Success) {
|
||||
sendUsbSystemKeyboardReportCompleted = false;
|
||||
}
|
||||
return usb_status;
|
||||
}
|
||||
|
||||
@@ -35,7 +41,12 @@ usb_status_t UsbSystemKeyboardCallback(class_handle_t handle, uint32_t event, vo
|
||||
usb_status_t error = kStatus_USB_Error;
|
||||
|
||||
switch (event) {
|
||||
// This report is received when the report has been sent
|
||||
case kUSB_DeviceHidEventSendResponse:
|
||||
sendUsbSystemKeyboardReportCompleted = true;
|
||||
error = kStatus_USB_Success;
|
||||
break;
|
||||
case kUSB_DeviceHidEventRecvResponse:
|
||||
case kUSB_DeviceHidEventGetReport:
|
||||
case kUSB_DeviceHidEventSetReport:
|
||||
case kUSB_DeviceHidEventRequestReportBuffer:
|
||||
|
||||
Reference in New Issue
Block a user