]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
compiles, but long delay on startup and problems
authorskullY <skullydazed@gmail.com>
Sat, 26 Jan 2019 22:33:55 +0000 (14:33 -0800)
committerskullydazed <skullydazed@users.noreply.github.com>
Sun, 10 Feb 2019 23:37:12 +0000 (15:37 -0800)
drivers/issi/is31fl3731-simple.c
drivers/issi/is31fl3731-simple.h
quantum/led_matrix.c
quantum/led_matrix.h
quantum/led_matrix_drivers.c
quantum/quantum.c
quantum/quantum.h
tmk_core/common/action.c

index 46d51dac7046a03dc9a82ec7db2a4ec73aa8bc02..9c31df20924514c3721d7b2a6940fa723c8985bc 100644 (file)
@@ -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);
     }
 }
index c102837a30f57f4008e0ebb2700427949ddd0be7..3b107d48f6babfcdddc9821ffe0aac64fe4effdd 100644 (file)
@@ -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);
index 9a0aa6acd940b395b03cfa03d29016b4de5b8978..3b284990d989d9bf24daa604335b1dd91e4e64dd 100644 (file)
@@ -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);
 }
index 20f2e73c69de5d67677c9f1ee87fc2cff1af6d1e..6db162963eec0be41ae408073ac2d9bd8a77b9e5 100644 (file)
 #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. */
index f00f4f366807a16d9c74e48d2dd11096eb66cf2a..e0f8b2094905e0c5e1e85c4ff9f93c170171ad81 100644 (file)
@@ -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
 }
index bd3715c80ab2c724ec175042a230c8fb55b25e7f..0e605d4cb45f0904561ffba16983a7d4df3e9705 100644 (file)
@@ -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)
index 56a6a1a991ada202659d6725759890349f838e55..1698836094de17bc3d9440a332d3140ce6c32eb7 100644 (file)
 #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"
index ec8d6ed7b9cbc1dee1d7eb3a2932e6e7135867df..d4d4ac28da79b8db3ebc4b17a4249d179dfd15ab 100644 (file)
@@ -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) {