From 1bff37781bda1d0c285aa5aa7102d6941ad64e7d Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 14 Oct 2023 22:21:20 +1100 Subject: Prep work for NKRO report separation (#22268) * Clean up some keyboard/userspace code * Rename `KEYBOARD_REPORT_BITS` -> `NKRO_REPORT_BITS` * Add some missing includes * Use `PACKED` define for report types * Fix incorrect function signatures for FlexRAM EEPROM driver --- tmk_core/protocol/report.c | 8 ++++---- tmk_core/protocol/report.h | 19 ++++++++++--------- tmk_core/protocol/usb_descriptor.c | 4 ++-- 3 files changed, 16 insertions(+), 15 deletions(-) (limited to 'tmk_core') diff --git a/tmk_core/protocol/report.c b/tmk_core/protocol/report.c index 1ba3be4604..27d267abae 100644 --- a/tmk_core/protocol/report.c +++ b/tmk_core/protocol/report.c @@ -59,7 +59,7 @@ uint8_t get_first_key(report_keyboard_t* keyboard_report) { #ifdef NKRO_ENABLE if (keyboard_protocol && keymap_config.nkro) { uint8_t i = 0; - for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) + for (; i < NKRO_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) ; return i << 3 | biton(keyboard_report->nkro.bits[i]); } @@ -89,7 +89,7 @@ bool is_key_pressed(report_keyboard_t* keyboard_report, uint8_t key) { } #ifdef NKRO_ENABLE if (keyboard_protocol && keymap_config.nkro) { - if ((key >> 3) < KEYBOARD_REPORT_BITS) { + if ((key >> 3) < NKRO_REPORT_BITS) { return keyboard_report->nkro.bits[key >> 3] & 1 << (key & 7); } else { return false; @@ -216,7 +216,7 @@ void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code) { * FIXME: Needs doc */ void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code) { - if ((code >> 3) < KEYBOARD_REPORT_BITS) { + if ((code >> 3) < NKRO_REPORT_BITS) { keyboard_report->nkro.bits[code >> 3] |= 1 << (code & 7); } else { dprintf("add_key_bit: can't add: %02X\n", code); @@ -228,7 +228,7 @@ void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code) { * FIXME: Needs doc */ void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code) { - if ((code >> 3) < KEYBOARD_REPORT_BITS) { + if ((code >> 3) < NKRO_REPORT_BITS) { keyboard_report->nkro.bits[code >> 3] &= ~(1 << (code & 7)); } else { dprintf("del_key_bit: can't del: %02X\n", code); diff --git a/tmk_core/protocol/report.h b/tmk_core/protocol/report.h index 9d415a3bfd..dd3cee3df0 100644 --- a/tmk_core/protocol/report.h +++ b/tmk_core/protocol/report.h @@ -20,6 +20,7 @@ along with this program. If not, see . #include #include #include "keycode.h" +#include "util.h" // clang-format off @@ -129,10 +130,10 @@ enum desktop_usages { #if defined(NKRO_ENABLE) # if defined(PROTOCOL_LUFA) || defined(PROTOCOL_CHIBIOS) # include "protocol/usb_descriptor.h" -# define KEYBOARD_REPORT_BITS (SHARED_EPSIZE - 2) +# define NKRO_REPORT_BITS (SHARED_EPSIZE - 2) # elif defined(PROTOCOL_ARM_ATSAM) # include "protocol/arm_atsam/usb/udi_device_epsize.h" -# define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1) +# define NKRO_REPORT_BITS (NKRO_EPSIZE - 1) # undef NKRO_SHARED_EP # undef MOUSE_SHARED_EP # else @@ -188,20 +189,20 @@ typedef union { uint8_t report_id; # endif uint8_t mods; - uint8_t bits[KEYBOARD_REPORT_BITS]; + uint8_t bits[NKRO_REPORT_BITS]; } nkro; #endif -} __attribute__((packed)) report_keyboard_t; +} PACKED report_keyboard_t; typedef struct { uint8_t report_id; uint16_t usage; -} __attribute__((packed)) report_extra_t; +} PACKED report_extra_t; typedef struct { uint8_t report_id; uint32_t usage; -} __attribute__((packed)) report_programmable_button_t; +} PACKED report_programmable_button_t; #ifdef MOUSE_EXTENDED_REPORT typedef int16_t mouse_xy_report_t; @@ -222,7 +223,7 @@ typedef struct { mouse_xy_report_t y; int8_t v; int8_t h; -} __attribute__((packed)) report_mouse_t; +} PACKED report_mouse_t; typedef struct { #ifdef DIGITIZER_SHARED_EP @@ -234,7 +235,7 @@ typedef struct { uint8_t reserved : 5; uint16_t x; uint16_t y; -} __attribute__((packed)) report_digitizer_t; +} PACKED report_digitizer_t; typedef struct { #ifdef JOYSTICK_SHARED_EP @@ -251,7 +252,7 @@ typedef struct { #if JOYSTICK_BUTTON_COUNT > 0 uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1]; #endif -} __attribute__((packed)) report_joystick_t; +} PACKED report_joystick_t; /* keycode to system usage */ static inline uint16_t KEYCODE2SYSTEM(uint8_t key) { diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c index e215c90900..eb214c0492 100644 --- a/tmk_core/protocol/usb_descriptor.c +++ b/tmk_core/protocol/usb_descriptor.c @@ -359,10 +359,10 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { // Keycodes HID_RI_USAGE_PAGE(8, 0x07), // Keyboard/Keypad HID_RI_USAGE_MINIMUM(8, 0x00), - HID_RI_USAGE_MAXIMUM(8, KEYBOARD_REPORT_BITS * 8 - 1), + HID_RI_USAGE_MAXIMUM(8, NKRO_REPORT_BITS * 8 - 1), HID_RI_LOGICAL_MINIMUM(8, 0x00), HID_RI_LOGICAL_MAXIMUM(8, 0x01), - HID_RI_REPORT_COUNT(8, KEYBOARD_REPORT_BITS * 8), + HID_RI_REPORT_COUNT(8, NKRO_REPORT_BITS * 8), HID_RI_REPORT_SIZE(8, 0x01), HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), -- cgit v1.2.3