mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-22 14:57:16 +02:00
Implement USB HID Device Support for ESP32-S2 (#5538)
* Add support and example for USB HID Devices * Add support and example for USB Vendor
This commit is contained in:
52
libraries/USB/examples/HIDVendor/HIDVendor.ino
Normal file
52
libraries/USB/examples/HIDVendor/HIDVendor.ino
Normal file
@ -0,0 +1,52 @@
|
||||
#include "USB.h"
|
||||
#include "USBHIDVendor.h"
|
||||
USBHIDVendor Vendor;
|
||||
|
||||
const int buttonPin = 0;
|
||||
int previousButtonState = HIGH;
|
||||
|
||||
static void vendorEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){
|
||||
if(event_base == ARDUINO_USB_HID_VENDOR_EVENTS){
|
||||
arduino_usb_hid_vendor_event_data_t * data = (arduino_usb_hid_vendor_event_data_t*)event_data;
|
||||
switch (event_id){
|
||||
case ARDUINO_USB_HID_VENDOR_GET_FEATURE_EVENT:
|
||||
Serial.printf("HID VENDOR GET FEATURE: len:%u\n", data->len);
|
||||
break;
|
||||
case ARDUINO_USB_HID_VENDOR_SET_FEATURE_EVENT:
|
||||
Serial.printf("HID VENDOR SET FEATURE: len:%u\n", data->len);
|
||||
for(uint16_t i=0; i<data->len; i++){
|
||||
Serial.printf("0x%02X ",data->buffer);
|
||||
}
|
||||
Serial.println();
|
||||
break;
|
||||
case ARDUINO_USB_HID_VENDOR_OUTPUT_EVENT:
|
||||
Serial.printf("HID VENDOR OUTPUT: len:%u\n", data->len);
|
||||
// for(uint16_t i=0; i<data->len; i++){
|
||||
// Serial.write(Vendor.read());
|
||||
// }
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(buttonPin, INPUT_PULLUP);
|
||||
Serial.begin(115200);
|
||||
Vendor.onEvent(vendorEventCallback);
|
||||
Vendor.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int buttonState = digitalRead(buttonPin);
|
||||
if ((buttonState != previousButtonState) && (buttonState == LOW)) {
|
||||
Vendor.println("Hello World!");
|
||||
}
|
||||
previousButtonState = buttonState;
|
||||
while(Vendor.available()){
|
||||
Serial.write(Vendor.read());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user