summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/action_util.c47
-rw-r--r--quantum/action_util.h21
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
47static uint8_t oneshot_mods = 0; 47static uint8_t oneshot_mods = 0;
48static uint8_t oneshot_locked_mods = 0; 48static uint8_t oneshot_locked_mods = 0;
49uint8_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 */
54uint8_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 */
60mod_t get_oneshot_locked_mod_state(void) {
61 return (mod_t)get_oneshot_locked_mods();
62}
52void add_oneshot_locked_mods(uint8_t mods) { 63void 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 */
333uint8_t get_mods(void) { 345uint8_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 */
351mod_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 */
369uint8_t get_weak_mods(void) { 388uint8_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 */
394mod_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 */
430uint8_t get_oneshot_mods(void) { 456uint8_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 */
463mod_t get_oneshot_mod_state(void) {
464 return (mod_t)get_oneshot_mods();
465}
466
434void add_oneshot_mods(uint8_t mods) { 467void 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/>.
25extern "C" { 27extern "C" {
26#endif 28#endif
27 29
30typedef 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;
43STATIC_ASSERT(sizeof(mod_t) == sizeof(uint8_t), "Invalid size for 'mod_t'");
44
28extern report_keyboard_t *keyboard_report; 45extern report_keyboard_t *keyboard_report;
29#ifdef NKRO_ENABLE 46#ifdef NKRO_ENABLE
30extern report_nkro_t *nkro_report; 47extern report_nkro_t *nkro_report;
@@ -47,6 +64,7 @@ inline void clear_keys(void) {
47 64
48/* modifier */ 65/* modifier */
49uint8_t get_mods(void); 66uint8_t get_mods(void);
67mod_t get_mod_state(void);
50void add_mods(uint8_t mods); 68void add_mods(uint8_t mods);
51void del_mods(uint8_t mods); 69void del_mods(uint8_t mods);
52void set_mods(uint8_t mods); 70void set_mods(uint8_t mods);
@@ -54,6 +72,7 @@ void clear_mods(void);
54 72
55/* weak modifier */ 73/* weak modifier */
56uint8_t get_weak_mods(void); 74uint8_t get_weak_mods(void);
75mod_t get_weak_mod_state(void);
57void add_weak_mods(uint8_t mods); 76void add_weak_mods(uint8_t mods);
58void del_weak_mods(uint8_t mods); 77void del_weak_mods(uint8_t mods);
59void set_weak_mods(uint8_t mods); 78void set_weak_mods(uint8_t mods);
@@ -61,6 +80,7 @@ void clear_weak_mods(void);
61 80
62/* oneshot modifier */ 81/* oneshot modifier */
63uint8_t get_oneshot_mods(void); 82uint8_t get_oneshot_mods(void);
83mod_t get_oneshot_mod_state(void);
64void add_oneshot_mods(uint8_t mods); 84void add_oneshot_mods(uint8_t mods);
65void del_oneshot_mods(uint8_t mods); 85void del_oneshot_mods(uint8_t mods);
66void set_oneshot_mods(uint8_t mods); 86void set_oneshot_mods(uint8_t mods);
@@ -68,6 +88,7 @@ void clear_oneshot_mods(void);
68bool has_oneshot_mods_timed_out(void); 88bool has_oneshot_mods_timed_out(void);
69 89
70uint8_t get_oneshot_locked_mods(void); 90uint8_t get_oneshot_locked_mods(void);
91mod_t get_oneshot_locked_mod_state(void);
71void add_oneshot_locked_mods(uint8_t mods); 92void add_oneshot_locked_mods(uint8_t mods);
72void set_oneshot_locked_mods(uint8_t mods); 93void set_oneshot_locked_mods(uint8_t mods);
73void clear_oneshot_locked_mods(void); 94void clear_oneshot_locked_mods(void);