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

USB Host feature available? #132

Open
unkyulee opened this issue Oct 11, 2024 · 2 comments
Open

USB Host feature available? #132

unkyulee opened this issue Oct 11, 2024 · 2 comments
Labels

Comments

@unkyulee
Copy link

Can't manage to get USB host features. I am trying to get the usb keyboard recognized by T5-ePaper-S3 but no avail.
Does anyone know if usb host is supported and have any example using usb host features?

#include "usb.h"
//
#include "app/app.h"
#include "config/config.h"
//
#include "keyboard/hid/hid.h"

class MyEspUsbHost : public EspUsbHost
{
  void onReceive(const usb_transfer_t *transfer)
  {
    JsonDocument &app = app_status();
    app["hid_usb"] = true;
  }
  void onGone(const usb_host_client_event_msg_t *eventMsg)
  {
    JsonDocument &app = app_status();
    app["hid_usb"] = false;
  }

  // USB Keycode is sent when key is pressed or released
  void onKeyboard(hid_keyboard_report_t report, hid_keyboard_report_t last_report)
  {
#ifdef DEBUG
    app_log("%02x %02x %02x %02x %02x %02x %02x %02x\n", report.modifier, report.reserved, report.keycode[0], report.keycode[1], report.keycode[2], report.keycode[3], report.keycode[4], report.keycode[5]);
#endif

    // Key Pressed
    for (int i = 0; i < 6; i++)
    {
      if (report.keycode[i] != 0)
      {
        // check if the same key appear in the previous report
        bool newkey = true;
        for (int j = 0; j < 6; j++)
        {
          if (last_report.keycode[j] == report.keycode[i])
          {
            newkey = false;
            break;
          }
        }

        // otherwise register new key press
        if (newkey)
        {
          // handle key pressed
          keyboard_hid_pressed(report.keycode[i], report.modifier);
        }
      }
    }

    // Key Released
    for (int i = 0; i < 6; i++)
    {
      if (last_report.keycode[i] != 0)
      {
        bool key_released = true;
        for (int j = 0; j < 6; j++)
        {
          if (last_report.keycode[i] == report.keycode[j])
          {
            key_released = false;
            break;
          }
        }
        if (key_released)
        {
          keyboard_hid_released(last_report.keycode[i], report.modifier);
        }
      }
    }
  }
};

// Handler for USB Keyboard
MyEspUsbHost usbHost;

//
void keyboard_usb_setup()
{
  //
  app_log("Initializing USB Keyboard\n");

  // usb host setup
  usbHost.begin();
}

//
void keyboard_usb_loop()
{
  // Process USB Keyboard Tasks
  usbHost.task();
}

@lewisxhe
Copy link
Contributor

TYPE-C does not have the ability to provide external power. If you want to act as a host, you need to provide additional power to the slave device.

https://github.com/espressif/arduino-esp32/tree/master/libraries/USB/examples

Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Nov 11, 2024
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