diff options
author | skullY <skullydazed@gmail.com> | 2019-01-27 16:52:07 -0800 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-02-10 15:37:12 -0800 |
commit | c080a3e7c4aa565c696224588b16d4e883f60a7b (patch) | |
tree | b41240a287e304e43124e6eaeee13d3ce3323c69 /quantum/led_matrix.c | |
parent | 32116f1a4580e36c92870ca800cf3cc9106c35dd (diff) | |
download | qmk_firmware-c080a3e7c4aa565c696224588b16d4e883f60a7b.tar.gz qmk_firmware-c080a3e7c4aa565c696224588b16d4e883f60a7b.zip |
cleanup
Diffstat (limited to 'quantum/led_matrix.c')
-rw-r--r-- | quantum/led_matrix.c | 76 |
1 files changed, 37 insertions, 39 deletions
diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c index 2709de112..ca37af0d3 100644 --- a/quantum/led_matrix.c +++ b/quantum/led_matrix.c | |||
@@ -55,9 +55,6 @@ led_config_t led_matrix_config; | |||
55 | 55 | ||
56 | bool g_suspend_state = false; | 56 | bool g_suspend_state = false; |
57 | 57 | ||
58 | // Last uniform brightness level. | ||
59 | uint8_t g_uniform_brightness = 0; | ||
60 | |||
61 | // Global tick at 20 Hz | 58 | // Global tick at 20 Hz |
62 | uint32_t g_tick = 0; | 59 | uint32_t g_tick = 0; |
63 | 60 | ||
@@ -70,9 +67,11 @@ uint32_t g_any_key_hit = 0; | |||
70 | uint32_t eeconfig_read_led_matrix(void) { | 67 | uint32_t eeconfig_read_led_matrix(void) { |
71 | return eeprom_read_dword(EECONFIG_LED_MATRIX); | 68 | return eeprom_read_dword(EECONFIG_LED_MATRIX); |
72 | } | 69 | } |
70 | |||
73 | void eeconfig_update_led_matrix(uint32_t config_value) { | 71 | void eeconfig_update_led_matrix(uint32_t config_value) { |
74 | eeprom_update_dword(EECONFIG_LED_MATRIX, config_value); | 72 | eeprom_update_dword(EECONFIG_LED_MATRIX, config_value); |
75 | } | 73 | } |
74 | |||
76 | void eeconfig_update_led_matrix_default(void) { | 75 | void eeconfig_update_led_matrix_default(void) { |
77 | dprintf("eeconfig_update_led_matrix_default\n"); | 76 | dprintf("eeconfig_update_led_matrix_default\n"); |
78 | led_matrix_config.enable = 1; | 77 | led_matrix_config.enable = 1; |
@@ -81,6 +80,7 @@ void eeconfig_update_led_matrix_default(void) { | |||
81 | led_matrix_config.speed = 0; | 80 | led_matrix_config.speed = 0; |
82 | eeconfig_update_led_matrix(led_matrix_config.raw); | 81 | eeconfig_update_led_matrix(led_matrix_config.raw); |
83 | } | 82 | } |
83 | |||
84 | void eeconfig_debug_led_matrix(void) { | 84 | void eeconfig_debug_led_matrix(void) { |
85 | dprintf("led_matrix_config eeprom\n"); | 85 | dprintf("led_matrix_config eeprom\n"); |
86 | dprintf("led_matrix_config.enable = %d\n", led_matrix_config.enable); | 86 | dprintf("led_matrix_config.enable = %d\n", led_matrix_config.enable); |
@@ -90,7 +90,9 @@ void eeconfig_debug_led_matrix(void) { | |||
90 | } | 90 | } |
91 | 91 | ||
92 | // Last led hit | 92 | // Last led hit |
93 | #define LED_HITS_TO_REMEMBER 8 | 93 | #ifndef LED_HITS_TO_REMEMBER |
94 | #define LED_HITS_TO_REMEMBER 8 | ||
95 | #endif | ||
94 | uint8_t g_last_led_hit[LED_HITS_TO_REMEMBER] = {255}; | 96 | uint8_t g_last_led_hit[LED_HITS_TO_REMEMBER] = {255}; |
95 | uint8_t g_last_led_count = 0; | 97 | uint8_t g_last_led_count = 0; |
96 | 98 | ||
@@ -121,7 +123,6 @@ void led_matrix_set_index_value_all(uint8_t value) { | |||
121 | } | 123 | } |
122 | 124 | ||
123 | bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { | 125 | bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { |
124 | /* FIXME: Why you comment out skully? | ||
125 | if (record->event.pressed) { | 126 | if (record->event.pressed) { |
126 | uint8_t led[8], led_count; | 127 | uint8_t led[8], led_count; |
127 | map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count); | 128 | map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count); |
@@ -145,7 +146,6 @@ bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { | |||
145 | g_any_key_hit = 255; | 146 | g_any_key_hit = 255; |
146 | #endif | 147 | #endif |
147 | } | 148 | } |
148 | */ | ||
149 | return true; | 149 | return true; |
150 | } | 150 | } |
151 | 151 | ||
@@ -160,11 +160,7 @@ void led_matrix_all_off(void) { | |||
160 | 160 | ||
161 | // Uniform brightness | 161 | // Uniform brightness |
162 | void led_matrix_uniform_brightness(void) { | 162 | void led_matrix_uniform_brightness(void) { |
163 | uint8_t current_brightness = (LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS) * led_matrix_config.val; | 163 | led_matrix_set_index_value_all(LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS * led_matrix_config.val); |
164 | if (current_brightness != g_uniform_brightness) { | ||
165 | g_uniform_brightness = current_brightness; | ||
166 | led_matrix_set_index_value_all(current_brightness); | ||
167 | } | ||
168 | } | 164 | } |
169 | 165 | ||
170 | void led_matrix_custom(void) {} | 166 | void led_matrix_custom(void) {} |
@@ -246,44 +242,44 @@ void led_matrix_indicators_user(void) {} | |||
246 | // } | 242 | // } |
247 | 243 | ||
248 | void led_matrix_init(void) { | 244 | void led_matrix_init(void) { |
249 | led_matrix_driver.init(); | 245 | led_matrix_driver.init(); |
250 | 246 | ||
251 | // Wait a second for the driver to finish initializing | 247 | // Wait half a second for the driver to finish initializing |
252 | wait_ms(1000); | 248 | wait_ms(500); |
253 | 249 | ||
254 | // clear the key hits | 250 | // clear the key hits |
255 | for (int led=0; led<LED_DRIVER_LED_COUNT; led++) { | 251 | for (int led=0; led<LED_DRIVER_LED_COUNT; led++) { |
256 | g_key_hit[led] = 255; | 252 | g_key_hit[led] = 255; |
257 | } | 253 | } |
258 | 254 | ||
259 | if (!eeconfig_is_enabled()) { | 255 | if (!eeconfig_is_enabled()) { |
260 | dprintf("led_matrix_init_drivers eeconfig is not enabled.\n"); | 256 | dprintf("led_matrix_init_drivers eeconfig is not enabled.\n"); |
261 | eeconfig_init(); | 257 | eeconfig_init(); |
262 | eeconfig_update_led_matrix_default(); | 258 | eeconfig_update_led_matrix_default(); |
263 | } | 259 | } |
264 | 260 | ||
265 | led_matrix_config.raw = eeconfig_read_led_matrix(); | 261 | led_matrix_config.raw = eeconfig_read_led_matrix(); |
266 | 262 | ||
267 | if (!led_matrix_config.mode) { | 263 | if (!led_matrix_config.mode) { |
268 | dprintf("led_matrix_init_drivers led_matrix_config.mode = 0. Write default values to EEPROM.\n"); | 264 | dprintf("led_matrix_init_drivers led_matrix_config.mode = 0. Write default values to EEPROM.\n"); |
269 | eeconfig_update_led_matrix_default(); | 265 | eeconfig_update_led_matrix_default(); |
270 | led_matrix_config.raw = eeconfig_read_led_matrix(); | 266 | led_matrix_config.raw = eeconfig_read_led_matrix(); |
271 | } | 267 | } |
272 | 268 | ||
273 | eeconfig_debug_led_matrix(); // display current eeprom values | 269 | eeconfig_debug_led_matrix(); // display current eeprom values |
274 | } | 270 | } |
275 | 271 | ||
276 | // Deals with the messy details of incrementing an integer | 272 | // Deals with the messy details of incrementing an integer |
277 | static uint8_t increment(uint8_t value, uint8_t step, uint8_t min, uint8_t max) { | 273 | static uint8_t increment(uint8_t value, uint8_t step, uint8_t min, uint8_t max) { |
278 | int16_t new_value = value; | 274 | int16_t new_value = value; |
279 | new_value += step; | 275 | new_value += step; |
280 | return MIN(MAX( new_value, min), max ); | 276 | return MIN(MAX(new_value, min), max); |
281 | } | 277 | } |
282 | 278 | ||
283 | static uint8_t decrement(uint8_t value, uint8_t step, uint8_t min, uint8_t max) { | 279 | static uint8_t decrement(uint8_t value, uint8_t step, uint8_t min, uint8_t max) { |
284 | int16_t new_value = value; | 280 | int16_t new_value = value; |
285 | new_value -= step; | 281 | new_value -= step; |
286 | return MIN(MAX( new_value, min), max ); | 282 | return MIN(MAX(new_value, min), max); |
287 | } | 283 | } |
288 | 284 | ||
289 | // void *backlight_get_custom_key_value_eeprom_address(uint8_t led) { | 285 | // void *backlight_get_custom_key_value_eeprom_address(uint8_t led) { |
@@ -312,39 +308,41 @@ uint32_t led_matrix_get_tick(void) { | |||
312 | } | 308 | } |
313 | 309 | ||
314 | void led_matrix_toggle(void) { | 310 | void led_matrix_toggle(void) { |
315 | led_matrix_config.enable ^= 1; | 311 | led_matrix_config.enable ^= 1; |
316 | eeconfig_update_led_matrix(led_matrix_config.raw); | 312 | eeconfig_update_led_matrix(led_matrix_config.raw); |
317 | } | 313 | } |
318 | 314 | ||
319 | void led_matrix_enable(void) { | 315 | void led_matrix_enable(void) { |
320 | led_matrix_config.enable = 1; | 316 | led_matrix_config.enable = 1; |
321 | eeconfig_update_led_matrix(led_matrix_config.raw); | 317 | eeconfig_update_led_matrix(led_matrix_config.raw); |
322 | } | 318 | } |
323 | 319 | ||
324 | void led_matrix_enable_noeeprom(void) { | 320 | void led_matrix_enable_noeeprom(void) { |
325 | led_matrix_config.enable = 1; | 321 | led_matrix_config.enable = 1; |
326 | } | 322 | } |
327 | 323 | ||
328 | void led_matrix_disable(void) { | 324 | void led_matrix_disable(void) { |
329 | led_matrix_config.enable = 0; | 325 | led_matrix_config.enable = 0; |
330 | eeconfig_update_led_matrix(led_matrix_config.raw); | 326 | eeconfig_update_led_matrix(led_matrix_config.raw); |
331 | } | 327 | } |
332 | 328 | ||
333 | void led_matrix_disable_noeeprom(void) { | 329 | void led_matrix_disable_noeeprom(void) { |
334 | led_matrix_config.enable = 0; | 330 | led_matrix_config.enable = 0; |
335 | } | 331 | } |
336 | 332 | ||
337 | void led_matrix_step(void) { | 333 | void led_matrix_step(void) { |
338 | led_matrix_config.mode++; | 334 | led_matrix_config.mode++; |
339 | if (led_matrix_config.mode >= LED_MATRIX_EFFECT_MAX) | 335 | if (led_matrix_config.mode >= LED_MATRIX_EFFECT_MAX) { |
340 | led_matrix_config.mode = 1; | 336 | led_matrix_config.mode = 1; |
337 | } | ||
341 | eeconfig_update_led_matrix(led_matrix_config.raw); | 338 | eeconfig_update_led_matrix(led_matrix_config.raw); |
342 | } | 339 | } |
343 | 340 | ||
344 | void led_matrix_step_reverse(void) { | 341 | void led_matrix_step_reverse(void) { |
345 | led_matrix_config.mode--; | 342 | led_matrix_config.mode--; |
346 | if (led_matrix_config.mode < 1) | 343 | if (led_matrix_config.mode < 1) { |
347 | led_matrix_config.mode = LED_MATRIX_EFFECT_MAX - 1; | 344 | led_matrix_config.mode = LED_MATRIX_EFFECT_MAX - 1; |
345 | } | ||
348 | eeconfig_update_led_matrix(led_matrix_config.raw); | 346 | eeconfig_update_led_matrix(led_matrix_config.raw); |
349 | } | 347 | } |
350 | 348 | ||