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 - Arduino v3.1 - USBHIDKeyboard won't wake up pc from sleep #10831

Open
1 task done
TheCrypt0 opened this issue Jan 8, 2025 · 0 comments
Open
1 task done
Assignees
Labels
Status: Needs investigation We need to do some research before taking next steps on this issue

Comments

@TheCrypt0
Copy link

Board

ESP32-S3

Device Description

Custom ESP32-S3 keyboard but it should work on any ESP32-S3 devkit with USB connection.

Hardware Configuration

N.A.

Version

v3.1.0

IDE Name

Arduino IDE

Operating System

macOS 15.2

Flash frequency

80MHz

PSRAM enabled

no

Upload speed

921600

Description

I’m using an ESP32-S3 with Arduino’s USBHIDKeyboard library to emulate a USB keyboard. However, the device never enters USB suspend mode when the host (PC) is put to sleep. This prevents the ESP32-S3 from waking the PC using the remote wakeup feature.

Expected Behavior:
• When the PC enters sleep mode, the ESP32-S3 should detect the USB suspend signal and enter suspend mode.
• Upon a key press or specific action, the ESP32-S3 should trigger a remote wakeup to wake the PC.

Actual Behavior:
• The ESP32-S3 simply detects the USB being disconnected.
• The remote wakeup functionality does not work because the device never transitions to suspend mode.

I tested this behavior using a windows notebook and a generic logitech keyboard and once the pc goes (or is forced) to sleep, the keyboard is able to wake it up. Important: the keyboard must be connected before going to sleep.

I tested this with both Arduino version v2.0.17 and v3.1.0, so it appears it's not a new issue.

I must specify I added the REMOTE_WAKEUP attribute before initializing the USB.

USB.usbAttributes(TUSB_DESC_CONFIG_ATT_SELF_POWERED | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP);
USB.begin();

I found another repository that doesn't use the Arduino Core and it seems this is something possible with the ESP32-S3 hardware and TinyUSB: https://github.com/nonoo/esp-remote-wakeup/

I also tried to manually call the tud_remote_wakeup function but without success, it is probably because the bus is not in the suspended mode.

In the example sketch you can replace the Serial Printf for ARDUINO_USB_SUSPEND_EVENT and ARDUINO_USB_RESUME_EVENT with a digitalWrite to a LED to see the behavior without having access to the serial.

Let me know if I can help by providing more details or other stuff I tested.

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;
    }
  }
}

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");

  // also tried with just TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP no change
  m_usb->usbAttributes(TUSB_DESC_CONFIG_ATT_SELF_POWERED | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP);



  m_usb->begin();
}

void
loop()
{
  // put your main code here, to run repeatedly:
  delay(1000);
}

Debug Message

N.A.

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@TheCrypt0 TheCrypt0 added the Status: Awaiting triage Issue is waiting for triage label Jan 8, 2025
@TheCrypt0 TheCrypt0 changed the title ESP32-S3 - USBHIDKeyboard won't wake up pc from sleep ESP32-S3 - Arduino v3.1 - USBHIDKeyboard won't wake up pc from sleep Jan 9, 2025
@SuGlider SuGlider added Status: Needs investigation We need to do some research before taking next steps on this issue and removed Status: Awaiting triage Issue is waiting for triage labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs investigation We need to do some research before taking next steps on this issue
Projects
None yet
Development

No branches or pull requests

2 participants