This gist uses the idf-release/v4.2 release of arduino-esp32, can be found here: https://github.com/espressif/arduino-esp32/tree/idf-release/v4.2
Last active
April 19, 2024 10:03
-
-
Save brgaulin/2dec28baf5e9e11dfd7ef8354adf103d to your computer and use it in GitHub Desktop.
ESP32-S2 Keyboard on Arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "esp32-hal.h" | |
#include "esp32-hal-tinyusb.h" | |
#include "USB.h" | |
#define EPNUM_HID 0x81 | |
ESPUSB usb = ESPUSB(); | |
uint8_t const desc_hid_report[] = { TUD_HID_REPORT_DESC_KEYBOARD() }; | |
const uint8_t* tud_hid_descriptor_report_cb(void) | |
{ | |
return desc_hid_report; | |
} | |
static uint16_t load_hid_descriptor(uint8_t * dst, uint8_t * itf) | |
{ | |
uint8_t str_index = tinyusb_add_string_descriptor("Keypad"); | |
uint8_t descriptor[TUD_HID_DESC_LEN] = { | |
TUD_HID_DESCRIPTOR(*itf, str_index, HID_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10) | |
}; | |
*itf+=1; | |
memcpy(dst, descriptor, TUD_HID_DESC_LEN); | |
return TUD_HID_DESC_LEN; | |
} | |
void setup() { | |
Serial.begin(115200); | |
usb.productName("Keypad"); | |
usb.manufacturerName("Me"); | |
tinyusb_enable_interface(USB_INTERFACE_HID, TUD_HID_DESC_LEN, load_hid_descriptor); | |
usb.begin(); | |
Serial.println("[setup] Setup Done!"); | |
} | |
void loop() { | |
if (tud_hid_ready()) { | |
Serial.println("HID Ready! Sending A key"); | |
uint8_t keycode[6] = { 0 }; | |
keycode[0] = HID_KEY_A; | |
tud_hid_keyboard_report(0, 0, keycode); | |
delay(10); | |
tud_hid_keyboard_report(0, 0, NULL); | |
Serial.println("pausing 3s..."); | |
delay(3000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment