Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32-S3 - Recent updates broke tud_hid_n_ready and other HID features #2825

Closed
1 task done
TheCrypt0 opened this issue Oct 2, 2024 · 1 comment
Closed
1 task done
Labels

Comments

@TheCrypt0
Copy link

Operating System

MacOS

Board

ESP32-S3

Firmware

Custom firmware with Arduino Core 3.x.x. See the issue: espressif/arduino-esp32#10296 for more details and a demo sketch.

Sketch
#include <USB.h>
#include <USBCDC.h>
#include <USBHIDKeyboard.h>

USBHIDKeyboard m_keyboard;
USBCDC         m_serial;
ESPUSB*        m_usb;

static void
usbEventCallback(void*            arg,
                 esp_event_base_t event_base,
                 int32_t          event_id,
                 void*            event_data)
{
  if (event_base == ARDUINO_USB_EVENTS) {
    arduino_usb_event_data_t* data = (arduino_usb_event_data_t*)event_data;
    switch (event_id) {
      case ARDUINO_USB_STARTED_EVENT:
        m_serial.println("USB PLUGGED");
        break;
      case ARDUINO_USB_STOPPED_EVENT:
        m_serial.println("USB UNPLUGGED");
        break;
      case ARDUINO_USB_SUSPEND_EVENT:
        m_serial.printf("USB SUSPENDED: remote_wakeup_en: %u\n",
                        data->suspend.remote_wakeup_en);
        break;
      case ARDUINO_USB_RESUME_EVENT:
        m_serial.println("USB RESUMED");
        break;

      default:
        break;
    }
  } else if (event_base == ARDUINO_USB_HID_EVENTS) {
    arduino_usb_hid_event_data_t* data =
      (arduino_usb_hid_event_data_t*)event_data;
    switch (event_id) {
      case ARDUINO_USB_HID_SET_PROTOCOL_EVENT:
        m_serial.printf("HID SET PROTOCOL: %s\n",
                        data->set_protocol.protocol ? "REPORT" : "BOOT");
        break;
      case ARDUINO_USB_HID_SET_IDLE_EVENT:
        m_serial.printf("HID SET IDLE: %u\n", data->set_idle.idle_rate);
        break;

      default:
        break;
    }
  } else if (event_base == ARDUINO_USB_HID_KEYBOARD_EVENTS) {
    arduino_usb_hid_keyboard_event_data_t* data =
      (arduino_usb_hid_keyboard_event_data_t*)event_data;
    switch (event_id) {
      case ARDUINO_USB_HID_KEYBOARD_LED_EVENT:
        m_serial.printf(
          "HID KEYBOARD LED: NumLock:%u, CapsLock:%u, ScrollLock:%u\n",
          data->numlock,
          data->capslock,
          data->scrolllock);
        break;

      default:
        break;
    }
  }
}

void
setup()
{
  // put your setup code here, to run once:
  // m_serial.begin(115200);

  USB.onEvent(usbEventCallback);
  m_keyboard.onEvent(usbEventCallback);
  m_serial.onEvent(usbEventCallback);

  m_keyboard.begin();
  m_serial.begin(115200);
  // m_serial.enableReboot(false);

  m_usb = &USB; // get the USB object
  m_usb->manufacturerName("TEST MAN");
  m_usb->productName("TEST DEV");

  m_usb->begin();
}

void
loop()
{
  // put your main code here, to run repeatedly:
  m_serial.println("Hello World!");

  delay(1000);
  m_keyboard.press(KEY_CAPS_LOCK);
  delay(1000);
  m_keyboard.release(KEY_CAPS_LOCK);

  delay(1000);
}

What happened ?

I'm currently building a USB keyboard using the ESP32-S3 and when upgrading to the latest Arduino Core, the reporting of LEDs (Caps Lock, Num Lock, etc.) did not happen anymore, even though the typing works. Downgrading to 2.0.13 makes the code work again.

We tried to troubleshoot the issue with arduino-esp32's devs but it seems like it is something tinyUSB related and they suggested me to open an issue here.

How to reproduce ?

Nothing specific. Just plug in the ESP32-S3 devkit and observe the serial log.

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

Hello World!
[ 31718][E][USBHID.cpp:347] SendReport(): not ready
[ 32723][E][USBHID.cpp:347] SendReport(): not ready
Hello World!
USB UNPLUGGED
[ 34728][E][USBHID.cpp:347] SendReport(): not ready
[ 35733][E][USBHID.cpp:347] SendReport(): not ready
Hello World!
USB PLUGGED
[ 37516][V][USBHID.cpp:240] tud_hid_set_idle_cb(): instance: 0, idle_rate:0
[ 37524][V][USBHID.cpp:219] tud_hid_descriptor_report_cb(): instance: 0
[ 37531][D][USBHID.cpp:176] tinyusb_load_enabled_hid_devices(): Loaded HID Descriptor with the following reports:
[ 37541][D][USBHID.cpp:179] tinyusb_load_enabled_hid_devices(): ID: 1, Type: INPUT, Size: 8, Usage: KEYBOARD
[ 37551][D][USBHID.cpp:179] tinyusb_load_enabled_hid_devices(): ID: 1, Type: OUTPUT, Size: 1, Usage: KEYBOARD
[ 37577][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 37740][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38227][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38259][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38291][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38339][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38371][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38405][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38438][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38466][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38498][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38530][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38562][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38595][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38626][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38678][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38692][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
[ 38722][D][USBHID.cpp:270] tud_hid_set_report_cb(): instance: 0, report_id: 0, report_type: OUTPUT, bufsize: 2
Hello World!

Screenshots

No response

I have checked existing issues, dicussion and documentation

  • I confirm I have checked existing issues, dicussion and documentation.
@me-no-dev
Copy link
Collaborator

We have found that the way that OUPUT reports are received has slightly changed. Actions are taken out of our end to workaround this issue. This can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants