mirror of
https://github.com/qmk/qmk_firmware.git
synced 2026-09-07 10:53:17 +02:00
Custom plover HID report type (#26018)
Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: dnaq <dnaq@users.noreply.github.com>
This commit is contained in:
co-authored by
Nick Brassel
dnaq
parent
0d401d1182
commit
b64014d5df
@@ -80,6 +80,14 @@ usb_endpoint_in_t usb_endpoints_in[USB_ENDPOINT_IN_COUNT] = {
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(PLOVER_HID_ENABLE)
|
||||
# if defined(USB_ENDPOINTS_ARE_REORDERABLE)
|
||||
[USB_ENDPOINT_IN_PLOVER_HID] = QMK_USB_ENDPOINT_IN_SHARED(USB_EP_MODE_TYPE_INTR, PLOVER_HID_EPSIZE, PLOVER_HID_IN_EPNUM, PLOVER_HID_IN_CAPACITY, NULL, QMK_USB_REPORT_STORAGE_DEFAULT(PLOVER_HID_EPSIZE)),
|
||||
# else
|
||||
[USB_ENDPOINT_IN_PLOVER_HID] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, PLOVER_HID_EPSIZE, PLOVER_HID_IN_EPNUM, PLOVER_HID_IN_CAPACITY, NULL, QMK_USB_REPORT_STORAGE_DEFAULT(PLOVER_HID_EPSIZE)),
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(MIDI_ENABLE)
|
||||
# if defined(USB_ENDPOINTS_ARE_REORDERABLE)
|
||||
[USB_ENDPOINT_IN_MIDI] = QMK_USB_ENDPOINT_IN_SHARED(USB_EP_MODE_TYPE_BULK, MIDI_STREAM_EPSIZE, MIDI_STREAM_IN_EPNUM, MIDI_STREAM_IN_CAPACITY, NULL, NULL),
|
||||
|
||||
@@ -43,6 +43,10 @@
|
||||
# define RAW_OUT_CAPACITY USB_DEFAULT_BUFFER_CAPACITY
|
||||
#endif
|
||||
|
||||
#if !defined(PLOVER_HID_IN_CAPACITY)
|
||||
# define PLOVER_HID_IN_CAPACITY USB_DEFAULT_BUFFER_CAPACITY
|
||||
#endif
|
||||
|
||||
#if !defined(MIDI_STREAM_IN_CAPACITY)
|
||||
# define MIDI_STREAM_IN_CAPACITY USB_DEFAULT_BUFFER_CAPACITY
|
||||
#endif
|
||||
@@ -90,6 +94,10 @@ typedef enum {
|
||||
USB_ENDPOINT_IN_RAW,
|
||||
#endif
|
||||
|
||||
#if defined(PLOVER_HID_ENABLE)
|
||||
USB_ENDPOINT_IN_PLOVER_HID,
|
||||
#endif
|
||||
|
||||
#if defined(MIDI_ENABLE)
|
||||
USB_ENDPOINT_IN_MIDI,
|
||||
#endif
|
||||
@@ -127,6 +135,7 @@ typedef enum {
|
||||
#if defined(RAW_ENABLE)
|
||||
USB_ENDPOINT_OUT_RAW,
|
||||
#endif
|
||||
|
||||
#if defined(MIDI_ENABLE)
|
||||
USB_ENDPOINT_OUT_MIDI,
|
||||
#endif
|
||||
|
||||
@@ -523,6 +523,28 @@ void raw_hid_task(void) {
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef PLOVER_HID_ENABLE
|
||||
static bool plover_hid_report_updated = false;
|
||||
static uint8_t plover_hid_current_report[PLOVER_HID_EPSIZE] = {0x50};
|
||||
|
||||
void plover_hid_update(uint8_t button, bool pressed) {
|
||||
if (pressed) {
|
||||
plover_hid_current_report[1 + button / 8] |= (1 << (7 - (button % 8)));
|
||||
} else {
|
||||
plover_hid_current_report[1 + button / 8] &= ~(1 << (7 - (button % 8)));
|
||||
}
|
||||
plover_hid_report_updated = true;
|
||||
}
|
||||
|
||||
void plover_hid_task(void) {
|
||||
if (!plover_hid_report_updated) {
|
||||
return;
|
||||
}
|
||||
send_report(USB_ENDPOINT_IN_PLOVER_HID, plover_hid_current_report, sizeof(plover_hid_current_report));
|
||||
plover_hid_report_updated = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MIDI_ENABLE
|
||||
|
||||
void send_midi_packet(MIDI_EventPacket_t *event) {
|
||||
|
||||
@@ -64,6 +64,10 @@
|
||||
# include "raw_hid.h"
|
||||
#endif
|
||||
|
||||
#ifdef PLOVER_HID_ENABLE
|
||||
# include "plover_hid.h"
|
||||
#endif
|
||||
|
||||
#ifdef WAIT_FOR_USB
|
||||
// TODO: Remove backwards compatibility with old define
|
||||
# define USB_WAIT_FOR_ENUMERATION
|
||||
@@ -179,6 +183,28 @@ void raw_hid_task(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PLOVER_HID_ENABLE
|
||||
static bool plover_hid_report_updated = false;
|
||||
static uint8_t plover_hid_current_report[PLOVER_HID_EPSIZE] = {0x50};
|
||||
|
||||
void plover_hid_update(uint8_t button, bool pressed) {
|
||||
if (pressed) {
|
||||
plover_hid_current_report[1 + button / 8] |= (1 << (7 - (button % 8)));
|
||||
} else {
|
||||
plover_hid_current_report[1 + button / 8] &= ~(1 << (7 - (button % 8)));
|
||||
}
|
||||
plover_hid_report_updated = true;
|
||||
}
|
||||
|
||||
void plover_hid_task(void) {
|
||||
if (!plover_hid_report_updated) {
|
||||
return;
|
||||
}
|
||||
send_report(PLOVER_HID_IN_EPNUM, plover_hid_current_report, sizeof(plover_hid_current_report));
|
||||
plover_hid_report_updated = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Console
|
||||
******************************************************************************/
|
||||
@@ -347,6 +373,11 @@ void EVENT_USB_Device_ConfigurationChanged(void) {
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint((RAW_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_INTERRUPT, RAW_EPSIZE, 1);
|
||||
#endif
|
||||
|
||||
#ifdef PLOVER_HID_ENABLE
|
||||
/* Setup plover HID endpoints */
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint((PLOVER_HID_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, PLOVER_HID_EPSIZE, 1);
|
||||
#endif
|
||||
|
||||
#ifdef CONSOLE_ENABLE
|
||||
/* Setup console endpoint */
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1);
|
||||
@@ -846,6 +877,10 @@ void protocol_post_task(void) {
|
||||
MIDI_Device_USBTask(&USB_MIDI_Interface);
|
||||
#endif
|
||||
|
||||
#ifdef PLOVER_HID_ENABLE
|
||||
plover_hid_task();
|
||||
#endif
|
||||
|
||||
#ifdef VIRTSER_ENABLE
|
||||
virtser_task();
|
||||
CDC_Device_USBTask(&cdc_device);
|
||||
|
||||
@@ -478,6 +478,24 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM RawReport[] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef PLOVER_HID_ENABLE
|
||||
const USB_Descriptor_HIDReport_Datatype_t PROGMEM PloverReport[] = {
|
||||
HID_RI_USAGE_PAGE(16, 0xff50), //
|
||||
HID_RI_USAGE(16, 0x4c56), // Vendor Defined (0xff P L V)
|
||||
HID_RI_COLLECTION(8, 0x01), // Application
|
||||
HID_RI_REPORT_ID(8, 80),
|
||||
HID_RI_LOGICAL_MINIMUM(8, 0),
|
||||
HID_RI_LOGICAL_MAXIMUM(8, 1),
|
||||
HID_RI_REPORT_SIZE(8, 1),
|
||||
HID_RI_REPORT_COUNT(8, 64),
|
||||
HID_RI_USAGE_PAGE(8, 0x0a), // Usage Page: Ordinal
|
||||
HID_RI_USAGE_MINIMUM(8, 0),
|
||||
HID_RI_USAGE_MAXIMUM(8, 63),
|
||||
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
HID_RI_END_COLLECTION(0),
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef CONSOLE_ENABLE
|
||||
const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = {
|
||||
HID_RI_USAGE_PAGE(16, 0xFF31), // Vendor Defined (PJRC Teensy compatible)
|
||||
@@ -643,6 +661,46 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
|
||||
},
|
||||
#endif
|
||||
|
||||
#ifdef PLOVER_HID_ENABLE
|
||||
/*
|
||||
* Plover HID
|
||||
*/
|
||||
.Plover_Interface = {
|
||||
.Header = {
|
||||
.Size = sizeof(USB_Descriptor_Interface_t),
|
||||
.Type = DTYPE_Interface
|
||||
},
|
||||
.InterfaceNumber = PLOVER_HID_INTERFACE,
|
||||
.AlternateSetting = 0x00,
|
||||
.TotalEndpoints = 1,
|
||||
.Class = HID_CSCP_HIDClass,
|
||||
.SubClass = HID_CSCP_NonBootSubclass,
|
||||
.Protocol = HID_CSCP_NonBootProtocol,
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
.Plover_HID = {
|
||||
.Header = {
|
||||
.Size = sizeof(USB_HID_Descriptor_HID_t),
|
||||
.Type = HID_DTYPE_HID
|
||||
},
|
||||
.HIDSpec = VERSION_BCD(1, 1, 1),
|
||||
.CountryCode = 0x00,
|
||||
.TotalReportDescriptors = 1,
|
||||
.HIDReportType = HID_DTYPE_Report,
|
||||
.HIDReportLength = sizeof(PloverReport)
|
||||
},
|
||||
.Plover_INEndpoint = {
|
||||
.Header = {
|
||||
.Size = sizeof(USB_Descriptor_Endpoint_t),
|
||||
.Type = DTYPE_Endpoint
|
||||
},
|
||||
.EndpointAddress = (ENDPOINT_DIR_IN | PLOVER_HID_IN_EPNUM),
|
||||
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = PLOVER_HID_EPSIZE,
|
||||
.PollingIntervalMS = 0x01
|
||||
},
|
||||
#endif
|
||||
|
||||
#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
|
||||
/*
|
||||
* Mouse
|
||||
@@ -1285,6 +1343,14 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef PLOVER_HID_ENABLE
|
||||
case PLOVER_HID_INTERFACE:
|
||||
Address = &ConfigurationDescriptor.Plover_HID;
|
||||
Size = sizeof(USB_HID_Descriptor_HID_t);
|
||||
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONSOLE_ENABLE
|
||||
case CONSOLE_INTERFACE:
|
||||
Address = &ConfigurationDescriptor.Console_HID;
|
||||
@@ -1342,6 +1408,14 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef PLOVER_HID_ENABLE
|
||||
case PLOVER_HID_INTERFACE:
|
||||
Address = &PloverReport;
|
||||
Size = sizeof(PloverReport);
|
||||
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONSOLE_ENABLE
|
||||
case CONSOLE_INTERFACE:
|
||||
Address = &ConsoleReport;
|
||||
|
||||
@@ -78,6 +78,13 @@ typedef struct {
|
||||
USB_Descriptor_Endpoint_t Raw_OUTEndpoint;
|
||||
#endif
|
||||
|
||||
#ifdef PLOVER_HID_ENABLE
|
||||
// Plover HID Interface
|
||||
USB_Descriptor_Interface_t Plover_Interface;
|
||||
USB_HID_Descriptor_HID_t Plover_HID;
|
||||
USB_Descriptor_Endpoint_t Plover_INEndpoint;
|
||||
#endif
|
||||
|
||||
#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
|
||||
// Mouse HID Interface
|
||||
USB_Descriptor_Interface_t Mouse_Interface;
|
||||
@@ -164,6 +171,10 @@ enum usb_interfaces {
|
||||
RAW_INTERFACE,
|
||||
#endif
|
||||
|
||||
#ifdef PLOVER_HID_ENABLE
|
||||
PLOVER_HID_INTERFACE,
|
||||
#endif
|
||||
|
||||
#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
|
||||
MOUSE_INTERFACE,
|
||||
#endif
|
||||
@@ -227,6 +238,10 @@ enum usb_endpoints {
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef PLOVER_HID_ENABLE
|
||||
PLOVER_HID_IN_EPNUM = NEXT_EPNUM,
|
||||
#endif
|
||||
|
||||
#ifdef SHARED_EP_ENABLE
|
||||
SHARED_IN_EPNUM = NEXT_EPNUM,
|
||||
#endif
|
||||
@@ -287,6 +302,7 @@ enum usb_endpoints {
|
||||
#define SHARED_EPSIZE 32
|
||||
#define MOUSE_EPSIZE 16
|
||||
#define RAW_EPSIZE 32
|
||||
#define PLOVER_HID_EPSIZE 9
|
||||
#define CONSOLE_EPSIZE 32
|
||||
#define MIDI_STREAM_EPSIZE 64
|
||||
#define CDC_NOTIFICATION_EPSIZE 8
|
||||
|
||||
Reference in New Issue
Block a user