summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpio/mcp23018.c12
-rw-r--r--drivers/gpio/pca9505.c10
-rw-r--r--drivers/gpio/pca9555.c12
-rw-r--r--drivers/haptic/drv2605l.c2
-rw-r--r--drivers/led/apa102.c99
-rw-r--r--drivers/led/apa102.h9
-rw-r--r--drivers/led/aw20216s.c3
-rw-r--r--drivers/led/aw20216s.h11
-rw-r--r--drivers/led/issi/is31fl3218-mono.c (renamed from drivers/led/issi/is31fl3218-simple.c)43
-rw-r--r--drivers/led/issi/is31fl3218-mono.h (renamed from drivers/led/issi/is31fl3218-simple.h)38
-rw-r--r--drivers/led/issi/is31fl3218.c53
-rw-r--r--drivers/led/issi/is31fl3218.h38
-rw-r--r--drivers/led/issi/is31fl3731-mono.c (renamed from drivers/led/issi/is31fl3731-simple.c)87
-rw-r--r--drivers/led/issi/is31fl3731-mono.h (renamed from drivers/led/issi/is31fl3731-simple.h)328
-rw-r--r--drivers/led/issi/is31fl3731.c98
-rw-r--r--drivers/led/issi/is31fl3731.h328
-rw-r--r--drivers/led/issi/is31fl3733-mono.c (renamed from drivers/led/issi/is31fl3733-simple.c)97
-rw-r--r--drivers/led/issi/is31fl3733-mono.h (renamed from drivers/led/issi/is31fl3733-simple.h)4
-rw-r--r--drivers/led/issi/is31fl3733.c93
-rw-r--r--drivers/led/issi/is31fl3733.h10
-rw-r--r--drivers/led/issi/is31fl3736-mono.c (renamed from drivers/led/issi/is31fl3736-simple.c)78
-rw-r--r--drivers/led/issi/is31fl3736-mono.h (renamed from drivers/led/issi/is31fl3736-simple.h)2
-rw-r--r--drivers/led/issi/is31fl3736.c76
-rw-r--r--drivers/led/issi/is31fl3736.h2
-rw-r--r--drivers/led/issi/is31fl3737-mono.c (renamed from drivers/led/issi/is31fl3737-simple.c)78
-rw-r--r--drivers/led/issi/is31fl3737-mono.h (renamed from drivers/led/issi/is31fl3737-simple.h)2
-rw-r--r--drivers/led/issi/is31fl3737.c78
-rw-r--r--drivers/led/issi/is31fl3737.h2
-rw-r--r--drivers/led/issi/is31fl3741-mono.c (renamed from drivers/led/issi/is31fl3741-simple.c)95
-rw-r--r--drivers/led/issi/is31fl3741-mono.h (renamed from drivers/led/issi/is31fl3741-simple.h)4
-rw-r--r--drivers/led/issi/is31fl3741.c101
-rw-r--r--drivers/led/issi/is31fl3741.h2
-rw-r--r--drivers/led/issi/is31fl3742a-mono.c215
-rw-r--r--drivers/led/issi/is31fl3742a-mono.h (renamed from drivers/led/issi/is31fl3742.h)157
-rw-r--r--drivers/led/issi/is31fl3742a.c219
-rw-r--r--drivers/led/issi/is31fl3742a.h298
-rw-r--r--drivers/led/issi/is31fl3743a-mono.c224
-rw-r--r--drivers/led/issi/is31fl3743a-mono.h (renamed from drivers/led/issi/is31fl3743.h)171
-rw-r--r--drivers/led/issi/is31fl3743a.c228
-rw-r--r--drivers/led/issi/is31fl3743a.h330
-rw-r--r--drivers/led/issi/is31fl3745-mono.c224
-rw-r--r--drivers/led/issi/is31fl3745-mono.h271
-rw-r--r--drivers/led/issi/is31fl3745.c228
-rw-r--r--drivers/led/issi/is31fl3745.h173
-rw-r--r--drivers/led/issi/is31fl3746.h198
-rw-r--r--drivers/led/issi/is31fl3746a-mono.c216
-rw-r--r--drivers/led/issi/is31fl3746a-mono.h201
-rw-r--r--drivers/led/issi/is31fl3746a.c220
-rw-r--r--drivers/led/issi/is31fl3746a.h203
-rw-r--r--drivers/led/issi/is31flcommon.c330
-rw-r--r--drivers/led/issi/is31flcommon.h95
-rw-r--r--drivers/led/snled27351-mono.c (renamed from drivers/led/snled27351-simple.c)102
-rw-r--r--drivers/led/snled27351-mono.h (renamed from drivers/led/snled27351-simple.h)4
-rw-r--r--drivers/led/snled27351.c103
-rw-r--r--drivers/led/snled27351.h4
-rw-r--r--drivers/oled/oled_driver.c9
-rw-r--r--drivers/painter/comms/qp_comms_i2c.c8
-rw-r--r--drivers/painter/sh1106/qp_sh1106.c14
-rw-r--r--drivers/painter/sh1106/qp_sh1106_opcodes.h2
-rw-r--r--drivers/sensors/analog_joystick.c71
-rw-r--r--drivers/sensors/azoteq_iqs5xx.c37
-rw-r--r--drivers/sensors/cirque_pinnacle.c27
-rw-r--r--drivers/sensors/cirque_pinnacle_i2c.c12
-rw-r--r--drivers/sensors/pimoroni_trackball.c4
-rw-r--r--drivers/ws2812.h6
65 files changed, 4385 insertions, 2114 deletions
diff --git a/drivers/gpio/mcp23018.c b/drivers/gpio/mcp23018.c
index 41cbfe087e..3eca4f9d34 100644
--- a/drivers/gpio/mcp23018.c
+++ b/drivers/gpio/mcp23018.c
@@ -33,13 +33,13 @@ bool mcp23018_set_config(uint8_t slave_addr, mcp23018_port_t port, uint8_t conf)
uint8_t cmdDirection = port ? CMD_IODIRB : CMD_IODIRA;
uint8_t cmdPullup = port ? CMD_GPPUB : CMD_GPPUA;
- i2c_status_t ret = i2c_writeReg(addr, cmdDirection, &conf, sizeof(conf), TIMEOUT);
+ i2c_status_t ret = i2c_write_register(addr, cmdDirection, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("mcp23018_set_config::directionFAILED::%u\n", ret);
return false;
}
- ret = i2c_writeReg(addr, cmdPullup, &conf, sizeof(conf), TIMEOUT);
+ ret = i2c_write_register(addr, cmdPullup, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("mcp23018_set_config::pullupFAILED::%u\n", ret);
return false;
@@ -52,7 +52,7 @@ bool mcp23018_set_output(uint8_t slave_addr, mcp23018_port_t port, uint8_t conf)
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t cmd = port ? CMD_GPIOB : CMD_GPIOA;
- i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
+ i2c_status_t ret = i2c_write_register(addr, cmd, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("mcp23018_set_output::FAILED::%u\n", ret);
return false;
@@ -65,7 +65,7 @@ bool mcp23018_set_output_all(uint8_t slave_addr, uint8_t confA, uint8_t confB) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t conf[2] = {confA, confB};
- i2c_status_t ret = i2c_writeReg(addr, CMD_GPIOA, &conf[0], sizeof(conf), TIMEOUT);
+ i2c_status_t ret = i2c_write_register(addr, CMD_GPIOA, &conf[0], sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("mcp23018_set_output::FAILED::%u\n", ret);
return false;
@@ -78,7 +78,7 @@ bool mcp23018_readPins(uint8_t slave_addr, mcp23018_port_t port, uint8_t* out) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t cmd = port ? CMD_GPIOB : CMD_GPIOA;
- i2c_status_t ret = i2c_readReg(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
+ i2c_status_t ret = i2c_read_register(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("mcp23018_readPins::FAILED::%u\n", ret);
return false;
@@ -97,7 +97,7 @@ bool mcp23018_readPins_all(uint8_t slave_addr, uint16_t* out) {
data16 data = {.u16 = 0};
- i2c_status_t ret = i2c_readReg(addr, CMD_GPIOA, &data.u8[0], sizeof(data), TIMEOUT);
+ i2c_status_t ret = i2c_read_register(addr, CMD_GPIOA, &data.u8[0], sizeof(data), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("mcp23018_readPins::FAILED::%u\n", ret);
return false;
diff --git a/drivers/gpio/pca9505.c b/drivers/gpio/pca9505.c
index 5803746c96..5617a14a8b 100644
--- a/drivers/gpio/pca9505.c
+++ b/drivers/gpio/pca9505.c
@@ -41,8 +41,6 @@ void pca9505_init(uint8_t slave_addr) {
}
// TODO: could check device connected
- // i2c_start(SLAVE_TO_ADDR(slave) | I2C_WRITE);
- // i2c_stop();
}
bool pca9505_set_config(uint8_t slave_addr, pca9505_port_t port, uint8_t conf) {
@@ -66,7 +64,7 @@ bool pca9505_set_config(uint8_t slave_addr, pca9505_port_t port, uint8_t conf) {
break;
}
- i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
+ i2c_status_t ret = i2c_write_register(addr, cmd, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9505_set_config::FAILED\n");
return false;
@@ -96,7 +94,7 @@ bool pca9505_set_polarity(uint8_t slave_addr, pca9505_port_t port, uint8_t conf)
break;
}
- i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
+ i2c_status_t ret = i2c_write_register(addr, cmd, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9505_set_polarity::FAILED\n");
return false;
@@ -126,7 +124,7 @@ bool pca9505_set_output(uint8_t slave_addr, pca9505_port_t port, uint8_t conf) {
break;
}
- i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
+ i2c_status_t ret = i2c_write_register(addr, cmd, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9505_set_output::FAILED\n");
return false;
@@ -156,7 +154,7 @@ bool pca9505_readPins(uint8_t slave_addr, pca9505_port_t port, uint8_t* out) {
break;
}
- i2c_status_t ret = i2c_readReg(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
+ i2c_status_t ret = i2c_read_register(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9505_readPins::FAILED\n");
return false;
diff --git a/drivers/gpio/pca9555.c b/drivers/gpio/pca9555.c
index adcd040083..0fc30099ac 100644
--- a/drivers/gpio/pca9555.c
+++ b/drivers/gpio/pca9555.c
@@ -29,15 +29,13 @@ void pca9555_init(uint8_t slave_addr) {
}
// TODO: could check device connected
- // i2c_start(SLAVE_TO_ADDR(slave) | I2C_WRITE);
- // i2c_stop();
}
bool pca9555_set_config(uint8_t slave_addr, pca9555_port_t port, uint8_t conf) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t cmd = port ? CMD_CONFIG_1 : CMD_CONFIG_0;
- i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
+ i2c_status_t ret = i2c_write_register(addr, cmd, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9555_set_config::FAILED\n");
return false;
@@ -50,7 +48,7 @@ bool pca9555_set_output(uint8_t slave_addr, pca9555_port_t port, uint8_t conf) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t cmd = port ? CMD_OUTPUT_1 : CMD_OUTPUT_0;
- i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
+ i2c_status_t ret = i2c_write_register(addr, cmd, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9555_set_output::FAILED\n");
return false;
@@ -63,7 +61,7 @@ bool pca9555_set_output_all(uint8_t slave_addr, uint8_t confA, uint8_t confB) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t conf[2] = {confA, confB};
- i2c_status_t ret = i2c_writeReg(addr, CMD_OUTPUT_0, &conf[0], sizeof(conf), TIMEOUT);
+ i2c_status_t ret = i2c_write_register(addr, CMD_OUTPUT_0, &conf[0], sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("pca9555_set_output::FAILED::%u\n", ret);
return false;
@@ -76,7 +74,7 @@ bool pca9555_readPins(uint8_t slave_addr, pca9555_port_t port, uint8_t* out) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t cmd = port ? CMD_INPUT_1 : CMD_INPUT_0;
- i2c_status_t ret = i2c_readReg(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
+ i2c_status_t ret = i2c_read_register(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9555_readPins::FAILED\n");
return false;
@@ -95,7 +93,7 @@ bool pca9555_readPins_all(uint8_t slave_addr, uint16_t* out) {
data16 data = {.u16 = 0};
- i2c_status_t ret = i2c_readReg(addr, CMD_INPUT_0, &data.u8[0], sizeof(data), TIMEOUT);
+ i2c_status_t ret = i2c_read_register(addr, CMD_INPUT_0, &data.u8[0], sizeof(data), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9555_readPins_all::FAILED\n");
return false;
diff --git a/drivers/haptic/drv2605l.c b/drivers/haptic/drv2605l.c
index 1ad2ad385f..a5adde5366 100644
--- a/drivers/haptic/drv2605l.c
+++ b/drivers/haptic/drv2605l.c
@@ -29,7 +29,7 @@ void drv2605l_write(uint8_t reg_addr, uint8_t data) {
}
uint8_t drv2605l_read(uint8_t reg_addr) {
- i2c_readReg(DRV2605L_I2C_ADDRESS << 1, reg_addr, &drv2605l_read_buffer, 1, 100);
+ i2c_read_register(DRV2605L_I2C_ADDRESS << 1, reg_addr, &drv2605l_read_buffer, 1, 100);
return drv2605l_read_buffer;
}
diff --git a/drivers/led/apa102.c b/drivers/led/apa102.c
index 527519eb8a..548b8f094e 100644
--- a/drivers/led/apa102.c
+++ b/drivers/led/apa102.c
@@ -55,60 +55,25 @@
uint8_t apa102_led_brightness = APA102_DEFAULT_BRIGHTNESS;
-void static apa102_start_frame(void);
-void static apa102_end_frame(uint16_t num_leds);
-
-void static apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness);
-void static apa102_send_byte(uint8_t byte);
-
-void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds) {
- rgb_led_t *end = start_led + num_leds;
-
- apa102_start_frame();
- for (rgb_led_t *led = start_led; led < end; led++) {
- apa102_send_frame(led->r, led->g, led->b, apa102_led_brightness);
- }
- apa102_end_frame(num_leds);
-}
-
-// Overwrite the default rgblight_call_driver to use apa102 driver
-void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) {
- apa102_setleds(start_led, num_leds);
-}
-
-void static apa102_init(void) {
- setPinOutput(APA102_DI_PIN);
- setPinOutput(APA102_CI_PIN);
-
- writePinLow(APA102_DI_PIN);
- writePinLow(APA102_CI_PIN);
-}
-
-void apa102_set_brightness(uint8_t brightness) {
- if (brightness > APA102_MAX_BRIGHTNESS) {
- apa102_led_brightness = APA102_MAX_BRIGHTNESS;
- } else if (brightness < 0) {
- apa102_led_brightness = 0;
- } else {
- apa102_led_brightness = brightness;
- }
-}
-
-void static apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness) {
- apa102_send_byte(0b11100000 | brightness);
- apa102_send_byte(blue);
- apa102_send_byte(green);
- apa102_send_byte(red);
+static void apa102_send_byte(uint8_t byte) {
+ APA102_SEND_BIT(byte, 7);
+ APA102_SEND_BIT(byte, 6);
+ APA102_SEND_BIT(byte, 5);
+ APA102_SEND_BIT(byte, 4);
+ APA102_SEND_BIT(byte, 3);
+ APA102_SEND_BIT(byte, 2);
+ APA102_SEND_BIT(byte, 1);
+ APA102_SEND_BIT(byte, 0);
}
-void static apa102_start_frame(void) {
+static void apa102_start_frame(void) {
apa102_init();
for (uint16_t i = 0; i < 4; i++) {
apa102_send_byte(0);
}
}
-void static apa102_end_frame(uint16_t num_leds) {
+static void apa102_end_frame(uint16_t num_leds) {
// This function has been taken from: https://github.com/pololu/apa102-arduino/blob/master/APA102.h
// and adapted. The code is MIT licensed. I think thats compatible?
//
@@ -141,13 +106,37 @@ void static apa102_end_frame(uint16_t num_leds) {
apa102_init();
}
-void static apa102_send_byte(uint8_t byte) {
- APA102_SEND_BIT(byte, 7);
- APA102_SEND_BIT(byte, 6);
- APA102_SEND_BIT(byte, 5);
- APA102_SEND_BIT(byte, 4);
- APA102_SEND_BIT(byte, 3);
- APA102_SEND_BIT(byte, 2);
- APA102_SEND_BIT(byte, 1);
- APA102_SEND_BIT(byte, 0);
+static void apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness) {
+ apa102_send_byte(0b11100000 | brightness);
+ apa102_send_byte(blue);
+ apa102_send_byte(green);
+ apa102_send_byte(red);
+}
+
+void apa102_init(void) {
+ setPinOutput(APA102_DI_PIN);
+ setPinOutput(APA102_CI_PIN);
+
+ writePinLow(APA102_DI_PIN);
+ writePinLow(APA102_CI_PIN);
+}
+
+void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds) {
+ rgb_led_t *end = start_led + num_leds;
+
+ apa102_start_frame();
+ for (rgb_led_t *led = start_led; led < end; led++) {
+ apa102_send_frame(led->r, led->g, led->b, apa102_led_brightness);
+ }
+ apa102_end_frame(num_leds);
+}
+
+void apa102_set_brightness(uint8_t brightness) {
+ if (brightness > APA102_MAX_BRIGHTNESS) {
+ apa102_led_brightness = APA102_MAX_BRIGHTNESS;
+ } else if (brightness < 0) {
+ apa102_led_brightness = 0;
+ } else {
+ apa102_led_brightness = brightness;
+ }
}
diff --git a/drivers/led/apa102.h b/drivers/led/apa102.h
index cd0a19d445..5e2f78658b 100644
--- a/drivers/led/apa102.h
+++ b/drivers/led/apa102.h
@@ -19,13 +19,19 @@
#include "color.h"
+#if defined(RGBLIGHT_APA102)
+# define APA102_LED_COUNT RGBLIGHT_LED_COUNT
+#elif defined(RGB_MATRIX_APA102)
+# define APA102_LED_COUNT RGB_MATRIX_LED_COUNT
+#endif
+
#ifndef APA102_DEFAULT_BRIGHTNESS
# define APA102_DEFAULT_BRIGHTNESS 31
#endif
#define APA102_MAX_BRIGHTNESS 31
-extern uint8_t apa102_led_brightness;
+void apa102_init(void);
/* User Interface
*
@@ -38,4 +44,5 @@ extern uint8_t apa102_led_brightness;
* - Send out the LED data
*/
void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds);
+
void apa102_set_brightness(uint8_t brightness);
diff --git a/drivers/led/aw20216s.c b/drivers/led/aw20216s.c
index ab7f3ccb42..49b059186d 100644
--- a/drivers/led/aw20216s.c
+++ b/drivers/led/aw20216s.c
@@ -134,6 +134,7 @@ void aw20216s_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) {
return;
}
+
g_pwm_buffer[led.driver][led.r] = red;
g_pwm_buffer[led.driver][led.g] = green;
g_pwm_buffer[led.driver][led.b] = blue;
@@ -149,8 +150,8 @@ void aw20216s_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
void aw20216s_update_pwm_buffers(pin_t cs_pin, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
aw20216s_write(cs_pin, AW20216S_PAGE_PWM, 0, g_pwm_buffer[index], AW20216S_PWM_REGISTER_COUNT);
+ g_pwm_buffer_update_required[index] = false;
}
- g_pwm_buffer_update_required[index] = false;
}
void aw20216s_flush(void) {
diff --git a/drivers/led/aw20216s.h b/drivers/led/aw20216s.h
index 38a0c92b2f..b8d8afc4cb 100644
--- a/drivers/led/aw20216s.h
+++ b/drivers/led/aw20216s.h
@@ -119,6 +119,7 @@ void aw20216s_flush(void);
#define CS16_SW1 0x0F
#define CS17_SW1 0x10
#define CS18_SW1 0x11
+
#define CS1_SW2 0x12
#define CS2_SW2 0x13
#define CS3_SW2 0x14
@@ -137,6 +138,7 @@ void aw20216s_flush(void);
#define CS16_SW2 0x21
#define CS17_SW2 0x22
#define CS18_SW2 0x23
+
#define CS1_SW3 0x24
#define CS2_SW3 0x25
#define CS3_SW3 0x26
@@ -155,6 +157,7 @@ void aw20216s_flush(void);
#define CS16_SW3 0x33
#define CS17_SW3 0x34
#define CS18_SW3 0x35
+
#define CS1_SW4 0x36
#define CS2_SW4 0x37
#define CS3_SW4 0x38
@@ -173,6 +176,7 @@ void aw20216s_flush(void);
#define CS16_SW4 0x45
#define CS17_SW4 0x46
#define CS18_SW4 0x47
+
#define CS1_SW5 0x48
#define CS2_SW5 0x49
#define CS3_SW5 0x4A
@@ -191,6 +195,7 @@ void aw20216s_flush(void);
#define CS16_SW5 0x57
#define CS17_SW5 0x58
#define CS18_SW5 0x59
+
#define CS1_SW6 0x5A
#define CS2_SW6 0x5B
#define CS3_SW6 0x5C
@@ -209,6 +214,7 @@ void aw20216s_flush(void);
#define CS16_SW6 0x69
#define CS17_SW6 0x6A
#define CS18_SW6 0x6B
+
#define CS1_SW7 0x6C
#define CS2_SW7 0x6D
#define CS3_SW7 0x6E
@@ -227,6 +233,7 @@ void aw20216s_flush(void);
#define CS16_SW7 0x7B
#define CS17_SW7 0x7C
#define CS18_SW7 0x7D
+
#define CS1_SW8 0x7E
#define CS2_SW8 0x7F
#define CS3_SW8 0x80
@@ -245,6 +252,7 @@ void aw20216s_flush(void);
#define CS16_SW8 0x8D
#define CS17_SW8 0x8E
#define CS18_SW8 0x8F
+
#define CS1_SW9 0x90
#define CS2_SW9 0x91
#define CS3_SW9 0x92
@@ -263,6 +271,7 @@ void aw20216s_flush(void);
#define CS16_SW9 0x9F
#define CS17_SW9 0xA0
#define CS18_SW9 0xA1
+
#define CS1_SW10 0xA2
#define CS2_SW10 0xA3
#define CS3_SW10 0xA4
@@ -281,6 +290,7 @@ void aw20216s_flush(void);
#define CS16_SW10 0xB1
#define CS17_SW10 0xB2
#define CS18_SW10 0xB3
+
#define CS1_SW11 0xB4
#define CS2_SW11 0xB5
#define CS3_SW11 0xB6
@@ -299,6 +309,7 @@ void aw20216s_flush(void);
#define CS16_SW11 0xC3
#define CS17_SW11 0xC4
#define CS18_SW11 0xC5
+
#define CS1_SW12 0xC6
#define CS2_SW12 0xC7
#define CS3_SW12 0xC8
diff --git a/drivers/led/issi/is31fl3218-simple.c b/drivers/led/issi/is31fl3218-mono.c
index ce28c51d18..1c5e4c055c 100644
--- a/drivers/led/issi/is31fl3218-simple.c
+++ b/drivers/led/issi/is31fl3218-mono.c
@@ -13,8 +13,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "is31fl3218.h"
-#include <string.h>
+
+#include "is31fl3218-mono.h"
#include "i2c_master.h"
#define IS31FL3218_PWM_REGISTER_COUNT 18
@@ -28,9 +28,6 @@
# define IS31FL3218_I2C_PERSISTENCE 0
#endif
-// Reusable buffer for transfers
-uint8_t g_twi_transfer_buffer[20];
-
// IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining.
uint8_t g_pwm_buffer[IS31FL3218_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required = false;
@@ -39,27 +36,22 @@ uint8_t g_led_control_registers[IS31FL3218_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required = false;
void is31fl3218_write_register(uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
#if IS31FL3218_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3218_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 2, IS31FL3218_I2C_TIMEOUT) == 0) break;
+ if (i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, reg, &data, 1, IS31FL3218_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 2, IS31FL3218_I2C_TIMEOUT);
+ i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, reg, &data, 1, IS31FL3218_I2C_TIMEOUT);
#endif
}
-void is31fl3218_write_pwm_buffer(uint8_t *pwm_buffer) {
- g_twi_transfer_buffer[0] = IS31FL3218_REG_PWM;
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer, 18);
-
+void is31fl3218_write_pwm_buffer(void) {
#if IS31FL3218_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3218_I2C_PERSISTENCE; i++) {
- i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 19, IS31FL3218_I2C_TIMEOUT);
+ if (i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, IS31FL3218_REG_PWM, g_pwm_buffer, 18, IS31FL3218_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 19, IS31FL3218_I2C_TIMEOUT);
+ i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, IS31FL3218_REG_PWM, g_pwm_buffer, 18, IS31FL3218_I2C_TIMEOUT);
#endif
}
@@ -94,14 +86,17 @@ void is31fl3218_init(void) {
void is31fl3218_set_value(int index, uint8_t value) {
is31fl3218_led_t led;
+
if (index >= 0 && index < IS31FL3218_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3218_leds[index]), sizeof(led));
+
+ if (g_pwm_buffer[led.v] == value) {
+ return;
+ }
+
+ g_pwm_buffer[led.v] = value;
+ g_pwm_buffer_update_required = true;
}
- if (g_pwm_buffer[led.v - IS31FL3218_REG_PWM] == value) {
- return;
- }
- g_pwm_buffer[led.v - IS31FL3218_REG_PWM] = value;
- g_pwm_buffer_update_required = true;
}
void is31fl3218_set_value_all(uint8_t value) {
@@ -114,8 +109,8 @@ void is31fl3218_set_led_control_register(uint8_t index, bool value) {
is31fl3218_led_t led;
memcpy_P(&led, (&g_is31fl3218_leds[index]), sizeof(led));
- uint8_t control_register = (led.v - IS31FL3218_REG_PWM) / 6;
- uint8_t bit_value = (led.v - IS31FL3218_REG_PWM) % 6;
+ uint8_t control_register = led.v / 6;
+ uint8_t bit_value = led.v % 6;
if (value) {
g_led_control_registers[control_register] |= (1 << bit_value);
@@ -128,7 +123,7 @@ void is31fl3218_set_led_control_register(uint8_t index, bool value) {
void is31fl3218_update_pwm_buffers(void) {
if (g_pwm_buffer_update_required) {
- is31fl3218_write_pwm_buffer(g_pwm_buffer);
+ is31fl3218_write_pwm_buffer();
// Load PWM registers and LED Control register data
is31fl3218_write_register(IS31FL3218_REG_UPDATE, 0x01);
@@ -138,7 +133,7 @@ void is31fl3218_update_pwm_buffers(void) {
void is31fl3218_update_led_control_registers(void) {
if (g_led_control_registers_update_required) {
- for (int i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3218_write_register(IS31FL3218_REG_LED_CONTROL_1 + i, g_led_control_registers[i]);
}
diff --git a/drivers/led/issi/is31fl3218-simple.h b/drivers/led/issi/is31fl3218-mono.h
index 9492817809..38beed0569 100644
--- a/drivers/led/issi/is31fl3218-simple.h
+++ b/drivers/led/issi/is31fl3218-mono.h
@@ -43,6 +43,8 @@ extern const is31fl3218_led_t PROGMEM g_is31fl3218_leds[IS31FL3218_LED_COUNT];
void is31fl3218_init(void);
+void is31fl3218_write_register(uint8_t reg, uint8_t data);
+
void is31fl3218_set_value(int index, uint8_t value);
void is31fl3218_set_value_all(uint8_t value);
@@ -53,21 +55,21 @@ void is31fl3218_update_pwm_buffers(void);
void is31fl3218_update_led_control_registers(void);
-#define OUT1 0x01
-#define OUT2 0x02
-#define OUT3 0x03
-#define OUT4 0x04
-#define OUT5 0x05
-#define OUT6 0x06
-#define OUT7 0x07
-#define OUT8 0x08
-#define OUT9 0x09
-#define OUT10 0x0A
-#define OUT11 0x0B
-#define OUT12 0x0C
-#define OUT13 0x0D
-#define OUT14 0x0E
-#define OUT15 0x0F
-#define OUT16 0x10
-#define OUT17 0x11
-#define OUT18 0x12
+#define OUT1 0x00
+#define OUT2 0x01
+#define OUT3 0x02
+#define OUT4 0x03
+#define OUT5 0x04
+#define OUT6 0x05
+#define OUT7 0x06
+#define OUT8 0x07
+#define OUT9 0x08
+#define OUT10 0x09
+#define OUT11 0x0A
+#define OUT12 0x0B
+#define OUT13 0x0C
+#define OUT14 0x0D
+#define OUT15 0x0E
+#define OUT16 0x0F
+#define OUT17 0x10
+#define OUT18 0x11
diff --git a/drivers/led/issi/is31fl3218.c b/drivers/led/issi/is31fl3218.c
index 39db09d518..5099480023 100644
--- a/drivers/led/issi/is31fl3218.c
+++ b/drivers/led/issi/is31fl3218.c
@@ -13,8 +13,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
#include "is31fl3218.h"
-#include <string.h>
#include "i2c_master.h"
#define IS31FL3218_PWM_REGISTER_COUNT 18
@@ -28,9 +28,6 @@
# define IS31FL3218_I2C_PERSISTENCE 0
#endif
-// Reusable buffer for transfers
-uint8_t g_twi_transfer_buffer[20];
-
// IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining.
uint8_t g_pwm_buffer[IS31FL3218_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required = false;
@@ -39,27 +36,22 @@ uint8_t g_led_control_registers[IS31FL3218_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required = false;
void is31fl3218_write_register(uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
#if IS31FL3218_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3218_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 2, IS31FL3218_I2C_TIMEOUT) == 0) break;
+ if (i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, reg, &data, 1, IS31FL3218_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 2, IS31FL3218_I2C_TIMEOUT);
+ i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, reg, &data, 1, IS31FL3218_I2C_TIMEOUT);
#endif
}
-void is31fl3218_write_pwm_buffer(uint8_t *pwm_buffer) {
- g_twi_transfer_buffer[0] = IS31FL3218_REG_PWM;
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer, 18);
-
+void is31fl3218_write_pwm_buffer(void) {
#if IS31FL3218_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3218_I2C_PERSISTENCE; i++) {
- i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 19, IS31FL3218_I2C_TIMEOUT);
+ if (i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, IS31FL3218_REG_PWM, g_pwm_buffer, 18, IS31FL3218_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 19, IS31FL3218_I2C_TIMEOUT);
+ i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, IS31FL3218_REG_PWM, g_pwm_buffer, 18, IS31FL3218_I2C_TIMEOUT);
#endif
}
@@ -94,16 +86,19 @@ void is31fl3218_init(void) {
void is31fl3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
is31fl3218_led_t led;
+
if (index >= 0 && index < IS31FL3218_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3218_leds[index]), sizeof(led));
+
+ if (g_pwm_buffer[led.r] == red && g_pwm_buffer[led.g] == green && g_pwm_buffer[led.b] == blue) {
+ return;
+ }
+
+ g_pwm_buffer[led.r] = red;
+ g_pwm_buffer[led.g] = green;
+ g_pwm_buffer[led.b] = blue;
+ g_pwm_buffer_update_required = true;
}
- if (g_pwm_buffer[led.r - IS31FL3218_REG_PWM] == red && g_pwm_buffer[led.g - IS31FL3218_REG_PWM] == green && g_pwm_buffer[led.b - IS31FL3218_REG_PWM] == blue) {
- return;
- }
- g_pwm_buffer[led.r - IS31FL3218_REG_PWM] = red;
- g_pwm_buffer[led.g - IS31FL3218_REG_PWM] = green;
- g_pwm_buffer[led.b - IS31FL3218_REG_PWM] = blue;
- g_pwm_buffer_update_required = true;
}
void is31fl3218_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
@@ -116,12 +111,12 @@ void is31fl3218_set_led_control_register(uint8_t index, bool red, bool green, bo
is31fl3218_led_t led;
memcpy_P(&led, (&g_is31fl3218_leds[index]), sizeof(led));
- uint8_t control_register_r = (led.r - IS31FL3218_REG_PWM) / 6;
- uint8_t control_register_g = (led.g - IS31FL3218_REG_PWM) / 6;
- uint8_t control_register_b = (led.b - IS31FL3218_REG_PWM) / 6;
- uint8_t bit_r = (led.r - IS31FL3218_REG_PWM) % 6;
- uint8_t bit_g = (led.g - IS31FL3218_REG_PWM) % 6;
- uint8_t bit_b = (led.b - IS31FL3218_REG_PWM) % 6;
+ uint8_t control_register_r = led.r / 6;
+ uint8_t control_register_g = led.g / 6;
+ uint8_t control_register_b = led.b / 6;
+ uint8_t bit_r = led.r % 6;
+ uint8_t bit_g = led.g % 6;
+ uint8_t bit_b = led.b % 6;
if (red) {
g_led_control_registers[control_register_r] |= (1 << bit_r);
@@ -144,7 +139,7 @@ void is31fl3218_set_led_control_register(uint8_t index, bool red, bool green, bo
void is31fl3218_update_pwm_buffers(void) {
if (g_pwm_buffer_update_required) {
- is31fl3218_write_pwm_buffer(g_pwm_buffer);
+ is31fl3218_write_pwm_buffer();
// Load PWM registers and LED Control register data
is31fl3218_write_register(IS31FL3218_REG_UPDATE, 0x01);
@@ -154,7 +149,7 @@ void is31fl3218_update_pwm_buffers(void) {
void is31fl3218_update_led_control_registers(void) {
if (g_led_control_registers_update_required) {
- for (int i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3218_write_register(IS31FL3218_REG_LED_CONTROL_1 + i, g_led_control_registers[i]);
}
diff --git a/drivers/led/issi/is31fl3218.h b/drivers/led/issi/is31fl3218.h
index ffa7f36d61..2228343329 100644
--- a/drivers/led/issi/is31fl3218.h
+++ b/drivers/led/issi/is31fl3218.h
@@ -45,6 +45,8 @@ extern const is31fl3218_led_t PROGMEM g_is31fl3218_leds[IS31FL3218_LED_COUNT];
void is31fl3218_init(void);
+void is31fl3218_write_register(uint8_t reg, uint8_t data);
+
void is31fl3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void is31fl3218_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
@@ -55,21 +57,21 @@ void is31fl3218_update_pwm_buffers(void);
void is31fl3218_update_led_control_registers(void);
-#define OUT1 0x01
-#define OUT2 0x02
-#define OUT3 0x03
-#define OUT4 0x04
-#define OUT5 0x05
-#define OUT6 0x06
-#define OUT7 0x07
-#define OUT8 0x08
-#define OUT9 0x09
-#define OUT10 0x0A
-#define OUT11 0x0B
-#define OUT12 0x0C
-#define OUT13 0x0D
-#define OUT14 0x0E
-#define OUT15 0x0F
-#define OUT16 0x10
-#define OUT17 0x11
-#define OUT18 0x12
+#define OUT1 0x00
+#define OUT2 0x01
+#define OUT3 0x02
+#define OUT4 0x03
+#define OUT5 0x04
+#define OUT6 0x05
+#define OUT7 0x06
+#define OUT8 0x07
+#define OUT9 0x08
+#define OUT10 0x09
+#define OUT11 0x0A
+#define OUT12 0x0B
+#define OUT13 0x0C
+#define OUT14 0x0D
+#define OUT15 0x0E
+#define OUT16 0x0F
+#define OUT17 0x10
+#define OUT18 0x11
diff --git a/drivers/led/issi/is31fl3731-simple.c b/drivers/led/issi/is31fl3731-mono.c
index 8dbfc3cd31..ca4e3449b2 100644
--- a/drivers/led/issi/is31fl3731-simple.c
+++ b/drivers/led/issi/is31fl3731-mono.c
@@ -17,8 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "is31fl3731-simple.h"
-#include <string.h>
+#include "is31fl3731-mono.h"
#include "i2c_master.h"
#include "wait.h"
@@ -33,9 +32,6 @@
# define IS31FL3731_I2C_PERSISTENCE 0
#endif
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
// These buffers match the IS31FL3731 PWM registers 0x24-0xB3.
// Storing them like this is optimal for I2C transfers to the registers.
// We could optimize this and take out the unused registers from these
@@ -48,41 +44,31 @@ uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][IS31FL3731_LED_CONTROL_
bool g_led_control_registers_update_required[IS31FL3731_DRIVER_COUNT] = {false};
void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
#if IS31FL3731_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3731_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3731_I2C_TIMEOUT) == 0) {
- break;
- }
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3731_I2C_TIMEOUT);
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3731_I2C_TIMEOUT);
#endif
}
-void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // assumes bank is already selected
-
- // transmit PWM registers in 9 transfers of 16 bytes
- // g_twi_transfer_buffer[] is 20 bytes
+void is31fl3731_select_page(uint8_t addr, uint8_t page) {
+ is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, page);
+}
- // iterate over the pwm_buffer contents at 16 byte intervals
- for (int i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i += 16) {
- // set the first register, e.g. 0x24, 0x34, 0x44, etc.
- g_twi_transfer_buffer[0] = 0x24 + i;
- // copy the data from i to i+15
- // device will auto-increment register for data after the first byte
- // thus this sets registers 0x24-0x33, 0x34-0x43, etc. in one transfer
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
+void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 0 is already selected.
+ // Transmit PWM registers in 9 transfers of 16 bytes.
+ // Iterate over the pwm_buffer contents at 16 byte intervals.
+ for (uint8_t i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3731_I2C_PERSISTENCE > 0
- for (uint8_t i = 0; i < IS31FL3731_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT) == 0) break;
+ for (uint8_t j = 0; j < IS31FL3731_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT);
+ i2c_write_register(addr << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT);
#endif
}
}
@@ -123,8 +109,7 @@ void is31fl3731_init(uint8_t addr) {
// then set up the mode and other settings, clear the PWM registers,
// then disable software shutdown.
- // select "function register" bank
- is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FUNCTION);
+ is31fl3731_select_page(addr, IS31FL3731_COMMAND_FUNCTION);
// enable software shutdown
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_SHUTDOWN, 0x00);
@@ -142,47 +127,45 @@ void is31fl3731_init(uint8_t addr) {
// audio sync off
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_AUDIO_SYNC, 0x00);
- // select bank 0
- is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FRAME_1);
+ is31fl3731_select_page(addr, IS31FL3731_COMMAND_FRAME_1);
// turn off all LEDs in the LED control register
- for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
- is31fl3731_write_register(addr, i, 0x00);
+ for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
+ is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_LED_CONTROL + i, 0x00);
}
// turn off all LEDs in the blink control register (not really needed)
- for (int i = 0x12; i <= 0x23; i++) {
- is31fl3731_write_register(addr, i, 0x00);
+ for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
+ is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_BLINK_CONTROL + i, 0x00);
}
// set PWM on all LEDs to 0
- for (int i = 0x24; i <= 0xB3; i++) {
- is31fl3731_write_register(addr, i, 0x00);
+ for (uint8_t i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i++) {
+ is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_PWM + i, 0x00);
}
- // select "function register" bank
- is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FUNCTION);
+ is31fl3731_select_page(addr, IS31FL3731_COMMAND_FUNCTION);
// disable software shutdown
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_SHUTDOWN, 0x01);
- // select bank 0 and leave it selected.
- // most usage after initialization is just writing PWM buffers in bank 0
+ // select page 0 and leave it selected.
+ // most usage after initialization is just writing PWM buffers in page 0
// as there's not much point in double-buffering
- is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FRAME_1);
+ is31fl3731_select_page(addr, IS31FL3731_COMMAND_FRAME_1);
}
void is31fl3731_set_value(int index, uint8_t value) {
is31fl3731_led_t led;
+
if (index >= 0 && index < IS31FL3731_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3731_leds[index]), sizeof(led));
- // Subtract 0x24 to get the second index of g_pwm_buffer
-
- if (g_pwm_buffer[led.driver][led.v - 0x24] == value) {
+ if (g_pwm_buffer[led.driver][led.v] == value) {
return;
}
- g_pwm_buffer[led.driver][led.v - 0x24] = value;
+
+ g_pwm_buffer[led.driver][led.v] = value;
g_pwm_buffer_update_required[led.driver] = true;
}
}
@@ -197,8 +180,8 @@ void is31fl3731_set_led_control_register(uint8_t index, bool value) {
is31fl3731_led_t led;
memcpy_P(&led, (&g_is31fl3731_leds[index]), sizeof(led));
- uint8_t control_register = (led.v - 0x24) / 8;
- uint8_t bit_value = (led.v - 0x24) % 8;
+ uint8_t control_register = led.v / 8;
+ uint8_t bit_value = led.v % 8;
if (value) {
g_led_control_registers[led.driver][control_register] |= (1 << bit_value);
@@ -211,16 +194,18 @@ void is31fl3731_set_led_control_register(uint8_t index, bool value) {
void is31fl3731_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
- is31fl3731_write_pwm_buffer(addr, g_pwm_buffer[index]);
+ is31fl3731_write_pwm_buffer(addr, index);
+
g_pwm_buffer_update_required[index] = false;
}
}
void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
- for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3731_write_register(addr, i, g_led_control_registers[index][i]);
}
+
g_led_control_registers_update_required[index] = false;
}
}
diff --git a/drivers/led/issi/is31fl3731-simple.h b/drivers/led/issi/is31fl3731-mono.h
index 4d173847dd..1b205e0115 100644
--- a/drivers/led/issi/is31fl3731-simple.h
+++ b/drivers/led/issi/is31fl3731-mono.h
@@ -61,6 +61,10 @@
#define IS31FL3731_COMMAND_FRAME_8 0x07
#define IS31FL3731_COMMAND_FUNCTION 0x0B
+#define IS31FL3731_FRAME_REG_LED_CONTROL 0x00
+#define IS31FL3731_FRAME_REG_BLINK_CONTROL 0x12
+#define IS31FL3731_FRAME_REG_PWM 0x24
+
#define IS31FL3731_FUNCTION_REG_CONFIG 0x00
#define IS31FL3731_CONFIG_MODE_PICTURE 0x00
#define IS31FL3731_CONFIG_MODE_AUTO_PLAY 0x08
@@ -103,7 +107,7 @@ extern const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT];
void is31fl3731_init_drivers(void);
void is31fl3731_init(uint8_t addr);
void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+void is31fl3731_select_page(uint8_t addr, uint8_t page);
void is31fl3731_set_value(int index, uint8_t value);
void is31fl3731_set_value_all(uint8_t value);
@@ -119,164 +123,164 @@ void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index);
void is31fl3731_flush(void);
-#define C1_1 0x24
-#define C1_2 0x25
-#define C1_3 0x26
-#define C1_4 0x27
-#define C1_5 0x28
-#define C1_6 0x29
-#define C1_7 0x2A
-#define C1_8 0x2B
-
-#define C1_9 0x2C
-#define C1_10 0x2D
-#define C1_11 0x2E
-#define C1_12 0x2F
-#define C1_13 0x30
-#define C1_14 0x31
-#define C1_15 0x32
-#define C1_16 0x33
-
-#define C2_1 0x34
-#define C2_2 0x35
-#define C2_3 0x36
-#define C2_4 0x37
-#define C2_5 0x38
-#define C2_6 0x39
-#define C2_7 0x3A
-#define C2_8 0x3B
-
-#define C2_9 0x3C
-#define C2_10 0x3D
-#define C2_11 0x3E
-#define C2_12 0x3F
-#define C2_13 0x40
-#define C2_14 0x41
-#define C2_15 0x42
-#define C2_16 0x43
-
-#define C3_1 0x44
-#define C3_2 0x45
-#define C3_3 0x46
-#define C3_4 0x47
-#define C3_5 0x48
-#define C3_6 0x49
-#define C3_7 0x4A
-#define C3_8 0x4B
-
-#define C3_9 0x4C
-#define C3_10 0x4D
-#define C3_11 0x4E
-#define C3_12 0x4F
-#define C3_13 0x50
-#define C3_14 0x51
-#define C3_15 0x52
-#define C3_16 0x53
-
-#define C4_1 0x54
-#define C4_2 0x55
-#define C4_3 0x56
-#define C4_4 0x57
-#define C4_5 0x58
-#define C4_6 0x59
-#define C4_7 0x5A
-#define C4_8 0x5B
-
-#define C4_9 0x5C
-#define C4_10 0x5D
-#define C4_11 0x5E
-#define C4_12 0x5F
-#define C4_13 0x60
-#define C4_14 0x61
-#define C4_15 0x62
-#define C4_16 0x63
-
-#define C5_1 0x64
-#define C5_2 0x65
-#define C5_3 0x66
-#define C5_4 0x67
-#define C5_5 0x68
-#define C5_6 0x69
-#define C5_7 0x6A
-#define C5_8 0x6B
-
-#define C5_9 0x6C
-#define C5_10 0x6D
-#define C5_11 0x6E
-#define C5_12 0x6F
-#define C5_13 0x70
-#define C5_14 0x71
-#define C5_15 0x72
-#define C5_16 0x73
-
-#define C6_1 0x74
-#define C6_2 0x75
-#define C6_3 0x76
-#define C6_4 0x77
-#define C6_5 0x78
-#define C6_6 0x79
-#define C6_7 0x7A
-#define C6_8 0x7B
-
-#define C6_9 0x7C
-#define C6_10 0x7D
-#define C6_11 0x7E
-#define C6_12 0x7F
-#define C6_13 0x80
-#define C6_14 0x81
-#define C6_15 0x82
-#define C6_16 0x83
-
-#define C7_1 0x84
-#define C7_2 0x85
-#define C7_3 0x86
-#define C7_4 0x87
-#define C7_5 0x88
-#define C7_6 0x89
-#define C7_7 0x8A
-#define C7_8 0x8B
-
-#define C7_9 0x8C
-#define C7_10 0x8D
-#define C7_11 0x8E
-#define C7_12 0x8F
-#define C7_13 0x90
-#define C7_14 0x91
-#define C7_15 0x92
-#define C7_16 0x93
-
-#define C8_1 0x94
-#define C8_2 0x95
-#define C8_3 0x96
-#define C8_4 0x97
-#define C8_5 0x98
-#define C8_6 0x99
-#define C8_7 0x9A
-#define C8_8 0x9B
-
-#define C8_9 0x9C
-#define C8_10 0x9D
-#define C8_11 0x9E
-#define C8_12 0x9F
-#define C8_13 0xA0
-#define C8_14 0xA1
-#define C8_15 0xA2
-#define C8_16 0xA3
-
-#define C9_1 0xA4
-#define C9_2 0xA5
-#define C9_3 0xA6
-#define C9_4 0xA7
-#define C9_5 0xA8
-#define C9_6 0xA9
-#define C9_7 0xAA
-#define C9_8 0xAB
-
-#define C9_9 0xAC
-#define C9_10 0xAD
-#define C9_11 0xAE
-#define C9_12 0xAF
-#define C9_13 0xB0
-#define C9_14 0xB1
-#define C9_15 0xB2
-#define C9_16 0xB3
+#define C1_1 0x00
+#define C1_2 0x01
+#define C1_3 0x02
+#define C1_4 0x03
+#define C1_5 0x04
+#define C1_6 0x05
+#define C1_7 0x06
+#define C1_8 0x07
+
+#define C1_9 0x08
+#define C1_10 0x09
+#define C1_11 0x0A
+#define C1_12 0x0B
+#define C1_13 0x0C
+#define C1_14 0x0D
+#define C1_15 0x0E
+#define C1_16 0x0F
+
+#define C2_1 0x10
+#define C2_2 0x11
+#define C2_3 0x12
+#define C2_4 0x13
+#define C2_5 0x14
+#define C2_6 0x15
+#define C2_7 0x16
+#define C2_8 0x17
+
+#define C2_9 0x18
+#define C2_10 0x19
+#define C2_11 0x1A
+#define C2_12 0x1B
+#define C2_13 0x1C
+#define C2_14 0x1D
+#define C2_15 0x1E
+#define C2_16 0x1F
+
+#define C3_1 0x20
+#define C3_2 0x21
+#define C3_3 0x22
+#define C3_4 0x23
+#define C3_5 0x24
+#define C3_6 0x25
+#define C3_7 0x26
+#define C3_8 0x27
+
+#define C3_9 0x28
+#define C3_10 0x29
+#define C3_11 0x2A
+#define C3_12 0x2B
+#define C3_13 0x2C
+#define C3_14 0x2D
+#define C3_15 0x2E
+#define C3_16 0x2F
+
+#define C4_1 0x30
+#define C4_2 0x31
+#define C4_3 0x32
+#define C4_4 0x33
+#define C4_5 0x34
+#define C4_6 0x35
+#define C4_7 0x36
+#define C4_8 0x37
+
+#define C4_9 0x38
+#define C4_10 0x39
+#define C4_11 0x3A
+#define C4_12 0x3B
+#define C4_13 0x3C
+#define C4_14 0x3D
+#define C4_15 0x3E
+#define C4_16 0x3F
+
+#define C5_1 0x40
+#define C5_2 0x41
+#define C5_3 0x42
+#define C5_4 0x43
+#define C5_5 0x44
+#define C5_6 0x45
+#define C5_7 0x46
+#define C5_8 0x47
+
+#define C5_9 0x48
+#define C5_10 0x49
+#define C5_11 0x4A
+#define C5_12 0x4B
+#define C5_13 0x4C
+#define C5_14 0x4D
+#define C5_15 0x4E
+#define C5_16 0x4F
+
+#define C6_1 0x50
+#define C6_2 0x51
+#define C6_3 0x52
+#define C6_4 0x53
+#define C6_5 0x54
+#define C6_6 0x55
+#define C6_7 0x56
+#define C6_8 0x57
+
+#define C6_9 0x58
+#define C6_10 0x59
+#define C6_11 0x5A
+#define C6_12 0x5B
+#define C6_13 0x5C
+#define C6_14 0x5D
+#define C6_15 0x5E
+#define C6_16 0x5F
+
+#define C7_1 0x60
+#define C7_2 0x61
+#define C7_3 0x62
+#define C7_4 0x63
+#define C7_5 0x64
+#define C7_6 0x65
+#define C7_7 0x66
+#define C7_8 0x67
+
+#define C7_9 0x68
+#define C7_10 0x69
+#define C7_11 0x6A
+#define C7_12 0x6B
+#define C7_13 0x6C
+#define C7_14 0x6D
+#define C7_15 0x6E
+#define C7_16 0x6F
+
+#define C8_1 0x70
+#define C8_2 0x71
+#define C8_3 0x72
+#define C8_4 0x73
+#define C8_5 0x74
+#define C8_6 0x75
+#define C8_7 0x76
+#define C8_8 0x77
+
+#define C8_9 0x78
+#define C8_10 0x79
+#define C8_11 0x7A
+#define C8_12 0x7B
+#define C8_13 0x7C
+#define C8_14 0x7D
+#define C8_15 0x7E
+#define C8_16 0x7F
+
+#define C9_1 0x80
+#define C9_2 0x81
+#define C9_3 0x82
+#define C9_4 0x83
+#define C9_5 0x84
+#define C9_6 0x85
+#define C9_7 0x86
+#define C9_8 0x87
+
+#define C9_9 0x88
+#define C9_10 0x89
+#define C9_11 0x8A
+#define C9_12 0x8B
+#define C9_13 0x8C
+#define C9_14 0x8D
+#define C9_15 0x8E
+#define C9_16 0x8F
diff --git a/drivers/led/issi/is31fl3731.c b/drivers/led/issi/is31fl3731.c
index 1ab8997731..07f8194c0b 100644
--- a/drivers/led/issi/is31fl3731.c
+++ b/drivers/led/issi/is31fl3731.c
@@ -17,7 +17,6 @@
*/
#include "is31fl3731.h"
-#include <string.h>
#include "i2c_master.h"
#include "wait.h"
@@ -32,9 +31,6 @@
# define IS31FL3731_I2C_PERSISTENCE 0
#endif
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
// These buffers match the IS31FL3731 PWM registers 0x24-0xB3.
// Storing them like this is optimal for I2C transfers to the registers.
// We could optimize this and take out the unused registers from these
@@ -47,39 +43,31 @@ uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][IS31FL3731_LED_CONTROL_
bool g_led_control_registers_update_required[IS31FL3731_DRIVER_COUNT] = {false};
void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
#if IS31FL3731_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3731_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3731_I2C_TIMEOUT) == 0) break;
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3731_I2C_TIMEOUT);
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3731_I2C_TIMEOUT);
#endif
}
-void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // assumes bank is already selected
-
- // transmit PWM registers in 9 transfers of 16 bytes
- // g_twi_transfer_buffer[] is 20 bytes
+void is31fl3731_select_page(uint8_t addr, uint8_t page) {
+ is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, page);
+}
- // iterate over the pwm_buffer contents at 16 byte intervals
- for (int i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i += 16) {
- // set the first register, e.g. 0x24, 0x34, 0x44, etc.
- g_twi_transfer_buffer[0] = 0x24 + i;
- // copy the data from i to i+15
- // device will auto-increment register for data after the first byte
- // thus this sets registers 0x24-0x33, 0x34-0x43, etc. in one transfer
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
+void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 0 is already selected.
+ // Transmit PWM registers in 9 transfers of 16 bytes.
+ // Iterate over the pwm_buffer contents at 16 byte intervals.
+ for (uint8_t i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3731_I2C_PERSISTENCE > 0
- for (uint8_t i = 0; i < IS31FL3731_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT) == 0) break;
+ for (uint8_t j = 0; j < IS31FL3731_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT);
+ i2c_write_register(addr << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT);
#endif
}
}
@@ -120,8 +108,7 @@ void is31fl3731_init(uint8_t addr) {
// then set up the mode and other settings, clear the PWM registers,
// then disable software shutdown.
- // select "function register" bank
- is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FUNCTION);
+ is31fl3731_select_page(addr, IS31FL3731_COMMAND_FUNCTION);
// enable software shutdown
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_SHUTDOWN, 0x00);
@@ -139,48 +126,47 @@ void is31fl3731_init(uint8_t addr) {
// audio sync off
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_AUDIO_SYNC, 0x00);
- // select bank 0
- is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FRAME_1);
+ is31fl3731_select_page(addr, IS31FL3731_COMMAND_FRAME_1);
// turn off all LEDs in the LED control register
- for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
- is31fl3731_write_register(addr, i, 0x00);
+ for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
+ is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_LED_CONTROL + i, 0x00);
}
// turn off all LEDs in the blink control register (not really needed)
- for (int i = 0x12; i <= 0x23; i++) {
- is31fl3731_write_register(addr, i, 0x00);
+ for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
+ is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_BLINK_CONTROL + i, 0x00);
}
// set PWM on all LEDs to 0
- for (int i = 0x24; i <= 0xB3; i++) {
- is31fl3731_write_register(addr, i, 0x00);
+ for (uint8_t i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i++) {
+ is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_PWM + i, 0x00);
}
- // select "function register" bank
- is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FUNCTION);
+ is31fl3731_select_page(addr, IS31FL3731_COMMAND_FUNCTION);
// disable software shutdown
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_SHUTDOWN, 0x01);
- // select bank 0 and leave it selected.
- // most usage after initialization is just writing PWM buffers in bank 0
+ // select page 0 and leave it selected.
+ // most usage after initialization is just writing PWM buffers in page 0
// as there's not much point in double-buffering
- is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, IS31FL3731_COMMAND_FRAME_1);
+ is31fl3731_select_page(addr, IS31FL3731_COMMAND_FRAME_1);
}
void is31fl3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
is31fl3731_led_t led;
+
if (index >= 0 && index < IS31FL3731_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3731_leds[index]), sizeof(led));
- // Subtract 0x24 to get the second index of g_pwm_buffer
- if (g_pwm_buffer[led.driver][led.r - 0x24] == red && g_pwm_buffer[led.driver][led.g - 0x24] == green && g_pwm_buffer[led.driver][led.b - 0x24] == blue) {
+ if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) {
return;
}
- g_pwm_buffer[led.driver][led.r - 0x24] = red;
- g_pwm_buffer[led.driver][led.g - 0x24] = green;
- g_pwm_buffer[led.driver][led.b - 0x24] = blue;
+
+ g_pwm_buffer[led.driver][led.r] = red;
+ g_pwm_buffer[led.driver][led.g] = green;
+ g_pwm_buffer[led.driver][led.b] = blue;
g_pwm_buffer_update_required[led.driver] = true;
}
}
@@ -195,12 +181,12 @@ void is31fl3731_set_led_control_register(uint8_t index, bool red, bool green, bo
is31fl3731_led_t led;
memcpy_P(&led, (&g_is31fl3731_leds[index]), sizeof(led));
- uint8_t control_register_r = (led.r - 0x24) / 8;
- uint8_t control_register_g = (led.g - 0x24) / 8;
- uint8_t control_register_b = (led.b - 0x24) / 8;
- uint8_t bit_r = (led.r - 0x24) % 8;
- uint8_t bit_g = (led.g - 0x24) % 8;
- uint8_t bit_b = (led.b - 0x24) % 8;
+ uint8_t control_register_r = led.r / 8;
+ uint8_t control_register_g = led.g / 8;
+ uint8_t control_register_b = led.b / 8;
+ uint8_t bit_r = led.r % 8;
+ uint8_t bit_g = led.g % 8;
+ uint8_t bit_b = led.b % 8;
if (red) {
g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
@@ -223,18 +209,20 @@ void is31fl3731_set_led_control_register(uint8_t index, bool red, bool green, bo
void is31fl3731_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
- is31fl3731_write_pwm_buffer(addr, g_pwm_buffer[index]);
+ is31fl3731_write_pwm_buffer(addr, index);
+
+ g_pwm_buffer_update_required[index] = false;
}
- g_pwm_buffer_update_required[index] = false;
}
void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
- for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3731_write_register(addr, i, g_led_control_registers[index][i]);
}
+
+ g_led_control_registers_update_required[index] = false;
}
- g_led_control_registers_update_required[index] = false;
}
void is31fl3731_flush(void) {
diff --git a/drivers/led/issi/is31fl3731.h b/drivers/led/issi/is31fl3731.h
index b45cb2b07d..71cf38db4d 100644
--- a/drivers/led/issi/is31fl3731.h
+++ b/drivers/led/issi/is31fl3731.h
@@ -60,6 +60,10 @@
#define IS31FL3731_COMMAND_FRAME_8 0x07
#define IS31FL3731_COMMAND_FUNCTION 0x0B
+#define IS31FL3731_FRAME_REG_LED_CONTROL 0x00
+#define IS31FL3731_FRAME_REG_BLINK_CONTROL 0x12
+#define IS31FL3731_FRAME_REG_PWM 0x24
+
#define IS31FL3731_FUNCTION_REG_CONFIG 0x00
#define IS31FL3731_CONFIG_MODE_PICTURE 0x00
#define IS31FL3731_CONFIG_MODE_AUTO_PLAY 0x08
@@ -104,7 +108,7 @@ extern const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT];
void is31fl3731_init_drivers(void);
void is31fl3731_init(uint8_t addr);
void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+void is31fl3731_select_page(uint8_t addr, uint8_t page);
void is31fl3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void is31fl3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
@@ -120,164 +124,164 @@ void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index);
void is31fl3731_flush(void);
-#define C1_1 0x24
-#define C1_2 0x25
-#define C1_3 0x26
-#define C1_4 0x27
-#define C1_5 0x28
-#define C1_6 0x29
-#define C1_7 0x2A
-#define C1_8 0x2B
-
-#define C1_9 0x2C
-#define C1_10 0x2D
-#define C1_11 0x2E
-#define C1_12 0x2F
-#define C1_13 0x30
-#define C1_14 0x31
-#define C1_15 0x32
-#define C1_16 0x33
-
-#define C2_1 0x34
-#define C2_2 0x35
-#define C2_3 0x36
-#define C2_4 0x37
-#define C2_5 0x38
-#define C2_6 0x39
-#define C2_7 0x3A
-#define C2_8 0x3B
-
-#define C2_9 0x3C
-#define C2_10 0x3D
-#define C2_11 0x3E
-#define C2_12 0x3F
-#define C2_13 0x40
-#define C2_14 0x41
-#define C2_15 0x42
-#define C2_16 0x43
-
-#define C3_1 0x44
-#define C3_2 0x45
-#define C3_3 0x46
-#define C3_4 0x47
-#define C3_5 0x48
-#define C3_6 0x49
-#define C3_7 0x4A
-#define C3_8 0x4B
-
-#define C3_9 0x4C
-#define C3_10 0x4D
-#define C3_11 0x4E
-#define C3_12 0x4F
-#define C3_13 0x50
-#define C3_14 0x51
-#define C3_15 0x52
-#define C3_16 0x53
-
-#define C4_1 0x54
-#define C4_2 0x55
-#define C4_3 0x56
-#define C4_4 0x57
-#define C4_5 0x58
-#define C4_6 0x59
-#define C4_7 0x5A
-#define C4_8 0x5B
-
-#define C4_9 0x5C
-#define C4_10 0x5D
-#define C4_11 0x5E
-#define C4_12 0x5F
-#define C4_13 0x60
-#define C4_14 0x61
-#define C4_15 0x62
-#define C4_16 0x63
-
-#define C5_1 0x64
-#define C5_2 0x65
-#define C5_3 0x66
-#define C5_4 0x67
-#define C5_5 0x68
-#define C5_6 0x69
-#define C5_7 0x6A
-#define C5_8 0x6B
-
-#define C5_9 0x6C
-#define C5_10 0x6D
-#define C5_11 0x6E
-#define C5_12 0x6F
-#define C5_13 0x70
-#define C5_14 0x71
-#define C5_15 0x72
-#define C5_16 0x73
-
-#define C6_1 0x74
-#define C6_2 0x75
-#define C6_3 0x76
-#define C6_4 0x77
-#define C6_5 0x78
-#define C6_6 0x79
-#define C6_7 0x7A
-#define C6_8 0x7B
-
-#define C6_9 0x7C
-#define C6_10 0x7D
-#define C6_11 0x7E
-#define C6_12 0x7F
-#define C6_13 0x80
-#define C6_14 0x81
-#define C6_15 0x82
-#define C6_16 0x83
-
-#define C7_1 0x84
-#define C7_2 0x85
-#define C7_3 0x86
-#define C7_4 0x87
-#define C7_5 0x88
-#define C7_6 0x89
-#define C7_7 0x8A
-#define C7_8 0x8B
-
-#define C7_9 0x8C
-#define C7_10 0x8D
-#define C7_11 0x8E
-#define C7_12 0x8F
-#define C7_13 0x90
-#define C7_14 0x91
-#define C7_15 0x92
-#define C7_16 0x93
-
-#define C8_1 0x94
-#define C8_2 0x95
-#define C8_3 0x96
-#define C8_4 0x97
-#define C8_5 0x98
-#define C8_6 0x99
-#define C8_7 0x9A
-#define C8_8 0x9B
-
-#define C8_9 0x9C
-#define C8_10 0x9D
-#define C8_11 0x9E
-#define C8_12 0x9F
-#define C8_13 0xA0
-#define C8_14 0xA1
-#define C8_15 0xA2
-#define C8_16 0xA3
-
-#define C9_1 0xA4
-#define C9_2 0xA5
-#define C9_3 0xA6
-#define C9_4 0xA7
-#define C9_5 0xA8
-#define C9_6 0xA9
-#define C9_7 0xAA
-#define C9_8 0xAB
-
-#define C9_9 0xAC
-#define C9_10 0xAD
-#define C9_11 0xAE
-#define C9_12 0xAF
-#define C9_13 0xB0
-#define C9_14 0xB1
-#define C9_15 0xB2
-#define C9_16 0xB3
+#define C1_1 0x00
+#define C1_2 0x01
+#define C1_3 0x02
+#define C1_4 0x03
+#define C1_5 0x04
+#define C1_6 0x05
+#define C1_7 0x06
+#define C1_8 0x07
+
+#define C1_9 0x08
+#define C1_10 0x09
+#define C1_11 0x0A
+#define C1_12 0x0B
+#define C1_13 0x0C
+#define C1_14 0x0D
+#define C1_15 0x0E
+#define C1_16 0x0F
+
+#define C2_1 0x10
+#define C2_2 0x11
+#define C2_3 0x12
+#define C2_4 0x13
+#define C2_5 0x14
+#define C2_6 0x15
+#define C2_7 0x16
+#define C2_8 0x17
+
+#define C2_9 0x18
+#define C2_10 0x19
+#define C2_11 0x1A
+#define C2_12 0x1B
+#define C2_13 0x1C
+#define C2_14 0x1D
+#define C2_15 0x1E
+#define C2_16 0x1F
+
+#define C3_1 0x20
+#define C3_2 0x21
+#define C3_3 0x22
+#define C3_4 0x23
+#define C3_5 0x24
+#define C3_6 0x25
+#define C3_7 0x26
+#define C3_8 0x27
+
+#define C3_9 0x28
+#define C3_10 0x29
+#define C3_11 0x2A
+#define C3_12 0x2B
+#define C3_13 0x2C
+#define C3_14 0x2D
+#define C3_15 0x2E
+#define C3_16 0x2F
+
+#define C4_1 0x30
+#define C4_2 0x31
+#define C4_3 0x32
+#define C4_4 0x33
+#define C4_5 0x34
+#define C4_6 0x35
+#define C4_7 0x36
+#define C4_8 0x37
+
+#define C4_9 0x38
+#define C4_10 0x39
+#define C4_11 0x3A
+#define C4_12 0x3B
+#define C4_13 0x3C
+#define C4_14 0x3D
+#define C4_15 0x3E
+#define C4_16 0x3F
+
+#define C5_1 0x40
+#define C5_2 0x41
+#define C5_3 0x42
+#define C5_4 0x43
+#define C5_5 0x44
+#define C5_6 0x45
+#define C5_7 0x46
+#define C5_8 0x47
+
+#define C5_9 0x48
+#define C5_10 0x49
+#define C5_11 0x4A
+#define C5_12 0x4B
+#define C5_13 0x4C
+#define C5_14 0x4D
+#define C5_15 0x4E
+#define C5_16 0x4F
+
+#define C6_1 0x50
+#define C6_2 0x51
+#define C6_3 0x52
+#define C6_4 0x53
+#define C6_5 0x54
+#define C6_6 0x55
+#define C6_7 0x56
+#define C6_8 0x57
+
+#define C6_9 0x58
+#define C6_10 0x59
+#define C6_11 0x5A
+#define C6_12 0x5B
+#define C6_13 0x5C
+#define C6_14 0x5D
+#define C6_15 0x5E
+#define C6_16 0x5F
+
+#define C7_1 0x60
+#define C7_2 0x61
+#define C7_3 0x62
+#define C7_4 0x63
+#define C7_5 0x64
+#define C7_6 0x65
+#define C7_7 0x66
+#define C7_8 0x67
+
+#define C7_9 0x68
+#define C7_10 0x69
+#define C7_11 0x6A
+#define C7_12 0x6B
+#define C7_13 0x6C
+#define C7_14 0x6D
+#define C7_15 0x6E
+#define C7_16 0x6F
+
+#define C8_1 0x70
+#define C8_2 0x71
+#define C8_3 0x72
+#define C8_4 0x73
+#define C8_5 0x74
+#define C8_6 0x75
+#define C8_7 0x76
+#define C8_8 0x77
+
+#define C8_9 0x78
+#define C8_10 0x79
+#define C8_11 0x7A
+#define C8_12 0x7B
+#define C8_13 0x7C
+#define C8_14 0x7D
+#define C8_15 0x7E
+#define C8_16 0x7F
+
+#define C9_1 0x80
+#define C9_2 0x81
+#define C9_3 0x82
+#define C9_4 0x83
+#define C9_5 0x84
+#define C9_6 0x85
+#define C9_7 0x86
+#define C9_8 0x87
+
+#define C9_9 0x88
+#define C9_10 0x89
+#define C9_11 0x8A
+#define C9_12 0x8B
+#define C9_13 0x8C
+#define C9_14 0x8D
+#define C9_15 0x8E
+#define C9_16 0x8F
diff --git a/drivers/led/issi/is31fl3733-simple.c b/drivers/led/issi/is31fl3733-mono.c
index 9f2444c253..fe8419e2bc 100644
--- a/drivers/led/issi/is31fl3733-simple.c
+++ b/drivers/led/issi/is31fl3733-mono.c
@@ -18,8 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "is31fl3733-simple.h"
-#include <string.h>
+#include "is31fl3733-mono.h"
#include "i2c_master.h"
#include "wait.h"
@@ -43,7 +42,7 @@
#endif
#ifndef IS31FL3733_CS_PULLDOWN
-# define IS31FL3733_CSPULLDOWN IS31FL3733_PDR_0_OHM
+# define IS31FL3733_CS_PULLDOWN IS31FL3733_PDR_0_OHM
#endif
#ifndef IS31FL3733_GLOBAL_CURRENT
@@ -63,11 +62,8 @@
# define IS31FL3733_SYNC_4 IS31FL3733_SYNC_NONE
#endif
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
// These buffers match the IS31FL3733 PWM registers.
-// The control buffers match the PG0 LED On/Off registers.
+// The control buffers match the page 0 LED On/Off registers.
// Storing them like this is optimal for I2C transfers to the registers.
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3733_write_pwm_buffer() but it's
@@ -78,52 +74,35 @@ bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false};
uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][IS31FL3733_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false};
-bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- // If the transaction fails function returns false.
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
+void is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
#if IS31FL3733_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
- return false;
- }
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
- return false;
- }
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3733_I2C_TIMEOUT);
#endif
- return true;
}
-bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // Assumes PG1 is already selected.
- // If any of the transactions fails function returns false.
+void is31fl3733_select_page(uint8_t addr, uint8_t page) {
+ is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, page);
+}
+
+void is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 1 is already selected.
// Transmit PWM registers in 12 transfers of 16 bytes.
- // g_twi_transfer_buffer[] is 20 bytes
// Iterate over the pwm_buffer contents at 16 byte intervals.
- for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
- g_twi_transfer_buffer[0] = i;
- // Copy the data from i to i+15.
- // Device will auto-increment register for data after the first byte
- // Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer.
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
-
+ for (uint8_t i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3733_I2C_PERSISTENCE > 0
- for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
- return false;
- }
+ for (uint8_t j = 0; j < IS31FL3733_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
- return false;
- }
+ i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT);
#endif
}
- return true;
}
void is31fl3733_init_drivers(void) {
@@ -163,32 +142,23 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) {
// then disable software shutdown.
// Sync is passed so set it according to the datasheet.
- // Unlock the command register.
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3733_select_page(addr, IS31FL3733_COMMAND_LED_CONTROL);
- // Select PG0
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_LED_CONTROL);
// Turn off all LEDs.
- for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3733_write_register(addr, i, 0x00);
}
- // Unlock the command register.
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3733_select_page(addr, IS31FL3733_COMMAND_PWM);
- // Select PG1
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_PWM);
// Set PWM on all LEDs to 0
// No need to setup Breath registers to PWM as that is the default.
- for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i++) {
is31fl3733_write_register(addr, i, 0x00);
}
- // Unlock the command register.
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3733_select_page(addr, IS31FL3733_COMMAND_FUNCTION);
- // Select PG3
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_FUNCTION);
// Set de-ghost pull-up resistors (SWx)
is31fl3733_write_register(addr, IS31FL3733_FUNCTION_REG_SW_PULLUP, IS31FL3733_SW_PULLUP);
// Set de-ghost pull-down resistors (CSx)
@@ -204,12 +174,14 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) {
void is31fl3733_set_value(int index, uint8_t value) {
is31fl3733_led_t led;
+
if (index >= 0 && index < IS31FL3733_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3733_leds[index]), sizeof(led));
if (g_pwm_buffer[led.driver][led.v] == value) {
return;
}
+
g_pwm_buffer[led.driver][led.v] = value;
g_pwm_buffer_update_required[led.driver] = true;
}
@@ -239,27 +211,22 @@ void is31fl3733_set_led_control_register(uint8_t index, bool value) {
void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
- // Firstly we need to unlock the command register and select PG1.
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_PWM);
-
- // If any of the transactions fail we risk writing dirty PG0,
- // refresh page 0 just in case.
- if (!is31fl3733_write_pwm_buffer(addr, g_pwm_buffer[index])) {
- g_led_control_registers_update_required[index] = true;
- }
+ is31fl3733_select_page(addr, IS31FL3733_COMMAND_PWM);
+
+ is31fl3733_write_pwm_buffer(addr, index);
+
g_pwm_buffer_update_required[index] = false;
}
}
void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
- // Firstly we need to unlock the command register and select PG0
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_LED_CONTROL);
- for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
+ is31fl3733_select_page(addr, IS31FL3733_COMMAND_LED_CONTROL);
+
+ for (uint8_t i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3733_write_register(addr, i, g_led_control_registers[index][i]);
}
+
g_led_control_registers_update_required[index] = false;
}
}
diff --git a/drivers/led/issi/is31fl3733-simple.h b/drivers/led/issi/is31fl3733-mono.h
index c37b1fe5f2..591fca907a 100644
--- a/drivers/led/issi/is31fl3733-simple.h
+++ b/drivers/led/issi/is31fl3733-mono.h
@@ -116,8 +116,8 @@ extern const is31fl3733_led_t PROGMEM g_is31fl3733_leds[IS31FL3733_LED_COUNT];
void is31fl3733_init_drivers(void);
void is31fl3733_init(uint8_t addr, uint8_t sync);
-bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+void is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void is31fl3733_select_page(uint8_t addr, uint8_t page);
void is31fl3733_set_value(int index, uint8_t value);
void is31fl3733_set_value_all(uint8_t value);
diff --git a/drivers/led/issi/is31fl3733.c b/drivers/led/issi/is31fl3733.c
index 5857a800d7..a54b9c90ba 100644
--- a/drivers/led/issi/is31fl3733.c
+++ b/drivers/led/issi/is31fl3733.c
@@ -18,7 +18,6 @@
*/
#include "is31fl3733.h"
-#include <string.h>
#include "i2c_master.h"
#include "wait.h"
@@ -62,11 +61,8 @@
# define IS31FL3733_SYNC_4 IS31FL3733_SYNC_NONE
#endif
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
// These buffers match the IS31FL3733 PWM registers.
-// The control buffers match the PG0 LED On/Off registers.
+// The control buffers match the page 0 LED On/Off registers.
// Storing them like this is optimal for I2C transfers to the registers.
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3733_write_pwm_buffer() but it's
@@ -77,52 +73,35 @@ bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false};
uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][IS31FL3733_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false};
-bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- // If the transaction fails function returns false.
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
+void is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
#if IS31FL3733_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
- return false;
- }
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
- return false;
- }
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3733_I2C_TIMEOUT);
#endif
- return true;
}
-bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // Assumes PG1 is already selected.
- // If any of the transactions fails function returns false.
+void is31fl3733_select_page(uint8_t addr, uint8_t page) {
+ is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, page);
+}
+
+void is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 1 is already selected.
// Transmit PWM registers in 12 transfers of 16 bytes.
- // g_twi_transfer_buffer[] is 20 bytes
// Iterate over the pwm_buffer contents at 16 byte intervals.
- for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
- g_twi_transfer_buffer[0] = i;
- // Copy the data from i to i+15.
- // Device will auto-increment register for data after the first byte
- // Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer.
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
-
+ for (uint8_t i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3733_I2C_PERSISTENCE > 0
- for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
- return false;
- }
+ for (uint8_t j = 0; j < IS31FL3733_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
- return false;
- }
+ i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT);
#endif
}
- return true;
}
void is31fl3733_init_drivers(void) {
@@ -162,32 +141,23 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) {
// then disable software shutdown.
// Sync is passed so set it according to the datasheet.
- // Unlock the command register.
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3733_select_page(addr, IS31FL3733_COMMAND_LED_CONTROL);
- // Select PG0
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_LED_CONTROL);
// Turn off all LEDs.
- for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3733_write_register(addr, i, 0x00);
}
- // Unlock the command register.
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3733_select_page(addr, IS31FL3733_COMMAND_PWM);
- // Select PG1
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_PWM);
// Set PWM on all LEDs to 0
// No need to setup Breath registers to PWM as that is the default.
- for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i++) {
is31fl3733_write_register(addr, i, 0x00);
}
- // Unlock the command register.
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3733_select_page(addr, IS31FL3733_COMMAND_FUNCTION);
- // Select PG3
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_FUNCTION);
// Set de-ghost pull-up resistors (SWx)
is31fl3733_write_register(addr, IS31FL3733_FUNCTION_REG_SW_PULLUP, IS31FL3733_SW_PULLUP);
// Set de-ghost pull-down resistors (CSx)
@@ -203,12 +173,14 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) {
void is31fl3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
is31fl3733_led_t led;
+
if (index >= 0 && index < IS31FL3733_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3733_leds[index]), sizeof(led));
if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) {
return;
}
+
g_pwm_buffer[led.driver][led.r] = red;
g_pwm_buffer[led.driver][led.g] = green;
g_pwm_buffer[led.driver][led.b] = blue;
@@ -254,27 +226,22 @@ void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bo
void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
- // Firstly we need to unlock the command register and select PG1.
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_PWM);
-
- // If any of the transactions fail we risk writing dirty PG0,
- // refresh page 0 just in case.
- if (!is31fl3733_write_pwm_buffer(addr, g_pwm_buffer[index])) {
- g_led_control_registers_update_required[index] = true;
- }
+ is31fl3733_select_page(addr, IS31FL3733_COMMAND_PWM);
+
+ is31fl3733_write_pwm_buffer(addr, index);
+
g_pwm_buffer_update_required[index] = false;
}
}
void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
- // Firstly we need to unlock the command register and select PG0
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_LED_CONTROL);
- for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
+ is31fl3733_select_page(addr, IS31FL3733_COMMAND_LED_CONTROL);
+
+ for (uint8_t i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3733_write_register(addr, i, g_led_control_registers[index][i]);
}
+
g_led_control_registers_update_required[index] = false;
}
}
diff --git a/drivers/led/issi/is31fl3733.h b/drivers/led/issi/is31fl3733.h
index 20804b016b..532d35ed57 100644
--- a/drivers/led/issi/is31fl3733.h
+++ b/drivers/led/issi/is31fl3733.h
@@ -40,13 +40,13 @@
#ifdef DRIVER_SYNC_1
# define IS31FL3733_SYNC_1 DRIVER_SYNC_1
#endif
-#ifdef DRIVER_ADDR_2
+#ifdef DRIVER_SYNC_2
# define IS31FL3733_SYNC_2 DRIVER_SYNC_2
#endif
-#ifdef DRIVER_ADDR_3
+#ifdef DRIVER_SYNC_3
# define IS31FL3733_SYNC_3 DRIVER_SYNC_3
#endif
-#ifdef DRIVER_ADDR_4
+#ifdef DRIVER_SYNC_4
# define IS31FL3733_SYNC_4 DRIVER_SYNC_4
#endif
#ifdef ISSI_TIMEOUT
@@ -141,8 +141,8 @@ extern const is31fl3733_led_t PROGMEM g_is31fl3733_leds[IS31FL3733_LED_COUNT];
void is31fl3733_init_drivers(void);
void is31fl3733_init(uint8_t addr, uint8_t sync);
-bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+void is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void is31fl3733_select_page(uint8_t addr, uint8_t page);
void is31fl3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void is31fl3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
diff --git a/drivers/led/issi/is31fl3736-simple.c b/drivers/led/issi/is31fl3736-mono.c
index e1cce3c48a..2bb83169a4 100644
--- a/drivers/led/issi/is31fl3736-simple.c
+++ b/drivers/led/issi/is31fl3736-mono.c
@@ -15,8 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "is31fl3736-simple.h"
-#include <string.h>
+#include "is31fl3736-mono.h"
#include "i2c_master.h"
#include "wait.h"
@@ -47,11 +46,8 @@
# define IS31FL3736_GLOBAL_CURRENT 0xFF
#endif
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
// These buffers match the IS31FL3736 PWM registers.
-// The control buffers match the PG0 LED On/Off registers.
+// The control buffers match the page 0 LED On/Off registers.
// Storing them like this is optimal for I2C transfers to the registers.
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3736_write_pwm_buffer() but it's
@@ -63,38 +59,32 @@ uint8_t g_led_control_registers[IS31FL3736_DRIVER_COUNT][IS31FL3736_LED_CONTROL_
bool g_led_control_registers_update_required[IS31FL3736_DRIVER_COUNT] = {false};
void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
#if IS31FL3736_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3736_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3736_I2C_TIMEOUT) == 0) break;
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3736_I2C_TIMEOUT);
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3736_I2C_TIMEOUT);
#endif
}
-void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // assumes PG1 is already selected
-
- // transmit PWM registers in 12 transfers of 16 bytes
- // g_twi_transfer_buffer[] is 20 bytes
+void is31fl3736_select_page(uint8_t addr, uint8_t page) {
+ is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND, page);
+}
- // iterate over the pwm_buffer contents at 16 byte intervals
- for (int i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i += 16) {
- g_twi_transfer_buffer[0] = i;
- // copy the data from i to i+15
- // device will auto-increment register for data after the first byte
- // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
+void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 1 is already selected.
+ // Transmit PWM registers in 12 transfers of 16 bytes.
+ // Iterate over the pwm_buffer contents at 16 byte intervals.
+ for (uint8_t i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3736_I2C_PERSISTENCE > 0
- for (uint8_t i = 0; i < IS31FL3736_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3736_I2C_TIMEOUT) == 0) break;
+ for (uint8_t j = 0; j < IS31FL3736_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3736_I2C_TIMEOUT);
+ i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT);
#endif
}
}
@@ -135,32 +125,23 @@ void is31fl3736_init(uint8_t addr) {
// Set up the mode and other settings, clear the PWM registers,
// then disable software shutdown.
- // Unlock the command register.
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3736_select_page(addr, IS31FL3736_COMMAND_LED_CONTROL);
- // Select PG0
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND, IS31FL3736_COMMAND_LED_CONTROL);
// Turn off all LEDs.
- for (int i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3736_write_register(addr, i, 0x00);
}
- // Unlock the command register.
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3736_select_page(addr, IS31FL3736_COMMAND_PWM);
- // Select PG1
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND, IS31FL3736_COMMAND_PWM);
// Set PWM on all LEDs to 0
// No need to setup Breath registers to PWM as that is the default.
- for (int i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i++) {
is31fl3736_write_register(addr, i, 0x00);
}
- // Unlock the command register.
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3736_select_page(addr, IS31FL3736_COMMAND_FUNCTION);
- // Select PG3
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND, IS31FL3736_COMMAND_FUNCTION);
// Set de-ghost pull-up resistors (SWx)
is31fl3736_write_register(addr, IS31FL3736_FUNCTION_REG_SW_PULLUP, IS31FL3736_SW_PULLUP);
// Set de-ghost pull-down resistors (CSx)
@@ -176,12 +157,14 @@ void is31fl3736_init(uint8_t addr) {
void is31fl3736_set_value(int index, uint8_t value) {
is31fl3736_led_t led;
+
if (index >= 0 && index < IS31FL3736_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3736_leds[index]), sizeof(led));
if (g_pwm_buffer[led.driver][led.v] == value) {
return;
}
+
g_pwm_buffer[led.driver][led.v] = value;
g_pwm_buffer_update_required[led.driver] = true;
}
@@ -217,23 +200,22 @@ void is31fl3736_set_led_control_register(uint8_t index, bool value) {
void is31fl3736_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
- // Firstly we need to unlock the command register and select PG1
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND, IS31FL3736_COMMAND_PWM);
+ is31fl3736_select_page(addr, IS31FL3736_COMMAND_PWM);
+
+ is31fl3736_write_pwm_buffer(addr, index);
- is31fl3736_write_pwm_buffer(addr, g_pwm_buffer[index]);
g_pwm_buffer_update_required[index] = false;
}
}
void is31fl3736_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
- // Firstly we need to unlock the command register and select PG0
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND, IS31FL3736_COMMAND_LED_CONTROL);
- for (int i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
+ is31fl3736_select_page(addr, IS31FL3736_COMMAND_LED_CONTROL);
+
+ for (uint8_t i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3736_write_register(addr, i, g_led_control_registers[index][i]);
}
+
g_led_control_registers_update_required[index] = false;
}
}
diff --git a/drivers/led/issi/is31fl3736-simple.h b/drivers/led/issi/is31fl3736-mono.h
index a73a872545..43d1548c02 100644
--- a/drivers/led/issi/is31fl3736-simple.h
+++ b/drivers/led/issi/is31fl3736-mono.h
@@ -112,7 +112,7 @@ extern const is31fl3736_led_t PROGMEM g_is31fl3736_leds[IS31FL3736_LED_COUNT];
void is31fl3736_init_drivers(void);
void is31fl3736_init(uint8_t addr);
void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+void is31fl3736_select_page(uint8_t addr, uint8_t page);
void is31fl3736_set_value(int index, uint8_t value);
void is31fl3736_set_value_all(uint8_t value);
diff --git a/drivers/led/issi/is31fl3736.c b/drivers/led/issi/is31fl3736.c
index 30ab796f3e..e4cba2c398 100644
--- a/drivers/led/issi/is31fl3736.c
+++ b/drivers/led/issi/is31fl3736.c
@@ -16,7 +16,6 @@
*/
#include "is31fl3736.h"
-#include <string.h>
#include "i2c_master.h"
#include "wait.h"
@@ -47,11 +46,8 @@
# define IS31FL3736_GLOBAL_CURRENT 0xFF
#endif
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
// These buffers match the IS31FL3736 PWM registers.
-// The control buffers match the PG0 LED On/Off registers.
+// The control buffers match the page 0 LED On/Off registers.
// Storing them like this is optimal for I2C transfers to the registers.
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3736_write_pwm_buffer() but it's
@@ -63,38 +59,32 @@ uint8_t g_led_control_registers[IS31FL3736_DRIVER_COUNT][IS31FL3736_LED_CONTROL_
bool g_led_control_registers_update_required[IS31FL3736_DRIVER_COUNT] = {false};
void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
#if IS31FL3736_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3736_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3736_I2C_TIMEOUT) == 0) break;
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3736_I2C_TIMEOUT);
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3736_I2C_TIMEOUT);
#endif
}
-void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // assumes PG1 is already selected
-
- // transmit PWM registers in 12 transfers of 16 bytes
- // g_twi_transfer_buffer[] is 20 bytes
+void is31fl3736_select_page(uint8_t addr, uint8_t page) {
+ is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND, page);
+}
- // iterate over the pwm_buffer contents at 16 byte intervals
- for (int i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i += 16) {
- g_twi_transfer_buffer[0] = i;
- // copy the data from i to i+15
- // device will auto-increment register for data after the first byte
- // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
+void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 1 is already selected.
+ // Transmit PWM registers in 12 transfers of 16 bytes.
+ // Iterate over the pwm_buffer contents at 16 byte intervals.
+ for (uint8_t i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3736_I2C_PERSISTENCE > 0
- for (uint8_t i = 0; i < IS31FL3736_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3736_I2C_TIMEOUT) == 0) break;
+ for (uint8_t j = 0; j < IS31FL3736_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3736_I2C_TIMEOUT);
+ i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT);
#endif
}
}
@@ -135,32 +125,23 @@ void is31fl3736_init(uint8_t addr) {
// Set up the mode and other settings, clear the PWM registers,
// then disable software shutdown.
- // Unlock the command register.
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3736_select_page(addr, IS31FL3736_COMMAND_LED_CONTROL);
- // Select PG0
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND, IS31FL3736_REG_LED_CONTROL);
// Turn off all LEDs.
- for (int i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3736_write_register(addr, i, 0x00);
}
- // Unlock the command register.
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND_WRITELOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3736_select_page(addr, IS31FL3736_COMMAND_PWM);
- // Select PG1
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND, IS31FL3736_COMMAND_PWM);
// Set PWM on all LEDs to 0
// No need to setup Breath registers to PWM as that is the default.
- for (int i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i++) {
is31fl3736_write_register(addr, i, 0x00);
}
- // Unlock the command register.
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3736_select_page(addr, IS31FL3736_COMMAND_FUNCTION);
- // Select PG3
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND, IS31FL3736_COMMAND_FUNCTION);
// Set de-ghost pull-up resistors (SWx)
is31fl3736_write_register(addr, IS31FL3736_FUNCTION_REG_SW_PULLUP, IS31FL3736_SW_PULLUP);
// Set de-ghost pull-down resistors (CSx)
@@ -176,12 +157,14 @@ void is31fl3736_init(uint8_t addr) {
void is31fl3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
is31fl3736_led_t led;
+
if (index >= 0 && index < IS31FL3736_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3736_leds[index]), sizeof(led));
if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) {
return;
}
+
g_pwm_buffer[led.driver][led.r] = red;
g_pwm_buffer[led.driver][led.g] = green;
g_pwm_buffer[led.driver][led.b] = blue;
@@ -234,23 +217,22 @@ void is31fl3736_set_led_control_register(uint8_t index, bool red, bool green, bo
void is31fl3736_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
- // Firstly we need to unlock the command register and select PG1
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND, IS31FL3736_COMMAND_PWM);
+ is31fl3736_select_page(addr, IS31FL3736_COMMAND_PWM);
+
+ is31fl3736_write_pwm_buffer(addr, index);
- is31fl3736_write_pwm_buffer(addr, g_pwm_buffer[index]);
g_pwm_buffer_update_required[index] = false;
}
}
void is31fl3736_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
- // Firstly we need to unlock the command register and select PG0
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND, IS31FL3736_COMMAND_LED_CONTROL);
- for (int i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
+ is31fl3736_select_page(addr, IS31FL3736_COMMAND_LED_CONTROL);
+
+ for (uint8_t i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3736_write_register(addr, i, g_led_control_registers[index][i]);
}
+
g_led_control_registers_update_required[index] = false;
}
}
diff --git a/drivers/led/issi/is31fl3736.h b/drivers/led/issi/is31fl3736.h
index a5710d7ed4..086edc0e4a 100644
--- a/drivers/led/issi/is31fl3736.h
+++ b/drivers/led/issi/is31fl3736.h
@@ -126,7 +126,7 @@ extern const is31fl3736_led_t PROGMEM g_is31fl3736_leds[IS31FL3736_LED_COUNT];
void is31fl3736_init_drivers(void);
void is31fl3736_init(uint8_t addr);
void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+void is31fl3736_select_page(uint8_t addr, uint8_t page);
void is31fl3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void is31fl3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
diff --git a/drivers/led/issi/is31fl3737-simple.c b/drivers/led/issi/is31fl3737-mono.c
index 7f641f4ca5..0e22ea8a6a 100644
--- a/drivers/led/issi/is31fl3737-simple.c
+++ b/drivers/led/issi/is31fl3737-mono.c
@@ -17,8 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "is31fl3737-simple.h"
-#include <string.h>
+#include "is31fl3737-mono.h"
#include "i2c_master.h"
#include "wait.h"
@@ -49,11 +48,8 @@
# define IS31FL3737_GLOBAL_CURRENT 0xFF
#endif
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
// These buffers match the IS31FL3737 PWM registers.
-// The control buffers match the PG0 LED On/Off registers.
+// The control buffers match the page 0 LED On/Off registers.
// Storing them like this is optimal for I2C transfers to the registers.
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3737_write_pwm_buffer() but it's
@@ -66,38 +62,32 @@ uint8_t g_led_control_registers[IS31FL3737_DRIVER_COUNT][IS31FL3737_LED_CONTROL_
bool g_led_control_registers_update_required[IS31FL3737_DRIVER_COUNT] = {false};
void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
#if IS31FL3737_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3737_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3737_I2C_TIMEOUT) == 0) break;
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3737_I2C_TIMEOUT);
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3737_I2C_TIMEOUT);
#endif
}
-void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // assumes PG1 is already selected
-
- // transmit PWM registers in 12 transfers of 16 bytes
- // g_twi_transfer_buffer[] is 20 bytes
+void is31fl3737_select_page(uint8_t addr, uint8_t page) {
+ is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND, page);
+}
- // iterate over the pwm_buffer contents at 16 byte intervals
- for (int i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i += 16) {
- g_twi_transfer_buffer[0] = i;
- // copy the data from i to i+15
- // device will auto-increment register for data after the first byte
- // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
+void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 1 is already selected.
+ // Transmit PWM registers in 12 transfers of 16 bytes.
+ // Iterate over the pwm_buffer contents at 16 byte intervals.
+ for (uint8_t i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3737_I2C_PERSISTENCE > 0
- for (uint8_t i = 0; i < IS31FL3737_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3737_I2C_TIMEOUT) == 0) break;
+ for (uint8_t j = 0; j < IS31FL3737_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3737_I2C_TIMEOUT);
+ i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT);
#endif
}
}
@@ -138,32 +128,23 @@ void is31fl3737_init(uint8_t addr) {
// Set up the mode and other settings, clear the PWM registers,
// then disable software shutdown.
- // Unlock the command register.
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3737_select_page(addr, IS31FL3737_COMMAND_LED_CONTROL);
- // Select PG0
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND, IS31FL3737_COMMAND_LED_CONTROL);
// Turn off all LEDs.
- for (int i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3737_write_register(addr, i, 0x00);
}
- // Unlock the command register.
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3737_select_page(addr, IS31FL3737_COMMAND_PWM);
- // Select PG1
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND, IS31FL3737_COMMAND_PWM);
// Set PWM on all LEDs to 0
// No need to setup Breath registers to PWM as that is the default.
- for (int i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i++) {
is31fl3737_write_register(addr, i, 0x00);
}
- // Unlock the command register.
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3737_select_page(addr, IS31FL3737_COMMAND_FUNCTION);
- // Select PG3
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND, IS31FL3737_COMMAND_FUNCTION);
// Set de-ghost pull-up resistors (SWx)
is31fl3737_write_register(addr, IS31FL3737_FUNCTION_REG_SW_PULLUP, IS31FL3737_SW_PULLUP);
// Set de-ghost pull-down resistors (CSx)
@@ -179,12 +160,14 @@ void is31fl3737_init(uint8_t addr) {
void is31fl3737_set_value(int index, uint8_t value) {
is31fl3737_led_t led;
+
if (index >= 0 && index < IS31FL3737_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3737_leds[index]), sizeof(led));
if (g_pwm_buffer[led.driver][led.v] == value) {
return;
}
+
g_pwm_buffer[led.driver][led.v] = value;
g_pwm_buffer_update_required[led.driver] = true;
}
@@ -214,23 +197,22 @@ void is31fl3737_set_led_control_register(uint8_t index, bool value) {
void is31fl3737_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
- // Firstly we need to unlock the command register and select PG1
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND, IS31FL3737_COMMAND_PWM);
+ is31fl3737_select_page(addr, IS31FL3737_COMMAND_PWM);
+
+ is31fl3737_write_pwm_buffer(addr, index);
- is31fl3737_write_pwm_buffer(addr, g_pwm_buffer[index]);
g_pwm_buffer_update_required[index] = false;
}
}
void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
- // Firstly we need to unlock the command register and select PG0
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND, IS31FL3737_COMMAND_LED_CONTROL);
- for (int i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
+ is31fl3737_select_page(addr, IS31FL3737_COMMAND_LED_CONTROL);
+
+ for (uint8_t i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3737_write_register(addr, i, g_led_control_registers[index][i]);
}
+
g_led_control_registers_update_required[index] = false;
}
}
diff --git a/drivers/led/issi/is31fl3737-simple.h b/drivers/led/issi/is31fl3737-mono.h
index 2658702b1b..6d081bfa00 100644
--- a/drivers/led/issi/is31fl3737-simple.h
+++ b/drivers/led/issi/is31fl3737-mono.h
@@ -102,7 +102,7 @@ extern const is31fl3737_led_t PROGMEM g_is31fl3737_leds[IS31FL3737_LED_COUNT];
void is31fl3737_init_drivers(void);
void is31fl3737_init(uint8_t addr);
void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+void is31fl3737_select_page(uint8_t addr, uint8_t page);
void is31fl3737_set_value(int index, uint8_t value);
void is31fl3737_set_value_all(uint8_t value);
diff --git a/drivers/led/issi/is31fl3737.c b/drivers/led/issi/is31fl3737.c
index a458431952..e17d73c36f 100644
--- a/drivers/led/issi/is31fl3737.c
+++ b/drivers/led/issi/is31fl3737.c
@@ -18,7 +18,6 @@
*/
#include "is31fl3737.h"
-#include <string.h>
#include "i2c_master.h"
#include "wait.h"
@@ -41,7 +40,7 @@
# define IS31FL3737_SW_PULLUP IS31FL3737_PUR_0_OHM
#endif
-#ifndef IS31FL3737_CS_PULLDONW
+#ifndef IS31FL3737_CS_PULLDOWN
# define IS31FL3737_CS_PULLDOWN IS31FL3737_PDR_0_OHM
#endif
@@ -49,11 +48,8 @@
# define IS31FL3737_GLOBAL_CURRENT 0xFF
#endif
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
// These buffers match the IS31FL3737 PWM registers.
-// The control buffers match the PG0 LED On/Off registers.
+// The control buffers match the page 0 LED On/Off registers.
// Storing them like this is optimal for I2C transfers to the registers.
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3737_write_pwm_buffer() but it's
@@ -66,38 +62,32 @@ uint8_t g_led_control_registers[IS31FL3737_DRIVER_COUNT][IS31FL3737_LED_CONTROL_
bool g_led_control_registers_update_required[IS31FL3737_DRIVER_COUNT] = {false};
void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
#if IS31FL3737_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3737_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3737_I2C_TIMEOUT) == 0) break;
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3737_I2C_TIMEOUT);
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3737_I2C_TIMEOUT);
#endif
}
-void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // assumes PG1 is already selected
-
- // transmit PWM registers in 12 transfers of 16 bytes
- // g_twi_transfer_buffer[] is 20 bytes
+void is31fl3737_select_page(uint8_t addr, uint8_t page) {
+ is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND, page);
+}
- // iterate over the pwm_buffer contents at 16 byte intervals
- for (int i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i += 16) {
- g_twi_transfer_buffer[0] = i;
- // copy the data from i to i+15
- // device will auto-increment register for data after the first byte
- // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
+void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 1 is already selected.
+ // Transmit PWM registers in 12 transfers of 16 bytes.
+ // Iterate over the pwm_buffer contents at 16 byte intervals.
+ for (uint8_t i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3737_I2C_PERSISTENCE > 0
- for (uint8_t i = 0; i < IS31FL3737_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3737_I2C_TIMEOUT) == 0) break;
+ for (uint8_t j = 0; j < IS31FL3737_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3737_I2C_TIMEOUT);
+ i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT);
#endif
}
}
@@ -138,32 +128,23 @@ void is31fl3737_init(uint8_t addr) {
// Set up the mode and other settings, clear the PWM registers,
// then disable software shutdown.
- // Unlock the command register.
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3737_select_page(addr, IS31FL3737_COMMAND_LED_CONTROL);
- // Select PG0
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND, IS31FL3737_COMMAND_LED_CONTROL);
// Turn off all LEDs.
- for (int i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3737_write_register(addr, i, 0x00);
}
- // Unlock the command register.
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3737_select_page(addr, IS31FL3737_COMMAND_PWM);
- // Select PG1
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND, IS31FL3737_COMMAND_PWM);
// Set PWM on all LEDs to 0
// No need to setup Breath registers to PWM as that is the default.
- for (int i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i++) {
+ for (uint8_t i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i++) {
is31fl3737_write_register(addr, i, 0x00);
}
- // Unlock the command register.
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3737_select_page(addr, IS31FL3737_COMMAND_FUNCTION);
- // Select PG3
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND, IS31FL3737_COMMAND_FUNCTION);
// Set de-ghost pull-up resistors (SWx)
is31fl3737_write_register(addr, IS31FL3737_FUNCTION_REG_SW_PULLUP, IS31FL3737_SW_PULLUP);
// Set de-ghost pull-down resistors (CSx)
@@ -179,12 +160,14 @@ void is31fl3737_init(uint8_t addr) {
void is31fl3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
is31fl3737_led_t led;
+
if (index >= 0 && index < IS31FL3737_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3737_leds[index]), sizeof(led));
if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) {
return;
}
+
g_pwm_buffer[led.driver][led.r] = red;
g_pwm_buffer[led.driver][led.g] = green;
g_pwm_buffer[led.driver][led.b] = blue;
@@ -230,23 +213,22 @@ void is31fl3737_set_led_control_register(uint8_t index, bool red, bool green, bo
void is31fl3737_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
- // Firstly we need to unlock the command register and select PG1
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND, IS31FL3737_COMMAND_PWM);
+ is31fl3737_select_page(addr, IS31FL3737_COMMAND_PWM);
+
+ is31fl3737_write_pwm_buffer(addr, index);
- is31fl3737_write_pwm_buffer(addr, g_pwm_buffer[index]);
g_pwm_buffer_update_required[index] = false;
}
}
void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
- // Firstly we need to unlock the command register and select PG0
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND, IS31FL3737_COMMAND_LED_CONTROL);
- for (int i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
+ is31fl3737_select_page(addr, IS31FL3737_COMMAND_LED_CONTROL);
+
+ for (uint8_t i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3737_write_register(addr, i, g_led_control_registers[index][i]);
}
+
g_led_control_registers_update_required[index] = false;
}
}
diff --git a/drivers/led/issi/is31fl3737.h b/drivers/led/issi/is31fl3737.h
index 8de3bf4ef5..7f0d86df82 100644
--- a/drivers/led/issi/is31fl3737.h
+++ b/drivers/led/issi/is31fl3737.h
@@ -119,7 +119,7 @@ extern const is31fl3737_led_t PROGMEM g_is31fl3737_leds[IS31FL3737_LED_COUNT];
void is31fl3737_init_drivers(void);
void is31fl3737_init(uint8_t addr);
void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+void is31fl3737_select_page(uint8_t addr, uint8_t page);
void is31fl3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void is31fl3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
diff --git a/drivers/led/issi/is31fl3741-simple.c b/drivers/led/issi/is31fl3741-mono.c
index f7009853ba..4f388f56b0 100644
--- a/drivers/led/issi/is31fl3741-simple.c
+++ b/drivers/led/issi/is31fl3741-mono.c
@@ -17,12 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "is31fl3741-simple.h"
-#include <string.h>
+#include "is31fl3741-mono.h"
#include "i2c_master.h"
#include "wait.h"
#define IS31FL3741_PWM_REGISTER_COUNT 351
+#define IS31FL3741_SCALING_REGISTER_COUNT 351
#ifndef IS31FL3741_I2C_TIMEOUT
# define IS31FL3741_I2C_TIMEOUT 100
@@ -52,11 +52,8 @@
# define IS31FL3741_GLOBAL_CURRENT 0xFF
#endif
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20] = {0xFF};
-
// These buffers match the IS31FL3741 and IS31FL3741A PWM registers.
-// The scaling buffers match the PG2 and PG3 LED On/Off registers.
+// The scaling buffers match the page 2 and 3 LED On/Off registers.
// Storing them like this is optimal for I2C transfers to the registers.
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3741_write_pwm_buffer() but it's
@@ -65,64 +62,48 @@ uint8_t g_pwm_buffer[IS31FL3741_DRIVER_COUNT][IS31FL3741_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[IS31FL3741_DRIVER_COUNT] = {false};
bool g_scaling_registers_update_required[IS31FL3741_DRIVER_COUNT] = {false};
-uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_PWM_REGISTER_COUNT];
+uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_SCALING_REGISTER_COUNT];
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3741_I2C_TIMEOUT) == 0) break;
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3741_I2C_TIMEOUT);
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3741_I2C_TIMEOUT);
#endif
}
-bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // Assume PG0 is already selected
+void is31fl3741_select_page(uint8_t addr, uint8_t page) {
+ is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, page);
+}
+
+void is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assume page 0 is already selected
- for (int i = 0; i < 342; i += 18) {
+ for (uint16_t i = 0; i < 342; i += 18) {
if (i == 180) {
- // unlock the command register and select PG1
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_PWM_1);
+ is31fl3741_select_page(addr, IS31FL3741_COMMAND_PWM_1);
}
- g_twi_transfer_buffer[0] = i % 180;
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 18);
-
#if IS31FL3741_I2C_PERSISTENCE > 0
- for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
- return false;
- }
+ for (uint8_t j = 0; j < IS31FL3741_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
- return false;
- }
+ i2c_write_register(addr << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT);
#endif
}
// transfer the left cause the total number is 351
- g_twi_transfer_buffer[0] = 162;
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer + 342, 9);
-
#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
- return false;
- }
+ if (i2c_write_register(addr << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
- return false;
- }
+ i2c_write_register(addr << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT);
#endif
-
- return true;
}
void is31fl3741_init_drivers(void) {
@@ -162,11 +143,7 @@ void is31fl3741_init(uint8_t addr) {
// then disable software shutdown.
// Unlock the command register.
- // Unlock the command register.
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
-
- // Select PG4
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_FUNCTION);
+ is31fl3741_select_page(addr, IS31FL3741_COMMAND_FUNCTION);
// Set to Normal operation
is31fl3741_write_register(addr, IS31FL3741_FUNCTION_REG_CONFIGURATION, IS31FL3741_CONFIGURATION);
@@ -186,12 +163,14 @@ void is31fl3741_init(uint8_t addr) {
void is31fl3741_set_value(int index, uint8_t value) {
is31fl3741_led_t led;
+
if (index >= 0 && index < IS31FL3741_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3741_leds[index]), sizeof(led));
if (g_pwm_buffer[led.driver][led.v] == value) {
return;
}
+
g_pwm_buffer_update_required[led.driver] = true;
g_pwm_buffer[led.driver][led.v] = value;
}
@@ -218,38 +197,31 @@ void is31fl3741_set_led_control_register(uint8_t index, bool value) {
void is31fl3741_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
- // unlock the command register and select PG2
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_PWM_0);
+ is31fl3741_select_page(addr, IS31FL3741_COMMAND_PWM_0);
- is31fl3741_write_pwm_buffer(addr, g_pwm_buffer[index]);
- }
+ is31fl3741_write_pwm_buffer(addr, index);
- g_pwm_buffer_update_required[index] = false;
+ g_pwm_buffer_update_required[index] = false;
+ }
}
void is31fl3741_set_pwm_buffer(const is31fl3741_led_t *pled, uint8_t value) {
- g_pwm_buffer[pled->driver][pled->v] = value;
-
+ g_pwm_buffer[pled->driver][pled->v] = value;
g_pwm_buffer_update_required[pled->driver] = true;
}
void is31fl3741_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_scaling_registers_update_required[index]) {
- // unlock the command register and select PG2
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_SCALING_0);
+ is31fl3741_select_page(addr, IS31FL3741_COMMAND_SCALING_0);
- // CS1_SW1 to CS30_SW6 are on PG2
+ // CS1_SW1 to CS30_SW6 are on page 2
for (int i = CS1_SW1; i <= CS30_SW6; ++i) {
is31fl3741_write_register(addr, i, g_scaling_registers[index][i]);
}
- // unlock the command register and select PG3
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_SCALING_1);
+ is31fl3741_select_page(addr, IS31FL3741_COMMAND_SCALING_1);
- // CS1_SW7 to CS39_SW9 are on PG3
+ // CS1_SW7 to CS39_SW9 are on page 3
for (int i = CS1_SW7; i <= CS39_SW9; ++i) {
is31fl3741_write_register(addr, i - CS1_SW7, g_scaling_registers[index][i]);
}
@@ -259,8 +231,7 @@ void is31fl3741_update_led_control_registers(uint8_t addr, uint8_t index) {
}
void is31fl3741_set_scaling_registers(const is31fl3741_led_t *pled, uint8_t value) {
- g_scaling_registers[pled->driver][pled->v] = value;
-
+ g_scaling_registers[pled->driver][pled->v] = value;
g_scaling_registers_update_required[pled->driver] = true;
}
diff --git a/drivers/led/issi/is31fl3741-simple.h b/drivers/led/issi/is31fl3741-mono.h
index 34608a37e0..d2ba1b7d17 100644
--- a/drivers/led/issi/is31fl3741-simple.h
+++ b/drivers/led/issi/is31fl3741-mono.h
@@ -104,7 +104,7 @@ extern const is31fl3741_led_t PROGMEM g_is31fl3741_leds[IS31FL3741_LED_COUNT];
void is31fl3741_init_drivers(void);
void is31fl3741_init(uint8_t addr);
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+void is31fl3741_select_page(uint8_t addr, uint8_t page);
void is31fl3741_set_value(int index, uint8_t value);
void is31fl3741_set_value_all(uint8_t value);
@@ -119,7 +119,7 @@ void is31fl3741_update_pwm_buffers(uint8_t addr, uint8_t index);
void is31fl3741_update_led_control_registers(uint8_t addr, uint8_t index);
void is31fl3741_set_scaling_registers(const is31fl3741_led_t *pled, uint8_t value);
-void is31fl3741_set_pwm_buffer(const is31fl3741_led *pled, uint8_t value);
+void is31fl3741_set_pwm_buffer(const is31fl3741_led_t *pled, uint8_t value);
void is31fl3741_flush(void);
diff --git a/drivers/led/issi/is31fl3741.c b/drivers/led/issi/is31fl3741.c
index efcfa77b46..5f641aa53f 100644
--- a/drivers/led/issi/is31fl3741.c
+++ b/drivers/led/issi/is31fl3741.c
@@ -18,11 +18,11 @@
*/
#include "is31fl3741.h"
-#include <string.h>
#include "i2c_master.h"
#include "wait.h"
#define IS31FL3741_PWM_REGISTER_COUNT 351
+#define IS31FL3741_SCALING_REGISTER_COUNT 351
#ifndef IS31FL3741_I2C_TIMEOUT
# define IS31FL3741_I2C_TIMEOUT 100
@@ -52,11 +52,8 @@
# define IS31FL3741_GLOBAL_CURRENT 0xFF
#endif
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20] = {0xFF};
-
// These buffers match the IS31FL3741 and IS31FL3741A PWM registers.
-// The scaling buffers match the PG2 and PG3 LED On/Off registers.
+// The scaling buffers match the page 2 and 3 LED On/Off registers.
// Storing them like this is optimal for I2C transfers to the registers.
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3741_write_pwm_buffer() but it's
@@ -65,64 +62,48 @@ uint8_t g_pwm_buffer[IS31FL3741_DRIVER_COUNT][IS31FL3741_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[IS31FL3741_DRIVER_COUNT] = {false};
bool g_scaling_registers_update_required[IS31FL3741_DRIVER_COUNT] = {false};
-uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_PWM_REGISTER_COUNT];
+uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_SCALING_REGISTER_COUNT];
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3741_I2C_TIMEOUT) == 0) break;
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3741_I2C_TIMEOUT);
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3741_I2C_TIMEOUT);
#endif
}
-bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // Assume PG0 is already selected
+void is31fl3741_select_page(uint8_t addr, uint8_t page) {
+ is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, page);
+}
+
+void is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assume page 0 is already selected
- for (int i = 0; i < 342; i += 18) {
+ for (uint16_t i = 0; i < 342; i += 18) {
if (i == 180) {
- // unlock the command register and select PG1
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_PWM_1);
+ is31fl3741_select_page(addr, IS31FL3741_COMMAND_PWM_1);
}
- g_twi_transfer_buffer[0] = i % 180;
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 18);
-
#if IS31FL3741_I2C_PERSISTENCE > 0
- for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
- return false;
- }
+ for (uint8_t j = 0; j < IS31FL3741_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
- return false;
- }
+ i2c_write_register(addr << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT);
#endif
}
// transfer the left cause the total number is 351
- g_twi_transfer_buffer[0] = 162;
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer + 342, 9);
-
#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
- return false;
- }
+ if (i2c_write_register(addr << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
- return false;
- }
+ i2c_write_register(addr << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT);
#endif
-
- return true;
}
void is31fl3741_init_drivers(void) {
@@ -162,11 +143,7 @@ void is31fl3741_init(uint8_t addr) {
// then disable software shutdown.
// Unlock the command register.
- // Unlock the command register.
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
-
- // Select PG4
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_FUNCTION);
+ is31fl3741_select_page(addr, IS31FL3741_COMMAND_FUNCTION);
// Set to Normal operation
is31fl3741_write_register(addr, IS31FL3741_FUNCTION_REG_CONFIGURATION, IS31FL3741_CONFIGURATION);
@@ -186,12 +163,14 @@ void is31fl3741_init(uint8_t addr) {
void is31fl3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
is31fl3741_led_t led;
+
if (index >= 0 && index < IS31FL3741_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3741_leds[index]), sizeof(led));
if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) {
return;
}
+
g_pwm_buffer_update_required[led.driver] = true;
g_pwm_buffer[led.driver][led.r] = red;
g_pwm_buffer[led.driver][led.g] = green;
@@ -232,40 +211,33 @@ void is31fl3741_set_led_control_register(uint8_t index, bool red, bool green, bo
void is31fl3741_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
- // unlock the command register and select PG2
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_PWM_0);
+ is31fl3741_select_page(addr, IS31FL3741_COMMAND_PWM_0);
- is31fl3741_write_pwm_buffer(addr, g_pwm_buffer[index]);
- }
+ is31fl3741_write_pwm_buffer(addr, index);
- g_pwm_buffer_update_required[index] = false;
+ g_pwm_buffer_update_required[index] = false;
+ }
}
void is31fl3741_set_pwm_buffer(const is31fl3741_led_t *pled, uint8_t red, uint8_t green, uint8_t blue) {
- g_pwm_buffer[pled->driver][pled->r] = red;
- g_pwm_buffer[pled->driver][pled->g] = green;
- g_pwm_buffer[pled->driver][pled->b] = blue;
-
+ g_pwm_buffer[pled->driver][pled->r] = red;
+ g_pwm_buffer[pled->driver][pled->g] = green;
+ g_pwm_buffer[pled->driver][pled->b] = blue;
g_pwm_buffer_update_required[pled->driver] = true;
}
void is31fl3741_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_scaling_registers_update_required[index]) {
- // unlock the command register and select PG2
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_SCALING_0);
+ is31fl3741_select_page(addr, IS31FL3741_COMMAND_SCALING_0);
- // CS1_SW1 to CS30_SW6 are on PG2
+ // CS1_SW1 to CS30_SW6 are on page 2
for (int i = CS1_SW1; i <= CS30_SW6; ++i) {
is31fl3741_write_register(addr, i, g_scaling_registers[index][i]);
}
- // unlock the command register and select PG3
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
- is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_SCALING_1);
+ is31fl3741_select_page(addr, IS31FL3741_COMMAND_SCALING_1);
- // CS1_SW7 to CS39_SW9 are on PG3
+ // CS1_SW7 to CS39_SW9 are on page 3
for (int i = CS1_SW7; i <= CS39_SW9; ++i) {
is31fl3741_write_register(addr, i - CS1_SW7, g_scaling_registers[index][i]);
}
@@ -275,10 +247,9 @@ void is31fl3741_update_led_control_registers(uint8_t addr, uint8_t index) {
}
void is31fl3741_set_scaling_registers(const is31fl3741_led_t *pled, uint8_t red, uint8_t green, uint8_t blue) {
- g_scaling_registers[pled->driver][pled->r] = red;
- g_scaling_registers[pled->driver][pled->g] = green;
- g_scaling_registers[pled->driver][pled->b] = blue;
-
+ g_scaling_registers[pled->driver][pled->r] = red;
+ g_scaling_registers[pled->driver][pled->g] = green;
+ g_scaling_registers[pled->driver][pled->b] = blue;
g_scaling_registers_update_required[pled->driver] = true;
}
diff --git a/drivers/led/issi/is31fl3741.h b/drivers/led/issi/is31fl3741.h
index 6466696b60..e7777a88d5 100644
--- a/drivers/led/issi/is31fl3741.h
+++ b/drivers/led/issi/is31fl3741.h
@@ -121,7 +121,7 @@ extern const is31fl3741_led_t PROGMEM g_is31fl3741_leds[IS31FL3741_LED_COUNT];
void is31fl3741_init_drivers(void);
void is31fl3741_init(uint8_t addr);
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+void is31fl3741_select_page(uint8_t addr, uint8_t page);
void is31fl3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void is31fl3741_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
diff --git a/drivers/led/issi/is31fl3742a-mono.c b/drivers/led/issi/is31fl3742a-mono.c
new file mode 100644
index 0000000000..3a607f02d1
--- /dev/null
+++ b/drivers/led/issi/is31fl3742a-mono.c
@@ -0,0 +1,215 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ * Copyright 2021 MasterSpoon
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "is31fl3742a-mono.h"
+#include "i2c_master.h"
+#include "wait.h"
+
+#define IS31FL3742A_PWM_REGISTER_COUNT 180
+#define IS31FL3742A_SCALING_REGISTER_COUNT 180
+
+#ifndef IS31FL3742A_I2C_TIMEOUT
+# define IS31FL3742A_I2C_TIMEOUT 100
+#endif
+
+#ifndef IS31FL3742A_I2C_PERSISTENCE
+# define IS31FL3742A_I2C_PERSISTENCE 0
+#endif
+
+#ifndef IS31FL3742A_CONFIGURATION
+# define IS31FL3742A_CONFIGURATION 0x31
+#endif
+
+#ifndef IS31FL3742A_PWM_FREQUENCY
+# define IS31FL3742A_PWM_FREQUENCY IS31FL3742A_PWM_FREQUENCY_29K_HZ
+#endif
+
+#ifndef IS31FL3742A_SW_PULLDOWN
+# define IS31FL3742A_SW_PULLDOWN IS31FL3742A_PDR_8K_OHM
+#endif
+
+#ifndef IS31FL3742A_CS_PULLUP
+# define IS31FL3742A_CS_PULLUP IS31FL3742A_PUR_8K_OHM
+#endif
+
+#ifndef IS31FL3742A_GLOBAL_CURRENT
+# define IS31FL3742A_GLOBAL_CURRENT 0xFF
+#endif
+
+uint8_t g_pwm_buffer[IS31FL3742A_DRIVER_COUNT][IS31FL3742A_PWM_REGISTER_COUNT];
+bool g_pwm_buffer_update_required[IS31FL3742A_DRIVER_COUNT] = {false};
+bool g_scaling_registers_update_required[IS31FL3742A_DRIVER_COUNT] = {false};
+
+uint8_t g_scaling_registers[IS31FL3742A_DRIVER_COUNT][IS31FL3742A_SCALING_REGISTER_COUNT];
+
+void is31fl3742a_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
+#if IS31FL3742A_I2C_PERSISTENCE > 0
+ for (uint8_t i = 0; i < IS31FL3742A_I2C_PERSISTENCE; i++) {
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3742A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3742A_I2C_TIMEOUT);
+#endif
+}
+
+void is31fl3742a_select_page(uint8_t addr, uint8_t page) {
+ is31fl3742a_write_register(addr, IS31FL3742A_REG_COMMAND_WRITE_LOCK, IS31FL3742A_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3742a_write_register(addr, IS31FL3742A_REG_COMMAND, page);
+}
+
+void is31fl3742a_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 0 is already selected.
+ // Transmit PWM registers in 6 transfers of 30 bytes.
+
+ // Iterate over the pwm_buffer contents at 30 byte intervals.
+ for (uint8_t i = 0; i < IS31FL3742A_PWM_REGISTER_COUNT; i += 30) {
+#if IS31FL3742A_I2C_PERSISTENCE > 0
+ for (uint8_t j = 0; j < IS31FL3742A_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 30, IS31FL3742A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 30, IS31FL3742A_I2C_TIMEOUT);
+#endif
+ }
+}
+
+void is31fl3742a_init_drivers(void) {
+ i2c_init();
+
+ is31fl3742a_init(IS31FL3742A_I2C_ADDRESS_1);
+#if defined(IS31FL3742A_I2C_ADDRESS_2)
+ is31fl3742a_init(IS31FL3742A_I2C_ADDRESS_2);
+# if defined(IS31FL3742A_I2C_ADDRESS_3)
+ is31fl3742a_init(IS31FL3742A_I2C_ADDRESS_3);
+# if defined(IS31FL3742A_I2C_ADDRESS_4)
+ is31fl3742a_init(IS31FL3742A_I2C_ADDRESS_4);
+# endif
+# endif
+#endif
+
+ for (int i = 0; i < IS31FL3742A_LED_COUNT; i++) {
+ is31fl3742a_set_scaling_register(i, 0xFF);
+ }
+
+ is31fl3742a_update_scaling_registers(IS31FL3742A_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3742A_I2C_ADDRESS_2)
+ is31fl3742a_update_scaling_registers(IS31FL3742A_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3742A_I2C_ADDRESS_3)
+ is31fl3742a_update_scaling_registers(IS31FL3742A_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3742A_I2C_ADDRESS_4)
+ is31fl3742a_update_scaling_registers(IS31FL3742A_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
+
+void is31fl3742a_init(uint8_t addr) {
+ // In order to avoid the LEDs being driven with garbage data
+ // in the LED driver's PWM registers, shutdown is enabled last.
+ // Set up the mode and other settings, clear the PWM registers,
+ // then disable software shutdown.
+
+ is31fl3742a_select_page(addr, IS31FL3742A_COMMAND_SCALING);
+
+ // Turn off all LEDs.
+ for (uint8_t i = 0; i < IS31FL3742A_SCALING_REGISTER_COUNT; i++) {
+ is31fl3742a_write_register(addr, i, 0x00);
+ }
+
+ is31fl3742a_select_page(addr, IS31FL3742A_COMMAND_PWM);
+
+ for (uint8_t i = 0; i < IS31FL3742A_PWM_REGISTER_COUNT; i++) {
+ is31fl3742a_write_register(addr, i, 0x00);
+ }
+
+ is31fl3742a_select_page(addr, IS31FL3742A_COMMAND_FUNCTION);
+
+ is31fl3742a_write_register(addr, IS31FL3742A_FUNCTION_REG_PULLDOWNUP, (IS31FL3742A_SW_PULLDOWN << 4) | IS31FL3742A_CS_PULLUP);
+ is31fl3742a_write_register(addr, IS31FL3742A_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3742A_GLOBAL_CURRENT);
+ is31fl3742a_write_register(addr, IS31FL3742A_FUNCTION_REG_PWM_FREQUENCY, (IS31FL3742A_PWM_FREQUENCY & 0b0111));
+ is31fl3742a_write_register(addr, IS31FL3742A_FUNCTION_REG_CONFIGURATION, IS31FL3742A_CONFIGURATION);
+
+ // Wait 10ms to ensure the device has woken up.
+ wait_ms(10);
+}
+
+void is31fl3742a_set_value(int index, uint8_t value) {
+ is31fl3742a_led_t led;
+
+ if (index >= 0 && index < IS31FL3742A_LED_COUNT) {
+ memcpy_P(&led, (&g_is31fl3742a_leds[index]), sizeof(led));
+
+ if (g_pwm_buffer[led.driver][led.v] == value) {
+ return;
+ }
+
+ g_pwm_buffer[led.driver][led.v] = value;
+ g_pwm_buffer_update_required[led.driver] = true;
+ }
+}
+
+void is31fl3742a_set_value_all(uint8_t value) {
+ for (int i = 0; i < IS31FL3742A_LED_COUNT; i++) {
+ is31fl3742a_set_value(i, value);
+ }
+}
+
+void is31fl3742a_set_scaling_register(uint8_t index, uint8_t value) {
+ is31fl3742a_led_t led;
+ memcpy_P(&led, (&g_is31fl3742a_leds[index]), sizeof(led));
+
+ g_scaling_registers[led.driver][led.v] = value;
+ g_scaling_registers_update_required[led.driver] = true;
+}
+
+void is31fl3742a_update_pwm_buffers(uint8_t addr, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
+ is31fl3742a_select_page(addr, IS31FL3742A_COMMAND_PWM);
+
+ is31fl3742a_write_pwm_buffer(addr, index);
+
+ g_pwm_buffer_update_required[index] = false;
+ }
+}
+
+void is31fl3742a_update_scaling_registers(uint8_t addr, uint8_t index) {
+ if (g_scaling_registers_update_required[index]) {
+ is31fl3742a_select_page(addr, IS31FL3742A_COMMAND_SCALING);
+
+ for (uint8_t i = 0; i < IS31FL3742A_SCALING_REGISTER_COUNT; i++) {
+ is31fl3742a_write_register(addr, i, g_scaling_registers[index][i]);
+ }
+
+ g_scaling_registers_update_required[index] = false;
+ }
+}
+
+void is31fl3742a_flush(void) {
+ is31fl3742a_update_pwm_buffers(IS31FL3742A_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3742A_I2C_ADDRESS_2)
+ is31fl3742a_update_pwm_buffers(IS31FL3742A_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3742A_I2C_ADDRESS_3)
+ is31fl3742a_update_pwm_buffers(IS31FL3742A_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3742A_I2C_ADDRESS_4)
+ is31fl3742a_update_pwm_buffers(IS31FL3742A_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
diff --git a/drivers/led/issi/is31fl3742.h b/drivers/led/issi/is31fl3742a-mono.h
index c96f12d0f1..8de284fa7d 100644
--- a/drivers/led/issi/is31fl3742.h
+++ b/drivers/led/issi/is31fl3742a-mono.h
@@ -20,98 +20,95 @@
#pragma once
-// 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)
-// The address will vary depending on your wiring:
-// 00 <-> GND
-// 01 <-> SCL
-// 10 <-> SDA
-// 11 <-> VCC
-// ADDR represents A1:A0 of the 7-bit address.
-// The result is: 0b01100(ADDR)
-#ifndef DRIVER_ADDR_1
-# define DRIVER_ADDR_1 0b0110000
-#endif
+#include <stdint.h>
+#include <stdbool.h>
+#include "progmem.h"
+#include "util.h"
-// Command Registers
-#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE
-#define ISSI_COMMANDREGISTER 0xFD
-#define ISSI_IDREGISTER 0xFC
-#define ISSI_REGISTER_UNLOCK 0xC5
+#define IS31FL3742A_REG_INTERRUPT_MASK 0xF0
+#define IS31FL3742A_REG_INTERRUPT_STATUS 0xF1
+#define IS31FL3742A_REG_ID 0xFC
-// Response Registers
-#define ISSI_PAGE_PWM 0x00
-#define ISSI_PAGE_SCALING 0x02
-#define ISSI_PAGE_FUNCTION 0x04
+#define IS31FL3742A_REG_COMMAND 0xFD
-// Registers under Function Register
-#define ISSI_REG_CONFIGURATION 0x00
-#define ISSI_REG_GLOBALCURRENT 0x01
-#define ISSI_REG_PULLDOWNUP 0x02
-#define ISSI_REG_SSR 0x41
-#define ISSI_REG_RESET 0x3F
-#define ISSI_REG_PWM_SET 0x36
+#define IS31FL3742A_COMMAND_PWM 0x00
+#define IS31FL3742A_COMMAND_SCALING 0x02
+#define IS31FL3742A_COMMAND_FUNCTION 0x04
-// Set defaults for Function Registers
-#ifndef ISSI_CONFIGURATION
-# define ISSI_CONFIGURATION 0x31
-#endif
-#ifndef ISSI_GLOBALCURRENT
-# define ISSI_GLOBALCURRENT 0xFF
-#endif
-#ifndef ISSI_PULLDOWNUP
-# define ISSI_PULLDOWNUP 0x55
-#endif
-#ifndef ISSI_PWM_SET
-# define ISSI_PWM_SET 0x00
-#endif
+#define IS31FL3742A_FUNCTION_REG_CONFIGURATION 0x00
+#define IS31FL3742A_FUNCTION_REG_GLOBAL_CURRENT 0x01
+#define IS31FL3742A_FUNCTION_REG_PULLDOWNUP 0x02
+#define IS31FL3742A_FUNCTION_REG_PWM_FREQUENCY 0x36
+#define IS31FL3742A_FUNCTION_REG_RESET 0x3F
+#define IS31FL3742A_FUNCTION_REG_SPREAD_SPECTRUM 0x41
-// Set defaults for Spread Spectrum Register
-#ifndef ISSI_SSR_1
-# define ISSI_SSR_1 0x00
-#endif
-#ifndef ISSI_SSR_2
-# define ISSI_SSR_2 0x00
-#endif
-#ifndef ISSI_SSR_3
-# define ISSI_SSR_3 0x00
-#endif
-#ifndef ISSI_SSR_4
-# define ISSI_SSR_4 0x00
-#endif
+#define IS31FL3742A_REG_COMMAND_WRITE_LOCK 0xFE
+#define IS31FL3742A_COMMAND_WRITE_LOCK_MAGIC 0xC5
-// Set defaults for Scaling registers
-#ifndef ISSI_SCAL_RED
-# define ISSI_SCAL_RED 0xFF
-#endif
-#ifndef ISSI_SCAL_BLUE
-# define ISSI_SCAL_BLUE 0xFF
-#endif
-#ifndef ISSI_SCAL_GREEN
-# define ISSI_SCAL_GREEN 0xFF
+#define IS31FL3742A_I2C_ADDRESS_GND 0x30
+#define IS31FL3742A_I2C_ADDRESS_SCL 0x31
+#define IS31FL3742A_I2C_ADDRESS_SDA 0x32
+#define IS31FL3742A_I2C_ADDRESS_VCC 0x33
+
+#if defined(LED_MATRIX_IS31FL3742A)
+# define IS31FL3742A_LED_COUNT LED_MATRIX_LED_COUNT
#endif
-#define ISSI_SCAL_RED_OFF 0x00
-#define ISSI_SCAL_GREEN_OFF 0x00
-#define ISSI_SCAL_BLUE_OFF 0x00
-#ifndef ISSI_SCAL_LED
-# define ISSI_SCAL_LED 0xFF
+#if defined(IS31FL3742A_I2C_ADDRESS_4)
+# define IS31FL3742A_DRIVER_COUNT 4
+#elif defined(IS31FL3742A_I2C_ADDRESS_3)
+# define IS31FL3742A_DRIVER_COUNT 3
+#elif defined(IS31FL3742A_I2C_ADDRESS_2)
+# define IS31FL3742A_DRIVER_COUNT 2
+#elif defined(IS31FL3742A_I2C_ADDRESS_1)
+# define IS31FL3742A_DRIVER_COUNT 1
#endif
-#define ISSI_SCAL_LED_OFF 0x00
-// Set buffer sizes
-#define ISSI_MAX_LEDS 180
-#define ISSI_SCALING_SIZE 180
-#define ISSI_PWM_TRF_SIZE 18
-#define ISSI_SCALING_TRF_SIZE 18
+typedef struct is31fl3742a_led_t {
+ uint8_t driver : 2;
+ uint8_t v;
+} PACKED is31fl3742a_led_t;
+
+extern const is31fl3742a_led_t PROGMEM g_is31fl3742a_leds[IS31FL3742A_LED_COUNT];
+
+void is31fl3742a_init_drivers(void);
+void is31fl3742a_init(uint8_t addr);
+void is31fl3742a_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void is31fl3742a_select_page(uint8_t addr, uint8_t page);
+
+void is31fl3742a_set_value(int index, uint8_t value);
+void is31fl3742a_set_value_all(uint8_t value);
+
+void is31fl3742a_set_scaling_register(uint8_t index, uint8_t value);
+
+void is31fl3742a_update_pwm_buffers(uint8_t addr, uint8_t index);
+void is31fl3742a_update_scaling_registers(uint8_t addr, uint8_t index);
+
+void is31fl3742a_flush(void);
+
+#define IS31FL3742A_PDR_0_OHM 0b000 // No pull-down resistor
+#define IS31FL3742A_PDR_0K5_OHM 0b001 // 0.5 kOhm resistor
+#define IS31FL3742A_PDR_1K_OHM 0b010 // 1 kOhm resistor
+#define IS31FL3742A_PDR_2K_OHM 0b011 // 2 kOhm resistor
+#define IS31FL3742A_PDR_4K_OHM 0b100 // 4 kOhm resistor
+#define IS31FL3742A_PDR_8K_OHM 0b101 // 8 kOhm resistor
+#define IS31FL3742A_PDR_16K_OHM 0b110 // 16 kOhm resistor
+#define IS31FL3742A_PDR_32K_OHM 0b111 // 32 kOhm resistor
+
+#define IS31FL3742A_PUR_0_OHM 0b000 // No pull-up resistor
+#define IS31FL3742A_PUR_0K5_OHM 0b001 // 0.5 kOhm resistor
+#define IS31FL3742A_PUR_1K_OHM 0b010 // 1 kOhm resistor
+#define IS31FL3742A_PUR_2K_OHM 0b011 // 2 kOhm resistor
+#define IS31FL3742A_PUR_4K_OHM 0b100 // 4 kOhm resistor
+#define IS31FL3742A_PUR_8K_OHM 0b101 // 8 kOhm resistor
+#define IS31FL3742A_PUR_16K_OHM 0b110 // 16 kOhm resistor
+#define IS31FL3742A_PUR_32K_OHM 0b111 // 32 kOhm resistor
-// Location of 1st bit for PWM and Scaling registers
-#define ISSI_PWM_REG_1ST 0x00
-#define ISSI_SCL_REG_1ST 0x00
+#define IS31FL3742A_PWM_FREQUENCY_29K_HZ 0b0000
+#define IS31FL3742A_PWM_FREQUENCY_3K6_HZ 0b0011
+#define IS31FL3742A_PWM_FREQUENCY_1K8_HZ 0b0111
+#define IS31FL3742A_PWM_FREQUENCY_900_HZ 0b1011
-// Map CS SW locations to order in PWM / Scaling buffers
-// This matches the ORDER in the Datasheet Register not the POSITION
-// It will always count from 0x00 to (ISSI_MAX_LEDS - 1)
#define CS1_SW1 0x00
#define CS2_SW1 0x01
#define CS3_SW1 0x02
diff --git a/drivers/led/issi/is31fl3742a.c b/drivers/led/issi/is31fl3742a.c
new file mode 100644
index 0000000000..2e6cf151c3
--- /dev/null
+++ b/drivers/led/issi/is31fl3742a.c
@@ -0,0 +1,219 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ * Copyright 2021 MasterSpoon
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "is31fl3742a.h"
+#include "i2c_master.h"
+#include "wait.h"
+
+#define IS31FL3742A_PWM_REGISTER_COUNT 180
+#define IS31FL3742A_SCALING_REGISTER_COUNT 180
+
+#ifndef IS31FL3742A_I2C_TIMEOUT
+# define IS31FL3742A_I2C_TIMEOUT 100
+#endif
+
+#ifndef IS31FL3742A_I2C_PERSISTENCE
+# define IS31FL3742A_I2C_PERSISTENCE 0
+#endif
+
+#ifndef IS31FL3742A_CONFIGURATION
+# define IS31FL3742A_CONFIGURATION 0x31
+#endif
+
+#ifndef IS31FL3742A_PWM_FREQUENCY
+# define IS31FL3742A_PWM_FREQUENCY IS31FL3742A_PWM_FREQUENCY_29K_HZ
+#endif
+
+#ifndef IS31FL3742A_SW_PULLDOWN
+# define IS31FL3742A_SW_PULLDOWN IS31FL3742A_PDR_8K_OHM
+#endif
+
+#ifndef IS31FL3742A_CS_PULLUP
+# define IS31FL3742A_CS_PULLUP IS31FL3742A_PUR_8K_OHM
+#endif
+
+#ifndef IS31FL3742A_GLOBAL_CURRENT
+# define IS31FL3742A_GLOBAL_CURRENT 0xFF
+#endif
+
+uint8_t g_pwm_buffer[IS31FL3742A_DRIVER_COUNT][IS31FL3742A_PWM_REGISTER_COUNT];
+bool g_pwm_buffer_update_required[IS31FL3742A_DRIVER_COUNT] = {false};
+bool g_scaling_registers_update_required[IS31FL3742A_DRIVER_COUNT] = {false};
+
+uint8_t g_scaling_registers[IS31FL3742A_DRIVER_COUNT][IS31FL3742A_SCALING_REGISTER_COUNT];
+
+void is31fl3742a_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
+#if IS31FL3742A_I2C_PERSISTENCE > 0
+ for (uint8_t i = 0; i < IS31FL3742A_I2C_PERSISTENCE; i++) {
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3742A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3742A_I2C_TIMEOUT);
+#endif
+}
+
+void is31fl3742a_select_page(uint8_t addr, uint8_t page) {
+ is31fl3742a_write_register(addr, IS31FL3742A_REG_COMMAND_WRITE_LOCK, IS31FL3742A_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3742a_write_register(addr, IS31FL3742A_REG_COMMAND, page);
+}
+
+void is31fl3742a_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 0 is already selected.
+ // Transmit PWM registers in 6 transfers of 30 bytes.
+
+ // Iterate over the pwm_buffer contents at 30 byte intervals.
+ for (uint8_t i = 0; i < IS31FL3742A_PWM_REGISTER_COUNT; i += 30) {
+#if IS31FL3742A_I2C_PERSISTENCE > 0
+ for (uint8_t j = 0; j < IS31FL3742A_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 30, IS31FL3742A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 30, IS31FL3742A_I2C_TIMEOUT);
+#endif
+ }
+}
+
+void is31fl3742a_init_drivers(void) {
+ i2c_init();
+
+ is31fl3742a_init(IS31FL3742A_I2C_ADDRESS_1);
+#if defined(IS31FL3742A_I2C_ADDRESS_2)
+ is31fl3742a_init(IS31FL3742A_I2C_ADDRESS_2);
+# if defined(IS31FL3742A_I2C_ADDRESS_3)
+ is31fl3742a_init(IS31FL3742A_I2C_ADDRESS_3);
+# if defined(IS31FL3742A_I2C_ADDRESS_4)
+ is31fl3742a_init(IS31FL3742A_I2C_ADDRESS_4);
+# endif
+# endif
+#endif
+
+ for (int i = 0; i < IS31FL3742A_LED_COUNT; i++) {
+ is31fl3742a_set_scaling_register(i, 0xFF, 0xFF, 0xFF);
+ }
+
+ is31fl3742a_update_scaling_registers(IS31FL3742A_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3742A_I2C_ADDRESS_2)
+ is31fl3742a_update_scaling_registers(IS31FL3742A_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3742A_I2C_ADDRESS_3)
+ is31fl3742a_update_scaling_registers(IS31FL3742A_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3742A_I2C_ADDRESS_4)
+ is31fl3742a_update_scaling_registers(IS31FL3742A_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
+
+void is31fl3742a_init(uint8_t addr) {
+ // In order to avoid the LEDs being driven with garbage data
+ // in the LED driver's PWM registers, shutdown is enabled last.
+ // Set up the mode and other settings, clear the PWM registers,
+ // then disable software shutdown.
+
+ is31fl3742a_select_page(addr, IS31FL3742A_COMMAND_SCALING);
+
+ // Turn off all LEDs.
+ for (uint8_t i = 0; i < IS31FL3742A_SCALING_REGISTER_COUNT; i++) {
+ is31fl3742a_write_register(addr, i, 0x00);
+ }
+
+ is31fl3742a_select_page(addr, IS31FL3742A_COMMAND_PWM);
+
+ for (uint8_t i = 0; i < IS31FL3742A_PWM_REGISTER_COUNT; i++) {
+ is31fl3742a_write_register(addr, i, 0x00);
+ }
+
+ is31fl3742a_select_page(addr, IS31FL3742A_COMMAND_FUNCTION);
+
+ is31fl3742a_write_register(addr, IS31FL3742A_FUNCTION_REG_PULLDOWNUP, (IS31FL3742A_SW_PULLDOWN << 4) | IS31FL3742A_CS_PULLUP);
+ is31fl3742a_write_register(addr, IS31FL3742A_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3742A_GLOBAL_CURRENT);
+ is31fl3742a_write_register(addr, IS31FL3742A_FUNCTION_REG_PWM_FREQUENCY, (IS31FL3742A_PWM_FREQUENCY & 0b0111));
+ is31fl3742a_write_register(addr, IS31FL3742A_FUNCTION_REG_CONFIGURATION, IS31FL3742A_CONFIGURATION);
+
+ // Wait 10ms to ensure the device has woken up.
+ wait_ms(10);
+}
+
+void is31fl3742a_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+ is31fl3742a_led_t led;
+
+ if (index >= 0 && index < IS31FL3742A_LED_COUNT) {
+ memcpy_P(&led, (&g_is31fl3742a_leds[index]), sizeof(led));
+
+ if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) {
+ return;
+ }
+
+ g_pwm_buffer[led.driver][led.r] = red;
+ g_pwm_buffer[led.driver][led.g] = green;
+ g_pwm_buffer[led.driver][led.b] = blue;
+ g_pwm_buffer_update_required[led.driver] = true;
+ }
+}
+
+void is31fl3742a_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+ for (int i = 0; i < IS31FL3742A_LED_COUNT; i++) {
+ is31fl3742a_set_color(i, red, green, blue);
+ }
+}
+
+void is31fl3742a_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue) {
+ is31fl3742a_led_t led;
+ memcpy_P(&led, (&g_is31fl3742a_leds[index]), sizeof(led));
+
+ g_scaling_registers[led.driver][led.r] = red;
+ g_scaling_registers[led.driver][led.g] = green;
+ g_scaling_registers[led.driver][led.b] = blue;
+ g_scaling_registers_update_required[led.driver] = true;
+}
+
+void is31fl3742a_update_pwm_buffers(uint8_t addr, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
+ is31fl3742a_select_page(addr, IS31FL3742A_COMMAND_PWM);
+
+ is31fl3742a_write_pwm_buffer(addr, index);
+
+ g_pwm_buffer_update_required[index] = false;
+ }
+}
+
+void is31fl3742a_update_scaling_registers(uint8_t addr, uint8_t index) {
+ if (g_scaling_registers_update_required[index]) {
+ is31fl3742a_select_page(addr, IS31FL3742A_COMMAND_SCALING);
+
+ for (uint8_t i = 0; i < IS31FL3742A_SCALING_REGISTER_COUNT; i++) {
+ is31fl3742a_write_register(addr, i, g_scaling_registers[index][i]);
+ }
+
+ g_scaling_registers_update_required[index] = false;
+ }
+}
+
+void is31fl3742a_flush(void) {
+ is31fl3742a_update_pwm_buffers(IS31FL3742A_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3742A_I2C_ADDRESS_2)
+ is31fl3742a_update_pwm_buffers(IS31FL3742A_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3742A_I2C_ADDRESS_3)
+ is31fl3742a_update_pwm_buffers(IS31FL3742A_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3742A_I2C_ADDRESS_4)
+ is31fl3742a_update_pwm_buffers(IS31FL3742A_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
diff --git a/drivers/led/issi/is31fl3742a.h b/drivers/led/issi/is31fl3742a.h
new file mode 100644
index 0000000000..5f34a3cdb9
--- /dev/null
+++ b/drivers/led/issi/is31fl3742a.h
@@ -0,0 +1,298 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ * Copyright 2021 MasterSpoon
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <stdbool.h>
+#include "progmem.h"
+#include "util.h"
+
+#define IS31FL3742A_REG_INTERRUPT_MASK 0xF0
+#define IS31FL3742A_REG_INTERRUPT_STATUS 0xF1
+#define IS31FL3742A_REG_ID 0xFC
+
+#define IS31FL3742A_REG_COMMAND 0xFD
+
+#define IS31FL3742A_COMMAND_PWM 0x00
+#define IS31FL3742A_COMMAND_SCALING 0x02
+#define IS31FL3742A_COMMAND_FUNCTION 0x04
+
+#define IS31FL3742A_FUNCTION_REG_CONFIGURATION 0x00
+#define IS31FL3742A_FUNCTION_REG_GLOBAL_CURRENT 0x01
+#define IS31FL3742A_FUNCTION_REG_PULLDOWNUP 0x02
+#define IS31FL3742A_FUNCTION_REG_PWM_FREQUENCY 0x36
+#define IS31FL3742A_FUNCTION_REG_RESET 0x3F
+#define IS31FL3742A_FUNCTION_REG_SPREAD_SPECTRUM 0x41
+
+#define IS31FL3742A_REG_COMMAND_WRITE_LOCK 0xFE
+#define IS31FL3742A_COMMAND_WRITE_LOCK_MAGIC 0xC5
+
+#define IS31FL3742A_I2C_ADDRESS_GND 0x30
+#define IS31FL3742A_I2C_ADDRESS_SCL 0x31
+#define IS31FL3742A_I2C_ADDRESS_SDA 0x32
+#define IS31FL3742A_I2C_ADDRESS_VCC 0x33
+
+#if defined(RGB_MATRIX_IS31FL3742A)
+# define IS31FL3742A_LED_COUNT RGB_MATRIX_LED_COUNT
+#endif
+
+#if defined(IS31FL3742A_I2C_ADDRESS_4)
+# define IS31FL3742A_DRIVER_COUNT 4
+#elif defined(IS31FL3742A_I2C_ADDRESS_3)
+# define IS31FL3742A_DRIVER_COUNT 3
+#elif defined(IS31FL3742A_I2C_ADDRESS_2)
+# define IS31FL3742A_DRIVER_COUNT 2
+#elif defined(IS31FL3742A_I2C_ADDRESS_1)
+# define IS31FL3742A_DRIVER_COUNT 1
+#endif
+
+typedef struct is31fl3742a_led_t {
+ uint8_t driver : 2;
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+} PACKED is31fl3742a_led_t;
+
+extern const is31fl3742a_led_t PROGMEM g_is31fl3742a_leds[IS31FL3742A_LED_COUNT];
+
+void is31fl3742a_init_drivers(void);
+void is31fl3742a_init(uint8_t addr);
+void is31fl3742a_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void is31fl3742a_select_page(uint8_t addr, uint8_t page);
+
+void is31fl3742a_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void is31fl3742a_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
+
+void is31fl3742a_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue);
+
+void is31fl3742a_update_pwm_buffers(uint8_t addr, uint8_t index);
+void is31fl3742a_update_scaling_registers(uint8_t addr, uint8_t index);
+
+void is31fl3742a_flush(void);
+
+#define IS31FL3742A_PDR_0_OHM 0b000 // No pull-down resistor
+#define IS31FL3742A_PDR_0K5_OHM 0b001 // 0.5 kOhm resistor
+#define IS31FL3742A_PDR_1K_OHM 0b010 // 1 kOhm resistor
+#define IS31FL3742A_PDR_2K_OHM 0b011 // 2 kOhm resistor
+#define IS31FL3742A_PDR_4K_OHM 0b100 // 4 kOhm resistor
+#define IS31FL3742A_PDR_8K_OHM 0b101 // 8 kOhm resistor
+#define IS31FL3742A_PDR_16K_OHM 0b110 // 16 kOhm resistor
+#define IS31FL3742A_PDR_32K_OHM 0b111 // 32 kOhm resistor
+
+#define IS31FL3742A_PUR_0_OHM 0b000 // No pull-up resistor
+#define IS31FL3742A_PUR_0K5_OHM 0b001 // 0.5 kOhm resistor
+#define IS31FL3742A_PUR_1K_OHM 0b010 // 1 kOhm resistor
+#define IS31FL3742A_PUR_2K_OHM 0b011 // 2 kOhm resistor
+#define IS31FL3742A_PUR_4K_OHM 0b100 // 4 kOhm resistor
+#define IS31FL3742A_PUR_8K_OHM 0b101 // 8 kOhm resistor
+#define IS31FL3742A_PUR_16K_OHM 0b110 // 16 kOhm resistor
+#define IS31FL3742A_PUR_32K_OHM 0b111 // 32 kOhm resistor
+
+#define IS31FL3742A_PWM_FREQUENCY_29K_HZ 0b0000
+#define IS31FL3742A_PWM_FREQUENCY_3K6_HZ 0b0011
+#define IS31FL3742A_PWM_FREQUENCY_1K8_HZ 0b0111
+#define IS31FL3742A_PWM_FREQUENCY_900_HZ 0b1011
+
+#define CS1_SW1 0x00
+#define CS2_SW1 0x01
+#define CS3_SW1 0x02
+#define CS4_SW1 0x03
+#define CS5_SW1 0x04
+#define CS6_SW1 0x05
+#define CS7_SW1 0x06
+#define CS8_SW1 0x07
+#define CS9_SW1 0x08
+#define CS10_SW1 0x09
+#define CS11_SW1 0x0A
+#define CS12_SW1 0x0B
+#define CS13_SW1 0x0C
+#define CS14_SW1 0x0D
+#define CS15_SW1 0x0E
+#define CS16_SW1 0x0F
+#define CS17_SW1 0x10
+#define CS18_SW1 0x11
+#define CS19_SW1 0x12
+#define CS20_SW1 0x13
+#define CS21_SW1 0x14
+#define CS22_SW1 0x15
+#define CS23_SW1 0x16
+#define CS24_SW1 0x17
+#define CS25_SW1 0x18
+#define CS26_SW1 0x19
+#define CS27_SW1 0x1A
+#define CS28_SW1 0x1B
+#define CS29_SW1 0x1C
+#define CS30_SW1 0x1D
+
+#define CS1_SW2 0x1E
+#define CS2_SW2 0x1F
+#define CS3_SW2 0x20
+#define CS4_SW2 0x21
+#define CS5_SW2 0x22
+#define CS6_SW2 0x23
+#define CS7_SW2 0x24
+#define CS8_SW2 0x25
+#define CS9_SW2 0x26
+#define CS10_SW2 0x27
+#define CS11_SW2 0x28
+#define CS12_SW2 0x29
+#define CS13_SW2 0x2A
+#define CS14_SW2 0x2B
+#define CS15_SW2 0x2C
+#define CS16_SW2 0x2D
+#define CS17_SW2 0x2E
+#define CS18_SW2 0x2F
+#define CS19_SW2 0x30
+#define CS20_SW2 0x31
+#define CS21_SW2 0x32
+#define CS22_SW2 0x33
+#define CS23_SW2 0x34
+#define CS24_SW2 0x35
+#define CS25_SW2 0x36
+#define CS26_SW2 0x37
+#define CS27_SW2 0x38
+#define CS28_SW2 0x39
+#define CS29_SW2 0x3A
+#define CS30_SW2 0x3B
+
+#define CS1_SW3 0x3C
+#define CS2_SW3 0x3D
+#define CS3_SW3 0x3E
+#define CS4_SW3 0x3F
+#define CS5_SW3 0x40
+#define CS6_SW3 0x41
+#define CS7_SW3 0x42
+#define CS8_SW3 0x43
+#define CS9_SW3 0x44
+#define CS10_SW3 0x45
+#define CS11_SW3 0x46
+#define CS12_SW3 0x47
+#define CS13_SW3 0x48
+#define CS14_SW3 0x49
+#define CS15_SW3 0x4A
+#define CS16_SW3 0x4B
+#define CS17_SW3 0x4C
+#define CS18_SW3 0x4D
+#define CS19_SW3 0x4E
+#define CS20_SW3 0x4F
+#define CS21_SW3 0x50
+#define CS22_SW3 0x51
+#define CS23_SW3 0x52
+#define CS24_SW3 0x53
+#define CS25_SW3 0x54
+#define CS26_SW3 0x55
+#define CS27_SW3 0x56
+#define CS28_SW3 0x57
+#define CS29_SW3 0x58
+#define CS30_SW3 0x59
+
+#define CS1_SW4 0x5A
+#define CS2_SW4 0x5B
+#define CS3_SW4 0x5C
+#define CS4_SW4 0x5D
+#define CS5_SW4 0x5E
+#define CS6_SW4 0x5F
+#define CS7_SW4 0x60
+#define CS8_SW4 0x61
+#define CS9_SW4 0x62
+#define CS10_SW4 0x63
+#define CS11_SW4 0x64
+#define CS12_SW4 0x65
+#define CS13_SW4 0x66
+#define CS14_SW4 0x67
+#define CS15_SW4 0x68
+#define CS16_SW4 0x69
+#define CS17_SW4 0x6A
+#define CS18_SW4 0x6B
+#define CS19_SW4 0x6C
+#define CS20_SW4 0x6D
+#define CS21_SW4 0x6E
+#define CS22_SW4 0x6F
+#define CS23_SW4 0x70
+#define CS24_SW4 0x71
+#define CS25_SW4 0x72
+#define CS26_SW4 0x73
+#define CS27_SW4 0x74
+#define CS28_SW4 0x75
+#define CS29_SW4 0x76
+#define CS30_SW4 0x77
+
+#define CS1_SW5 0x78
+#define CS2_SW5 0x79
+#define CS3_SW5 0x7A
+#define CS4_SW5 0x7B
+#define CS5_SW5 0x7C
+#define CS6_SW5 0x7D
+#define CS7_SW5 0x7E
+#define CS8_SW5 0x7F
+#define CS9_SW5 0x80
+#define CS10_SW5 0x81
+#define CS11_SW5 0x82
+#define CS12_SW5 0x83
+#define CS13_SW5 0x84
+#define CS14_SW5 0x85
+#define CS15_SW5 0x86
+#define CS16_SW5 0x87
+#define CS17_SW5 0x88
+#define CS18_SW5 0x89
+#define CS19_SW5 0x8A
+#define CS20_SW5 0x8B
+#define CS21_SW5 0x8C
+#define CS22_SW5 0x8D
+#define CS23_SW5 0x8E
+#define CS24_SW5 0x8F
+#define CS25_SW5 0x90
+#define CS26_SW5 0x91
+#define CS27_SW5 0x92
+#define CS28_SW5 0x93
+#define CS29_SW5 0x94
+#define CS30_SW5 0x95
+
+#define CS1_SW6 0x96
+#define CS2_SW6 0x97
+#define CS3_SW6 0x98
+#define CS4_SW6 0x99
+#define CS5_SW6 0x9A
+#define CS6_SW6 0x9B
+#define CS7_SW6 0x9C
+#define CS8_SW6 0x9D
+#define CS9_SW6 0x9E
+#define CS10_SW6 0x9F
+#define CS11_SW6 0xA0
+#define CS12_SW6 0xA1
+#define CS13_SW6 0xA2
+#define CS14_SW6 0xA3
+#define CS15_SW6 0xA4
+#define CS16_SW6 0xA5
+#define CS17_SW6 0xA6
+#define CS18_SW6 0xA7
+#define CS19_SW6 0xA8
+#define CS20_SW6 0xA9
+#define CS21_SW6 0xAA
+#define CS22_SW6 0xAB
+#define CS23_SW6 0xAC
+#define CS24_SW6 0xAD
+#define CS25_SW6 0xAE
+#define CS26_SW6 0xAF
+#define CS27_SW6 0xB0
+#define CS28_SW6 0xB1
+#define CS29_SW6 0xB2
+#define CS30_SW6 0xB3
diff --git a/drivers/led/issi/is31fl3743a-mono.c b/drivers/led/issi/is31fl3743a-mono.c
new file mode 100644
index 0000000000..4df0956ed2
--- /dev/null
+++ b/drivers/led/issi/is31fl3743a-mono.c
@@ -0,0 +1,224 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ * Copyright 2021 MasterSpoon
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "is31fl3743a-mono.h"
+#include "i2c_master.h"
+#include "wait.h"
+
+#define IS31FL3743A_PWM_REGISTER_COUNT 198
+#define IS31FL3743A_SCALING_REGISTER_COUNT 198
+
+#ifndef IS31FL3743A_I2C_TIMEOUT
+# define IS31FL3743A_I2C_TIMEOUT 100
+#endif
+
+#ifndef IS31FL3743A_I2C_PERSISTENCE
+# define IS31FL3743A_I2C_PERSISTENCE 0
+#endif
+
+#ifndef IS31FL3743A_CONFIGURATION
+# define IS31FL3743A_CONFIGURATION 0x01
+#endif
+
+#ifndef IS31FL3743A_SW_PULLDOWN
+# define IS31FL3743A_SW_PULLDOWN IS31FL3743A_PDR_2K_OHM_SW_OFF
+#endif
+
+#ifndef IS31FL3743A_CS_PULLUP
+# define IS31FL3743A_CS_PULLUP IS31FL3743A_PUR_2K_OHM_CS_OFF
+#endif
+
+#ifndef IS31FL3743A_GLOBAL_CURRENT
+# define IS31FL3743A_GLOBAL_CURRENT 0xFF
+#endif
+
+#ifndef IS31FL3743A_SYNC_1
+# define IS31FL3743A_SYNC_1 IS31FL3743A_SYNC_NONE
+#endif
+#ifndef IS31FL3743A_SYNC_2
+# define IS31FL3743A_SYNC_2 IS31FL3743A_SYNC_NONE
+#endif
+#ifndef IS31FL3743A_SYNC_3
+# define IS31FL3743A_SYNC_3 IS31FL3743A_SYNC_NONE
+#endif
+#ifndef IS31FL3743A_SYNC_4
+# define IS31FL3743A_SYNC_4 IS31FL3743A_SYNC_NONE
+#endif
+
+uint8_t g_pwm_buffer[IS31FL3743A_DRIVER_COUNT][IS31FL3743A_PWM_REGISTER_COUNT];
+bool g_pwm_buffer_update_required[IS31FL3743A_DRIVER_COUNT] = {false};
+bool g_scaling_registers_update_required[IS31FL3743A_DRIVER_COUNT] = {false};
+
+uint8_t g_scaling_registers[IS31FL3743A_DRIVER_COUNT][IS31FL3743A_SCALING_REGISTER_COUNT];
+
+void is31fl3743a_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
+#if IS31FL3743A_I2C_PERSISTENCE > 0
+ for (uint8_t i = 0; i < IS31FL3743A_I2C_PERSISTENCE; i++) {
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3743A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3743A_I2C_TIMEOUT);
+#endif
+}
+
+void is31fl3743a_select_page(uint8_t addr, uint8_t page) {
+ is31fl3743a_write_register(addr, IS31FL3743A_REG_COMMAND_WRITE_LOCK, IS31FL3743A_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3743a_write_register(addr, IS31FL3743A_REG_COMMAND, page);
+}
+
+void is31fl3743a_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 0 is already selected.
+ // Transmit PWM registers in 11 transfers of 18 bytes.
+
+ // Iterate over the pwm_buffer contents at 18 byte intervals.
+ for (uint8_t i = 0; i < IS31FL3743A_PWM_REGISTER_COUNT; i += 18) {
+#if IS31FL3743A_I2C_PERSISTENCE > 0
+ for (uint8_t j = 0; j < IS31FL3743A_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3743A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3743A_I2C_TIMEOUT);
+#endif
+ }
+}
+
+void is31fl3743a_init_drivers(void) {
+ i2c_init();
+
+ is31fl3743a_init(IS31FL3743A_I2C_ADDRESS_1, IS31FL3743A_SYNC_1);
+#if defined(IS31FL3743A_I2C_ADDRESS_2)
+ is31fl3743a_init(IS31FL3743A_I2C_ADDRESS_2, IS31FL3743A_SYNC_2);
+# if defined(IS31FL3743A_I2C_ADDRESS_3)
+ is31fl3743a_init(IS31FL3743A_I2C_ADDRESS_3, IS31FL3743A_SYNC_3);
+# if defined(IS31FL3743A_I2C_ADDRESS_4)
+ is31fl3743a_init(IS31FL3743A_I2C_ADDRESS_4, IS31FL3743A_SYNC_4);
+# endif
+# endif
+#endif
+
+ for (int i = 0; i < IS31FL3743A_LED_COUNT; i++) {
+ is31fl3743a_set_scaling_register(i, 0xFF);
+ }
+
+ is31fl3743a_update_scaling_registers(IS31FL3743A_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3743A_I2C_ADDRESS_2)
+ is31fl3743a_update_scaling_registers(IS31FL3743A_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3743A_I2C_ADDRESS_3)
+ is31fl3743a_update_scaling_registers(IS31FL3743A_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3743A_I2C_ADDRESS_4)
+ is31fl3743a_update_scaling_registers(IS31FL3743A_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
+
+void is31fl3743a_init(uint8_t addr, uint8_t sync) {
+ // In order to avoid the LEDs being driven with garbage data
+ // in the LED driver's PWM registers, shutdown is enabled last.
+ // Set up the mode and other settings, clear the PWM registers,
+ // then disable software shutdown.
+
+ is31fl3743a_select_page(addr, IS31FL3743A_COMMAND_SCALING);
+
+ // Turn off all LEDs.
+ for (uint8_t i = 0; i < IS31FL3743A_SCALING_REGISTER_COUNT; i++) {
+ is31fl3743a_write_register(addr, i + 1, 0x00);
+ }
+
+ is31fl3743a_select_page(addr, IS31FL3743A_COMMAND_PWM);
+
+ for (uint8_t i = 0; i < IS31FL3743A_PWM_REGISTER_COUNT; i++) {
+ is31fl3743a_write_register(addr, i + 1, 0x00);
+ }
+
+ is31fl3743a_select_page(addr, IS31FL3743A_COMMAND_FUNCTION);
+
+ is31fl3743a_write_register(addr, IS31FL3743A_FUNCTION_REG_PULLDOWNUP, (IS31FL3743A_SW_PULLDOWN << 4) | IS31FL3743A_CS_PULLUP);
+ is31fl3743a_write_register(addr, IS31FL3743A_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3743A_GLOBAL_CURRENT);
+ is31fl3743a_write_register(addr, IS31FL3743A_FUNCTION_REG_SPREAD_SPECTRUM, (sync & 0b11) << 6);
+ is31fl3743a_write_register(addr, IS31FL3743A_FUNCTION_REG_CONFIGURATION, IS31FL3743A_CONFIGURATION);
+
+ // Wait 10ms to ensure the device has woken up.
+ wait_ms(10);
+}
+
+void is31fl3743a_set_value(int index, uint8_t value) {
+ is31fl3743a_led_t led;
+
+ if (index >= 0 && index < IS31FL3743A_LED_COUNT) {
+ memcpy_P(&led, (&g_is31fl3743a_leds[index]), sizeof(led));
+
+ if (g_pwm_buffer[led.driver][led.v] == value) {
+ return;
+ }
+
+ g_pwm_buffer_update_required[led.driver] = true;
+ g_pwm_buffer[led.driver][led.v] = value;
+ }
+}
+
+void is31fl3743a_set_value_all(uint8_t value) {
+ for (int i = 0; i < IS31FL3743A_LED_COUNT; i++) {
+ is31fl3743a_set_value(i, value);
+ }
+}
+
+void is31fl3743a_set_scaling_register(uint8_t index, uint8_t value) {
+ is31fl3743a_led_t led;
+ memcpy_P(&led, (&g_is31fl3743a_leds[index]), sizeof(led));
+
+ g_scaling_registers[led.driver][led.v] = value;
+ g_scaling_registers_update_required[led.driver] = true;
+}
+
+void is31fl3743a_update_pwm_buffers(uint8_t addr, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
+ is31fl3743a_select_page(addr, IS31FL3743A_COMMAND_PWM);
+
+ is31fl3743a_write_pwm_buffer(addr, index);
+
+ g_pwm_buffer_update_required[index] = false;
+ }
+}
+
+void is31fl3743a_update_scaling_registers(uint8_t addr, uint8_t index) {
+ if (g_scaling_registers_update_required[index]) {
+ is31fl3743a_select_page(addr, IS31FL3743A_COMMAND_SCALING);
+
+ for (uint8_t i = 0; i < IS31FL3743A_SCALING_REGISTER_COUNT; i++) {
+ is31fl3743a_write_register(addr, i + 1, g_scaling_registers[index][i]);
+ }
+
+ g_scaling_registers_update_required[index] = false;
+ }
+}
+
+void is31fl3743a_flush(void) {
+ is31fl3743a_update_pwm_buffers(IS31FL3743A_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3743A_I2C_ADDRESS_2)
+ is31fl3743a_update_pwm_buffers(IS31FL3743A_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3743A_I2C_ADDRESS_3)
+ is31fl3743a_update_pwm_buffers(IS31FL3743A_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3743A_I2C_ADDRESS_4)
+ is31fl3743a_update_pwm_buffers(IS31FL3743A_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
diff --git a/drivers/led/issi/is31fl3743.h b/drivers/led/issi/is31fl3743a-mono.h
index 706b271254..8ec3ce0755 100644
--- a/drivers/led/issi/is31fl3743.h
+++ b/drivers/led/issi/is31fl3743a-mono.h
@@ -20,103 +20,104 @@
#pragma once
-// 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)
-// The address will vary depending on your wiring:
-// 00 <-> GND
-// 01 <-> SCL
-// 10 <-> SDA
-// 11 <-> VCC
-// ADDR1 represents A1:A0 of the 7-bit address.
-// ADDR2 represents A3:A2 of the 7-bit address.
-// The result is: 0b010(ADDR2)(ADDR1)
-#ifndef DRIVER_ADDR_1
-# define DRIVER_ADDR_1 0b0100000
-#endif
+#include <stdint.h>
+#include <stdbool.h>
+#include "progmem.h"
+#include "util.h"
-// Set defaults for Spread Spectrum Register
-#ifndef ISSI_SSR_1
-# ifndef DRIVER_ADDR_2
-# define ISSI_SSR_1 0x00
-# else
-# define ISSI_SSR_1 0xC0
-# endif
-#endif
-#ifndef ISSI_SSR_2
-# define ISSI_SSR_2 0x80
-#endif
-#ifndef ISSI_SSR_3
-# define ISSI_SSR_3 0x80
-#endif
-#ifndef ISSI_SSR_4
-# define ISSI_SSR_4 0x80
-#endif
+#define IS31FL3743A_REG_ID 0xFC
-// Command Registers
-#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE
-#define ISSI_COMMANDREGISTER 0xFD
-#define ISSI_IDREGISTER 0xFC
-#define ISSI_REGISTER_UNLOCK 0xC5
+#define IS31FL3743A_REG_COMMAND 0xFD
-// Response Registers
-#define ISSI_PAGE_PWM 0x00
-#define ISSI_PAGE_SCALING 0x01
-#define ISSI_PAGE_FUNCTION 0x02
+#define IS31FL3743A_COMMAND_PWM 0x00
+#define IS31FL3743A_COMMAND_SCALING 0x01
+#define IS31FL3743A_COMMAND_FUNCTION 0x02
-// Registers under Function Register
-#define ISSI_REG_CONFIGURATION 0x00
-#define ISSI_REG_GLOBALCURRENT 0x01
-#define ISSI_REG_PULLDOWNUP 0x02
-#define ISSI_REG_TEMP 0x24
-#define ISSI_REG_SSR 0x25
-#define ISSI_REG_RESET 0x2F
+#define IS31FL3743A_FUNCTION_REG_CONFIGURATION 0x00
+#define IS31FL3743A_FUNCTION_REG_GLOBAL_CURRENT 0x01
+#define IS31FL3743A_FUNCTION_REG_PULLDOWNUP 0x02
+#define IS31FL3743A_FUNCTION_REG_TEMPERATURE 0x24
+#define IS31FL3743A_FUNCTION_REG_SPREAD_SPECTRUM 0x25
+#define IS31FL3743A_FUNCTION_REG_RESET 0x2F
-// Set defaults for Function Registers
-#ifndef ISSI_CONFIGURATION
-# define ISSI_CONFIGURATION 0x01
-#endif
-#ifndef ISSI_GLOBALCURRENT
-# define ISSI_GLOBALCURRENT 0xFF
-#endif
-#ifndef ISSI_PULLDOWNUP
-# define ISSI_PULLDOWNUP 0x33
-#endif
-#ifndef ISSI_TEMP
-# define ISSI_TEMP 0x00
-#endif
+#define IS31FL3743A_REG_COMMAND_WRITE_LOCK 0xFE
+#define IS31FL3743A_COMMAND_WRITE_LOCK_MAGIC 0xC5
-// Set defaults for Scaling registers
-#ifndef ISSI_SCAL_RED
-# define ISSI_SCAL_RED 0xFF
-#endif
-#ifndef ISSI_SCAL_BLUE
-# define ISSI_SCAL_BLUE 0xFF
-#endif
-#ifndef ISSI_SCAL_GREEN
-# define ISSI_SCAL_GREEN 0xFF
+#define IS31FL3743A_I2C_ADDRESS_GND_GND 0x20
+#define IS31FL3743A_I2C_ADDRESS_GND_SCL 0x21
+#define IS31FL3743A_I2C_ADDRESS_GND_SDA 0x22
+#define IS31FL3743A_I2C_ADDRESS_GND_VCC 0x23
+#define IS31FL3743A_I2C_ADDRESS_SCL_GND 0x24
+#define IS31FL3743A_I2C_ADDRESS_SCL_SCL 0x25
+#define IS31FL3743A_I2C_ADDRESS_SCL_SDA 0x26
+#define IS31FL3743A_I2C_ADDRESS_SCL_VCC 0x27
+#define IS31FL3743A_I2C_ADDRESS_SDA_GND 0x28
+#define IS31FL3743A_I2C_ADDRESS_SDA_SCL 0x29
+#define IS31FL3743A_I2C_ADDRESS_SDA_SDA 0x2A
+#define IS31FL3743A_I2C_ADDRESS_SDA_VCC 0x2B
+#define IS31FL3743A_I2C_ADDRESS_VCC_GND 0x2C
+#define IS31FL3743A_I2C_ADDRESS_VCC_SCL 0x2D
+#define IS31FL3743A_I2C_ADDRESS_VCC_SDA 0x2E
+#define IS31FL3743A_I2C_ADDRESS_VCC_VCC 0x2F
+
+#if defined(LED_MATRIX_IS31FL3743A)
+# define IS31FL3743A_LED_COUNT LED_MATRIX_LED_COUNT
#endif
-#define ISSI_SCAL_RED_OFF 0x00
-#define ISSI_SCAL_GREEN_OFF 0x00
-#define ISSI_SCAL_BLUE_OFF 0x00
-#ifndef ISSI_SCAL_LED
-# define ISSI_SCAL_LED 0xFF
+#if defined(IS31FL3743A_I2C_ADDRESS_4)
+# define IS31FL3743A_DRIVER_COUNT 4
+#elif defined(IS31FL3743A_I2C_ADDRESS_3)
+# define IS31FL3743A_DRIVER_COUNT 3
+#elif defined(IS31FL3743A_I2C_ADDRESS_2)
+# define IS31FL3743A_DRIVER_COUNT 2
+#elif defined(IS31FL3743A_I2C_ADDRESS_1)
+# define IS31FL3743A_DRIVER_COUNT 1
#endif
-#define ISSI_SCAL_LED_OFF 0x00
-// Set buffer sizes
-#define ISSI_MAX_LEDS 198
-#define ISSI_SCALING_SIZE 198
-#define ISSI_PWM_TRF_SIZE 18
-#define ISSI_SCALING_TRF_SIZE 18
+typedef struct is31fl3743a_led_t {
+ uint8_t driver : 2;
+ uint8_t v;
+} PACKED is31fl3743a_led_t;
+
+extern const is31fl3743a_led_t PROGMEM g_is31fl3743a_leds[IS31FL3743A_LED_COUNT];
+
+void is31fl3743a_init_drivers(void);
+void is31fl3743a_init(uint8_t addr, uint8_t sync);
+void is31fl3743a_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void is31fl3743a_select_page(uint8_t addr, uint8_t page);
+
+void is31fl3743a_set_value(int index, uint8_t value);
+void is31fl3743a_set_value_all(uint8_t value);
+
+void is31fl3743a_set_scaling_register(uint8_t index, uint8_t value);
+
+void is31fl3743a_update_pwm_buffers(uint8_t addr, uint8_t index);
+void is31fl3743a_update_scaling_registers(uint8_t addr, uint8_t index);
+
+void is31fl3743a_flush(void);
+
+#define IS31FL3743A_PDR_0_OHM 0b000 // No pull-down resistor
+#define IS31FL3743A_PDR_0K5_OHM_SW_OFF 0b001 // 0.5 kOhm resistor in SWx off time
+#define IS31FL3743A_PDR_1K_OHM_SW_OFF 0b010 // 1 kOhm resistor in SWx off time
+#define IS31FL3743A_PDR_2K_OHM_SW_OFF 0b011 // 2 kOhm resistor in SWx off time
+#define IS31FL3743A_PDR_1K_OHM 0b100 // 1 kOhm resistor
+#define IS31FL3743A_PDR_2K_OHM 0b101 // 2 kOhm resistor
+#define IS31FL3743A_PDR_4K_OHM 0b110 // 4 kOhm resistor
+#define IS31FL3743A_PDR_8K_OHM 0b111 // 8 kOhm resistor
+
+#define IS31FL3743A_PUR_0_OHM 0b000 // No pull-up resistor
+#define IS31FL3743A_PUR_0K5_OHM_CS_OFF 0b001 // 0.5 kOhm resistor in CSy off time
+#define IS31FL3743A_PUR_1K_OHM_CS_OFF 0b010 // 1 kOhm resistor in CSy off time
+#define IS31FL3743A_PUR_2K_OHM_CS_OFF 0b011 // 2 kOhm resistor in CSy off time
+#define IS31FL3743A_PUR_1K_OHM 0b100 // 1 kOhm resistor
+#define IS31FL3743A_PUR_2K_OHM 0b101 // 2 kOhm resistor
+#define IS31FL3743A_PUR_4K_OHM 0b110 // 4 kOhm resistor
+#define IS31FL3743A_PUR_8K_OHM 0b111 // 8 kOhm resistor
-// Location of 1st bit for PWM and Scaling registers
-#define ISSI_PWM_REG_1ST 0x01
-#define ISSI_SCL_REG_1ST 0x01
+#define IS31FL3743A_SYNC_NONE 0b00
+#define IS31FL3743A_SYNC_SLAVE 0b10
+#define IS31FL3743A_SYNC_MASTER 0b11
-// Map CS SW locations to order in PWM / Scaling buffers
-// This matches the ORDER in the Datasheet Register not the POSITION
-// It will always count from 0x00 to (ISSI_MAX_LEDS - 1)
#define CS1_SW1 0x00
#define CS2_SW1 0x01
#define CS3_SW1 0x02
diff --git a/drivers/led/issi/is31fl3743a.c b/drivers/led/issi/is31fl3743a.c
new file mode 100644
index 0000000000..f9cdb130da
--- /dev/null
+++ b/drivers/led/issi/is31fl3743a.c
@@ -0,0 +1,228 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ * Copyright 2021 MasterSpoon
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "is31fl3743a.h"
+#include "i2c_master.h"
+#include "wait.h"
+
+#define IS31FL3743A_PWM_REGISTER_COUNT 198
+#define IS31FL3743A_SCALING_REGISTER_COUNT 198
+
+#ifndef IS31FL3743A_I2C_TIMEOUT
+# define IS31FL3743A_I2C_TIMEOUT 100
+#endif
+
+#ifndef IS31FL3743A_I2C_PERSISTENCE
+# define IS31FL3743A_I2C_PERSISTENCE 0
+#endif
+
+#ifndef IS31FL3743A_CONFIGURATION
+# define IS31FL3743A_CONFIGURATION 0x01
+#endif
+
+#ifndef IS31FL3743A_SW_PULLDOWN
+# define IS31FL3743A_SW_PULLDOWN IS31FL3743A_PDR_2K_OHM_SW_OFF
+#endif
+
+#ifndef IS31FL3743A_CS_PULLUP
+# define IS31FL3743A_CS_PULLUP IS31FL3743A_PUR_2K_OHM_CS_OFF
+#endif
+
+#ifndef IS31FL3743A_GLOBAL_CURRENT
+# define IS31FL3743A_GLOBAL_CURRENT 0xFF
+#endif
+
+#ifndef IS31FL3743A_SYNC_1
+# define IS31FL3743A_SYNC_1 IS31FL3743A_SYNC_NONE
+#endif
+#ifndef IS31FL3743A_SYNC_2
+# define IS31FL3743A_SYNC_2 IS31FL3743A_SYNC_NONE
+#endif
+#ifndef IS31FL3743A_SYNC_3
+# define IS31FL3743A_SYNC_3 IS31FL3743A_SYNC_NONE
+#endif
+#ifndef IS31FL3743A_SYNC_4
+# define IS31FL3743A_SYNC_4 IS31FL3743A_SYNC_NONE
+#endif
+
+uint8_t g_pwm_buffer[IS31FL3743A_DRIVER_COUNT][IS31FL3743A_PWM_REGISTER_COUNT];
+bool g_pwm_buffer_update_required[IS31FL3743A_DRIVER_COUNT] = {false};
+bool g_scaling_registers_update_required[IS31FL3743A_DRIVER_COUNT] = {false};
+
+uint8_t g_scaling_registers[IS31FL3743A_DRIVER_COUNT][IS31FL3743A_SCALING_REGISTER_COUNT];
+
+void is31fl3743a_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
+#if IS31FL3743A_I2C_PERSISTENCE > 0
+ for (uint8_t i = 0; i < IS31FL3743A_I2C_PERSISTENCE; i++) {
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3743A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3743A_I2C_TIMEOUT);
+#endif
+}
+
+void is31fl3743a_select_page(uint8_t addr, uint8_t page) {
+ is31fl3743a_write_register(addr, IS31FL3743A_REG_COMMAND_WRITE_LOCK, IS31FL3743A_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3743a_write_register(addr, IS31FL3743A_REG_COMMAND, page);
+}
+
+void is31fl3743a_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 0 is already selected.
+ // Transmit PWM registers in 11 transfers of 18 bytes.
+
+ // Iterate over the pwm_buffer contents at 18 byte intervals.
+ for (uint8_t i = 0; i < IS31FL3743A_PWM_REGISTER_COUNT; i += 18) {
+#if IS31FL3743A_I2C_PERSISTENCE > 0
+ for (uint8_t j = 0; j < IS31FL3743A_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3743A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3743A_I2C_TIMEOUT);
+#endif
+ }
+}
+
+void is31fl3743a_init_drivers(void) {
+ i2c_init();
+
+ is31fl3743a_init(IS31FL3743A_I2C_ADDRESS_1, IS31FL3743A_SYNC_1);
+#if defined(IS31FL3743A_I2C_ADDRESS_2)
+ is31fl3743a_init(IS31FL3743A_I2C_ADDRESS_2, IS31FL3743A_SYNC_2);
+# if defined(IS31FL3743A_I2C_ADDRESS_3)
+ is31fl3743a_init(IS31FL3743A_I2C_ADDRESS_3, IS31FL3743A_SYNC_3);
+# if defined(IS31FL3743A_I2C_ADDRESS_4)
+ is31fl3743a_init(IS31FL3743A_I2C_ADDRESS_4, IS31FL3743A_SYNC_4);
+# endif
+# endif
+#endif
+
+ for (int i = 0; i < IS31FL3743A_LED_COUNT; i++) {
+ is31fl3743a_set_scaling_register(i, 0xFF, 0xFF, 0xFF);
+ }
+
+ is31fl3743a_update_scaling_registers(IS31FL3743A_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3743A_I2C_ADDRESS_2)
+ is31fl3743a_update_scaling_registers(IS31FL3743A_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3743A_I2C_ADDRESS_3)
+ is31fl3743a_update_scaling_registers(IS31FL3743A_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3743A_I2C_ADDRESS_4)
+ is31fl3743a_update_scaling_registers(IS31FL3743A_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
+
+void is31fl3743a_init(uint8_t addr, uint8_t sync) {
+ // In order to avoid the LEDs being driven with garbage data
+ // in the LED driver's PWM registers, shutdown is enabled last.
+ // Set up the mode and other settings, clear the PWM registers,
+ // then disable software shutdown.
+
+ is31fl3743a_select_page(addr, IS31FL3743A_COMMAND_SCALING);
+
+ // Turn off all LEDs.
+ for (uint8_t i = 0; i < IS31FL3743A_SCALING_REGISTER_COUNT; i++) {
+ is31fl3743a_write_register(addr, i + 1, 0x00);
+ }
+
+ is31fl3743a_select_page(addr, IS31FL3743A_COMMAND_PWM);
+
+ for (uint8_t i = 0; i < IS31FL3743A_PWM_REGISTER_COUNT; i++) {
+ is31fl3743a_write_register(addr, i + 1, 0x00);
+ }
+
+ is31fl3743a_select_page(addr, IS31FL3743A_COMMAND_FUNCTION);
+
+ is31fl3743a_write_register(addr, IS31FL3743A_FUNCTION_REG_PULLDOWNUP, (IS31FL3743A_SW_PULLDOWN << 4) | IS31FL3743A_CS_PULLUP);
+ is31fl3743a_write_register(addr, IS31FL3743A_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3743A_GLOBAL_CURRENT);
+ is31fl3743a_write_register(addr, IS31FL3743A_FUNCTION_REG_SPREAD_SPECTRUM, (sync & 0b11) << 6);
+ is31fl3743a_write_register(addr, IS31FL3743A_FUNCTION_REG_CONFIGURATION, IS31FL3743A_CONFIGURATION);
+
+ // Wait 10ms to ensure the device has woken up.
+ wait_ms(10);
+}
+
+void is31fl3743a_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+ is31fl3743a_led_t led;
+
+ if (index >= 0 && index < IS31FL3743A_LED_COUNT) {
+ memcpy_P(&led, (&g_is31fl3743a_leds[index]), sizeof(led));
+
+ if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) {
+ return;
+ }
+
+ g_pwm_buffer_update_required[led.driver] = true;
+ g_pwm_buffer[led.driver][led.r] = red;
+ g_pwm_buffer[led.driver][led.g] = green;
+ g_pwm_buffer[led.driver][led.b] = blue;
+ }
+}
+
+void is31fl3743a_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+ for (int i = 0; i < IS31FL3743A_LED_COUNT; i++) {
+ is31fl3743a_set_color(i, red, green, blue);
+ }
+}
+
+void is31fl3743a_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue) {
+ is31fl3743a_led_t led;
+ memcpy_P(&led, (&g_is31fl3743a_leds[index]), sizeof(led));
+
+ g_scaling_registers[led.driver][led.r] = red;
+ g_scaling_registers[led.driver][led.g] = green;
+ g_scaling_registers[led.driver][led.b] = blue;
+ g_scaling_registers_update_required[led.driver] = true;
+}
+
+void is31fl3743a_update_pwm_buffers(uint8_t addr, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
+ is31fl3743a_select_page(addr, IS31FL3743A_COMMAND_PWM);
+
+ is31fl3743a_write_pwm_buffer(addr, index);
+
+ g_pwm_buffer_update_required[index] = false;
+ }
+}
+
+void is31fl3743a_update_scaling_registers(uint8_t addr, uint8_t index) {
+ if (g_scaling_registers_update_required[index]) {
+ is31fl3743a_select_page(addr, IS31FL3743A_COMMAND_SCALING);
+
+ for (uint8_t i = 0; i < IS31FL3743A_SCALING_REGISTER_COUNT; i++) {
+ is31fl3743a_write_register(addr, i + 1, g_scaling_registers[index][i]);
+ }
+
+ g_scaling_registers_update_required[index] = false;
+ }
+}
+
+void is31fl3743a_flush(void) {
+ is31fl3743a_update_pwm_buffers(IS31FL3743A_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3743A_I2C_ADDRESS_2)
+ is31fl3743a_update_pwm_buffers(IS31FL3743A_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3743A_I2C_ADDRESS_3)
+ is31fl3743a_update_pwm_buffers(IS31FL3743A_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3743A_I2C_ADDRESS_4)
+ is31fl3743a_update_pwm_buffers(IS31FL3743A_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
diff --git a/drivers/led/issi/is31fl3743a.h b/drivers/led/issi/is31fl3743a.h
new file mode 100644
index 0000000000..381b853716
--- /dev/null
+++ b/drivers/led/issi/is31fl3743a.h
@@ -0,0 +1,330 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ * Copyright 2021 MasterSpoon
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <stdbool.h>
+#include "progmem.h"
+#include "util.h"
+
+#define IS31FL3743A_REG_ID 0xFC
+
+#define IS31FL3743A_REG_COMMAND 0xFD
+
+#define IS31FL3743A_COMMAND_PWM 0x00
+#define IS31FL3743A_COMMAND_SCALING 0x01
+#define IS31FL3743A_COMMAND_FUNCTION 0x02
+
+#define IS31FL3743A_FUNCTION_REG_CONFIGURATION 0x00
+#define IS31FL3743A_FUNCTION_REG_GLOBAL_CURRENT 0x01
+#define IS31FL3743A_FUNCTION_REG_PULLDOWNUP 0x02
+#define IS31FL3743A_FUNCTION_REG_TEMPERATURE 0x24
+#define IS31FL3743A_FUNCTION_REG_SPREAD_SPECTRUM 0x25
+#define IS31FL3743A_FUNCTION_REG_RESET 0x2F
+
+#define IS31FL3743A_REG_COMMAND_WRITE_LOCK 0xFE
+#define IS31FL3743A_COMMAND_WRITE_LOCK_MAGIC 0xC5
+
+#define IS31FL3743A_I2C_ADDRESS_GND_GND 0x20
+#define IS31FL3743A_I2C_ADDRESS_GND_SCL 0x21
+#define IS31FL3743A_I2C_ADDRESS_GND_SDA 0x22
+#define IS31FL3743A_I2C_ADDRESS_GND_VCC 0x23
+#define IS31FL3743A_I2C_ADDRESS_SCL_GND 0x24
+#define IS31FL3743A_I2C_ADDRESS_SCL_SCL 0x25
+#define IS31FL3743A_I2C_ADDRESS_SCL_SDA 0x26
+#define IS31FL3743A_I2C_ADDRESS_SCL_VCC 0x27
+#define IS31FL3743A_I2C_ADDRESS_SDA_GND 0x28
+#define IS31FL3743A_I2C_ADDRESS_SDA_SCL 0x29
+#define IS31FL3743A_I2C_ADDRESS_SDA_SDA 0x2A
+#define IS31FL3743A_I2C_ADDRESS_SDA_VCC 0x2B
+#define IS31FL3743A_I2C_ADDRESS_VCC_GND 0x2C
+#define IS31FL3743A_I2C_ADDRESS_VCC_SCL 0x2D
+#define IS31FL3743A_I2C_ADDRESS_VCC_SDA 0x2E
+#define IS31FL3743A_I2C_ADDRESS_VCC_VCC 0x2F
+
+#if defined(RGB_MATRIX_IS31FL3743A)
+# define IS31FL3743A_LED_COUNT RGB_MATRIX_LED_COUNT
+#endif
+
+#if defined(IS31FL3743A_I2C_ADDRESS_4)
+# define IS31FL3743A_DRIVER_COUNT 4
+#elif defined(IS31FL3743A_I2C_ADDRESS_3)
+# define IS31FL3743A_DRIVER_COUNT 3
+#elif defined(IS31FL3743A_I2C_ADDRESS_2)
+# define IS31FL3743A_DRIVER_COUNT 2
+#elif defined(IS31FL3743A_I2C_ADDRESS_1)
+# define IS31FL3743A_DRIVER_COUNT 1
+#endif
+
+typedef struct is31fl3743a_led_t {
+ uint8_t driver : 2;
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+} PACKED is31fl3743a_led_t;
+
+extern const is31fl3743a_led_t PROGMEM g_is31fl3743a_leds[IS31FL3743A_LED_COUNT];
+
+void is31fl3743a_init_drivers(void);
+void is31fl3743a_init(uint8_t addr, uint8_t sync);
+void is31fl3743a_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void is31fl3743a_select_page(uint8_t addr, uint8_t page);
+
+void is31fl3743a_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void is31fl3743a_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
+
+void is31fl3743a_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue);
+
+void is31fl3743a_update_pwm_buffers(uint8_t addr, uint8_t index);
+void is31fl3743a_update_scaling_registers(uint8_t addr, uint8_t index);
+
+void is31fl3743a_flush(void);
+
+#define IS31FL3743A_PDR_0_OHM 0b000 // No pull-down resistor
+#define IS31FL3743A_PDR_0K5_OHM_SW_OFF 0b001 // 0.5 kOhm resistor in SWx off time
+#define IS31FL3743A_PDR_1K_OHM_SW_OFF 0b010 // 1 kOhm resistor in SWx off time
+#define IS31FL3743A_PDR_2K_OHM_SW_OFF 0b011 // 2 kOhm resistor in SWx off time
+#define IS31FL3743A_PDR_1K_OHM 0b100 // 1 kOhm resistor
+#define IS31FL3743A_PDR_2K_OHM 0b101 // 2 kOhm resistor
+#define IS31FL3743A_PDR_4K_OHM 0b110 // 4 kOhm resistor
+#define IS31FL3743A_PDR_8K_OHM 0b111 // 8 kOhm resistor
+
+#define IS31FL3743A_PUR_0_OHM 0b000 // No pull-up resistor
+#define IS31FL3743A_PUR_0K5_OHM_CS_OFF 0b001 // 0.5 kOhm resistor in CSy off time
+#define IS31FL3743A_PUR_1K_OHM_CS_OFF 0b010 // 1 kOhm resistor in CSy off time
+#define IS31FL3743A_PUR_2K_OHM_CS_OFF 0b011 // 2 kOhm resistor in CSy off time
+#define IS31FL3743A_PUR_1K_OHM 0b100 // 1 kOhm resistor
+#define IS31FL3743A_PUR_2K_OHM 0b101 // 2 kOhm resistor
+#define IS31FL3743A_PUR_4K_OHM 0b110 // 4 kOhm resistor
+#define IS31FL3743A_PUR_8K_OHM 0b111 // 8 kOhm resistor
+
+#define IS31FL3743A_SYNC_NONE 0b00
+#define IS31FL3743A_SYNC_SLAVE 0b10
+#define IS31FL3743A_SYNC_MASTER 0b11
+
+#define CS1_SW1 0x00
+#define CS2_SW1 0x01
+#define CS3_SW1 0x02
+#define CS4_SW1 0x03
+#define CS5_SW1 0x04
+#define CS6_SW1 0x05
+#define CS7_SW1 0x06
+#define CS8_SW1 0x07
+#define CS9_SW1 0x08
+#define CS10_SW1 0x09
+#define CS11_SW1 0x0A
+#define CS12_SW1 0x0B
+#define CS13_SW1 0x0C
+#define CS14_SW1 0x0D
+#define CS15_SW1 0x0E
+#define CS16_SW1 0x0F
+#define CS17_SW1 0x10
+#define CS18_SW1 0x11
+
+#define CS1_SW2 0x12
+#define CS2_SW2 0x13
+#define CS3_SW2 0x14
+#define CS4_SW2 0x15
+#define CS5_SW2 0x16
+#define CS6_SW2 0x17
+#define CS7_SW2 0x18
+#define CS8_SW2 0x19
+#define CS9_SW2 0x1A
+#define CS10_SW2 0x1B
+#define CS11_SW2 0x1C
+#define CS12_SW2 0x1D
+#define CS13_SW2 0x1E
+#define CS14_SW2 0x1F
+#define CS15_SW2 0x20
+#define CS16_SW2 0x21
+#define CS17_SW2 0x22
+#define CS18_SW2 0x23
+
+#define CS1_SW3 0x24
+#define CS2_SW3 0x25
+#define CS3_SW3 0x26
+#define CS4_SW3 0x27
+#define CS5_SW3 0x28
+#define CS6_SW3 0x29
+#define CS7_SW3 0x2A
+#define CS8_SW3 0x2B
+#define CS9_SW3 0x2C
+#define CS10_SW3 0x2D
+#define CS11_SW3 0x2E
+#define CS12_SW3 0x2F
+#define CS13_SW3 0x30
+#define CS14_SW3 0x31
+#define CS15_SW3 0x32
+#define CS16_SW3 0x33
+#define CS17_SW3 0x34
+#define CS18_SW3 0x35
+
+#define CS1_SW4 0x36
+#define CS2_SW4 0x37
+#define CS3_SW4 0x38
+#define CS4_SW4 0x39
+#define CS5_SW4 0x3A
+#define CS6_SW4 0x3B
+#define CS7_SW4 0x3C
+#define CS8_SW4 0x3D
+#define CS9_SW4 0x3E
+#define CS10_SW4 0x3F
+#define CS11_SW4 0x40
+#define CS12_SW4 0x41
+#define CS13_SW4 0x42
+#define CS14_SW4 0x43
+#define CS15_SW4 0x44
+#define CS16_SW4 0x45
+#define CS17_SW4 0x46
+#define CS18_SW4 0x47
+
+#define CS1_SW5 0x48
+#define CS2_SW5 0x49
+#define CS3_SW5 0x4A
+#define CS4_SW5 0x4B
+#define CS5_SW5 0x4C
+#define CS6_SW5 0x4D
+#define CS7_SW5 0x4E
+#define CS8_SW5 0x4F
+#define CS9_SW5 0x50
+#define CS10_SW5 0x51
+#define CS11_SW5 0x52
+#define CS12_SW5 0x53
+#define CS13_SW5 0x54
+#define CS14_SW5 0x55
+#define CS15_SW5 0x56
+#define CS16_SW5 0x57
+#define CS17_SW5 0x58
+#define CS18_SW5 0x59
+
+#define CS1_SW6 0x5A
+#define CS2_SW6 0x5B
+#define CS3_SW6 0x5C
+#define CS4_SW6 0x5D
+#define CS5_SW6 0x5E
+#define CS6_SW6 0x5F
+#define CS7_SW6 0x60
+#define CS8_SW6 0x61
+#define CS9_SW6 0x62
+#define CS10_SW6 0x63
+#define CS11_SW6 0x64
+#define CS12_SW6 0x65
+#define CS13_SW6 0x66
+#define CS14_SW6 0x67
+#define CS15_SW6 0x68
+#define CS16_SW6 0x69
+#define CS17_SW6 0x6A
+#define CS18_SW6 0x6B
+
+#define CS1_SW7 0x6C
+#define CS2_SW7 0x6D
+#define CS3_SW7 0x6E
+#define CS4_SW7 0x6F
+#define CS5_SW7 0x70
+#define CS6_SW7 0x71
+#define CS7_SW7 0x72
+#define CS8_SW7 0x73
+#define CS9_SW7 0x74
+#define CS10_SW7 0x75
+#define CS11_SW7 0x76
+#define CS12_SW7 0x77
+#define CS13_SW7 0x78
+#define CS14_SW7 0x79
+#define CS15_SW7 0x7A
+#define CS16_SW7 0x7B
+#define CS17_SW7 0x7C
+#define CS18_SW7 0x7D
+
+#define CS1_SW8 0x7E
+#define CS2_SW8 0x7F
+#define CS3_SW8 0x80
+#define CS4_SW8 0x81
+#define CS5_SW8 0x82
+#define CS6_SW8 0x83
+#define CS7_SW8 0x84
+#define CS8_SW8 0x85
+#define CS9_SW8 0x86
+#define CS10_SW8 0x87
+#define CS11_SW8 0x88
+#define CS12_SW8 0x89
+#define CS13_SW8 0x8A
+#define CS14_SW8 0x8B
+#define CS15_SW8 0x8C
+#define CS16_SW8 0x8D
+#define CS17_SW8 0x8E
+#define CS18_SW8 0x8F
+
+#define CS1_SW9 0x90
+#define CS2_SW9 0x91
+#define CS3_SW9 0x92
+#define CS4_SW9 0x93
+#define CS5_SW9 0x94
+#define CS6_SW9 0x95
+#define CS7_SW9 0x96
+#define CS8_SW9 0x97
+#define CS9_SW9 0x98
+#define CS10_SW9 0x99
+#define CS11_SW9 0x9A
+#define CS12_SW9 0x9B
+#define CS13_SW9 0x9C
+#define CS14_SW9 0x9D
+#define CS15_SW9 0x9E
+#define CS16_SW9 0x9F
+#define CS17_SW9 0xA0
+#define CS18_SW9 0xA1
+
+#define CS1_SW10 0xA2
+#define CS2_SW10 0xA3
+#define CS3_SW10 0xA4
+#define CS4_SW10 0xA5
+#define CS5_SW10 0xA6
+#define CS6_SW10 0xA7
+#define CS7_SW10 0xA8
+#define CS8_SW10 0xA9
+#define CS9_SW10 0xAA
+#define CS10_SW10 0xAB
+#define CS11_SW10 0xAC
+#define CS12_SW10 0xAD
+#define CS13_SW10 0xAE
+#define CS14_SW10 0xAF
+#define CS15_SW10 0xB0
+#define CS16_SW10 0xB1
+#define CS17_SW10 0xB2
+#define CS18_SW10 0xB3
+
+#define CS1_SW11 0xB4
+#define CS2_SW11 0xB5
+#define CS3_SW11 0xB6
+#define CS4_SW11 0xB7
+#define CS5_SW11 0xB8
+#define CS6_SW11 0xB9
+#define CS7_SW11 0xBA
+#define CS8_SW11 0xBB
+#define CS9_SW11 0xBC
+#define CS10_SW11 0xBD
+#define CS11_SW11 0xBE
+#define CS12_SW11 0xBF
+#define CS13_SW11 0xC0
+#define CS14_SW11 0xC1
+#define CS15_SW11 0xC2
+#define CS16_SW11 0xC3
+#define CS17_SW11 0xC4
+#define CS18_SW11 0xC5
diff --git a/drivers/led/issi/is31fl3745-mono.c b/drivers/led/issi/is31fl3745-mono.c
new file mode 100644
index 0000000000..2b68c96326
--- /dev/null
+++ b/drivers/led/issi/is31fl3745-mono.c
@@ -0,0 +1,224 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ * Copyright 2021 MasterSpoon
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "is31fl3745-mono.h"
+#include "i2c_master.h"
+#include "wait.h"
+
+#define IS31FL3745_PWM_REGISTER_COUNT 144
+#define IS31FL3745_SCALING_REGISTER_COUNT 144
+
+#ifndef IS31FL3745_I2C_TIMEOUT
+# define IS31FL3745_I2C_TIMEOUT 100
+#endif
+
+#ifndef IS31FL3745_I2C_PERSISTENCE
+# define IS31FL3745_I2C_PERSISTENCE 0
+#endif
+
+#ifndef IS31FL3745_CONFIGURATION
+# define IS31FL3745_CONFIGURATION 0x31
+#endif
+
+#ifndef IS31FL3745_SW_PULLDOWN
+# define IS31FL3745_SW_PULLDOWN IS31FL3745_PDR_2K_OHM_SW_OFF
+#endif
+
+#ifndef IS31FL3745_CS_PULLUP
+# define IS31FL3745_CS_PULLUP IS31FL3745_PUR_2K_OHM_CS_OFF
+#endif
+
+#ifndef IS31FL3745_GLOBAL_CURRENT
+# define IS31FL3745_GLOBAL_CURRENT 0xFF
+#endif
+
+#ifndef IS31FL3745_SYNC_1
+# define IS31FL3745_SYNC_1 IS31FL3745_SYNC_NONE
+#endif
+#ifndef IS31FL3745_SYNC_2
+# define IS31FL3745_SYNC_2 IS31FL3745_SYNC_NONE
+#endif
+#ifndef IS31FL3745_SYNC_3
+# define IS31FL3745_SYNC_3 IS31FL3745_SYNC_NONE
+#endif
+#ifndef IS31FL3745_SYNC_4
+# define IS31FL3745_SYNC_4 IS31FL3745_SYNC_NONE
+#endif
+
+uint8_t g_pwm_buffer[IS31FL3745_DRIVER_COUNT][IS31FL3745_PWM_REGISTER_COUNT];
+bool g_pwm_buffer_update_required[IS31FL3745_DRIVER_COUNT] = {false};
+bool g_scaling_registers_update_required[IS31FL3745_DRIVER_COUNT] = {false};
+
+uint8_t g_scaling_registers[IS31FL3745_DRIVER_COUNT][IS31FL3745_SCALING_REGISTER_COUNT];
+
+void is31fl3745_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
+#if IS31FL3745_I2C_PERSISTENCE > 0
+ for (uint8_t i = 0; i < IS31FL3745_I2C_PERSISTENCE; i++) {
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3745_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3745_I2C_TIMEOUT);
+#endif
+}
+
+void is31fl3745_select_page(uint8_t addr, uint8_t page) {
+ is31fl3745_write_register(addr, IS31FL3745_REG_COMMAND_WRITE_LOCK, IS31FL3745_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3745_write_register(addr, IS31FL3745_REG_COMMAND, page);
+}
+
+void is31fl3745_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 0 is already selected.
+ // Transmit PWM registers in 8 transfers of 18 bytes.
+
+ // Iterate over the pwm_buffer contents at 18 byte intervals.
+ for (uint8_t i = 0; i < IS31FL3745_PWM_REGISTER_COUNT; i += 18) {
+#if IS31FL3745_I2C_PERSISTENCE > 0
+ for (uint8_t j = 0; j < IS31FL3745_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3745_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3745_I2C_TIMEOUT);
+#endif
+ }
+}
+
+void is31fl3745_init_drivers(void) {
+ i2c_init();
+
+ is31fl3745_init(IS31FL3745_I2C_ADDRESS_1, IS31FL3745_SYNC_1);
+#if defined(IS31FL3745_I2C_ADDRESS_2)
+ is31fl3745_init(IS31FL3745_I2C_ADDRESS_2, IS31FL3745_SYNC_2);
+# if defined(IS31FL3745_I2C_ADDRESS_3)
+ is31fl3745_init(IS31FL3745_I2C_ADDRESS_3, IS31FL3745_SYNC_3);
+# if defined(IS31FL3745_I2C_ADDRESS_4)
+ is31fl3745_init(IS31FL3745_I2C_ADDRESS_4, IS31FL3745_SYNC_4);
+# endif
+# endif
+#endif
+
+ for (int i = 0; i < IS31FL3745_LED_COUNT; i++) {
+ is31fl3745_set_scaling_register(i, 0xFF);
+ }
+
+ is31fl3745_update_scaling_registers(IS31FL3745_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3745_I2C_ADDRESS_2)
+ is31fl3745_update_scaling_registers(IS31FL3745_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3745_I2C_ADDRESS_3)
+ is31fl3745_update_scaling_registers(IS31FL3745_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3745_I2C_ADDRESS_4)
+ is31fl3745_update_scaling_registers(IS31FL3745_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
+
+void is31fl3745_init(uint8_t addr, uint8_t sync) {
+ // In order to avoid the LEDs being driven with garbage data
+ // in the LED driver's PWM registers, shutdown is enabled last.
+ // Set up the mode and other settings, clear the PWM registers,
+ // then disable software shutdown.
+
+ is31fl3745_select_page(addr, IS31FL3745_COMMAND_SCALING);
+
+ // Turn off all LEDs.
+ for (uint8_t i = 0; i < IS31FL3745_SCALING_REGISTER_COUNT; i++) {
+ is31fl3745_write_register(addr, i + 1, 0x00);
+ }
+
+ is31fl3745_select_page(addr, IS31FL3745_COMMAND_PWM);
+
+ for (uint8_t i = 0; i < IS31FL3745_PWM_REGISTER_COUNT; i++) {
+ is31fl3745_write_register(addr, i + 1, 0x00);
+ }
+
+ is31fl3745_select_page(addr, IS31FL3745_COMMAND_FUNCTION);
+
+ is31fl3745_write_register(addr, IS31FL3745_FUNCTION_REG_PULLDOWNUP, (IS31FL3745_SW_PULLDOWN << 4) | IS31FL3745_CS_PULLUP);
+ is31fl3745_write_register(addr, IS31FL3745_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3745_GLOBAL_CURRENT);
+ is31fl3745_write_register(addr, IS31FL3745_FUNCTION_REG_SPREAD_SPECTRUM, (sync & 0b11) << 6);
+ is31fl3745_write_register(addr, IS31FL3745_FUNCTION_REG_CONFIGURATION, IS31FL3745_CONFIGURATION);
+
+ // Wait 10ms to ensure the device has woken up.
+ wait_ms(10);
+}
+
+void is31fl3745_set_value(int index, uint8_t value) {
+ is31fl3745_led_t led;
+
+ if (index >= 0 && index < IS31FL3745_LED_COUNT) {
+ memcpy_P(&led, (&g_is31fl3745_leds[index]), sizeof(led));
+
+ if (g_pwm_buffer[led.driver][led.v] == value) {
+ return;
+ }
+
+ g_pwm_buffer_update_required[led.driver] = true;
+ g_pwm_buffer[led.driver][led.v] = value;
+ }
+}
+
+void is31fl3745_set_value_all(uint8_t value) {
+ for (int i = 0; i < IS31FL3745_LED_COUNT; i++) {
+ is31fl3745_set_value(i, value);
+ }
+}
+
+void is31fl3745_set_scaling_register(uint8_t index, uint8_t value) {
+ is31fl3745_led_t led;
+ memcpy_P(&led, (&g_is31fl3745_leds[index]), sizeof(led));
+
+ g_scaling_registers[led.driver][led.v] = value;
+ g_scaling_registers_update_required[led.driver] = true;
+}
+
+void is31fl3745_update_pwm_buffers(uint8_t addr, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
+ is31fl3745_select_page(addr, IS31FL3745_COMMAND_PWM);
+
+ is31fl3745_write_pwm_buffer(addr, index);
+
+ g_pwm_buffer_update_required[index] = false;
+ }
+}
+
+void is31fl3745_update_scaling_registers(uint8_t addr, uint8_t index) {
+ if (g_scaling_registers_update_required[index]) {
+ is31fl3745_select_page(addr, IS31FL3745_COMMAND_SCALING);
+
+ for (uint8_t i = 0; i < IS31FL3745_SCALING_REGISTER_COUNT; i++) {
+ is31fl3745_write_register(addr, i + 1, g_scaling_registers[index][i]);
+ }
+
+ g_scaling_registers_update_required[index] = false;
+ }
+}
+
+void is31fl3745_flush(void) {
+ is31fl3745_update_pwm_buffers(IS31FL3745_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3745_I2C_ADDRESS_2)
+ is31fl3745_update_pwm_buffers(IS31FL3745_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3745_I2C_ADDRESS_3)
+ is31fl3745_update_pwm_buffers(IS31FL3745_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3745_I2C_ADDRESS_4)
+ is31fl3745_update_pwm_buffers(IS31FL3745_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
diff --git a/drivers/led/issi/is31fl3745-mono.h b/drivers/led/issi/is31fl3745-mono.h
new file mode 100644
index 0000000000..f60f0acfd9
--- /dev/null
+++ b/drivers/led/issi/is31fl3745-mono.h
@@ -0,0 +1,271 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ * Copyright 2021 MasterSpoon
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <stdbool.h>
+#include "progmem.h"
+#include "util.h"
+
+#define IS31FL3745_REG_ID 0xFC
+
+#define IS31FL3745_REG_COMMAND 0xFD
+
+#define IS31FL3745_COMMAND_PWM 0x00
+#define IS31FL3745_COMMAND_SCALING 0x01
+#define IS31FL3745_COMMAND_FUNCTION 0x02
+
+#define IS31FL3745_FUNCTION_REG_CONFIGURATION 0x00
+#define IS31FL3745_FUNCTION_REG_GLOBAL_CURRENT 0x01
+#define IS31FL3745_FUNCTION_REG_PULLDOWNUP 0x02
+#define IS31FL3745_FUNCTION_REG_TEMPERATURE 0x24
+#define IS31FL3745_FUNCTION_REG_SPREAD_SPECTRUM 0x25
+#define IS31FL3745_FUNCTION_REG_RESET 0x2F
+
+#define IS31FL3745_REG_COMMAND_WRITE_LOCK 0xFE
+#define IS31FL3745_COMMAND_WRITE_LOCK_MAGIC 0xC5
+
+#define IS31FL3745_I2C_ADDRESS_GND_GND 0x20
+#define IS31FL3745_I2C_ADDRESS_GND_SCL 0x21
+#define IS31FL3745_I2C_ADDRESS_GND_SDA 0x22
+#define IS31FL3745_I2C_ADDRESS_GND_VCC 0x23
+#define IS31FL3745_I2C_ADDRESS_SCL_GND 0x24
+#define IS31FL3745_I2C_ADDRESS_SCL_SCL 0x25
+#define IS31FL3745_I2C_ADDRESS_SCL_SDA 0x26
+#define IS31FL3745_I2C_ADDRESS_SCL_VCC 0x27
+#define IS31FL3745_I2C_ADDRESS_SDA_GND 0x28
+#define IS31FL3745_I2C_ADDRESS_SDA_SCL 0x29
+#define IS31FL3745_I2C_ADDRESS_SDA_SDA 0x2A
+#define IS31FL3745_I2C_ADDRESS_SDA_VCC 0x2B
+#define IS31FL3745_I2C_ADDRESS_VCC_GND 0x2C
+#define IS31FL3745_I2C_ADDRESS_VCC_SCL 0x2D
+#define IS31FL3745_I2C_ADDRESS_VCC_SDA 0x2E
+#define IS31FL3745_I2C_ADDRESS_VCC_VCC 0x2F
+
+#if defined(LED_MATRIX_IS31FL3745)
+# define IS31FL3745_LED_COUNT LED_MATRIX_LED_COUNT
+#endif
+
+#if defined(IS31FL3745_I2C_ADDRESS_4)
+# define IS31FL3745_DRIVER_COUNT 4
+#elif defined(IS31FL3745_I2C_ADDRESS_3)
+# define IS31FL3745_DRIVER_COUNT 3
+#elif defined(IS31FL3745_I2C_ADDRESS_2)
+# define IS31FL3745_DRIVER_COUNT 2
+#elif defined(IS31FL3745_I2C_ADDRESS_1)
+# define IS31FL3745_DRIVER_COUNT 1
+#endif
+
+typedef struct is31fl3745_led_t {
+ uint8_t driver : 2;
+ uint8_t v;
+} PACKED is31fl3745_led_t;
+
+extern const is31fl3745_led_t PROGMEM g_is31fl3745_leds[IS31FL3745_LED_COUNT];
+
+void is31fl3745_init_drivers(void);
+void is31fl3745_init(uint8_t addr, uint8_t sync);
+void is31fl3745_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void is31fl3745_select_page(uint8_t addr, uint8_t page);
+
+void is31fl3745_set_value(int index, uint8_t value);
+void is31fl3745_set_value_all(uint8_t value);
+
+void is31fl3745_set_scaling_register(uint8_t index, uint8_t value);
+
+void is31fl3745_update_pwm_buffers(uint8_t addr, uint8_t index);
+void is31fl3745_update_scaling_registers(uint8_t addr, uint8_t index);
+
+void is31fl3745_flush(void);
+
+#define IS31FL3745_PDR_0_OHM 0b000 // No pull-down resistor
+#define IS31FL3745_PDR_0K5_OHM_SW_OFF 0b001 // 0.5 kOhm resistor in SWx off time
+#define IS31FL3745_PDR_1K_OHM_SW_OFF 0b010 // 1 kOhm resistor in SWx off time
+#define IS31FL3745_PDR_2K_OHM_SW_OFF 0b011 // 2 kOhm resistor in SWx off time
+#define IS31FL3745_PDR_1K_OHM 0b100 // 1 kOhm resistor
+#define IS31FL3745_PDR_2K_OHM 0b101 // 2 kOhm resistor
+#define IS31FL3745_PDR_4K_OHM 0b110 // 4 kOhm resistor
+#define IS31FL3745_PDR_8K_OHM 0b111 // 8 kOhm resistor
+
+#define IS31FL3745_PUR_0_OHM 0b000 // No pull-up resistor
+#define IS31FL3745_PUR_0K5_OHM_CS_OFF 0b001 // 0.5 kOhm resistor in CSy off time
+#define IS31FL3745_PUR_1K_OHM_CS_OFF 0b010 // 1 kOhm resistor in CSy off time
+#define IS31FL3745_PUR_2K_OHM_CS_OFF 0b011 // 2 kOhm resistor in CSy off time
+#define IS31FL3745_PUR_1K_OHM 0b100 // 1 kOhm resistor
+#define IS31FL3745_PUR_2K_OHM 0b101 // 2 kOhm resistor
+#define IS31FL3745_PUR_4K_OHM 0b110 // 4 kOhm resistor
+#define IS31FL3745_PUR_8K_OHM 0b111 // 8 kOhm resistor
+
+#define IS31FL3745_SYNC_NONE 0b00
+#define IS31FL3745_SYNC_SLAVE 0b10
+#define IS31FL3745_SYNC_MASTER 0b11
+
+#define CS1_SW1 0x00
+#define CS2_SW1 0x01
+#define CS3_SW1 0x02
+#define CS4_SW1 0x03
+#define CS5_SW1 0x04
+#define CS6_SW1 0x05
+#define CS7_SW1 0x06
+#define CS8_SW1 0x07
+#define CS9_SW1 0x08
+#define CS10_SW1 0x09
+#define CS11_SW1 0x0A
+#define CS12_SW1 0x0B
+#define CS13_SW1 0x0C
+#define CS14_SW1 0x0D
+#define CS15_SW1 0x0E
+#define CS16_SW1 0x0F
+#define CS17_SW1 0x10
+#define CS18_SW1 0x11
+
+#define CS1_SW2 0x12
+#define CS2_SW2 0x13
+#define CS3_SW2 0x14
+#define CS4_SW2 0x15
+#define CS5_SW2 0x16
+#define CS6_SW2 0x17
+#define CS7_SW2 0x18
+#define CS8_SW2 0x19
+#define CS9_SW2 0x1A
+#define CS10_SW2 0x1B
+#define CS11_SW2 0x1C
+#define CS12_SW2 0x1D
+#define CS13_SW2 0x1E
+#define CS14_SW2 0x1F
+#define CS15_SW2 0x20
+#define CS16_SW2 0x21
+#define CS17_SW2 0x22
+#define CS18_SW2 0x23
+
+#define CS1_SW3 0x24
+#define CS2_SW3 0x25
+#define CS3_SW3 0x26
+#define CS4_SW3 0x27
+#define CS5_SW3 0x28
+#define CS6_SW3 0x29
+#define CS7_SW3 0x2A
+#define CS8_SW3 0x2B
+#define CS9_SW3 0x2C
+#define CS10_SW3 0x2D
+#define CS11_SW3 0x2E
+#define CS12_SW3 0x2F
+#define CS13_SW3 0x30
+#define CS14_SW3 0x31
+#define CS15_SW3 0x32
+#define CS16_SW3 0x33
+#define CS17_SW3 0x34
+#define CS18_SW3 0x35
+
+#define CS1_SW4 0x36
+#define CS2_SW4 0x37
+#define CS3_SW4 0x38
+#define CS4_SW4 0x39
+#define CS5_SW4 0x3A
+#define CS6_SW4 0x3B
+#define CS7_SW4 0x3C
+#define CS8_SW4 0x3D
+#define CS9_SW4 0x3E
+#define CS10_SW4 0x3F
+#define CS11_SW4 0x40
+#define CS12_SW4 0x41
+#define CS13_SW4 0x42
+#define CS14_SW4 0x43
+#define CS15_SW4 0x44
+#define CS16_SW4 0x45
+#define CS17_SW4 0x46
+#define CS18_SW4 0x47
+
+#define CS1_SW5 0x48
+#define CS2_SW5 0x49
+#define CS3_SW5 0x4A
+#define CS4_SW5 0x4B
+#define CS5_SW5 0x4C
+#define CS6_SW5 0x4D
+#define CS7_SW5 0x4E
+#define CS8_SW5 0x4F
+#define CS9_SW5 0x50
+#define CS10_SW5 0x51
+#define CS11_SW5 0x52
+#define CS12_SW5 0x53
+#define CS13_SW5 0x54
+#define CS14_SW5 0x55
+#define CS15_SW5 0x56
+#define CS16_SW5 0x57
+#define CS17_SW5 0x58
+#define CS18_SW5 0x59
+
+#define CS1_SW6 0x5A
+#define CS2_SW6 0x5B
+#define CS3_SW6 0x5C
+#define CS4_SW6 0x5D
+#define CS5_SW6 0x5E
+#define CS6_SW6 0x5F
+#define CS7_SW6 0x60
+#define CS8_SW6 0x61
+#define CS9_SW6 0x62
+#define CS10_SW6 0x63
+#define CS11_SW6 0x64
+#define CS12_SW6 0x65
+#define CS13_SW6 0x66
+#define CS14_SW6 0x67
+#define CS15_SW6 0x68
+#define CS16_SW6 0x69
+#define CS17_SW6 0x6A
+#define CS18_SW6 0x6B
+
+#define CS1_SW7 0x6C
+#define CS2_SW7 0x6D
+#define CS3_SW7 0x6E
+#define CS4_SW7 0x6F
+#define CS5_SW7 0x70
+#define CS6_SW7 0x71
+#define CS7_SW7 0x72
+#define CS8_SW7 0x73
+#define CS9_SW7 0x74
+#define CS10_SW7 0x75
+#define CS11_SW7 0x76
+#define CS12_SW7 0x77
+#define CS13_SW7 0x78
+#define CS14_SW7 0x79
+#define CS15_SW7 0x7A
+#define CS16_SW7 0x7B
+#define CS17_SW7 0x7C
+#define CS18_SW7 0x7D
+
+#define CS1_SW8 0x7E
+#define CS2_SW8 0x7F
+#define CS3_SW8 0x80
+#define CS4_SW8 0x81
+#define CS5_SW8 0x82
+#define CS6_SW8 0x83
+#define CS7_SW8 0x84
+#define CS8_SW8 0x85
+#define CS9_SW8 0x86
+#define CS10_SW8 0x87
+#define CS11_SW8 0x88
+#define CS12_SW8 0x89
+#define CS13_SW8 0x8A
+#define CS14_SW8 0x8B
+#define CS15_SW8 0x8C
+#define CS16_SW8 0x8D
+#define CS17_SW8 0x8E
+#define CS18_SW8 0x8F
diff --git a/drivers/led/issi/is31fl3745.c b/drivers/led/issi/is31fl3745.c
new file mode 100644
index 0000000000..0f91a75bcc
--- /dev/null
+++ b/drivers/led/issi/is31fl3745.c
@@ -0,0 +1,228 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ * Copyright 2021 MasterSpoon
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "is31fl3745.h"
+#include "i2c_master.h"
+#include "wait.h"
+
+#define IS31FL3745_PWM_REGISTER_COUNT 144
+#define IS31FL3745_SCALING_REGISTER_COUNT 144
+
+#ifndef IS31FL3745_I2C_TIMEOUT
+# define IS31FL3745_I2C_TIMEOUT 100
+#endif
+
+#ifndef IS31FL3745_I2C_PERSISTENCE
+# define IS31FL3745_I2C_PERSISTENCE 0
+#endif
+
+#ifndef IS31FL3745_CONFIGURATION
+# define IS31FL3745_CONFIGURATION 0x31
+#endif
+
+#ifndef IS31FL3745_SW_PULLDOWN
+# define IS31FL3745_SW_PULLDOWN IS31FL3745_PDR_2K_OHM_SW_OFF
+#endif
+
+#ifndef IS31FL3745_CS_PULLUP
+# define IS31FL3745_CS_PULLUP IS31FL3745_PUR_2K_OHM_CS_OFF
+#endif
+
+#ifndef IS31FL3745_GLOBAL_CURRENT
+# define IS31FL3745_GLOBAL_CURRENT 0xFF
+#endif
+
+#ifndef IS31FL3745_SYNC_1
+# define IS31FL3745_SYNC_1 IS31FL3745_SYNC_NONE
+#endif
+#ifndef IS31FL3745_SYNC_2
+# define IS31FL3745_SYNC_2 IS31FL3745_SYNC_NONE
+#endif
+#ifndef IS31FL3745_SYNC_3
+# define IS31FL3745_SYNC_3 IS31FL3745_SYNC_NONE
+#endif
+#ifndef IS31FL3745_SYNC_4
+# define IS31FL3745_SYNC_4 IS31FL3745_SYNC_NONE
+#endif
+
+uint8_t g_pwm_buffer[IS31FL3745_DRIVER_COUNT][IS31FL3745_PWM_REGISTER_COUNT];
+bool g_pwm_buffer_update_required[IS31FL3745_DRIVER_COUNT] = {false};
+bool g_scaling_registers_update_required[IS31FL3745_DRIVER_COUNT] = {false};
+
+uint8_t g_scaling_registers[IS31FL3745_DRIVER_COUNT][IS31FL3745_SCALING_REGISTER_COUNT];
+
+void is31fl3745_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
+#if IS31FL3745_I2C_PERSISTENCE > 0
+ for (uint8_t i = 0; i < IS31FL3745_I2C_PERSISTENCE; i++) {
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3745_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3745_I2C_TIMEOUT);
+#endif
+}
+
+void is31fl3745_select_page(uint8_t addr, uint8_t page) {
+ is31fl3745_write_register(addr, IS31FL3745_REG_COMMAND_WRITE_LOCK, IS31FL3745_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3745_write_register(addr, IS31FL3745_REG_COMMAND, page);
+}
+
+void is31fl3745_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 0 is already selected.
+ // Transmit PWM registers in 8 transfers of 18 bytes.
+
+ // Iterate over the pwm_buffer contents at 18 byte intervals.
+ for (uint8_t i = 0; i < IS31FL3745_PWM_REGISTER_COUNT; i += 18) {
+#if IS31FL3745_I2C_PERSISTENCE > 0
+ for (uint8_t j = 0; j < IS31FL3745_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3745_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3745_I2C_TIMEOUT);
+#endif
+ }
+}
+
+void is31fl3745_init_drivers(void) {
+ i2c_init();
+
+ is31fl3745_init(IS31FL3745_I2C_ADDRESS_1, IS31FL3745_SYNC_1);
+#if defined(IS31FL3745_I2C_ADDRESS_2)
+ is31fl3745_init(IS31FL3745_I2C_ADDRESS_2, IS31FL3745_SYNC_2);
+# if defined(IS31FL3745_I2C_ADDRESS_3)
+ is31fl3745_init(IS31FL3745_I2C_ADDRESS_3, IS31FL3745_SYNC_3);
+# if defined(IS31FL3745_I2C_ADDRESS_4)
+ is31fl3745_init(IS31FL3745_I2C_ADDRESS_4, IS31FL3745_SYNC_4);
+# endif
+# endif
+#endif
+
+ for (int i = 0; i < IS31FL3745_LED_COUNT; i++) {
+ is31fl3745_set_scaling_register(i, 0xFF, 0xFF, 0xFF);
+ }
+
+ is31fl3745_update_scaling_registers(IS31FL3745_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3745_I2C_ADDRESS_2)
+ is31fl3745_update_scaling_registers(IS31FL3745_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3745_I2C_ADDRESS_3)
+ is31fl3745_update_scaling_registers(IS31FL3745_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3745_I2C_ADDRESS_4)
+ is31fl3745_update_scaling_registers(IS31FL3745_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
+
+void is31fl3745_init(uint8_t addr, uint8_t sync) {
+ // In order to avoid the LEDs being driven with garbage data
+ // in the LED driver's PWM registers, shutdown is enabled last.
+ // Set up the mode and other settings, clear the PWM registers,
+ // then disable software shutdown.
+
+ is31fl3745_select_page(addr, IS31FL3745_COMMAND_SCALING);
+
+ // Turn off all LEDs.
+ for (uint8_t i = 0; i < IS31FL3745_SCALING_REGISTER_COUNT; i++) {
+ is31fl3745_write_register(addr, i + 1, 0x00);
+ }
+
+ is31fl3745_select_page(addr, IS31FL3745_COMMAND_PWM);
+
+ for (uint8_t i = 0; i < IS31FL3745_PWM_REGISTER_COUNT; i++) {
+ is31fl3745_write_register(addr, i + 1, 0x00);
+ }
+
+ is31fl3745_select_page(addr, IS31FL3745_COMMAND_FUNCTION);
+
+ is31fl3745_write_register(addr, IS31FL3745_FUNCTION_REG_PULLDOWNUP, (IS31FL3745_SW_PULLDOWN << 4) | IS31FL3745_CS_PULLUP);
+ is31fl3745_write_register(addr, IS31FL3745_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3745_GLOBAL_CURRENT);
+ is31fl3745_write_register(addr, IS31FL3745_FUNCTION_REG_SPREAD_SPECTRUM, (sync & 0b11) << 6);
+ is31fl3745_write_register(addr, IS31FL3745_FUNCTION_REG_CONFIGURATION, IS31FL3745_CONFIGURATION);
+
+ // Wait 10ms to ensure the device has woken up.
+ wait_ms(10);
+}
+
+void is31fl3745_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+ is31fl3745_led_t led;
+
+ if (index >= 0 && index < IS31FL3745_LED_COUNT) {
+ memcpy_P(&led, (&g_is31fl3745_leds[index]), sizeof(led));
+
+ if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) {
+ return;
+ }
+
+ g_pwm_buffer_update_required[led.driver] = true;
+ g_pwm_buffer[led.driver][led.r] = red;
+ g_pwm_buffer[led.driver][led.g] = green;
+ g_pwm_buffer[led.driver][led.b] = blue;
+ }
+}
+
+void is31fl3745_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+ for (int i = 0; i < IS31FL3745_LED_COUNT; i++) {
+ is31fl3745_set_color(i, red, green, blue);
+ }
+}
+
+void is31fl3745_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue) {
+ is31fl3745_led_t led;
+ memcpy_P(&led, (&g_is31fl3745_leds[index]), sizeof(led));
+
+ g_scaling_registers[led.driver][led.r] = red;
+ g_scaling_registers[led.driver][led.g] = green;
+ g_scaling_registers[led.driver][led.b] = blue;
+ g_scaling_registers_update_required[led.driver] = true;
+}
+
+void is31fl3745_update_pwm_buffers(uint8_t addr, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
+ is31fl3745_select_page(addr, IS31FL3745_COMMAND_PWM);
+
+ is31fl3745_write_pwm_buffer(addr, index);
+
+ g_pwm_buffer_update_required[index] = false;
+ }
+}
+
+void is31fl3745_update_scaling_registers(uint8_t addr, uint8_t index) {
+ if (g_scaling_registers_update_required[index]) {
+ is31fl3745_select_page(addr, IS31FL3745_COMMAND_SCALING);
+
+ for (uint8_t i = 0; i < IS31FL3745_SCALING_REGISTER_COUNT; i++) {
+ is31fl3745_write_register(addr, i + 1, g_scaling_registers[index][i]);
+ }
+
+ g_scaling_registers_update_required[index] = false;
+ }
+}
+
+void is31fl3745_flush(void) {
+ is31fl3745_update_pwm_buffers(IS31FL3745_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3745_I2C_ADDRESS_2)
+ is31fl3745_update_pwm_buffers(IS31FL3745_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3745_I2C_ADDRESS_3)
+ is31fl3745_update_pwm_buffers(IS31FL3745_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3745_I2C_ADDRESS_4)
+ is31fl3745_update_pwm_buffers(IS31FL3745_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
diff --git a/drivers/led/issi/is31fl3745.h b/drivers/led/issi/is31fl3745.h
index 1e88aab4a8..3c67f7ecc7 100644
--- a/drivers/led/issi/is31fl3745.h
+++ b/drivers/led/issi/is31fl3745.h
@@ -20,103 +20,106 @@
#pragma once
-// 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)
-// The address will vary depending on your wiring:
-// 00 <-> GND
-// 01 <-> SCL
-// 10 <-> SDA
-// 11 <-> VCC
-// ADDR1 represents A1:A0 of the 7-bit address.
-// ADDR2 represents A3:A2 of the 7-bit address.
-// The result is: 0b010(ADDR2)(ADDR1)
-#ifndef DRIVER_ADDR_1
-# define DRIVER_ADDR_1 0b0100000
-#endif
+#include <stdint.h>
+#include <stdbool.h>
+#include "progmem.h"
+#include "util.h"
-// Set defaults for Spread Spectrum Register
-#ifndef ISSI_SSR_1
-# ifndef DRIVER_ADDR_2
-# define ISSI_SSR_1 0x00
-# else
-# define ISSI_SSR_1 0xC0
-# endif
-#endif
-#ifndef ISSI_SSR_2
-# define ISSI_SSR_2 0x80
-#endif
-#ifndef ISSI_SSR_3
-# define ISSI_SSR_3 0x80
-#endif
-#ifndef ISSI_SSR_4
-# define ISSI_SSR_4 0x80
-#endif
+#define IS31FL3745_REG_ID 0xFC
-// Command Registers
-#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE
-#define ISSI_COMMANDREGISTER 0xFD
-#define ISSI_IDREGISTER 0xFC
-#define ISSI_REGISTER_UNLOCK 0xC5
+#define IS31FL3745_REG_COMMAND 0xFD
-// Response Registers
-#define ISSI_PAGE_PWM 0x00
-#define ISSI_PAGE_SCALING 0x01
-#define ISSI_PAGE_FUNCTION 0x02
+#define IS31FL3745_COMMAND_PWM 0x00
+#define IS31FL3745_COMMAND_SCALING 0x01
+#define IS31FL3745_COMMAND_FUNCTION 0x02
-// Registers under Function Register
-#define ISSI_REG_CONFIGURATION 0x00
-#define ISSI_REG_GLOBALCURRENT 0x01
-#define ISSI_REG_PULLDOWNUP 0x02
-#define ISSI_REG_TEMP 0x24
-#define ISSI_REG_SSR 0x25
-#define ISSI_REG_RESET 0x2F
+#define IS31FL3745_FUNCTION_REG_CONFIGURATION 0x00
+#define IS31FL3745_FUNCTION_REG_GLOBAL_CURRENT 0x01
+#define IS31FL3745_FUNCTION_REG_PULLDOWNUP 0x02
+#define IS31FL3745_FUNCTION_REG_TEMPERATURE 0x24
+#define IS31FL3745_FUNCTION_REG_SPREAD_SPECTRUM 0x25
+#define IS31FL3745_FUNCTION_REG_RESET 0x2F
-// Set defaults for Function Registers
-#ifndef ISSI_CONFIGURATION
-# define ISSI_CONFIGURATION 0x31
-#endif
-#ifndef ISSI_GLOBALCURRENT
-# define ISSI_GLOBALCURRENT 0xFF
-#endif
-#ifndef ISSI_PULLDOWNUP
-# define ISSI_PULLDOWNUP 0x33
-#endif
-#ifndef ISSI_TEMP
-# define ISSI_TEMP 0x00
-#endif
+#define IS31FL3745_REG_COMMAND_WRITE_LOCK 0xFE
+#define IS31FL3745_COMMAND_WRITE_LOCK_MAGIC 0xC5
-// Set defaults for Scaling registers
-#ifndef ISSI_SCAL_RED
-# define ISSI_SCAL_RED 0xFF
-#endif
-#ifndef ISSI_SCAL_BLUE
-# define ISSI_SCAL_BLUE 0xFF
-#endif
-#ifndef ISSI_SCAL_GREEN
-# define ISSI_SCAL_GREEN 0xFF
+#define IS31FL3745_I2C_ADDRESS_GND_GND 0x20
+#define IS31FL3745_I2C_ADDRESS_GND_SCL 0x21
+#define IS31FL3745_I2C_ADDRESS_GND_SDA 0x22
+#define IS31FL3745_I2C_ADDRESS_GND_VCC 0x23
+#define IS31FL3745_I2C_ADDRESS_SCL_GND 0x24
+#define IS31FL3745_I2C_ADDRESS_SCL_SCL 0x25
+#define IS31FL3745_I2C_ADDRESS_SCL_SDA 0x26
+#define IS31FL3745_I2C_ADDRESS_SCL_VCC 0x27
+#define IS31FL3745_I2C_ADDRESS_SDA_GND 0x28
+#define IS31FL3745_I2C_ADDRESS_SDA_SCL 0x29
+#define IS31FL3745_I2C_ADDRESS_SDA_SDA 0x2A
+#define IS31FL3745_I2C_ADDRESS_SDA_VCC 0x2B
+#define IS31FL3745_I2C_ADDRESS_VCC_GND 0x2C
+#define IS31FL3745_I2C_ADDRESS_VCC_SCL 0x2D
+#define IS31FL3745_I2C_ADDRESS_VCC_SDA 0x2E
+#define IS31FL3745_I2C_ADDRESS_VCC_VCC 0x2F
+
+#if defined(RGB_MATRIX_IS31FL3745)
+# define IS31FL3745_LED_COUNT RGB_MATRIX_LED_COUNT
#endif
-#define ISSI_SCAL_RED_OFF 0x00
-#define ISSI_SCAL_GREEN_OFF 0x00
-#define ISSI_SCAL_BLUE_OFF 0x00
-#ifndef ISSI_SCAL_LED
-# define ISSI_SCAL_LED 0xFF
+#if defined(IS31FL3745_I2C_ADDRESS_4)
+# define IS31FL3745_DRIVER_COUNT 4
+#elif defined(IS31FL3745_I2C_ADDRESS_3)
+# define IS31FL3745_DRIVER_COUNT 3
+#elif defined(IS31FL3745_I2C_ADDRESS_2)
+# define IS31FL3745_DRIVER_COUNT 2
+#elif defined(IS31FL3745_I2C_ADDRESS_1)
+# define IS31FL3745_DRIVER_COUNT 1
#endif
-#define ISSI_SCAL_LED_OFF 0x00
-// Set buffer sizes
-#define ISSI_MAX_LEDS 144
-#define ISSI_SCALING_SIZE 144
-#define ISSI_PWM_TRF_SIZE 18
-#define ISSI_SCALING_TRF_SIZE 18
+typedef struct is31fl3745_led_t {
+ uint8_t driver : 2;
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+} PACKED is31fl3745_led_t;
+
+extern const is31fl3745_led_t PROGMEM g_is31fl3745_leds[IS31FL3745_LED_COUNT];
+
+void is31fl3745_init_drivers(void);
+void is31fl3745_init(uint8_t addr, uint8_t sync);
+void is31fl3745_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void is31fl3745_select_page(uint8_t addr, uint8_t page);
+
+void is31fl3745_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void is31fl3745_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
+
+void is31fl3745_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue);
+
+void is31fl3745_update_pwm_buffers(uint8_t addr, uint8_t index);
+void is31fl3745_update_scaling_registers(uint8_t addr, uint8_t index);
+
+void is31fl3745_flush(void);
+
+#define IS31FL3745_PDR_0_OHM 0b000 // No pull-down resistor
+#define IS31FL3745_PDR_0K5_OHM_SW_OFF 0b001 // 0.5 kOhm resistor in SWx off time
+#define IS31FL3745_PDR_1K_OHM_SW_OFF 0b010 // 1 kOhm resistor in SWx off time
+#define IS31FL3745_PDR_2K_OHM_SW_OFF 0b011 // 2 kOhm resistor in SWx off time
+#define IS31FL3745_PDR_1K_OHM 0b100 // 1 kOhm resistor
+#define IS31FL3745_PDR_2K_OHM 0b101 // 2 kOhm resistor
+#define IS31FL3745_PDR_4K_OHM 0b110 // 4 kOhm resistor
+#define IS31FL3745_PDR_8K_OHM 0b111 // 8 kOhm resistor
+
+#define IS31FL3745_PUR_0_OHM 0b000 // No pull-up resistor
+#define IS31FL3745_PUR_0K5_OHM_CS_OFF 0b001 // 0.5 kOhm resistor in CSy off time
+#define IS31FL3745_PUR_1K_OHM_CS_OFF 0b010 // 1 kOhm resistor in CSy off time
+#define IS31FL3745_PUR_2K_OHM_CS_OFF 0b011 // 2 kOhm resistor in CSy off time
+#define IS31FL3745_PUR_1K_OHM 0b100 // 1 kOhm resistor
+#define IS31FL3745_PUR_2K_OHM 0b101 // 2 kOhm resistor
+#define IS31FL3745_PUR_4K_OHM 0b110 // 4 kOhm resistor
+#define IS31FL3745_PUR_8K_OHM 0b111 // 8 kOhm resistor
-// Location of 1st bit for PWM and Scaling registers
-#define ISSI_PWM_REG_1ST 0x01
-#define ISSI_SCL_REG_1ST 0x01
+#define IS31FL3745_SYNC_NONE 0b00
+#define IS31FL3745_SYNC_SLAVE 0b10
+#define IS31FL3745_SYNC_MASTER 0b11
-// Map CS SW locations to order in PWM / Scaling buffers
-// This matches the ORDER in the Datasheet Register not the POSITION
-// It will always count from 0x00 to (ISSI_MAX_LEDS - 1)
#define CS1_SW1 0x00
#define CS2_SW1 0x01
#define CS3_SW1 0x02
diff --git a/drivers/led/issi/is31fl3746.h b/drivers/led/issi/is31fl3746.h
deleted file mode 100644
index f89f281533..0000000000
--- a/drivers/led/issi/is31fl3746.h
+++ /dev/null
@@ -1,198 +0,0 @@
-/* Copyright 2017 Jason Williams
- * Copyright 2018 Jack Humbert
- * Copyright 2018 Yiancar
- * Copyright 2020 MelGeek
- * Copyright 2021 MasterSpoon
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-// 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)
-// The address will vary depending on your wiring:
-// 00 <-> GND
-// 01 <-> SCL
-// 10 <-> SDA
-// 11 <-> VCC
-// ADDR1 represents A1:A0 of the 7-bit address.
-// ADDR2 represents A3:A2 of the 7-bit address.
-// The result is: 0b110(ADDR2)(ADDR1)
-#ifndef DRIVER_ADDR_1
-# define DRIVER_ADDR_1 0b1100000
-#endif
-
-// Set defaults for Spread Spectrum Register
-#ifndef ISSI_SSR_1
-# define ISSI_SSR_1 0x00
-#endif
-#ifndef ISSI_SSR_2
-# define ISSI_SSR_2 0x00
-#endif
-#ifndef ISSI_SSR_3
-# define ISSI_SSR_3 0x00
-#endif
-#ifndef ISSI_SSR_4
-# define ISSI_SSR_4 0x00
-#endif
-
-// Command Registers
-#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE
-#define ISSI_COMMANDREGISTER 0xFD
-#define ISSI_IDREGISTER 0xFC
-#define ISSI_REGISTER_UNLOCK 0xC5
-
-// Response Registers
-#define ISSI_PAGE_PWM 0x00
-#define ISSI_PAGE_SCALING 0x01
-#define ISSI_PAGE_FUNCTION 0x01
-
-// Registers under Function Register
-#define ISSI_REG_CONFIGURATION 0x50
-#define ISSI_REG_GLOBALCURRENT 0x51
-#define ISSI_REG_PULLDOWNUP 0x52
-#define ISSI_REG_TEMP 0x5F
-#define ISSI_REG_SSR 0x60
-#define ISSI_REG_RESET 0x8F
-#define ISSI_REG_PWM_ENABLE 0xE0
-#define ISSI_REG_PWM_SET 0xE2
-
-// Set defaults for Function Registers
-#ifndef ISSI_CONFIGURATION
-# define ISSI_CONFIGURATION 0x01
-#endif
-#ifndef ISSI_GLOBALCURRENT
-# define ISSI_GLOBALCURRENT 0xFF
-#endif
-#ifndef ISSI_PULLDOWNUP
-# define ISSI_PULLDOWNUP 0x33
-#endif
-#ifndef ISSI_TEMP
-# define ISSI_TEMP 0x00
-#endif
-#ifndef ISSI_PWM_ENABLE
-# define ISSI_PWM_ENABLE 0x00
-#endif
-#ifndef ISSI_PWM_SET
-# define ISSI_PWM_SET 0x00
-#endif
-
-// Set defaults for Scaling registers
-#ifndef ISSI_SCAL_RED
-# define ISSI_SCAL_RED 0xFF
-#endif
-#ifndef ISSI_SCAL_BLUE
-# define ISSI_SCAL_BLUE 0xFF
-#endif
-#ifndef ISSI_SCAL_GREEN
-# define ISSI_SCAL_GREEN 0xFF
-#endif
-#define ISSI_SCAL_RED_OFF 0x00
-#define ISSI_SCAL_GREEN_OFF 0x00
-#define ISSI_SCAL_BLUE_OFF 0x00
-
-#ifndef ISSI_SCAL_LED
-# define ISSI_SCAL_LED 0xFF
-#endif
-#define ISSI_SCAL_LED_OFF 0x00
-
-// Set buffer sizes
-#define ISSI_MAX_LEDS 72
-#define ISSI_SCALING_SIZE 72
-#define ISSI_PWM_TRF_SIZE 18
-#define ISSI_SCALING_TRF_SIZE 18
-
-// Location of 1st bit for PWM and Scaling registers
-#define ISSI_PWM_REG_1ST 0x01
-#define ISSI_SCL_REG_1ST 0x01
-
-// Map CS SW locations to order in PWM / Scaling buffers
-// This matches the ORDER in the Datasheet Register not the POSITION
-// It will always count from 0x00 to (ISSI_MAX_LEDS - 1)
-#define CS1_SW1 0x00
-#define CS2_SW1 0x01
-#define CS3_SW1 0x02
-#define CS4_SW1 0x03
-#define CS5_SW1 0x04
-#define CS6_SW1 0x05
-#define CS7_SW1 0x06
-#define CS8_SW1 0x07
-#define CS9_SW1 0x08
-#define CS10_SW1 0x09
-#define CS11_SW1 0x0A
-#define CS12_SW1 0x0B
-#define CS13_SW1 0x0C
-#define CS14_SW1 0x0D
-#define CS15_SW1 0x0E
-#define CS16_SW1 0x0F
-#define CS17_SW1 0x10
-#define CS18_SW1 0x11
-
-#define CS1_SW2 0x12
-#define CS2_SW2 0x13
-#define CS3_SW2 0x14
-#define CS4_SW2 0x15
-#define CS5_SW2 0x16
-#define CS6_SW2 0x17
-#define CS7_SW2 0x18
-#define CS8_SW2 0x19
-#define CS9_SW2 0x1A
-#define CS10_SW2 0x1B
-#define CS11_SW2 0x1C
-#define CS12_SW2 0x1D
-#define CS13_SW2 0x1E
-#define CS14_SW2 0x1F
-#define CS15_SW2 0x20
-#define CS16_SW2 0x21
-#define CS17_SW2 0x22
-#define CS18_SW2 0x23
-
-#define CS1_SW3 0x24
-#define CS2_SW3 0x25
-#define CS3_SW3 0x26
-#define CS4_SW3 0x27
-#define CS5_SW3 0x28
-#define CS6_SW3 0x29
-#define CS7_SW3 0x2A
-#define CS8_SW3 0x2B
-#define CS9_SW3 0x2C
-#define CS10_SW3 0x2D
-#define CS11_SW3 0x2E
-#define CS12_SW3 0x2F
-#define CS13_SW3 0x30
-#define CS14_SW3 0x31
-#define CS15_SW3 0x32
-#define CS16_SW3 0x33
-#define CS17_SW3 0x34
-#define CS18_SW3 0x35
-
-#define CS1_SW4 0x36
-#define CS2_SW4 0x37
-#define CS3_SW4 0x38
-#define CS4_SW4 0x39
-#define CS5_SW4 0x3A
-#define CS6_SW4 0x3B
-#define CS7_SW4 0x3C
-#define CS8_SW4 0x3D
-#define CS9_SW4 0x3E
-#define CS10_SW4 0x3F
-#define CS11_SW4 0x40
-#define CS12_SW4 0x41
-#define CS13_SW4 0x42
-#define CS14_SW4 0x43
-#define CS15_SW4 0x44
-#define CS16_SW4 0x45
-#define CS17_SW4 0x46
-#define CS18_SW4 0x47
diff --git a/drivers/led/issi/is31fl3746a-mono.c b/drivers/led/issi/is31fl3746a-mono.c
new file mode 100644
index 0000000000..c21269b3a3
--- /dev/null
+++ b/drivers/led/issi/is31fl3746a-mono.c
@@ -0,0 +1,216 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ * Copyright 2021 MasterSpoon
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "is31fl3746a-mono.h"
+#include "i2c_master.h"
+#include "wait.h"
+
+#define IS31FL3746A_PWM_REGISTER_COUNT 72
+#define IS31FL3746A_SCALING_REGISTER_COUNT 72
+
+#ifndef IS31FL3746A_I2C_TIMEOUT
+# define IS31FL3746A_I2C_TIMEOUT 100
+#endif
+
+#ifndef IS31FL3746A_I2C_PERSISTENCE
+# define IS31FL3746A_I2C_PERSISTENCE 0
+#endif
+
+#ifndef IS31FL3746A_CONFIGURATION
+# define IS31FL3746A_CONFIGURATION 0x01
+#endif
+
+#ifndef IS31FL3746A_PWM_FREQUENCY
+# define IS31FL3746A_PWM_FREQUENCY IS31FL3746A_PWM_FREQUENCY_29K_HZ
+#endif
+
+#ifndef IS31FL3746A_SW_PULLDOWN
+# define IS31FL3746A_SW_PULLDOWN IS31FL3746A_PDR_2K_OHM_SW_OFF
+#endif
+
+#ifndef IS31FL3746A_CS_PULLUP
+# define IS31FL3746A_CS_PULLUP IS31FL3746A_PUR_2K_OHM_CS_OFF
+#endif
+
+#ifndef IS31FL3746A_GLOBAL_CURRENT
+# define IS31FL3746A_GLOBAL_CURRENT 0xFF
+#endif
+
+uint8_t g_pwm_buffer[IS31FL3746A_DRIVER_COUNT][IS31FL3746A_PWM_REGISTER_COUNT];
+bool g_pwm_buffer_update_required[IS31FL3746A_DRIVER_COUNT] = {false};
+bool g_scaling_registers_update_required[IS31FL3746A_DRIVER_COUNT] = {false};
+
+uint8_t g_scaling_registers[IS31FL3746A_DRIVER_COUNT][IS31FL3746A_SCALING_REGISTER_COUNT];
+
+void is31fl3746a_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
+#if IS31FL3746A_I2C_PERSISTENCE > 0
+ for (uint8_t i = 0; i < IS31FL3746A_I2C_PERSISTENCE; i++) {
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3746A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3746A_I2C_TIMEOUT);
+#endif
+}
+
+void is31fl3746a_select_page(uint8_t addr, uint8_t page) {
+ is31fl3746a_write_register(addr, IS31FL3746A_REG_COMMAND_WRITE_LOCK, IS31FL3746A_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3746a_write_register(addr, IS31FL3746A_REG_COMMAND, page);
+}
+
+void is31fl3746a_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 0 is already selected.
+ // Transmit PWM registers in 4 transfers of 18 bytes.
+
+ // Iterate over the pwm_buffer contents at 18 byte intervals.
+ for (uint8_t i = 0; i < IS31FL3746A_PWM_REGISTER_COUNT; i += 18) {
+#if IS31FL3746A_I2C_PERSISTENCE > 0
+ for (uint8_t j = 0; j < IS31FL3746A_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3746A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3746A_I2C_TIMEOUT);
+#endif
+ }
+}
+
+void is31fl3746a_init_drivers(void) {
+ i2c_init();
+
+ is31fl3746a_init(IS31FL3746A_I2C_ADDRESS_1);
+#if defined(IS31FL3746A_I2C_ADDRESS_2)
+ is31fl3746a_init(IS31FL3746A_I2C_ADDRESS_2);
+# if defined(IS31FL3746A_I2C_ADDRESS_3)
+ is31fl3746a_init(IS31FL3746A_I2C_ADDRESS_3);
+# if defined(IS31FL3746A_I2C_ADDRESS_4)
+ is31fl3746a_init(IS31FL3746A_I2C_ADDRESS_4);
+# endif
+# endif
+#endif
+
+ for (int i = 0; i < IS31FL3746A_LED_COUNT; i++) {
+ is31fl3746a_set_scaling_register(i, 0xFF);
+ }
+
+ is31fl3746a_update_scaling_registers(IS31FL3746A_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3746A_I2C_ADDRESS_2)
+ is31fl3746a_update_scaling_registers(IS31FL3746A_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3746A_I2C_ADDRESS_3)
+ is31fl3746a_update_scaling_registers(IS31FL3746A_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3746A_I2C_ADDRESS_4)
+ is31fl3746a_update_scaling_registers(IS31FL3746A_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
+
+void is31fl3746a_init(uint8_t addr) {
+ // In order to avoid the LEDs being driven with garbage data
+ // in the LED driver's PWM registers, shutdown is enabled last.
+ // Set up the mode and other settings, clear the PWM registers,
+ // then disable software shutdown.
+
+ is31fl3746a_select_page(addr, IS31FL3746A_COMMAND_SCALING);
+
+ // Turn off all LEDs.
+ for (uint8_t i = 0; i < IS31FL3746A_SCALING_REGISTER_COUNT; i++) {
+ is31fl3746a_write_register(addr, i + 1, 0x00);
+ }
+
+ is31fl3746a_select_page(addr, IS31FL3746A_COMMAND_PWM);
+
+ for (uint8_t i = 0; i < IS31FL3746A_PWM_REGISTER_COUNT; i++) {
+ is31fl3746a_write_register(addr, i + 1, 0x00);
+ }
+
+ is31fl3746a_select_page(addr, IS31FL3746A_COMMAND_FUNCTION);
+
+ is31fl3746a_write_register(addr, IS31FL3746A_FUNCTION_REG_PULLDOWNUP, (IS31FL3746A_SW_PULLDOWN << 4) | IS31FL3746A_CS_PULLUP);
+ is31fl3746a_write_register(addr, IS31FL3746A_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3746A_GLOBAL_CURRENT);
+ is31fl3746a_write_register(addr, IS31FL3746A_FUNCTION_REG_PWM_ENABLE, 0x01);
+ is31fl3746a_write_register(addr, IS31FL3746A_FUNCTION_REG_PWM_FREQUENCY, IS31FL3746A_PWM_FREQUENCY);
+ is31fl3746a_write_register(addr, IS31FL3746A_FUNCTION_REG_CONFIGURATION, IS31FL3746A_CONFIGURATION);
+
+ // Wait 10ms to ensure the device has woken up.
+ wait_ms(10);
+}
+
+void is31fl3746a_set_value(int index, uint8_t value) {
+ is31fl3746a_led_t led;
+
+ if (index >= 0 && index < IS31FL3746A_LED_COUNT) {
+ memcpy_P(&led, (&g_is31fl3746a_leds[index]), sizeof(led));
+
+ if (g_pwm_buffer[led.driver][led.v] == value) {
+ return;
+ }
+
+ g_pwm_buffer_update_required[led.driver] = true;
+ g_pwm_buffer[led.driver][led.v] = value;
+ }
+}
+
+void is31fl3746a_set_value_all(uint8_t value) {
+ for (int i = 0; i < IS31FL3746A_LED_COUNT; i++) {
+ is31fl3746a_set_value(i, value);
+ }
+}
+
+void is31fl3746a_set_scaling_register(uint8_t index, uint8_t value) {
+ is31fl3746a_led_t led;
+ memcpy_P(&led, (&g_is31fl3746a_leds[index]), sizeof(led));
+
+ g_scaling_registers[led.driver][led.v] = value;
+ g_scaling_registers_update_required[led.driver] = true;
+}
+
+void is31fl3746a_update_pwm_buffers(uint8_t addr, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
+ is31fl3746a_select_page(addr, IS31FL3746A_COMMAND_PWM);
+
+ is31fl3746a_write_pwm_buffer(addr, index);
+
+ g_pwm_buffer_update_required[index] = false;
+ }
+}
+
+void is31fl3746a_update_scaling_registers(uint8_t addr, uint8_t index) {
+ if (g_scaling_registers_update_required[index]) {
+ is31fl3746a_select_page(addr, IS31FL3746A_COMMAND_SCALING);
+
+ for (uint8_t i = 0; i < IS31FL3746A_SCALING_REGISTER_COUNT; i++) {
+ is31fl3746a_write_register(addr, i + 1, g_scaling_registers[index][i]);
+ }
+
+ g_scaling_registers_update_required[index] = false;
+ }
+}
+
+void is31fl3746a_flush(void) {
+ is31fl3746a_update_pwm_buffers(IS31FL3746A_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3746A_I2C_ADDRESS_2)
+ is31fl3746a_update_pwm_buffers(IS31FL3746A_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3746A_I2C_ADDRESS_3)
+ is31fl3746a_update_pwm_buffers(IS31FL3746A_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3746A_I2C_ADDRESS_4)
+ is31fl3746a_update_pwm_buffers(IS31FL3746A_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
diff --git a/drivers/led/issi/is31fl3746a-mono.h b/drivers/led/issi/is31fl3746a-mono.h
new file mode 100644
index 0000000000..002a91f175
--- /dev/null
+++ b/drivers/led/issi/is31fl3746a-mono.h
@@ -0,0 +1,201 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ * Copyright 2021 MasterSpoon
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <stdbool.h>
+#include "progmem.h"
+#include "util.h"
+
+#define IS31FL3746A_REG_ID 0xFC
+
+#define IS31FL3746A_REG_COMMAND 0xFD
+
+#define IS31FL3746A_COMMAND_PWM 0x00
+#define IS31FL3746A_COMMAND_SCALING 0x01
+#define IS31FL3746A_COMMAND_FUNCTION 0x01
+
+#define IS31FL3746A_FUNCTION_REG_CONFIGURATION 0x50
+#define IS31FL3746A_FUNCTION_REG_GLOBAL_CURRENT 0x51
+#define IS31FL3746A_FUNCTION_REG_PULLDOWNUP 0x52
+#define IS31FL3746A_FUNCTION_REG_TEMPERATURE 0x5F
+#define IS31FL3746A_FUNCTION_REG_SPREAD_SPECTRUM 0x60
+#define IS31FL3746A_FUNCTION_REG_RESET 0x8F
+#define IS31FL3746A_FUNCTION_REG_PWM_ENABLE 0xE0
+#define IS31FL3746A_FUNCTION_REG_PWM_FREQUENCY 0xE2
+
+#define IS31FL3746A_REG_COMMAND_WRITE_LOCK 0xFE
+#define IS31FL3746A_COMMAND_WRITE_LOCK_MAGIC 0xC5
+
+#define IS31FL3746A_I2C_ADDRESS_GND_GND 0x60
+#define IS31FL3746A_I2C_ADDRESS_GND_SCL 0x61
+#define IS31FL3746A_I2C_ADDRESS_GND_SDA 0x62
+#define IS31FL3746A_I2C_ADDRESS_GND_VCC 0x63
+#define IS31FL3746A_I2C_ADDRESS_SCL_GND 0x64
+#define IS31FL3746A_I2C_ADDRESS_SCL_SCL 0x65
+#define IS31FL3746A_I2C_ADDRESS_SCL_SDA 0x66
+#define IS31FL3746A_I2C_ADDRESS_SCL_VCC 0x67
+#define IS31FL3746A_I2C_ADDRESS_SDA_GND 0x68
+#define IS31FL3746A_I2C_ADDRESS_SDA_SCL 0x69
+#define IS31FL3746A_I2C_ADDRESS_SDA_SDA 0x6A
+#define IS31FL3746A_I2C_ADDRESS_SDA_VCC 0x6B
+#define IS31FL3746A_I2C_ADDRESS_VCC_GND 0x6C
+#define IS31FL3746A_I2C_ADDRESS_VCC_SCL 0x6D
+#define IS31FL3746A_I2C_ADDRESS_VCC_SDA 0x6E
+#define IS31FL3746A_I2C_ADDRESS_VCC_VCC 0x6F
+
+#if defined(LED_MATRIX_IS31FL3746A)
+# define IS31FL3746A_LED_COUNT LED_MATRIX_LED_COUNT
+#endif
+
+#if defined(IS31FL3746A_I2C_ADDRESS_4)
+# define IS31FL3746A_DRIVER_COUNT 4
+#elif defined(IS31FL3746A_I2C_ADDRESS_3)
+# define IS31FL3746A_DRIVER_COUNT 3
+#elif defined(IS31FL3746A_I2C_ADDRESS_2)
+# define IS31FL3746A_DRIVER_COUNT 2
+#elif defined(IS31FL3746A_I2C_ADDRESS_1)
+# define IS31FL3746A_DRIVER_COUNT 1
+#endif
+
+typedef struct is31fl3746a_led_t {
+ uint8_t driver : 2;
+ uint8_t v;
+} PACKED is31fl3746a_led_t;
+
+extern const is31fl3746a_led_t PROGMEM g_is31fl3746a_leds[IS31FL3746A_LED_COUNT];
+
+void is31fl3746a_init_drivers(void);
+void is31fl3746a_init(uint8_t addr);
+void is31fl3746a_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void is31fl3746a_select_page(uint8_t addr, uint8_t page);
+
+void is31fl3746a_set_value(int index, uint8_t value);
+void is31fl3746a_set_value_all(uint8_t value);
+
+void is31fl3746a_set_scaling_register(uint8_t index, uint8_t value);
+
+void is31fl3746a_update_pwm_buffers(uint8_t addr, uint8_t index);
+void is31fl3746a_update_scaling_registers(uint8_t addr, uint8_t index);
+
+void is31fl3746a_flush(void);
+
+#define IS31FL3746A_PDR_0_OHM 0b000 // No pull-down resistor
+#define IS31FL3746A_PDR_0K5_OHM_SW_OFF 0b001 // 0.5 kOhm resistor in SWx off time
+#define IS31FL3746A_PDR_1K_OHM_SW_OFF 0b010 // 1 kOhm resistor in SWx off time
+#define IS31FL3746A_PDR_2K_OHM_SW_OFF 0b011 // 2 kOhm resistor in SWx off time
+#define IS31FL3746A_PDR_1K_OHM 0b100 // 1 kOhm resistor
+#define IS31FL3746A_PDR_2K_OHM 0b101 // 2 kOhm resistor
+#define IS31FL3746A_PDR_4K_OHM 0b110 // 4 kOhm resistor
+#define IS31FL3746A_PDR_8K_OHM 0b111 // 8 kOhm resistor
+
+#define IS31FL3746A_PUR_0_OHM 0b000 // No pull-up resistor
+#define IS31FL3746A_PUR_0K5_OHM_CS_OFF 0b001 // 0.5 kOhm resistor in CSy off time
+#define IS31FL3746A_PUR_1K_OHM_CS_OFF 0b010 // 1 kOhm resistor in CSy off time
+#define IS31FL3746A_PUR_2K_OHM_CS_OFF 0b011 // 2 kOhm resistor in CSy off time
+#define IS31FL3746A_PUR_1K_OHM 0b100 // 1 kOhm resistor
+#define IS31FL3746A_PUR_2K_OHM 0b101 // 2 kOhm resistor
+#define IS31FL3746A_PUR_4K_OHM 0b110 // 4 kOhm resistor
+#define IS31FL3746A_PUR_8K_OHM 0b111 // 8 kOhm resistor
+
+#define IS31FL3746A_PWM_FREQUENCY_29K_HZ 0b000
+#define IS31FL3746A_PWM_FREQUENCY_14K5_HZ 0b001
+#define IS31FL3746A_PWM_FREQUENCY_7K25_HZ 0b010
+#define IS31FL3746A_PWM_FREQUENCY_3K63_HZ 0b011
+#define IS31FL3746A_PWM_FREQUENCY_1K81_HZ 0b100
+#define IS31FL3746A_PWM_FREQUENCY_906_HZ 0b101
+#define IS31FL3746A_PWM_FREQUENCY_453_HZ 0b110
+
+#define CS1_SW1 0x00
+#define CS2_SW1 0x01
+#define CS3_SW1 0x02
+#define CS4_SW1 0x03
+#define CS5_SW1 0x04
+#define CS6_SW1 0x05
+#define CS7_SW1 0x06
+#define CS8_SW1 0x07
+#define CS9_SW1 0x08
+#define CS10_SW1 0x09
+#define CS11_SW1 0x0A
+#define CS12_SW1 0x0B
+#define CS13_SW1 0x0C
+#define CS14_SW1 0x0D
+#define CS15_SW1 0x0E
+#define CS16_SW1 0x0F
+#define CS17_SW1 0x10
+#define CS18_SW1 0x11
+
+#define CS1_SW2 0x12
+#define CS2_SW2 0x13
+#define CS3_SW2 0x14
+#define CS4_SW2 0x15
+#define CS5_SW2 0x16
+#define CS6_SW2 0x17
+#define CS7_SW2 0x18
+#define CS8_SW2 0x19
+#define CS9_SW2 0x1A
+#define CS10_SW2 0x1B
+#define CS11_SW2 0x1C
+#define CS12_SW2 0x1D
+#define CS13_SW2 0x1E
+#define CS14_SW2 0x1F
+#define CS15_SW2 0x20
+#define CS16_SW2 0x21
+#define CS17_SW2 0x22
+#define CS18_SW2 0x23
+
+#define CS1_SW3 0x24
+#define CS2_SW3 0x25
+#define CS3_SW3 0x26
+#define CS4_SW3 0x27
+#define CS5_SW3 0x28
+#define CS6_SW3 0x29
+#define CS7_SW3 0x2A
+#define CS8_SW3 0x2B
+#define CS9_SW3 0x2C
+#define CS10_SW3 0x2D
+#define CS11_SW3 0x2E
+#define CS12_SW3 0x2F
+#define CS13_SW3 0x30
+#define CS14_SW3 0x31
+#define CS15_SW3 0x32
+#define CS16_SW3 0x33
+#define CS17_SW3 0x34
+#define CS18_SW3 0x35
+
+#define CS1_SW4 0x36
+#define CS2_SW4 0x37
+#define CS3_SW4 0x38
+#define CS4_SW4 0x39
+#define CS5_SW4 0x3A
+#define CS6_SW4 0x3B
+#define CS7_SW4 0x3C
+#define CS8_SW4 0x3D
+#define CS9_SW4 0x3E
+#define CS10_SW4 0x3F
+#define CS11_SW4 0x40
+#define CS12_SW4 0x41
+#define CS13_SW4 0x42
+#define CS14_SW4 0x43
+#define CS15_SW4 0x44
+#define CS16_SW4 0x45
+#define CS17_SW4 0x46
+#define CS18_SW4 0x47
diff --git a/drivers/led/issi/is31fl3746a.c b/drivers/led/issi/is31fl3746a.c
new file mode 100644
index 0000000000..d167cdd90b
--- /dev/null
+++ b/drivers/led/issi/is31fl3746a.c
@@ -0,0 +1,220 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ * Copyright 2021 MasterSpoon
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "is31fl3746a.h"
+#include "i2c_master.h"
+#include "wait.h"
+
+#define IS31FL3746A_PWM_REGISTER_COUNT 72
+#define IS31FL3746A_SCALING_REGISTER_COUNT 72
+
+#ifndef IS31FL3746A_I2C_TIMEOUT
+# define IS31FL3746A_I2C_TIMEOUT 100
+#endif
+
+#ifndef IS31FL3746A_I2C_PERSISTENCE
+# define IS31FL3746A_I2C_PERSISTENCE 0
+#endif
+
+#ifndef IS31FL3746A_CONFIGURATION
+# define IS31FL3746A_CONFIGURATION 0x01
+#endif
+
+#ifndef IS31FL3746A_PWM_FREQUENCY
+# define IS31FL3746A_PWM_FREQUENCY IS31FL3746A_PWM_FREQUENCY_29K_HZ
+#endif
+
+#ifndef IS31FL3746A_SW_PULLDOWN
+# define IS31FL3746A_SW_PULLDOWN IS31FL3746A_PDR_2K_OHM_SW_OFF
+#endif
+
+#ifndef IS31FL3746A_CS_PULLUP
+# define IS31FL3746A_CS_PULLUP IS31FL3746A_PUR_2K_OHM_CS_OFF
+#endif
+
+#ifndef IS31FL3746A_GLOBAL_CURRENT
+# define IS31FL3746A_GLOBAL_CURRENT 0xFF
+#endif
+
+uint8_t g_pwm_buffer[IS31FL3746A_DRIVER_COUNT][IS31FL3746A_PWM_REGISTER_COUNT];
+bool g_pwm_buffer_update_required[IS31FL3746A_DRIVER_COUNT] = {false};
+bool g_scaling_registers_update_required[IS31FL3746A_DRIVER_COUNT] = {false};
+
+uint8_t g_scaling_registers[IS31FL3746A_DRIVER_COUNT][IS31FL3746A_SCALING_REGISTER_COUNT];
+
+void is31fl3746a_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
+#if IS31FL3746A_I2C_PERSISTENCE > 0
+ for (uint8_t i = 0; i < IS31FL3746A_I2C_PERSISTENCE; i++) {
+ if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3746A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, reg, &data, 1, IS31FL3746A_I2C_TIMEOUT);
+#endif
+}
+
+void is31fl3746a_select_page(uint8_t addr, uint8_t page) {
+ is31fl3746a_write_register(addr, IS31FL3746A_REG_COMMAND_WRITE_LOCK, IS31FL3746A_COMMAND_WRITE_LOCK_MAGIC);
+ is31fl3746a_write_register(addr, IS31FL3746A_REG_COMMAND, page);
+}
+
+void is31fl3746a_write_pwm_buffer(uint8_t addr, uint8_t index) {
+ // Assumes page 0 is already selected.
+ // Transmit PWM registers in 4 transfers of 18 bytes.
+
+ // Iterate over the pwm_buffer contents at 18 byte intervals.
+ for (uint8_t i = 0; i < IS31FL3746A_PWM_REGISTER_COUNT; i += 18) {
+#if IS31FL3746A_I2C_PERSISTENCE > 0
+ for (uint8_t j = 0; j < IS31FL3746A_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3746A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
+ }
+#else
+ i2c_write_register(addr << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3746A_I2C_TIMEOUT);
+#endif
+ }
+}
+
+void is31fl3746a_init_drivers(void) {
+ i2c_init();
+
+ is31fl3746a_init(IS31FL3746A_I2C_ADDRESS_1);
+#if defined(IS31FL3746A_I2C_ADDRESS_2)
+ is31fl3746a_init(IS31FL3746A_I2C_ADDRESS_2);
+# if defined(IS31FL3746A_I2C_ADDRESS_3)
+ is31fl3746a_init(IS31FL3746A_I2C_ADDRESS_3);
+# if defined(IS31FL3746A_I2C_ADDRESS_4)
+ is31fl3746a_init(IS31FL3746A_I2C_ADDRESS_4);
+# endif
+# endif
+#endif
+
+ for (int i = 0; i < IS31FL3746A_LED_COUNT; i++) {
+ is31fl3746a_set_scaling_register(i, 0xFF, 0xFF, 0xFF);
+ }
+
+ is31fl3746a_update_scaling_registers(IS31FL3746A_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3746A_I2C_ADDRESS_2)
+ is31fl3746a_update_scaling_registers(IS31FL3746A_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3746A_I2C_ADDRESS_3)
+ is31fl3746a_update_scaling_registers(IS31FL3746A_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3746A_I2C_ADDRESS_4)
+ is31fl3746a_update_scaling_registers(IS31FL3746A_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
+
+void is31fl3746a_init(uint8_t addr) {
+ // In order to avoid the LEDs being driven with garbage data
+ // in the LED driver's PWM registers, shutdown is enabled last.
+ // Set up the mode and other settings, clear the PWM registers,
+ // then disable software shutdown.
+
+ is31fl3746a_select_page(addr, IS31FL3746A_COMMAND_SCALING);
+
+ // Turn off all LEDs.
+ for (uint8_t i = 0; i < IS31FL3746A_SCALING_REGISTER_COUNT; i++) {
+ is31fl3746a_write_register(addr, i + 1, 0x00);
+ }
+
+ is31fl3746a_select_page(addr, IS31FL3746A_COMMAND_PWM);
+
+ for (uint8_t i = 0; i < IS31FL3746A_PWM_REGISTER_COUNT; i++) {
+ is31fl3746a_write_register(addr, i + 1, 0x00);
+ }
+
+ is31fl3746a_select_page(addr, IS31FL3746A_COMMAND_FUNCTION);
+
+ is31fl3746a_write_register(addr, IS31FL3746A_FUNCTION_REG_PULLDOWNUP, (IS31FL3746A_SW_PULLDOWN << 4) | IS31FL3746A_CS_PULLUP);
+ is31fl3746a_write_register(addr, IS31FL3746A_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3746A_GLOBAL_CURRENT);
+ is31fl3746a_write_register(addr, IS31FL3746A_FUNCTION_REG_PWM_ENABLE, 0x01);
+ is31fl3746a_write_register(addr, IS31FL3746A_FUNCTION_REG_PWM_FREQUENCY, IS31FL3746A_PWM_FREQUENCY);
+ is31fl3746a_write_register(addr, IS31FL3746A_FUNCTION_REG_CONFIGURATION, IS31FL3746A_CONFIGURATION);
+
+ // Wait 10ms to ensure the device has woken up.
+ wait_ms(10);
+}
+
+void is31fl3746a_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+ is31fl3746a_led_t led;
+
+ if (index >= 0 && index < IS31FL3746A_LED_COUNT) {
+ memcpy_P(&led, (&g_is31fl3746a_leds[index]), sizeof(led));
+
+ if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) {
+ return;
+ }
+
+ g_pwm_buffer_update_required[led.driver] = true;
+ g_pwm_buffer[led.driver][led.r] = red;
+ g_pwm_buffer[led.driver][led.g] = green;
+ g_pwm_buffer[led.driver][led.b] = blue;
+ }
+}
+
+void is31fl3746a_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+ for (int i = 0; i < IS31FL3746A_LED_COUNT; i++) {
+ is31fl3746a_set_color(i, red, green, blue);
+ }
+}
+
+void is31fl3746a_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue) {
+ is31fl3746a_led_t led;
+ memcpy_P(&led, (&g_is31fl3746a_leds[index]), sizeof(led));
+
+ g_scaling_registers[led.driver][led.r] = red;
+ g_scaling_registers[led.driver][led.g] = green;
+ g_scaling_registers[led.driver][led.b] = blue;
+ g_scaling_registers_update_required[led.driver] = true;
+}
+
+void is31fl3746a_update_pwm_buffers(uint8_t addr, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
+ is31fl3746a_select_page(addr, IS31FL3746A_COMMAND_PWM);
+
+ is31fl3746a_write_pwm_buffer(addr, index);
+
+ g_pwm_buffer_update_required[index] = false;
+ }
+}
+
+void is31fl3746a_update_scaling_registers(uint8_t addr, uint8_t index) {
+ if (g_scaling_registers_update_required[index]) {
+ is31fl3746a_select_page(addr, IS31FL3746A_COMMAND_SCALING);
+
+ for (uint8_t i = 0; i < IS31FL3746A_SCALING_REGISTER_COUNT; i++) {
+ is31fl3746a_write_register(addr, i + 1, g_scaling_registers[index][i]);
+ }
+
+ g_scaling_registers_update_required[index] = false;
+ }
+}
+
+void is31fl3746a_flush(void) {
+ is31fl3746a_update_pwm_buffers(IS31FL3746A_I2C_ADDRESS_1, 0);
+#if defined(IS31FL3746A_I2C_ADDRESS_2)
+ is31fl3746a_update_pwm_buffers(IS31FL3746A_I2C_ADDRESS_2, 1);
+# if defined(IS31FL3746A_I2C_ADDRESS_3)
+ is31fl3746a_update_pwm_buffers(IS31FL3746A_I2C_ADDRESS_3, 2);
+# if defined(IS31FL3746A_I2C_ADDRESS_4)
+ is31fl3746a_update_pwm_buffers(IS31FL3746A_I2C_ADDRESS_4, 3);
+# endif
+# endif
+#endif
+}
diff --git a/drivers/led/issi/is31fl3746a.h b/drivers/led/issi/is31fl3746a.h
new file mode 100644
index 0000000000..32647a37bd
--- /dev/null
+++ b/drivers/led/issi/is31fl3746a.h
@@ -0,0 +1,203 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ * Copyright 2021 MasterSpoon
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <stdbool.h>
+#include "progmem.h"
+#include "util.h"
+
+#define IS31FL3746A_REG_ID 0xFC
+
+#define IS31FL3746A_REG_COMMAND 0xFD
+
+#define IS31FL3746A_COMMAND_PWM 0x00
+#define IS31FL3746A_COMMAND_SCALING 0x01
+#define IS31FL3746A_COMMAND_FUNCTION 0x01
+
+#define IS31FL3746A_FUNCTION_REG_CONFIGURATION 0x50
+#define IS31FL3746A_FUNCTION_REG_GLOBAL_CURRENT 0x51
+#define IS31FL3746A_FUNCTION_REG_PULLDOWNUP 0x52
+#define IS31FL3746A_FUNCTION_REG_TEMPERATURE 0x5F
+#define IS31FL3746A_FUNCTION_REG_SPREAD_SPECTRUM 0x60
+#define IS31FL3746A_FUNCTION_REG_RESET 0x8F
+#define IS31FL3746A_FUNCTION_REG_PWM_ENABLE 0xE0
+#define IS31FL3746A_FUNCTION_REG_PWM_FREQUENCY 0xE2
+
+#define IS31FL3746A_REG_COMMAND_WRITE_LOCK 0xFE
+#define IS31FL3746A_COMMAND_WRITE_LOCK_MAGIC 0xC5
+
+#define IS31FL3746A_I2C_ADDRESS_GND_GND 0x60
+#define IS31FL3746A_I2C_ADDRESS_GND_SCL 0x61
+#define IS31FL3746A_I2C_ADDRESS_GND_SDA 0x62
+#define IS31FL3746A_I2C_ADDRESS_GND_VCC 0x63
+#define IS31FL3746A_I2C_ADDRESS_SCL_GND 0x64
+#define IS31FL3746A_I2C_ADDRESS_SCL_SCL 0x65
+#define IS31FL3746A_I2C_ADDRESS_SCL_SDA 0x66
+#define IS31FL3746A_I2C_ADDRESS_SCL_VCC 0x67
+#define IS31FL3746A_I2C_ADDRESS_SDA_GND 0x68
+#define IS31FL3746A_I2C_ADDRESS_SDA_SCL 0x69
+#define IS31FL3746A_I2C_ADDRESS_SDA_SDA 0x6A
+#define IS31FL3746A_I2C_ADDRESS_SDA_VCC 0x6B
+#define IS31FL3746A_I2C_ADDRESS_VCC_GND 0x6C
+#define IS31FL3746A_I2C_ADDRESS_VCC_SCL 0x6D
+#define IS31FL3746A_I2C_ADDRESS_VCC_SDA 0x6E
+#define IS31FL3746A_I2C_ADDRESS_VCC_VCC 0x6F
+
+#if defined(RGB_MATRIX_IS31FL3746A)
+# define IS31FL3746A_LED_COUNT RGB_MATRIX_LED_COUNT
+#endif
+
+#if defined(IS31FL3746A_I2C_ADDRESS_4)
+# define IS31FL3746A_DRIVER_COUNT 4
+#elif defined(IS31FL3746A_I2C_ADDRESS_3)
+# define IS31FL3746A_DRIVER_COUNT 3
+#elif defined(IS31FL3746A_I2C_ADDRESS_2)
+# define IS31FL3746A_DRIVER_COUNT 2
+#elif defined(IS31FL3746A_I2C_ADDRESS_1)
+# define IS31FL3746A_DRIVER_COUNT 1
+#endif
+
+typedef struct is31fl3746a_led_t {
+ uint8_t driver : 2;
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+} PACKED is31fl3746a_led_t;
+
+extern const is31fl3746a_led_t PROGMEM g_is31fl3746a_leds[IS31FL3746A_LED_COUNT];
+
+void is31fl3746a_init_drivers(void);
+void is31fl3746a_init(uint8_t addr);
+void is31fl3746a_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void is31fl3746a_select_page(uint8_t addr, uint8_t page);
+
+void is31fl3746a_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void is31fl3746a_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
+
+void is31fl3746a_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue);
+
+void is31fl3746a_update_pwm_buffers(uint8_t addr, uint8_t index);
+void is31fl3746a_update_scaling_registers(uint8_t addr, uint8_t index);
+
+void is31fl3746a_flush(void);
+
+#define IS31FL3746A_PDR_0_OHM 0b000 // No pull-down resistor
+#define IS31FL3746A_PDR_0K5_OHM_SW_OFF 0b001 // 0.5 kOhm resistor in SWx off time
+#define IS31FL3746A_PDR_1K_OHM_SW_OFF 0b010 // 1 kOhm resistor in SWx off time
+#define IS31FL3746A_PDR_2K_OHM_SW_OFF 0b011 // 2 kOhm resistor in SWx off time
+#define IS31FL3746A_PDR_1K_OHM 0b100 // 1 kOhm resistor
+#define IS31FL3746A_PDR_2K_OHM 0b101 // 2 kOhm resistor
+#define IS31FL3746A_PDR_4K_OHM 0b110 // 4 kOhm resistor
+#define IS31FL3746A_PDR_8K_OHM 0b111 // 8 kOhm resistor
+
+#define IS31FL3746A_PUR_0_OHM 0b000 // No pull-up resistor
+#define IS31FL3746A_PUR_0K5_OHM_CS_OFF 0b001 // 0.5 kOhm resistor in CSy off time
+#define IS31FL3746A_PUR_1K_OHM_CS_OFF 0b010 // 1 kOhm resistor in CSy off time
+#define IS31FL3746A_PUR_2K_OHM_CS_OFF 0b011 // 2 kOhm resistor in CSy off time
+#define IS31FL3746A_PUR_1K_OHM 0b100 // 1 kOhm resistor
+#define IS31FL3746A_PUR_2K_OHM 0b101 // 2 kOhm resistor
+#define IS31FL3746A_PUR_4K_OHM 0b110 // 4 kOhm resistor
+#define IS31FL3746A_PUR_8K_OHM 0b111 // 8 kOhm resistor
+
+#define IS31FL3746A_PWM_FREQUENCY_29K_HZ 0b000
+#define IS31FL3746A_PWM_FREQUENCY_14K5_HZ 0b001
+#define IS31FL3746A_PWM_FREQUENCY_7K25_HZ 0b010
+#define IS31FL3746A_PWM_FREQUENCY_3K63_HZ 0b011
+#define IS31FL3746A_PWM_FREQUENCY_1K81_HZ 0b100
+#define IS31FL3746A_PWM_FREQUENCY_906_HZ 0b101
+#define IS31FL3746A_PWM_FREQUENCY_453_HZ 0b110
+
+#define CS1_SW1 0x00
+#define CS2_SW1 0x01
+#define CS3_SW1 0x02
+#define CS4_SW1 0x03
+#define CS5_SW1 0x04
+#define CS6_SW1 0x05
+#define CS7_SW1 0x06
+#define CS8_SW1 0x07
+#define CS9_SW1 0x08
+#define CS10_SW1 0x09
+#define CS11_SW1 0x0A
+#define CS12_SW1 0x0B
+#define CS13_SW1 0x0C
+#define CS14_SW1 0x0D
+#define CS15_SW1 0x0E
+#define CS16_SW1 0x0F
+#define CS17_SW1 0x10
+#define CS18_SW1 0x11
+
+#define CS1_SW2 0x12
+#define CS2_SW2 0x13
+#define CS3_SW2 0x14
+#define CS4_SW2 0x15
+#define CS5_SW2 0x16
+#define CS6_SW2 0x17
+#define CS7_SW2 0x18
+#define CS8_SW2 0x19
+#define CS9_SW2 0x1A
+#define CS10_SW2 0x1B
+#define CS11_SW2 0x1C
+#define CS12_SW2 0x1D
+#define CS13_SW2 0x1E
+#define CS14_SW2 0x1F
+#define CS15_SW2 0x20
+#define CS16_SW2 0x21
+#define CS17_SW2 0x22
+#define CS18_SW2 0x23
+
+#define CS1_SW3 0x24
+#define CS2_SW3 0x25
+#define CS3_SW3 0x26
+#define CS4_SW3 0x27
+#define CS5_SW3 0x28
+#define CS6_SW3 0x29
+#define CS7_SW3 0x2A
+#define CS8_SW3 0x2B
+#define CS9_SW3 0x2C
+#define CS10_SW3 0x2D
+#define CS11_SW3 0x2E
+#define CS12_SW3 0x2F
+#define CS13_SW3 0x30
+#define CS14_SW3 0x31
+#define CS15_SW3 0x32
+#define CS16_SW3 0x33
+#define CS17_SW3 0x34
+#define CS18_SW3 0x35
+
+#define CS1_SW4 0x36
+#define CS2_SW4 0x37
+#define CS3_SW4 0x38
+#define CS4_SW4 0x39
+#define CS5_SW4 0x3A
+#define CS6_SW4 0x3B
+#define CS7_SW4 0x3C
+#define CS8_SW4 0x3D
+#define CS9_SW4 0x3E
+#define CS10_SW4 0x3F
+#define CS11_SW4 0x40
+#define CS12_SW4 0x41
+#define CS13_SW4 0x42
+#define CS14_SW4 0x43
+#define CS15_SW4 0x44
+#define CS16_SW4 0x45
+#define CS17_SW4 0x46
+#define CS18_SW4 0x47
diff --git a/drivers/led/issi/is31flcommon.c b/drivers/led/issi/is31flcommon.c
deleted file mode 100644
index d6b9bce93d..0000000000
--- a/drivers/led/issi/is31flcommon.c
+++ /dev/null
@@ -1,330 +0,0 @@
-/* Copyright 2017 Jason Williams
- * Copyright 2018 Jack Humbert
- * Copyright 2018 Yiancar
- * Copyright 2020 MelGeek
- * Copyright 2021 MasterSpoon
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "is31flcommon.h"
-#include "i2c_master.h"
-#include "wait.h"
-#include <string.h>
-
-// Set defaults for Timeout and Persistence
-#ifndef ISSI_TIMEOUT
-# define ISSI_TIMEOUT 100
-#endif
-#ifndef ISSI_PERSISTENCE
-# define ISSI_PERSISTENCE 0
-#endif
-
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
-// These buffers match the PWM & scaling registers.
-// Storing them like this is optimal for I2C transfers to the registers.
-uint8_t g_pwm_buffer[DRIVER_COUNT][ISSI_MAX_LEDS];
-bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
-
-uint8_t g_scaling_buffer[DRIVER_COUNT][ISSI_SCALING_SIZE];
-bool g_scaling_buffer_update_required[DRIVER_COUNT] = {false};
-
-// For writing of single register entry
-void IS31FL_write_single_register(uint8_t addr, uint8_t reg, uint8_t data) {
- // Set register address and register data ready to write
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
- }
-#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
-#endif
-}
-
-// For writing of mulitple register entries to make use of address auto increment
-// Once the controller has been called and we have written the first bit of data
-// the controller will move to the next register meaning we can write sequential blocks.
-bool IS31FL_write_multi_registers(uint8_t addr, uint8_t *source_buffer, uint8_t buffer_size, uint8_t transfer_size, uint8_t start_reg_addr) {
- // Split the buffer into chunks to transfer
- for (int i = 0; i < buffer_size; i += transfer_size) {
- // Set the first entry of transfer buffer to the first register we want to write
- g_twi_transfer_buffer[0] = i + start_reg_addr;
- // Copy the section of our source buffer into the transfer buffer after first register address
- memcpy(g_twi_transfer_buffer + 1, source_buffer + i, transfer_size);
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, transfer_size + 1, ISSI_TIMEOUT) != 0) {
- return false;
- }
- }
-#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, transfer_size + 1, ISSI_TIMEOUT) != 0) {
- return false;
- }
-#endif
- }
- return true;
-}
-
-void IS31FL_unlock_register(uint8_t addr, uint8_t page) {
- // unlock the command register and select Page to write
- IS31FL_write_single_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, ISSI_REGISTER_UNLOCK);
- IS31FL_write_single_register(addr, ISSI_COMMANDREGISTER, page);
-}
-
-void IS31FL_common_init(uint8_t addr, uint8_t ssr) {
- // Setup phase, need to take out of software shutdown and configure
- // ISSI_SSR_x is passed to allow Master / Slave setting where applicable
-
- // Unlock the command register & select Function Register
- IS31FL_unlock_register(addr, ISSI_PAGE_FUNCTION);
- // Set Configuration Register to remove Software shutdown
- IS31FL_write_single_register(addr, ISSI_REG_CONFIGURATION, ISSI_CONFIGURATION);
- // Set Golbal Current Control Register
- IS31FL_write_single_register(addr, ISSI_REG_GLOBALCURRENT, ISSI_GLOBALCURRENT);
- // Set Pull up & Down for SWx CSy
- IS31FL_write_single_register(addr, ISSI_REG_PULLDOWNUP, ISSI_PULLDOWNUP);
-// Set Tempature Status
-#ifdef ISSI_REG_TEMP
- IS31FL_write_single_register(addr, ISSI_REG_TEMP, ISSI_TEMP);
-#endif
- // Set Spread Spectrum Register, passed through as sets SYNC function
- IS31FL_write_single_register(addr, ISSI_REG_SSR, ssr);
-// Set PWM Frequency Enable Register if applicable
-#ifdef ISSI_REG_PWM_ENABLE
- IS31FL_write_single_register(addr, ISSI_REG_PWM_ENABLE, ISSI_PWM_ENABLE);
-#endif
-// Set PWM Frequency Register if applicable
-#ifdef ISSI_REG_PWM_SET
- IS31FL_write_single_register(addr, ISSI_REG_PWM_SET, ISSI_PWM_SET);
-#endif
-
- // Wait 10ms to ensure the device has woken up.
- wait_ms(10);
-}
-
-void IS31FL_common_update_pwm_register(uint8_t addr, uint8_t index) {
- if (g_pwm_buffer_update_required[index]) {
- // Queue up the correct page
- IS31FL_unlock_register(addr, ISSI_PAGE_PWM);
- // Hand off the update to IS31FL_write_multi_registers
- IS31FL_write_multi_registers(addr, g_pwm_buffer[index], ISSI_MAX_LEDS, ISSI_PWM_TRF_SIZE, ISSI_PWM_REG_1ST);
- // Update flags that pwm_buffer has been updated
- g_pwm_buffer_update_required[index] = false;
- }
-}
-
-#ifdef ISSI_MANUAL_SCALING
-void IS31FL_set_manual_scaling_buffer(void) {
- is31_led led;
- is31_led scale;
- for (int i = 0; i < ISSI_MANUAL_SCALING; i++) {
- memcpy_P(&scale, (&g_is31_scaling[i]), sizeof(scale));
-
-# ifdef RGB_MATRIX_ENABLE
- if (scale.driver >= 0 && scale.driver < RGB_MATRIX_LED_COUNT) {
- memcpy_P(&led, (&g_is31_leds[scale.driver]), sizeof(led));
-
- if (g_scaling_buffer[led.driver][led.r] = scale.r && g_scaling_buffer[led.driver][led.g] = scale.g && g_scaling_buffer[led.driver][led.b] = scale.b) {
- return;
- }
- g_scaling_buffer[led.driver][led.r] = scale.r;
- g_scaling_buffer[led.driver][led.g] = scale.g;
- g_scaling_buffer[led.driver][led.b] = scale.b;
-# elif defined(LED_MATRIX_ENABLE)
- if (scale.driver >= 0 && scale.driver < LED_MATRIX_LED_COUNT) {
- memcpy_P(&led, (&g_is31_leds[scale.driver]), sizeof(led));
-
- if (g_scaling_buffer[led.driver][led.v] == scale.v) {
- return;
- }
- g_scaling_buffer[led.driver][led.v] = scale.v;
-# endif
- g_scaling_buffer_update_required[led.driver] = true;
- }
- }
-}
-#endif
-
-void IS31FL_common_update_scaling_register(uint8_t addr, uint8_t index) {
- if (g_scaling_buffer_update_required[index]) {
- // Queue up the correct page
- IS31FL_unlock_register(addr, ISSI_PAGE_SCALING);
- // Hand off the update to IS31FL_write_multi_registers
- IS31FL_write_multi_registers(addr, g_scaling_buffer[index], ISSI_SCALING_SIZE, ISSI_SCALING_TRF_SIZE, ISSI_SCL_REG_1ST);
- // Update flags that scaling_buffer has been updated
- g_scaling_buffer_update_required[index] = false;
- }
-}
-
-void IS31FL_common_flush(void) {
- IS31FL_common_update_pwm_register(DRIVER_ADDR_1, 0);
-#if defined(DRIVER_ADDR_2)
- IS31FL_common_update_pwm_register(DRIVER_ADDR_2, 1);
-# if defined(DRIVER_ADDR_3)
- IS31FL_common_update_pwm_register(DRIVER_ADDR_3, 2);
-# if defined(DRIVER_ADDR_4)
- IS31FL_common_update_pwm_register(DRIVER_ADDR_4, 3);
-# endif
-# endif
-#endif
-}
-
-#ifdef RGB_MATRIX_ENABLE
-void IS31FL_RGB_init_drivers(void) {
- i2c_init();
-
- IS31FL_common_init(DRIVER_ADDR_1, ISSI_SSR_1);
-# if defined(DRIVER_ADDR_2)
- IS31FL_common_init(DRIVER_ADDR_2, ISSI_SSR_2);
-# if defined(DRIVER_ADDR_3)
- IS31FL_common_init(DRIVER_ADDR_3, ISSI_SSR_3);
-# if defined(DRIVER_ADDR_4)
- IS31FL_common_init(DRIVER_ADDR_4, ISSI_SSR_4);
-# endif
-# endif
-# endif
-
- for (int i = 0; i < RGB_MATRIX_LED_COUNT; i++) {
- IS31FL_RGB_set_scaling_buffer(i, true, true, true);
- }
-
- // This actually updates the LED drivers
-# ifdef ISSI_MANUAL_SCALING
- IS31FL_set_manual_scaling_buffer();
-# endif
-
- IS31FL_common_update_scaling_register(DRIVER_ADDR_1, 0);
-# if defined(DRIVER_ADDR_2)
- IS31FL_common_update_scaling_register(DRIVER_ADDR_2, 1);
-# if defined(DRIVER_ADDR_3)
- IS31FL_common_update_scaling_register(DRIVER_ADDR_3, 2);
-# if defined(DRIVER_ADDR_4)
- IS31FL_common_update_scaling_register(DRIVER_ADDR_4, 3);
-# endif
-# endif
-# endif
-}
-
-// Colour is set by adjusting PWM register
-void IS31FL_RGB_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
- if (index >= 0 && index < RGB_MATRIX_LED_COUNT) {
- is31_led led;
- memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
-
- g_pwm_buffer[led.driver][led.r] = red;
- g_pwm_buffer[led.driver][led.g] = green;
- g_pwm_buffer[led.driver][led.b] = blue;
- g_pwm_buffer_update_required[led.driver] = true;
- }
-}
-
-void IS31FL_RGB_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
- for (int i = 0; i < RGB_MATRIX_LED_COUNT; i++) {
- IS31FL_RGB_set_color(i, red, green, blue);
- }
-}
-
-// Setup Scaling register that decides the peak current of each LED
-void IS31FL_RGB_set_scaling_buffer(uint8_t index, bool red, bool green, bool blue) {
- is31_led led;
- memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
- if (red) {
- g_scaling_buffer[led.driver][led.r] = ISSI_SCAL_RED;
- } else {
- g_scaling_buffer[led.driver][led.r] = ISSI_SCAL_RED_OFF;
- }
- if (green) {
- g_scaling_buffer[led.driver][led.g] = ISSI_SCAL_GREEN;
- } else {
- g_scaling_buffer[led.driver][led.g] = ISSI_SCAL_GREEN_OFF;
- }
- if (blue) {
- g_scaling_buffer[led.driver][led.b] = ISSI_SCAL_BLUE;
- } else {
- g_scaling_buffer[led.driver][led.b] = ISSI_SCAL_BLUE_OFF;
- }
- g_scaling_buffer_update_required[led.driver] = true;
-}
-
-#elif defined(LED_MATRIX_ENABLE)
-// LED Matrix Specific scripts
-void IS31FL_simple_init_drivers(void) {
- i2c_init();
-
- IS31FL_common_init(DRIVER_ADDR_1, ISSI_SSR_1);
-# if defined(DRIVER_ADDR_2)
- IS31FL_common_init(DRIVER_ADDR_2, ISSI_SSR_2);
-# if defined(DRIVER_ADDR_3)
- IS31FL_common_init(DRIVER_ADDR_3, ISSI_SSR_3);
-# if defined(DRIVER_ADDR_4)
- IS31FL_common_init(DRIVER_ADDR_4, ISSI_SSR_4);
-# endif
-# endif
-# endif
-
- for (int i = 0; i < LED_MATRIX_LED_COUNT; i++) {
- IS31FL_simple_set_scaling_buffer(i, true);
- }
-
-// This actually updates the LED drivers
-# ifdef ISSI_MANUAL_SCALING
- IS31FL_set_manual_scaling_buffer();
-# endif
-
- IS31FL_common_update_scaling_register(DRIVER_ADDR_1, 0);
-# if defined(DRIVER_ADDR_2)
- IS31FL_common_update_scaling_register(DRIVER_ADDR_2, 1);
-# if defined(DRIVER_ADDR_3)
- IS31FL_common_update_scaling_register(DRIVER_ADDR_3, 2);
-# if defined(DRIVER_ADDR_4)
- IS31FL_common_update_scaling_register(DRIVER_ADDR_4, 3);
-# endif
-# endif
-# endif
-}
-
-void IS31FL_simple_set_scaling_buffer(uint8_t index, bool value) {
- is31_led led;
- memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
- if (value) {
- g_scaling_buffer[led.driver][led.v] = ISSI_SCAL_LED;
- } else {
- g_scaling_buffer[led.driver][led.v] = ISSI_SCAL_LED_OFF;
- }
- g_scaling_buffer_update_required[led.driver] = true;
-}
-
-void IS31FL_simple_set_brightness(int index, uint8_t value) {
- if (index >= 0 && index < LED_MATRIX_LED_COUNT) {
- is31_led led;
- memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
-
- g_pwm_buffer[led.driver][led.v] = value;
- g_pwm_buffer_update_required[led.driver] = true;
- }
-}
-
-void IS31FL_simple_set_brigntness_all(uint8_t value) {
- for (int i = 0; i < LED_MATRIX_LED_COUNT; i++) {
- IS31FL_simple_set_brightness(i, value);
- }
-}
-#endif
diff --git a/drivers/led/issi/is31flcommon.h b/drivers/led/issi/is31flcommon.h
deleted file mode 100644
index 10613a6eed..0000000000
--- a/drivers/led/issi/is31flcommon.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/* Copyright 2017 Jason Williams
- * Copyright 2018 Jack Humbert
- * Copyright 2018 Yiancar
- * Copyright 2020 MelGeek
- * Copyright 2021 MasterSpoon
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-#include <stdint.h>
-#include <stdbool.h>
-#include "progmem.h"
-#include "util.h"
-
-// Which variant header file to use
-#if defined(LED_MATRIX_IS31FL3742A) || defined(RGB_MATRIX_IS31FL3742A)
-# include "is31fl3742.h"
-#elif defined(LED_MATRIX_IS31FL3743A) || defined(RGB_MATRIX_IS31FL3743A)
-# include "is31fl3743.h"
-#elif defined(LED_MATRIX_IS31FL3745) || defined(RGB_MATRIX_IS31FL3745)
-# include "is31fl3745.h"
-#elif defined(LED_MATRIX_IS31FL3746A) || defined(RGB_MATRIX_IS31FL3746A)
-# include "is31fl3746.h"
-#endif
-
-#if defined DRIVER_ADDR_4
-# define DRIVER_COUNT 4
-#elif defined DRIVER_ADDR_3
-# define DRIVER_COUNT 3
-#elif defined DRIVER_ADDR_2
-# define DRIVER_COUNT 2
-#elif defined DRIVER_ADDR_1
-# define DRIVER_COUNT 1
-#endif
-
-#ifdef RGB_MATRIX_ENABLE
-typedef struct is31_led {
- uint8_t driver : 2;
- uint8_t r;
- uint8_t g;
- uint8_t b;
-} PACKED is31_led;
-
-extern const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT];
-
-#elif defined(LED_MATRIX_ENABLE)
-typedef struct is31_led {
- uint8_t driver : 2;
- uint8_t v;
-} PACKED is31_led;
-
-extern const is31_led PROGMEM g_is31_leds[LED_MATRIX_LED_COUNT];
-#endif
-
-#ifdef ISSI_MANUAL_SCALING
-extern const is31_led PROGMEM g_is31_scaling[];
-void IS31FL_set_manual_scaling_buffer(void);
-#endif
-
-void IS31FL_write_single_register(uint8_t addr, uint8_t reg, uint8_t data);
-bool IS31FL_write_multi_registers(uint8_t addr, uint8_t *source_buffer, uint8_t buffer_size, uint8_t transfer_size, uint8_t start_reg_addr);
-void IS31FL_unlock_register(uint8_t addr, uint8_t page);
-void IS31FL_common_init(uint8_t addr, uint8_t ssr);
-
-void IS31FL_common_update_pwm_register(uint8_t addr, uint8_t index);
-void IS31FL_common_update_scaling_register(uint8_t addr, uint8_t index);
-
-void IS31FL_common_flush(void);
-
-#ifdef RGB_MATRIX_ENABLE
-// RGB Matrix Specific scripts
-void IS31FL_RGB_init_drivers(void);
-void IS31FL_RGB_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
-void IS31FL_RGB_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
-void IS31FL_RGB_set_scaling_buffer(uint8_t index, bool red, bool green, bool blue);
-#elif defined(LED_MATRIX_ENABLE)
-// LED Matrix Specific scripts
-void IS31FL_simple_init_drivers(void);
-void IS31FL_simple_set_scaling_buffer(uint8_t index, bool value);
-void IS31FL_simple_set_brightness(int index, uint8_t value);
-void IS31FL_simple_set_brigntness_all(uint8_t value);
-#endif
diff --git a/drivers/led/snled27351-simple.c b/drivers/led/snled27351-mono.c
index b2054c96d5..854d21d3dc 100644
--- a/drivers/led/snled27351-simple.c
+++ b/drivers/led/snled27351-mono.c
@@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "snled27351-simple.h"
+#include "snled27351-mono.h"
#include "i2c_master.h"
#define SNLED27351_PWM_REGISTER_COUNT 192
@@ -37,9 +37,6 @@
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
#endif
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
// These buffers match the SNLED27351 PWM registers.
// The control buffers match the PG0 LED On/Off registers.
// Storing them like this is optimal for I2C transfers to the registers.
@@ -52,54 +49,34 @@ bool g_pwm_buffer_update_required[SNLED27351_DRIVER_COUNT] = {false};
uint8_t g_led_control_registers[SNLED27351_DRIVER_COUNT][SNLED27351_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required[SNLED27351_DRIVER_COUNT] = {false};
-bool snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- // If the transaction fails function returns false.
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
+void snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
#if SNLED27351_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < SNLED27351_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, SNLED27351_I2C_TIMEOUT) != 0) {
- return false;
- }
+ if (i2c_write_register(addr << 1, reg, &data, 1, SNLED27351_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, SNLED27351_I2C_TIMEOUT) != 0) {
- return false;
- }
+ i2c_write_register(addr << 1, reg, &data, 1, SNLED27351_I2C_TIMEOUT);
#endif
- return true;
}
-bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
+void snled27351_select_page(uint8_t addr, uint8_t page) {
+ snled27351_write_register(addr, SNLED27351_REG_COMMAND, page);
+}
+
+void snled27351_write_pwm_buffer(uint8_t addr, uint8_t index) {
// Assumes PG1 is already selected.
- // If any of the transactions fails function returns false.
// Transmit PWM registers in 12 transfers of 16 bytes.
- // g_twi_transfer_buffer[] is 20 bytes
// Iterate over the pwm_buffer contents at 16 byte intervals.
- for (int i = 0; i < SNLED27351_PWM_REGISTER_COUNT; i += 16) {
- g_twi_transfer_buffer[0] = i;
- // Copy the data from i to i+15.
- // Device will auto-increment register for data after the first byte
- // Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer.
- for (int j = 0; j < 16; j++) {
- g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
- }
-
+ for (uint8_t i = 0; i < SNLED27351_PWM_REGISTER_COUNT; i += 16) {
#if SNLED27351_I2C_PERSISTENCE > 0
- for (uint8_t i = 0; i < SNLED27351_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, SNLED27351_I2C_TIMEOUT) != 0) {
- return false;
- }
+ for (uint8_t j = 0; j < SNLED27351_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, SNLED27351_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, SNLED27351_I2C_TIMEOUT) != 0) {
- return false;
- }
+ i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, SNLED27351_I2C_TIMEOUT);
#endif
}
- return true;
}
void snled27351_init_drivers(void) {
@@ -133,8 +110,8 @@ void snled27351_init_drivers(void) {
}
void snled27351_init(uint8_t addr) {
- // Select to function page
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_FUNCTION);
+ snled27351_select_page(addr, SNLED27351_COMMAND_FUNCTION);
+
// Setting LED driver to shutdown mode
snled27351_write_register(addr, SNLED27351_FUNCTION_REG_SOFTWARE_SHUTDOWN, SNLED27351_SOFTWARE_SHUTDOWN_SSD_SHUTDOWN);
// Setting internal channel pulldown/pullup
@@ -147,33 +124,34 @@ void snled27351_init(uint8_t addr) {
snled27351_write_register(addr, SNLED27351_FUNCTION_REG_SLEW_RATE_CONTROL_MODE_2, SNLED27351_SLEW_RATE_CONTROL_MODE_2_DSL_ENABLE | SNLED27351_SLEW_RATE_CONTROL_MODE_2_SSL_ENABLE);
// Setting Iref
snled27351_write_register(addr, SNLED27351_FUNCTION_REG_SOFTWARE_SLEEP, 0);
- // Set LED CONTROL PAGE (Page 0)
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_LED_CONTROL);
+
+ snled27351_select_page(addr, SNLED27351_COMMAND_LED_CONTROL);
+
for (int i = 0; i < SNLED27351_LED_CONTROL_ON_OFF_LENGTH; i++) {
snled27351_write_register(addr, i, 0x00);
}
- // Set PWM PAGE (Page 1)
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_PWM);
+ snled27351_select_page(addr, SNLED27351_COMMAND_PWM);
+
for (int i = 0; i < SNLED27351_LED_CURRENT_TUNE_LENGTH; i++) {
snled27351_write_register(addr, i, 0x00);
}
- // Set CURRENT PAGE (Page 4)
+ snled27351_select_page(addr, SNLED27351_COMMAND_CURRENT_TUNE);
+
uint8_t current_tune_reg_list[SNLED27351_LED_CURRENT_TUNE_LENGTH] = SNLED27351_CURRENT_TUNE;
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_CURRENT_TUNE);
for (int i = 0; i < SNLED27351_LED_CURRENT_TUNE_LENGTH; i++) {
snled27351_write_register(addr, i, current_tune_reg_list[i]);
}
- // Enable LEDs ON/OFF
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_LED_CONTROL);
+ snled27351_select_page(addr, SNLED27351_COMMAND_LED_CONTROL);
+
for (int i = 0; i < SNLED27351_LED_CONTROL_ON_OFF_LENGTH; i++) {
snled27351_write_register(addr, i, 0xFF);
}
- // Select to function page
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_FUNCTION);
+ snled27351_select_page(addr, SNLED27351_COMMAND_FUNCTION);
+
// Setting LED driver to normal mode
snled27351_write_register(addr, SNLED27351_FUNCTION_REG_SOFTWARE_SHUTDOWN, SNLED27351_SOFTWARE_SHUTDOWN_SSD_NORMAL);
}
@@ -186,6 +164,7 @@ void snled27351_set_value(int index, uint8_t value) {
if (g_pwm_buffer[led.driver][led.v] == value) {
return;
}
+
g_pwm_buffer[led.driver][led.v] = value;
g_pwm_buffer_update_required[led.driver] = true;
}
@@ -215,25 +194,24 @@ void snled27351_set_led_control_register(uint8_t index, bool value) {
void snled27351_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_PWM);
+ snled27351_select_page(addr, SNLED27351_COMMAND_PWM);
- // If any of the transactions fail we risk writing dirty PG0,
- // refresh page 0 just in case.
- if (!snled27351_write_pwm_buffer(addr, g_pwm_buffer[index])) {
- g_led_control_registers_update_required[index] = true;
- }
+ snled27351_write_pwm_buffer(addr, index);
+
+ g_pwm_buffer_update_required[index] = false;
}
- g_pwm_buffer_update_required[index] = false;
}
void snled27351_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_LED_CONTROL);
- for (int i = 0; i < SNLED27351_LED_CONTROL_REGISTER_COUNT; i++) {
+ snled27351_select_page(addr, SNLED27351_COMMAND_LED_CONTROL);
+
+ for (uint8_t i = 0; i < SNLED27351_LED_CONTROL_REGISTER_COUNT; i++) {
snled27351_write_register(addr, i, g_led_control_registers[index][i]);
}
+
+ g_led_control_registers_update_required[index] = false;
}
- g_led_control_registers_update_required[index] = false;
}
void snled27351_flush(void) {
@@ -250,15 +228,15 @@ void snled27351_flush(void) {
}
void snled27351_sw_return_normal(uint8_t addr) {
- // Select to function page
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_FUNCTION);
+ snled27351_select_page(addr, SNLED27351_COMMAND_FUNCTION);
+
// Setting LED driver to normal mode
snled27351_write_register(addr, SNLED27351_FUNCTION_REG_SOFTWARE_SHUTDOWN, SNLED27351_SOFTWARE_SHUTDOWN_SSD_NORMAL);
}
void snled27351_sw_shutdown(uint8_t addr) {
- // Select to function page
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_FUNCTION);
+ snled27351_select_page(addr, SNLED27351_COMMAND_FUNCTION);
+
// Setting LED driver to shutdown mode
snled27351_write_register(addr, SNLED27351_FUNCTION_REG_SOFTWARE_SHUTDOWN, SNLED27351_SOFTWARE_SHUTDOWN_SSD_SHUTDOWN);
// Write SW Sleep Register
diff --git a/drivers/led/snled27351-simple.h b/drivers/led/snled27351-mono.h
index 2fc62a6f0a..3a22115623 100644
--- a/drivers/led/snled27351-simple.h
+++ b/drivers/led/snled27351-mono.h
@@ -155,8 +155,8 @@ extern const snled27351_led_t PROGMEM g_snled27351_leds[SNLED27351_LED_COUNT];
void snled27351_init_drivers(void);
void snled27351_init(uint8_t addr);
-bool snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+void snled27351_select_page(uint8_t addr, uint8_t page);
+void snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data);
void snled27351_set_value(int index, uint8_t value);
void snled27351_set_value_all(uint8_t value);
diff --git a/drivers/led/snled27351.c b/drivers/led/snled27351.c
index 71992b7322..662335afd2 100644
--- a/drivers/led/snled27351.c
+++ b/drivers/led/snled27351.c
@@ -37,9 +37,6 @@
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
#endif
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[65];
-
// These buffers match the SNLED27351 PWM registers.
// The control buffers match the PG0 LED On/Off registers.
// Storing them like this is optimal for I2C transfers to the registers.
@@ -52,53 +49,34 @@ bool g_pwm_buffer_update_required[SNLED27351_DRIVER_COUNT] = {false};
uint8_t g_led_control_registers[SNLED27351_DRIVER_COUNT][SNLED27351_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required[SNLED27351_DRIVER_COUNT] = {false};
-bool snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- // If the transaction fails function returns false.
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
+void snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
#if SNLED27351_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < SNLED27351_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, SNLED27351_I2C_TIMEOUT) != 0) {
- return false;
- }
+ if (i2c_write_register(addr << 1, reg, &data, 1, SNLED27351_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, SNLED27351_I2C_TIMEOUT) != 0) {
- return false;
- }
+ i2c_write_register(addr << 1, reg, &data, 1, SNLED27351_I2C_TIMEOUT);
#endif
- return true;
}
-bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
+void snled27351_select_page(uint8_t addr, uint8_t page) {
+ snled27351_write_register(addr, SNLED27351_REG_COMMAND, page);
+}
+
+void snled27351_write_pwm_buffer(uint8_t addr, uint8_t index) {
// Assumes PG1 is already selected.
- // If any of the transactions fails function returns false.
- // Transmit PWM registers in 3 transfers of 64 bytes.
-
- // Iterate over the pwm_buffer contents at 64 byte intervals.
- for (uint8_t i = 0; i < SNLED27351_PWM_REGISTER_COUNT; i += 64) {
- g_twi_transfer_buffer[0] = i;
- // Copy the data from i to i+63.
- // Device will auto-increment register for data after the first byte
- // Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer.
- for (uint8_t j = 0; j < 64; j++) {
- g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
- }
+ // Transmit PWM registers in 12 transfers of 16 bytes.
+ // Iterate over the pwm_buffer contents at 16 byte intervals.
+ for (uint8_t i = 0; i < SNLED27351_PWM_REGISTER_COUNT; i += 16) {
#if SNLED27351_I2C_PERSISTENCE > 0
- for (uint8_t i = 0; i < SNLED27351_I2C_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 65, SNLED27351_I2C_TIMEOUT) != 0) {
- return false;
- }
+ for (uint8_t j = 0; j < SNLED27351_I2C_PERSISTENCE; j++) {
+ if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, SNLED27351_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 65, SNLED27351_I2C_TIMEOUT) != 0) {
- return false;
- }
+ i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, SNLED27351_I2C_TIMEOUT);
#endif
}
- return true;
}
void snled27351_init_drivers(void) {
@@ -132,8 +110,8 @@ void snled27351_init_drivers(void) {
}
void snled27351_init(uint8_t addr) {
- // Select to function page
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_FUNCTION);
+ snled27351_select_page(addr, SNLED27351_COMMAND_FUNCTION);
+
// Setting LED driver to shutdown mode
snled27351_write_register(addr, SNLED27351_FUNCTION_REG_SOFTWARE_SHUTDOWN, SNLED27351_SOFTWARE_SHUTDOWN_SSD_SHUTDOWN);
// Setting internal channel pulldown/pullup
@@ -146,33 +124,34 @@ void snled27351_init(uint8_t addr) {
snled27351_write_register(addr, SNLED27351_FUNCTION_REG_SLEW_RATE_CONTROL_MODE_2, SNLED27351_SLEW_RATE_CONTROL_MODE_2_DSL_ENABLE | SNLED27351_SLEW_RATE_CONTROL_MODE_2_SSL_ENABLE);
// Setting Iref
snled27351_write_register(addr, SNLED27351_FUNCTION_REG_SOFTWARE_SLEEP, 0);
- // Set LED CONTROL PAGE (Page 0)
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_LED_CONTROL);
+
+ snled27351_select_page(addr, SNLED27351_COMMAND_LED_CONTROL);
+
for (int i = 0; i < SNLED27351_LED_CONTROL_ON_OFF_LENGTH; i++) {
snled27351_write_register(addr, i, 0x00);
}
- // Set PWM PAGE (Page 1)
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_PWM);
+ snled27351_select_page(addr, SNLED27351_COMMAND_PWM);
+
for (int i = 0; i < SNLED27351_LED_CURRENT_TUNE_LENGTH; i++) {
snled27351_write_register(addr, i, 0x00);
}
- // Set CURRENT PAGE (Page 4)
+ snled27351_select_page(addr, SNLED27351_COMMAND_CURRENT_TUNE);
+
uint8_t current_tune_reg_list[SNLED27351_LED_CURRENT_TUNE_LENGTH] = SNLED27351_CURRENT_TUNE;
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_CURRENT_TUNE);
for (int i = 0; i < SNLED27351_LED_CURRENT_TUNE_LENGTH; i++) {
snled27351_write_register(addr, i, current_tune_reg_list[i]);
}
- // Enable LEDs ON/OFF
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_LED_CONTROL);
+ snled27351_select_page(addr, SNLED27351_COMMAND_LED_CONTROL);
+
for (int i = 0; i < SNLED27351_LED_CONTROL_ON_OFF_LENGTH; i++) {
snled27351_write_register(addr, i, 0xFF);
}
- // Select to function page
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_FUNCTION);
+ snled27351_select_page(addr, SNLED27351_COMMAND_FUNCTION);
+
// Setting LED driver to normal mode
snled27351_write_register(addr, SNLED27351_FUNCTION_REG_SOFTWARE_SHUTDOWN, SNLED27351_SOFTWARE_SHUTDOWN_SSD_NORMAL);
}
@@ -185,6 +164,7 @@ void snled27351_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
if (g_pwm_buffer[led.driver][led.r] == red && g_pwm_buffer[led.driver][led.g] == green && g_pwm_buffer[led.driver][led.b] == blue) {
return;
}
+
g_pwm_buffer[led.driver][led.r] = red;
g_pwm_buffer[led.driver][led.g] = green;
g_pwm_buffer[led.driver][led.b] = blue;
@@ -230,25 +210,24 @@ void snled27351_set_led_control_register(uint8_t index, bool red, bool green, bo
void snled27351_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_PWM);
+ snled27351_select_page(addr, SNLED27351_COMMAND_PWM);
- // If any of the transactions fail we risk writing dirty PG0,
- // refresh page 0 just in case.
- if (!snled27351_write_pwm_buffer(addr, g_pwm_buffer[index])) {
- g_led_control_registers_update_required[index] = true;
- }
+ snled27351_write_pwm_buffer(addr, index);
+
+ g_pwm_buffer_update_required[index] = false;
}
- g_pwm_buffer_update_required[index] = false;
}
void snled27351_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_LED_CONTROL);
- for (int i = 0; i < SNLED27351_LED_CONTROL_REGISTER_COUNT; i++) {
+ snled27351_select_page(addr, SNLED27351_COMMAND_LED_CONTROL);
+
+ for (uint8_t i = 0; i < SNLED27351_LED_CONTROL_REGISTER_COUNT; i++) {
snled27351_write_register(addr, i, g_led_control_registers[index][i]);
}
+
+ g_led_control_registers_update_required[index] = false;
}
- g_led_control_registers_update_required[index] = false;
}
void snled27351_flush(void) {
@@ -265,15 +244,15 @@ void snled27351_flush(void) {
}
void snled27351_sw_return_normal(uint8_t addr) {
- // Select to function page
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_FUNCTION);
+ snled27351_select_page(addr, SNLED27351_COMMAND_FUNCTION);
+
// Setting LED driver to normal mode
snled27351_write_register(addr, SNLED27351_FUNCTION_REG_SOFTWARE_SHUTDOWN, SNLED27351_SOFTWARE_SHUTDOWN_SSD_NORMAL);
}
void snled27351_sw_shutdown(uint8_t addr) {
- // Select to function page
- snled27351_write_register(addr, SNLED27351_REG_COMMAND, SNLED27351_COMMAND_FUNCTION);
+ snled27351_select_page(addr, SNLED27351_COMMAND_FUNCTION);
+
// Setting LED driver to shutdown mode
snled27351_write_register(addr, SNLED27351_FUNCTION_REG_SOFTWARE_SHUTDOWN, SNLED27351_SOFTWARE_SHUTDOWN_SSD_SHUTDOWN);
// Write SW Sleep Register
diff --git a/drivers/led/snled27351.h b/drivers/led/snled27351.h
index 77337f177b..4b811719d9 100644
--- a/drivers/led/snled27351.h
+++ b/drivers/led/snled27351.h
@@ -169,8 +169,8 @@ extern const snled27351_led_t PROGMEM g_snled27351_leds[SNLED27351_LED_COUNT];
void snled27351_init_drivers(void);
void snled27351_init(uint8_t addr);
-bool snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+void snled27351_select_page(uint8_t addr, uint8_t page);
+void snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data);
void snled27351_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void snled27351_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
diff --git a/drivers/oled/oled_driver.c b/drivers/oled/oled_driver.c
index 4a2121cd7c..8cca41394f 100644
--- a/drivers/oled/oled_driver.c
+++ b/drivers/oled/oled_driver.c
@@ -223,13 +223,8 @@ __attribute__((weak)) bool oled_send_cmd_P(const uint8_t *data, uint16_t size) {
spi_stop();
return (status >= 0);
# elif defined(OLED_TRANSPORT_I2C)
- i2c_status_t status = i2c_start((OLED_DISPLAY_ADDRESS << 1) | I2C_WRITE, OLED_I2C_TIMEOUT);
- for (uint16_t i = 0; i < size && status >= 0; i++) {
- status = i2c_write(pgm_read_byte((const char *)data++), OLED_I2C_TIMEOUT);
- }
-
- i2c_stop();
+ i2c_status_t status = i2c_transmit_P((OLED_DISPLAY_ADDRESS << 1), data, size, OLED_I2C_TIMEOUT);
return (status == I2C_STATUS_SUCCESS);
# endif
@@ -253,7 +248,7 @@ __attribute__((weak)) bool oled_send_data(const uint8_t *data, uint16_t size) {
spi_stop();
return true;
#elif defined(OLED_TRANSPORT_I2C)
- i2c_status_t status = i2c_writeReg((OLED_DISPLAY_ADDRESS << 1), I2C_DATA, data, size, OLED_I2C_TIMEOUT);
+ i2c_status_t status = i2c_write_register((OLED_DISPLAY_ADDRESS << 1), I2C_DATA, data, size, OLED_I2C_TIMEOUT);
return (status == I2C_STATUS_SUCCESS);
#endif
}
diff --git a/drivers/painter/comms/qp_comms_i2c.c b/drivers/painter/comms/qp_comms_i2c.c
index ec45ddfb3b..93f503f3dd 100644
--- a/drivers/painter/comms/qp_comms_i2c.c
+++ b/drivers/painter/comms/qp_comms_i2c.c
@@ -28,18 +28,14 @@ bool qp_comms_i2c_init(painter_device_t device) {
}
bool qp_comms_i2c_start(painter_device_t device) {
- painter_driver_t * driver = (painter_driver_t *)device;
- qp_comms_i2c_config_t *comms_config = (qp_comms_i2c_config_t *)driver->comms_config;
- return i2c_start(comms_config->chip_address << 1) == I2C_STATUS_SUCCESS;
+ return true;
}
uint32_t qp_comms_i2c_send_data(painter_device_t device, const void *data, uint32_t byte_count) {
return qp_comms_i2c_send_raw(device, data, byte_count);
}
-void qp_comms_i2c_stop(painter_device_t device) {
- i2c_stop();
-}
+void qp_comms_i2c_stop(painter_device_t device) {}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Command+Data I2C support
diff --git a/drivers/painter/sh1106/qp_sh1106.c b/drivers/painter/sh1106/qp_sh1106.c
index 7cb6e398fa..4117115aec 100644
--- a/drivers/painter/sh1106/qp_sh1106.c
+++ b/drivers/painter/sh1106/qp_sh1106.c
@@ -44,7 +44,7 @@ __attribute__((weak)) bool qp_sh1106_init(painter_device_t device, painter_rotat
}
// clang-format off
- const uint8_t sh1106_init_sequence[] = {
+ uint8_t sh1106_init_sequence[] = {
// Command, Delay, N, Data[N]
SH1106_SET_MUX_RATIO, 0, 1, 0x3F,
SH1106_DISPLAY_OFFSET, 0, 1, 0x00,
@@ -61,6 +61,16 @@ __attribute__((weak)) bool qp_sh1106_init(painter_device_t device, painter_rotat
};
// clang-format on
+ // If the display height is anything other than the default 64 pixels, change SH1106_SET_MUX_RATIO data byte to the correct value
+ if (driver->oled.base.panel_height != 64) {
+ sh1106_init_sequence[3] = driver->oled.base.panel_height - 1;
+ }
+
+ // For 128x32 or 96x16 displays, change SH1106_COM_PADS_HW_CFG data byte from alternative (0x12) to sequential (0x02) configuration
+ if (driver->oled.base.panel_height <= 32) {
+ sh1106_init_sequence[20] = 0x02;
+ }
+
qp_comms_bulk_command_sequence(device, sh1106_init_sequence, sizeof(sh1106_init_sequence));
return true;
}
@@ -203,4 +213,4 @@ painter_device_t qp_sh1106_make_i2c_device(uint16_t panel_width, uint16_t panel_
return NULL;
}
-#endif // QUANTUM_PAINTER_SH1106_SPI_ENABLE
+#endif // QUANTUM_PAINTER_SH1106_I2C_ENABLE
diff --git a/drivers/painter/sh1106/qp_sh1106_opcodes.h b/drivers/painter/sh1106/qp_sh1106_opcodes.h
index a2e100d770..bf86ba4c2c 100644
--- a/drivers/painter/sh1106/qp_sh1106_opcodes.h
+++ b/drivers/painter/sh1106/qp_sh1106_opcodes.h
@@ -16,7 +16,7 @@
#define SH1106_COM_PADS_HW_CFG 0xDA
#define SH1106_SET_CONTRAST 0x81
#define SH1106_SET_PRECHARGE_PERIOD 0xD9
-#define SH1106_VCOM_DETECT 0xDB
+#define SH1106_VCOM_DESELECT_LEVEL 0xDB
#define SH1106_ALL_ON_RESUME 0xA4
#define SH1106_NON_INVERTING_DISPLAY 0xA6
#define SH1106_DEACTIVATE_SCROLL 0x2E
diff --git a/drivers/sensors/analog_joystick.c b/drivers/sensors/analog_joystick.c
index 12256a8e7a..221625075c 100644
--- a/drivers/sensors/analog_joystick.c
+++ b/drivers/sensors/analog_joystick.c
@@ -22,17 +22,28 @@
#include <stdlib.h>
// Set Parameters
+#ifndef ANALOG_JOYSTICK_AUTO_AXIS
uint16_t minAxisValue = ANALOG_JOYSTICK_AXIS_MIN;
uint16_t maxAxisValue = ANALOG_JOYSTICK_AXIS_MAX;
+#else
+int16_t minAxisValues[2];
+int16_t maxAxisValues[2];
+#endif
uint8_t maxCursorSpeed = ANALOG_JOYSTICK_SPEED_MAX;
uint8_t speedRegulator = ANALOG_JOYSTICK_SPEED_REGULATOR; // Lower Values Create Faster Movement
+#ifdef ANALOG_JOYSTICK_WEIGHTS
+int8_t weights[101] = ANALOG_JOYSTICK_WEIGHTS;
+#endif
+
int16_t xOrigin, yOrigin;
uint16_t lastCursor = 0;
-int16_t axisCoordinate(pin_t pin, uint16_t origin) {
+uint8_t prevValues[2] = {0, 0};
+
+int16_t axisCoordinate(pin_t pin, uint16_t origin, uint8_t axis) {
int8_t direction;
int16_t distanceFromOrigin;
int16_t range;
@@ -43,12 +54,27 @@ int16_t axisCoordinate(pin_t pin, uint16_t origin) {
return 0;
} else if (origin > position) {
distanceFromOrigin = origin - position;
- range = origin - minAxisValue;
- direction = -1;
+#ifdef ANALOG_JOYSTICK_AUTO_AXIS
+ if (position < minAxisValues[axis]) {
+ minAxisValues[axis] = position;
+ }
+ range = origin - minAxisValues[axis];
+#else
+ range = origin - minAxisValue;
+#endif
+ direction = -1;
} else {
distanceFromOrigin = position - origin;
- range = maxAxisValue - origin;
- direction = 1;
+
+#ifdef ANALOG_JOYSTICK_AUTO_AXIS
+ if (position > maxAxisValues[axis]) {
+ maxAxisValues[axis] = position;
+ }
+ range = maxAxisValues[axis] - origin;
+#else
+ range = maxAxisValue - origin;
+#endif
+ direction = 1;
}
float percent = (float)distanceFromOrigin / range;
@@ -62,14 +88,29 @@ int16_t axisCoordinate(pin_t pin, uint16_t origin) {
}
}
-int8_t axisToMouseComponent(pin_t pin, int16_t origin, uint8_t maxSpeed) {
- int16_t coordinate = axisCoordinate(pin, origin);
+int8_t axisToMouseComponent(pin_t pin, int16_t origin, uint8_t maxSpeed, uint8_t axis) {
+ int16_t coordinate = axisCoordinate(pin, origin, axis);
+ int8_t result;
+#ifndef ANALOG_JOYSTICK_WEIGHTS
if (coordinate != 0) {
float percent = (float)coordinate / 100;
- return percent * maxCursorSpeed * (abs(coordinate) / speedRegulator);
+ result = percent * maxCursorSpeed * (abs(coordinate) / speedRegulator);
} else {
return 0;
}
+#else
+ result = weights[abs(coordinate)] * (coordinate < 0 ? -1 : 1) * maxCursorSpeed / speedRegulator;
+#endif
+
+#ifdef ANALOG_JOYSTICK_CUTOFF
+ uint8_t pv = prevValues[axis];
+ prevValues[axis] = abs(result);
+ if (pv > abs(result)) {
+ return 0;
+ }
+#endif
+
+ return result;
}
report_analog_joystick_t analog_joystick_read(void) {
@@ -77,8 +118,8 @@ report_analog_joystick_t analog_joystick_read(void) {
if (timer_elapsed(lastCursor) > ANALOG_JOYSTICK_READ_INTERVAL) {
lastCursor = timer_read();
- report.x = axisToMouseComponent(ANALOG_JOYSTICK_X_AXIS_PIN, xOrigin, maxCursorSpeed);
- report.y = axisToMouseComponent(ANALOG_JOYSTICK_Y_AXIS_PIN, yOrigin, maxCursorSpeed);
+ report.x = axisToMouseComponent(ANALOG_JOYSTICK_X_AXIS_PIN, xOrigin, maxCursorSpeed, 0);
+ report.y = axisToMouseComponent(ANALOG_JOYSTICK_Y_AXIS_PIN, yOrigin, maxCursorSpeed, 1);
}
#ifdef ANALOG_JOYSTICK_CLICK_PIN
report.button = !readPin(ANALOG_JOYSTICK_CLICK_PIN);
@@ -87,10 +128,20 @@ report_analog_joystick_t analog_joystick_read(void) {
}
void analog_joystick_init(void) {
+ setPinInputHigh(ANALOG_JOYSTICK_X_AXIS_PIN);
+ setPinInputHigh(ANALOG_JOYSTICK_Y_AXIS_PIN);
+
#ifdef ANALOG_JOYSTICK_CLICK_PIN
setPinInputHigh(ANALOG_JOYSTICK_CLICK_PIN);
#endif
// Account for drift
xOrigin = analogReadPin(ANALOG_JOYSTICK_X_AXIS_PIN);
yOrigin = analogReadPin(ANALOG_JOYSTICK_Y_AXIS_PIN);
+
+#ifdef ANALOG_JOYSTICK_AUTO_AXIS
+ minAxisValues[0] = xOrigin - 100;
+ minAxisValues[1] = yOrigin - 100;
+ maxAxisValues[0] = xOrigin + 100;
+ maxAxisValues[1] = yOrigin + 100;
+#endif
}
diff --git a/drivers/sensors/azoteq_iqs5xx.c b/drivers/sensors/azoteq_iqs5xx.c
index 521f558b5f..367873eb06 100644
--- a/drivers/sensors/azoteq_iqs5xx.c
+++ b/drivers/sensors/azoteq_iqs5xx.c
@@ -107,18 +107,17 @@ static struct {
i2c_status_t azoteq_iqs5xx_wake(void) {
uint8_t data = 0;
- i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_PREVIOUS_CYCLE_TIME, (uint8_t *)&data, sizeof(data), 1);
- i2c_stop();
+ i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_PREVIOUS_CYCLE_TIME, (uint8_t *)&data, sizeof(data), 1);
wait_us(150);
return status;
}
i2c_status_t azoteq_iqs5xx_end_session(void) {
const uint8_t END_BYTE = 1; // any data
- return i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_END_COMMS, &END_BYTE, 1, AZOTEQ_IQS5XX_TIMEOUT_MS);
+ return i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_END_COMMS, &END_BYTE, 1, AZOTEQ_IQS5XX_TIMEOUT_MS);
}
i2c_status_t azoteq_iqs5xx_get_base_data(azoteq_iqs5xx_base_data_t *base_data) {
- i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_PREVIOUS_CYCLE_TIME, (uint8_t *)base_data, 10, AZOTEQ_IQS5XX_TIMEOUT_MS);
+ i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_PREVIOUS_CYCLE_TIME, (uint8_t *)base_data, 10, AZOTEQ_IQS5XX_TIMEOUT_MS);
if (status == I2C_STATUS_SUCCESS) {
azoteq_iqs5xx_end_session();
}
@@ -131,7 +130,7 @@ i2c_status_t azoteq_iqs5xx_get_report_rate(azoteq_iqs5xx_report_rate_t *report_r
return I2C_STATUS_ERROR;
}
uint16_t selected_reg = AZOTEQ_IQS5XX_REG_REPORT_RATE_ACTIVE + (2 * mode);
- i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, selected_reg, (uint8_t *)report_rate, 2, AZOTEQ_IQS5XX_TIMEOUT_MS);
+ i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, selected_reg, (uint8_t *)report_rate, 2, AZOTEQ_IQS5XX_TIMEOUT_MS);
if (end_session) {
azoteq_iqs5xx_end_session();
}
@@ -147,7 +146,7 @@ i2c_status_t azoteq_iqs5xx_set_report_rate(uint16_t report_rate_ms, azoteq_iqs5x
azoteq_iqs5xx_report_rate_t report_rate = {0};
report_rate.h = (uint8_t)((report_rate_ms >> 8) & 0xFF);
report_rate.l = (uint8_t)(report_rate_ms & 0xFF);
- i2c_status_t status = i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, selected_reg, (uint8_t *)&report_rate, 2, AZOTEQ_IQS5XX_TIMEOUT_MS);
+ i2c_status_t status = i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, selected_reg, (uint8_t *)&report_rate, 2, AZOTEQ_IQS5XX_TIMEOUT_MS);
if (end_session) {
azoteq_iqs5xx_end_session();
}
@@ -156,10 +155,10 @@ i2c_status_t azoteq_iqs5xx_set_report_rate(uint16_t report_rate_ms, azoteq_iqs5x
i2c_status_t azoteq_iqs5xx_set_reati(bool enabled, bool end_session) {
azoteq_iqs5xx_system_config_0_t config = {0};
- i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
+ i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
if (status == I2C_STATUS_SUCCESS) {
config.reati = enabled;
- status = i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
+ status = i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
}
if (end_session) {
azoteq_iqs5xx_end_session();
@@ -169,7 +168,7 @@ i2c_status_t azoteq_iqs5xx_set_reati(bool enabled, bool end_session) {
i2c_status_t azoteq_iqs5xx_set_event_mode(bool enabled, bool end_session) {
azoteq_iqs5xx_system_config_1_t config = {0};
- i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
+ i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
if (status == I2C_STATUS_SUCCESS) {
config.event_mode = enabled;
config.touch_event = true;
@@ -179,7 +178,7 @@ i2c_status_t azoteq_iqs5xx_set_event_mode(bool enabled, bool end_session) {
config.reati_event = false;
config.alp_prox_event = false;
config.gesture_event = true;
- status = i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
+ status = i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
}
if (end_session) {
azoteq_iqs5xx_end_session();
@@ -189,7 +188,7 @@ i2c_status_t azoteq_iqs5xx_set_event_mode(bool enabled, bool end_session) {
i2c_status_t azoteq_iqs5xx_set_gesture_config(bool end_session) {
azoteq_iqs5xx_gesture_config_t config = {0};
- i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SINGLE_FINGER_GESTURES, (uint8_t *)&config, sizeof(azoteq_iqs5xx_gesture_config_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
+ i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SINGLE_FINGER_GESTURES, (uint8_t *)&config, sizeof(azoteq_iqs5xx_gesture_config_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
pd_dprintf("azo scroll: %d\n", config.multi_finger_gestures.scroll);
if (status == I2C_STATUS_SUCCESS) {
config.single_finger_gestures.single_tap = AZOTEQ_IQS5XX_TAP_ENABLE;
@@ -211,7 +210,7 @@ i2c_status_t azoteq_iqs5xx_set_gesture_config(bool end_session) {
config.scroll_initial_distance = AZOTEQ_IQS5XX_SWAP_H_L_BYTES(AZOTEQ_IQS5XX_SCROLL_INITIAL_DISTANCE);
config.zoom_initial_distance = AZOTEQ_IQS5XX_SWAP_H_L_BYTES(AZOTEQ_IQS5XX_ZOOM_INITIAL_DISTANCE);
config.zoom_consecutive_distance = AZOTEQ_IQS5XX_SWAP_H_L_BYTES(AZOTEQ_IQS5XX_ZOOM_CONSECUTIVE_DISTANCE);
- status = i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SINGLE_FINGER_GESTURES, (uint8_t *)&config, sizeof(azoteq_iqs5xx_gesture_config_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
+ status = i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SINGLE_FINGER_GESTURES, (uint8_t *)&config, sizeof(azoteq_iqs5xx_gesture_config_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
}
if (end_session) {
azoteq_iqs5xx_end_session();
@@ -221,7 +220,7 @@ i2c_status_t azoteq_iqs5xx_set_gesture_config(bool end_session) {
i2c_status_t azoteq_iqs5xx_set_xy_config(bool flip_x, bool flip_y, bool switch_xy, bool palm_reject, bool end_session) {
azoteq_iqs5xx_xy_config_0_t config = {0};
- i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_XY_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_xy_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
+ i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_XY_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_xy_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
if (status == I2C_STATUS_SUCCESS) {
if (flip_x) {
config.flip_x = !config.flip_x;
@@ -233,7 +232,7 @@ i2c_status_t azoteq_iqs5xx_set_xy_config(bool flip_x, bool flip_y, bool switch_x
config.switch_xy_axis = !config.switch_xy_axis;
}
config.palm_reject = palm_reject;
- status = i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_XY_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_xy_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
+ status = i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_XY_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_xy_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
}
if (end_session) {
azoteq_iqs5xx_end_session();
@@ -243,11 +242,11 @@ i2c_status_t azoteq_iqs5xx_set_xy_config(bool flip_x, bool flip_y, bool switch_x
i2c_status_t azoteq_iqs5xx_reset_suspend(bool reset, bool suspend, bool end_session) {
azoteq_iqs5xx_system_control_1_t config = {0};
- i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONTROL_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_control_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
+ i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONTROL_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_control_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
if (status == I2C_STATUS_SUCCESS) {
config.reset = reset;
config.suspend = suspend;
- status = i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONTROL_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_control_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
+ status = i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONTROL_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_control_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
}
if (end_session) {
azoteq_iqs5xx_end_session();
@@ -260,14 +259,14 @@ void azoteq_iqs5xx_set_cpi(uint16_t cpi) {
azoteq_iqs5xx_resolution_t resolution = {0};
resolution.x_resolution = AZOTEQ_IQS5XX_SWAP_H_L_BYTES(MIN(azoteq_iqs5xx_device_resolution_t.resolution_x, AZOTEQ_IQS5XX_INCH_TO_RESOLUTION_X(cpi)));
resolution.y_resolution = AZOTEQ_IQS5XX_SWAP_H_L_BYTES(MIN(azoteq_iqs5xx_device_resolution_t.resolution_y, AZOTEQ_IQS5XX_INCH_TO_RESOLUTION_Y(cpi)));
- i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_X_RESOLUTION, (uint8_t *)&resolution, sizeof(azoteq_iqs5xx_resolution_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
+ i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_X_RESOLUTION, (uint8_t *)&resolution, sizeof(azoteq_iqs5xx_resolution_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
}
}
uint16_t azoteq_iqs5xx_get_cpi(void) {
if (azoteq_iqs5xx_product_number != AZOTEQ_IQS5XX_UNKNOWN) {
azoteq_iqs5xx_resolution_t resolution = {0};
- i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_X_RESOLUTION, (uint8_t *)&resolution, sizeof(azoteq_iqs5xx_resolution_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
+ i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_X_RESOLUTION, (uint8_t *)&resolution, sizeof(azoteq_iqs5xx_resolution_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
if (status == I2C_STATUS_SUCCESS) {
return AZOTEQ_IQS5XX_RESOLUTION_X_TO_INCH(AZOTEQ_IQS5XX_SWAP_H_L_BYTES(resolution.x_resolution));
}
@@ -276,7 +275,7 @@ uint16_t azoteq_iqs5xx_get_cpi(void) {
}
uint16_t azoteq_iqs5xx_get_product(void) {
- i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_PRODUCT_NUMBER, (uint8_t *)&azoteq_iqs5xx_product_number, sizeof(uint16_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
+ i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_PRODUCT_NUMBER, (uint8_t *)&azoteq_iqs5xx_product_number, sizeof(uint16_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
if (status == I2C_STATUS_SUCCESS) {
azoteq_iqs5xx_product_number = AZOTEQ_IQS5XX_SWAP_H_L_BYTES(azoteq_iqs5xx_product_number);
}
diff --git a/drivers/sensors/cirque_pinnacle.c b/drivers/sensors/cirque_pinnacle.c
index 3131805c20..9afc9df804 100644
--- a/drivers/sensors/cirque_pinnacle.c
+++ b/drivers/sensors/cirque_pinnacle.c
@@ -216,6 +216,20 @@ void cirque_pinnacle_cursor_smoothing(bool enable) {
RAP_Write(HOSTREG__FEEDCONFIG3, feedconfig3);
}
+// Check sensor is connected
+bool cirque_pinnacle_connected(void) {
+ uint8_t current_zidle = 0;
+ uint8_t temp_zidle = 0;
+ RAP_ReadBytes(HOSTREG__ZIDLE, &current_zidle, 1);
+ RAP_Write(HOSTREG__ZIDLE, HOSTREG__ZIDLE_DEFVAL);
+ RAP_ReadBytes(HOSTREG__ZIDLE, &temp_zidle, 1);
+ if (temp_zidle == HOSTREG__ZIDLE_DEFVAL) {
+ RAP_Write(HOSTREG__ZIDLE, current_zidle);
+ return true;
+ }
+ return false;
+}
+
/* Pinnacle-based TM040040/TM035035/TM023023 Functions */
void cirque_pinnacle_init(void) {
#if defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi)
@@ -274,6 +288,10 @@ void cirque_pinnacle_init(void) {
}
cirque_pinnacle_enable_feed(true);
+
+#ifndef CIRQUE_PINNACLE_SKIP_SENSOR_CHECK
+ touchpad_init = cirque_pinnacle_connected();
+#endif
}
pinnacle_data_t cirque_pinnacle_read_data(void) {
@@ -320,6 +338,15 @@ pinnacle_data_t cirque_pinnacle_read_data(void) {
result.wheelCount = ((int8_t*)data)[3];
#endif
+#ifdef CIRQUE_PINNACLE_REACHABLE_CALIBRATION
+ static uint16_t xMin = UINT16_MAX, yMin = UINT16_MAX, yMax = 0, xMax = 0;
+ if (result.xValue < xMin) xMin = result.xValue;
+ if (result.xValue > xMax) xMax = result.xValue;
+ if (result.yValue < yMin) yMin = result.yValue;
+ if (result.yValue > yMax) yMax = result.yValue;
+ pd_dprintf("%s: xLo=%3d xHi=%3d yLo=%3d yHi=%3d\n", __FUNCTION__, xMin, xMax, yMin, yMax);
+#endif
+
result.valid = true;
return result;
}
diff --git a/drivers/sensors/cirque_pinnacle_i2c.c b/drivers/sensors/cirque_pinnacle_i2c.c
index 3c11e5f079..a3622e9d60 100644
--- a/drivers/sensors/cirque_pinnacle_i2c.c
+++ b/drivers/sensors/cirque_pinnacle_i2c.c
@@ -14,12 +14,11 @@ extern bool touchpad_init;
void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count) {
uint8_t cmdByte = READ_MASK | address; // Form the READ command byte
if (touchpad_init) {
- i2c_writeReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, NULL, 0, CIRQUE_PINNACLE_TIMEOUT);
- if (i2c_readReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, data, count, CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
- pd_dprintf("error cirque_pinnacle i2c_readReg\n");
+ i2c_write_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, NULL, 0, CIRQUE_PINNACLE_TIMEOUT);
+ if (i2c_read_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, data, count, CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
+ pd_dprintf("error cirque_pinnacle i2c_read_register\n");
touchpad_init = false;
}
- i2c_stop();
}
}
@@ -28,10 +27,9 @@ void RAP_Write(uint8_t address, uint8_t data) {
uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte
if (touchpad_init) {
- if (i2c_writeReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, &data, sizeof(data), CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
- pd_dprintf("error cirque_pinnacle i2c_writeReg\n");
+ if (i2c_write_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, &data, sizeof(data), CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
+ pd_dprintf("error cirque_pinnacle i2c_write_register\n");
touchpad_init = false;
}
- i2c_stop();
}
}
diff --git a/drivers/sensors/pimoroni_trackball.c b/drivers/sensors/pimoroni_trackball.c
index 326e59744f..9c6d26d73d 100644
--- a/drivers/sensors/pimoroni_trackball.c
+++ b/drivers/sensors/pimoroni_trackball.c
@@ -56,13 +56,13 @@ void pimoroni_trackball_set_cpi(uint16_t cpi) {
void pimoroni_trackball_set_rgbw(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
uint8_t data[4] = {r, g, b, w};
- __attribute__((unused)) i2c_status_t status = i2c_writeReg(PIMORONI_TRACKBALL_ADDRESS << 1, PIMORONI_TRACKBALL_REG_LED_RED, data, sizeof(data), PIMORONI_TRACKBALL_TIMEOUT);
+ __attribute__((unused)) i2c_status_t status = i2c_write_register(PIMORONI_TRACKBALL_ADDRESS << 1, PIMORONI_TRACKBALL_REG_LED_RED, data, sizeof(data), PIMORONI_TRACKBALL_TIMEOUT);
pd_dprintf("Trackball RGBW i2c_status_t: %d\n", status);
}
i2c_status_t read_pimoroni_trackball(pimoroni_data_t* data) {
- i2c_status_t status = i2c_readReg(PIMORONI_TRACKBALL_ADDRESS << 1, PIMORONI_TRACKBALL_REG_LEFT, (uint8_t*)data, sizeof(*data), PIMORONI_TRACKBALL_TIMEOUT);
+ i2c_status_t status = i2c_read_register(PIMORONI_TRACKBALL_ADDRESS << 1, PIMORONI_TRACKBALL_REG_LEFT, (uint8_t*)data, sizeof(*data), PIMORONI_TRACKBALL_TIMEOUT);
#ifdef POINTING_DEVICE_DEBUG
static uint16_t d_timer;
diff --git a/drivers/ws2812.h b/drivers/ws2812.h
index 1527df23d3..134de51c50 100644
--- a/drivers/ws2812.h
+++ b/drivers/ws2812.h
@@ -56,9 +56,9 @@
# define WS2812_TRST_US 280
#endif
-#if defined(RGBLED_NUM)
-# define WS2812_LED_COUNT RGBLED_NUM
-#elif defined(RGB_MATRIX_LED_COUNT)
+#if defined(RGBLIGHT_WS2812)
+# define WS2812_LED_COUNT RGBLIGHT_LED_COUNT
+#elif defined(RGB_MATRIX_WS2812)
# define WS2812_LED_COUNT RGB_MATRIX_LED_COUNT
#endif