From bf2670601d29551896bab6811b9bb64de2d0ee0e Mon Sep 17 00:00:00 2001 From: skullY Date: Sat, 26 Jan 2019 14:33:55 -0800 Subject: [PATCH] compiles, but long delay on startup and problems --- drivers/issi/is31fl3731-simple.c | 18 +++++++++--- drivers/issi/is31fl3731-simple.h | 2 +- quantum/led_matrix.c | 20 +++++++------ quantum/led_matrix.h | 30 +++++++------------ quantum/led_matrix_drivers.c | 50 ++++++++++++++++---------------- quantum/quantum.c | 16 +++++++--- quantum/quantum.h | 6 +++- tmk_core/common/action.c | 2 +- 8 files changed, 79 insertions(+), 65 deletions(-) diff --git a/drivers/issi/is31fl3731-simple.c b/drivers/issi/is31fl3731-simple.c index 46d51dac7..9c31df209 100644 --- a/drivers/issi/is31fl3731-simple.c +++ b/drivers/issi/is31fl3731-simple.c @@ -29,6 +29,7 @@ #include "is31fl3731-simple.h" #include "i2c_master.h" #include "progmem.h" +#include "print.h" // This is a 7-bit address, that gets left-shifted and bit 0 // set to 0 for write, 1 for read (as per I2C protocol) @@ -72,10 +73,19 @@ uint8_t g_twi_transfer_buffer[20]; // We could optimize this and take out the unused registers from these // buffers and the transfers in IS31FL3731_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[DRIVER_COUNT][144]; +uint8_t g_pwm_buffer[LED_DRIVER_COUNT][144]; bool g_pwm_buffer_update_required = false; -uint8_t g_led_control_registers[DRIVER_COUNT][18] = { { 0 }, { 0 } }; +/* There's probably a better way to init this... */ +#if LED_DRIVER_COUNT == 1 + uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}}; +#elif LED_DRIVER_COUNT == 2 + uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}}; +#elif LED_DRIVER_COUNT == 3 + uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}, {0}}; +#elif LED_DRIVER_COUNT == 4 + uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}, {0}, {0}}; +#endif bool g_led_control_registers_update_required = false; // This is the bit pattern in the LED control registers @@ -194,7 +204,7 @@ void IS31FL3731_init(uint8_t addr) { } void IS31FL3731_set_value(int index, uint8_t value) { - if (index >= 0 && index < DRIVER_LED_TOTAL) { + if (index >= 0 && index < LED_DRIVER_LED_COUNT) { is31_led led = g_is31_leds[index]; // Subtract 0x24 to get the second index of g_pwm_buffer @@ -204,7 +214,7 @@ void IS31FL3731_set_value(int index, uint8_t value) { } void IS31FL3731_set_value_all(uint8_t value) { - for (int i = 0; i < DRIVER_LED_TOTAL; i++) { + for (int i = 0; i < LED_DRIVER_LED_COUNT; i++) { IS31FL3731_set_value(i, value); } } diff --git a/drivers/issi/is31fl3731-simple.h b/drivers/issi/is31fl3731-simple.h index c102837a3..3b107d48f 100644 --- a/drivers/issi/is31fl3731-simple.h +++ b/drivers/issi/is31fl3731-simple.h @@ -25,7 +25,7 @@ typedef struct is31_led { uint8_t v; } __attribute__((packed)) is31_led; -extern const is31_led g_is31_leds[DRIVER_LED_TOTAL]; +extern const is31_led g_is31_leds[LED_DRIVER_LED_COUNT]; void IS31FL3731_init(uint8_t addr); void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data); diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c index 9a0aa6acd..3b284990d 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 BACKLIGHT_LEVELS) diff --git a/quantum/quantum.h b/quantum/quantum.h index 56a6a1a99..169883609 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" diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index ec8d6ed7b..d4d4ac28d 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -537,7 +537,7 @@ void process_action(keyrecord_t *record, action_t action) action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); break; #endif -#ifdef BACKLIGHT_ENABLE +#if defined(BACKLIGHT_ENABLE) | defined(LED_MATRIX_ENABLE) case ACT_BACKLIGHT: if (!event.pressed) { switch (action.backlight.opt) {