3.3.7
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
#include "USB.h"
|
||||
#include "USBHIDMouse.h"
|
||||
#include "USBHIDKeyboard.h"
|
||||
#include "USBHIDGamepad.h"
|
||||
#include "USBHIDConsumerControl.h"
|
||||
#include "USBHIDSystemControl.h"
|
||||
#include "USBHIDVendor.h"
|
||||
#include "FirmwareMSC.h"
|
||||
|
||||
#if !ARDUINO_USB_MSC_ON_BOOT
|
||||
FirmwareMSC MSC_Update;
|
||||
#endif
|
||||
|
||||
#if !ARDUINO_USB_CDC_ON_BOOT
|
||||
USBCDC USBSerial;
|
||||
#endif
|
||||
|
||||
USBHID HID;
|
||||
USBHIDKeyboard Keyboard;
|
||||
USBHIDMouse Mouse;
|
||||
USBHIDGamepad Gamepad;
|
||||
USBHIDConsumerControl ConsumerControl;
|
||||
USBHIDSystemControl SystemControl;
|
||||
USBHIDVendor Vendor;
|
||||
|
||||
const int buttonPin = 0;
|
||||
int previousButtonState = HIGH;
|
||||
|
||||
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: Serial.println("USB PLUGGED"); break;
|
||||
case ARDUINO_USB_STOPPED_EVENT: Serial.println("USB UNPLUGGED"); break;
|
||||
case ARDUINO_USB_SUSPEND_EVENT: Serial.printf("USB SUSPENDED: remote_wakeup_en: %u\n", data->suspend.remote_wakeup_en); break;
|
||||
case ARDUINO_USB_RESUME_EVENT: Serial.println("USB RESUMED"); break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
} else if (event_base == ARDUINO_USB_CDC_EVENTS) {
|
||||
arduino_usb_cdc_event_data_t *data = (arduino_usb_cdc_event_data_t *)event_data;
|
||||
switch (event_id) {
|
||||
case ARDUINO_USB_CDC_CONNECTED_EVENT: Serial.println("CDC CONNECTED"); break;
|
||||
case ARDUINO_USB_CDC_DISCONNECTED_EVENT: Serial.println("CDC DISCONNECTED"); break;
|
||||
case ARDUINO_USB_CDC_LINE_STATE_EVENT: Serial.printf("CDC LINE STATE: dtr: %u, rts: %u\n", data->line_state.dtr, data->line_state.rts); break;
|
||||
case ARDUINO_USB_CDC_LINE_CODING_EVENT:
|
||||
Serial.printf(
|
||||
"CDC LINE CODING: bit_rate: %lu, data_bits: %u, stop_bits: %u, parity: %u\n", data->line_coding.bit_rate, data->line_coding.data_bits,
|
||||
data->line_coding.stop_bits, data->line_coding.parity
|
||||
);
|
||||
break;
|
||||
case ARDUINO_USB_CDC_RX_EVENT:
|
||||
Serial.printf("CDC RX [%u]:", data->rx.len);
|
||||
{
|
||||
uint8_t buf[data->rx.len];
|
||||
size_t len = USBSerial.read(buf, data->rx.len);
|
||||
Serial.write(buf, len);
|
||||
}
|
||||
Serial.println();
|
||||
break;
|
||||
case ARDUINO_USB_CDC_RX_OVERFLOW_EVENT: Serial.printf("CDC RX Overflow of %d bytes", data->rx_overflow.dropped_bytes); break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
} else if (event_base == ARDUINO_FIRMWARE_MSC_EVENTS) {
|
||||
arduino_firmware_msc_event_data_t *data = (arduino_firmware_msc_event_data_t *)event_data;
|
||||
switch (event_id) {
|
||||
case ARDUINO_FIRMWARE_MSC_START_EVENT: Serial.println("MSC Update Start"); break;
|
||||
case ARDUINO_FIRMWARE_MSC_WRITE_EVENT:
|
||||
//Serial.printf("MSC Update Write %u bytes at offset %u\n", data->write.size, data->write.offset);
|
||||
Serial.print(".");
|
||||
break;
|
||||
case ARDUINO_FIRMWARE_MSC_END_EVENT: Serial.printf("\nMSC Update End: %u bytes\n", data->end.size); break;
|
||||
case ARDUINO_FIRMWARE_MSC_ERROR_EVENT: Serial.printf("MSC Update ERROR! Progress: %u bytes\n", data->error.size); break;
|
||||
case ARDUINO_FIRMWARE_MSC_POWER_EVENT:
|
||||
Serial.printf("MSC Update Power: power: %u, start: %u, eject: %u\n", data->power.power_condition, data->power.start, data->power.load_eject);
|
||||
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: Serial.printf("HID SET PROTOCOL: %s\n", data->set_protocol.protocol ? "REPORT" : "BOOT"); break;
|
||||
case ARDUINO_USB_HID_SET_IDLE_EVENT: 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:
|
||||
Serial.printf("HID KEYBOARD LED: NumLock:%u, CapsLock:%u, ScrollLock:%u\n", data->numlock, data->capslock, data->scrolllock);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
} else 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);
|
||||
for (uint16_t i = 0; i < data->len; i++) {
|
||||
Serial.write(data->buffer[i] ? data->buffer[i] : '.');
|
||||
}
|
||||
Serial.println();
|
||||
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.write(data->buffer[i] ? data->buffer[i] : '.');
|
||||
}
|
||||
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());
|
||||
}
|
||||
Serial.println();
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.setDebugOutput(true);
|
||||
|
||||
pinMode(buttonPin, INPUT_PULLUP);
|
||||
|
||||
USB.onEvent(usbEventCallback);
|
||||
USBSerial.onEvent(usbEventCallback);
|
||||
MSC_Update.onEvent(usbEventCallback);
|
||||
HID.onEvent(usbEventCallback);
|
||||
Keyboard.onEvent(usbEventCallback);
|
||||
Vendor.onEvent(usbEventCallback);
|
||||
|
||||
USBSerial.begin();
|
||||
MSC_Update.begin();
|
||||
Vendor.begin();
|
||||
Mouse.begin();
|
||||
Keyboard.begin();
|
||||
Gamepad.begin();
|
||||
ConsumerControl.begin();
|
||||
SystemControl.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int buttonState = digitalRead(buttonPin);
|
||||
if (HID.ready() && buttonState != previousButtonState) {
|
||||
previousButtonState = buttonState;
|
||||
if (buttonState == LOW) {
|
||||
if (Serial != USBSerial) {
|
||||
Serial.println("Button Pressed");
|
||||
}
|
||||
USBSerial.println("Button Pressed");
|
||||
Vendor.println("Button Pressed");
|
||||
Mouse.move(10, 10);
|
||||
Keyboard.pressRaw(HID_KEY_CAPS_LOCK);
|
||||
Gamepad.leftStick(100, 100);
|
||||
ConsumerControl.press(CONSUMER_CONTROL_VOLUME_INCREMENT);
|
||||
//SystemControl.press(SYSTEM_CONTROL_POWER_OFF);
|
||||
} else {
|
||||
Keyboard.releaseRaw(HID_KEY_CAPS_LOCK);
|
||||
Gamepad.leftStick(0, 0);
|
||||
ConsumerControl.release();
|
||||
//SystemControl.release();
|
||||
Vendor.println("Button Released");
|
||||
USBSerial.println("Button Released");
|
||||
if (Serial != USBSerial) {
|
||||
Serial.println("Button Released");
|
||||
}
|
||||
}
|
||||
delay(100);
|
||||
}
|
||||
|
||||
while (Serial.available()) {
|
||||
size_t l = Serial.available();
|
||||
uint8_t b[l];
|
||||
l = Serial.read(b, l);
|
||||
USBSerial.write(b, l);
|
||||
if (HID.ready()) {
|
||||
Vendor.write(b, l);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
#include "USB.h"
|
||||
#include "USBHIDConsumerControl.h"
|
||||
USBHIDConsumerControl ConsumerControl;
|
||||
|
||||
const int buttonPin = 0;
|
||||
int previousButtonState = HIGH;
|
||||
|
||||
void setup() {
|
||||
pinMode(buttonPin, INPUT_PULLUP);
|
||||
ConsumerControl.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int buttonState = digitalRead(buttonPin);
|
||||
if ((buttonState != previousButtonState) && (buttonState == LOW)) {
|
||||
ConsumerControl.press(CONSUMER_CONTROL_VOLUME_INCREMENT);
|
||||
ConsumerControl.release();
|
||||
}
|
||||
previousButtonState = buttonState;
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,88 @@
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
#include "USB.h"
|
||||
#include "USBHID.h"
|
||||
USBHID HID;
|
||||
|
||||
static const uint8_t report_descriptor[] = {
|
||||
// 8 axis
|
||||
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
|
||||
0x09, 0x04, // Usage (Joystick)
|
||||
0xa1, 0x01, // Collection (Application)
|
||||
0xa1, 0x00, // Collection (Physical)
|
||||
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
|
||||
0x09, 0x30, // Usage (X)
|
||||
0x09, 0x31, // Usage (Y)
|
||||
0x09, 0x32, // Usage (Z)
|
||||
0x09, 0x33, // Usage (Rx)
|
||||
0x09, 0x34, // Usage (Ry)
|
||||
0x09, 0x35, // Usage (Rz)
|
||||
0x09, 0x36, // Usage (Slider)
|
||||
0x09, 0x36, // Usage (Slider)
|
||||
0x15, 0x81, // Logical Minimum (-127)
|
||||
0x25, 0x7f, // Logical Maximum (127)
|
||||
0x75, 0x08, // Report Size (8)
|
||||
0x95, 0x08, // Report Count (8)
|
||||
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
|
||||
0xC0, // End Collection
|
||||
0xC0, // End Collection
|
||||
};
|
||||
|
||||
class CustomHIDDevice : public USBHIDDevice {
|
||||
public:
|
||||
CustomHIDDevice(void) {
|
||||
static bool initialized = false;
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
HID.addDevice(this, sizeof(report_descriptor));
|
||||
}
|
||||
}
|
||||
|
||||
void begin(void) {
|
||||
HID.begin();
|
||||
}
|
||||
|
||||
uint16_t _onGetDescriptor(uint8_t *buffer) {
|
||||
memcpy(buffer, report_descriptor, sizeof(report_descriptor));
|
||||
return sizeof(report_descriptor);
|
||||
}
|
||||
|
||||
bool send(uint8_t *value) {
|
||||
return HID.SendReport(0, value, 8);
|
||||
}
|
||||
};
|
||||
|
||||
CustomHIDDevice Device;
|
||||
|
||||
const int buttonPin = 0;
|
||||
int previousButtonState = HIGH;
|
||||
uint8_t axis[8];
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.setDebugOutput(true);
|
||||
pinMode(buttonPin, INPUT_PULLUP);
|
||||
Device.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int buttonState = digitalRead(buttonPin);
|
||||
if (HID.ready() && buttonState != previousButtonState) {
|
||||
previousButtonState = buttonState;
|
||||
if (buttonState == LOW) {
|
||||
Serial.println("Button Pressed");
|
||||
axis[0] = random() & 0xFF;
|
||||
Device.send(axis);
|
||||
} else {
|
||||
Serial.println("Button Released");
|
||||
}
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,58 @@
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
#include "USB.h"
|
||||
#include "FirmwareMSC.h"
|
||||
|
||||
#if !ARDUINO_USB_MSC_ON_BOOT
|
||||
FirmwareMSC MSC_Update;
|
||||
#endif
|
||||
|
||||
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: Serial.println("USB PLUGGED"); break;
|
||||
case ARDUINO_USB_STOPPED_EVENT: Serial.println("USB UNPLUGGED"); break;
|
||||
case ARDUINO_USB_SUSPEND_EVENT: Serial.printf("USB SUSPENDED: remote_wakeup_en: %u\n", data->suspend.remote_wakeup_en); break;
|
||||
case ARDUINO_USB_RESUME_EVENT: Serial.println("USB RESUMED"); break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
} else if (event_base == ARDUINO_FIRMWARE_MSC_EVENTS) {
|
||||
arduino_firmware_msc_event_data_t *data = (arduino_firmware_msc_event_data_t *)event_data;
|
||||
switch (event_id) {
|
||||
case ARDUINO_FIRMWARE_MSC_START_EVENT: Serial.println("MSC Update Start"); break;
|
||||
case ARDUINO_FIRMWARE_MSC_WRITE_EVENT:
|
||||
//Serial.printf("MSC Update Write %u bytes at offset %u\n", data->write.size, data->write.offset);
|
||||
Serial.print(".");
|
||||
break;
|
||||
case ARDUINO_FIRMWARE_MSC_END_EVENT: Serial.printf("\nMSC Update End: %u bytes\n", data->end.size); break;
|
||||
case ARDUINO_FIRMWARE_MSC_ERROR_EVENT: Serial.printf("MSC Update ERROR! Progress: %u bytes\n", data->error.size); break;
|
||||
case ARDUINO_FIRMWARE_MSC_POWER_EVENT:
|
||||
Serial.printf("MSC Update Power: power: %u, start: %u, eject: %u", data->power.power_condition, data->power.start, data->power.load_eject);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.setDebugOutput(true);
|
||||
|
||||
USB.onEvent(usbEventCallback);
|
||||
MSC_Update.onEvent(usbEventCallback);
|
||||
MSC_Update.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,57 @@
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
#include "USB.h"
|
||||
#include "USBHIDGamepad.h"
|
||||
USBHIDGamepad Gamepad;
|
||||
|
||||
const int buttonPin = 0;
|
||||
int previousButtonState = HIGH;
|
||||
|
||||
void setup() {
|
||||
pinMode(buttonPin, INPUT_PULLUP);
|
||||
Gamepad.begin();
|
||||
USB.begin();
|
||||
Serial.begin(115200);
|
||||
Serial.println("\n==================\nUSB Gamepad Testing\n==================\n");
|
||||
Serial.println("Press BOOT Button to activate the USB gamepad.");
|
||||
Serial.println("Longer press will change the affected button and controls.");
|
||||
Serial.println("Shorter press/release just activates the button and controls.");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static uint8_t padID = 0;
|
||||
static long lastPress = 0;
|
||||
|
||||
int buttonState = digitalRead(buttonPin);
|
||||
if (buttonState != previousButtonState) {
|
||||
if (buttonState == LOW) { // BOOT Button pressed
|
||||
Gamepad.pressButton(padID); // Buttons 1 to 32
|
||||
Gamepad.leftStick(padID << 3, padID << 3); // X Axis, Y Axis
|
||||
Gamepad.rightStick(-(padID << 2), padID << 2); // Z Axis, Z Rotation
|
||||
Gamepad.leftTrigger(padID << 4); // X Rotation
|
||||
Gamepad.rightTrigger(-(padID << 4)); // Y Rotation
|
||||
Gamepad.hat((padID & 0x7) + 1); // Point of View Hat
|
||||
log_d("Pressed PadID [%d]", padID);
|
||||
lastPress = millis();
|
||||
} else {
|
||||
Gamepad.releaseButton(padID);
|
||||
Gamepad.leftStick(0, 0);
|
||||
Gamepad.rightStick(0, 0);
|
||||
Gamepad.leftTrigger(0);
|
||||
Gamepad.rightTrigger(0);
|
||||
Gamepad.hat(HAT_CENTER);
|
||||
log_d("Released PadID [%d]\n", padID);
|
||||
if (millis() - lastPress > 300) {
|
||||
padID = (padID + 1) & 0x1F;
|
||||
log_d("Changed padID to %d\n", padID);
|
||||
}
|
||||
}
|
||||
}
|
||||
previousButtonState = buttonState;
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,57 @@
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
#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());
|
||||
}
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
Keyboard logout
|
||||
|
||||
This sketch demonstrates the Keyboard library.
|
||||
|
||||
When you connect pin 2 to ground, it performs a logout.
|
||||
It uses keyboard combinations to do this, as follows:
|
||||
|
||||
On Windows, CTRL-ALT-DEL followed by ALT-l
|
||||
On Ubuntu, CTRL-ALT-DEL, and ENTER
|
||||
On OSX, CMD-SHIFT-q
|
||||
|
||||
To wake: Spacebar.
|
||||
|
||||
Circuit:
|
||||
- Arduino Leonardo or Micro
|
||||
- wire to connect D2 to ground
|
||||
|
||||
created 6 Mar 2012
|
||||
modified 27 Mar 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardLogout
|
||||
*/
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
|
||||
#define OSX 0
|
||||
#define WINDOWS 1
|
||||
#define UBUNTU 2
|
||||
|
||||
#include "USB.h"
|
||||
#include "USBHIDKeyboard.h"
|
||||
USBHIDKeyboard Keyboard;
|
||||
|
||||
// change this to match your platform:
|
||||
int platform = OSX;
|
||||
|
||||
const int buttonPin = 0; // input pin for pushbutton
|
||||
|
||||
void setup() {
|
||||
// make pin 0 an input and turn on the pull-up resistor so it goes high unless
|
||||
// connected to ground:
|
||||
pinMode(buttonPin, INPUT_PULLUP);
|
||||
Keyboard.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
while (digitalRead(buttonPin) == HIGH) {
|
||||
// do nothing until pin 2 goes low
|
||||
delay(500);
|
||||
}
|
||||
delay(1000);
|
||||
|
||||
switch (platform) {
|
||||
case OSX:
|
||||
Keyboard.press(KEY_LEFT_GUI);
|
||||
// Shift-Q logs out:
|
||||
Keyboard.press(KEY_LEFT_SHIFT);
|
||||
Keyboard.press('Q');
|
||||
delay(100);
|
||||
Keyboard.releaseAll();
|
||||
// enter:
|
||||
Keyboard.write(KEY_RETURN);
|
||||
break;
|
||||
case WINDOWS:
|
||||
// CTRL-ALT-DEL:
|
||||
Keyboard.press(KEY_LEFT_CTRL);
|
||||
Keyboard.press(KEY_LEFT_ALT);
|
||||
Keyboard.press(KEY_DELETE);
|
||||
delay(100);
|
||||
Keyboard.releaseAll();
|
||||
// ALT-l:
|
||||
delay(2000);
|
||||
Keyboard.press(KEY_LEFT_ALT);
|
||||
Keyboard.press('l');
|
||||
Keyboard.releaseAll();
|
||||
break;
|
||||
case UBUNTU:
|
||||
// CTRL-ALT-DEL:
|
||||
Keyboard.press(KEY_LEFT_CTRL);
|
||||
Keyboard.press(KEY_LEFT_ALT);
|
||||
Keyboard.press(KEY_DELETE);
|
||||
delay(1000);
|
||||
Keyboard.releaseAll();
|
||||
// Enter to confirm logout:
|
||||
Keyboard.write(KEY_RETURN);
|
||||
break;
|
||||
}
|
||||
|
||||
// do nothing:
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Keyboard Message test
|
||||
|
||||
For the Arduino Leonardo and Micro.
|
||||
|
||||
Sends a text string when a button is pressed.
|
||||
|
||||
The circuit:
|
||||
- pushbutton attached from pin 0 to ground
|
||||
- 10 kilohm resistor attached from pin 0 to +5V
|
||||
|
||||
created 24 Oct 2011
|
||||
modified 27 Mar 2012
|
||||
by Tom Igoe
|
||||
modified 11 Nov 2013
|
||||
by Scott Fitzgerald
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardMessage
|
||||
*/
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
|
||||
#include "USB.h"
|
||||
#include "USBHIDKeyboard.h"
|
||||
USBHIDKeyboard Keyboard;
|
||||
|
||||
const int buttonPin = 0; // input pin for pushbutton
|
||||
int previousButtonState = HIGH; // for checking the state of a pushButton
|
||||
int counter = 0; // button push counter
|
||||
|
||||
void setup() {
|
||||
// make the pushButton pin an input:
|
||||
pinMode(buttonPin, INPUT_PULLUP);
|
||||
// initialize control over the keyboard:
|
||||
Keyboard.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the pushbutton:
|
||||
int buttonState = digitalRead(buttonPin);
|
||||
// if the button state has changed,
|
||||
if ((buttonState != previousButtonState)
|
||||
// and it's currently pressed:
|
||||
&& (buttonState == LOW)) {
|
||||
// increment the button counter
|
||||
counter++;
|
||||
// type out a message
|
||||
Keyboard.print("You pressed the button ");
|
||||
Keyboard.print(counter);
|
||||
Keyboard.println(" times.");
|
||||
}
|
||||
// save the current button state for comparison next time:
|
||||
previousButtonState = buttonState;
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
Arduino Programs Blink
|
||||
|
||||
This sketch demonstrates the Keyboard library.
|
||||
|
||||
For Leonardo and Due boards only.
|
||||
|
||||
When you connect pin 2 to ground, it creates a new window with a key
|
||||
combination (CTRL-N), then types in the Blink sketch, then auto-formats the
|
||||
text using another key combination (CTRL-T), then uploads the sketch to the
|
||||
currently selected Arduino using a final key combination (CTRL-U).
|
||||
|
||||
Circuit:
|
||||
- Arduino Leonardo, Micro, Due, LilyPad USB, or Yún
|
||||
- wire to connect D2 to ground
|
||||
|
||||
created 5 Mar 2012
|
||||
modified 29 Mar 2012
|
||||
by Tom Igoe
|
||||
modified 3 May 2014
|
||||
by Scott Fitzgerald
|
||||
|
||||
This example is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardReprogram
|
||||
*/
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
|
||||
#include "USB.h"
|
||||
#include "USBHIDKeyboard.h"
|
||||
USBHIDKeyboard Keyboard;
|
||||
|
||||
const int buttonPin = 0; // input pin for pushbutton
|
||||
|
||||
// use this option for OSX.
|
||||
// Comment it out if using Windows or Linux:
|
||||
char ctrlKey = KEY_LEFT_GUI;
|
||||
// use this option for Windows and Linux.
|
||||
// leave commented out if using OSX:
|
||||
// char ctrlKey = KEY_LEFT_CTRL;
|
||||
|
||||
void setup() {
|
||||
// make pin 0 an input and turn on the pull-up resistor so it goes high unless
|
||||
// connected to ground:
|
||||
pinMode(buttonPin, INPUT_PULLUP);
|
||||
// initialize control over the keyboard:
|
||||
Keyboard.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
while (digitalRead(buttonPin) == HIGH) {
|
||||
// do nothing until pin 0 goes low
|
||||
delay(500);
|
||||
}
|
||||
delay(1000);
|
||||
// new document:
|
||||
Keyboard.press(ctrlKey);
|
||||
Keyboard.press('n');
|
||||
delay(100);
|
||||
Keyboard.releaseAll();
|
||||
// wait for new window to open:
|
||||
delay(1000);
|
||||
|
||||
// versions of the Arduino IDE after 1.5 pre-populate new sketches with
|
||||
// setup() and loop() functions let's clear the window before typing anything new
|
||||
// select all
|
||||
Keyboard.press(ctrlKey);
|
||||
Keyboard.press('a');
|
||||
delay(500);
|
||||
Keyboard.releaseAll();
|
||||
// delete the selected text
|
||||
Keyboard.write(KEY_BACKSPACE);
|
||||
delay(500);
|
||||
|
||||
// Type out "blink":
|
||||
Keyboard.println("void setup() {");
|
||||
Keyboard.println("pinMode(13, OUTPUT);");
|
||||
Keyboard.println("}");
|
||||
Keyboard.println();
|
||||
Keyboard.println("void loop() {");
|
||||
Keyboard.println("digitalWrite(13, HIGH);");
|
||||
Keyboard.print("delay(3000);");
|
||||
// 3000 ms is too long. Delete it:
|
||||
for (int keystrokes = 0; keystrokes < 6; keystrokes++) {
|
||||
delay(500);
|
||||
Keyboard.write(KEY_BACKSPACE);
|
||||
}
|
||||
// make it 1000 instead:
|
||||
Keyboard.println("1000);");
|
||||
Keyboard.println("digitalWrite(13, LOW);");
|
||||
Keyboard.println("delay(1000);");
|
||||
Keyboard.println("}");
|
||||
// tidy up:
|
||||
Keyboard.press(ctrlKey);
|
||||
Keyboard.press('t');
|
||||
delay(100);
|
||||
Keyboard.releaseAll();
|
||||
delay(3000);
|
||||
// upload code:
|
||||
Keyboard.press(ctrlKey);
|
||||
Keyboard.press('u');
|
||||
delay(100);
|
||||
Keyboard.releaseAll();
|
||||
|
||||
// wait for the sweet oblivion of reprogramming:
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Keyboard test
|
||||
|
||||
Reads a byte from the serial port, sends a keystroke back.
|
||||
The sent keystroke is one higher than what's received, e.g. if you send a,
|
||||
you get b, send A you get B, and so forth.
|
||||
|
||||
The circuit:
|
||||
- none
|
||||
|
||||
created 21 Oct 2011
|
||||
modified 27 Mar 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardSerial
|
||||
*/
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
|
||||
#include "USB.h"
|
||||
#include "USBHIDKeyboard.h"
|
||||
USBHIDKeyboard Keyboard;
|
||||
|
||||
void setup() {
|
||||
// open the serial port:
|
||||
Serial.begin(115200);
|
||||
// initialize control over the keyboard:
|
||||
Keyboard.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check for incoming serial data:
|
||||
if (Serial.available() > 0) {
|
||||
// read incoming serial data:
|
||||
char inChar = Serial.read();
|
||||
// Type the next ASCII value from what you received:
|
||||
Keyboard.write(inChar + 1);
|
||||
}
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
KeyboardAndMouseControl
|
||||
|
||||
Hardware:
|
||||
- five pushbuttons attached to D12, D13, D14, D15, D0
|
||||
|
||||
The mouse movement is always relative. This sketch reads four pushbuttons, and
|
||||
uses them to set the movement of the mouse.
|
||||
|
||||
WARNING: When you use the Mouse.move() command, the Arduino takes over your
|
||||
mouse! Make sure you have control before you use the mouse commands.
|
||||
|
||||
created 15 Mar 2012
|
||||
modified 27 Mar 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardAndMouseControl
|
||||
*/
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
|
||||
#include "USB.h"
|
||||
#include "USBHIDMouse.h"
|
||||
#include "USBHIDKeyboard.h"
|
||||
USBHIDMouse Mouse;
|
||||
USBHIDKeyboard Keyboard;
|
||||
|
||||
// set pin numbers for the five buttons:
|
||||
const int upButton = 12;
|
||||
const int downButton = 13;
|
||||
const int leftButton = 14;
|
||||
const int rightButton = 15;
|
||||
const int mouseButton = 0;
|
||||
|
||||
void setup() { // initialize the buttons' inputs:
|
||||
pinMode(upButton, INPUT_PULLUP);
|
||||
pinMode(downButton, INPUT_PULLUP);
|
||||
pinMode(leftButton, INPUT_PULLUP);
|
||||
pinMode(rightButton, INPUT_PULLUP);
|
||||
pinMode(mouseButton, INPUT_PULLUP);
|
||||
|
||||
Serial.begin(115200);
|
||||
// initialize mouse control:
|
||||
Mouse.begin();
|
||||
Keyboard.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// use serial input to control the mouse:
|
||||
if (Serial.available() > 0) {
|
||||
char inChar = Serial.read();
|
||||
|
||||
switch (inChar) {
|
||||
case 'u':
|
||||
// move mouse up
|
||||
Mouse.move(0, -40);
|
||||
break;
|
||||
case 'd':
|
||||
// move mouse down
|
||||
Mouse.move(0, 40);
|
||||
break;
|
||||
case 'l':
|
||||
// move mouse left
|
||||
Mouse.move(-40, 0);
|
||||
break;
|
||||
case 'r':
|
||||
// move mouse right
|
||||
Mouse.move(40, 0);
|
||||
break;
|
||||
case 'm':
|
||||
// perform mouse left click
|
||||
Mouse.click(MOUSE_LEFT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// use the pushbuttons to control the keyboard:
|
||||
if (digitalRead(upButton) == LOW) {
|
||||
Keyboard.write('u');
|
||||
}
|
||||
if (digitalRead(downButton) == LOW) {
|
||||
Keyboard.write('d');
|
||||
}
|
||||
if (digitalRead(leftButton) == LOW) {
|
||||
Keyboard.write('l');
|
||||
}
|
||||
if (digitalRead(rightButton) == LOW) {
|
||||
Keyboard.write('r');
|
||||
}
|
||||
if (digitalRead(mouseButton) == LOW) {
|
||||
Keyboard.write('m');
|
||||
}
|
||||
delay(5);
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
This is an example of a Simple MIDI Controller using an ESP32 with a native USB support stack (S2, S3,
|
||||
etc.).
|
||||
|
||||
For a hookup guide and more information on reading the ADC, please see:
|
||||
https://randomnerdtutorials.com/esp32-adc-analog-read-arduino-ide/ (Note: This sketch uses GPIO05)
|
||||
|
||||
For best results, it is recommended to add an extra offset resistor between VCC and the potentiometer.
|
||||
(For a standard 10kOhm potentiometer, 3kOhm - 4kOhm will do.)
|
||||
|
||||
View this sketch in action on YouTube: https://youtu.be/Y9TLXs_3w1M
|
||||
*/
|
||||
#if ARDUINO_USB_MODE
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "USB.h"
|
||||
#include "USBMIDI.h"
|
||||
// Creates the MIDI device with specific descriptor
|
||||
USBMIDI MIDI("ESP MIDI Device");
|
||||
|
||||
#define MIDI_NOTE_C4 60
|
||||
|
||||
#define MIDI_CC_CUTOFF 74
|
||||
|
||||
///// ADC & Controller Input Handling /////
|
||||
|
||||
#define CONTROLLER_PIN 5
|
||||
|
||||
// ESP32 ADC needs a ton of smoothing
|
||||
#define SMOOTHING_VALUE 1000
|
||||
static double controllerInputValue = 0;
|
||||
|
||||
void updateControllerInputValue() {
|
||||
controllerInputValue = (controllerInputValue * (SMOOTHING_VALUE - 1) + analogRead(CONTROLLER_PIN)) / SMOOTHING_VALUE;
|
||||
}
|
||||
|
||||
void primeControllerInputValue() {
|
||||
for (int i = 0; i < SMOOTHING_VALUE; i++) {
|
||||
updateControllerInputValue();
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t readControllerValue() {
|
||||
// Lower ADC input amplitude to get a stable value
|
||||
return round(controllerInputValue / 12);
|
||||
}
|
||||
|
||||
///// Button Handling /////
|
||||
|
||||
#define BUTTON_PIN 0
|
||||
|
||||
// Simple button state transition function with debounce
|
||||
// (See also: https://tinyurl.com/simple-debounce)
|
||||
#define PRESSED 0xff00
|
||||
#define RELEASED 0xfe1f
|
||||
uint16_t getButtonEvent() {
|
||||
static uint16_t state = 0;
|
||||
state = (state << 1) | digitalRead(BUTTON_PIN) | 0xfe00;
|
||||
return state;
|
||||
}
|
||||
|
||||
///// Arduino Hooks /////
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
MIDI.begin();
|
||||
USB.begin();
|
||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||
primeControllerInputValue();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
uint16_t newControllerValue = readControllerValue();
|
||||
static uint16_t lastControllerValue = 0;
|
||||
|
||||
// Auto-calibrate the controller range
|
||||
static uint16_t maxControllerValue = 0;
|
||||
static uint16_t minControllerValue = 0xFFFF;
|
||||
|
||||
if (newControllerValue < minControllerValue) {
|
||||
minControllerValue = newControllerValue;
|
||||
}
|
||||
if (newControllerValue > maxControllerValue) {
|
||||
maxControllerValue = newControllerValue;
|
||||
}
|
||||
|
||||
// Send update if the controller value has changed
|
||||
if (lastControllerValue != newControllerValue) {
|
||||
lastControllerValue = newControllerValue;
|
||||
|
||||
// Can't map if the range is zero
|
||||
if (minControllerValue != maxControllerValue) {
|
||||
MIDI.controlChange(MIDI_CC_CUTOFF, map(newControllerValue, minControllerValue, maxControllerValue, 0, 127));
|
||||
}
|
||||
}
|
||||
|
||||
updateControllerInputValue();
|
||||
|
||||
// Hook Button0 to a MIDI note so that we can observe
|
||||
// the CC effect without the need for a MIDI keyboard.
|
||||
switch (getButtonEvent()) {
|
||||
case PRESSED: MIDI.noteOn(MIDI_NOTE_C4, 64); break;
|
||||
case RELEASED: MIDI.noteOff(MIDI_NOTE_C4, 0); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
This is an example of using an ESP32 with a native USB support stack (S2, S3, etc.) as a Serial MIDI to
|
||||
USB MIDI bridge (AKA "A MIDI Interface").
|
||||
|
||||
View this sketch in action on YouTube: https://youtu.be/BXG5i55I9s0
|
||||
|
||||
Receiving and decoding USB MIDI 1.0 packets is a more advanced topic than sending MIDI over USB,
|
||||
please refer to the other examples in this library for a more basic example of sending MIDI over USB.
|
||||
|
||||
This example should still be self explanatory, please refer to the USB MIDI 1.0 specification (the spec)
|
||||
for a more in-depth explanation of the packet format.
|
||||
|
||||
For the spec please visit: https://www.midi.org/specifications-old/item/usb-midi-1-0-specification
|
||||
|
||||
Note: Because ESP32 works at VCC=3.3v normal schematics for Serial MIDI connections will not suffice,
|
||||
Please refer to the Updated MIDI 1.1 Electrical Specification [1] for information on how to hookup
|
||||
Serial MIDI for 3.3v devices.
|
||||
|
||||
[1] - https://www.midi.org/specifications/midi-transports-specifications/5-pin-din-electrical-specs
|
||||
*/
|
||||
#if ARDUINO_USB_MODE
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
|
||||
// define a new USB MIDI device name using a macro
|
||||
SET_USB_MIDI_DEVICE_NAME("ESP MIDI Device")
|
||||
|
||||
#include "USB.h"
|
||||
#include "USBMIDI.h"
|
||||
// Creates the MIDI device with specific name defined with the SET_USB_MIDI_DEVICE_NAME() macro
|
||||
USBMIDI MIDI;
|
||||
|
||||
#define MIDI_RX 39
|
||||
#define MIDI_TX 40
|
||||
|
||||
void setup() {
|
||||
// USBCDC Serial
|
||||
Serial.begin(115200);
|
||||
|
||||
// HW UART Serial
|
||||
Serial1.begin(31250, SERIAL_8N1, MIDI_RX, MIDI_TX);
|
||||
|
||||
MIDI.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// MIDI Serial 1.0 to USB MIDI 1.0
|
||||
if (Serial1.available()) {
|
||||
byte data = Serial1.read();
|
||||
MIDI.write(data);
|
||||
}
|
||||
|
||||
// USB MIDI 1.0 to MIDI Serial 1.0
|
||||
midiEventPacket_t midi_packet_in = {0, 0, 0, 0};
|
||||
// See Chapter 4: USB-MIDI Event Packets (page 16) of the spec.
|
||||
int8_t cin_to_midix_size[16] = {-1, -1, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1};
|
||||
|
||||
if (MIDI.readPacket(&midi_packet_in)) {
|
||||
midi_code_index_number_t code_index_num = MIDI_EP_HEADER_CIN_GET(midi_packet_in.header);
|
||||
int8_t midix_size = cin_to_midix_size[code_index_num];
|
||||
|
||||
// We skip Misc and Cable Events for simplicity
|
||||
if (code_index_num >= 0x2) {
|
||||
for (int i = 0; i < midix_size; i++) {
|
||||
Serial1.write(((uint8_t *)&midi_packet_in)[i + 1]);
|
||||
}
|
||||
Serial1.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
This is an example of a MIDI Music Box using an ESP32 with a native USB support stack (S2, S3, etc.).
|
||||
|
||||
Every time the button on the ESP32 board (attached to pin 0) is pressed the next note of a melody is
|
||||
played. It is up to the user to get the timing of the button presses right.
|
||||
|
||||
One simple way of running this sketch is to download the Pianoteq evaluation version, because upon
|
||||
application start it automatically listens to the first MIDI Input on Channel 1, which is the case,
|
||||
if the ESP32 is the only MIDI device attached.
|
||||
|
||||
View this sketch in action on YouTube: https://youtu.be/JFrc-wSmcus
|
||||
*/
|
||||
#if ARDUINO_USB_MODE
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
|
||||
#include "USB.h"
|
||||
#include "USBMIDI.h"
|
||||
USBMIDI MIDI;
|
||||
|
||||
#define END_OF_SONG 255
|
||||
uint8_t notes[] = {END_OF_SONG, 71, 76, 79, 78, 76, 83, 81, 78, 76, 79, 78, 75, 77, 71};
|
||||
uint8_t noteIndex = 0; // From 0 to sizeof(notes)
|
||||
#define SONG_LENGTH (sizeof(notes) - 1) // END_OF_SONG does not attribute to the length.
|
||||
|
||||
#define BUTTON_PIN 0
|
||||
|
||||
// Simple button press check with debounce
|
||||
// (See also: https://tinyurl.com/simple-debounce)
|
||||
bool isButtonPressed() {
|
||||
static uint16_t state = 0;
|
||||
state = (state << 1) | digitalRead(BUTTON_PIN) | 0xfe00;
|
||||
return (state == 0xff00);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
// Make the BUTTON_PIN an input:
|
||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||
|
||||
MIDI.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (isButtonPressed()) {
|
||||
// Stop current note
|
||||
MIDI.noteOff(notes[noteIndex]);
|
||||
|
||||
// Play next note
|
||||
noteIndex = noteIndex < SONG_LENGTH ? noteIndex + 1 : 0;
|
||||
if (notes[noteIndex] != END_OF_SONG) {
|
||||
MIDI.noteOn(notes[noteIndex], 64);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
This is an example of receiving USB MIDI 1.0 messages using an ESP32 with a native USB support stack
|
||||
(S2, S3, etc.).
|
||||
|
||||
Receiving and decoding USB MIDI 1.0 packets is a more advanced topic than sending MIDI over USB,
|
||||
please refer to the other examples in this library for a more basic example of sending MIDI over USB.
|
||||
|
||||
This example should still be self explanatory, please refer to the USB MIDI 1.0 specification (the spec)
|
||||
for a more in-depth explanation of the packet format.
|
||||
|
||||
For the spec please visit: https://www.midi.org/specifications-old/item/usb-midi-1-0-specification
|
||||
*/
|
||||
#if ARDUINO_USB_MODE
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
|
||||
#include "USB.h"
|
||||
#include "USBMIDI.h"
|
||||
USBMIDI MIDI;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
MIDI.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
midiEventPacket_t midi_packet_in = {0, 0, 0, 0};
|
||||
|
||||
if (MIDI.readPacket(&midi_packet_in)) {
|
||||
printDetails(midi_packet_in);
|
||||
}
|
||||
}
|
||||
|
||||
void printDetails(midiEventPacket_t &midi_packet_in) {
|
||||
// See Chapter 4: USB-MIDI Event Packets (page 16) of the spec.
|
||||
uint8_t cable_num = MIDI_EP_HEADER_CN_GET(midi_packet_in.header);
|
||||
midi_code_index_number_t code_index_num = MIDI_EP_HEADER_CIN_GET(midi_packet_in.header);
|
||||
|
||||
Serial.println("Received a USB MIDI packet:");
|
||||
Serial.println(".----.-----.--------.--------.--------.");
|
||||
Serial.println("| CN | CIN | STATUS | DATA 0 | DATA 1 |");
|
||||
Serial.println("+----+-----+--------+--------+--------+");
|
||||
Serial.printf("| %d | %X | %X | %X | %X |\n", cable_num, code_index_num, midi_packet_in.byte1, midi_packet_in.byte2, midi_packet_in.byte3);
|
||||
Serial.println("'----'-----'--------.--------'--------'\n");
|
||||
Serial.print("Description: ");
|
||||
|
||||
switch (code_index_num) {
|
||||
case MIDI_CIN_MISC: Serial.println("This a Miscellaneous event"); break;
|
||||
case MIDI_CIN_CABLE_EVENT: Serial.println("This a Cable event"); break;
|
||||
case MIDI_CIN_SYSCOM_2BYTE: // 2 byte system common message e.g MTC, SongSelect
|
||||
case MIDI_CIN_SYSCOM_3BYTE: // 3 byte system common message e.g SPP
|
||||
Serial.println("This a System Common (SysCom) event");
|
||||
break;
|
||||
case MIDI_CIN_SYSEX_START: // SysEx starts or continue
|
||||
case MIDI_CIN_SYSEX_END_1BYTE: // SysEx ends with 1 data, or 1 byte system common message
|
||||
case MIDI_CIN_SYSEX_END_2BYTE: // SysEx ends with 2 data
|
||||
case MIDI_CIN_SYSEX_END_3BYTE: // SysEx ends with 3 data
|
||||
Serial.println("This a system exclusive (SysEx) event");
|
||||
break;
|
||||
case MIDI_CIN_NOTE_ON: Serial.printf("This a Note-On event of Note %d with a Velocity of %d\n", midi_packet_in.byte2, midi_packet_in.byte3); break;
|
||||
case MIDI_CIN_NOTE_OFF: Serial.printf("This a Note-Off event of Note %d with a Velocity of %d\n", midi_packet_in.byte2, midi_packet_in.byte3); break;
|
||||
case MIDI_CIN_POLY_KEYPRESS: Serial.printf("This a Poly Aftertouch event for Note %d and Value %d\n", midi_packet_in.byte2, midi_packet_in.byte3); break;
|
||||
case MIDI_CIN_CONTROL_CHANGE:
|
||||
Serial.printf(
|
||||
"This a Control Change/Continuous Controller (CC) event of Controller %d "
|
||||
"with a Value of %d\n",
|
||||
midi_packet_in.byte2, midi_packet_in.byte3
|
||||
);
|
||||
break;
|
||||
case MIDI_CIN_PROGRAM_CHANGE: Serial.printf("This a Program Change event with a Value of %d\n", midi_packet_in.byte2); break;
|
||||
case MIDI_CIN_CHANNEL_PRESSURE: Serial.printf("This a Channel Pressure event with a Value of %d\n", midi_packet_in.byte2); break;
|
||||
case MIDI_CIN_PITCH_BEND_CHANGE:
|
||||
Serial.printf("This a Pitch Bend Change event with a Value of %d\n", ((uint16_t)midi_packet_in.byte2) << 7 | midi_packet_in.byte3);
|
||||
break;
|
||||
case MIDI_CIN_1BYTE_DATA: Serial.printf("This an embedded Serial MIDI event byte with Value %X\n", midi_packet_in.byte1); break;
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
ButtonMouseControl
|
||||
|
||||
Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due.
|
||||
|
||||
Hardware:
|
||||
- five pushbuttons attached to D12, D13, D14, D15, D0
|
||||
|
||||
The mouse movement is always relative. This sketch reads four pushbuttons,
|
||||
and uses them to set the movement of the mouse.
|
||||
|
||||
WARNING: When you use the Mouse.move() command, the Arduino takes over your
|
||||
mouse! Make sure you have control before you use the mouse commands.
|
||||
|
||||
created 15 Mar 2012
|
||||
modified 27 Mar 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/ButtonMouseControl
|
||||
*/
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
|
||||
#include "USB.h"
|
||||
#include "USBHIDMouse.h"
|
||||
USBHIDMouse Mouse;
|
||||
|
||||
// set pin numbers for the five buttons:
|
||||
const int upButton = 12;
|
||||
const int downButton = 13;
|
||||
const int leftButton = 14;
|
||||
const int rightButton = 15;
|
||||
const int mouseButton = 0;
|
||||
|
||||
int range = 5; // output range of X or Y movement; affects movement speed
|
||||
int responseDelay = 10; // response delay of the mouse, in ms
|
||||
|
||||
void setup() {
|
||||
// initialize the buttons' inputs:
|
||||
pinMode(upButton, INPUT_PULLUP);
|
||||
pinMode(downButton, INPUT_PULLUP);
|
||||
pinMode(leftButton, INPUT_PULLUP);
|
||||
pinMode(rightButton, INPUT_PULLUP);
|
||||
pinMode(mouseButton, INPUT_PULLUP);
|
||||
// initialize mouse control:
|
||||
Mouse.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the buttons:
|
||||
int upState = digitalRead(upButton);
|
||||
int downState = digitalRead(downButton);
|
||||
int rightState = digitalRead(rightButton);
|
||||
int leftState = digitalRead(leftButton);
|
||||
int clickState = digitalRead(mouseButton);
|
||||
|
||||
// calculate the movement distance based on the button states:
|
||||
int xDistance = (leftState - rightState) * range;
|
||||
int yDistance = (upState - downState) * range;
|
||||
|
||||
// if X or Y is non-zero, move:
|
||||
if ((xDistance != 0) || (yDistance != 0)) {
|
||||
Mouse.move(xDistance, yDistance, 0);
|
||||
}
|
||||
|
||||
// if the mouse button is pressed:
|
||||
if (clickState == LOW) {
|
||||
// if the mouse is not pressed, press it:
|
||||
if (!Mouse.isPressed(MOUSE_LEFT)) {
|
||||
Mouse.press(MOUSE_LEFT);
|
||||
}
|
||||
}
|
||||
// else the mouse button is not pressed:
|
||||
else {
|
||||
// if the mouse is pressed, release it:
|
||||
if (Mouse.isPressed(MOUSE_LEFT)) {
|
||||
Mouse.release(MOUSE_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
// a delay so the mouse doesn't move too fast:
|
||||
delay(responseDelay);
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
#include "USB.h"
|
||||
#include "USBHIDSystemControl.h"
|
||||
USBHIDSystemControl SystemControl;
|
||||
|
||||
const int buttonPin = 0;
|
||||
int previousButtonState = HIGH;
|
||||
|
||||
void setup() {
|
||||
pinMode(buttonPin, INPUT_PULLUP);
|
||||
SystemControl.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int buttonState = digitalRead(buttonPin);
|
||||
if ((buttonState != previousButtonState) && (buttonState == LOW)) {
|
||||
SystemControl.press(SYSTEM_CONTROL_POWER_OFF);
|
||||
SystemControl.release();
|
||||
}
|
||||
previousButtonState = buttonState;
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,166 @@
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
#include "USB.h"
|
||||
#include "USBMSC.h"
|
||||
|
||||
USBMSC MSC;
|
||||
|
||||
#define FAT_U8(v) ((v) & 0xFF)
|
||||
#define FAT_U16(v) FAT_U8(v), FAT_U8((v) >> 8)
|
||||
#define FAT_U32(v) FAT_U8(v), FAT_U8((v) >> 8), FAT_U8((v) >> 16), FAT_U8((v) >> 24)
|
||||
#define FAT_MS2B(s, ms) FAT_U8(((((s) & 0x1) * 1000) + (ms)) / 10)
|
||||
#define FAT_HMS2B(h, m, s) FAT_U8(((s) >> 1) | (((m) & 0x7) << 5)), FAT_U8((((m) >> 3) & 0x7) | ((h) << 3))
|
||||
#define FAT_YMD2B(y, m, d) FAT_U8(((d) & 0x1F) | (((m) & 0x7) << 5)), FAT_U8((((m) >> 3) & 0x1) | ((((y) - 1980) & 0x7F) << 1))
|
||||
#define FAT_TBL2B(l, h) FAT_U8(l), FAT_U8(((l >> 8) & 0xF) | ((h << 4) & 0xF0)), FAT_U8(h >> 4)
|
||||
|
||||
#define README_CONTENTS \
|
||||
"This is tinyusb's MassStorage Class demo.\r\n\r\nIf you find any bugs or get any questions, feel free to file an\r\nissue at github.com/hathach/tinyusb"
|
||||
|
||||
static const uint32_t DISK_SECTOR_COUNT = 2 * 8; // 8KB is the smallest size that windows allow to mount
|
||||
static const uint16_t DISK_SECTOR_SIZE = 512; // Should be 512
|
||||
static const uint16_t DISC_SECTORS_PER_TABLE = 1; //each table sector can fit 170KB (340 sectors)
|
||||
|
||||
static uint8_t msc_disk[DISK_SECTOR_COUNT][DISK_SECTOR_SIZE] = {
|
||||
//------------- Block0: Boot Sector -------------//
|
||||
{ // Header (62 bytes)
|
||||
0xEB, 0x3C, 0x90, //jump_instruction
|
||||
'M', 'S', 'D', 'O', 'S', '5', '.', '0', //oem_name
|
||||
FAT_U16(DISK_SECTOR_SIZE), //bytes_per_sector
|
||||
FAT_U8(1), //sectors_per_cluster
|
||||
FAT_U16(1), //reserved_sectors_count
|
||||
FAT_U8(1), //file_alloc_tables_num
|
||||
FAT_U16(16), //max_root_dir_entries
|
||||
FAT_U16(DISK_SECTOR_COUNT), //fat12_sector_num
|
||||
0xF8, //media_descriptor
|
||||
FAT_U16(DISC_SECTORS_PER_TABLE), //sectors_per_alloc_table;//FAT12 and FAT16
|
||||
FAT_U16(1), //sectors_per_track;//A value of 0 may indicate LBA-only access
|
||||
FAT_U16(1), //num_heads
|
||||
FAT_U32(0), //hidden_sectors_count
|
||||
FAT_U32(0), //total_sectors_32
|
||||
0x00, //physical_drive_number;0x00 for (first) removable media, 0x80 for (first) fixed disk
|
||||
0x00, //reserved
|
||||
0x29, //extended_boot_signature;//should be 0x29
|
||||
FAT_U32(0x1234), //serial_number: 0x1234 => 1234
|
||||
'T', 'i', 'n', 'y', 'U', 'S', 'B', ' ', 'M', 'S', 'C', //volume_label padded with spaces (0x20)
|
||||
'F', 'A', 'T', '1', '2', ' ', ' ', ' ', //file_system_type padded with spaces (0x20)
|
||||
|
||||
// Zero up to 2 last bytes of FAT magic code (448 bytes)
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
//boot signature (2 bytes)
|
||||
0x55, 0xAA
|
||||
},
|
||||
|
||||
//------------- Block1: FAT12 Table -------------//
|
||||
{
|
||||
FAT_TBL2B(0xFF8, 0xFFF), FAT_TBL2B(0xFFF, 0x000) // first 2 entries must be 0xFF8 0xFFF, third entry is cluster end of readme file
|
||||
},
|
||||
|
||||
//------------- Block2: Root Directory -------------//
|
||||
{
|
||||
// first entry is volume label
|
||||
'E', 'S', 'P', '3', '2', 'S', '2', ' ', 'M', 'S', 'C',
|
||||
0x08, //FILE_ATTR_VOLUME_LABEL
|
||||
0x00, FAT_MS2B(0, 0), FAT_HMS2B(0, 0, 0), FAT_YMD2B(0, 0, 0), FAT_YMD2B(0, 0, 0), FAT_U16(0), FAT_HMS2B(13, 42, 30), //last_modified_hms
|
||||
FAT_YMD2B(2018, 11, 5), //last_modified_ymd
|
||||
FAT_U16(0), FAT_U32(0),
|
||||
|
||||
// second entry is readme file
|
||||
'R', 'E', 'A', 'D', 'M', 'E', ' ', ' ', //file_name[8]; padded with spaces (0x20)
|
||||
'T', 'X', 'T', //file_extension[3]; padded with spaces (0x20)
|
||||
0x20, //file attributes: FILE_ATTR_ARCHIVE
|
||||
0x00, //ignore
|
||||
FAT_MS2B(1, 980), //creation_time_10_ms (max 199x10 = 1s 990ms)
|
||||
FAT_HMS2B(13, 42, 36), //create_time_hms [5:6:5] => h:m:(s/2)
|
||||
FAT_YMD2B(2018, 11, 5), //create_time_ymd [7:4:5] => (y+1980):m:d
|
||||
FAT_YMD2B(2020, 11, 5), //last_access_ymd
|
||||
FAT_U16(0), //extended_attributes
|
||||
FAT_HMS2B(13, 44, 16), //last_modified_hms
|
||||
FAT_YMD2B(2019, 11, 5), //last_modified_ymd
|
||||
FAT_U16(2), //start of file in cluster
|
||||
FAT_U32(sizeof(README_CONTENTS) - 1) //file size
|
||||
},
|
||||
|
||||
//------------- Block3: Readme Content -------------//
|
||||
README_CONTENTS
|
||||
};
|
||||
|
||||
static int32_t onWrite(uint32_t lba, uint32_t offset, uint8_t *buffer, uint32_t bufsize) {
|
||||
Serial.printf("MSC WRITE: lba: %lu, offset: %lu, bufsize: %lu\n", lba, offset, bufsize);
|
||||
memcpy(msc_disk[lba] + offset, buffer, bufsize);
|
||||
return bufsize;
|
||||
}
|
||||
|
||||
static int32_t onRead(uint32_t lba, uint32_t offset, void *buffer, uint32_t bufsize) {
|
||||
Serial.printf("MSC READ: lba: %lu, offset: %lu, bufsize: %lu\n", lba, offset, bufsize);
|
||||
memcpy(buffer, msc_disk[lba] + offset, bufsize);
|
||||
return bufsize;
|
||||
}
|
||||
|
||||
static bool onStartStop(uint8_t power_condition, bool start, bool load_eject) {
|
||||
Serial.printf("MSC START/STOP: power: %u, start: %u, eject: %u\n", power_condition, start, load_eject);
|
||||
return true;
|
||||
}
|
||||
|
||||
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: Serial.println("USB PLUGGED"); break;
|
||||
case ARDUINO_USB_STOPPED_EVENT: Serial.println("USB UNPLUGGED"); break;
|
||||
case ARDUINO_USB_SUSPEND_EVENT: Serial.printf("USB SUSPENDED: remote_wakeup_en: %u\n", data->suspend.remote_wakeup_en); break;
|
||||
case ARDUINO_USB_RESUME_EVENT: Serial.println("USB RESUMED"); break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.setDebugOutput(true);
|
||||
|
||||
USB.onEvent(usbEventCallback);
|
||||
MSC.vendorID("ESP32"); //max 8 chars
|
||||
MSC.productID("USB_MSC"); //max 16 chars
|
||||
MSC.productRevision("1.0"); //max 4 chars
|
||||
MSC.onStartStop(onStartStop);
|
||||
MSC.onRead(onRead);
|
||||
MSC.onWrite(onWrite);
|
||||
|
||||
MSC.mediaPresent(true);
|
||||
MSC.isWritable(true); // true if writable, false if read-only
|
||||
|
||||
MSC.begin(DISK_SECTOR_COUNT, DISK_SECTOR_SIZE);
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
#include "USB.h"
|
||||
|
||||
#if !ARDUINO_USB_CDC_ON_BOOT
|
||||
USBCDC USBSerial;
|
||||
#endif
|
||||
|
||||
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: Serial.println("USB PLUGGED"); break;
|
||||
case ARDUINO_USB_STOPPED_EVENT: Serial.println("USB UNPLUGGED"); break;
|
||||
case ARDUINO_USB_SUSPEND_EVENT: Serial.printf("USB SUSPENDED: remote_wakeup_en: %u\n", data->suspend.remote_wakeup_en); break;
|
||||
case ARDUINO_USB_RESUME_EVENT: Serial.println("USB RESUMED"); break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
} else if (event_base == ARDUINO_USB_CDC_EVENTS) {
|
||||
arduino_usb_cdc_event_data_t *data = (arduino_usb_cdc_event_data_t *)event_data;
|
||||
switch (event_id) {
|
||||
case ARDUINO_USB_CDC_CONNECTED_EVENT: Serial.println("CDC CONNECTED"); break;
|
||||
case ARDUINO_USB_CDC_DISCONNECTED_EVENT: Serial.println("CDC DISCONNECTED"); break;
|
||||
case ARDUINO_USB_CDC_LINE_STATE_EVENT: Serial.printf("CDC LINE STATE: dtr: %u, rts: %u\n", data->line_state.dtr, data->line_state.rts); break;
|
||||
case ARDUINO_USB_CDC_LINE_CODING_EVENT:
|
||||
Serial.printf(
|
||||
"CDC LINE CODING: bit_rate: %lu, data_bits: %u, stop_bits: %u, parity: %u\n", data->line_coding.bit_rate, data->line_coding.data_bits,
|
||||
data->line_coding.stop_bits, data->line_coding.parity
|
||||
);
|
||||
break;
|
||||
case ARDUINO_USB_CDC_RX_EVENT:
|
||||
Serial.printf("CDC RX [%u]:", data->rx.len);
|
||||
{
|
||||
uint8_t buf[data->rx.len];
|
||||
size_t len = USBSerial.read(buf, data->rx.len);
|
||||
Serial.write(buf, len);
|
||||
}
|
||||
Serial.println();
|
||||
break;
|
||||
case ARDUINO_USB_CDC_RX_OVERFLOW_EVENT: Serial.printf("CDC RX Overflow of %d bytes", data->rx_overflow.dropped_bytes); break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.setDebugOutput(true);
|
||||
|
||||
USB.onEvent(usbEventCallback);
|
||||
USBSerial.onEvent(usbEventCallback);
|
||||
|
||||
USBSerial.begin();
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
while (Serial.available()) {
|
||||
size_t l = Serial.available();
|
||||
uint8_t b[l];
|
||||
l = Serial.read(b, l);
|
||||
USBSerial.write(b, l);
|
||||
}
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,186 @@
|
||||
#ifndef ARDUINO_USB_MODE
|
||||
#error This ESP32 SoC has no Native USB interface
|
||||
#elif ARDUINO_USB_MODE == 1
|
||||
#warning This sketch should be used when USB is in OTG mode
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
#else
|
||||
#include "USB.h"
|
||||
#include "USBVendor.h"
|
||||
|
||||
USBVendor Vendor;
|
||||
const int buttonPin = 0;
|
||||
|
||||
//CDC Control Requests
|
||||
#define REQUEST_SET_LINE_CODING 0x20
|
||||
#define REQUEST_GET_LINE_CODING 0x21
|
||||
#define REQUEST_SET_CONTROL_LINE_STATE 0x22
|
||||
|
||||
//CDC Line Coding Control Request Structure
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint32_t bit_rate;
|
||||
uint8_t stop_bits; //0: 1 stop bit, 1: 1.5 stop bits, 2: 2 stop bits
|
||||
uint8_t parity; //0: None, 1: Odd, 2: Even, 3: Mark, 4: Space
|
||||
uint8_t data_bits; //5, 6, 7, 8 or 16
|
||||
} request_line_coding_t;
|
||||
|
||||
static request_line_coding_t vendor_line_coding = {9600, 0, 0, 8};
|
||||
|
||||
// Bit 0: DTR (Data Terminal Ready), Bit 1: RTS (Request to Send)
|
||||
static uint8_t vendor_line_state = 0;
|
||||
|
||||
//USB and Vendor events
|
||||
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: Serial.println("USB PLUGGED"); break;
|
||||
case ARDUINO_USB_STOPPED_EVENT: Serial.println("USB UNPLUGGED"); break;
|
||||
case ARDUINO_USB_SUSPEND_EVENT: Serial.printf("USB SUSPENDED: remote_wakeup_en: %u\n", data->suspend.remote_wakeup_en); break;
|
||||
case ARDUINO_USB_RESUME_EVENT: Serial.println("USB RESUMED"); break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
} else if (event_base == ARDUINO_USB_VENDOR_EVENTS) {
|
||||
arduino_usb_vendor_event_data_t *data = (arduino_usb_vendor_event_data_t *)event_data;
|
||||
switch (event_id) {
|
||||
case ARDUINO_USB_VENDOR_DATA_EVENT:
|
||||
Serial.printf("Vendor RX: len:%u\n", data->data.len);
|
||||
for (uint16_t i = 0; i < data->data.len; i++) {
|
||||
Serial.write(Vendor.read());
|
||||
}
|
||||
Serial.println();
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const char *strRequestDirections[] = {"OUT", "IN"};
|
||||
static const char *strRequestTypes[] = {"STANDARD", "CLASS", "VENDOR", "INVALID"};
|
||||
static const char *strRequestRecipients[] = {"DEVICE", "INTERFACE", "ENDPOINT", "OTHER"};
|
||||
static const char *strRequestStages[] = {"SETUP", "DATA", "ACK"};
|
||||
|
||||
//Handle USB requests to the vendor interface
|
||||
bool vendorRequestCallback(uint8_t rhport, uint8_t requestStage, arduino_usb_control_request_t const *request) {
|
||||
Serial.printf(
|
||||
"Vendor Request: Stage: %5s, Direction: %3s, Type: %8s, Recipient: %9s, bRequest: 0x%02x, wValue: 0x%04x, wIndex: %u, wLength: %u\n",
|
||||
strRequestStages[requestStage], strRequestDirections[request->bmRequestDirection], strRequestTypes[request->bmRequestType],
|
||||
strRequestRecipients[request->bmRequestRecipient], request->bRequest, request->wValue, request->wIndex, request->wLength
|
||||
);
|
||||
|
||||
bool result = false;
|
||||
|
||||
if (request->bmRequestDirection == REQUEST_DIRECTION_OUT && request->bmRequestType == REQUEST_TYPE_STANDARD
|
||||
&& request->bmRequestRecipient == REQUEST_RECIPIENT_INTERFACE && request->bRequest == 0x0b) {
|
||||
if (requestStage == REQUEST_STAGE_SETUP) {
|
||||
// response with status OK
|
||||
result = Vendor.sendResponse(rhport, request);
|
||||
} else {
|
||||
result = true;
|
||||
}
|
||||
} else
|
||||
//Implement CDC Control Requests
|
||||
if (request->bmRequestType == REQUEST_TYPE_CLASS && request->bmRequestRecipient == REQUEST_RECIPIENT_DEVICE) {
|
||||
switch (request->bRequest) {
|
||||
|
||||
case REQUEST_SET_LINE_CODING: //0x20
|
||||
// Accept only direction OUT with data size 7
|
||||
if (request->wLength != sizeof(request_line_coding_t) || request->bmRequestDirection != REQUEST_DIRECTION_OUT) {
|
||||
break;
|
||||
}
|
||||
if (requestStage == REQUEST_STAGE_SETUP) {
|
||||
//Send the response in setup stage (it will write the data to vendor_line_coding in the DATA stage)
|
||||
result = Vendor.sendResponse(rhport, request, (void *)&vendor_line_coding, sizeof(request_line_coding_t));
|
||||
} else if (requestStage == REQUEST_STAGE_ACK) {
|
||||
//In the ACK stage the response is complete
|
||||
Serial.printf(
|
||||
"Vendor Line Coding: bit_rate: %lu, data_bits: %u, stop_bits: %u, parity: %u\n", vendor_line_coding.bit_rate, vendor_line_coding.data_bits,
|
||||
vendor_line_coding.stop_bits, vendor_line_coding.parity
|
||||
);
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
|
||||
case REQUEST_GET_LINE_CODING: //0x21
|
||||
// Accept only direction IN with data size 7
|
||||
if (request->wLength != sizeof(request_line_coding_t) || request->bmRequestDirection != REQUEST_DIRECTION_IN) {
|
||||
break;
|
||||
}
|
||||
if (requestStage == REQUEST_STAGE_SETUP) {
|
||||
//Send the response in setup stage (it will write the data to vendor_line_coding in the DATA stage)
|
||||
result = Vendor.sendResponse(rhport, request, (void *)&vendor_line_coding, sizeof(request_line_coding_t));
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
|
||||
case REQUEST_SET_CONTROL_LINE_STATE: //0x22
|
||||
// Accept only direction OUT with data size 0
|
||||
if (request->wLength != 0 || request->bmRequestDirection != REQUEST_DIRECTION_OUT) {
|
||||
break;
|
||||
}
|
||||
if (requestStage == REQUEST_STAGE_SETUP) {
|
||||
//Send the response in setup stage
|
||||
vendor_line_state = request->wValue;
|
||||
result = Vendor.sendResponse(rhport, request);
|
||||
} else if (requestStage == REQUEST_STAGE_ACK) {
|
||||
//In the ACK stage the response is complete
|
||||
bool dtr = (vendor_line_state & 1) != 0;
|
||||
bool rts = (vendor_line_state & 2) != 0;
|
||||
Serial.printf("Vendor Line State: dtr: %u, rts: %u\n", dtr, rts);
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
// stall unknown request
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(buttonPin, INPUT_PULLUP);
|
||||
Serial.begin(115200);
|
||||
Serial.setDebugOutput(true);
|
||||
|
||||
Vendor.onEvent(usbEventCallback);
|
||||
Vendor.onRequest(vendorRequestCallback);
|
||||
Vendor.begin();
|
||||
|
||||
USB.onEvent(usbEventCallback);
|
||||
USB.webUSB(true);
|
||||
// Set the URL for your WebUSB landing page
|
||||
USB.webUSBURL("https://docs.espressif.com/projects/arduino-esp32/en/latest/_static/webusb.html");
|
||||
USB.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static int previousButtonState = HIGH;
|
||||
int buttonState = digitalRead(buttonPin);
|
||||
if (buttonState != previousButtonState) {
|
||||
previousButtonState = buttonState;
|
||||
if (buttonState == LOW) {
|
||||
Serial.println("Button Pressed");
|
||||
Vendor.println("Button Pressed");
|
||||
Vendor.flush(); //Without flushing the data will only be sent when the buffer is full (64 bytes)
|
||||
} else {
|
||||
Serial.println("Button Released");
|
||||
Vendor.println("Button Released");
|
||||
Vendor.flush(); //Without flushing the data will only be sent when the buffer is full (64 bytes)
|
||||
}
|
||||
delay(100);
|
||||
}
|
||||
|
||||
while (Serial.available()) {
|
||||
size_t l = Serial.available();
|
||||
uint8_t b[l];
|
||||
l = Serial.read(b, l);
|
||||
Vendor.write(b, l);
|
||||
Vendor.flush(); //Without flushing the data will only be sent when the buffer is full (64 bytes)
|
||||
}
|
||||
}
|
||||
#endif /* ARDUINO_USB_MODE */
|
||||
@@ -0,0 +1,2 @@
|
||||
requires:
|
||||
- CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||
@@ -0,0 +1,133 @@
|
||||
<!-- Based on https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/subsys/usb/webusb -->
|
||||
|
||||
<!--
|
||||
Example of WebUSB web page to communicate with a USB device.
|
||||
This can be used as a starting point for your self-hosted WebUSB landing page.
|
||||
-->
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Espressif WebUSB Console Example</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script>
|
||||
var serial = {};
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
serial.getPorts = function() {
|
||||
return navigator.usb.getDevices().then(devices => {
|
||||
return devices.map(device => new serial.Port(device));
|
||||
});
|
||||
};
|
||||
|
||||
serial.requestPort = function() {
|
||||
const filters = [
|
||||
{ 'vendorId': 0x10c4, 'productId': 0xea60 },
|
||||
{ 'vendorId': 0x303a, 'productId': 0x1001 },
|
||||
{ 'vendorId': 0x303a, 'productId': 0x0002 },
|
||||
];
|
||||
return navigator.usb.requestDevice({ 'filters': filters }).then(
|
||||
device => new serial.Port(device)
|
||||
);
|
||||
}
|
||||
|
||||
serial.Port = function(device) {
|
||||
this.device_ = device;
|
||||
};
|
||||
|
||||
serial.Port.prototype.connect = function() {
|
||||
let readLoop = () => {
|
||||
const {
|
||||
endpointNumber
|
||||
} = this.device_.configuration.interfaces[0].alternate.endpoints[0]
|
||||
this.device_.transferIn(endpointNumber, 64).then(result => {
|
||||
this.onReceive(result.data);
|
||||
readLoop();
|
||||
}, error => {
|
||||
this.onReceiveError(error);
|
||||
});
|
||||
};
|
||||
|
||||
return this.device_.open()
|
||||
.then(() => {
|
||||
if (this.device_.configuration === null) {
|
||||
return this.device_.selectConfiguration(1);
|
||||
}
|
||||
})
|
||||
.then(() => this.device_.claimInterface(0))
|
||||
.then(() => {
|
||||
readLoop();
|
||||
});
|
||||
};
|
||||
|
||||
serial.Port.prototype.disconnect = function() {
|
||||
return this.device_.close();
|
||||
};
|
||||
|
||||
serial.Port.prototype.send = function(data) {
|
||||
const {
|
||||
endpointNumber
|
||||
} = this.device_.configuration.interfaces[0].alternate.endpoints[1]
|
||||
return this.device_.transferOut(endpointNumber, data);
|
||||
};
|
||||
})();
|
||||
|
||||
let port;
|
||||
|
||||
function connect() {
|
||||
port.connect().then(() => {
|
||||
port.onReceive = data => {
|
||||
let textDecoder = new TextDecoder();
|
||||
console.log("Received:", textDecoder.decode(data));
|
||||
document.getElementById('output').value += textDecoder.decode(data);
|
||||
}
|
||||
port.onReceiveError = error => {
|
||||
console.error(error);
|
||||
document.querySelector("#connect").style = "visibility: initial";
|
||||
port.disconnect();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function send(string) {
|
||||
console.log("sending to serial:" + string.length);
|
||||
if (string.length === 0)
|
||||
return;
|
||||
console.log("sending to serial: [" + string +"]\n");
|
||||
|
||||
let view = new TextEncoder('utf-8').encode(string);
|
||||
console.log(view);
|
||||
if (port) {
|
||||
port.send(view);
|
||||
}
|
||||
};
|
||||
|
||||
window.onload = _ => {
|
||||
document.querySelector("#connect").onclick = function() {
|
||||
serial.requestPort().then(selectedPort => {
|
||||
port = selectedPort;
|
||||
this.style = "visibility: hidden";
|
||||
connect();
|
||||
});
|
||||
}
|
||||
|
||||
document.querySelector("#submit").onclick = () => {
|
||||
let source = document.querySelector("#input").value;
|
||||
send(source);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<button id="connect" style="visibility: initial">Connect To ESP Device</button>
|
||||
<br><br><label for="input">Sender: </label> <br>
|
||||
<textarea id="input" rows="25" cols="80">Send to ESP Device</textarea>
|
||||
<br><button id="submit">Send</button>
|
||||
<br><br>
|
||||
<label for="output">Receiver: </label> <br>
|
||||
<textarea id="output" rows="25" cols="80"></textarea>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,32 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
USB KEYWORD1
|
||||
USBCDC KEYWORD1
|
||||
USBMSC KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
begin KEYWORD2
|
||||
end KEYWORD2
|
||||
onEvent KEYWORD2
|
||||
enableReset KEYWORD2
|
||||
|
||||
vendorID KEYWORD2
|
||||
productID KEYWORD2
|
||||
productRevision KEYWORD2
|
||||
mediaPresent KEYWORD2
|
||||
onStartStop KEYWORD2
|
||||
onRead KEYWORD2
|
||||
onWrite KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
@@ -0,0 +1,9 @@
|
||||
name=USB
|
||||
version=3.3.7
|
||||
author=Hristo Gochkov
|
||||
maintainer=Hristo Gochkov <hristo@espressif.com>
|
||||
sentence=ESP32S2 USB Library
|
||||
paragraph=
|
||||
category=Communication
|
||||
url=
|
||||
architectures=esp32
|
||||
@@ -0,0 +1,390 @@
|
||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "USBHID.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
|
||||
#include "esp32-hal-tinyusb.h"
|
||||
#include "USB.h"
|
||||
#include "esp_hid_common.h"
|
||||
|
||||
#define USB_HID_DEVICES_MAX 10
|
||||
|
||||
ESP_EVENT_DEFINE_BASE(ARDUINO_USB_HID_EVENTS);
|
||||
esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, TickType_t ticks_to_wait);
|
||||
esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg);
|
||||
|
||||
typedef struct {
|
||||
USBHIDDevice *device;
|
||||
uint8_t reports_num;
|
||||
uint8_t *report_ids;
|
||||
} tinyusb_hid_device_t;
|
||||
|
||||
static tinyusb_hid_device_t tinyusb_hid_devices[USB_HID_DEVICES_MAX];
|
||||
|
||||
static uint8_t tinyusb_hid_devices_num = 0;
|
||||
static bool tinyusb_hid_devices_is_initialized = false;
|
||||
static SemaphoreHandle_t tinyusb_hid_device_input_sem = NULL;
|
||||
static SemaphoreHandle_t tinyusb_hid_device_input_mutex = NULL;
|
||||
|
||||
static bool tinyusb_hid_is_initialized = false;
|
||||
static hid_interface_protocol_enum_t tinyusb_interface_protocol = HID_ITF_PROTOCOL_NONE;
|
||||
static uint8_t tinyusb_loaded_hid_devices_num = 0;
|
||||
static uint16_t tinyusb_hid_device_descriptor_len = 0;
|
||||
static uint8_t *tinyusb_hid_device_descriptor = NULL;
|
||||
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
|
||||
static const char *tinyusb_hid_device_report_types[4] = {"INVALID", "INPUT", "OUTPUT", "FEATURE"};
|
||||
#endif
|
||||
|
||||
static bool tinyusb_enable_hid_device(uint16_t descriptor_len, USBHIDDevice *device) {
|
||||
if (tinyusb_hid_is_initialized) {
|
||||
log_e("TinyUSB HID has already started! Device not enabled");
|
||||
return false;
|
||||
}
|
||||
if (tinyusb_loaded_hid_devices_num >= USB_HID_DEVICES_MAX) {
|
||||
log_e("Maximum devices already enabled! Device not enabled");
|
||||
return false;
|
||||
}
|
||||
tinyusb_hid_device_descriptor_len += descriptor_len;
|
||||
tinyusb_hid_devices[tinyusb_loaded_hid_devices_num++].device = device;
|
||||
|
||||
log_d("Device[%u] len: %u", tinyusb_loaded_hid_devices_num - 1, descriptor_len);
|
||||
return true;
|
||||
}
|
||||
|
||||
USBHIDDevice *tinyusb_get_device_by_report_id(uint8_t report_id) {
|
||||
for (uint8_t i = 0; i < tinyusb_loaded_hid_devices_num; i++) {
|
||||
tinyusb_hid_device_t *device = &tinyusb_hid_devices[i];
|
||||
if (device->device && device->reports_num) {
|
||||
for (uint8_t r = 0; r < device->reports_num; r++) {
|
||||
if (report_id == device->report_ids[r]) {
|
||||
return device->device;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static uint16_t tinyusb_on_get_feature(uint8_t report_id, uint8_t *buffer, uint16_t reqlen) {
|
||||
USBHIDDevice *device = tinyusb_get_device_by_report_id(report_id);
|
||||
if (device) {
|
||||
return device->_onGetFeature(report_id, buffer, reqlen);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool tinyusb_on_set_feature(uint8_t report_id, const uint8_t *buffer, uint16_t reqlen) {
|
||||
USBHIDDevice *device = tinyusb_get_device_by_report_id(report_id);
|
||||
if (device) {
|
||||
device->_onSetFeature(report_id, buffer, reqlen);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool tinyusb_on_set_output(uint8_t report_id, const uint8_t *buffer, uint16_t reqlen) {
|
||||
USBHIDDevice *device = tinyusb_get_device_by_report_id(report_id);
|
||||
if (device) {
|
||||
device->_onOutput(report_id, buffer, reqlen);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static uint16_t tinyusb_on_add_descriptor(uint8_t device_index, uint8_t *dst) {
|
||||
uint16_t res = 0;
|
||||
uint8_t report_id = 0, reports_num = 0;
|
||||
tinyusb_hid_device_t *device = &tinyusb_hid_devices[device_index];
|
||||
if (device->device) {
|
||||
res = device->device->_onGetDescriptor(dst);
|
||||
if (res) {
|
||||
|
||||
esp_hid_report_map_t *hid_report_map = esp_hid_parse_report_map(dst, res);
|
||||
if (hid_report_map) {
|
||||
if (device->report_ids) {
|
||||
free(device->report_ids);
|
||||
}
|
||||
device->reports_num = hid_report_map->reports_len;
|
||||
device->report_ids = (uint8_t *)malloc(device->reports_num);
|
||||
memset(device->report_ids, 0, device->reports_num);
|
||||
reports_num = device->reports_num;
|
||||
|
||||
for (uint8_t i = 0; i < device->reports_num; i++) {
|
||||
if (hid_report_map->reports[i].protocol_mode == ESP_HID_PROTOCOL_MODE_REPORT) {
|
||||
report_id = hid_report_map->reports[i].report_id;
|
||||
for (uint8_t r = 0; r < device->reports_num; r++) {
|
||||
if (!report_id) {
|
||||
//todo: handle better when device has no report ID set
|
||||
break;
|
||||
} else if (report_id == device->report_ids[r]) {
|
||||
//already added
|
||||
reports_num--;
|
||||
break;
|
||||
} else if (!device->report_ids[r]) {
|
||||
//empty slot
|
||||
device->report_ids[r] = report_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reports_num--;
|
||||
}
|
||||
}
|
||||
device->reports_num = reports_num;
|
||||
esp_hid_free_report_map(hid_report_map);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static bool tinyusb_load_enabled_hid_devices() {
|
||||
if (tinyusb_hid_device_descriptor != NULL) {
|
||||
return true;
|
||||
}
|
||||
tinyusb_hid_device_descriptor = (uint8_t *)malloc(tinyusb_hid_device_descriptor_len);
|
||||
if (tinyusb_hid_device_descriptor == NULL) {
|
||||
log_e("HID Descriptor Malloc Failed");
|
||||
return false;
|
||||
}
|
||||
uint8_t *dst = tinyusb_hid_device_descriptor;
|
||||
|
||||
for (uint8_t i = 0; i < tinyusb_loaded_hid_devices_num; i++) {
|
||||
uint16_t len = tinyusb_on_add_descriptor(i, dst);
|
||||
if (!len) {
|
||||
break;
|
||||
} else {
|
||||
dst += len;
|
||||
}
|
||||
}
|
||||
|
||||
esp_hid_report_map_t *hid_report_map = esp_hid_parse_report_map(tinyusb_hid_device_descriptor, tinyusb_hid_device_descriptor_len);
|
||||
if (hid_report_map) {
|
||||
log_d("Loaded HID Descriptor with the following reports:");
|
||||
for (uint8_t i = 0; i < hid_report_map->reports_len; i++) {
|
||||
if (hid_report_map->reports[i].protocol_mode == ESP_HID_PROTOCOL_MODE_REPORT) {
|
||||
log_d(
|
||||
" ID: %3u, Type: %7s, Size: %2u, Usage: %8s", hid_report_map->reports[i].report_id, esp_hid_report_type_str(hid_report_map->reports[i].report_type),
|
||||
hid_report_map->reports[i].value_len, esp_hid_usage_str(hid_report_map->reports[i].usage)
|
||||
);
|
||||
}
|
||||
}
|
||||
esp_hid_free_report_map(hid_report_map);
|
||||
} else {
|
||||
log_e("Failed to parse the hid report descriptor!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" uint16_t tusb_hid_load_descriptor(uint8_t *dst, uint8_t *itf) {
|
||||
if (tinyusb_hid_is_initialized) {
|
||||
return 0;
|
||||
}
|
||||
tinyusb_hid_is_initialized = true;
|
||||
|
||||
uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB HID");
|
||||
// For keyboard boot protocol, we've already called tinyusb_enable_interface2(reserve_endpoints=true)
|
||||
uint8_t ep_in = tinyusb_interface_protocol == HID_ITF_PROTOCOL_KEYBOARD ? 1 : tinyusb_get_free_in_endpoint();
|
||||
TU_VERIFY(ep_in != 0);
|
||||
uint8_t ep_out = tinyusb_interface_protocol == HID_ITF_PROTOCOL_KEYBOARD ? 1 : tinyusb_get_free_out_endpoint();
|
||||
TU_VERIFY(ep_out != 0);
|
||||
uint8_t descriptor[TUD_HID_INOUT_DESC_LEN] = {
|
||||
// HID Input & Output descriptor
|
||||
// Interface number, string index, protocol, report descriptor len, EP OUT & IN address, size & polling interval
|
||||
TUD_HID_INOUT_DESCRIPTOR(
|
||||
*itf, str_index, tinyusb_interface_protocol, tinyusb_hid_device_descriptor_len, ep_out, (uint8_t)(0x80 | ep_in), CFG_TUD_ENDOINT_SIZE, 1
|
||||
)
|
||||
};
|
||||
*itf += 1;
|
||||
memcpy(dst, descriptor, TUD_HID_INOUT_DESC_LEN);
|
||||
return TUD_HID_INOUT_DESC_LEN;
|
||||
}
|
||||
|
||||
// Invoked when received GET HID REPORT DESCRIPTOR request
|
||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
||||
uint8_t const *tud_hid_descriptor_report_cb(uint8_t instance) {
|
||||
log_v("instance: %u", instance);
|
||||
if (!tinyusb_load_enabled_hid_devices()) {
|
||||
return NULL;
|
||||
}
|
||||
return tinyusb_hid_device_descriptor;
|
||||
}
|
||||
|
||||
// Invoked when received SET_PROTOCOL request
|
||||
// protocol is either HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1)
|
||||
void tud_hid_set_protocol_cb(uint8_t instance, uint8_t protocol) {
|
||||
log_v("instance: %u, protocol:%u", instance, protocol);
|
||||
arduino_usb_hid_event_data_t p;
|
||||
p.instance = instance;
|
||||
p.set_protocol.protocol = protocol;
|
||||
arduino_usb_event_post(ARDUINO_USB_HID_EVENTS, ARDUINO_USB_HID_SET_PROTOCOL_EVENT, &p, sizeof(arduino_usb_hid_event_data_t), portMAX_DELAY);
|
||||
}
|
||||
|
||||
// Invoked when received SET_IDLE request. return false will stall the request
|
||||
// - Idle Rate = 0 : only send report if there is changes, i.e skip duplication
|
||||
// - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms).
|
||||
bool tud_hid_set_idle_cb(uint8_t instance, uint8_t idle_rate) {
|
||||
log_v("instance: %u, idle_rate:%u", instance, idle_rate);
|
||||
arduino_usb_hid_event_data_t p;
|
||||
p.instance = instance;
|
||||
p.set_idle.idle_rate = idle_rate;
|
||||
arduino_usb_event_post(ARDUINO_USB_HID_EVENTS, ARDUINO_USB_HID_SET_IDLE_EVENT, &p, sizeof(arduino_usb_hid_event_data_t), portMAX_DELAY);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Invoked when received GET_REPORT control request
|
||||
// Application must fill buffer report's content and return its length.
|
||||
// Return zero will cause the stack to STALL request
|
||||
uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen) {
|
||||
uint16_t res = tinyusb_on_get_feature(report_id, buffer, reqlen);
|
||||
if (!res) {
|
||||
log_d("instance: %u, report_id: %u, report_type: %s, reqlen: %u", instance, report_id, tinyusb_hid_device_report_types[report_type], reqlen);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// Invoked when received SET_REPORT control request or
|
||||
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
|
||||
void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize) {
|
||||
if (!report_id && (!report_type || report_type == HID_REPORT_TYPE_OUTPUT)) {
|
||||
if (!tinyusb_on_set_output(0, buffer, bufsize) && !tinyusb_on_set_output(buffer[0], buffer + 1, bufsize - 1)) {
|
||||
log_d(
|
||||
"instance: %u, report_id: %u, report_type: %s, bufsize: %u", instance, buffer[0], tinyusb_hid_device_report_types[HID_REPORT_TYPE_OUTPUT], bufsize - 1
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (!tinyusb_on_set_feature(report_id, buffer, bufsize)) {
|
||||
log_d("instance: %u, report_id: %u, report_type: %s, bufsize: %u", instance, report_id, tinyusb_hid_device_report_types[report_type], bufsize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
USBHID::USBHID(hid_interface_protocol_enum_t itf_protocol) {
|
||||
if (!tinyusb_hid_devices_is_initialized) {
|
||||
tinyusb_hid_devices_is_initialized = true;
|
||||
for (uint8_t i = 0; i < USB_HID_DEVICES_MAX; i++) {
|
||||
memset(&tinyusb_hid_devices[i], 0, sizeof(tinyusb_hid_device_t));
|
||||
}
|
||||
tinyusb_hid_devices_num = 0;
|
||||
tinyusb_interface_protocol = itf_protocol;
|
||||
tinyusb_enable_interface2(USB_INTERFACE_HID, TUD_HID_INOUT_DESC_LEN, tusb_hid_load_descriptor, itf_protocol == HID_ITF_PROTOCOL_KEYBOARD);
|
||||
}
|
||||
}
|
||||
|
||||
void USBHID::begin() {
|
||||
if (tinyusb_hid_device_input_sem == NULL) {
|
||||
tinyusb_hid_device_input_sem = xSemaphoreCreateBinary();
|
||||
}
|
||||
if (tinyusb_hid_device_input_mutex == NULL) {
|
||||
tinyusb_hid_device_input_mutex = xSemaphoreCreateMutex();
|
||||
}
|
||||
}
|
||||
|
||||
void USBHID::end() {
|
||||
if (tinyusb_hid_device_input_sem != NULL) {
|
||||
vSemaphoreDelete(tinyusb_hid_device_input_sem);
|
||||
tinyusb_hid_device_input_sem = NULL;
|
||||
}
|
||||
if (tinyusb_hid_device_input_mutex != NULL) {
|
||||
vSemaphoreDelete(tinyusb_hid_device_input_mutex);
|
||||
tinyusb_hid_device_input_mutex = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool USBHID::ready(void) {
|
||||
return tud_hid_n_ready(0);
|
||||
}
|
||||
|
||||
// TinyUSB is in the process of changing the type of the last argument to
|
||||
// tud_hid_report_complete_cb(), so extract the type from the version of TinyUSB that we're
|
||||
// compiled with.
|
||||
template<class F> struct ArgType;
|
||||
|
||||
template<class R, class T1, class T2, class T3> struct ArgType<R (*)(T1, T2, T3)> {
|
||||
typedef T1 type1;
|
||||
typedef T2 type2;
|
||||
typedef T3 type3;
|
||||
};
|
||||
|
||||
typedef ArgType<decltype(&tud_hid_report_complete_cb)>::type3 tud_hid_report_complete_cb_len_t;
|
||||
|
||||
void tud_hid_report_complete_cb(uint8_t instance, uint8_t const *report, tud_hid_report_complete_cb_len_t len) {
|
||||
if (tinyusb_hid_device_input_sem) {
|
||||
xSemaphoreGive(tinyusb_hid_device_input_sem);
|
||||
}
|
||||
}
|
||||
|
||||
bool USBHID::SendReport(uint8_t id, const void *data, size_t len, uint32_t timeout_ms) {
|
||||
if (!tinyusb_hid_device_input_sem || !tinyusb_hid_device_input_mutex) {
|
||||
log_e("TX Semaphore is NULL. You must call USBHID::begin() before you can send reports");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (xSemaphoreTake(tinyusb_hid_device_input_mutex, timeout_ms / portTICK_PERIOD_MS) != pdTRUE) {
|
||||
log_e("report %u mutex failed", id);
|
||||
return false;
|
||||
}
|
||||
|
||||
// If we're configured to support boot protocol, and the host has requested boot protocol, prevent
|
||||
// sending of report ID, by passing report ID of 0 to tud_hid_n_report().
|
||||
uint8_t effective_id = ((tinyusb_interface_protocol != HID_ITF_PROTOCOL_NONE) && (tud_hid_n_get_protocol(0) == HID_PROTOCOL_BOOT)) ? 0 : id;
|
||||
|
||||
bool res = ready();
|
||||
if (!res) {
|
||||
log_e("not ready");
|
||||
} else {
|
||||
// The semaphore may be given if the last SendReport() timed out waiting for the report to
|
||||
// be sent. Or, tud_hid_report_complete_cb() may be called an extra time, causing the
|
||||
// semaphore to be given. In these cases, take the semaphore to clear its state so that
|
||||
// we can wait for it to be given after calling tud_hid_n_report().
|
||||
xSemaphoreTake(tinyusb_hid_device_input_sem, 0);
|
||||
|
||||
res = tud_hid_n_report(0, effective_id, data, len);
|
||||
if (!res) {
|
||||
log_e("report %u failed", id);
|
||||
} else {
|
||||
if (xSemaphoreTake(tinyusb_hid_device_input_sem, timeout_ms / portTICK_PERIOD_MS) != pdTRUE) {
|
||||
log_e("report %u wait failed", id);
|
||||
res = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xSemaphoreGive(tinyusb_hid_device_input_mutex);
|
||||
return res;
|
||||
}
|
||||
|
||||
bool USBHID::addDevice(USBHIDDevice *device, uint16_t descriptor_len) {
|
||||
if (device && tinyusb_loaded_hid_devices_num < USB_HID_DEVICES_MAX) {
|
||||
if (!tinyusb_enable_hid_device(descriptor_len, device)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void USBHID::onEvent(esp_event_handler_t callback) {
|
||||
onEvent(ARDUINO_USB_HID_ANY_EVENT, callback);
|
||||
}
|
||||
void USBHID::onEvent(arduino_usb_hid_event_t event, esp_event_handler_t callback) {
|
||||
arduino_usb_event_handler_register_with(ARDUINO_USB_HID_EVENTS, event, callback, this);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_TINYUSB_HID_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,86 @@
|
||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
#include "esp_event.h"
|
||||
#include "class/hid/hid.h"
|
||||
#include "class/hid/hid_device.h"
|
||||
|
||||
// Used by the included TinyUSB drivers
|
||||
enum {
|
||||
HID_REPORT_ID_NONE,
|
||||
HID_REPORT_ID_KEYBOARD,
|
||||
HID_REPORT_ID_MOUSE,
|
||||
HID_REPORT_ID_GAMEPAD,
|
||||
HID_REPORT_ID_CONSUMER_CONTROL,
|
||||
HID_REPORT_ID_SYSTEM_CONTROL,
|
||||
HID_REPORT_ID_VENDOR
|
||||
};
|
||||
|
||||
ESP_EVENT_DECLARE_BASE(ARDUINO_USB_HID_EVENTS);
|
||||
|
||||
typedef enum {
|
||||
ARDUINO_USB_HID_ANY_EVENT = ESP_EVENT_ANY_ID,
|
||||
ARDUINO_USB_HID_SET_PROTOCOL_EVENT = 0,
|
||||
ARDUINO_USB_HID_SET_IDLE_EVENT,
|
||||
ARDUINO_USB_HID_MAX_EVENT,
|
||||
} arduino_usb_hid_event_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t instance;
|
||||
union {
|
||||
struct {
|
||||
uint8_t protocol;
|
||||
} set_protocol;
|
||||
struct {
|
||||
uint8_t idle_rate;
|
||||
} set_idle;
|
||||
};
|
||||
} arduino_usb_hid_event_data_t;
|
||||
|
||||
class USBHIDDevice {
|
||||
public:
|
||||
virtual uint16_t _onGetDescriptor(uint8_t *buffer) {
|
||||
return 0;
|
||||
}
|
||||
virtual uint16_t _onGetFeature(uint8_t report_id, uint8_t *buffer, uint16_t len) {
|
||||
return 0;
|
||||
}
|
||||
virtual void _onSetFeature(uint8_t report_id, const uint8_t *buffer, uint16_t len) {}
|
||||
virtual void _onOutput(uint8_t report_id, const uint8_t *buffer, uint16_t len) {}
|
||||
};
|
||||
|
||||
class USBHID {
|
||||
public:
|
||||
USBHID(hid_interface_protocol_enum_t itf_protocol = HID_ITF_PROTOCOL_NONE);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
bool ready(void);
|
||||
bool SendReport(uint8_t report_id, const void *data, size_t len, uint32_t timeout_ms = 100);
|
||||
void onEvent(esp_event_handler_t callback);
|
||||
void onEvent(arduino_usb_hid_event_t event, esp_event_handler_t callback);
|
||||
static bool addDevice(USBHIDDevice *device, uint16_t descriptor_len);
|
||||
};
|
||||
|
||||
#endif /* CONFIG_TINYUSB_HID_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,55 @@
|
||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "USBHID.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
|
||||
#include "USBHIDConsumerControl.h"
|
||||
|
||||
static const uint8_t report_descriptor[] = {TUD_HID_REPORT_DESC_CONSUMER(HID_REPORT_ID(HID_REPORT_ID_CONSUMER_CONTROL))};
|
||||
|
||||
USBHIDConsumerControl::USBHIDConsumerControl() : hid() {
|
||||
static bool initialized = false;
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
hid.addDevice(this, sizeof(report_descriptor));
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t USBHIDConsumerControl::_onGetDescriptor(uint8_t *dst) {
|
||||
memcpy(dst, report_descriptor, sizeof(report_descriptor));
|
||||
return sizeof(report_descriptor);
|
||||
}
|
||||
|
||||
void USBHIDConsumerControl::begin() {
|
||||
hid.begin();
|
||||
}
|
||||
|
||||
void USBHIDConsumerControl::end() {}
|
||||
|
||||
bool USBHIDConsumerControl::send(uint16_t value) {
|
||||
return hid.SendReport(HID_REPORT_ID_CONSUMER_CONTROL, &value, 2);
|
||||
}
|
||||
|
||||
size_t USBHIDConsumerControl::press(uint16_t k) {
|
||||
return send(k);
|
||||
}
|
||||
|
||||
size_t USBHIDConsumerControl::release() {
|
||||
return send(0);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_TINYUSB_HID_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,95 @@
|
||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#include "USBHID.h"
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
|
||||
// Power Control
|
||||
#define CONSUMER_CONTROL_POWER 0x0030
|
||||
#define CONSUMER_CONTROL_RESET 0x0031
|
||||
#define CONSUMER_CONTROL_SLEEP 0x0032
|
||||
|
||||
// Screen Brightness
|
||||
#define CONSUMER_CONTROL_BRIGHTNESS_INCREMENT 0x006F
|
||||
#define CONSUMER_CONTROL_BRIGHTNESS_DECREMENT 0x0070
|
||||
|
||||
// These HID usages operate only on mobile systems (battery powered) and
|
||||
// require Windows 8 (build 8302 or greater).
|
||||
#define CONSUMER_CONTROL_WIRELESS_RADIO_CONTROLS 0x000C
|
||||
#define CONSUMER_CONTROL_WIRELESS_RADIO_BUTTONS 0x00C6
|
||||
#define CONSUMER_CONTROL_WIRELESS_RADIO_LED 0x00C7
|
||||
#define CONSUMER_CONTROL_WIRELESS_RADIO_SLIDER_SWITCH 0x00C8
|
||||
|
||||
// Media Control
|
||||
#define CONSUMER_CONTROL_RECORD 0x00B2
|
||||
#define CONSUMER_CONTROL_FAST_FORWARD 0x00B3
|
||||
#define CONSUMER_CONTROL_REWIND 0x00B4
|
||||
#define CONSUMER_CONTROL_SCAN_NEXT 0x00B5
|
||||
#define CONSUMER_CONTROL_SCAN_PREVIOUS 0x00B6
|
||||
#define CONSUMER_CONTROL_STOP 0x00B7
|
||||
#define CONSUMER_CONTROL_EJECT 0x00B8
|
||||
#define CONSUMER_CONTROL_PLAY_PAUSE 0x00CD
|
||||
#define CONSUMER_CONTROL_VOLUME 0x00E0
|
||||
#define CONSUMER_CONTROL_MUTE 0x00E2
|
||||
#define CONSUMER_CONTROL_BASS 0x00E3
|
||||
#define CONSUMER_CONTROL_TREBLE 0x00E4
|
||||
#define CONSUMER_CONTROL_BASS_BOOST 0x00E5
|
||||
#define CONSUMER_CONTROL_VOLUME_INCREMENT 0x00E9
|
||||
#define CONSUMER_CONTROL_VOLUME_DECREMENT 0x00EA
|
||||
#define CONSUMER_CONTROL_BASS_INCREMENT 0x0152
|
||||
#define CONSUMER_CONTROL_BASS_DECREMENT 0x0153
|
||||
#define CONSUMER_CONTROL_TREBLE_INCREMENT 0x0154
|
||||
#define CONSUMER_CONTROL_TREBLE_DECREMENT 0x0155
|
||||
|
||||
// Application Launcher
|
||||
#define CONSUMER_CONTROL_CONFIGURATION 0x0183
|
||||
#define CONSUMER_CONTROL_EMAIL_READER 0x018A
|
||||
#define CONSUMER_CONTROL_CALCULATOR 0x0192
|
||||
#define CONSUMER_CONTROL_LOCAL_BROWSER 0x0194
|
||||
|
||||
// Browser/Explorer Specific
|
||||
#define CONSUMER_CONTROL_SEARCH 0x0221
|
||||
#define CONSUMER_CONTROL_HOME 0x0223
|
||||
#define CONSUMER_CONTROL_BACK 0x0224
|
||||
#define CONSUMER_CONTROL_FORWARD 0x0225
|
||||
#define CONSUMER_CONTROL_BR_STOP 0x0226
|
||||
#define CONSUMER_CONTROL_REFRESH 0x0227
|
||||
#define CONSUMER_CONTROL_BOOKMARKS 0x022A
|
||||
|
||||
// Mouse Horizontal scroll
|
||||
#define CONSUMER_CONTROL_PAN 0x0238
|
||||
|
||||
class USBHIDConsumerControl : public USBHIDDevice {
|
||||
private:
|
||||
USBHID hid;
|
||||
bool send(uint16_t value);
|
||||
|
||||
public:
|
||||
USBHIDConsumerControl(void);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
size_t press(uint16_t k);
|
||||
size_t release();
|
||||
|
||||
// internal use
|
||||
uint16_t _onGetDescriptor(uint8_t *buffer);
|
||||
};
|
||||
|
||||
#endif /* CONFIG_TINYUSB_HID_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,109 @@
|
||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "USBHID.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
|
||||
#include "USBHIDGamepad.h"
|
||||
|
||||
static const uint8_t report_descriptor[] = {TUD_HID_REPORT_DESC_GAMEPAD(HID_REPORT_ID(HID_REPORT_ID_GAMEPAD))};
|
||||
|
||||
USBHIDGamepad::USBHIDGamepad() : hid(), _x(0), _y(0), _z(0), _rz(0), _rx(0), _ry(0), _hat(0), _buttons(0) {
|
||||
static bool initialized = false;
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
hid.addDevice(this, sizeof(report_descriptor));
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t USBHIDGamepad::_onGetDescriptor(uint8_t *dst) {
|
||||
memcpy(dst, report_descriptor, sizeof(report_descriptor));
|
||||
return sizeof(report_descriptor);
|
||||
}
|
||||
|
||||
void USBHIDGamepad::begin() {
|
||||
hid.begin();
|
||||
}
|
||||
|
||||
void USBHIDGamepad::end() {}
|
||||
|
||||
bool USBHIDGamepad::write() {
|
||||
hid_gamepad_report_t report = {.x = _x, .y = _y, .z = _z, .rz = _rz, .rx = _rx, .ry = _ry, .hat = _hat, .buttons = _buttons};
|
||||
return hid.SendReport(HID_REPORT_ID_GAMEPAD, &report, sizeof(report));
|
||||
}
|
||||
|
||||
bool USBHIDGamepad::leftStick(int8_t x, int8_t y) {
|
||||
_x = x;
|
||||
_y = y;
|
||||
return write();
|
||||
}
|
||||
|
||||
bool USBHIDGamepad::rightStick(int8_t z, int8_t rz) {
|
||||
_z = z;
|
||||
_rz = rz;
|
||||
return write();
|
||||
}
|
||||
|
||||
bool USBHIDGamepad::leftTrigger(int8_t rx) {
|
||||
_rx = rx;
|
||||
return write();
|
||||
}
|
||||
|
||||
bool USBHIDGamepad::rightTrigger(int8_t ry) {
|
||||
_ry = ry;
|
||||
return write();
|
||||
}
|
||||
|
||||
bool USBHIDGamepad::hat(uint8_t hat) {
|
||||
if (hat > 9) {
|
||||
return false;
|
||||
}
|
||||
_hat = hat;
|
||||
return write();
|
||||
}
|
||||
|
||||
bool USBHIDGamepad::pressButton(uint8_t button) {
|
||||
if (button > 31) {
|
||||
return false;
|
||||
}
|
||||
_buttons |= (1 << button);
|
||||
return write();
|
||||
}
|
||||
|
||||
bool USBHIDGamepad::releaseButton(uint8_t button) {
|
||||
if (button > 31) {
|
||||
return false;
|
||||
}
|
||||
_buttons &= ~(1 << button);
|
||||
return write();
|
||||
}
|
||||
|
||||
bool USBHIDGamepad::send(int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons) {
|
||||
if (hat > 9) {
|
||||
return false;
|
||||
}
|
||||
_x = x;
|
||||
_y = y;
|
||||
_z = z;
|
||||
_rz = rz;
|
||||
_rx = rx;
|
||||
_ry = ry;
|
||||
_hat = hat;
|
||||
_buttons = buttons;
|
||||
return write();
|
||||
}
|
||||
|
||||
#endif /* CONFIG_TINYUSB_HID_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,93 @@
|
||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#include "USBHID.h"
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
|
||||
/// Standard Gamepad Buttons Naming from Linux input event codes
|
||||
/// https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h
|
||||
#define BUTTON_A 0
|
||||
#define BUTTON_B 1
|
||||
#define BUTTON_C 2
|
||||
#define BUTTON_X 3
|
||||
#define BUTTON_Y 4
|
||||
#define BUTTON_Z 5
|
||||
#define BUTTON_TL 6
|
||||
#define BUTTON_TR 7
|
||||
#define BUTTON_TL2 8
|
||||
#define BUTTON_TR2 9
|
||||
#define BUTTON_SELECT 10
|
||||
#define BUTTON_START 11
|
||||
#define BUTTON_MODE 12
|
||||
#define BUTTON_THUMBL 13
|
||||
#define BUTTON_THUMBR 14
|
||||
|
||||
#define BUTTON_SOUTH BUTTON_A
|
||||
#define BUTTON_EAST BUTTON_B
|
||||
#define BUTTON_NORTH BUTTON_X
|
||||
#define BUTTON_WEST BUTTON_Y
|
||||
|
||||
/// Standard Gamepad HAT/DPAD Buttons (from Linux input event codes)
|
||||
#define HAT_CENTER 0
|
||||
#define HAT_UP 1
|
||||
#define HAT_UP_RIGHT 2
|
||||
#define HAT_RIGHT 3
|
||||
#define HAT_DOWN_RIGHT 4
|
||||
#define HAT_DOWN 5
|
||||
#define HAT_DOWN_LEFT 6
|
||||
#define HAT_LEFT 7
|
||||
#define HAT_UP_LEFT 8
|
||||
|
||||
class USBHIDGamepad : public USBHIDDevice {
|
||||
private:
|
||||
USBHID hid;
|
||||
int8_t _x; ///< Delta x movement of left analog-stick
|
||||
int8_t _y; ///< Delta y movement of left analog-stick
|
||||
int8_t _z; ///< Delta z movement of right analog-joystick
|
||||
int8_t _rz; ///< Delta Rz movement of right analog-joystick
|
||||
int8_t _rx; ///< Delta Rx movement of analog left trigger
|
||||
int8_t _ry; ///< Delta Ry movement of analog right trigger
|
||||
uint8_t _hat; ///< Buttons mask for currently pressed buttons in the DPad/hat
|
||||
uint32_t _buttons; ///< Buttons mask for currently pressed buttons
|
||||
bool write();
|
||||
|
||||
public:
|
||||
USBHIDGamepad(void);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
|
||||
bool leftStick(int8_t x, int8_t y);
|
||||
bool rightStick(int8_t z, int8_t rz);
|
||||
|
||||
bool leftTrigger(int8_t rx);
|
||||
bool rightTrigger(int8_t ry);
|
||||
|
||||
bool hat(uint8_t hat);
|
||||
|
||||
bool pressButton(uint8_t button);
|
||||
bool releaseButton(uint8_t button);
|
||||
|
||||
bool send(int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons);
|
||||
|
||||
// internal use
|
||||
uint16_t _onGetDescriptor(uint8_t *buffer);
|
||||
};
|
||||
|
||||
#endif /* CONFIG_TINYUSB_HID_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
Keyboard.cpp
|
||||
|
||||
Copyright (c) 2015, Arduino LLC
|
||||
Original code (pre-library): Copyright (c) 2011, Peter Barrett
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "USBHID.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
|
||||
#include "USBHIDKeyboard.h"
|
||||
#include "keyboardLayout/KeyboardLayout.h"
|
||||
|
||||
ESP_EVENT_DEFINE_BASE(ARDUINO_USB_HID_KEYBOARD_EVENTS);
|
||||
esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, TickType_t ticks_to_wait);
|
||||
esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg);
|
||||
|
||||
static const uint8_t report_descriptor[] = {TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(HID_REPORT_ID_KEYBOARD))};
|
||||
|
||||
USBHIDKeyboard::USBHIDKeyboard() : hid(HID_ITF_PROTOCOL_KEYBOARD), _asciimap(KeyboardLayout_en_US), shiftKeyReports(false) {
|
||||
static bool initialized = false;
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
memset(&_keyReport, 0, sizeof(KeyReport));
|
||||
hid.addDevice(this, sizeof(report_descriptor));
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t USBHIDKeyboard::_onGetDescriptor(uint8_t *dst) {
|
||||
memcpy(dst, report_descriptor, sizeof(report_descriptor));
|
||||
return sizeof(report_descriptor);
|
||||
}
|
||||
|
||||
void USBHIDKeyboard::begin(const uint8_t *layout) {
|
||||
_asciimap = layout;
|
||||
hid.begin();
|
||||
}
|
||||
|
||||
void USBHIDKeyboard::end() {}
|
||||
|
||||
void USBHIDKeyboard::onEvent(esp_event_handler_t callback) {
|
||||
onEvent(ARDUINO_USB_HID_KEYBOARD_ANY_EVENT, callback);
|
||||
}
|
||||
void USBHIDKeyboard::onEvent(arduino_usb_hid_keyboard_event_t event, esp_event_handler_t callback) {
|
||||
arduino_usb_event_handler_register_with(ARDUINO_USB_HID_KEYBOARD_EVENTS, event, callback, this);
|
||||
}
|
||||
|
||||
void USBHIDKeyboard::_onOutput(uint8_t report_id, const uint8_t *buffer, uint16_t len) {
|
||||
if (report_id == HID_REPORT_ID_KEYBOARD) {
|
||||
arduino_usb_hid_keyboard_event_data_t p;
|
||||
p.leds = buffer[0];
|
||||
arduino_usb_event_post(
|
||||
ARDUINO_USB_HID_KEYBOARD_EVENTS, ARDUINO_USB_HID_KEYBOARD_LED_EVENT, &p, sizeof(arduino_usb_hid_keyboard_event_data_t), portMAX_DELAY
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void USBHIDKeyboard::sendReport(KeyReport *keys) {
|
||||
hid_keyboard_report_t report;
|
||||
report.reserved = 0;
|
||||
report.modifier = keys->modifiers;
|
||||
memcpy(report.keycode, keys->keys, 6);
|
||||
hid.SendReport(HID_REPORT_ID_KEYBOARD, &report, sizeof(report));
|
||||
}
|
||||
|
||||
void USBHIDKeyboard::setShiftKeyReports(bool set) {
|
||||
shiftKeyReports = set;
|
||||
}
|
||||
|
||||
size_t USBHIDKeyboard::pressRaw(uint8_t k) {
|
||||
uint8_t i;
|
||||
if (k >= 0xE0 && k < 0xE8) {
|
||||
// it's a modifier key
|
||||
_keyReport.modifiers |= (1 << (k - 0xE0));
|
||||
} else if (k && k < 0xA5) {
|
||||
// Add k to the key report only if it's not already present
|
||||
// and if there is an empty slot.
|
||||
if (_keyReport.keys[0] != k && _keyReport.keys[1] != k && _keyReport.keys[2] != k && _keyReport.keys[3] != k && _keyReport.keys[4] != k
|
||||
&& _keyReport.keys[5] != k) {
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
if (_keyReport.keys[i] == 0x00) {
|
||||
_keyReport.keys[i] = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == 6) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else if (_keyReport.modifiers == 0) {
|
||||
//not a modifier and not a key
|
||||
return 0;
|
||||
}
|
||||
sendReport(&_keyReport);
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t USBHIDKeyboard::releaseRaw(uint8_t k) {
|
||||
uint8_t i;
|
||||
if (k >= 0xE0 && k < 0xE8) {
|
||||
// it's a modifier key
|
||||
_keyReport.modifiers &= ~(1 << (k - 0xE0));
|
||||
} else if (k && k < 0xA5) {
|
||||
// Test the key report to see if k is present. Clear it if it exists.
|
||||
// Check all positions in case the key is present more than once (which it shouldn't be)
|
||||
for (i = 0; i < 6; i++) {
|
||||
if (0 != k && _keyReport.keys[i] == k) {
|
||||
_keyReport.keys[i] = 0x00;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Allowing for the release of a modifier key without a corresponding press
|
||||
sendReport(&_keyReport);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// press() adds the specified key (printing, non-printing, or modifier)
|
||||
// to the persistent key report and sends the report. Because of the way
|
||||
// USB HID works, the host acts like the key remains pressed until we
|
||||
// call release(), releaseAll(), or otherwise clear the report and resend.
|
||||
size_t USBHIDKeyboard::press(uint8_t k) {
|
||||
if (k >= 0x88) { // it's a non-printing key (not a modifier)
|
||||
k = k - 0x88;
|
||||
} else if (k >= 0x80) { // it's a modifier key
|
||||
_keyReport.modifiers |= (1 << (k - 0x80));
|
||||
k = 0;
|
||||
} else { // it's a printing key (k is a ASCII 0..127)
|
||||
k = _asciimap[k];
|
||||
if (!k) {
|
||||
return 0;
|
||||
}
|
||||
if ((k & SHIFT) == SHIFT) { // it's a capital letter or other character reached with shift
|
||||
// At boot, some PCs need a separate report with the shift key down like a real keyboard.
|
||||
if (shiftKeyReports) {
|
||||
pressRaw(HID_KEY_SHIFT_LEFT);
|
||||
} else {
|
||||
_keyReport.modifiers |= 0x02; // the left shift modifier
|
||||
}
|
||||
k &= ~SHIFT;
|
||||
}
|
||||
if ((k & ALT_GR) == ALT_GR) {
|
||||
_keyReport.modifiers |= 0x40; // AltGr = right Alt
|
||||
k &= ~ALT_GR;
|
||||
}
|
||||
if (k == ISO_REPLACEMENT) {
|
||||
k = ISO_KEY;
|
||||
}
|
||||
}
|
||||
return pressRaw(k);
|
||||
}
|
||||
|
||||
// release() takes the specified key out of the persistent key report and
|
||||
// sends the report. This tells the OS the key is no longer pressed and that
|
||||
// it shouldn't be repeated any more.
|
||||
size_t USBHIDKeyboard::release(uint8_t k) {
|
||||
if (k >= 0x88) { // it's a non-printing key (not a modifier)
|
||||
k = k - 0x88;
|
||||
} else if (k >= 0x80) { // it's a modifier key
|
||||
_keyReport.modifiers &= ~(1 << (k - 0x80));
|
||||
k = 0;
|
||||
} else { // it's a printing key
|
||||
k = _asciimap[k];
|
||||
if (!k) {
|
||||
return 0;
|
||||
}
|
||||
if ((k & SHIFT) == SHIFT) { // it's a capital letter or other character reached with shift
|
||||
if (shiftKeyReports) {
|
||||
releaseRaw(k & 0x7F); // Release key without shift modifier
|
||||
k = HID_KEY_SHIFT_LEFT; // Below, release shift modifier
|
||||
} else {
|
||||
_keyReport.modifiers &= ~(0x02); // the left shift modifier
|
||||
k &= ~SHIFT;
|
||||
}
|
||||
}
|
||||
if ((k & ALT_GR) == ALT_GR) {
|
||||
_keyReport.modifiers &= ~(0x40); // AltGr = right Alt
|
||||
k &= ~ALT_GR;
|
||||
}
|
||||
if (k == ISO_REPLACEMENT) {
|
||||
k = ISO_KEY;
|
||||
}
|
||||
}
|
||||
return releaseRaw(k);
|
||||
}
|
||||
|
||||
void USBHIDKeyboard::releaseAll(void) {
|
||||
_keyReport.keys[0] = 0;
|
||||
_keyReport.keys[1] = 0;
|
||||
_keyReport.keys[2] = 0;
|
||||
_keyReport.keys[3] = 0;
|
||||
_keyReport.keys[4] = 0;
|
||||
_keyReport.keys[5] = 0;
|
||||
_keyReport.modifiers = 0;
|
||||
sendReport(&_keyReport);
|
||||
}
|
||||
|
||||
size_t USBHIDKeyboard::write(uint8_t c) {
|
||||
uint8_t p = press(c); // Keydown
|
||||
release(c); // Keyup
|
||||
return p; // just return the result of press() since release() almost always returns 1
|
||||
}
|
||||
|
||||
size_t USBHIDKeyboard::write(const uint8_t *buffer, size_t size) {
|
||||
size_t n = 0;
|
||||
while (size--) {
|
||||
if (*buffer != '\r') {
|
||||
if (write(*buffer)) {
|
||||
n++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
buffer++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_TINYUSB_HID_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
Keyboard.h
|
||||
|
||||
Copyright (c) 2015, Arduino LLC
|
||||
Original code (pre-library): Copyright (c) 2011, Peter Barrett
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#include "Print.h"
|
||||
#include "USBHID.h"
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
|
||||
#include "esp_event.h"
|
||||
|
||||
ESP_EVENT_DECLARE_BASE(ARDUINO_USB_HID_KEYBOARD_EVENTS);
|
||||
|
||||
typedef enum {
|
||||
ARDUINO_USB_HID_KEYBOARD_ANY_EVENT = ESP_EVENT_ANY_ID,
|
||||
ARDUINO_USB_HID_KEYBOARD_LED_EVENT = 0,
|
||||
ARDUINO_USB_HID_KEYBOARD_MAX_EVENT,
|
||||
} arduino_usb_hid_keyboard_event_t;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t numlock : 1;
|
||||
uint8_t capslock : 1;
|
||||
uint8_t scrolllock : 1;
|
||||
uint8_t compose : 1;
|
||||
uint8_t kana : 1;
|
||||
uint8_t reserved : 3;
|
||||
};
|
||||
uint8_t leds;
|
||||
} arduino_usb_hid_keyboard_event_data_t;
|
||||
|
||||
// Supported keyboard layouts
|
||||
extern const uint8_t KeyboardLayout_de_DE[];
|
||||
extern const uint8_t KeyboardLayout_en_US[];
|
||||
extern const uint8_t KeyboardLayout_es_ES[];
|
||||
extern const uint8_t KeyboardLayout_fr_FR[];
|
||||
extern const uint8_t KeyboardLayout_it_IT[];
|
||||
extern const uint8_t KeyboardLayout_pt_PT[];
|
||||
extern const uint8_t KeyboardLayout_sv_SE[];
|
||||
extern const uint8_t KeyboardLayout_da_DK[];
|
||||
extern const uint8_t KeyboardLayout_hu_HU[];
|
||||
extern const uint8_t KeyboardLayout_pt_BR[];
|
||||
|
||||
#define KEY_LEFT_CTRL 0x80
|
||||
#define KEY_LEFT_SHIFT 0x81
|
||||
#define KEY_LEFT_ALT 0x82
|
||||
#define KEY_LEFT_GUI 0x83
|
||||
#define KEY_RIGHT_CTRL 0x84
|
||||
#define KEY_RIGHT_SHIFT 0x85
|
||||
#define KEY_RIGHT_ALT 0x86 // AltGr (Right Alt) Key
|
||||
#define KEY_RIGHT_GUI 0x87
|
||||
|
||||
#define KEY_UP_ARROW 0xDA
|
||||
#define KEY_DOWN_ARROW 0xD9
|
||||
#define KEY_LEFT_ARROW 0xD8
|
||||
#define KEY_RIGHT_ARROW 0xD7
|
||||
#define KEY_MENU 0xED // "Keyboard Application" in USB standard
|
||||
#define KEY_SPACE 0x20
|
||||
#define KEY_BACKSPACE 0xB2
|
||||
#define KEY_TAB 0xB3
|
||||
#define KEY_RETURN 0xB0
|
||||
#define KEY_ESC 0xB1
|
||||
#define KEY_INSERT 0xD1
|
||||
#define KEY_DELETE 0xD4
|
||||
#define KEY_PAGE_UP 0xD3
|
||||
#define KEY_PAGE_DOWN 0xD6
|
||||
#define KEY_HOME 0xD2
|
||||
#define KEY_END 0xD5
|
||||
#define KEY_NUM_LOCK 0xDB
|
||||
#define KEY_CAPS_LOCK 0xC1
|
||||
#define KEY_F1 0xC2
|
||||
#define KEY_F2 0xC3
|
||||
#define KEY_F3 0xC4
|
||||
#define KEY_F4 0xC5
|
||||
#define KEY_F5 0xC6
|
||||
#define KEY_F6 0xC7
|
||||
#define KEY_F7 0xC8
|
||||
#define KEY_F8 0xC9
|
||||
#define KEY_F9 0xCA
|
||||
#define KEY_F10 0xCB
|
||||
#define KEY_F11 0xCC
|
||||
#define KEY_F12 0xCD
|
||||
#define KEY_F13 0xF0
|
||||
#define KEY_F14 0xF1
|
||||
#define KEY_F15 0xF2
|
||||
#define KEY_F16 0xF3
|
||||
#define KEY_F17 0xF4
|
||||
#define KEY_F18 0xF5
|
||||
#define KEY_F19 0xF6
|
||||
#define KEY_F20 0xF7
|
||||
#define KEY_F21 0xF8
|
||||
#define KEY_F22 0xF9
|
||||
#define KEY_F23 0xFA
|
||||
#define KEY_F24 0xFB
|
||||
#define KEY_PRINT_SCREEN 0xCE
|
||||
#define KEY_SCROLL_LOCK 0xCF
|
||||
#define KEY_PAUSE 0xD0
|
||||
|
||||
#define LED_NUMLOCK 0x01
|
||||
#define LED_CAPSLOCK 0x02
|
||||
#define LED_SCROLLLOCK 0x04
|
||||
#define LED_COMPOSE 0x08
|
||||
#define LED_KANA 0x10
|
||||
|
||||
// Numeric keypad
|
||||
#define KEY_KP_SLASH 0xDC
|
||||
#define KEY_KP_ASTERISK 0xDD
|
||||
#define KEY_KP_MINUS 0xDE
|
||||
#define KEY_KP_PLUS 0xDF
|
||||
#define KEY_KP_ENTER 0xE0
|
||||
#define KEY_KP_1 0xE1
|
||||
#define KEY_KP_2 0xE2
|
||||
#define KEY_KP_3 0xE3
|
||||
#define KEY_KP_4 0xE4
|
||||
#define KEY_KP_5 0xE5
|
||||
#define KEY_KP_6 0xE6
|
||||
#define KEY_KP_7 0xE7
|
||||
#define KEY_KP_8 0xE8
|
||||
#define KEY_KP_9 0xE9
|
||||
#define KEY_KP_0 0xEA
|
||||
#define KEY_KP_DOT 0xEB
|
||||
|
||||
// Low level key report: up to 6 keys and shift, ctrl etc at once
|
||||
typedef struct {
|
||||
uint8_t modifiers;
|
||||
uint8_t reserved;
|
||||
uint8_t keys[6];
|
||||
} KeyReport;
|
||||
|
||||
class USBHIDKeyboard : public USBHIDDevice, public Print {
|
||||
private:
|
||||
USBHID hid;
|
||||
KeyReport _keyReport;
|
||||
const uint8_t *_asciimap;
|
||||
bool shiftKeyReports;
|
||||
|
||||
public:
|
||||
USBHIDKeyboard(void);
|
||||
void begin(const uint8_t *layout = KeyboardLayout_en_US);
|
||||
void end(void);
|
||||
size_t write(uint8_t k);
|
||||
size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t press(uint8_t k);
|
||||
size_t release(uint8_t k);
|
||||
void releaseAll(void);
|
||||
void sendReport(KeyReport *keys);
|
||||
void setShiftKeyReports(bool set);
|
||||
|
||||
//raw functions work with TinyUSB's HID_KEY_* macros
|
||||
size_t pressRaw(uint8_t k);
|
||||
size_t releaseRaw(uint8_t k);
|
||||
|
||||
void onEvent(esp_event_handler_t callback);
|
||||
void onEvent(arduino_usb_hid_keyboard_event_t event, esp_event_handler_t callback);
|
||||
|
||||
// internal use
|
||||
uint16_t _onGetDescriptor(uint8_t *buffer);
|
||||
void _onOutput(uint8_t report_id, const uint8_t *buffer, uint16_t len);
|
||||
};
|
||||
|
||||
#endif /* CONFIG_TINYUSB_HID_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
Mouse.cpp
|
||||
|
||||
Copyright (c) 2015, Arduino LLC
|
||||
Original code (pre-library): Copyright (c) 2011, Peter Barrett
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "USBHID.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
|
||||
#include "USBHIDMouse.h"
|
||||
|
||||
USBHIDMouseBase::USBHIDMouseBase(HIDMouseType_t *type) : hid(), _buttons(0), _type(type) {
|
||||
static bool initialized = false;
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
hid.addDevice(this, _type->descriptor_size);
|
||||
}
|
||||
};
|
||||
|
||||
uint16_t USBHIDMouseBase::_onGetDescriptor(uint8_t *dst) {
|
||||
memcpy(dst, _type->report_descriptor, _type->descriptor_size);
|
||||
return _type->descriptor_size;
|
||||
}
|
||||
|
||||
void USBHIDMouseBase::buttons(uint8_t b) {
|
||||
if (b != _buttons) {
|
||||
_buttons = b;
|
||||
}
|
||||
}
|
||||
|
||||
void USBHIDMouseBase::begin() {
|
||||
hid.begin();
|
||||
}
|
||||
|
||||
void USBHIDMouseBase::end() {}
|
||||
|
||||
void USBHIDMouseBase::press(uint8_t b) {
|
||||
this->buttons(_buttons | b);
|
||||
}
|
||||
|
||||
void USBHIDMouseBase::release(uint8_t b) {
|
||||
this->buttons(_buttons & ~b);
|
||||
}
|
||||
|
||||
bool USBHIDMouseBase::isPressed(uint8_t b) {
|
||||
if ((b & _buttons) > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static const uint8_t abs_mouse_report_descriptor[] = {TUD_HID_REPORT_DESC_ABSMOUSE(HID_REPORT_ID(HID_REPORT_ID_MOUSE))};
|
||||
|
||||
HIDMouseType_t HIDMouseAbs = {HID_MOUSE_ABSOLUTE, abs_mouse_report_descriptor, sizeof(abs_mouse_report_descriptor), sizeof(hid_abs_mouse_report_t)};
|
||||
|
||||
void USBHIDAbsoluteMouse::move(int16_t x, int16_t y, int8_t wheel, int8_t pan) {
|
||||
hid_abs_mouse_report_t report;
|
||||
report.buttons = _buttons;
|
||||
report.x = _lastx = x;
|
||||
report.y = _lasty = y;
|
||||
report.wheel = wheel;
|
||||
report.pan = pan;
|
||||
sendReport(report);
|
||||
}
|
||||
|
||||
void USBHIDAbsoluteMouse::click(uint8_t b) {
|
||||
_buttons = b;
|
||||
move(_lastx, _lasty);
|
||||
_buttons = 0;
|
||||
move(_lastx, _lasty);
|
||||
}
|
||||
|
||||
void USBHIDAbsoluteMouse::buttons(uint8_t b) {
|
||||
if (b != _buttons) {
|
||||
_buttons = b;
|
||||
move(_lastx, _lasty);
|
||||
}
|
||||
}
|
||||
|
||||
static const uint8_t rel_mouse_report_descriptor[] = {TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(HID_REPORT_ID_MOUSE))};
|
||||
|
||||
HIDMouseType_t HIDMouseRel = {HID_MOUSE_RELATIVE, rel_mouse_report_descriptor, sizeof(rel_mouse_report_descriptor), sizeof(hid_mouse_report_t)};
|
||||
|
||||
void USBHIDRelativeMouse::move(int8_t x, int8_t y, int8_t wheel, int8_t pan) {
|
||||
hid_mouse_report_t report = {.buttons = _buttons, .x = x, .y = y, .wheel = wheel, .pan = pan};
|
||||
sendReport(report);
|
||||
}
|
||||
|
||||
void USBHIDRelativeMouse::click(uint8_t b) {
|
||||
_buttons = b;
|
||||
move(0, 0);
|
||||
_buttons = 0;
|
||||
move(0, 0);
|
||||
}
|
||||
|
||||
void USBHIDRelativeMouse::buttons(uint8_t b) {
|
||||
if (b != _buttons) {
|
||||
_buttons = b;
|
||||
move(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_TINYUSB_HID_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
Mouse.h
|
||||
|
||||
Copyright (c) 2015, Arduino LLC
|
||||
Original code (pre-library): Copyright (c) 2011, Peter Barrett
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#include "USBHID.h"
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
|
||||
#define MOUSE_LEFT 0x01
|
||||
#define MOUSE_RIGHT 0x02
|
||||
#define MOUSE_MIDDLE 0x04
|
||||
#define MOUSE_BACKWARD 0x08
|
||||
#define MOUSE_FORWARD 0x10
|
||||
#define MOUSE_ALL 0x1F
|
||||
|
||||
enum MousePositioning_t {
|
||||
HID_MOUSE_RELATIVE,
|
||||
HID_MOUSE_ABSOLUTE
|
||||
};
|
||||
|
||||
struct HIDMouseType_t {
|
||||
MousePositioning_t positioning;
|
||||
const uint8_t *report_descriptor;
|
||||
size_t descriptor_size;
|
||||
size_t report_size;
|
||||
};
|
||||
|
||||
extern HIDMouseType_t HIDMouseRel;
|
||||
extern HIDMouseType_t HIDMouseAbs;
|
||||
|
||||
class USBHIDMouseBase : public USBHIDDevice {
|
||||
public:
|
||||
USBHIDMouseBase(HIDMouseType_t *type);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
void press(uint8_t b = MOUSE_LEFT); // press LEFT by default
|
||||
void release(uint8_t b = MOUSE_LEFT); // release LEFT by default
|
||||
bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default
|
||||
template<typename T> bool sendReport(T report) {
|
||||
return hid.SendReport(HID_REPORT_ID_MOUSE, &report, _type->report_size);
|
||||
};
|
||||
// internal use
|
||||
uint16_t _onGetDescriptor(uint8_t *buffer);
|
||||
virtual void click(uint8_t b) = 0;
|
||||
virtual void buttons(uint8_t b) = 0;
|
||||
|
||||
protected:
|
||||
USBHID hid;
|
||||
uint8_t _buttons;
|
||||
HIDMouseType_t *_type;
|
||||
};
|
||||
|
||||
class USBHIDRelativeMouse : public USBHIDMouseBase {
|
||||
public:
|
||||
USBHIDRelativeMouse(void) : USBHIDMouseBase(&HIDMouseRel) {}
|
||||
void move(int8_t x, int8_t y, int8_t wheel = 0, int8_t pan = 0);
|
||||
void click(uint8_t b = MOUSE_LEFT) override;
|
||||
void buttons(uint8_t b) override;
|
||||
};
|
||||
|
||||
class USBHIDAbsoluteMouse : public USBHIDMouseBase {
|
||||
public:
|
||||
USBHIDAbsoluteMouse(void) : USBHIDMouseBase(&HIDMouseAbs) {}
|
||||
void move(int16_t x, int16_t y, int8_t wheel = 0, int8_t pan = 0);
|
||||
void click(uint8_t b = MOUSE_LEFT) override;
|
||||
void buttons(uint8_t b) override;
|
||||
|
||||
private:
|
||||
int16_t _lastx = 0;
|
||||
int16_t _lasty = 0;
|
||||
};
|
||||
|
||||
// don't break examples and old sketches
|
||||
typedef USBHIDRelativeMouse USBHIDMouse;
|
||||
|
||||
#endif /* CONFIG_TINYUSB_HID_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "USBHID.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
|
||||
#include "USBHIDSystemControl.h"
|
||||
|
||||
static const uint8_t report_descriptor[] = {TUD_HID_REPORT_DESC_SYSTEM_CONTROL(HID_REPORT_ID(HID_REPORT_ID_SYSTEM_CONTROL))};
|
||||
|
||||
USBHIDSystemControl::USBHIDSystemControl() : hid() {
|
||||
static bool initialized = false;
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
hid.addDevice(this, sizeof(report_descriptor));
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t USBHIDSystemControl::_onGetDescriptor(uint8_t *dst) {
|
||||
memcpy(dst, report_descriptor, sizeof(report_descriptor));
|
||||
return sizeof(report_descriptor);
|
||||
}
|
||||
|
||||
void USBHIDSystemControl::begin() {
|
||||
hid.begin();
|
||||
}
|
||||
|
||||
void USBHIDSystemControl::end() {}
|
||||
|
||||
bool USBHIDSystemControl::send(uint8_t value) {
|
||||
return hid.SendReport(HID_REPORT_ID_SYSTEM_CONTROL, &value, 1);
|
||||
}
|
||||
|
||||
size_t USBHIDSystemControl::press(uint8_t k) {
|
||||
if (k > 3) {
|
||||
return 0;
|
||||
}
|
||||
return send(k);
|
||||
}
|
||||
|
||||
size_t USBHIDSystemControl::release() {
|
||||
return send(0);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_TINYUSB_HID_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#include "USBHID.h"
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
|
||||
#define SYSTEM_CONTROL_NONE 0
|
||||
#define SYSTEM_CONTROL_POWER_OFF 1
|
||||
#define SYSTEM_CONTROL_STANDBY 2
|
||||
#define SYSTEM_CONTROL_WAKE_HOST 3
|
||||
|
||||
class USBHIDSystemControl : public USBHIDDevice {
|
||||
private:
|
||||
USBHID hid;
|
||||
bool send(uint8_t value);
|
||||
|
||||
public:
|
||||
USBHIDSystemControl(void);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
size_t press(uint8_t k);
|
||||
size_t release();
|
||||
|
||||
// internal use
|
||||
uint16_t _onGetDescriptor(uint8_t *buffer);
|
||||
};
|
||||
|
||||
#endif /* CONFIG_TINYUSB_HID_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,221 @@
|
||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "USBHID.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
|
||||
#include "esp32-hal-log.h"
|
||||
#include "USBHIDVendor.h"
|
||||
|
||||
ESP_EVENT_DEFINE_BASE(ARDUINO_USB_HID_VENDOR_EVENTS);
|
||||
esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, TickType_t ticks_to_wait);
|
||||
esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg);
|
||||
|
||||
// HID Generic Input, Output & Feature
|
||||
// - 1st parameter is report size (mandatory)
|
||||
// - 2nd parameter is report id HID_REPORT_ID(n) (optional)
|
||||
#define TUD_HID_REPORT_DESC_GENERIC_INOUT_FEATURE(report_size, ...) \
|
||||
HID_USAGE_PAGE_N(HID_USAGE_PAGE_VENDOR, 2), HID_USAGE(0x01), HID_COLLECTION(HID_COLLECTION_APPLICATION), /* Report ID if any */ \
|
||||
__VA_ARGS__ /* Input */ \
|
||||
HID_USAGE(0x02), \
|
||||
HID_LOGICAL_MIN(0x00), HID_LOGICAL_MAX(0xff), HID_REPORT_SIZE(8), HID_REPORT_COUNT(report_size), \
|
||||
HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), /* Output */ \
|
||||
HID_USAGE(0x03), HID_LOGICAL_MIN(0x00), HID_LOGICAL_MAX(0xff), HID_REPORT_SIZE(8), HID_REPORT_COUNT(report_size), \
|
||||
HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), /* Feature */ \
|
||||
HID_USAGE(0x04), HID_LOGICAL_MIN(0x00), HID_LOGICAL_MAX(0xff), HID_REPORT_SIZE(8), HID_REPORT_COUNT(report_size), \
|
||||
HID_FEATURE(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), HID_COLLECTION_END
|
||||
|
||||
#define TUD_HID_REPORT_DESC_GENERIC_INOUT_FEATURE_LEN 46
|
||||
|
||||
// max size is 64 and we need one byte for the report ID
|
||||
static uint8_t HID_VENDOR_REPORT_SIZE = 63;
|
||||
static uint8_t feature[64];
|
||||
static QueueHandle_t rx_queue = NULL;
|
||||
static bool prepend_size = false;
|
||||
|
||||
USBHIDVendor::USBHIDVendor(uint8_t report_size, bool prepend) : hid() {
|
||||
static bool initialized = false;
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
hid.addDevice(this, TUD_HID_REPORT_DESC_GENERIC_INOUT_FEATURE_LEN);
|
||||
memset(feature, 0, 64);
|
||||
if (report_size < 64) {
|
||||
HID_VENDOR_REPORT_SIZE = report_size;
|
||||
}
|
||||
prepend_size = prepend;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t USBHIDVendor::_onGetDescriptor(uint8_t *dst) {
|
||||
uint8_t report_descriptor[] = {TUD_HID_REPORT_DESC_GENERIC_INOUT_FEATURE(HID_VENDOR_REPORT_SIZE, HID_REPORT_ID(HID_REPORT_ID_VENDOR))};
|
||||
memcpy(dst, report_descriptor, sizeof(report_descriptor));
|
||||
return sizeof(report_descriptor);
|
||||
}
|
||||
|
||||
void USBHIDVendor::prependInputPacketsWithSize(bool enable) {
|
||||
prepend_size = enable;
|
||||
}
|
||||
|
||||
size_t USBHIDVendor::setRxBufferSize(size_t rx_queue_len) {
|
||||
if (rx_queue) {
|
||||
if (!rx_queue_len) {
|
||||
vQueueDelete(rx_queue);
|
||||
rx_queue = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t));
|
||||
if (!rx_queue) {
|
||||
return 0;
|
||||
}
|
||||
return rx_queue_len;
|
||||
}
|
||||
|
||||
void USBHIDVendor::begin() {
|
||||
hid.begin();
|
||||
setRxBufferSize(256); //default if not preset
|
||||
}
|
||||
|
||||
void USBHIDVendor::end() {
|
||||
setRxBufferSize(0);
|
||||
}
|
||||
|
||||
void USBHIDVendor::onEvent(esp_event_handler_t callback) {
|
||||
onEvent(ARDUINO_USB_HID_VENDOR_ANY_EVENT, callback);
|
||||
}
|
||||
|
||||
void USBHIDVendor::onEvent(arduino_usb_hid_vendor_event_t event, esp_event_handler_t callback) {
|
||||
arduino_usb_event_handler_register_with(ARDUINO_USB_HID_VENDOR_EVENTS, event, callback, this);
|
||||
}
|
||||
|
||||
uint16_t USBHIDVendor::_onGetFeature(uint8_t report_id, uint8_t *buffer, uint16_t len) {
|
||||
if (report_id != HID_REPORT_ID_VENDOR) {
|
||||
return 0;
|
||||
}
|
||||
memcpy(buffer, feature, len);
|
||||
arduino_usb_hid_vendor_event_data_t p;
|
||||
p.buffer = feature;
|
||||
p.len = len;
|
||||
arduino_usb_event_post(
|
||||
ARDUINO_USB_HID_VENDOR_EVENTS, ARDUINO_USB_HID_VENDOR_GET_FEATURE_EVENT, &p, sizeof(arduino_usb_hid_vendor_event_data_t), portMAX_DELAY
|
||||
);
|
||||
return len;
|
||||
}
|
||||
|
||||
void USBHIDVendor::_onSetFeature(uint8_t report_id, const uint8_t *buffer, uint16_t len) {
|
||||
if (report_id != HID_REPORT_ID_VENDOR) {
|
||||
return;
|
||||
}
|
||||
memcpy(feature, buffer, len);
|
||||
arduino_usb_hid_vendor_event_data_t p;
|
||||
p.buffer = feature;
|
||||
p.len = len;
|
||||
arduino_usb_event_post(
|
||||
ARDUINO_USB_HID_VENDOR_EVENTS, ARDUINO_USB_HID_VENDOR_SET_FEATURE_EVENT, &p, sizeof(arduino_usb_hid_vendor_event_data_t), portMAX_DELAY
|
||||
);
|
||||
}
|
||||
|
||||
void USBHIDVendor::_onOutput(uint8_t report_id, const uint8_t *buffer, uint16_t len) {
|
||||
if (report_id != HID_REPORT_ID_VENDOR) {
|
||||
return;
|
||||
}
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
if (rx_queue == NULL || !xQueueSend(rx_queue, buffer + i, 0)) {
|
||||
len = i + 1;
|
||||
log_e("RX Queue Overflow");
|
||||
break;
|
||||
}
|
||||
}
|
||||
arduino_usb_hid_vendor_event_data_t p;
|
||||
p.buffer = buffer;
|
||||
p.len = len;
|
||||
arduino_usb_event_post(ARDUINO_USB_HID_VENDOR_EVENTS, ARDUINO_USB_HID_VENDOR_OUTPUT_EVENT, &p, sizeof(arduino_usb_hid_vendor_event_data_t), portMAX_DELAY);
|
||||
}
|
||||
|
||||
size_t USBHIDVendor::write(const uint8_t *buffer, size_t len) {
|
||||
uint8_t hid_in[HID_VENDOR_REPORT_SIZE];
|
||||
const uint8_t *data = (const uint8_t *)buffer;
|
||||
uint8_t size_offset = prepend_size ? 1 : 0;
|
||||
size_t to_send = len, max_send = HID_VENDOR_REPORT_SIZE - size_offset, will_send = 0;
|
||||
while (to_send) {
|
||||
will_send = to_send;
|
||||
if (will_send > max_send) {
|
||||
will_send = max_send;
|
||||
}
|
||||
if (prepend_size) {
|
||||
hid_in[0] = will_send;
|
||||
}
|
||||
// We can get INPUT only when data length equals the input report size
|
||||
memcpy(hid_in + size_offset, data, will_send);
|
||||
// pad with zeroes
|
||||
memset(hid_in + size_offset + will_send, 0, max_send - will_send);
|
||||
if (!hid.SendReport(HID_REPORT_ID_VENDOR, hid_in, HID_VENDOR_REPORT_SIZE)) {
|
||||
return len - to_send;
|
||||
}
|
||||
to_send -= will_send;
|
||||
data += will_send;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t USBHIDVendor::write(uint8_t c) {
|
||||
return write(&c, 1);
|
||||
}
|
||||
|
||||
int USBHIDVendor::available(void) {
|
||||
if (rx_queue == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return uxQueueMessagesWaiting(rx_queue);
|
||||
}
|
||||
|
||||
int USBHIDVendor::peek(void) {
|
||||
if (rx_queue == NULL) {
|
||||
return -1;
|
||||
}
|
||||
uint8_t c;
|
||||
if (xQueuePeek(rx_queue, &c, 0)) {
|
||||
return c;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int USBHIDVendor::read(void) {
|
||||
if (rx_queue == NULL) {
|
||||
return -1;
|
||||
}
|
||||
uint8_t c = 0;
|
||||
if (xQueueReceive(rx_queue, &c, 0)) {
|
||||
return c;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t USBHIDVendor::read(uint8_t *buffer, size_t size) {
|
||||
if (rx_queue == NULL) {
|
||||
return -1;
|
||||
}
|
||||
uint8_t c = 0;
|
||||
size_t count = 0;
|
||||
while (count < size && xQueueReceive(rx_queue, &c, 0)) {
|
||||
buffer[count++] = c;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void USBHIDVendor::flush(void) {}
|
||||
|
||||
#endif /* CONFIG_TINYUSB_HID_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,73 @@
|
||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#include "Stream.h"
|
||||
#include "USBHID.h"
|
||||
#if CONFIG_TINYUSB_HID_ENABLED
|
||||
|
||||
ESP_EVENT_DECLARE_BASE(ARDUINO_USB_HID_VENDOR_EVENTS);
|
||||
|
||||
typedef enum {
|
||||
ARDUINO_USB_HID_VENDOR_ANY_EVENT = ESP_EVENT_ANY_ID,
|
||||
ARDUINO_USB_HID_VENDOR_SET_FEATURE_EVENT = 0,
|
||||
ARDUINO_USB_HID_VENDOR_GET_FEATURE_EVENT,
|
||||
ARDUINO_USB_HID_VENDOR_OUTPUT_EVENT,
|
||||
ARDUINO_USB_HID_VENDOR_MAX_EVENT,
|
||||
} arduino_usb_hid_vendor_event_t;
|
||||
|
||||
typedef struct {
|
||||
const uint8_t *buffer;
|
||||
uint16_t len;
|
||||
} arduino_usb_hid_vendor_event_data_t;
|
||||
|
||||
class USBHIDVendor : public USBHIDDevice, public Stream {
|
||||
private:
|
||||
USBHID hid;
|
||||
|
||||
public:
|
||||
// Max report size is 64, but we need one byte for report ID, so in reality max is 63.
|
||||
// Because input packets are always with length equal to the report size
|
||||
// it will not be known how many bytes actually matter. Setting 'prepend_size' to 'true' will
|
||||
// make the first byte of each packet to be the length of data in that packet.
|
||||
// This comes with penalty of one byte, but is very useful when using Vendor for streaming
|
||||
USBHIDVendor(uint8_t report_size = 63, bool prepend_size = false);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
void prependInputPacketsWithSize(bool enable);
|
||||
size_t setRxBufferSize(size_t);
|
||||
size_t write(const uint8_t *buffer, size_t len);
|
||||
size_t write(uint8_t);
|
||||
int available(void);
|
||||
int peek(void);
|
||||
int read(void);
|
||||
size_t read(uint8_t *buffer, size_t size);
|
||||
void flush(void);
|
||||
|
||||
void onEvent(esp_event_handler_t callback);
|
||||
void onEvent(arduino_usb_hid_vendor_event_t event, esp_event_handler_t callback);
|
||||
|
||||
// internal use
|
||||
uint16_t _onGetDescriptor(uint8_t *buffer);
|
||||
uint16_t _onGetFeature(uint8_t report_id, uint8_t *buffer, uint16_t len);
|
||||
void _onSetFeature(uint8_t report_id, const uint8_t *buffer, uint16_t len);
|
||||
void _onOutput(uint8_t report_id, const uint8_t *buffer, uint16_t len);
|
||||
};
|
||||
|
||||
#endif /* CONFIG_TINYUSB_HID_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,200 @@
|
||||
#include "USBMIDI.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#if CONFIG_TINYUSB_MIDI_ENABLED
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "esp32-hal-tinyusb.h"
|
||||
|
||||
// Initialize static members
|
||||
char *USBMIDI::midiUserDeviceName = nullptr;
|
||||
// Weak definition of getUSBMIDIDefaultDeviceName to provide a default name
|
||||
__attribute__((weak)) const char *getUSBMIDIDefaultDeviceName() {
|
||||
return ESP32_USB_MIDI_DEFAULT_NAME;
|
||||
}
|
||||
|
||||
// Default Cable Number (for simplified APIs that do not expose this)
|
||||
#define DEFAULT_CN 0
|
||||
|
||||
static bool tinyusb_midi_descriptor_loaded = false;
|
||||
static bool tinyusb_midi_interface_enabled = false;
|
||||
|
||||
extern "C" uint16_t tusb_midi_load_descriptor(uint8_t *dst, uint8_t *itf) {
|
||||
if (tinyusb_midi_descriptor_loaded) {
|
||||
return 0;
|
||||
}
|
||||
tinyusb_midi_descriptor_loaded = true;
|
||||
|
||||
uint8_t str_index = tinyusb_add_string_descriptor(USBMIDI::getCurrentDeviceName());
|
||||
uint8_t ep_in = tinyusb_get_free_in_endpoint();
|
||||
TU_VERIFY(ep_in != 0);
|
||||
uint8_t ep_out = tinyusb_get_free_out_endpoint();
|
||||
TU_VERIFY(ep_out != 0);
|
||||
uint8_t descriptor[TUD_MIDI_DESC_LEN] = {
|
||||
TUD_MIDI_DESCRIPTOR(*itf, str_index, ep_out, (uint8_t)(0x80 | ep_in), CFG_TUD_ENDOINT_SIZE),
|
||||
};
|
||||
*itf += 2;
|
||||
memcpy(dst, descriptor, TUD_MIDI_DESC_LEN);
|
||||
|
||||
return TUD_MIDI_DESC_LEN;
|
||||
}
|
||||
|
||||
USBMIDI::USBMIDI() {
|
||||
if (!tinyusb_midi_interface_enabled) {
|
||||
tinyusb_midi_interface_enabled = true;
|
||||
tinyusb_enable_interface(USB_INTERFACE_MIDI, TUD_MIDI_DESC_LEN, tusb_midi_load_descriptor);
|
||||
} else {
|
||||
log_e("USBMIDI: Multiple instances of USBMIDI not supported!");
|
||||
}
|
||||
}
|
||||
|
||||
// private function for setting a not null/empty MIDI device name limited to 32 characters
|
||||
void USBMIDI::setDeviceName(const char *name) {
|
||||
const uint8_t maxNameLength = 32; // tinyUSB Descriptor limit
|
||||
if (name != nullptr && strlen(name) > 0) {
|
||||
if (strlen(name) > maxNameLength) {
|
||||
log_w("USBMIDI: Device name too long, truncating to %d characters.", maxNameLength);
|
||||
}
|
||||
if (!midiUserDeviceName) {
|
||||
midiUserDeviceName = new char[maxNameLength + 1]; // +1 for null-terminator
|
||||
}
|
||||
if (midiUserDeviceName) {
|
||||
strncpy(midiUserDeviceName, name, maxNameLength);
|
||||
// Ensure null-termination when overflowing
|
||||
midiUserDeviceName[maxNameLength] = '\0';
|
||||
} else {
|
||||
log_e("USBMIDI: Failed to allocate memory for device name, using default name.");
|
||||
}
|
||||
} else {
|
||||
log_w("USBMIDI: No device name provided, using default name [%s].", getUSBMIDIDefaultDeviceName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Constructor for setting the current device name
|
||||
* 1. Name set via constructor (if any)
|
||||
* 2. Name set via SET_USB_MIDI_DEVICE_NAME() macro (if defined)
|
||||
* 3. Default name "TinyUSB MIDI"
|
||||
* If device name is set as "", it will be ignored
|
||||
*/
|
||||
USBMIDI::USBMIDI(const char *name) {
|
||||
if (!tinyusb_midi_interface_enabled) {
|
||||
setDeviceName(name);
|
||||
tinyusb_midi_interface_enabled = true;
|
||||
tinyusb_enable_interface(USB_INTERFACE_MIDI, TUD_MIDI_DESC_LEN, tusb_midi_load_descriptor);
|
||||
} else {
|
||||
log_e("USBMIDI: Multiple instances of USBMIDI not supported!");
|
||||
}
|
||||
}
|
||||
|
||||
USBMIDI::~USBMIDI() {
|
||||
if (midiUserDeviceName) {
|
||||
delete[] midiUserDeviceName;
|
||||
midiUserDeviceName = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void USBMIDI::begin() {}
|
||||
void USBMIDI::end() {}
|
||||
|
||||
const char *USBMIDI::getCurrentDeviceName(void) {
|
||||
if (midiUserDeviceName) {
|
||||
return midiUserDeviceName;
|
||||
}
|
||||
// If no user name set, use the compile-time default name limited to 32 characters
|
||||
setDeviceName(getUSBMIDIDefaultDeviceName());
|
||||
if (midiUserDeviceName && strlen(midiUserDeviceName)) {
|
||||
return midiUserDeviceName;
|
||||
} else {
|
||||
return "TinyUSB MIDI";
|
||||
}
|
||||
}
|
||||
|
||||
// uint compatible version of constrain
|
||||
#define uconstrain(amt, low, high) ((amt) <= (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
|
||||
|
||||
#define STATUS(CIN, CHANNEL) static_cast<uint8_t>(((CIN & 0x7F) << 4) | (uconstrain(CHANNEL - 1, 0, 15) & 0x7F))
|
||||
|
||||
// Note: All the user-level API calls do extensive input constraining to prevent easy to make mistakes.
|
||||
// (You can thank me later.)
|
||||
#define _(x) static_cast<uint8_t>(uconstrain(x, 0, 127))
|
||||
|
||||
// Note On
|
||||
void USBMIDI::noteOn(uint8_t note, uint8_t velocity, uint8_t channel) {
|
||||
midiEventPacket_t event = {MIDI_CIN_NOTE_ON, STATUS(MIDI_CIN_NOTE_ON, channel), _(note), _(velocity)};
|
||||
writePacket(&event);
|
||||
}
|
||||
|
||||
// Note Off
|
||||
void USBMIDI::noteOff(uint8_t note, uint8_t velocity, uint8_t channel) {
|
||||
midiEventPacket_t event = {MIDI_CIN_NOTE_OFF, STATUS(MIDI_CIN_NOTE_OFF, channel), _(note), _(velocity)};
|
||||
writePacket(&event);
|
||||
}
|
||||
|
||||
// Program Change
|
||||
void USBMIDI::programChange(uint8_t program, uint8_t channel) {
|
||||
midiEventPacket_t event = {MIDI_CIN_PROGRAM_CHANGE, STATUS(MIDI_CIN_PROGRAM_CHANGE, channel), _(program), 0x0};
|
||||
writePacket(&event);
|
||||
}
|
||||
|
||||
// Control Change (Continuous Controller)
|
||||
void USBMIDI::controlChange(uint8_t control, uint8_t value, uint8_t channel) {
|
||||
midiEventPacket_t event = {MIDI_CIN_CONTROL_CHANGE, STATUS(MIDI_CIN_CONTROL_CHANGE, channel), _(control), _(value)};
|
||||
writePacket(&event);
|
||||
}
|
||||
|
||||
// Polyphonic Key Pressure (Aftertouch)
|
||||
void USBMIDI::polyPressure(uint8_t note, uint8_t pressure, uint8_t channel) {
|
||||
midiEventPacket_t event = {MIDI_CIN_POLY_KEYPRESS, STATUS(MIDI_CIN_POLY_KEYPRESS, channel), _(note), _(pressure)};
|
||||
writePacket(&event);
|
||||
}
|
||||
|
||||
// Channel Pressure (Aftertouch)
|
||||
void USBMIDI::channelPressure(uint8_t pressure, uint8_t channel) {
|
||||
midiEventPacket_t event = {MIDI_CIN_CHANNEL_PRESSURE, STATUS(MIDI_CIN_CHANNEL_PRESSURE, channel), _(pressure), 0x0};
|
||||
writePacket(&event);
|
||||
}
|
||||
|
||||
// Pitch Bend Change [-8192,0,8191]
|
||||
void USBMIDI::pitchBend(int16_t value, uint8_t channel) {
|
||||
uint16_t pitchBendValue = constrain(value, -8192, 8191) + 8192;
|
||||
pitchBend(pitchBendValue, channel);
|
||||
}
|
||||
|
||||
// Pitch Bend Change [0,8192,16383]
|
||||
void USBMIDI::pitchBend(uint16_t value, uint8_t channel) {
|
||||
uint16_t pitchBendValue = static_cast<uint16_t>(uconstrain(value, 0, 16383));
|
||||
// Split the 14-bit integer into two 7-bit values
|
||||
uint8_t lsb = pitchBendValue & 0x7F; // Lower 7 bits
|
||||
uint8_t msb = (pitchBendValue >> 7) & 0x7F; // Upper 7 bits
|
||||
|
||||
midiEventPacket_t event = {MIDI_CIN_PITCH_BEND_CHANGE, STATUS(MIDI_CIN_PITCH_BEND_CHANGE, channel), lsb, msb};
|
||||
writePacket(&event);
|
||||
}
|
||||
|
||||
// Pitch Bend Change [-1.0,0,1.0]
|
||||
void USBMIDI::pitchBend(double value, uint8_t channel) {
|
||||
// Multiply by 8191 and round to nearest integer
|
||||
int16_t pitchBendValue = static_cast<int16_t>(round(constrain(value, -1.0, 1.0) * 8191.0));
|
||||
|
||||
pitchBend(pitchBendValue, channel);
|
||||
}
|
||||
|
||||
bool USBMIDI::readPacket(midiEventPacket_t *packet) {
|
||||
return tud_midi_packet_read((uint8_t *)packet);
|
||||
}
|
||||
|
||||
bool USBMIDI::writePacket(midiEventPacket_t *packet) {
|
||||
return tud_midi_packet_write((uint8_t *)packet);
|
||||
}
|
||||
|
||||
size_t USBMIDI::write(uint8_t c) {
|
||||
// MIDI_CIN_1BYTE_DATA => Verbatim MIDI byte-stream copy
|
||||
// (See also Table 4-1 of USB MIDI spec 1.0)
|
||||
midiEventPacket_t packet = {DEFAULT_CN | MIDI_CIN_1BYTE_DATA, c, 0, 0};
|
||||
|
||||
return tud_midi_packet_write((uint8_t *)&packet);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_TINYUSB_MIDI_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,91 @@
|
||||
#include "soc/soc_caps.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
#include "esp32-hal-tinyusb.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#if CONFIG_TINYUSB_MIDI_ENABLED
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MIDI_EP_HEADER_CN_GET(x) (x >> 4)
|
||||
#define MIDI_EP_HEADER_CIN_GET(x) ((midi_code_index_number_t)((x) & 0xF))
|
||||
|
||||
typedef struct {
|
||||
uint8_t header;
|
||||
uint8_t byte1;
|
||||
uint8_t byte2;
|
||||
uint8_t byte3;
|
||||
} midiEventPacket_t;
|
||||
|
||||
class USBMIDI {
|
||||
private:
|
||||
static char *midiUserDeviceName; // user device name
|
||||
static void setDeviceName(const char *name); // set user device name limited to 32 characters
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor
|
||||
* Will use the compile-time name if set via SET_USB_MIDI_DEVICE_NAME(),
|
||||
* otherwise uses "TinyUSB MIDI"
|
||||
*/
|
||||
USBMIDI(void);
|
||||
|
||||
/**
|
||||
* @brief Set the current device name
|
||||
* 1. Name set via constructor (if any)
|
||||
* 2. Name set via SET_USB_MIDI_DEVICE_NAME() macro (if defined)
|
||||
* 3. Default name "TinyUSB MIDI"
|
||||
* It has no effect if name is set as NULL or ""
|
||||
*/
|
||||
USBMIDI(const char *name);
|
||||
|
||||
~USBMIDI();
|
||||
|
||||
void begin(void);
|
||||
void end(void);
|
||||
|
||||
/**
|
||||
* @brief Get the current device name
|
||||
* @return The device name in order of precedence:
|
||||
* 1. Name set via constructor (if any)
|
||||
* 2. Name set via SET_USB_MIDI_DEVICE_NAME() macro (if defined)
|
||||
* 3. Default name "TinyUSB MIDI"
|
||||
*/
|
||||
static const char *getCurrentDeviceName(void);
|
||||
|
||||
/* User-level API */
|
||||
|
||||
// Note On
|
||||
void noteOn(uint8_t note, uint8_t velocity = 0, uint8_t channel = 1);
|
||||
// Note Off
|
||||
void noteOff(uint8_t note, uint8_t velocity = 0, uint8_t channel = 1);
|
||||
// Program Change
|
||||
void programChange(uint8_t inProgramNumber, uint8_t channel = 1);
|
||||
// Control Change (Continuous Controller)
|
||||
void controlChange(uint8_t inControlNumber, uint8_t inControlValue = 0, uint8_t channel = 1);
|
||||
// Polyphonic Key Pressure (Aftertouch)
|
||||
void polyPressure(uint8_t note, uint8_t pressure, uint8_t channel = 1);
|
||||
// Channel Pressure (Aftertouch)
|
||||
void channelPressure(uint8_t pressure, uint8_t channel = 1);
|
||||
// Pitch Bend Change [-8192,0,8191]
|
||||
void pitchBend(int16_t pitchBendValue, uint8_t channel = 1);
|
||||
// Pitch Bend Change [0,8192,16383]
|
||||
void pitchBend(uint16_t pitchBendValue, uint8_t channel = 1);
|
||||
// Pitch Bend Change [-1.0,0,1.0]
|
||||
void pitchBend(double pitchBendValue, uint8_t channel = 1);
|
||||
|
||||
/* USB MIDI 1.0 interface */
|
||||
|
||||
// Attempt to read a USB MIDI packet from the USB Bus
|
||||
bool readPacket(midiEventPacket_t *packet);
|
||||
// Attempt to write a USB MIDI packet to the USB Bus
|
||||
bool writePacket(midiEventPacket_t *packet);
|
||||
|
||||
/* Serial MIDI 1.0 interface */
|
||||
|
||||
// Write a Serial MIDI byte (status or data) to the USB Bus
|
||||
size_t write(uint8_t c);
|
||||
};
|
||||
|
||||
#endif /* CONFIG_TINYUSB_MIDI_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,222 @@
|
||||
// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "USBVendor.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#if CONFIG_TINYUSB_VENDOR_ENABLED
|
||||
|
||||
#include "esp32-hal-tinyusb.h"
|
||||
|
||||
ESP_EVENT_DEFINE_BASE(ARDUINO_USB_VENDOR_EVENTS);
|
||||
esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, TickType_t ticks_to_wait);
|
||||
esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg);
|
||||
|
||||
static USBVendor *_Vendor = NULL;
|
||||
static QueueHandle_t rx_queue = NULL;
|
||||
static uint16_t USB_VENDOR_ENDPOINT_SIZE = CFG_TUD_ENDOINT_SIZE;
|
||||
|
||||
uint16_t tusb_vendor_load_descriptor(uint8_t *dst, uint8_t *itf) {
|
||||
uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB Vendor");
|
||||
uint8_t ep_num = tinyusb_get_free_duplex_endpoint();
|
||||
TU_VERIFY(ep_num != 0);
|
||||
uint8_t descriptor[TUD_VENDOR_DESC_LEN] = {// Interface number, string index, EP Out & IN address, EP size
|
||||
TUD_VENDOR_DESCRIPTOR(*itf, str_index, ep_num, (uint8_t)(0x80 | ep_num), USB_VENDOR_ENDPOINT_SIZE)
|
||||
};
|
||||
*itf += 1;
|
||||
memcpy(dst, descriptor, TUD_VENDOR_DESC_LEN);
|
||||
return TUD_VENDOR_DESC_LEN;
|
||||
}
|
||||
|
||||
void tud_vendor_rx_cb(uint8_t itf) {
|
||||
size_t len = tud_vendor_n_available(itf);
|
||||
log_v("%u", len);
|
||||
if (len) {
|
||||
uint8_t buffer[len];
|
||||
len = tud_vendor_n_read(itf, buffer, len);
|
||||
log_buf_v(buffer, len);
|
||||
if (_Vendor) {
|
||||
_Vendor->_onRX(buffer, len);
|
||||
}
|
||||
} else {
|
||||
if (_Vendor) {
|
||||
_Vendor->_onRX(NULL, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" bool tinyusb_vendor_control_request_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) {
|
||||
log_v(
|
||||
"Port: %u, Stage: %u, Direction: %u, Type: %u, Recipient: %u, bRequest: 0x%x, wValue: %u, wIndex: %u, wLength: %u", rhport, stage,
|
||||
request->bmRequestType_bit.direction, request->bmRequestType_bit.type, request->bmRequestType_bit.recipient, request->bRequest, request->wValue,
|
||||
request->wIndex, request->wLength
|
||||
);
|
||||
|
||||
if (_Vendor) {
|
||||
return _Vendor->_onRequest(rhport, stage, (arduino_usb_control_request_t const *)request);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
USBVendor::USBVendor(uint16_t endpoint_size) : itf(0), cb(NULL) {
|
||||
if (!_Vendor) {
|
||||
_Vendor = this;
|
||||
if (endpoint_size == 0) {
|
||||
endpoint_size = CFG_TUD_ENDOINT_SIZE;
|
||||
}
|
||||
if (endpoint_size <= CFG_TUD_ENDOINT_SIZE) {
|
||||
USB_VENDOR_ENDPOINT_SIZE = endpoint_size;
|
||||
}
|
||||
tinyusb_enable_interface(USB_INTERFACE_VENDOR, TUD_VENDOR_DESC_LEN, tusb_vendor_load_descriptor);
|
||||
} else {
|
||||
itf = _Vendor->itf;
|
||||
cb = _Vendor->cb;
|
||||
}
|
||||
}
|
||||
|
||||
size_t USBVendor::setRxBufferSize(size_t rx_queue_len) {
|
||||
if (rx_queue) {
|
||||
if (!rx_queue_len) {
|
||||
vQueueDelete(rx_queue);
|
||||
rx_queue = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t));
|
||||
if (!rx_queue) {
|
||||
return 0;
|
||||
}
|
||||
return rx_queue_len;
|
||||
}
|
||||
|
||||
void USBVendor::begin() {
|
||||
setRxBufferSize(512); //default if not preset
|
||||
}
|
||||
|
||||
void USBVendor::end() {
|
||||
setRxBufferSize(0);
|
||||
}
|
||||
|
||||
void USBVendor::onEvent(esp_event_handler_t callback) {
|
||||
onEvent(ARDUINO_USB_VENDOR_ANY_EVENT, callback);
|
||||
}
|
||||
|
||||
void USBVendor::onEvent(arduino_usb_vendor_event_t event, esp_event_handler_t callback) {
|
||||
arduino_usb_event_handler_register_with(ARDUINO_USB_VENDOR_EVENTS, event, callback, this);
|
||||
}
|
||||
|
||||
bool USBVendor::mounted() {
|
||||
return tud_vendor_n_mounted(itf);
|
||||
}
|
||||
|
||||
bool USBVendor::sendResponse(uint8_t rhport, arduino_usb_control_request_t const *request, void *data, size_t len) {
|
||||
if (!request) {
|
||||
return false;
|
||||
}
|
||||
if (!data || !len) {
|
||||
return tud_control_status(rhport, (tusb_control_request_t const *)request);
|
||||
} else {
|
||||
return tud_control_xfer(rhport, (tusb_control_request_t const *)request, data, len);
|
||||
}
|
||||
}
|
||||
|
||||
void USBVendor::onRequest(arduino_usb_vendor_control_request_handler_t handler) {
|
||||
cb = handler;
|
||||
}
|
||||
|
||||
bool USBVendor::_onRequest(uint8_t rhport, uint8_t stage, arduino_usb_control_request_t const *request) {
|
||||
if (cb) {
|
||||
return cb(rhport, stage, request);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void USBVendor::_onRX(const uint8_t *buffer, size_t len) {
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
if (rx_queue == NULL || !xQueueSend(rx_queue, buffer + i, 0)) {
|
||||
len = i + 1;
|
||||
log_e("RX Queue Overflow");
|
||||
break;
|
||||
}
|
||||
}
|
||||
arduino_usb_vendor_event_data_t p;
|
||||
p.data.len = len;
|
||||
arduino_usb_event_post(ARDUINO_USB_VENDOR_EVENTS, ARDUINO_USB_VENDOR_DATA_EVENT, &p, sizeof(arduino_usb_vendor_event_data_t), portMAX_DELAY);
|
||||
}
|
||||
|
||||
size_t USBVendor::write(const uint8_t *buffer, size_t len) {
|
||||
if (!mounted()) {
|
||||
log_e("not mounted");
|
||||
return 0;
|
||||
}
|
||||
size_t max_len = tud_vendor_n_write_available(itf);
|
||||
if (len > max_len) {
|
||||
len = max_len;
|
||||
}
|
||||
if (len) {
|
||||
return tud_vendor_n_write(itf, buffer, len);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t USBVendor::write(uint8_t c) {
|
||||
return write(&c, 1);
|
||||
}
|
||||
|
||||
int USBVendor::available(void) {
|
||||
if (rx_queue == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return uxQueueMessagesWaiting(rx_queue);
|
||||
}
|
||||
|
||||
int USBVendor::peek(void) {
|
||||
if (rx_queue == NULL) {
|
||||
return -1;
|
||||
}
|
||||
uint8_t c;
|
||||
if (xQueuePeek(rx_queue, &c, 0)) {
|
||||
return c;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int USBVendor::read(void) {
|
||||
if (rx_queue == NULL) {
|
||||
return -1;
|
||||
}
|
||||
uint8_t c = 0;
|
||||
if (xQueueReceive(rx_queue, &c, 0)) {
|
||||
return c;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t USBVendor::read(uint8_t *buffer, size_t size) {
|
||||
if (rx_queue == NULL) {
|
||||
return -1;
|
||||
}
|
||||
uint8_t c = 0;
|
||||
size_t count = 0;
|
||||
while (count < size && xQueueReceive(rx_queue, &c, 0)) {
|
||||
buffer[count++] = c;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void USBVendor::flush(void) {
|
||||
tud_vendor_n_write_flush(itf);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_TINYUSB_VENDOR_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,100 @@
|
||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#if SOC_USB_OTG_SUPPORTED
|
||||
|
||||
#include "Stream.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#if CONFIG_TINYUSB_VENDOR_ENABLED
|
||||
#include "esp_event.h"
|
||||
|
||||
ESP_EVENT_DECLARE_BASE(ARDUINO_USB_VENDOR_EVENTS);
|
||||
|
||||
#define REQUEST_STAGE_SETUP 0
|
||||
#define REQUEST_STAGE_DATA 1
|
||||
#define REQUEST_STAGE_ACK 2
|
||||
|
||||
#define REQUEST_TYPE_STANDARD 0
|
||||
#define REQUEST_TYPE_CLASS 1
|
||||
#define REQUEST_TYPE_VENDOR 2
|
||||
#define REQUEST_TYPE_INVALID 3
|
||||
|
||||
#define REQUEST_RECIPIENT_DEVICE 0
|
||||
#define REQUEST_RECIPIENT_INTERFACE 1
|
||||
#define REQUEST_RECIPIENT_ENDPOINT 2
|
||||
#define REQUEST_RECIPIENT_OTHER 3
|
||||
|
||||
#define REQUEST_DIRECTION_OUT 0
|
||||
#define REQUEST_DIRECTION_IN 1
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
struct __attribute__((packed)) {
|
||||
uint8_t bmRequestRecipient : 5;
|
||||
uint8_t bmRequestType : 2;
|
||||
uint8_t bmRequestDirection : 1;
|
||||
};
|
||||
uint8_t bRequest;
|
||||
uint16_t wValue;
|
||||
uint16_t wIndex;
|
||||
uint16_t wLength;
|
||||
} arduino_usb_control_request_t;
|
||||
|
||||
typedef enum {
|
||||
ARDUINO_USB_VENDOR_ANY_EVENT = ESP_EVENT_ANY_ID,
|
||||
ARDUINO_USB_VENDOR_DATA_EVENT,
|
||||
ARDUINO_USB_VENDOR_MAX_EVENT,
|
||||
} arduino_usb_vendor_event_t;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint16_t len;
|
||||
} data;
|
||||
} arduino_usb_vendor_event_data_t;
|
||||
|
||||
typedef bool (*arduino_usb_vendor_control_request_handler_t)(uint8_t rhport, uint8_t stage, arduino_usb_control_request_t const *request);
|
||||
|
||||
class USBVendor : public Stream {
|
||||
private:
|
||||
uint8_t itf;
|
||||
arduino_usb_vendor_control_request_handler_t cb;
|
||||
|
||||
public:
|
||||
USBVendor(uint16_t endpoint_size = 0);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
size_t setRxBufferSize(size_t);
|
||||
bool mounted(void);
|
||||
size_t write(const uint8_t *buffer, size_t len);
|
||||
size_t write(uint8_t);
|
||||
int available(void);
|
||||
int peek(void);
|
||||
int read(void);
|
||||
size_t read(uint8_t *buffer, size_t size);
|
||||
void flush(void);
|
||||
|
||||
void onEvent(esp_event_handler_t callback);
|
||||
void onEvent(arduino_usb_vendor_event_t event, esp_event_handler_t callback);
|
||||
void onRequest(arduino_usb_vendor_control_request_handler_t handler);
|
||||
bool sendResponse(uint8_t rhport, arduino_usb_control_request_t const *request, void *data = NULL, size_t len = 0);
|
||||
|
||||
bool _onRequest(uint8_t rhport, uint8_t stage, arduino_usb_control_request_t const *request);
|
||||
void _onRX(const uint8_t *buffer, size_t len);
|
||||
};
|
||||
|
||||
#endif /* CONFIG_TINYUSB_VENDOR_ENABLED */
|
||||
#endif /* SOC_USB_OTG_SUPPORTED */
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
KeyboardLayout.h
|
||||
|
||||
This file is not part of the public API. It is meant to be included
|
||||
only in Keyboard.cpp and the keyboard layout files. Layout files map
|
||||
ASCII character codes to keyboard scan codes (technically, to USB HID
|
||||
Usage codes), possibly altered by the SHIFT or ALT_GR modifiers.
|
||||
Non-ASCII characters (anything outside the 7-bit range NUL..DEL) are
|
||||
not supported.
|
||||
|
||||
== Creating your own layout ==
|
||||
|
||||
In order to create your own layout file, copy an existing layout that
|
||||
is similar to yours, then modify it to use the correct keys. The
|
||||
layout is an array in ASCII order. Each entry contains a scan code,
|
||||
possibly modified by "|SHIFT" or "|ALT_GR", as in this excerpt from
|
||||
the Italian layout:
|
||||
|
||||
0x35, // bslash
|
||||
0x30|ALT_GR, // ]
|
||||
0x2e|SHIFT, // ^
|
||||
|
||||
Do not change the control characters (those before scan code 0x2c,
|
||||
corresponding to space). Do not attempt to grow the table past DEL. Do
|
||||
not use both SHIFT and ALT_GR on the same character: this is not
|
||||
supported. Unsupported characters should have 0x00 as scan code.
|
||||
|
||||
For a keyboard with an ISO physical layout, use the scan codes below:
|
||||
|
||||
+---+---+---+---+---+---+---+---+---+---+---+---+---+-------+
|
||||
|35 |1e |1f |20 |21 |22 |23 |24 |25 |26 |27 |2d |2e |BackSp |
|
||||
+---+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-----+
|
||||
| Tab |14 |1a |08 |15 |17 |1c |18 |0c |12 |13 |2f |30 | Ret |
|
||||
+-----++--++--++--++--++--++--++--++--++--++--++--++--++ |
|
||||
|CapsL |04 |16 |07 |09 |0a |0b |0d |0e |0f |33 |34 |31 | |
|
||||
+----+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+---+----+
|
||||
|Shi.|32 |1d |1b |06 |19 |05 |11 |10 |36 |37 |38 | Shift |
|
||||
+----+---++--+-+-+---+---+---+---+---+--++---+---++----+----+
|
||||
|Ctrl|Win |Alt | |AlGr|Win |Menu|Ctrl|
|
||||
+----+----+----+------------------------+----+----+----+----+
|
||||
|
||||
The ANSI layout is identical except that key 0x31 is above (rather
|
||||
than next to) Return, and there is not key 0x32.
|
||||
|
||||
Give a unique name to the layout array, then declare it in Keyboard.h
|
||||
with a line of the form:
|
||||
|
||||
extern const uint8_t KeyboardLayout_xx_YY[];
|
||||
|
||||
== Encoding details ==
|
||||
|
||||
All scan codes are less than 0x80, which makes bit 7 available to
|
||||
signal that a modifier (Shift or AltGr) is needed to generate the
|
||||
character. With only one exception, keys that are used with modifiers
|
||||
have scan codes that are less than 0x40. This makes bit 6 available
|
||||
to signal whether the modifier is Shift or AltGr. The exception is
|
||||
0x64, the key next next to Left Shift on the ISO layout (and absent
|
||||
from the ANSI layout). We handle it by replacing its value by 0x32 in
|
||||
the layout arrays.
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
// Modifier keys for _asciimap[] table (not to be used directly)
|
||||
#define SHIFT 0x80
|
||||
#define ALT_GR 0x40
|
||||
#define ISO_KEY 0x64
|
||||
#define ISO_REPLACEMENT 0x32
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Danish keyboard layout.
|
||||
*/
|
||||
|
||||
#include "KeyboardLayout.h"
|
||||
|
||||
extern const uint8_t KeyboardLayout_da_DK[128] = {
|
||||
0x00, // NUL
|
||||
0x00, // SOH
|
||||
0x00, // STX
|
||||
0x00, // ETX
|
||||
0x00, // EOT
|
||||
0x00, // ENQ
|
||||
0x00, // ACK
|
||||
0x00, // BEL
|
||||
0x2a, // BS Backspace
|
||||
0x2b, // TAB Tab
|
||||
0x28, // LF Enter
|
||||
0x00, // VT
|
||||
0x00, // FF
|
||||
0x00, // CR
|
||||
0x00, // SO
|
||||
0x00, // SI
|
||||
0x00, // DEL
|
||||
0x00, // DC1
|
||||
0x00, // DC2
|
||||
0x00, // DC3
|
||||
0x00, // DC4
|
||||
0x00, // NAK
|
||||
0x00, // SYN
|
||||
0x00, // ETB
|
||||
0x00, // CAN
|
||||
0x00, // EM
|
||||
0x00, // SUB
|
||||
0x00, // ESC
|
||||
0x00, // FS
|
||||
0x00, // GS
|
||||
0x00, // RS
|
||||
0x00, // US
|
||||
|
||||
0x2c, // ' '
|
||||
0x1e | SHIFT, // !
|
||||
0x1f | SHIFT, // "
|
||||
0x20 | SHIFT, // #
|
||||
0x21 | ALT_GR, // $
|
||||
0x22 | SHIFT, // %
|
||||
0x23 | SHIFT, // &
|
||||
0x31, // '
|
||||
0x25 | SHIFT, // (
|
||||
0x26 | SHIFT, // )
|
||||
0x31 | SHIFT, // *
|
||||
0x2d, // +
|
||||
0x36, // ,
|
||||
0x38, // -
|
||||
0x37, // .
|
||||
0x24 | SHIFT, // /
|
||||
0x27, // 0
|
||||
0x1e, // 1
|
||||
0x1f, // 2
|
||||
0x20, // 3
|
||||
0x21, // 4
|
||||
0x22, // 5
|
||||
0x23, // 6
|
||||
0x24, // 7
|
||||
0x25, // 8
|
||||
0x26, // 9
|
||||
0x37 | SHIFT, // :
|
||||
0x36 | SHIFT, // ;
|
||||
0x32, // <
|
||||
0x27 | SHIFT, // =
|
||||
0x32 | SHIFT, // >
|
||||
0x2d | SHIFT, // ?
|
||||
0x1f | ALT_GR, // @
|
||||
0x04 | SHIFT, // A
|
||||
0x05 | SHIFT, // B
|
||||
0x06 | SHIFT, // C
|
||||
0x07 | SHIFT, // D
|
||||
0x08 | SHIFT, // E
|
||||
0x09 | SHIFT, // F
|
||||
0x0a | SHIFT, // G
|
||||
0x0b | SHIFT, // H
|
||||
0x0c | SHIFT, // I
|
||||
0x0d | SHIFT, // J
|
||||
0x0e | SHIFT, // K
|
||||
0x0f | SHIFT, // L
|
||||
0x10 | SHIFT, // M
|
||||
0x11 | SHIFT, // N
|
||||
0x12 | SHIFT, // O
|
||||
0x13 | SHIFT, // P
|
||||
0x14 | SHIFT, // Q
|
||||
0x15 | SHIFT, // R
|
||||
0x16 | SHIFT, // S
|
||||
0x17 | SHIFT, // T
|
||||
0x18 | SHIFT, // U
|
||||
0x19 | SHIFT, // V
|
||||
0x1a | SHIFT, // W
|
||||
0x1b | SHIFT, // X
|
||||
0x1c | SHIFT, // Y
|
||||
0x1d | SHIFT, // Z
|
||||
0x25 | ALT_GR, // [
|
||||
0x32 | ALT_GR, // bslash
|
||||
0x26 | ALT_GR, // ]
|
||||
0x00, // ^ not supported (requires dead key + space)
|
||||
0x38 | SHIFT, // _
|
||||
0x00, // ` not supported (requires dead key + space)
|
||||
0x04, // a
|
||||
0x05, // b
|
||||
0x06, // c
|
||||
0x07, // d
|
||||
0x08, // e
|
||||
0x09, // f
|
||||
0x0a, // g
|
||||
0x0b, // h
|
||||
0x0c, // i
|
||||
0x0d, // j
|
||||
0x0e, // k
|
||||
0x0f, // l
|
||||
0x10, // m
|
||||
0x11, // n
|
||||
0x12, // o
|
||||
0x13, // p
|
||||
0x14, // q
|
||||
0x15, // r
|
||||
0x16, // s
|
||||
0x17, // t
|
||||
0x18, // u
|
||||
0x19, // v
|
||||
0x1a, // w
|
||||
0x1b, // x
|
||||
0x1c, // y
|
||||
0x1d, // z
|
||||
0x24 | ALT_GR, // {
|
||||
0x2e | ALT_GR, // |
|
||||
0x27 | ALT_GR, // }
|
||||
0x00, // ~ not supported (requires dead key + space)
|
||||
0x00 // DEL
|
||||
};
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* German keyboard layout.
|
||||
*/
|
||||
|
||||
#include "KeyboardLayout.h"
|
||||
|
||||
extern const uint8_t KeyboardLayout_de_DE[128] PROGMEM = {
|
||||
0x00, // NUL
|
||||
0x00, // SOH
|
||||
0x00, // STX
|
||||
0x00, // ETX
|
||||
0x00, // EOT
|
||||
0x00, // ENQ
|
||||
0x00, // ACK
|
||||
0x00, // BEL
|
||||
0x2a, // BS Backspace
|
||||
0x2b, // TAB Tab
|
||||
0x28, // LF Enter
|
||||
0x00, // VT
|
||||
0x00, // FF
|
||||
0x00, // CR
|
||||
0x00, // SO
|
||||
0x00, // SI
|
||||
0x00, // DEL
|
||||
0x00, // DC1
|
||||
0x00, // DC2
|
||||
0x00, // DC3
|
||||
0x00, // DC4
|
||||
0x00, // NAK
|
||||
0x00, // SYN
|
||||
0x00, // ETB
|
||||
0x00, // CAN
|
||||
0x00, // EM
|
||||
0x00, // SUB
|
||||
0x00, // ESC
|
||||
0x00, // FS
|
||||
0x00, // GS
|
||||
0x00, // RS
|
||||
0x00, // US
|
||||
|
||||
0x2c, // ' '
|
||||
0x1e | SHIFT, // !
|
||||
0x1f | SHIFT, // "
|
||||
0x31, // #
|
||||
0x21 | SHIFT, // $
|
||||
0x22 | SHIFT, // %
|
||||
0x23 | SHIFT, // &
|
||||
0x31 | SHIFT, // '
|
||||
0x25 | SHIFT, // (
|
||||
0x26 | SHIFT, // )
|
||||
0x30 | SHIFT, // *
|
||||
0x30, // +
|
||||
0x36, // ,
|
||||
0x38, // -
|
||||
0x37, // .
|
||||
0x24 | SHIFT, // /
|
||||
0x27, // 0
|
||||
0x1e, // 1
|
||||
0x1f, // 2
|
||||
0x20, // 3
|
||||
0x21, // 4
|
||||
0x22, // 5
|
||||
0x23, // 6
|
||||
0x24, // 7
|
||||
0x25, // 8
|
||||
0x26, // 9
|
||||
0x37 | SHIFT, // :
|
||||
0x36 | SHIFT, // ;
|
||||
0x32, // <
|
||||
0x27 | SHIFT, // =
|
||||
0x32 | SHIFT, // >
|
||||
0x2d | SHIFT, // ?
|
||||
0x14 | ALT_GR, // @
|
||||
0x04 | SHIFT, // A
|
||||
0x05 | SHIFT, // B
|
||||
0x06 | SHIFT, // C
|
||||
0x07 | SHIFT, // D
|
||||
0x08 | SHIFT, // E
|
||||
0x09 | SHIFT, // F
|
||||
0x0a | SHIFT, // G
|
||||
0x0b | SHIFT, // H
|
||||
0x0c | SHIFT, // I
|
||||
0x0d | SHIFT, // J
|
||||
0x0e | SHIFT, // K
|
||||
0x0f | SHIFT, // L
|
||||
0x10 | SHIFT, // M
|
||||
0x11 | SHIFT, // N
|
||||
0x12 | SHIFT, // O
|
||||
0x13 | SHIFT, // P
|
||||
0x14 | SHIFT, // Q
|
||||
0x15 | SHIFT, // R
|
||||
0x16 | SHIFT, // S
|
||||
0x17 | SHIFT, // T
|
||||
0x18 | SHIFT, // U
|
||||
0x19 | SHIFT, // V
|
||||
0x1a | SHIFT, // W
|
||||
0x1b | SHIFT, // X
|
||||
0x1d | SHIFT, // Y
|
||||
0x1c | SHIFT, // Z
|
||||
0x25 | ALT_GR, // [
|
||||
0x2d | ALT_GR, // bslash
|
||||
0x26 | ALT_GR, // ]
|
||||
0x00, // ^ not supported (requires dead key + space)
|
||||
0x38 | SHIFT, // _
|
||||
0x00, // ` not supported (requires dead key + space)
|
||||
0x04, // a
|
||||
0x05, // b
|
||||
0x06, // c
|
||||
0x07, // d
|
||||
0x08, // e
|
||||
0x09, // f
|
||||
0x0a, // g
|
||||
0x0b, // h
|
||||
0x0c, // i
|
||||
0x0d, // j
|
||||
0x0e, // k
|
||||
0x0f, // l
|
||||
0x10, // m
|
||||
0x11, // n
|
||||
0x12, // o
|
||||
0x13, // p
|
||||
0x14, // q
|
||||
0x15, // r
|
||||
0x16, // s
|
||||
0x17, // t
|
||||
0x18, // u
|
||||
0x19, // v
|
||||
0x1a, // w
|
||||
0x1b, // x
|
||||
0x1d, // y
|
||||
0x1c, // z
|
||||
0x24 | ALT_GR, // {
|
||||
0x32 | ALT_GR, // |
|
||||
0x27 | ALT_GR, // }
|
||||
0x30 | ALT_GR, // ~
|
||||
0x00 // DEL
|
||||
};
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Standard US keyboard layout.
|
||||
*/
|
||||
|
||||
#include "KeyboardLayout.h"
|
||||
|
||||
extern const uint8_t KeyboardLayout_en_US[128] PROGMEM = {
|
||||
0x00, // NUL
|
||||
0x00, // SOH
|
||||
0x00, // STX
|
||||
0x00, // ETX
|
||||
0x00, // EOT
|
||||
0x00, // ENQ
|
||||
0x00, // ACK
|
||||
0x00, // BEL
|
||||
0x2a, // BS Backspace
|
||||
0x2b, // TAB Tab
|
||||
0x28, // LF Enter
|
||||
0x00, // VT
|
||||
0x00, // FF
|
||||
0x00, // CR
|
||||
0x00, // SO
|
||||
0x00, // SI
|
||||
0x00, // DEL
|
||||
0x00, // DC1
|
||||
0x00, // DC2
|
||||
0x00, // DC3
|
||||
0x00, // DC4
|
||||
0x00, // NAK
|
||||
0x00, // SYN
|
||||
0x00, // ETB
|
||||
0x00, // CAN
|
||||
0x00, // EM
|
||||
0x00, // SUB
|
||||
0x00, // ESC
|
||||
0x00, // FS
|
||||
0x00, // GS
|
||||
0x00, // RS
|
||||
0x00, // US
|
||||
|
||||
0x2c, // ' '
|
||||
0x1e | SHIFT, // !
|
||||
0x34 | SHIFT, // "
|
||||
0x20 | SHIFT, // #
|
||||
0x21 | SHIFT, // $
|
||||
0x22 | SHIFT, // %
|
||||
0x24 | SHIFT, // &
|
||||
0x34, // '
|
||||
0x26 | SHIFT, // (
|
||||
0x27 | SHIFT, // )
|
||||
0x25 | SHIFT, // *
|
||||
0x2e | SHIFT, // +
|
||||
0x36, // ,
|
||||
0x2d, // -
|
||||
0x37, // .
|
||||
0x38, // /
|
||||
0x27, // 0
|
||||
0x1e, // 1
|
||||
0x1f, // 2
|
||||
0x20, // 3
|
||||
0x21, // 4
|
||||
0x22, // 5
|
||||
0x23, // 6
|
||||
0x24, // 7
|
||||
0x25, // 8
|
||||
0x26, // 9
|
||||
0x33 | SHIFT, // :
|
||||
0x33, // ;
|
||||
0x36 | SHIFT, // <
|
||||
0x2e, // =
|
||||
0x37 | SHIFT, // >
|
||||
0x38 | SHIFT, // ?
|
||||
0x1f | SHIFT, // @
|
||||
0x04 | SHIFT, // A
|
||||
0x05 | SHIFT, // B
|
||||
0x06 | SHIFT, // C
|
||||
0x07 | SHIFT, // D
|
||||
0x08 | SHIFT, // E
|
||||
0x09 | SHIFT, // F
|
||||
0x0a | SHIFT, // G
|
||||
0x0b | SHIFT, // H
|
||||
0x0c | SHIFT, // I
|
||||
0x0d | SHIFT, // J
|
||||
0x0e | SHIFT, // K
|
||||
0x0f | SHIFT, // L
|
||||
0x10 | SHIFT, // M
|
||||
0x11 | SHIFT, // N
|
||||
0x12 | SHIFT, // O
|
||||
0x13 | SHIFT, // P
|
||||
0x14 | SHIFT, // Q
|
||||
0x15 | SHIFT, // R
|
||||
0x16 | SHIFT, // S
|
||||
0x17 | SHIFT, // T
|
||||
0x18 | SHIFT, // U
|
||||
0x19 | SHIFT, // V
|
||||
0x1a | SHIFT, // W
|
||||
0x1b | SHIFT, // X
|
||||
0x1c | SHIFT, // Y
|
||||
0x1d | SHIFT, // Z
|
||||
0x2f, // [
|
||||
0x31, // bslash
|
||||
0x30, // ]
|
||||
0x23 | SHIFT, // ^
|
||||
0x2d | SHIFT, // _
|
||||
0x35, // `
|
||||
0x04, // a
|
||||
0x05, // b
|
||||
0x06, // c
|
||||
0x07, // d
|
||||
0x08, // e
|
||||
0x09, // f
|
||||
0x0a, // g
|
||||
0x0b, // h
|
||||
0x0c, // i
|
||||
0x0d, // j
|
||||
0x0e, // k
|
||||
0x0f, // l
|
||||
0x10, // m
|
||||
0x11, // n
|
||||
0x12, // o
|
||||
0x13, // p
|
||||
0x14, // q
|
||||
0x15, // r
|
||||
0x16, // s
|
||||
0x17, // t
|
||||
0x18, // u
|
||||
0x19, // v
|
||||
0x1a, // w
|
||||
0x1b, // x
|
||||
0x1c, // y
|
||||
0x1d, // z
|
||||
0x2f | SHIFT, // {
|
||||
0x31 | SHIFT, // |
|
||||
0x30 | SHIFT, // }
|
||||
0x35 | SHIFT, // ~
|
||||
0x00 // DEL
|
||||
};
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Spanish keyboard layout.
|
||||
*/
|
||||
|
||||
#include "KeyboardLayout.h"
|
||||
|
||||
extern const uint8_t KeyboardLayout_es_ES[128] PROGMEM = {
|
||||
0x00, // NUL
|
||||
0x00, // SOH
|
||||
0x00, // STX
|
||||
0x00, // ETX
|
||||
0x00, // EOT
|
||||
0x00, // ENQ
|
||||
0x00, // ACK
|
||||
0x00, // BEL
|
||||
0x2a, // BS Backspace
|
||||
0x2b, // TAB Tab
|
||||
0x28, // LF Enter
|
||||
0x00, // VT
|
||||
0x00, // FF
|
||||
0x00, // CR
|
||||
0x00, // SO
|
||||
0x00, // SI
|
||||
0x00, // DEL
|
||||
0x00, // DC1
|
||||
0x00, // DC2
|
||||
0x00, // DC3
|
||||
0x00, // DC4
|
||||
0x00, // NAK
|
||||
0x00, // SYN
|
||||
0x00, // ETB
|
||||
0x00, // CAN
|
||||
0x00, // EM
|
||||
0x00, // SUB
|
||||
0x00, // ESC
|
||||
0x00, // FS
|
||||
0x00, // GS
|
||||
0x00, // RS
|
||||
0x00, // US
|
||||
|
||||
0x2c, // ' '
|
||||
0x1e | SHIFT, // !
|
||||
0x1f | SHIFT, // "
|
||||
0x20 | ALT_GR, // #
|
||||
0x21 | SHIFT, // $
|
||||
0x22 | SHIFT, // %
|
||||
0x23 | SHIFT, // &
|
||||
0x2d, // '
|
||||
0x25 | SHIFT, // (
|
||||
0x26 | SHIFT, // )
|
||||
0x30 | SHIFT, // *
|
||||
0x30, // +
|
||||
0x36, // ,
|
||||
0x38, // -
|
||||
0x37, // .
|
||||
0x24 | SHIFT, // /
|
||||
0x27, // 0
|
||||
0x1e, // 1
|
||||
0x1f, // 2
|
||||
0x20, // 3
|
||||
0x21, // 4
|
||||
0x22, // 5
|
||||
0x23, // 6
|
||||
0x24, // 7
|
||||
0x25, // 8
|
||||
0x26, // 9
|
||||
0x37 | SHIFT, // :
|
||||
0x36 | SHIFT, // ;
|
||||
0x32, // <
|
||||
0x27 | SHIFT, // =
|
||||
0x32 | SHIFT, // >
|
||||
0x2d | SHIFT, // ?
|
||||
0x1f | ALT_GR, // @
|
||||
0x04 | SHIFT, // A
|
||||
0x05 | SHIFT, // B
|
||||
0x06 | SHIFT, // C
|
||||
0x07 | SHIFT, // D
|
||||
0x08 | SHIFT, // E
|
||||
0x09 | SHIFT, // F
|
||||
0x0a | SHIFT, // G
|
||||
0x0b | SHIFT, // H
|
||||
0x0c | SHIFT, // I
|
||||
0x0d | SHIFT, // J
|
||||
0x0e | SHIFT, // K
|
||||
0x0f | SHIFT, // L
|
||||
0x10 | SHIFT, // M
|
||||
0x11 | SHIFT, // N
|
||||
0x12 | SHIFT, // O
|
||||
0x13 | SHIFT, // P
|
||||
0x14 | SHIFT, // Q
|
||||
0x15 | SHIFT, // R
|
||||
0x16 | SHIFT, // S
|
||||
0x17 | SHIFT, // T
|
||||
0x18 | SHIFT, // U
|
||||
0x19 | SHIFT, // V
|
||||
0x1a | SHIFT, // W
|
||||
0x1b | SHIFT, // X
|
||||
0x1c | SHIFT, // Y
|
||||
0x1d | SHIFT, // Z
|
||||
0x2f | ALT_GR, // [
|
||||
0x35 | ALT_GR, // bslash
|
||||
0x30 | ALT_GR, // ]
|
||||
0x00, // ^ not supported (requires dead key + space)
|
||||
0x38 | SHIFT, // _
|
||||
0x00, // ` not supported (requires dead key + space)
|
||||
0x04, // a
|
||||
0x05, // b
|
||||
0x06, // c
|
||||
0x07, // d
|
||||
0x08, // e
|
||||
0x09, // f
|
||||
0x0a, // g
|
||||
0x0b, // h
|
||||
0x0c, // i
|
||||
0x0d, // j
|
||||
0x0e, // k
|
||||
0x0f, // l
|
||||
0x10, // m
|
||||
0x11, // n
|
||||
0x12, // o
|
||||
0x13, // p
|
||||
0x14, // q
|
||||
0x15, // r
|
||||
0x16, // s
|
||||
0x17, // t
|
||||
0x18, // u
|
||||
0x19, // v
|
||||
0x1a, // w
|
||||
0x1b, // x
|
||||
0x1c, // y
|
||||
0x1d, // z
|
||||
0x34 | ALT_GR, // {
|
||||
0x1e | ALT_GR, // |
|
||||
0x31 | ALT_GR, // }
|
||||
0x00, // ~ not supported (requires dead key + space)
|
||||
0x00 // DEL
|
||||
};
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Traditional (not AFNOR) French keyboard layout.
|
||||
*/
|
||||
|
||||
#include "KeyboardLayout.h"
|
||||
|
||||
extern const uint8_t KeyboardLayout_fr_FR[128] PROGMEM = {
|
||||
0x00, // NUL
|
||||
0x00, // SOH
|
||||
0x00, // STX
|
||||
0x00, // ETX
|
||||
0x00, // EOT
|
||||
0x00, // ENQ
|
||||
0x00, // ACK
|
||||
0x00, // BEL
|
||||
0x2a, // BS Backspace
|
||||
0x2b, // TAB Tab
|
||||
0x28, // LF Enter
|
||||
0x00, // VT
|
||||
0x00, // FF
|
||||
0x00, // CR
|
||||
0x00, // SO
|
||||
0x00, // SI
|
||||
0x00, // DEL
|
||||
0x00, // DC1
|
||||
0x00, // DC2
|
||||
0x00, // DC3
|
||||
0x00, // DC4
|
||||
0x00, // NAK
|
||||
0x00, // SYN
|
||||
0x00, // ETB
|
||||
0x00, // CAN
|
||||
0x00, // EM
|
||||
0x00, // SUB
|
||||
0x00, // ESC
|
||||
0x00, // FS
|
||||
0x00, // GS
|
||||
0x00, // RS
|
||||
0x00, // US
|
||||
|
||||
0x2c, // ' '
|
||||
0x38, // !
|
||||
0x20, // "
|
||||
0x20 | ALT_GR, // #
|
||||
0x30, // $
|
||||
0x34 | SHIFT, // %
|
||||
0x1E, // &
|
||||
0x21, // '
|
||||
0x22, // (
|
||||
0x2d, // )
|
||||
0x31, // *
|
||||
0x2e | SHIFT, // +
|
||||
0x10, // ,
|
||||
0x23, // -
|
||||
0x36 | SHIFT, // .
|
||||
0x37 | SHIFT, // /
|
||||
0x27 | SHIFT, // 0
|
||||
0x1e | SHIFT, // 1
|
||||
0x1f | SHIFT, // 2
|
||||
0x20 | SHIFT, // 3
|
||||
0x21 | SHIFT, // 4
|
||||
0x22 | SHIFT, // 5
|
||||
0x23 | SHIFT, // 6
|
||||
0x24 | SHIFT, // 7
|
||||
0x25 | SHIFT, // 8
|
||||
0x26 | SHIFT, // 9
|
||||
0x37, // :
|
||||
0x36, // ;
|
||||
0x32, // <
|
||||
0x2e, // =
|
||||
0x32 | SHIFT, // >
|
||||
0x10 | SHIFT, // ?
|
||||
0x27 | ALT_GR, // @
|
||||
0x14 | SHIFT, // A
|
||||
0x05 | SHIFT, // B
|
||||
0x06 | SHIFT, // C
|
||||
0x07 | SHIFT, // D
|
||||
0x08 | SHIFT, // E
|
||||
0x09 | SHIFT, // F
|
||||
0x0a | SHIFT, // G
|
||||
0x0b | SHIFT, // H
|
||||
0x0c | SHIFT, // I
|
||||
0x0d | SHIFT, // J
|
||||
0x0e | SHIFT, // K
|
||||
0x0f | SHIFT, // L
|
||||
0x33 | SHIFT, // M
|
||||
0x11 | SHIFT, // N
|
||||
0x12 | SHIFT, // O
|
||||
0x13 | SHIFT, // P
|
||||
0x04 | SHIFT, // Q
|
||||
0x15 | SHIFT, // R
|
||||
0x16 | SHIFT, // S
|
||||
0x17 | SHIFT, // T
|
||||
0x18 | SHIFT, // U
|
||||
0x19 | SHIFT, // V
|
||||
0x1d | SHIFT, // W
|
||||
0x1b | SHIFT, // X
|
||||
0x1c | SHIFT, // Y
|
||||
0x1a | SHIFT, // Z
|
||||
0x22 | ALT_GR, // [
|
||||
0x25 | ALT_GR, // bslash
|
||||
0x2d | ALT_GR, // ]
|
||||
0x26 | ALT_GR, // ^
|
||||
0x25, // _
|
||||
0x24 | ALT_GR, // `
|
||||
0x14, // a
|
||||
0x05, // b
|
||||
0x06, // c
|
||||
0x07, // d
|
||||
0x08, // e
|
||||
0x09, // f
|
||||
0x0a, // g
|
||||
0x0b, // h
|
||||
0x0c, // i
|
||||
0x0d, // j
|
||||
0x0e, // k
|
||||
0x0f, // l
|
||||
0x33, // m
|
||||
0x11, // n
|
||||
0x12, // o
|
||||
0x13, // p
|
||||
0x04, // q
|
||||
0x15, // r
|
||||
0x16, // s
|
||||
0x17, // t
|
||||
0x18, // u
|
||||
0x19, // v
|
||||
0x1d, // w
|
||||
0x1b, // x
|
||||
0x1c, // y
|
||||
0x1a, // z
|
||||
0x21 | ALT_GR, // {
|
||||
0x23 | ALT_GR, // |
|
||||
0x2e | ALT_GR, // }
|
||||
0x1f | ALT_GR, // ~
|
||||
0x00 // DEL
|
||||
};
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Standard HU keyboard layout.
|
||||
*/
|
||||
|
||||
#include "KeyboardLayout.h"
|
||||
|
||||
extern const uint8_t KeyboardLayout_hu_HU[128] PROGMEM = {
|
||||
0x00, // NUL
|
||||
0x00, // SOH
|
||||
0x00, // STX
|
||||
0x00, // ETX
|
||||
0x00, // EOT
|
||||
0x00, // ENQ
|
||||
0x00, // ACK
|
||||
0x00, // BEL
|
||||
0x2a, // BS Backspace
|
||||
0x2b, // TAB Tab
|
||||
0x28, // LF Enter
|
||||
0x00, // VT
|
||||
0x00, // FF
|
||||
0x00, // CR
|
||||
0x00, // SO
|
||||
0x00, // SI
|
||||
0x00, // DEL
|
||||
0x00, // DC1
|
||||
0x00, // DC2
|
||||
0x00, // DC3
|
||||
0x00, // DC4
|
||||
0x00, // NAK
|
||||
0x00, // SYN
|
||||
0x00, // ETB
|
||||
0x00, // CAN
|
||||
0x00, // EM
|
||||
0x00, // SUB
|
||||
0x00, // ESC
|
||||
0x00, // FS
|
||||
0x00, // GS
|
||||
0x00, // RS
|
||||
0x00, // US
|
||||
|
||||
0x2c, // ' '
|
||||
0x21 | SHIFT, // !
|
||||
0x1f | SHIFT, // "
|
||||
0x1b | ALT_GR, // #
|
||||
0x33 | ALT_GR, // $
|
||||
0x22 | SHIFT, // %
|
||||
0x06 | ALT_GR, // &
|
||||
0x1e | SHIFT, // '
|
||||
0x25 | SHIFT, // (
|
||||
0x26 | SHIFT, // )
|
||||
0x38 | ALT_GR, // *
|
||||
0x20 | SHIFT, // +
|
||||
0x36, // ,
|
||||
0x38, // -
|
||||
0x37, // .
|
||||
0x23 | SHIFT, // /
|
||||
|
||||
0x35, // 0
|
||||
0x1e, // 1
|
||||
0x1f, // 2
|
||||
0x20, // 3
|
||||
0x21, // 4
|
||||
0x22, // 5
|
||||
0x23, // 6
|
||||
0x24, // 7
|
||||
0x25, // 8
|
||||
0x26, // 9
|
||||
|
||||
0x37 | SHIFT, // :
|
||||
0x36 | ALT_GR, // ;
|
||||
0x32 | ALT_GR, // <
|
||||
0x24 | SHIFT, // =
|
||||
0x1d | ALT_GR, // >
|
||||
0x36 | SHIFT, // ?
|
||||
0x19 | ALT_GR, // @
|
||||
|
||||
0x04 | SHIFT, // A
|
||||
0x05 | SHIFT, // B
|
||||
0x06 | SHIFT, // C
|
||||
0x07 | SHIFT, // D
|
||||
0x08 | SHIFT, // E
|
||||
0x09 | SHIFT, // F
|
||||
0x0a | SHIFT, // G
|
||||
0x0b | SHIFT, // H
|
||||
0x0c | SHIFT, // I
|
||||
0x0d | SHIFT, // J
|
||||
0x0e | SHIFT, // K
|
||||
0x0f | SHIFT, // L
|
||||
0x10 | SHIFT, // M
|
||||
0x11 | SHIFT, // N
|
||||
0x12 | SHIFT, // O
|
||||
0x13 | SHIFT, // P
|
||||
0x14 | SHIFT, // Q
|
||||
0x15 | SHIFT, // R
|
||||
0x16 | SHIFT, // S
|
||||
0x17 | SHIFT, // T
|
||||
0x18 | SHIFT, // U
|
||||
0x19 | SHIFT, // V
|
||||
0x1a | SHIFT, // W
|
||||
0x1b | SHIFT, // X
|
||||
0x1d | SHIFT, // Y
|
||||
0x1c | SHIFT, // Z
|
||||
|
||||
0x09 | ALT_GR, // [
|
||||
0x14 | ALT_GR, // bslash
|
||||
0x0a | ALT_GR, // ]
|
||||
0x20 | ALT_GR, // ^
|
||||
0x38 | SHIFT, // _
|
||||
0x24 | ALT_GR, // `
|
||||
|
||||
0x04, // a
|
||||
0x05, // b
|
||||
0x06, // c
|
||||
0x07, // d
|
||||
0x08, // e
|
||||
0x09, // f
|
||||
0x0a, // g
|
||||
0x0b, // h
|
||||
0x0c, // i
|
||||
0x0d, // j
|
||||
0x0e, // k
|
||||
0x0f, // l
|
||||
0x10, // m
|
||||
0x11, // n
|
||||
0x12, // o
|
||||
0x13, // p
|
||||
0x14, // q
|
||||
0x15, // r
|
||||
0x16, // s
|
||||
0x17, // t
|
||||
0x18, // u
|
||||
0x19, // v
|
||||
0x1a, // w
|
||||
0x1b, // x
|
||||
0x1d, // y
|
||||
0x1c, // z
|
||||
|
||||
0x05 | ALT_GR, // {
|
||||
0x1a | ALT_GR, // |
|
||||
0x11 | ALT_GR, // }
|
||||
0x1e | ALT_GR, // ~
|
||||
0x00 // DEL
|
||||
};
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Italian keyboard layout.
|
||||
*/
|
||||
|
||||
#include "KeyboardLayout.h"
|
||||
|
||||
extern const uint8_t KeyboardLayout_it_IT[128] PROGMEM = {
|
||||
0x00, // NUL
|
||||
0x00, // SOH
|
||||
0x00, // STX
|
||||
0x00, // ETX
|
||||
0x00, // EOT
|
||||
0x00, // ENQ
|
||||
0x00, // ACK
|
||||
0x00, // BEL
|
||||
0x2a, // BS Backspace
|
||||
0x2b, // TAB Tab
|
||||
0x28, // LF Enter
|
||||
0x00, // VT
|
||||
0x00, // FF
|
||||
0x00, // CR
|
||||
0x00, // SO
|
||||
0x00, // SI
|
||||
0x00, // DEL
|
||||
0x00, // DC1
|
||||
0x00, // DC2
|
||||
0x00, // DC3
|
||||
0x00, // DC4
|
||||
0x00, // NAK
|
||||
0x00, // SYN
|
||||
0x00, // ETB
|
||||
0x00, // CAN
|
||||
0x00, // EM
|
||||
0x00, // SUB
|
||||
0x00, // ESC
|
||||
0x00, // FS
|
||||
0x00, // GS
|
||||
0x00, // RS
|
||||
0x00, // US
|
||||
|
||||
0x2c, // ' '
|
||||
0x1e | SHIFT, // !
|
||||
0x1f | SHIFT, // "
|
||||
0x34 | ALT_GR, // #
|
||||
0x21 | SHIFT, // $
|
||||
0x22 | SHIFT, // %
|
||||
0x23 | SHIFT, // &
|
||||
0x2d, // '
|
||||
0x25 | SHIFT, // (
|
||||
0x26 | SHIFT, // )
|
||||
0x30 | SHIFT, // *
|
||||
0x30, // +
|
||||
0x36, // ,
|
||||
0x38, // -
|
||||
0x37, // .
|
||||
0x24 | SHIFT, // /
|
||||
0x27, // 0
|
||||
0x1e, // 1
|
||||
0x1f, // 2
|
||||
0x20, // 3
|
||||
0x21, // 4
|
||||
0x22, // 5
|
||||
0x23, // 6
|
||||
0x24, // 7
|
||||
0x25, // 8
|
||||
0x26, // 9
|
||||
0x37 | SHIFT, // :
|
||||
0x36 | SHIFT, // ;
|
||||
0x32, // <
|
||||
0x27 | SHIFT, // =
|
||||
0x32 | SHIFT, // >
|
||||
0x2d | SHIFT, // ?
|
||||
0x33 | ALT_GR, // @
|
||||
0x04 | SHIFT, // A
|
||||
0x05 | SHIFT, // B
|
||||
0x06 | SHIFT, // C
|
||||
0x07 | SHIFT, // D
|
||||
0x08 | SHIFT, // E
|
||||
0x09 | SHIFT, // F
|
||||
0x0a | SHIFT, // G
|
||||
0x0b | SHIFT, // H
|
||||
0x0c | SHIFT, // I
|
||||
0x0d | SHIFT, // J
|
||||
0x0e | SHIFT, // K
|
||||
0x0f | SHIFT, // L
|
||||
0x10 | SHIFT, // M
|
||||
0x11 | SHIFT, // N
|
||||
0x12 | SHIFT, // O
|
||||
0x13 | SHIFT, // P
|
||||
0x14 | SHIFT, // Q
|
||||
0x15 | SHIFT, // R
|
||||
0x16 | SHIFT, // S
|
||||
0x17 | SHIFT, // T
|
||||
0x18 | SHIFT, // U
|
||||
0x19 | SHIFT, // V
|
||||
0x1a | SHIFT, // W
|
||||
0x1b | SHIFT, // X
|
||||
0x1c | SHIFT, // Y
|
||||
0x1d | SHIFT, // Z
|
||||
0x2f | ALT_GR, // [
|
||||
0x35, // bslash
|
||||
0x30 | ALT_GR, // ]
|
||||
0x2e | SHIFT, // ^
|
||||
0x38 | SHIFT, // _
|
||||
0x00, // ` not in this layout
|
||||
0x04, // a
|
||||
0x05, // b
|
||||
0x06, // c
|
||||
0x07, // d
|
||||
0x08, // e
|
||||
0x09, // f
|
||||
0x0a, // g
|
||||
0x0b, // h
|
||||
0x0c, // i
|
||||
0x0d, // j
|
||||
0x0e, // k
|
||||
0x0f, // l
|
||||
0x10, // m
|
||||
0x11, // n
|
||||
0x12, // o
|
||||
0x13, // p
|
||||
0x14, // q
|
||||
0x15, // r
|
||||
0x16, // s
|
||||
0x17, // t
|
||||
0x18, // u
|
||||
0x19, // v
|
||||
0x1a, // w
|
||||
0x1b, // x
|
||||
0x1c, // y
|
||||
0x1d, // z
|
||||
0x00, // { not supported (requires AltGr+Shift)
|
||||
0x35 | SHIFT, // |
|
||||
0x00, // } not supported (requires AltGr+Shift)
|
||||
0x00, // ~ not in this layout
|
||||
0x00 // DEL
|
||||
};
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Keyboard_pt_BR.h
|
||||
* Portuguese Brazilian keyboard layout.
|
||||
*/
|
||||
|
||||
#include "KeyboardLayout.h"
|
||||
|
||||
extern const uint8_t KeyboardLayout_pt_BR[128] PROGMEM = {
|
||||
0x00, // NUL
|
||||
0x00, // SOH
|
||||
0x00, // STX
|
||||
0x00, // ETX
|
||||
0x00, // EOT
|
||||
0x00, // ENQ
|
||||
0x00, // ACK
|
||||
0x00, // BEL
|
||||
0x2a, // BS Backspace
|
||||
0x2b, // TAB Tab
|
||||
0x28, // LF Enter
|
||||
0x00, // VT
|
||||
0x00, // FF
|
||||
0x00, // CR
|
||||
0x00, // SO
|
||||
0x00, // SI
|
||||
0x00, // DEL
|
||||
0x00, // DC1
|
||||
0x00, // DC2
|
||||
0x00, // DC3
|
||||
0x00, // DC4
|
||||
0x00, // NAK
|
||||
0x00, // SYN
|
||||
0x00, // ETB
|
||||
0x00, // CAN
|
||||
0x00, // EM
|
||||
0x00, // SUB
|
||||
0x00, // ESC
|
||||
0x00, // FS
|
||||
0x00, // GS
|
||||
0x00, // RS
|
||||
0x00, // US
|
||||
|
||||
0x2c, // ' '
|
||||
0x1e | SHIFT, // !
|
||||
0x35 | SHIFT, // "
|
||||
0x20 | SHIFT, // #
|
||||
0x21 | SHIFT, // $
|
||||
0x22 | SHIFT, // %
|
||||
0x24 | SHIFT, // &
|
||||
0x35, // '
|
||||
0x26 | SHIFT, // (
|
||||
0x27 | SHIFT, // )
|
||||
0x25 | SHIFT, // *
|
||||
0x2e | SHIFT, // +
|
||||
0x36, // ,
|
||||
0x2d, // -
|
||||
0x37, // .
|
||||
0x14 | ALT_GR, // / R_ALT + q
|
||||
0x27, // 0
|
||||
0x1e, // 1
|
||||
0x1f, // 2
|
||||
0x20, // 3
|
||||
0x21, // 4
|
||||
0x22, // 5
|
||||
0x23, // 6
|
||||
0x24, // 7
|
||||
0x25, // 8
|
||||
0x26, // 9
|
||||
0x38 | SHIFT, // :
|
||||
0x38, // ;
|
||||
0x36 | SHIFT, // <
|
||||
0x2e, // =
|
||||
0x37 | SHIFT, // >
|
||||
0x1a | ALT_GR, // ? R_ALT + w
|
||||
0x1f | SHIFT, // @
|
||||
0x04 | SHIFT, // A
|
||||
0x05 | SHIFT, // B
|
||||
0x06 | SHIFT, // C
|
||||
0x07 | SHIFT, // D
|
||||
0x08 | SHIFT, // E
|
||||
0x09 | SHIFT, // F
|
||||
0x0a | SHIFT, // G
|
||||
0x0b | SHIFT, // H
|
||||
0x0c | SHIFT, // I
|
||||
0x0d | SHIFT, // J
|
||||
0x0e | SHIFT, // K
|
||||
0x0f | SHIFT, // L
|
||||
0x10 | SHIFT, // M
|
||||
0x11 | SHIFT, // N
|
||||
0x12 | SHIFT, // O
|
||||
0x13 | SHIFT, // P
|
||||
0x14 | SHIFT, // Q
|
||||
0x15 | SHIFT, // R
|
||||
0x16 | SHIFT, // S
|
||||
0x17 | SHIFT, // T
|
||||
0x18 | SHIFT, // U
|
||||
0x19 | SHIFT, // V
|
||||
0x1a | SHIFT, // W
|
||||
0x1b | SHIFT, // X
|
||||
0x1c | SHIFT, // Y
|
||||
0x1d | SHIFT, // Z
|
||||
0x30, // [
|
||||
0x32, // bslash -->ISO Key
|
||||
0x31, // ]
|
||||
0x34 | SHIFT, // ^
|
||||
0x2d | SHIFT, // _
|
||||
0x2f | SHIFT, // `
|
||||
0x04, // a
|
||||
0x05, // b
|
||||
0x06, // c
|
||||
0x07, // d
|
||||
0x08, // e
|
||||
0x09, // f
|
||||
0x0a, // g
|
||||
0x0b, // h
|
||||
0x0c, // i
|
||||
0x0d, // j
|
||||
0x0e, // k
|
||||
0x0f, // l
|
||||
0x10, // m
|
||||
0x11, // n
|
||||
0x12, // o
|
||||
0x13, // p
|
||||
0x14, // q
|
||||
0x15, // r
|
||||
0x16, // s
|
||||
0x17, // t
|
||||
0x18, // u
|
||||
0x19, // v
|
||||
0x1a, // w
|
||||
0x1b, // x
|
||||
0x1c, // y
|
||||
0x1d, // z
|
||||
0x30 | SHIFT, // {
|
||||
0x32 | SHIFT, // | -->ISO Key
|
||||
0x31 | SHIFT, // }
|
||||
0x34, // ~
|
||||
0x4c // DEL
|
||||
};
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Portuguese keyboard layout.
|
||||
*/
|
||||
|
||||
#include "KeyboardLayout.h"
|
||||
|
||||
extern const uint8_t KeyboardLayout_pt_PT[128] PROGMEM = {
|
||||
0x00, // NUL
|
||||
0x00, // SOH
|
||||
0x00, // STX
|
||||
0x00, // ETX
|
||||
0x00, // EOT
|
||||
0x00, // ENQ
|
||||
0x00, // ACK
|
||||
0x00, // BEL
|
||||
0x2a, // BS Backspace
|
||||
0x2b, // TAB Tab
|
||||
0x28, // LF Enter
|
||||
0x00, // VT
|
||||
0x00, // FF
|
||||
0x00, // CR
|
||||
0x00, // SO
|
||||
0x00, // SI
|
||||
0x00, // DEL
|
||||
0x00, // DC1
|
||||
0x00, // DC2
|
||||
0x00, // DC3
|
||||
0x00, // DC4
|
||||
0x00, // NAK
|
||||
0x00, // SYN
|
||||
0x00, // ETB
|
||||
0x00, // CAN
|
||||
0x00, // EM
|
||||
0x00, // SUB
|
||||
0x00, // ESC
|
||||
0x00, // FS
|
||||
0x00, // GS
|
||||
0x00, // RS
|
||||
0x00, // US
|
||||
|
||||
0x2c, // ' '
|
||||
0x1e | SHIFT, // !
|
||||
0x1f | SHIFT, // "
|
||||
0x20 | SHIFT, // #
|
||||
0x21 | SHIFT, // $
|
||||
0x22 | SHIFT, // %
|
||||
0x23 | SHIFT, // &
|
||||
0x2d, // '
|
||||
0x25 | SHIFT, // (
|
||||
0x26 | SHIFT, // )
|
||||
0x2f | SHIFT, // *
|
||||
0x2f, // +
|
||||
0x36, // ,
|
||||
0x38, // -
|
||||
0x37, // .
|
||||
0x24 | SHIFT, // /
|
||||
0x27, // 0
|
||||
0x1e, // 1
|
||||
0x1f, // 2
|
||||
0x20, // 3
|
||||
0x21, // 4
|
||||
0x22, // 5
|
||||
0x23, // 6
|
||||
0x24, // 7
|
||||
0x25, // 8
|
||||
0x26, // 9
|
||||
0x37 | SHIFT, // :
|
||||
0x36 | SHIFT, // ;
|
||||
0x32, // <
|
||||
0x27 | SHIFT, // =
|
||||
0x32 | SHIFT, // >
|
||||
0x2d | SHIFT, // ?
|
||||
0x1f | ALT_GR, // @
|
||||
0x04 | SHIFT, // A
|
||||
0x05 | SHIFT, // B
|
||||
0x06 | SHIFT, // C
|
||||
0x07 | SHIFT, // D
|
||||
0x08 | SHIFT, // E
|
||||
0x09 | SHIFT, // F
|
||||
0x0a | SHIFT, // G
|
||||
0x0b | SHIFT, // H
|
||||
0x0c | SHIFT, // I
|
||||
0x0d | SHIFT, // J
|
||||
0x0e | SHIFT, // K
|
||||
0x0f | SHIFT, // L
|
||||
0x10 | SHIFT, // M
|
||||
0x11 | SHIFT, // N
|
||||
0x12 | SHIFT, // O
|
||||
0x13 | SHIFT, // P
|
||||
0x14 | SHIFT, // Q
|
||||
0x15 | SHIFT, // R
|
||||
0x16 | SHIFT, // S
|
||||
0x17 | SHIFT, // T
|
||||
0x18 | SHIFT, // U
|
||||
0x19 | SHIFT, // V
|
||||
0x1a | SHIFT, // W
|
||||
0x1b | SHIFT, // X
|
||||
0x1c | SHIFT, // Y
|
||||
0x1d | SHIFT, // Z
|
||||
0x25 | ALT_GR, // [
|
||||
0x35, // bslash
|
||||
0x26 | ALT_GR, // ]
|
||||
0x00, // ^ not supported (requires dead key + space)
|
||||
0x38 | SHIFT, // _
|
||||
0x00, // ` not supported (requires dead key + space)
|
||||
0x04, // a
|
||||
0x05, // b
|
||||
0x06, // c
|
||||
0x07, // d
|
||||
0x08, // e
|
||||
0x09, // f
|
||||
0x0a, // g
|
||||
0x0b, // h
|
||||
0x0c, // i
|
||||
0x0d, // j
|
||||
0x0e, // k
|
||||
0x0f, // l
|
||||
0x10, // m
|
||||
0x11, // n
|
||||
0x12, // o
|
||||
0x13, // p
|
||||
0x14, // q
|
||||
0x15, // r
|
||||
0x16, // s
|
||||
0x17, // t
|
||||
0x18, // u
|
||||
0x19, // v
|
||||
0x1a, // w
|
||||
0x1b, // x
|
||||
0x1c, // y
|
||||
0x1d, // z
|
||||
0x24 | ALT_GR, // {
|
||||
0x35 | SHIFT, // |
|
||||
0x27 | ALT_GR, // }
|
||||
0x00, // ~ not supported (requires dead key + space)
|
||||
0x00 // DEL
|
||||
};
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Swedish keyboard layout.
|
||||
*/
|
||||
|
||||
#include "KeyboardLayout.h"
|
||||
|
||||
extern const uint8_t KeyboardLayout_sv_SE[128] PROGMEM = {
|
||||
0x00, // NUL
|
||||
0x00, // SOH
|
||||
0x00, // STX
|
||||
0x00, // ETX
|
||||
0x00, // EOT
|
||||
0x00, // ENQ
|
||||
0x00, // ACK
|
||||
0x00, // BEL
|
||||
0x2a, // BS Backspace
|
||||
0x2b, // TAB Tab
|
||||
0x28, // LF Enter
|
||||
0x00, // VT
|
||||
0x00, // FF
|
||||
0x00, // CR
|
||||
0x00, // SO
|
||||
0x00, // SI
|
||||
0x00, // DEL
|
||||
0x00, // DC1
|
||||
0x00, // DC2
|
||||
0x00, // DC3
|
||||
0x00, // DC4
|
||||
0x00, // NAK
|
||||
0x00, // SYN
|
||||
0x00, // ETB
|
||||
0x00, // CAN
|
||||
0x00, // EM
|
||||
0x00, // SUB
|
||||
0x00, // ESC
|
||||
0x00, // FS
|
||||
0x00, // GS
|
||||
0x00, // RS
|
||||
0x00, // US
|
||||
|
||||
0x2c, // ' '
|
||||
0x1e | SHIFT, // !
|
||||
0x1f | SHIFT, // "
|
||||
0x20 | SHIFT, // #
|
||||
0x21 | ALT_GR, // $
|
||||
0x22 | SHIFT, // %
|
||||
0x23 | SHIFT, // &
|
||||
0x31, // '
|
||||
0x25 | SHIFT, // (
|
||||
0x26 | SHIFT, // )
|
||||
0x31 | SHIFT, // *
|
||||
0x2d, // +
|
||||
0x36, // ,
|
||||
0x38, // -
|
||||
0x37, // .
|
||||
0x24 | SHIFT, // /
|
||||
0x27, // 0
|
||||
0x1e, // 1
|
||||
0x1f, // 2
|
||||
0x20, // 3
|
||||
0x21, // 4
|
||||
0x22, // 5
|
||||
0x23, // 6
|
||||
0x24, // 7
|
||||
0x25, // 8
|
||||
0x26, // 9
|
||||
0x37 | SHIFT, // :
|
||||
0x36 | SHIFT, // ;
|
||||
0x32, // <
|
||||
0x27 | SHIFT, // =
|
||||
0x32 | SHIFT, // >
|
||||
0x2d | SHIFT, // ?
|
||||
0x1f | ALT_GR, // @
|
||||
0x04 | SHIFT, // A
|
||||
0x05 | SHIFT, // B
|
||||
0x06 | SHIFT, // C
|
||||
0x07 | SHIFT, // D
|
||||
0x08 | SHIFT, // E
|
||||
0x09 | SHIFT, // F
|
||||
0x0a | SHIFT, // G
|
||||
0x0b | SHIFT, // H
|
||||
0x0c | SHIFT, // I
|
||||
0x0d | SHIFT, // J
|
||||
0x0e | SHIFT, // K
|
||||
0x0f | SHIFT, // L
|
||||
0x10 | SHIFT, // M
|
||||
0x11 | SHIFT, // N
|
||||
0x12 | SHIFT, // O
|
||||
0x13 | SHIFT, // P
|
||||
0x14 | SHIFT, // Q
|
||||
0x15 | SHIFT, // R
|
||||
0x16 | SHIFT, // S
|
||||
0x17 | SHIFT, // T
|
||||
0x18 | SHIFT, // U
|
||||
0x19 | SHIFT, // V
|
||||
0x1a | SHIFT, // W
|
||||
0x1b | SHIFT, // X
|
||||
0x1c | SHIFT, // Y
|
||||
0x1d | SHIFT, // Z
|
||||
0x25 | ALT_GR, // [
|
||||
0x2d | ALT_GR, // bslash
|
||||
0x26 | ALT_GR, // ]
|
||||
0x00, // ^ not supported (requires dead key + space)
|
||||
0x38 | SHIFT, // _
|
||||
0x00, // ` not supported (requires dead key + space)
|
||||
0x04, // a
|
||||
0x05, // b
|
||||
0x06, // c
|
||||
0x07, // d
|
||||
0x08, // e
|
||||
0x09, // f
|
||||
0x0a, // g
|
||||
0x0b, // h
|
||||
0x0c, // i
|
||||
0x0d, // j
|
||||
0x0e, // k
|
||||
0x0f, // l
|
||||
0x10, // m
|
||||
0x11, // n
|
||||
0x12, // o
|
||||
0x13, // p
|
||||
0x14, // q
|
||||
0x15, // r
|
||||
0x16, // s
|
||||
0x17, // t
|
||||
0x18, // u
|
||||
0x19, // v
|
||||
0x1a, // w
|
||||
0x1b, // x
|
||||
0x1c, // y
|
||||
0x1d, // z
|
||||
0x24 | ALT_GR, // {
|
||||
0x32 | ALT_GR, // |
|
||||
0x27 | ALT_GR, // }
|
||||
0x00, // ~ not supported (requires dead key + space)
|
||||
0x00 // DEL
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Keyboard_da_DK.h
|
||||
|
||||
Copyright (c) 2021, Peter John
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef KEYBOARD_DA_DK_h
|
||||
#define KEYBOARD_DA_DK_h
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// Keyboard
|
||||
|
||||
// DA_DK keys
|
||||
#define KEY_A_RING (0x88 + 0x2f)
|
||||
#define KEY_SLASHED_O (0x88 + 0x34)
|
||||
#define KEY_ASH (0x88 + 0x33)
|
||||
#define KEY_UMLAUT (0x88 + 0x30)
|
||||
#define KEY_ACUTE_ACC (0x88 + 0x2e)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Keyboard_de_DE.h
|
||||
|
||||
Copyright (c) 2022, Edgar Bonet
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef KEYBOARD_DE_DE_h
|
||||
#define KEYBOARD_DE_DE_h
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// Keyboard
|
||||
|
||||
// de_DE keys
|
||||
#define KEY_CIRCUMFLEX (0x88 + 0x35)
|
||||
#define KEY_ESZETT (0x88 + 0x2d)
|
||||
#define KEY_ACUTE (0x88 + 0x2e)
|
||||
#define KEY_U_UMLAUT (0x88 + 0x2f)
|
||||
#define KEY_O_UMLAUT (0x88 + 0x33)
|
||||
#define KEY_A_UMLAUT (0x88 + 0x34)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
Keyboard_es_ES.h
|
||||
|
||||
Copyright (c) 2022, Edgar Bonet
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef KEYBOARD_ES_ES_h
|
||||
#define KEYBOARD_ES_ES_h
|
||||
|
||||
#include "class/hid/hid.h"
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// Keyboard
|
||||
|
||||
// es_ES keys
|
||||
#define KEY_MASCULINE_ORDINAL (0x88 + 0x35)
|
||||
#define KEY_INVERTED_EXCLAMATION (0x88 + 0x2e)
|
||||
#define KEY_GRAVE (0x88 + 0x2f)
|
||||
#define KEY_N_TILDE (0x88 + 0x33)
|
||||
#define KEY_ACUTE (0x88 + 0x34)
|
||||
#define KEY_C_CEDILLA (0x88 + 0x31)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
Keyboard_fr_FR.h
|
||||
|
||||
Copyright (c) 2022, Edgar Bonet
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef KEYBOARD_FR_FR_h
|
||||
#define KEYBOARD_FR_FR_h
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// Keyboard
|
||||
|
||||
// fr_FR keys
|
||||
#define KEY_SUPERSCRIPT_TWO (0x88 + 0x35)
|
||||
#define KEY_E_ACUTE (0x88 + 0x1f)
|
||||
#define KEY_E_GRAVE (0x88 + 0x24)
|
||||
#define KEY_C_CEDILLA (0x88 + 0x26)
|
||||
#define KEY_A_GRAVE (0x88 + 0x27)
|
||||
#define KEY_CIRCUMFLEX (0x88 + 0x2f)
|
||||
#define KEY_U_GRAVE (0x88 + 0x34)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
Keyboard_hu_HU.h
|
||||
|
||||
Copyright (c) 2023, Barab(0x34)si Rich(0x34)rd
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef KEYBOARD_HU_HU_h
|
||||
#define KEYBOARD_HU_HU_h
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// Keyboard
|
||||
|
||||
// hu_HU keys
|
||||
#define KEY_O_ACUTE (0x88 + 0x2e)
|
||||
#define KEY_O_UMLAUT (0x88 + 0x27)
|
||||
#define KEY_O_DOUBLE_ACUTE (0x88 + 0x2f)
|
||||
|
||||
#define KEY_U_ACUTE (0x88 + 0x30)
|
||||
#define KEY_U_UMLAUT (0x88 + 0x2d)
|
||||
#define KEY_U_DOUBLE_ACUTE (0x88 + 0x31)
|
||||
|
||||
#define KEY_A_ACUTE (0x88 + 0x34)
|
||||
|
||||
#define KEY_E_ACUTE (0x88 + 0x33)
|
||||
|
||||
#define KEY_I_ACUTE (0x88 + 0x32)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Keyboard_it_IT.h
|
||||
|
||||
Copyright (c) 2022, Edgar Bonet
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef KEYBOARD_IT_IT_h
|
||||
#define KEYBOARD_IT_IT_h
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// Keyboard
|
||||
|
||||
// it_IT keys
|
||||
#define KEY_I_GRAVE (0x88 + 0x2e)
|
||||
#define KEY_E_GRAVE (0x88 + 0x2f)
|
||||
#define KEY_O_GRAVE (0x88 + 0x33)
|
||||
#define KEY_A_GRAVE (0x88 + 0x34)
|
||||
#define KEY_U_GRAVE (0x88 + 0x31)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Keyboard_pt_BR.h
|
||||
* Portuguese Brazilian keyboard layout.
|
||||
*/
|
||||
|
||||
#ifndef KEYBOARD_PT_BR_h
|
||||
#define KEYBOARD_PT_BR_h
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// Keyboard
|
||||
|
||||
// pt_BR keys
|
||||
#define KEY_C_CEDILLA (0x88 + 0x33)
|
||||
#define KEY_ACUTE (0x88 + 0x2f)
|
||||
// use the pressRaw() to press the modification key and then press the key you want to modify
|
||||
#define KEY_MASCULINE_ORDINAL (0x88 + 0x32) // first pressRaw(HID_KEY_ALT_RIGHT), then press(KEY_MASCULINE_ORDINAL)
|
||||
#define KEY_FEMININE_ORDINAL (0x88 + 0x30) // first pressRaw(HID_KEY_ALT_RIGHT), then press(KEY_FEMININE_ORDINAL)
|
||||
#define KEY_PARAGRAPH (0x88 + 0x2e) // first pressRaw(HID_KEY_ALT_RIGHT), then press(KEY_PARAGRAPH)
|
||||
#define KEY_UMLAUT (0x88 + 0x23) // first pressRaw(HID_KEY_SHIFT_RIGHT), then press(KEY_UMLAUT)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Keyboard_pt_PT.h
|
||||
|
||||
Copyright (c) 2022, Edgar Bonet
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef KEYBOARD_PT_PT_h
|
||||
#define KEYBOARD_PT_PT_h
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// Keyboard
|
||||
|
||||
// pt_PT keys
|
||||
#define KEY_LEFT_GUILLEMET (0x88 + 0x2e)
|
||||
#define KEY_ACUTE (0x88 + 0x30)
|
||||
#define KEY_C_CEDILLA (0x88 + 0x33)
|
||||
#define KEY_MASCULINE_ORDINAL (0x88 + 0x34)
|
||||
#define KEY_TILDE (0x88 + 0x31)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Keyboard_sv_SE.h
|
||||
|
||||
Copyright (c) 2021, Peter John
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef KEYBOARD_SV_SE_h
|
||||
#define KEYBOARD_SV_SE_h
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// Keyboard
|
||||
|
||||
// SV_SE keys
|
||||
#define KEY_A_RING (0x88 + 0x2f)
|
||||
#define KEY_A_UMLAUT (0x88 + 0x34)
|
||||
#define KEY_O_UMLAUT (0x88 + 0x33)
|
||||
#define KEY_UMLAUT (0x88 + 0x30)
|
||||
#define KEY_ACUTE_ACC (0x88 + 0x2e)
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user