#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)
// 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
}
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
}
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);
}
}
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);
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;
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) {
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);
// 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;
}
// 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);
// }
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);
}
#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;
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;
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. */
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
// 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
}
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
}
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();
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
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)
#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"
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) {