diff options
author | skullY <skullydazed@gmail.com> | 2019-08-30 11:19:03 -0700 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-08-30 15:01:52 -0700 |
commit | b624f32f944acdc59dcb130674c09090c5c404cb (patch) | |
tree | bc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /quantum/rgb_matrix.c | |
parent | 61af76a10d00aba185b8338604171de490a13e3b (diff) | |
download | qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip |
clang-format changes
Diffstat (limited to 'quantum/rgb_matrix.c')
-rw-r--r-- | quantum/rgb_matrix.c | 624 |
1 files changed, 295 insertions, 329 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index f649525cc..55a6f74be 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c | |||
@@ -16,7 +16,6 @@ | |||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | |||
20 | #include "rgb_matrix.h" | 19 | #include "rgb_matrix.h" |
21 | #include "progmem.h" | 20 | #include "progmem.h" |
22 | #include "config.h" | 21 | #include "config.h" |
@@ -27,9 +26,9 @@ | |||
27 | #include "lib/lib8tion/lib8tion.h" | 26 | #include "lib/lib8tion/lib8tion.h" |
28 | 27 | ||
29 | #ifndef RGB_MATRIX_CENTER | 28 | #ifndef RGB_MATRIX_CENTER |
30 | const point_t k_rgb_matrix_center = { 112, 32 }; | 29 | const point_t k_rgb_matrix_center = {112, 32}; |
31 | #else | 30 | #else |
32 | const point_t k_rgb_matrix_center = RGB_MATRIX_CENTER; | 31 | const point_t k_rgb_matrix_center = RGB_MATRIX_CENTER; |
33 | #endif | 32 | #endif |
34 | 33 | ||
35 | // Generic effect runners | 34 | // Generic effect runners |
@@ -47,10 +46,10 @@ | |||
47 | 46 | ||
48 | #include "rgb_matrix_animations/rgb_matrix_effects.inc" | 47 | #include "rgb_matrix_animations/rgb_matrix_effects.inc" |
49 | #ifdef RGB_MATRIX_CUSTOM_KB | 48 | #ifdef RGB_MATRIX_CUSTOM_KB |
50 | #include "rgb_matrix_kb.inc" | 49 | # include "rgb_matrix_kb.inc" |
51 | #endif | 50 | #endif |
52 | #ifdef RGB_MATRIX_CUSTOM_USER | 51 | #ifdef RGB_MATRIX_CUSTOM_USER |
53 | #include "rgb_matrix_user.inc" | 52 | # include "rgb_matrix_user.inc" |
54 | #endif | 53 | #endif |
55 | 54 | ||
56 | #undef RGB_MATRIX_CUSTOM_EFFECT_IMPLS | 55 | #undef RGB_MATRIX_CUSTOM_EFFECT_IMPLS |
@@ -59,48 +58,48 @@ | |||
59 | // ------------------------------------------ | 58 | // ------------------------------------------ |
60 | 59 | ||
61 | #ifndef RGB_DISABLE_AFTER_TIMEOUT | 60 | #ifndef RGB_DISABLE_AFTER_TIMEOUT |
62 | #define RGB_DISABLE_AFTER_TIMEOUT 0 | 61 | # define RGB_DISABLE_AFTER_TIMEOUT 0 |
63 | #endif | 62 | #endif |
64 | 63 | ||
65 | #ifndef RGB_DISABLE_WHEN_USB_SUSPENDED | 64 | #ifndef RGB_DISABLE_WHEN_USB_SUSPENDED |
66 | #define RGB_DISABLE_WHEN_USB_SUSPENDED false | 65 | # define RGB_DISABLE_WHEN_USB_SUSPENDED false |
67 | #endif | 66 | #endif |
68 | 67 | ||
69 | #if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX | 68 | #if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX |
70 | #undef RGB_MATRIX_MAXIMUM_BRIGHTNESS | 69 | # undef RGB_MATRIX_MAXIMUM_BRIGHTNESS |
71 | #define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX | 70 | # define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX |
72 | #endif | 71 | #endif |
73 | 72 | ||
74 | #if !defined(RGB_MATRIX_HUE_STEP) | 73 | #if !defined(RGB_MATRIX_HUE_STEP) |
75 | #define RGB_MATRIX_HUE_STEP 8 | 74 | # define RGB_MATRIX_HUE_STEP 8 |
76 | #endif | 75 | #endif |
77 | 76 | ||
78 | #if !defined(RGB_MATRIX_SAT_STEP) | 77 | #if !defined(RGB_MATRIX_SAT_STEP) |
79 | #define RGB_MATRIX_SAT_STEP 16 | 78 | # define RGB_MATRIX_SAT_STEP 16 |
80 | #endif | 79 | #endif |
81 | 80 | ||
82 | #if !defined(RGB_MATRIX_VAL_STEP) | 81 | #if !defined(RGB_MATRIX_VAL_STEP) |
83 | #define RGB_MATRIX_VAL_STEP 16 | 82 | # define RGB_MATRIX_VAL_STEP 16 |
84 | #endif | 83 | #endif |
85 | 84 | ||
86 | #if !defined(RGB_MATRIX_SPD_STEP) | 85 | #if !defined(RGB_MATRIX_SPD_STEP) |
87 | #define RGB_MATRIX_SPD_STEP 16 | 86 | # define RGB_MATRIX_SPD_STEP 16 |
88 | #endif | 87 | #endif |
89 | 88 | ||
90 | #if !defined(RGB_MATRIX_STARTUP_MODE) | 89 | #if !defined(RGB_MATRIX_STARTUP_MODE) |
91 | #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT | 90 | # ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT |
92 | #define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT | 91 | # define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT |
93 | #else | 92 | # else |
94 | // fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace | 93 | // fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace |
95 | #define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_SOLID_COLOR | 94 | # define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_SOLID_COLOR |
96 | #endif | 95 | # endif |
97 | #endif | 96 | #endif |
98 | 97 | ||
99 | bool g_suspend_state = false; | 98 | bool g_suspend_state = false; |
100 | 99 | ||
101 | rgb_config_t rgb_matrix_config; | 100 | rgb_config_t rgb_matrix_config; |
102 | 101 | ||
103 | rgb_counters_t g_rgb_counters; | 102 | rgb_counters_t g_rgb_counters; |
104 | static uint32_t rgb_counters_buffer; | 103 | static uint32_t rgb_counters_buffer; |
105 | 104 | ||
106 | #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS | 105 | #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS |
@@ -108,454 +107,421 @@ uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}}; | |||
108 | #endif | 107 | #endif |
109 | 108 | ||
110 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | 109 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
111 | last_hit_t g_last_hit_tracker; | 110 | last_hit_t g_last_hit_tracker; |
112 | static last_hit_t last_hit_buffer; | 111 | static last_hit_t last_hit_buffer; |
113 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | 112 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED |
114 | 113 | ||
115 | void eeconfig_read_rgb_matrix(void) { | 114 | void eeconfig_read_rgb_matrix(void) { eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } |
116 | eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); | ||
117 | } | ||
118 | 115 | ||
119 | void eeconfig_update_rgb_matrix(void) { | 116 | void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } |
120 | eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); | ||
121 | } | ||
122 | 117 | ||
123 | void eeconfig_update_rgb_matrix_default(void) { | 118 | void eeconfig_update_rgb_matrix_default(void) { |
124 | dprintf("eeconfig_update_rgb_matrix_default\n"); | 119 | dprintf("eeconfig_update_rgb_matrix_default\n"); |
125 | rgb_matrix_config.enable = 1; | 120 | rgb_matrix_config.enable = 1; |
126 | rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE; | 121 | rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE; |
127 | rgb_matrix_config.hsv = (HSV){ 0, UINT8_MAX, RGB_MATRIX_MAXIMUM_BRIGHTNESS }; | 122 | rgb_matrix_config.hsv = (HSV){0, UINT8_MAX, RGB_MATRIX_MAXIMUM_BRIGHTNESS}; |
128 | rgb_matrix_config.speed = UINT8_MAX / 2; | 123 | rgb_matrix_config.speed = UINT8_MAX / 2; |
129 | eeconfig_update_rgb_matrix(); | 124 | eeconfig_update_rgb_matrix(); |
130 | } | 125 | } |
131 | 126 | ||
132 | void eeconfig_debug_rgb_matrix(void) { | 127 | void eeconfig_debug_rgb_matrix(void) { |
133 | dprintf("rgb_matrix_config eprom\n"); | 128 | dprintf("rgb_matrix_config eprom\n"); |
134 | dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable); | 129 | dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable); |
135 | dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode); | 130 | dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode); |
136 | dprintf("rgb_matrix_config.hsv.h = %d\n", rgb_matrix_config.hsv.h); | 131 | dprintf("rgb_matrix_config.hsv.h = %d\n", rgb_matrix_config.hsv.h); |
137 | dprintf("rgb_matrix_config.hsv.s = %d\n", rgb_matrix_config.hsv.s); | 132 | dprintf("rgb_matrix_config.hsv.s = %d\n", rgb_matrix_config.hsv.s); |
138 | dprintf("rgb_matrix_config.hsv.v = %d\n", rgb_matrix_config.hsv.v); | 133 | dprintf("rgb_matrix_config.hsv.v = %d\n", rgb_matrix_config.hsv.v); |
139 | dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed); | 134 | dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed); |
140 | } | 135 | } |
141 | 136 | ||
142 | __attribute__ ((weak)) | 137 | __attribute__((weak)) uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; } |
143 | uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { | ||
144 | return 0; | ||
145 | } | ||
146 | 138 | ||
147 | uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) { | 139 | uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) { |
148 | uint8_t led_count = rgb_matrix_map_row_column_to_led_kb(row, column, led_i); | 140 | uint8_t led_count = rgb_matrix_map_row_column_to_led_kb(row, column, led_i); |
149 | uint8_t led_index = g_led_config.matrix_co[row][column]; | 141 | uint8_t led_index = g_led_config.matrix_co[row][column]; |
150 | if (led_index != NO_LED) { | 142 | if (led_index != NO_LED) { |
151 | led_i[led_count] = led_index; | 143 | led_i[led_count] = led_index; |
152 | led_count++; | 144 | led_count++; |
153 | } | 145 | } |
154 | return led_count; | 146 | return led_count; |
155 | } | 147 | } |
156 | 148 | ||
157 | void rgb_matrix_update_pwm_buffers(void) { | 149 | void rgb_matrix_update_pwm_buffers(void) { rgb_matrix_driver.flush(); } |
158 | rgb_matrix_driver.flush(); | ||
159 | } | ||
160 | 150 | ||
161 | void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) { | 151 | void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color(index, red, green, blue); } |
162 | rgb_matrix_driver.set_color(index, red, green, blue); | ||
163 | } | ||
164 | 152 | ||
165 | void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) { | 153 | void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color_all(red, green, blue); } |
166 | rgb_matrix_driver.set_color_all(red, green, blue); | ||
167 | } | ||
168 | 154 | ||
169 | bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { | 155 | bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { |
170 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | 156 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
171 | uint8_t led[LED_HITS_TO_REMEMBER]; | 157 | uint8_t led[LED_HITS_TO_REMEMBER]; |
172 | uint8_t led_count = 0; | 158 | uint8_t led_count = 0; |
173 | 159 | ||
174 | #if defined(RGB_MATRIX_KEYRELEASES) | 160 | # if defined(RGB_MATRIX_KEYRELEASES) |
175 | if (!record->event.pressed) { | 161 | if (!record->event.pressed) { |
176 | led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led); | 162 | led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led); |
177 | g_rgb_counters.any_key_hit = 0; | 163 | g_rgb_counters.any_key_hit = 0; |
178 | } | 164 | } |
179 | #elif defined(RGB_MATRIX_KEYPRESSES) | 165 | # elif defined(RGB_MATRIX_KEYPRESSES) |
180 | if (record->event.pressed) { | 166 | if (record->event.pressed) { |
181 | led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led); | 167 | led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led); |
182 | g_rgb_counters.any_key_hit = 0; | 168 | g_rgb_counters.any_key_hit = 0; |
183 | } | 169 | } |
184 | #endif // defined(RGB_MATRIX_KEYRELEASES) | 170 | # endif // defined(RGB_MATRIX_KEYRELEASES) |
185 | 171 | ||
186 | if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) { | 172 | if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) { |
187 | memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count); | 173 | memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count); |
188 | memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count); | 174 | memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count); |
189 | memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit | 175 | memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit |
190 | memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count); | 176 | memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count); |
191 | last_hit_buffer.count--; | 177 | last_hit_buffer.count--; |
192 | } | 178 | } |
193 | 179 | ||
194 | for(uint8_t i = 0; i < led_count; i++) { | 180 | for (uint8_t i = 0; i < led_count; i++) { |
195 | uint8_t index = last_hit_buffer.count; | 181 | uint8_t index = last_hit_buffer.count; |
196 | last_hit_buffer.x[index] = g_led_config.point[led[i]].x; | 182 | last_hit_buffer.x[index] = g_led_config.point[led[i]].x; |
197 | last_hit_buffer.y[index] = g_led_config.point[led[i]].y; | 183 | last_hit_buffer.y[index] = g_led_config.point[led[i]].y; |
198 | last_hit_buffer.index[index] = led[i]; | 184 | last_hit_buffer.index[index] = led[i]; |
199 | last_hit_buffer.tick[index] = 0; | 185 | last_hit_buffer.tick[index] = 0; |
200 | last_hit_buffer.count++; | 186 | last_hit_buffer.count++; |
201 | } | 187 | } |
202 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | 188 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED |
203 | 189 | ||
204 | #if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) | 190 | #if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) |
205 | if (rgb_matrix_config.mode == RGB_MATRIX_TYPING_HEATMAP) { | 191 | if (rgb_matrix_config.mode == RGB_MATRIX_TYPING_HEATMAP) { |
206 | process_rgb_matrix_typing_heatmap(record); | 192 | process_rgb_matrix_typing_heatmap(record); |
207 | } | 193 | } |
208 | #endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) | 194 | #endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) |
209 | 195 | ||
210 | return true; | 196 | return true; |
211 | } | 197 | } |
212 | 198 | ||
213 | void rgb_matrix_test(void) { | 199 | void rgb_matrix_test(void) { |
214 | // Mask out bits 4 and 5 | 200 | // Mask out bits 4 and 5 |
215 | // Increase the factor to make the test animation slower (and reduce to make it faster) | 201 | // Increase the factor to make the test animation slower (and reduce to make it faster) |
216 | uint8_t factor = 10; | 202 | uint8_t factor = 10; |
217 | switch ( (g_rgb_counters.tick & (0b11 << factor)) >> factor ) | 203 | switch ((g_rgb_counters.tick & (0b11 << factor)) >> factor) { |
218 | { | 204 | case 0: { |
219 | case 0: { | 205 | rgb_matrix_set_color_all(20, 0, 0); |
220 | rgb_matrix_set_color_all( 20, 0, 0 ); | 206 | break; |
221 | break; | 207 | } |
222 | } | 208 | case 1: { |
223 | case 1: { | 209 | rgb_matrix_set_color_all(0, 20, 0); |
224 | rgb_matrix_set_color_all( 0, 20, 0 ); | 210 | break; |
225 | break; | 211 | } |
212 | case 2: { | ||
213 | rgb_matrix_set_color_all(0, 0, 20); | ||
214 | break; | ||
215 | } | ||
216 | case 3: { | ||
217 | rgb_matrix_set_color_all(20, 20, 20); | ||
218 | break; | ||
219 | } | ||
226 | } | 220 | } |
227 | case 2: { | ||
228 | rgb_matrix_set_color_all( 0, 0, 20 ); | ||
229 | break; | ||
230 | } | ||
231 | case 3: { | ||
232 | rgb_matrix_set_color_all( 20, 20, 20 ); | ||
233 | break; | ||
234 | } | ||
235 | } | ||
236 | } | 221 | } |
237 | 222 | ||
238 | static bool rgb_matrix_none(effect_params_t* params) { | 223 | static bool rgb_matrix_none(effect_params_t *params) { |
239 | if (!params->init) { | 224 | if (!params->init) { |
240 | return false; | 225 | return false; |
241 | } | 226 | } |
242 | 227 | ||
243 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | 228 | RGB_MATRIX_USE_LIMITS(led_min, led_max); |
244 | for (uint8_t i = led_min; i < led_max; i++) { | 229 | for (uint8_t i = led_min; i < led_max; i++) { |
245 | rgb_matrix_set_color(i, 0, 0, 0); | 230 | rgb_matrix_set_color(i, 0, 0, 0); |
246 | } | 231 | } |
247 | return led_max < DRIVER_LED_TOTAL; | 232 | return led_max < DRIVER_LED_TOTAL; |
248 | } | 233 | } |
249 | 234 | ||
250 | static uint8_t rgb_last_enable = UINT8_MAX; | 235 | static uint8_t rgb_last_enable = UINT8_MAX; |
251 | static uint8_t rgb_last_effect = UINT8_MAX; | 236 | static uint8_t rgb_last_effect = UINT8_MAX; |
252 | static effect_params_t rgb_effect_params = { 0, 0xFF }; | 237 | static effect_params_t rgb_effect_params = {0, 0xFF}; |
253 | static rgb_task_states rgb_task_state = SYNCING; | 238 | static rgb_task_states rgb_task_state = SYNCING; |
254 | 239 | ||
255 | static void rgb_task_timers(void) { | 240 | static void rgb_task_timers(void) { |
256 | // Update double buffer timers | 241 | // Update double buffer timers |
257 | uint16_t deltaTime = timer_elapsed32(rgb_counters_buffer); | 242 | uint16_t deltaTime = timer_elapsed32(rgb_counters_buffer); |
258 | rgb_counters_buffer = timer_read32(); | 243 | rgb_counters_buffer = timer_read32(); |
259 | if (g_rgb_counters.any_key_hit < UINT32_MAX) { | 244 | if (g_rgb_counters.any_key_hit < UINT32_MAX) { |
260 | if (UINT32_MAX - deltaTime < g_rgb_counters.any_key_hit) { | 245 | if (UINT32_MAX - deltaTime < g_rgb_counters.any_key_hit) { |
261 | g_rgb_counters.any_key_hit = UINT32_MAX; | 246 | g_rgb_counters.any_key_hit = UINT32_MAX; |
262 | } else { | 247 | } else { |
263 | g_rgb_counters.any_key_hit += deltaTime; | 248 | g_rgb_counters.any_key_hit += deltaTime; |
249 | } | ||
264 | } | 250 | } |
265 | } | ||
266 | 251 | ||
267 | // Update double buffer last hit timers | 252 | // Update double buffer last hit timers |
268 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | 253 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
269 | uint8_t count = last_hit_buffer.count; | 254 | uint8_t count = last_hit_buffer.count; |
270 | for (uint8_t i = 0; i < count; ++i) { | 255 | for (uint8_t i = 0; i < count; ++i) { |
271 | if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) { | 256 | if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) { |
272 | last_hit_buffer.count--; | 257 | last_hit_buffer.count--; |
273 | continue; | 258 | continue; |
259 | } | ||
260 | last_hit_buffer.tick[i] += deltaTime; | ||
274 | } | 261 | } |
275 | last_hit_buffer.tick[i] += deltaTime; | 262 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED |
276 | } | ||
277 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | ||
278 | } | 263 | } |
279 | 264 | ||
280 | static void rgb_task_sync(void) { | 265 | static void rgb_task_sync(void) { |
281 | // next task | 266 | // next task |
282 | if (timer_elapsed32(g_rgb_counters.tick) >= RGB_MATRIX_LED_FLUSH_LIMIT) | 267 | if (timer_elapsed32(g_rgb_counters.tick) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING; |
283 | rgb_task_state = STARTING; | ||
284 | } | 268 | } |
285 | 269 | ||
286 | static void rgb_task_start(void) { | 270 | static void rgb_task_start(void) { |
287 | // reset iter | 271 | // reset iter |
288 | rgb_effect_params.iter = 0; | 272 | rgb_effect_params.iter = 0; |
289 | 273 | ||
290 | // update double buffers | 274 | // update double buffers |
291 | g_rgb_counters.tick = rgb_counters_buffer; | 275 | g_rgb_counters.tick = rgb_counters_buffer; |
292 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | 276 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
293 | g_last_hit_tracker = last_hit_buffer; | 277 | g_last_hit_tracker = last_hit_buffer; |
294 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | 278 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED |
295 | 279 | ||
296 | // next task | 280 | // next task |
297 | rgb_task_state = RENDERING; | 281 | rgb_task_state = RENDERING; |
298 | } | 282 | } |
299 | 283 | ||
300 | static void rgb_task_render(uint8_t effect) { | 284 | static void rgb_task_render(uint8_t effect) { |
301 | bool rendering = false; | 285 | bool rendering = false; |
302 | rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable); | 286 | rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable); |
303 | 287 | ||
304 | // each effect can opt to do calculations | 288 | // each effect can opt to do calculations |
305 | // and/or request PWM buffer updates. | 289 | // and/or request PWM buffer updates. |
306 | switch (effect) { | 290 | switch (effect) { |
307 | case RGB_MATRIX_NONE: | 291 | case RGB_MATRIX_NONE: |
308 | rendering = rgb_matrix_none(&rgb_effect_params); | 292 | rendering = rgb_matrix_none(&rgb_effect_params); |
309 | break; | 293 | break; |
310 | 294 | ||
311 | // --------------------------------------------- | 295 | // --------------------------------------------- |
312 | // -----Begin rgb effect switch case macros----- | 296 | // -----Begin rgb effect switch case macros----- |
313 | #define RGB_MATRIX_EFFECT(name, ...) \ | 297 | #define RGB_MATRIX_EFFECT(name, ...) \ |
314 | case RGB_MATRIX_##name: \ | 298 | case RGB_MATRIX_##name: \ |
315 | rendering = name(&rgb_effect_params); \ | 299 | rendering = name(&rgb_effect_params); \ |
316 | break; | 300 | break; |
317 | #include "rgb_matrix_animations/rgb_matrix_effects.inc" | 301 | #include "rgb_matrix_animations/rgb_matrix_effects.inc" |
318 | #undef RGB_MATRIX_EFFECT | 302 | #undef RGB_MATRIX_EFFECT |
319 | 303 | ||
320 | #if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER) | 304 | #if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER) |
321 | #define RGB_MATRIX_EFFECT(name, ...) \ | 305 | # define RGB_MATRIX_EFFECT(name, ...) \ |
322 | case RGB_MATRIX_CUSTOM_##name: \ | 306 | case RGB_MATRIX_CUSTOM_##name: \ |
323 | rendering = name(&rgb_effect_params); \ | 307 | rendering = name(&rgb_effect_params); \ |
324 | break; | 308 | break; |
325 | #ifdef RGB_MATRIX_CUSTOM_KB | 309 | # ifdef RGB_MATRIX_CUSTOM_KB |
326 | #include "rgb_matrix_kb.inc" | 310 | # include "rgb_matrix_kb.inc" |
327 | #endif | 311 | # endif |
328 | #ifdef RGB_MATRIX_CUSTOM_USER | 312 | # ifdef RGB_MATRIX_CUSTOM_USER |
329 | #include "rgb_matrix_user.inc" | 313 | # include "rgb_matrix_user.inc" |
330 | #endif | 314 | # endif |
331 | #undef RGB_MATRIX_EFFECT | 315 | # undef RGB_MATRIX_EFFECT |
332 | #endif | 316 | #endif |
333 | // -----End rgb effect switch case macros------- | 317 | // -----End rgb effect switch case macros------- |
334 | // --------------------------------------------- | 318 | // --------------------------------------------- |
319 | |||
320 | // Factory default magic value | ||
321 | case UINT8_MAX: { | ||
322 | rgb_matrix_test(); | ||
323 | rgb_task_state = FLUSHING; | ||
324 | } | ||
325 | return; | ||
326 | } | ||
327 | |||
328 | rgb_effect_params.iter++; | ||
335 | 329 | ||
336 | // Factory default magic value | 330 | // next task |
337 | case UINT8_MAX: { | 331 | if (!rendering) { |
338 | rgb_matrix_test(); | ||
339 | rgb_task_state = FLUSHING; | 332 | rgb_task_state = FLUSHING; |
340 | } | 333 | if (!rgb_effect_params.init && effect == RGB_MATRIX_NONE) { |
341 | return; | 334 | // We only need to flush once if we are RGB_MATRIX_NONE |
342 | } | 335 | rgb_task_state = SYNCING; |
343 | 336 | } | |
344 | rgb_effect_params.iter++; | ||
345 | |||
346 | // next task | ||
347 | if (!rendering) { | ||
348 | rgb_task_state = FLUSHING; | ||
349 | if (!rgb_effect_params.init && effect == RGB_MATRIX_NONE) { | ||
350 | // We only need to flush once if we are RGB_MATRIX_NONE | ||
351 | rgb_task_state = SYNCING; | ||
352 | } | 337 | } |
353 | } | ||
354 | } | 338 | } |
355 | 339 | ||
356 | static void rgb_task_flush(uint8_t effect) { | 340 | static void rgb_task_flush(uint8_t effect) { |
357 | // update last trackers after the first full render so we can init over several frames | 341 | // update last trackers after the first full render so we can init over several frames |
358 | rgb_last_effect = effect; | 342 | rgb_last_effect = effect; |
359 | rgb_last_enable = rgb_matrix_config.enable; | 343 | rgb_last_enable = rgb_matrix_config.enable; |
360 | 344 | ||
361 | // update pwm buffers | 345 | // update pwm buffers |
362 | rgb_matrix_update_pwm_buffers(); | 346 | rgb_matrix_update_pwm_buffers(); |
363 | 347 | ||
364 | // next task | 348 | // next task |
365 | rgb_task_state = SYNCING; | 349 | rgb_task_state = SYNCING; |
366 | } | 350 | } |
367 | 351 | ||
368 | void rgb_matrix_task(void) { | 352 | void rgb_matrix_task(void) { |
369 | rgb_task_timers(); | 353 | rgb_task_timers(); |
370 | 354 | ||
371 | // Ideally we would also stop sending zeros to the LED driver PWM buffers | 355 | // Ideally we would also stop sending zeros to the LED driver PWM buffers |
372 | // while suspended and just do a software shutdown. This is a cheap hack for now. | 356 | // while suspended and just do a software shutdown. This is a cheap hack for now. |
373 | bool suspend_backlight = ((g_suspend_state && RGB_DISABLE_WHEN_USB_SUSPENDED) || (RGB_DISABLE_AFTER_TIMEOUT > 0 && g_rgb_counters.any_key_hit > RGB_DISABLE_AFTER_TIMEOUT * 60 * 20)); | 357 | bool suspend_backlight = ((g_suspend_state && RGB_DISABLE_WHEN_USB_SUSPENDED) || (RGB_DISABLE_AFTER_TIMEOUT > 0 && g_rgb_counters.any_key_hit > RGB_DISABLE_AFTER_TIMEOUT * 60 * 20)); |
374 | uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode; | 358 | uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode; |
375 | 359 | ||
376 | switch (rgb_task_state) { | 360 | switch (rgb_task_state) { |
377 | case STARTING: | 361 | case STARTING: |
378 | rgb_task_start(); | 362 | rgb_task_start(); |
379 | break; | 363 | break; |
380 | case RENDERING: | 364 | case RENDERING: |
381 | rgb_task_render(effect); | 365 | rgb_task_render(effect); |
382 | break; | 366 | break; |
383 | case FLUSHING: | 367 | case FLUSHING: |
384 | rgb_task_flush(effect); | 368 | rgb_task_flush(effect); |
385 | break; | 369 | break; |
386 | case SYNCING: | 370 | case SYNCING: |
387 | rgb_task_sync(); | 371 | rgb_task_sync(); |
388 | break; | 372 | break; |
389 | } | 373 | } |
390 | 374 | ||
391 | if (!suspend_backlight) { | 375 | if (!suspend_backlight) { |
392 | rgb_matrix_indicators(); | 376 | rgb_matrix_indicators(); |
393 | } | 377 | } |
394 | } | 378 | } |
395 | 379 | ||
396 | void rgb_matrix_indicators(void) { | 380 | void rgb_matrix_indicators(void) { |
397 | rgb_matrix_indicators_kb(); | 381 | rgb_matrix_indicators_kb(); |
398 | rgb_matrix_indicators_user(); | 382 | rgb_matrix_indicators_user(); |
399 | } | 383 | } |
400 | 384 | ||
401 | __attribute__((weak)) | 385 | __attribute__((weak)) void rgb_matrix_indicators_kb(void) {} |
402 | void rgb_matrix_indicators_kb(void) {} | ||
403 | 386 | ||
404 | __attribute__((weak)) | 387 | __attribute__((weak)) void rgb_matrix_indicators_user(void) {} |
405 | void rgb_matrix_indicators_user(void) {} | ||
406 | 388 | ||
407 | void rgb_matrix_init(void) { | 389 | void rgb_matrix_init(void) { |
408 | rgb_matrix_driver.init(); | 390 | rgb_matrix_driver.init(); |
409 | 391 | ||
410 | // TODO: put the 1 second startup delay here? | 392 | // TODO: put the 1 second startup delay here? |
411 | 393 | ||
412 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | 394 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
413 | g_last_hit_tracker.count = 0; | 395 | g_last_hit_tracker.count = 0; |
414 | for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { | 396 | for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { |
415 | g_last_hit_tracker.tick[i] = UINT16_MAX; | 397 | g_last_hit_tracker.tick[i] = UINT16_MAX; |
416 | } | 398 | } |
417 | 399 | ||
418 | last_hit_buffer.count = 0; | 400 | last_hit_buffer.count = 0; |
419 | for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { | 401 | for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { |
420 | last_hit_buffer.tick[i] = UINT16_MAX; | 402 | last_hit_buffer.tick[i] = UINT16_MAX; |
421 | } | 403 | } |
422 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | 404 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED |
423 | 405 | ||
424 | if (!eeconfig_is_enabled()) { | 406 | if (!eeconfig_is_enabled()) { |
425 | dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n"); | 407 | dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n"); |
426 | eeconfig_init(); | 408 | eeconfig_init(); |
427 | eeconfig_update_rgb_matrix_default(); | 409 | eeconfig_update_rgb_matrix_default(); |
428 | } | 410 | } |
429 | 411 | ||
430 | eeconfig_read_rgb_matrix(); | 412 | eeconfig_read_rgb_matrix(); |
431 | if (!rgb_matrix_config.mode) { | 413 | if (!rgb_matrix_config.mode) { |
432 | dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); | 414 | dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); |
433 | eeconfig_update_rgb_matrix_default(); | 415 | eeconfig_update_rgb_matrix_default(); |
434 | } | 416 | } |
435 | eeconfig_debug_rgb_matrix(); // display current eeprom values | 417 | eeconfig_debug_rgb_matrix(); // display current eeprom values |
436 | } | 418 | } |
437 | 419 | ||
438 | void rgb_matrix_set_suspend_state(bool state) { | 420 | void rgb_matrix_set_suspend_state(bool state) { g_suspend_state = state; } |
439 | g_suspend_state = state; | ||
440 | } | ||
441 | 421 | ||
442 | void rgb_matrix_toggle(void) { | 422 | void rgb_matrix_toggle(void) { |
443 | rgb_matrix_config.enable ^= 1; | 423 | rgb_matrix_config.enable ^= 1; |
444 | rgb_task_state = STARTING; | 424 | rgb_task_state = STARTING; |
445 | eeconfig_update_rgb_matrix(); | 425 | eeconfig_update_rgb_matrix(); |
446 | } | 426 | } |
447 | 427 | ||
448 | void rgb_matrix_enable(void) { | 428 | void rgb_matrix_enable(void) { |
449 | rgb_matrix_enable_noeeprom(); | 429 | rgb_matrix_enable_noeeprom(); |
450 | eeconfig_update_rgb_matrix(); | 430 | eeconfig_update_rgb_matrix(); |
451 | } | 431 | } |
452 | 432 | ||
453 | void rgb_matrix_enable_noeeprom(void) { | 433 | void rgb_matrix_enable_noeeprom(void) { |
454 | if (!rgb_matrix_config.enable) | 434 | if (!rgb_matrix_config.enable) rgb_task_state = STARTING; |
455 | rgb_task_state = STARTING; | 435 | rgb_matrix_config.enable = 1; |
456 | rgb_matrix_config.enable = 1; | ||
457 | } | 436 | } |
458 | 437 | ||
459 | void rgb_matrix_disable(void) { | 438 | void rgb_matrix_disable(void) { |
460 | rgb_matrix_disable_noeeprom(); | 439 | rgb_matrix_disable_noeeprom(); |
461 | eeconfig_update_rgb_matrix(); | 440 | eeconfig_update_rgb_matrix(); |
462 | } | 441 | } |
463 | 442 | ||
464 | void rgb_matrix_disable_noeeprom(void) { | 443 | void rgb_matrix_disable_noeeprom(void) { |
465 | if (rgb_matrix_config.enable) | 444 | if (rgb_matrix_config.enable) rgb_task_state = STARTING; |
466 | rgb_task_state = STARTING; | 445 | rgb_matrix_config.enable = 0; |
467 | rgb_matrix_config.enable = 0; | ||
468 | } | 446 | } |
469 | 447 | ||
470 | void rgb_matrix_step(void) { | 448 | void rgb_matrix_step(void) { |
471 | rgb_matrix_config.mode++; | 449 | rgb_matrix_config.mode++; |
472 | if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX) | 450 | if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX) rgb_matrix_config.mode = 1; |
473 | rgb_matrix_config.mode = 1; | 451 | rgb_task_state = STARTING; |
474 | rgb_task_state = STARTING; | 452 | eeconfig_update_rgb_matrix(); |
475 | eeconfig_update_rgb_matrix(); | ||
476 | } | 453 | } |
477 | 454 | ||
478 | void rgb_matrix_step_reverse(void) { | 455 | void rgb_matrix_step_reverse(void) { |
479 | rgb_matrix_config.mode--; | 456 | rgb_matrix_config.mode--; |
480 | if (rgb_matrix_config.mode < 1) | 457 | if (rgb_matrix_config.mode < 1) rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; |
481 | rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; | 458 | rgb_task_state = STARTING; |
482 | rgb_task_state = STARTING; | 459 | eeconfig_update_rgb_matrix(); |
483 | eeconfig_update_rgb_matrix(); | ||
484 | } | 460 | } |
485 | 461 | ||
486 | void rgb_matrix_increase_hue(void) { | 462 | void rgb_matrix_increase_hue(void) { |
487 | rgb_matrix_config.hsv.h += RGB_MATRIX_HUE_STEP; | 463 | rgb_matrix_config.hsv.h += RGB_MATRIX_HUE_STEP; |
488 | eeconfig_update_rgb_matrix(); | 464 | eeconfig_update_rgb_matrix(); |
489 | } | 465 | } |
490 | 466 | ||
491 | void rgb_matrix_decrease_hue(void) { | 467 | void rgb_matrix_decrease_hue(void) { |
492 | rgb_matrix_config.hsv.h -= RGB_MATRIX_HUE_STEP; | 468 | rgb_matrix_config.hsv.h -= RGB_MATRIX_HUE_STEP; |
493 | eeconfig_update_rgb_matrix(); | 469 | eeconfig_update_rgb_matrix(); |
494 | } | 470 | } |
495 | 471 | ||
496 | void rgb_matrix_increase_sat(void) { | 472 | void rgb_matrix_increase_sat(void) { |
497 | rgb_matrix_config.hsv.s = qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP); | 473 | rgb_matrix_config.hsv.s = qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP); |
498 | eeconfig_update_rgb_matrix(); | 474 | eeconfig_update_rgb_matrix(); |
499 | } | 475 | } |
500 | 476 | ||
501 | void rgb_matrix_decrease_sat(void) { | 477 | void rgb_matrix_decrease_sat(void) { |
502 | rgb_matrix_config.hsv.s = qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP); | 478 | rgb_matrix_config.hsv.s = qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP); |
503 | eeconfig_update_rgb_matrix(); | 479 | eeconfig_update_rgb_matrix(); |
504 | } | 480 | } |
505 | 481 | ||
506 | void rgb_matrix_increase_val(void) { | 482 | void rgb_matrix_increase_val(void) { |
507 | rgb_matrix_config.hsv.v = qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); | 483 | rgb_matrix_config.hsv.v = qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); |
508 | if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS) | 484 | if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS) rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS; |
509 | rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS; | 485 | eeconfig_update_rgb_matrix(); |
510 | eeconfig_update_rgb_matrix(); | ||
511 | } | 486 | } |
512 | 487 | ||
513 | void rgb_matrix_decrease_val(void) { | 488 | void rgb_matrix_decrease_val(void) { |
514 | rgb_matrix_config.hsv.v = qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); | 489 | rgb_matrix_config.hsv.v = qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); |
515 | eeconfig_update_rgb_matrix(); | 490 | eeconfig_update_rgb_matrix(); |
516 | } | 491 | } |
517 | 492 | ||
518 | void rgb_matrix_increase_speed(void) { | 493 | void rgb_matrix_increase_speed(void) { |
519 | rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); | 494 | rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); |
520 | eeconfig_update_rgb_matrix(); | 495 | eeconfig_update_rgb_matrix(); |
521 | } | 496 | } |
522 | 497 | ||
523 | void rgb_matrix_decrease_speed(void) { | 498 | void rgb_matrix_decrease_speed(void) { |
524 | rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); | 499 | rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); |
525 | eeconfig_update_rgb_matrix(); | 500 | eeconfig_update_rgb_matrix(); |
526 | } | 501 | } |
527 | 502 | ||
528 | led_flags_t rgb_matrix_get_flags(void) { | 503 | led_flags_t rgb_matrix_get_flags(void) { return rgb_effect_params.flags; } |
529 | return rgb_effect_params.flags; | ||
530 | } | ||
531 | 504 | ||
532 | void rgb_matrix_set_flags(led_flags_t flags) { | 505 | void rgb_matrix_set_flags(led_flags_t flags) { rgb_effect_params.flags = flags; } |
533 | rgb_effect_params.flags = flags; | ||
534 | } | ||
535 | 506 | ||
536 | void rgb_matrix_mode(uint8_t mode) { | 507 | void rgb_matrix_mode(uint8_t mode) { |
537 | rgb_matrix_config.mode = mode; | 508 | rgb_matrix_config.mode = mode; |
538 | rgb_task_state = STARTING; | 509 | rgb_task_state = STARTING; |
539 | eeconfig_update_rgb_matrix(); | 510 | eeconfig_update_rgb_matrix(); |
540 | } | 511 | } |
541 | 512 | ||
542 | void rgb_matrix_mode_noeeprom(uint8_t mode) { | 513 | void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_config.mode = mode; } |
543 | rgb_matrix_config.mode = mode; | ||
544 | } | ||
545 | 514 | ||
546 | uint8_t rgb_matrix_get_mode(void) { | 515 | uint8_t rgb_matrix_get_mode(void) { return rgb_matrix_config.mode; } |
547 | return rgb_matrix_config.mode; | ||
548 | } | ||
549 | 516 | ||
550 | void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { | 517 | void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { |
551 | rgb_matrix_sethsv_noeeprom(hue, sat, val); | 518 | rgb_matrix_sethsv_noeeprom(hue, sat, val); |
552 | eeconfig_update_rgb_matrix(); | 519 | eeconfig_update_rgb_matrix(); |
553 | } | 520 | } |
554 | 521 | ||
555 | void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { | 522 | void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { |
556 | rgb_matrix_config.hsv.h = hue; | 523 | rgb_matrix_config.hsv.h = hue; |
557 | rgb_matrix_config.hsv.s = sat; | 524 | rgb_matrix_config.hsv.s = sat; |
558 | rgb_matrix_config.hsv.v = val; | 525 | rgb_matrix_config.hsv.v = val; |
559 | if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS) | 526 | if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS) rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS; |
560 | rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS; | ||
561 | } | 527 | } |