forked from jappel/VersaMCU
96 lines
3.4 KiB
C++
96 lines
3.4 KiB
C++
#include "usb_hid.h"
|
|
#include <Arduino.h>
|
|
#include <HID.h>
|
|
|
|
// ── HID Report Descriptor: Keyboard + Consumer Control ───────────────────────
|
|
// Vendor-Kommunikation läuft über CVendorHID (eigenes PluggableUSBModule).
|
|
|
|
static const uint8_t k_hid_descriptor[] = {
|
|
|
|
// ── Report ID 1: Keyboard ─────────────────────────────────────────────────
|
|
0x05, 0x01, // Usage Page (Generic Desktop)
|
|
0x09, 0x06, // Usage (Keyboard)
|
|
0xA1, 0x01, // Collection (Application)
|
|
0x85, HID_REPORT_ID_KEYBOARD,
|
|
0x05, 0x07, // Usage Page (Key Codes)
|
|
0x19, 0xE0, // Usage Minimum (Left Ctrl)
|
|
0x29, 0xE7, // Usage Maximum (Right GUI)
|
|
0x15, 0x00, // Logical Minimum (0)
|
|
0x25, 0x01, // Logical Maximum (1)
|
|
0x75, 0x01, // Report Size (1 Bit)
|
|
0x95, 0x08, // Report Count (8)
|
|
0x81, 0x02, // Input (Data, Variable, Absolute)
|
|
0x95, 0x01, // Report Count (1)
|
|
0x75, 0x08, // Report Size (8 Bit)
|
|
0x81, 0x01, // Input (Constant)
|
|
0x95, 0x06, // Report Count (6)
|
|
0x75, 0x08, // Report Size (8 Bit)
|
|
0x15, 0x00, // Logical Minimum (0)
|
|
0x25, 0x65, // Logical Maximum (101)
|
|
0x05, 0x07, // Usage Page (Key Codes)
|
|
0x19, 0x00, // Usage Minimum (0)
|
|
0x29, 0x65, // Usage Maximum (101)
|
|
0x81, 0x00, // Input (Data, Array)
|
|
0xC0, // End Collection
|
|
|
|
// ── Report ID 2: Consumer Control ─────────────────────────────────────────
|
|
0x05, 0x0C, // Usage Page (Consumer Devices)
|
|
0x09, 0x01, // Usage (Consumer Control)
|
|
0xA1, 0x01, // Collection (Application)
|
|
0x85, HID_REPORT_ID_CONSUMER,
|
|
0x15, 0x00, // Logical Minimum (0)
|
|
0x26, 0xFF, 0x03, // Logical Maximum (1023)
|
|
0x19, 0x00, // Usage Minimum (0)
|
|
0x2A, 0xFF, 0x03, // Usage Maximum (1023)
|
|
0x75, 0x10, // Report Size (16 Bit)
|
|
0x95, 0x01, // Report Count (1)
|
|
0x81, 0x00, // Input (Data, Array)
|
|
0xC0, // End Collection
|
|
};
|
|
|
|
namespace {
|
|
struct HIDRegistrar {
|
|
HIDSubDescriptor node;
|
|
HIDRegistrar() : node(k_hid_descriptor, sizeof(k_hid_descriptor)) {
|
|
HID().AppendDescriptor(&node);
|
|
}
|
|
} s_hid_registrar;
|
|
}
|
|
|
|
struct KeyboardReport {
|
|
uint8_t modifier;
|
|
uint8_t reserved;
|
|
uint8_t keycodes[6];
|
|
};
|
|
|
|
struct ConsumerReport {
|
|
uint16_t usage;
|
|
};
|
|
|
|
void usb_hid_init() {}
|
|
|
|
void usb_hid_send_key(uint8_t keycode, uint8_t modifier)
|
|
{
|
|
KeyboardReport report = {};
|
|
report.modifier = modifier;
|
|
report.keycodes[0] = keycode;
|
|
HID().SendReport(HID_REPORT_ID_KEYBOARD, &report, sizeof(report));
|
|
}
|
|
|
|
void usb_hid_release_key()
|
|
{
|
|
KeyboardReport report = {};
|
|
HID().SendReport(HID_REPORT_ID_KEYBOARD, &report, sizeof(report));
|
|
}
|
|
|
|
void usb_hid_send_consumer(uint16_t usage)
|
|
{
|
|
ConsumerReport report = { usage };
|
|
HID().SendReport(HID_REPORT_ID_CONSUMER, &report, sizeof(report));
|
|
}
|
|
|
|
void usb_hid_release_consumer()
|
|
{
|
|
ConsumerReport report = { 0 };
|
|
HID().SendReport(HID_REPORT_ID_CONSUMER, &report, sizeof(report));
|
|
}
|