plover hid changes, bunch the reports up and send

This commit is contained in:
dnaq 2021-09-24 22:48:12 +02:00
parent 0f6d6af257
commit ae191ab099
3 changed files with 19 additions and 16 deletions

View file

@ -1,4 +1,5 @@
#pragma once
#define PLOVER_HID_SIMPLE_REPORT_SIZE 9
void plover_hid_send(uint8_t data[PLOVER_HID_SIMPLE_REPORT_SIZE]);
void plover_hid_update(uint8_t button, bool pressed);
void plover_hid_task(void);

View file

@ -2,22 +2,10 @@
#include "keymap_plover_hid.h"
#include "plover_hid.h"
// Simple report consists of a single byte set to one
// followed by one bit for each of the 64 buttons defined
// in the report type.
static uint8_t report[PLOVER_HID_SIMPLE_REPORT_SIZE] = {1};
bool process_plover_hid(uint16_t keycode, keyrecord_t *record) {
if (keycode < PLV__MIN || keycode > PLV__MAX) {
return true;
}
keycode = keycode - PLV__MIN;
if (record->event.pressed) {
report[1 + keycode/8] |= (1 << (7 - (keycode % 8)));
} else {
report[1 + keycode/8] &= ~(1 << (7 - (keycode % 8)));
}
plover_hid_send(report);
plover_hid_update((uint8_t)(keycode - PLV__MIN), record->event.pressed);
return false;
}

View file

@ -214,7 +214,16 @@ static void raw_hid_task(void) {
#endif
#ifdef PLOVER_HID_ENABLE
void plover_hid_send(uint8_t data[PLOVER_HID_SIMPLE_REPORT_SIZE]) {
static uint8_t plover_hid_current_report[PLOVER_HID_SIMPLE_REPORT_SIZE] = {1};
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)));
}
}
void plover_hid_task(void) {
if (USB_DeviceState != DEVICE_STATE_Configured) {
return;
}
@ -226,7 +235,7 @@ void plover_hid_send(uint8_t data[PLOVER_HID_SIMPLE_REPORT_SIZE]) {
// Check to see if the host is ready to accept another packet
if (Endpoint_IsINReady()) {
// Write data
Endpoint_Write_Stream_LE(data, PLOVER_HID_SIMPLE_REPORT_SIZE, NULL);
Endpoint_Write_Stream_LE(plover_hid_current_report, sizeof(plover_hid_current_report), NULL);
// Finalize The stream transfer to send the last packet
Endpoint_ClearIN();
}
@ -462,6 +471,7 @@ void EVENT_USB_Device_StartOfFrame(void) {
if (!console_flush) return;
Console_Task();
console_flush = false;
}
#endif
@ -1127,6 +1137,10 @@ void protocol_post_task(void) {
raw_hid_task();
#endif
#ifdef PLOVER_HID_ENABLE
plover_hid_task();
#endif
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
USB_USBTask();
#endif