From 89dff4462fc6a55276d773637f34442545c97747 Mon Sep 17 00:00:00 2001 From: elpekenin Date: Thu, 17 Apr 2025 21:27:39 +0200 Subject: [PATCH 1/7] initial implementation for #25163 --- quantum/action_util.c | 22 ++++++++++++++++++++++ quantum/action_util.h | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/quantum/action_util.c b/quantum/action_util.c index 9fe17f2124b..a466e213ada 100644 --- a/quantum/action_util.c +++ b/quantum/action_util.c @@ -336,6 +336,13 @@ void send_keyboard_report(void) { uint8_t get_mods(void) { return real_mods; } +/** \brief Get mods + * + * FIXME: needs doc + */ +mod_t get_mod_state(void) { + return (mod_t)get_mods(); +} /** \brief add mods * * FIXME: needs doc @@ -372,6 +379,13 @@ void clear_mods(void) { uint8_t get_weak_mods(void) { return weak_mods; } +/** \brief get weak mods + * + * FIXME: needs doc + */ +mod_t get_weak_mod_state(void) { + return (mod_t)get_weak_mods(); +} /** \brief add weak mods * * FIXME: needs doc @@ -434,6 +448,14 @@ uint8_t get_oneshot_mods(void) { return oneshot_mods; } +/** \brief get oneshot mods + * + * FIXME: needs doc + */ +mod_t get_oneshot_mod_state(void) { + return (mod_t)get_oneshot_mods(); +} + void add_oneshot_mods(uint8_t mods) { if ((oneshot_mods & mods) != mods) { # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) diff --git a/quantum/action_util.h b/quantum/action_util.h index d2ecb145bed..994e2f26268 100644 --- a/quantum/action_util.h +++ b/quantum/action_util.h @@ -25,6 +25,20 @@ along with this program. If not, see . extern "C" { #endif +typedef union { + uint8_t raw; + struct { + bool left_ctrl: 1; + bool left_shift: 1; + bool left_alt: 1; + bool left_gui: 1; + bool right_ctrl: 1; + bool right_shift: 1; + bool right_alt: 1; + bool right_gui: 1; + }; +} mod_t; + extern report_keyboard_t *keyboard_report; #ifdef NKRO_ENABLE extern report_nkro_t *nkro_report; @@ -47,6 +61,7 @@ inline void clear_keys(void) { /* modifier */ uint8_t get_mods(void); +mod_t get_mod_state(void); void add_mods(uint8_t mods); void del_mods(uint8_t mods); void set_mods(uint8_t mods); @@ -54,6 +69,7 @@ void clear_mods(void); /* weak modifier */ uint8_t get_weak_mods(void); +mod_t get_weak_mod_state(void); void add_weak_mods(uint8_t mods); void del_weak_mods(uint8_t mods); void set_weak_mods(uint8_t mods); @@ -61,6 +77,7 @@ void clear_weak_mods(void); /* oneshot modifier */ uint8_t get_oneshot_mods(void); +mod_t get_oneshot_mod_state(void); void add_oneshot_mods(uint8_t mods); void del_oneshot_mods(uint8_t mods); void set_oneshot_mods(uint8_t mods); @@ -68,6 +85,7 @@ void clear_oneshot_mods(void); bool has_oneshot_mods_timed_out(void); uint8_t get_oneshot_locked_mods(void); +mod_t get_oneshot_locked_mod_state(void); void add_oneshot_locked_mods(uint8_t mods); void set_oneshot_locked_mods(uint8_t mods); void clear_oneshot_locked_mods(void); From 6cbdc1597b18ae13e9f14b3da4f269a7eb77920a Mon Sep 17 00:00:00 2001 From: elpekenin Date: Thu, 17 Apr 2025 21:30:59 +0200 Subject: [PATCH 2/7] missed a func... --- quantum/action_util.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/quantum/action_util.c b/quantum/action_util.c index a466e213ada..94673e9622e 100644 --- a/quantum/action_util.c +++ b/quantum/action_util.c @@ -50,6 +50,9 @@ static uint8_t oneshot_locked_mods = 0; uint8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; } +mod_t get_oneshot_locked_mod_state(void) { + return (mod_t)get_oneshot_locked_mods(); +} void add_oneshot_locked_mods(uint8_t mods) { if ((oneshot_locked_mods & mods) != mods) { oneshot_locked_mods |= mods; From 4dc64618f259e48512a4c2c9a0b63aaf46b4f36d Mon Sep 17 00:00:00 2001 From: elpekenin Date: Fri, 18 Apr 2025 15:43:26 +0200 Subject: [PATCH 3/7] lint --- quantum/action_util.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/quantum/action_util.h b/quantum/action_util.h index 994e2f26268..95ae38882ce 100644 --- a/quantum/action_util.h +++ b/quantum/action_util.h @@ -28,14 +28,14 @@ extern "C" { typedef union { uint8_t raw; struct { - bool left_ctrl: 1; - bool left_shift: 1; - bool left_alt: 1; - bool left_gui: 1; - bool right_ctrl: 1; - bool right_shift: 1; - bool right_alt: 1; - bool right_gui: 1; + bool left_ctrl : 1; + bool left_shift : 1; + bool left_alt : 1; + bool left_gui : 1; + bool right_ctrl : 1; + bool right_shift : 1; + bool right_alt : 1; + bool right_gui : 1; }; } mod_t; From 04ebdf6136dda0512b39b2b6be946d4b142c5a8e Mon Sep 17 00:00:00 2001 From: elpekenin Date: Tue, 22 Apr 2025 20:52:16 +0200 Subject: [PATCH 4/7] add PR feedback --- quantum/action_util.c | 40 ++++++++++++++++++++++++---------------- quantum/action_util.h | 3 ++- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/quantum/action_util.c b/quantum/action_util.c index 94673e9622e..dbffd6a4649 100644 --- a/quantum/action_util.c +++ b/quantum/action_util.c @@ -47,9 +47,17 @@ extern inline void clear_keys(void); #ifndef NO_ACTION_ONESHOT static uint8_t oneshot_mods = 0; static uint8_t oneshot_locked_mods = 0; -uint8_t get_oneshot_locked_mods(void) { +/** + * @brief Retrieve current state of locked oneshot modifiers. + * + * @return Current state of the locked oneshot modifier keys as a bitmask. + */ +uint8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; } +/** + * Same as \ref get_oneshot_locked_mods but returns \ref mod_t for convenience. + */ mod_t get_oneshot_locked_mod_state(void) { return (mod_t)get_oneshot_locked_mods(); } @@ -332,16 +340,16 @@ void send_keyboard_report(void) { #endif } -/** \brief Get mods +/** + * @brief Retrieve current state of modifiers. * - * FIXME: needs doc + * @return Current state of the modifier keys as a bitmask. */ uint8_t get_mods(void) { return real_mods; } -/** \brief Get mods - * - * FIXME: needs doc +/** + * Same as \ref get_mods but returns \ref mod_t for convenience. */ mod_t get_mod_state(void) { return (mod_t)get_mods(); @@ -375,16 +383,16 @@ void clear_mods(void) { real_mods = 0; } -/** \brief get weak mods +/** + * @brief Retrieve current state of weak modifiers. * - * FIXME: needs doc + * @return Current state of the weak modifier keys as a bitmask. */ uint8_t get_weak_mods(void) { return weak_mods; } -/** \brief get weak mods - * - * FIXME: needs doc +/** + * Same as \ref get_weak_mods but returns \ref mod_t for convenience. */ mod_t get_weak_mod_state(void) { return (mod_t)get_weak_mods(); @@ -443,17 +451,17 @@ void clear_suppressed_override_mods(void) { #endif #ifndef NO_ACTION_ONESHOT -/** \brief get oneshot mods +/** + * @brief Retrieve current state of oneshot modifiers. * - * FIXME: needs doc + * @return Current state of the oneshot modifier keys as a bitmask. */ uint8_t get_oneshot_mods(void) { return oneshot_mods; } -/** \brief get oneshot mods - * - * FIXME: needs doc +/** + * Same as \ref get_oneshot_mods but returns \ref mod_t for convenience. */ mod_t get_oneshot_mod_state(void) { return (mod_t)get_oneshot_mods(); diff --git a/quantum/action_util.h b/quantum/action_util.h index 95ae38882ce..72b4c56d013 100644 --- a/quantum/action_util.h +++ b/quantum/action_util.h @@ -36,8 +36,9 @@ typedef union { bool right_shift : 1; bool right_alt : 1; bool right_gui : 1; - }; + } PACKED; } mod_t; +_Static_assert(sizeof(mod_t) == sizeof(uint8_t), "Invalid size for 'mod_t'"); extern report_keyboard_t *keyboard_report; #ifdef NKRO_ENABLE From fae7c04de01e11c7a520dd38791f4b4b0d34988b Mon Sep 17 00:00:00 2001 From: elpekenin Date: Wed, 23 Apr 2025 15:44:09 +0200 Subject: [PATCH 5/7] move `PACKED`, add it to `led_t` too --- quantum/action_util.h | 4 ++-- quantum/led.h | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/quantum/action_util.h b/quantum/action_util.h index 72b4c56d013..c9d27ef92dc 100644 --- a/quantum/action_util.h +++ b/quantum/action_util.h @@ -36,8 +36,8 @@ typedef union { bool right_shift : 1; bool right_alt : 1; bool right_gui : 1; - } PACKED; -} mod_t; + }; +} PACKED mod_t; _Static_assert(sizeof(mod_t) == sizeof(uint8_t), "Invalid size for 'mod_t'"); extern report_keyboard_t *keyboard_report; diff --git a/quantum/led.h b/quantum/led.h index 669e93e1944..85819b20470 100644 --- a/quantum/led.h +++ b/quantum/led.h @@ -19,6 +19,7 @@ along with this program. If not, see . #include #include +#include "util.h" /* FIXME: Add doxygen comments here. */ @@ -36,7 +37,8 @@ typedef union { bool kana : 1; uint8_t reserved : 3; }; -} led_t; +} PACKED led_t; +_Static_assert(sizeof(led_t) == sizeof(uint8_t), "Invalid size for 'led_t'"); void led_set(uint8_t usb_led); From ec1d304a454385f4ca6e85d9965e973f76d29362 Mon Sep 17 00:00:00 2001 From: elpekenin Date: Mon, 19 May 2025 14:08:07 +0200 Subject: [PATCH 6/7] PR feedback --- quantum/led.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/quantum/led.h b/quantum/led.h index 85819b20470..669e93e1944 100644 --- a/quantum/led.h +++ b/quantum/led.h @@ -19,7 +19,6 @@ along with this program. If not, see . #include #include -#include "util.h" /* FIXME: Add doxygen comments here. */ @@ -37,8 +36,7 @@ typedef union { bool kana : 1; uint8_t reserved : 3; }; -} PACKED led_t; -_Static_assert(sizeof(led_t) == sizeof(uint8_t), "Invalid size for 'led_t'"); +} led_t; void led_set(uint8_t usb_led); From 2aef65c3fc22936ddbeb8615b631301e3e7a5030 Mon Sep 17 00:00:00 2001 From: elpekenin Date: Thu, 22 May 2025 16:21:32 +0200 Subject: [PATCH 7/7] use `STATIC_ASSERT` --- quantum/action_util.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/quantum/action_util.h b/quantum/action_util.h index c9d27ef92dc..8b1974cd321 100644 --- a/quantum/action_util.h +++ b/quantum/action_util.h @@ -18,6 +18,8 @@ along with this program. If not, see . #pragma once #include + +#include "compiler_support.h" #include "report.h" #include "modifiers.h" @@ -38,7 +40,7 @@ typedef union { bool right_gui : 1; }; } PACKED mod_t; -_Static_assert(sizeof(mod_t) == sizeof(uint8_t), "Invalid size for 'mod_t'"); +STATIC_ASSERT(sizeof(mod_t) == sizeof(uint8_t), "Invalid size for 'mod_t'"); extern report_keyboard_t *keyboard_report; #ifdef NKRO_ENABLE