diff options
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/led_matrix.c | 20 | ||||
-rw-r--r-- | quantum/led_matrix.h | 30 | ||||
-rw-r--r-- | quantum/led_matrix_drivers.c | 50 | ||||
-rw-r--r-- | quantum/quantum.c | 16 | ||||
-rw-r--r-- | quantum/quantum.h | 6 |
5 files changed, 63 insertions, 59 deletions
diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c index 9a0aa6acd9..3b284990d9 100644 --- a/quantum/led_matrix.c +++ b/quantum/led_matrix.c @@ -59,7 +59,7 @@ bool g_suspend_state = false; uint32_t g_tick = 0; // Ticks since this key was last hit. -uint8_t g_key_hit[DRIVER_LED_TOTAL]; +uint8_t g_key_hit[LED_DRIVER_LED_COUNT]; // Ticks since any key was last hit. uint32_t g_any_key_hit = 0; @@ -95,7 +95,7 @@ void map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i, uint8_t led_matrix led; *led_count = 0; - for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { + for (uint8_t i = 0; i < LED_DRIVER_LED_COUNT; i++) { // map_index_to_led(i, &led); led = g_leds[i]; if (row == led.matrix_co.row && column == led.matrix_co.col) { @@ -187,7 +187,7 @@ void led_matrix_task(void) { g_any_key_hit++; } - for (int led = 0; led < DRIVER_LED_TOTAL; led++) { + for (int led = 0; led < LED_DRIVER_LED_COUNT; led++) { if (g_key_hit[led] < 255) { if (g_key_hit[led] == 254) g_last_led_count = MAX(g_last_led_count - 1, 0); @@ -271,7 +271,7 @@ void led_matrix_init(void) { // TODO: put the 1 second startup delay here? // clear the key hits - for (int led=0; led<DRIVER_LED_TOTAL; led++) { + for (int led=0; led<LED_DRIVER_LED_COUNT; led++) { g_key_hit[led] = 255; } @@ -317,7 +317,7 @@ static uint8_t decrement(uint8_t value, uint8_t step, uint8_t min, uint8_t max) // uint8_t led[8], led_count; // map_row_column_to_led(row,column,led,&led_count); // for(uint8_t i = 0; i < led_count; i++) { -// if (led[i] < DRIVER_LED_TOTAL) { +// if (led[i] < LED_DRIVER_LED_COUNT) { // void *address = backlight_get_custom_key_value_eeprom_address(led[i]); // eeprom_update_byte(address, value); // } @@ -396,9 +396,11 @@ uint8_t led_matrix_get_mode(void) { return led_matrix_config.mode; } -void led_matrix_set_value(uint8_t val, bool eeprom_write) { +void led_matrix_set_value_noeeprom(uint8_t val) { led_matrix_config.val = val; - if (eeprom_write) { - eeconfig_update_led_matrix(led_matrix_config.raw); - } +} + +void led_matrix_set_value(uint8_t val) { + led_matrix_set_value_noeeprom(val); + eeconfig_update_led_matrix(led_matrix_config.raw); } diff --git a/quantum/led_matrix.h b/quantum/led_matrix.h index 20f2e73c69..6db162963e 100644 --- a/quantum/led_matrix.h +++ b/quantum/led_matrix.h @@ -21,6 +21,11 @@ #define LED_MATRIX_H +#ifndef BACKLIGHT_ENABLE + #error You must define BACKLIGHT_ENABLE with LED_MATRIX_ENABLE +#endif + + typedef struct Point { uint8_t x; uint8_t y; @@ -38,7 +43,7 @@ typedef struct led_matrix { uint8_t modifier:1; } __attribute__((packed)) led_matrix; -extern const led_matrix g_leds[DRIVER_LED_TOTAL]; +extern const led_matrix g_leds[LED_DRIVER_LED_COUNT]; typedef struct { uint8_t index; @@ -104,26 +109,11 @@ void led_matrix_decrease_speed(void); void led_matrix_mode(uint8_t mode, bool eeprom_write); void led_matrix_mode_noeeprom(uint8_t mode); uint8_t led_matrix_get_mode(void); -void led_matrix_set_value(uint8_t mode, bool eeprom_write); +void led_matrix_set_value(uint8_t mode); +void led_matrix_set_value_noeeprom(uint8_t mode); -#ifndef BACKLIGHT_ENABLE -#define backlight_toggle() backlight_matrix_toggle() -#define backlight_enable() backlight_matrix_enable() -#define backlight_enable_noeeprom() backlight_matrix_enable_noeeprom() -#define backlight_disable() backlight_matrix_disable() -#define backlight_disable_noeeprom() backlight_matrix_disable_noeeprom() -#define backlight_step() backlight_matrix_step() -#define backlight_set_value(val) backlight_matrix_set_value(val) -#define backlight_set_value_noeeprom(val) backlight_matrix_set_value_noeeprom(val) -#define backlight_step_reverse() backlight_matrix_step_reverse() -#define backlight_increase_val() backlight_matrix_increase_val() -#define backlight_decrease_val() backlight_matrix_decrease_val() -#define backlight_increase_speed() backlight_matrix_increase_speed() -#define backlight_decrease_speed() backlight_matrix_decrease_speed() -#define backlight_mode(mode) backlight_matrix_mode(mode) -#define backlight_mode_noeeprom(mode) backlight_matrix_mode_noeeprom(mode) -#define backlight_get_mode() backlight_matrix_get_mode() -#endif +// Hook into the existing backlight API +#define backlight_set(val) led_matrix_set_value(val) typedef struct { /* Perform any initialisation required for the other driver functions to work. */ diff --git a/quantum/led_matrix_drivers.c b/quantum/led_matrix_drivers.c index f00f4f3668..e0f8b20949 100644 --- a/quantum/led_matrix_drivers.c +++ b/quantum/led_matrix_drivers.c @@ -39,32 +39,32 @@ static void init(void) { i2c_init(); #ifdef IS31FL3731 #ifdef LED_DRIVER_ADDR_1 - IS31FL3731_init(DRIVER_ADDR_1); + IS31FL3731_init(LED_DRIVER_ADDR_1); #endif #ifdef LED_DRIVER_ADDR_2 - IS31FL3731_init(DRIVER_ADDR_2); + IS31FL3731_init(LED_DRIVER_ADDR_2); #endif #ifdef LED_DRIVER_ADDR_3 - IS31FL3731_init(DRIVER_ADDR_3); + IS31FL3731_init(LED_DRIVER_ADDR_3); #endif #ifdef LED_DRIVER_ADDR_4 - IS31FL3731_init(DRIVER_ADDR_4); + IS31FL3731_init(LED_DRIVER_ADDR_4); #endif #else #ifdef LED_DRIVER_ADDR_1 - IS31FL3733_init(DRIVER_ADDR_1); + IS31FL3733_init(LED_DRIVER_ADDR_1); #endif #ifdef LED_DRIVER_ADDR_2 - IS31FL3733_init(DRIVER_ADDR_2); + IS31FL3733_init(LED_DRIVER_ADDR_2); #endif #ifdef LED_DRIVER_ADDR_3 - IS31FL3733_init(DRIVER_ADDR_3); + IS31FL3733_init(LED_DRIVER_ADDR_3); #endif #ifdef LED_DRIVER_ADDR_4 - IS31FL3733_init(DRIVER_ADDR_4); + IS31FL3733_init(LED_DRIVER_ADDR_4); #endif #endif - for (int index = 0; index < DRIVER_LED_TOTAL; index++) { + for (int index = 0; index < LED_DRIVER_COUNT; index++) { #ifdef IS31FL3731 IS31FL3731_set_led_control_register(index, true); #else @@ -74,29 +74,29 @@ static void init(void) { // This actually updates the LED drivers #ifdef IS31FL3731 #ifdef LED_DRIVER_ADDR_1 - IS31FL3731_update_led_control_registers(DRIVER_ADDR_1); + IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0); #endif #ifdef LED_DRIVER_ADDR_2 - IS31FL3731_update_led_control_registers(DRIVER_ADDR_2); + IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1); #endif #ifdef LED_DRIVER_ADDR_3 - IS31FL3731_update_led_control_registers(DRIVER_ADDR_3); + IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2); #endif #ifdef LED_DRIVER_ADDR_4 - IS31FL3731_update_led_control_registers(DRIVER_ADDR_4); + IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3); #endif #else #ifdef LED_DRIVER_ADDR_1 - IS31FL3733_update_led_control_registers(DRIVER_ADDR_1); + IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0); #endif #ifdef LED_DRIVER_ADDR_2 - IS31FL3733_update_led_control_registers(DRIVER_ADDR_2); + IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1); #endif #ifdef LED_DRIVER_ADDR_3 - IS31FL3733_update_led_control_registers(DRIVER_ADDR_3); + IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2); #endif #ifdef LED_DRIVER_ADDR_4 - IS31FL3733_update_led_control_registers(DRIVER_ADDR_4); + IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3); #endif #endif } @@ -104,29 +104,29 @@ static void init(void) { static void flush(void) { #ifdef IS31FL3731 #ifdef LED_DRIVER_ADDR_1 - IS31FL3731_update_pwm_buffers(DRIVER_ADDR_1); + IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0); #endif #ifdef LED_DRIVER_ADDR_2 - IS31FL3731_update_pwm_buffers(DRIVER_ADDR_2); + IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1); #endif #ifdef LED_DRIVER_ADDR_3 - IS31FL3731_update_pwm_buffers(DRIVER_ADDR_3); + IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2); #endif #ifdef LED_DRIVER_ADDR_4 - IS31FL3731_update_pwm_buffers(DRIVER_ADDR_4); + IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3); #endif #else #ifdef LED_DRIVER_ADDR_1 - IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1); + IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0); #endif #ifdef LED_DRIVER_ADDR_2 - IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2); + IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1); #endif #ifdef LED_DRIVER_ADDR_3 - IS31FL3733_update_pwm_buffers(DRIVER_ADDR_3); + IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2); #endif #ifdef LED_DRIVER_ADDR_4 - IS31FL3733_update_pwm_buffers(DRIVER_ADDR_4); + IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3); #endif #endif } diff --git a/quantum/quantum.c b/quantum/quantum.c index bd3715c80a..0e605d4cb4 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -1031,7 +1031,11 @@ void matrix_init_quantum() { eeconfig_init(); } #ifdef BACKLIGHT_ENABLE - backlight_init_ports(); + #ifdef LED_MATRIX_ENABLE + led_matrix_init(); + #else + backlight_init_ports(); + #endif #endif #ifdef AUDIO_ENABLE audio_init(); @@ -1067,8 +1071,12 @@ void matrix_scan_quantum() { matrix_scan_combo(); #endif - #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN) - backlight_task(); + #if defined(BACKLIGHT_ENABLE) + #if defined(LED_MATRIX_ENABLE) + led_matrix_task(); + #elif defined(BACKLIGHT_PIN) + backlight_task(); + #endif #endif #ifdef RGB_MATRIX_ENABLE @@ -1198,7 +1206,7 @@ static inline void set_pwm(uint16_t val) { OCRxx = val; } -#ifndef BACKLIGHT_CUSTOM_DRIVER +#ifndef BACKLIGHT_CUSTOM_DRIVER || LED_MATRIX_ENABLE __attribute__ ((weak)) void backlight_set(uint8_t level) { if (level > BACKLIGHT_LEVELS) diff --git a/quantum/quantum.h b/quantum/quantum.h index 56a6a1a991..1698836094 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -28,7 +28,11 @@ #include "matrix.h" #include "keymap.h" #ifdef BACKLIGHT_ENABLE - #include "backlight.h" + #ifdef LED_MATRIX_ENABLE + #include "led_matrix.h" + #else + #include "backlight.h" + #endif #endif #ifdef RGBLIGHT_ENABLE #include "rgblight.h" |