summaryrefslogtreecommitdiff
path: root/quantum/process_keycode
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2024-10-13 03:43:50 +1100
committerGitHub <noreply@github.com>2024-10-12 18:43:50 +0200
commit6fa11bf21913b5ccb531acc3c2baec963f4d384a (patch)
treeaaf6188a4579949cc1fbac61d0fee5234b97996a /quantum/process_keycode
parent5c97a78ce6ab45643dcb420ba2ad20c30dcd5b8a (diff)
Separate RGBLight/RGB Matrix keycode handling (#23679)
* Separate RGBLight/RGB Matrix keycode handling * Remove `_DISABLE_KEYCODES` handling * Update RGB Matrix keycode docs * Update underglow keycodes for previously migrated boards * Update keycodes for boards with custom handling * Fix typos * Fix bad merge
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r--quantum/process_keycode/process_rgb.c226
-rw-r--r--quantum/process_keycode/process_rgb.h22
2 files changed, 0 insertions, 248 deletions
diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c
deleted file mode 100644
index b113d1c1e7..0000000000
--- a/quantum/process_keycode/process_rgb.c
+++ /dev/null
@@ -1,226 +0,0 @@
1/* Copyright 2019
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#include "process_rgb.h"
17#include "action_util.h"
18
19#ifdef RGB_MATRIX_ENABLE
20# include "rgb_matrix.h"
21#endif
22#ifdef RGBLIGHT_ENABLE
23# include "rgblight.h"
24#endif
25
26typedef void (*rgb_func_pointer)(void);
27
28/**
29 * Wrapper for inc/dec rgb keycode
30 *
31 * noinline to optimise for firmware size not speed (not in hot path)
32 */
33#if (defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)) || (defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES))
34static void __attribute__((noinline)) handleKeycodeRGB(const uint8_t is_shifted, const rgb_func_pointer inc_func, const rgb_func_pointer dec_func) {
35 if (is_shifted) {
36 dec_func();
37 } else {
38 inc_func();
39 }
40}
41#endif
42
43/**
44 * Wrapper for animation mode
45 * - if not in animation family -> jump to that animation
46 * - otherwise -> wrap round animation speed
47 *
48 * noinline to optimise for firmware size not speed (not in hot path)
49 */
50static void __attribute__((noinline, unused)) handleKeycodeRGBMode(const uint8_t start, const uint8_t end) {
51 if ((start <= rgblight_get_mode()) && (rgblight_get_mode() < end)) {
52 rgblight_step();
53 } else {
54 rgblight_mode(start);
55 }
56}
57
58/**
59 * Handle keycodes for both rgblight and rgbmatrix
60 */
61bool process_rgb(const uint16_t keycode, const keyrecord_t *record) {
62 // need to trigger on key-up for edge-case issue
63#ifndef RGB_TRIGGER_ON_KEYDOWN
64 if (!record->event.pressed) {
65#else
66 if (record->event.pressed) {
67#endif
68#if (defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)) || (defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES))
69 uint8_t shifted = get_mods() & MOD_MASK_SHIFT;
70#endif
71 switch (keycode) {
72 case QK_UNDERGLOW_TOGGLE:
73#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
74 rgblight_toggle();
75#endif
76#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
77 rgb_matrix_toggle();
78#endif
79 return false;
80 case QK_UNDERGLOW_MODE_NEXT:
81#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
82 handleKeycodeRGB(shifted, rgblight_step, rgblight_step_reverse);
83#endif
84#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
85 handleKeycodeRGB(shifted, rgb_matrix_step, rgb_matrix_step_reverse);
86#endif
87 return false;
88 case QK_UNDERGLOW_MODE_PREVIOUS:
89#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
90 handleKeycodeRGB(shifted, rgblight_step_reverse, rgblight_step);
91#endif
92#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
93 handleKeycodeRGB(shifted, rgb_matrix_step_reverse, rgb_matrix_step);
94#endif
95 return false;
96 case QK_UNDERGLOW_HUE_UP:
97#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
98 handleKeycodeRGB(shifted, rgblight_increase_hue, rgblight_decrease_hue);
99#endif
100#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
101 handleKeycodeRGB(shifted, rgb_matrix_increase_hue, rgb_matrix_decrease_hue);
102#endif
103 return false;
104 case QK_UNDERGLOW_HUE_DOWN:
105#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
106 handleKeycodeRGB(shifted, rgblight_decrease_hue, rgblight_increase_hue);
107#endif
108#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
109 handleKeycodeRGB(shifted, rgb_matrix_decrease_hue, rgb_matrix_increase_hue);
110#endif
111 return false;
112 case QK_UNDERGLOW_SATURATION_UP:
113#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
114 handleKeycodeRGB(shifted, rgblight_increase_sat, rgblight_decrease_sat);
115#endif
116#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
117 handleKeycodeRGB(shifted, rgb_matrix_increase_sat, rgb_matrix_decrease_sat);
118#endif
119 return false;
120 case QK_UNDERGLOW_SATURATION_DOWN:
121#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
122 handleKeycodeRGB(shifted, rgblight_decrease_sat, rgblight_increase_sat);
123#endif
124#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
125 handleKeycodeRGB(shifted, rgb_matrix_decrease_sat, rgb_matrix_increase_sat);
126#endif
127 return false;
128 case QK_UNDERGLOW_VALUE_UP:
129#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
130 handleKeycodeRGB(shifted, rgblight_increase_val, rgblight_decrease_val);
131#endif
132#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
133 handleKeycodeRGB(shifted, rgb_matrix_increase_val, rgb_matrix_decrease_val);
134#endif
135 return false;
136 case QK_UNDERGLOW_VALUE_DOWN:
137#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
138 handleKeycodeRGB(shifted, rgblight_decrease_val, rgblight_increase_val);
139#endif
140#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
141 handleKeycodeRGB(shifted, rgb_matrix_decrease_val, rgb_matrix_increase_val);
142#endif
143 return false;
144 case QK_UNDERGLOW_SPEED_UP:
145#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
146 handleKeycodeRGB(shifted, rgblight_increase_speed, rgblight_decrease_speed);
147#endif
148#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
149 handleKeycodeRGB(shifted, rgb_matrix_increase_speed, rgb_matrix_decrease_speed);
150#endif
151 return false;
152 case QK_UNDERGLOW_SPEED_DOWN:
153#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
154 handleKeycodeRGB(shifted, rgblight_decrease_speed, rgblight_increase_speed);
155#endif
156#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
157 handleKeycodeRGB(shifted, rgb_matrix_decrease_speed, rgb_matrix_increase_speed);
158#endif
159 return false;
160 case RGB_MODE_PLAIN:
161#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
162 rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
163#endif
164#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
165 rgb_matrix_mode(RGB_MATRIX_SOLID_COLOR);
166#endif
167 return false;
168 case RGB_MODE_BREATHE:
169#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_BREATHING)
170 handleKeycodeRGBMode(RGBLIGHT_MODE_BREATHING, RGBLIGHT_MODE_BREATHING_end);
171#endif
172#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) && defined(ENABLE_RGB_MATRIX_BREATHING)
173 rgb_matrix_mode(RGB_MATRIX_BREATHING);
174#endif
175 return false;
176 case RGB_MODE_RAINBOW:
177#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_RAINBOW_MOOD)
178 handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_MOOD, RGBLIGHT_MODE_RAINBOW_MOOD_end);
179#endif
180#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) && defined(ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT)
181 rgb_matrix_mode(RGB_MATRIX_CYCLE_LEFT_RIGHT);
182#endif
183 return false;
184 case RGB_MODE_SWIRL:
185#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL)
186 handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_SWIRL, RGBLIGHT_MODE_RAINBOW_SWIRL_end);
187#endif
188#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) && defined(ENABLE_RGB_MATRIX_CYCLE_PINWHEEL)
189 rgb_matrix_mode(RGB_MATRIX_CYCLE_PINWHEEL);
190#endif
191 return false;
192 case RGB_MODE_SNAKE:
193#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_SNAKE)
194 handleKeycodeRGBMode(RGBLIGHT_MODE_SNAKE, RGBLIGHT_MODE_SNAKE_end);
195#endif
196 return false;
197 case RGB_MODE_KNIGHT:
198#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_KNIGHT)
199 handleKeycodeRGBMode(RGBLIGHT_MODE_KNIGHT, RGBLIGHT_MODE_KNIGHT_end);
200#endif
201 return false;
202 case RGB_MODE_XMAS:
203#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_CHRISTMAS)
204 rgblight_mode(RGBLIGHT_MODE_CHRISTMAS);
205#endif
206 return false;
207 case RGB_MODE_GRADIENT:
208#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_STATIC_GRADIENT)
209 handleKeycodeRGBMode(RGBLIGHT_MODE_STATIC_GRADIENT, RGBLIGHT_MODE_STATIC_GRADIENT_end);
210#endif
211 return false;
212 case RGB_MODE_RGBTEST:
213#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_RGB_TEST)
214 rgblight_mode(RGBLIGHT_MODE_RGB_TEST);
215#endif
216 return false;
217 case RGB_MODE_TWINKLE:
218#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_TWINKLE)
219 handleKeycodeRGBMode(RGBLIGHT_MODE_TWINKLE, RGBLIGHT_MODE_TWINKLE_end);
220#endif
221 return false;
222 }
223 }
224
225 return true;
226}
diff --git a/quantum/process_keycode/process_rgb.h b/quantum/process_keycode/process_rgb.h
deleted file mode 100644
index b1069d4bb6..0000000000
--- a/quantum/process_keycode/process_rgb.h
+++ /dev/null
@@ -1,22 +0,0 @@
1/* Copyright 2019
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#pragma once
17
18#include <stdint.h>
19#include <stdbool.h>
20#include "action.h"
21
22bool process_rgb(const uint16_t keycode, const keyrecord_t *record);