diff options
author | skullY <skullydazed@gmail.com> | 2019-01-26 21:25:59 -0800 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-02-10 15:37:12 -0800 |
commit | 6b74dd6de5359da18e87b2d4894e3ffc3fc89d47 (patch) | |
tree | d4b467f032aadac477c4c2fb21d17a6c35dd30a0 /quantum/led_matrix.c | |
parent | bf2670601d29551896bab6811b9bb64de2d0ee0e (diff) | |
download | qmk_firmware-6b74dd6de5359da18e87b2d4894e3ffc3fc89d47.tar.gz qmk_firmware-6b74dd6de5359da18e87b2d4894e3ffc3fc89d47.zip |
led_matrix works now
Diffstat (limited to 'quantum/led_matrix.c')
-rw-r--r-- | quantum/led_matrix.c | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c index 3b284990d..f849d478d 100644 --- a/quantum/led_matrix.c +++ b/quantum/led_matrix.c | |||
@@ -55,6 +55,9 @@ 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 | |||
58 | // Global tick at 20 Hz | 61 | // Global tick at 20 Hz |
59 | uint32_t g_tick = 0; | 62 | uint32_t g_tick = 0; |
60 | 63 | ||
@@ -118,6 +121,7 @@ void led_matrix_set_index_value_all(uint8_t value) { | |||
118 | } | 121 | } |
119 | 122 | ||
120 | bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { | 123 | bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { |
124 | /* FIXME: Why you comment out skully? | ||
121 | if (record->event.pressed) { | 125 | if (record->event.pressed) { |
122 | uint8_t led[8], led_count; | 126 | uint8_t led[8], led_count; |
123 | map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count); | 127 | map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count); |
@@ -141,6 +145,7 @@ bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { | |||
141 | g_any_key_hit = 255; | 145 | g_any_key_hit = 255; |
142 | #endif | 146 | #endif |
143 | } | 147 | } |
148 | */ | ||
144 | return true; | 149 | return true; |
145 | } | 150 | } |
146 | 151 | ||
@@ -155,22 +160,20 @@ void led_matrix_all_off(void) { | |||
155 | 160 | ||
156 | // Uniform brightness | 161 | // Uniform brightness |
157 | void led_matrix_uniform_brightness(void) { | 162 | void led_matrix_uniform_brightness(void) { |
158 | led_matrix_set_index_value_all(led_matrix_config.val); | 163 | uint8_t current_brightness = (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 | } | ||
159 | } | 168 | } |
160 | 169 | ||
161 | void led_matrix_custom(void) {} | 170 | void led_matrix_custom(void) {} |
162 | 171 | ||
163 | void led_matrix_task(void) { | 172 | void led_matrix_task(void) { |
164 | #ifdef TRACK_PREVIOUS_EFFECT | 173 | if (!led_matrix_config.enable) { |
165 | static uint8_t toggle_enable_last = 255; | 174 | led_matrix_all_off(); |
166 | #endif | 175 | led_matrix_indicators(); |
167 | if (!led_matrix_config.enable) { | 176 | return; |
168 | led_matrix_all_off(); | ||
169 | led_matrix_indicators(); | ||
170 | #ifdef TRACK_PREVIOUS_EFFECT | ||
171 | toggle_enable_last = led_matrix_config.enable; | ||
172 | #endif | ||
173 | return; | ||
174 | } | 177 | } |
175 | 178 | ||
176 | // delay 1 second before driving LEDs or doing anything else | 179 | // delay 1 second before driving LEDs or doing anything else |
@@ -187,6 +190,7 @@ void led_matrix_task(void) { | |||
187 | g_any_key_hit++; | 190 | g_any_key_hit++; |
188 | } | 191 | } |
189 | 192 | ||
193 | /* FIXME: WHY YOU COMMENT OUT?! | ||
190 | for (int led = 0; led < LED_DRIVER_LED_COUNT; led++) { | 194 | for (int led = 0; led < LED_DRIVER_LED_COUNT; led++) { |
191 | if (g_key_hit[led] < 255) { | 195 | if (g_key_hit[led] < 255) { |
192 | if (g_key_hit[led] == 254) | 196 | if (g_key_hit[led] == 254) |
@@ -200,24 +204,13 @@ void led_matrix_task(void) { | |||
200 | led_matrix_uniform_brightness(); | 204 | led_matrix_uniform_brightness(); |
201 | return; | 205 | return; |
202 | } | 206 | } |
203 | 207 | */ | |
204 | // Ideally we would also stop sending zeros to the LED driver PWM buffers | 208 | // Ideally we would also stop sending zeros to the LED driver PWM buffers |
205 | // while suspended and just do a software shutdown. This is a cheap hack for now. | 209 | // while suspended and just do a software shutdown. This is a cheap hack for now. |
206 | bool suspend_backlight = ((g_suspend_state && LED_DISABLE_WHEN_USB_SUSPENDED) || | 210 | bool suspend_backlight = ((g_suspend_state && LED_DISABLE_WHEN_USB_SUSPENDED) || |
207 | (LED_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > LED_DISABLE_AFTER_TIMEOUT * 60 * 20)); | 211 | (LED_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > LED_DISABLE_AFTER_TIMEOUT * 60 * 20)); |
208 | uint8_t effect = suspend_backlight ? 0 : led_matrix_config.mode; | 212 | uint8_t effect = suspend_backlight ? 0 : led_matrix_config.mode; |
209 | 213 | ||
210 | #ifdef TRACK_PREVIOUS_EFFECT | ||
211 | // Keep track of the effect used last time, | ||
212 | // detect change in effect, so each effect can | ||
213 | // have an optional initialization. | ||
214 | |||
215 | static uint8_t effect_last = 255; | ||
216 | bool initialize = (effect != effect_last) || (led_matrix_config.enable != toggle_enable_last); | ||
217 | effect_last = effect; | ||
218 | toggle_enable_last = led_matrix_config.enable; | ||
219 | #endif | ||
220 | |||
221 | // this gets ticked at 20 Hz. | 214 | // this gets ticked at 20 Hz. |
222 | // each effect can opt to do calculations | 215 | // each effect can opt to do calculations |
223 | // and/or request PWM buffer updates. | 216 | // and/or request PWM buffer updates. |
@@ -230,10 +223,12 @@ void led_matrix_task(void) { | |||
230 | break; | 223 | break; |
231 | } | 224 | } |
232 | 225 | ||
233 | if (! suspend_backlight) { | 226 | if (!suspend_backlight) { |
234 | led_matrix_indicators(); | 227 | led_matrix_indicators(); |
235 | } | 228 | } |
236 | 229 | ||
230 | // Tell the LED driver to update its state | ||
231 | led_matrix_driver.flush(); | ||
237 | } | 232 | } |
238 | 233 | ||
239 | void led_matrix_indicators(void) { | 234 | void led_matrix_indicators(void) { |
@@ -404,3 +399,7 @@ void led_matrix_set_value(uint8_t val) { | |||
404 | led_matrix_set_value_noeeprom(val); | 399 | led_matrix_set_value_noeeprom(val); |
405 | eeconfig_update_led_matrix(led_matrix_config.raw); | 400 | eeconfig_update_led_matrix(led_matrix_config.raw); |
406 | } | 401 | } |
402 | |||
403 | void backlight_set(uint8_t val) { | ||
404 | led_matrix_set_value(val); | ||
405 | } | ||