diff options
| author | Pablo MartÃnez <58857054+elpekenin@users.noreply.github.com> | 2025-09-30 16:52:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-30 15:52:43 +0100 |
| commit | bbd6e8ab340bb4b3f25671fea59fd608397e8a34 (patch) | |
| tree | 0e23e03f465054450bc4a950e427622b881ef9e8 | |
| parent | 24bc4aef03ea3aec8cdb515ffe0942e4f6939c4a (diff) | |
[Feature] Implement `mod_t` packed struct (#25168)
| -rw-r--r-- | quantum/action_util.c | 47 | ||||
| -rw-r--r-- | quantum/action_util.h | 21 |
2 files changed, 61 insertions, 7 deletions
diff --git a/quantum/action_util.c b/quantum/action_util.c index e821e113ef..0996ff908e 100644 --- a/quantum/action_util.c +++ b/quantum/action_util.c | |||
| @@ -46,9 +46,20 @@ extern inline void clear_keys(void); | |||
| 46 | #ifndef NO_ACTION_ONESHOT | 46 | #ifndef NO_ACTION_ONESHOT |
| 47 | static uint8_t oneshot_mods = 0; | 47 | static uint8_t oneshot_mods = 0; |
| 48 | static uint8_t oneshot_locked_mods = 0; | 48 | static uint8_t oneshot_locked_mods = 0; |
| 49 | uint8_t get_oneshot_locked_mods(void) { | 49 | /** |
| 50 | * @brief Retrieve current state of locked oneshot modifiers. | ||
| 51 | * | ||
| 52 | * @return Current state of the locked oneshot modifier keys as a bitmask. | ||
| 53 | */ | ||
| 54 | uint8_t get_oneshot_locked_mods(void) { | ||
| 50 | return oneshot_locked_mods; | 55 | return oneshot_locked_mods; |
| 51 | } | 56 | } |
| 57 | /** | ||
| 58 | * Same as \ref get_oneshot_locked_mods but returns \ref mod_t for convenience. | ||
| 59 | */ | ||
| 60 | mod_t get_oneshot_locked_mod_state(void) { | ||
| 61 | return (mod_t)get_oneshot_locked_mods(); | ||
| 62 | } | ||
| 52 | void add_oneshot_locked_mods(uint8_t mods) { | 63 | void add_oneshot_locked_mods(uint8_t mods) { |
| 53 | if ((oneshot_locked_mods & mods) != mods) { | 64 | if ((oneshot_locked_mods & mods) != mods) { |
| 54 | oneshot_locked_mods |= mods; | 65 | oneshot_locked_mods |= mods; |
| @@ -326,13 +337,20 @@ void send_keyboard_report(void) { | |||
| 326 | send_6kro_report(); | 337 | send_6kro_report(); |
| 327 | } | 338 | } |
| 328 | 339 | ||
| 329 | /** \brief Get mods | 340 | /** |
| 341 | * @brief Retrieve current state of modifiers. | ||
| 330 | * | 342 | * |
| 331 | * FIXME: needs doc | 343 | * @return Current state of the modifier keys as a bitmask. |
| 332 | */ | 344 | */ |
| 333 | uint8_t get_mods(void) { | 345 | uint8_t get_mods(void) { |
| 334 | return real_mods; | 346 | return real_mods; |
| 335 | } | 347 | } |
| 348 | /** | ||
| 349 | * Same as \ref get_mods but returns \ref mod_t for convenience. | ||
| 350 | */ | ||
| 351 | mod_t get_mod_state(void) { | ||
| 352 | return (mod_t)get_mods(); | ||
| 353 | } | ||
| 336 | /** \brief add mods | 354 | /** \brief add mods |
| 337 | * | 355 | * |
| 338 | * FIXME: needs doc | 356 | * FIXME: needs doc |
| @@ -362,13 +380,20 @@ void clear_mods(void) { | |||
| 362 | real_mods = 0; | 380 | real_mods = 0; |
| 363 | } | 381 | } |
| 364 | 382 | ||
| 365 | /** \brief get weak mods | 383 | /** |
| 384 | * @brief Retrieve current state of weak modifiers. | ||
| 366 | * | 385 | * |
| 367 | * FIXME: needs doc | 386 | * @return Current state of the weak modifier keys as a bitmask. |
| 368 | */ | 387 | */ |
| 369 | uint8_t get_weak_mods(void) { | 388 | uint8_t get_weak_mods(void) { |
| 370 | return weak_mods; | 389 | return weak_mods; |
| 371 | } | 390 | } |
| 391 | /** | ||
| 392 | * Same as \ref get_weak_mods but returns \ref mod_t for convenience. | ||
| 393 | */ | ||
| 394 | mod_t get_weak_mod_state(void) { | ||
| 395 | return (mod_t)get_weak_mods(); | ||
| 396 | } | ||
| 372 | /** \brief add weak mods | 397 | /** \brief add weak mods |
| 373 | * | 398 | * |
| 374 | * FIXME: needs doc | 399 | * FIXME: needs doc |
| @@ -423,14 +448,22 @@ void clear_suppressed_override_mods(void) { | |||
| 423 | #endif | 448 | #endif |
| 424 | 449 | ||
| 425 | #ifndef NO_ACTION_ONESHOT | 450 | #ifndef NO_ACTION_ONESHOT |
| 426 | /** \brief get oneshot mods | 451 | /** |
| 452 | * @brief Retrieve current state of oneshot modifiers. | ||
| 427 | * | 453 | * |
| 428 | * FIXME: needs doc | 454 | * @return Current state of the oneshot modifier keys as a bitmask. |
| 429 | */ | 455 | */ |
| 430 | uint8_t get_oneshot_mods(void) { | 456 | uint8_t get_oneshot_mods(void) { |
| 431 | return oneshot_mods; | 457 | return oneshot_mods; |
| 432 | } | 458 | } |
| 433 | 459 | ||
| 460 | /** | ||
| 461 | * Same as \ref get_oneshot_mods but returns \ref mod_t for convenience. | ||
| 462 | */ | ||
| 463 | mod_t get_oneshot_mod_state(void) { | ||
| 464 | return (mod_t)get_oneshot_mods(); | ||
| 465 | } | ||
| 466 | |||
| 434 | void add_oneshot_mods(uint8_t mods) { | 467 | void add_oneshot_mods(uint8_t mods) { |
| 435 | if ((oneshot_mods & mods) != mods) { | 468 | if ((oneshot_mods & mods) != mods) { |
| 436 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 469 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
diff --git a/quantum/action_util.h b/quantum/action_util.h index d2ecb145be..8b1974cd32 100644 --- a/quantum/action_util.h +++ b/quantum/action_util.h | |||
| @@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 18 | #pragma once | 18 | #pragma once |
| 19 | 19 | ||
| 20 | #include <stdint.h> | 20 | #include <stdint.h> |
| 21 | |||
| 22 | #include "compiler_support.h" | ||
| 21 | #include "report.h" | 23 | #include "report.h" |
| 22 | #include "modifiers.h" | 24 | #include "modifiers.h" |
| 23 | 25 | ||
| @@ -25,6 +27,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 25 | extern "C" { | 27 | extern "C" { |
| 26 | #endif | 28 | #endif |
| 27 | 29 | ||
| 30 | typedef union { | ||
| 31 | uint8_t raw; | ||
| 32 | struct { | ||
| 33 | bool left_ctrl : 1; | ||
| 34 | bool left_shift : 1; | ||
| 35 | bool left_alt : 1; | ||
| 36 | bool left_gui : 1; | ||
| 37 | bool right_ctrl : 1; | ||
| 38 | bool right_shift : 1; | ||
| 39 | bool right_alt : 1; | ||
| 40 | bool right_gui : 1; | ||
| 41 | }; | ||
| 42 | } PACKED mod_t; | ||
| 43 | STATIC_ASSERT(sizeof(mod_t) == sizeof(uint8_t), "Invalid size for 'mod_t'"); | ||
| 44 | |||
| 28 | extern report_keyboard_t *keyboard_report; | 45 | extern report_keyboard_t *keyboard_report; |
| 29 | #ifdef NKRO_ENABLE | 46 | #ifdef NKRO_ENABLE |
| 30 | extern report_nkro_t *nkro_report; | 47 | extern report_nkro_t *nkro_report; |
| @@ -47,6 +64,7 @@ inline void clear_keys(void) { | |||
| 47 | 64 | ||
| 48 | /* modifier */ | 65 | /* modifier */ |
| 49 | uint8_t get_mods(void); | 66 | uint8_t get_mods(void); |
| 67 | mod_t get_mod_state(void); | ||
| 50 | void add_mods(uint8_t mods); | 68 | void add_mods(uint8_t mods); |
| 51 | void del_mods(uint8_t mods); | 69 | void del_mods(uint8_t mods); |
| 52 | void set_mods(uint8_t mods); | 70 | void set_mods(uint8_t mods); |
| @@ -54,6 +72,7 @@ void clear_mods(void); | |||
| 54 | 72 | ||
| 55 | /* weak modifier */ | 73 | /* weak modifier */ |
| 56 | uint8_t get_weak_mods(void); | 74 | uint8_t get_weak_mods(void); |
| 75 | mod_t get_weak_mod_state(void); | ||
| 57 | void add_weak_mods(uint8_t mods); | 76 | void add_weak_mods(uint8_t mods); |
| 58 | void del_weak_mods(uint8_t mods); | 77 | void del_weak_mods(uint8_t mods); |
| 59 | void set_weak_mods(uint8_t mods); | 78 | void set_weak_mods(uint8_t mods); |
| @@ -61,6 +80,7 @@ void clear_weak_mods(void); | |||
| 61 | 80 | ||
| 62 | /* oneshot modifier */ | 81 | /* oneshot modifier */ |
| 63 | uint8_t get_oneshot_mods(void); | 82 | uint8_t get_oneshot_mods(void); |
| 83 | mod_t get_oneshot_mod_state(void); | ||
| 64 | void add_oneshot_mods(uint8_t mods); | 84 | void add_oneshot_mods(uint8_t mods); |
| 65 | void del_oneshot_mods(uint8_t mods); | 85 | void del_oneshot_mods(uint8_t mods); |
| 66 | void set_oneshot_mods(uint8_t mods); | 86 | void set_oneshot_mods(uint8_t mods); |
| @@ -68,6 +88,7 @@ void clear_oneshot_mods(void); | |||
| 68 | bool has_oneshot_mods_timed_out(void); | 88 | bool has_oneshot_mods_timed_out(void); |
| 69 | 89 | ||
| 70 | uint8_t get_oneshot_locked_mods(void); | 90 | uint8_t get_oneshot_locked_mods(void); |
| 91 | mod_t get_oneshot_locked_mod_state(void); | ||
| 71 | void add_oneshot_locked_mods(uint8_t mods); | 92 | void add_oneshot_locked_mods(uint8_t mods); |
| 72 | void set_oneshot_locked_mods(uint8_t mods); | 93 | void set_oneshot_locked_mods(uint8_t mods); |
| 73 | void clear_oneshot_locked_mods(void); | 94 | void clear_oneshot_locked_mods(void); |
