LED drivers: create structs to hold PWM/scaling buffers (#22955)

This commit is contained in:
Ryan 2024-02-10 18:48:13 +11:00 committed by GitHub
parent a5ea619139
commit 66015f1645
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 668 additions and 479 deletions

View File

@ -45,8 +45,15 @@
# define AW20216S_SPI_DIVISOR 4
#endif
uint8_t g_pwm_buffer[AW20216S_DRIVER_COUNT][AW20216S_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[AW20216S_DRIVER_COUNT] = {false};
typedef struct aw20216s_driver_t {
uint8_t pwm_buffer[AW20216S_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
} PACKED aw20216s_driver_t;
aw20216s_driver_t driver_buffers[AW20216S_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
}};
bool aw20216s_write(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t* data, uint8_t len) {
static uint8_t s_spi_transfer_buffer[2] = {0};
@ -131,14 +138,14 @@ void aw20216s_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
aw20216s_led_t led;
memcpy_P(&led, (&g_aw20216s_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) {
if (driver_buffers[led.driver].pwm_buffer[led.r] == red && driver_buffers[led.driver].pwm_buffer[led.g] == green && driver_buffers[led.driver].pwm_buffer[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;
driver_buffers[led.driver].pwm_buffer[led.r] = red;
driver_buffers[led.driver].pwm_buffer[led.g] = green;
driver_buffers[led.driver].pwm_buffer[led.b] = blue;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
void aw20216s_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
@ -148,9 +155,9 @@ 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;
if (driver_buffers[index].pwm_buffer_dirty) {
aw20216s_write(cs_pin, AW20216S_PAGE_PWM, 0, driver_buffers[index].pwm_buffer, AW20216S_PWM_REGISTER_COUNT);
driver_buffers[index].pwm_buffer_dirty = false;
}
}

View File

@ -28,12 +28,20 @@
# define IS31FL3218_I2C_PERSISTENCE 0
#endif
// 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;
typedef struct is31fl3218_driver_t {
uint8_t pwm_buffer[IS31FL3218_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t led_control_buffer[IS31FL3218_LED_CONTROL_REGISTER_COUNT];
bool led_control_buffer_dirty;
} PACKED is31fl3218_driver_t;
uint8_t g_led_control_registers[IS31FL3218_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required = false;
// IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining.
is31fl3218_driver_t driver_buffers = {
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.led_control_buffer = {0},
.led_control_buffer_dirty = false,
};
void is31fl3218_write_register(uint8_t reg, uint8_t data) {
#if IS31FL3218_I2C_PERSISTENCE > 0
@ -48,10 +56,10 @@ void is31fl3218_write_register(uint8_t reg, uint8_t data) {
void is31fl3218_write_pwm_buffer(void) {
#if IS31FL3218_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3218_I2C_PERSISTENCE; i++) {
if (i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, IS31FL3218_REG_PWM, g_pwm_buffer, 18, IS31FL3218_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, IS31FL3218_REG_PWM, driver_buffers.pwm_buffer, 18, IS31FL3218_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, IS31FL3218_REG_PWM, g_pwm_buffer, 18, IS31FL3218_I2C_TIMEOUT);
i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, IS31FL3218_REG_PWM, driver_buffers.pwm_buffer, 18, IS31FL3218_I2C_TIMEOUT);
#endif
}
@ -90,12 +98,12 @@ void is31fl3218_set_value(int index, uint8_t value) {
if (index >= 0 && index < IS31FL3218_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3218_leds[index]), sizeof(led));
if (g_pwm_buffer[led.v] == value) {
if (driver_buffers.pwm_buffer[led.v] == value) {
return;
}
g_pwm_buffer[led.v] = value;
g_pwm_buffer_update_required = true;
driver_buffers.pwm_buffer[led.v] = value;
driver_buffers.pwm_buffer_dirty = true;
}
}
@ -113,30 +121,30 @@ void is31fl3218_set_led_control_register(uint8_t index, bool value) {
uint8_t bit_value = led.v % 6;
if (value) {
g_led_control_registers[control_register] |= (1 << bit_value);
driver_buffers.led_control_buffer[control_register] |= (1 << bit_value);
} else {
g_led_control_registers[control_register] &= ~(1 << bit_value);
driver_buffers.led_control_buffer[control_register] &= ~(1 << bit_value);
}
g_led_control_registers_update_required = true;
driver_buffers.led_control_buffer_dirty = true;
}
void is31fl3218_update_pwm_buffers(void) {
if (g_pwm_buffer_update_required) {
if (driver_buffers.pwm_buffer_dirty) {
is31fl3218_write_pwm_buffer();
// Load PWM registers and LED Control register data
is31fl3218_write_register(IS31FL3218_REG_UPDATE, 0x01);
g_pwm_buffer_update_required = false;
driver_buffers.pwm_buffer_dirty = false;
}
}
void is31fl3218_update_led_control_registers(void) {
if (g_led_control_registers_update_required) {
if (driver_buffers.led_control_buffer_dirty) {
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]);
is31fl3218_write_register(IS31FL3218_REG_LED_CONTROL_1 + i, driver_buffers.led_control_buffer[i]);
}
g_led_control_registers_update_required = false;
driver_buffers.led_control_buffer_dirty = false;
}
}

View File

@ -28,12 +28,20 @@
# define IS31FL3218_I2C_PERSISTENCE 0
#endif
// 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;
typedef struct is31fl3218_driver_t {
uint8_t pwm_buffer[IS31FL3218_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t led_control_buffer[IS31FL3218_LED_CONTROL_REGISTER_COUNT];
bool led_control_buffer_dirty;
} PACKED is31fl3218_driver_t;
uint8_t g_led_control_registers[IS31FL3218_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required = false;
// IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining.
is31fl3218_driver_t driver_buffers = {
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.led_control_buffer = {0},
.led_control_buffer_dirty = false,
};
void is31fl3218_write_register(uint8_t reg, uint8_t data) {
#if IS31FL3218_I2C_PERSISTENCE > 0
@ -48,10 +56,10 @@ void is31fl3218_write_register(uint8_t reg, uint8_t data) {
void is31fl3218_write_pwm_buffer(void) {
#if IS31FL3218_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3218_I2C_PERSISTENCE; i++) {
if (i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, IS31FL3218_REG_PWM, g_pwm_buffer, 18, IS31FL3218_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, IS31FL3218_REG_PWM, driver_buffers.pwm_buffer, 18, IS31FL3218_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, IS31FL3218_REG_PWM, g_pwm_buffer, 18, IS31FL3218_I2C_TIMEOUT);
i2c_write_register(IS31FL3218_I2C_ADDRESS << 1, IS31FL3218_REG_PWM, driver_buffers.pwm_buffer, 18, IS31FL3218_I2C_TIMEOUT);
#endif
}
@ -90,14 +98,14 @@ void is31fl3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
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) {
if (driver_buffers.pwm_buffer[led.r] == red && driver_buffers.pwm_buffer[led.g] == green && driver_buffers.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;
driver_buffers.pwm_buffer[led.r] = red;
driver_buffers.pwm_buffer[led.g] = green;
driver_buffers.pwm_buffer[led.b] = blue;
driver_buffers.pwm_buffer_dirty = true;
}
}
@ -119,40 +127,40 @@ void is31fl3218_set_led_control_register(uint8_t index, bool red, bool green, bo
uint8_t bit_b = led.b % 6;
if (red) {
g_led_control_registers[control_register_r] |= (1 << bit_r);
driver_buffers.led_control_buffer[control_register_r] |= (1 << bit_r);
} else {
g_led_control_registers[control_register_r] &= ~(1 << bit_r);
driver_buffers.led_control_buffer[control_register_r] &= ~(1 << bit_r);
}
if (green) {
g_led_control_registers[control_register_g] |= (1 << bit_g);
driver_buffers.led_control_buffer[control_register_g] |= (1 << bit_g);
} else {
g_led_control_registers[control_register_g] &= ~(1 << bit_g);
driver_buffers.led_control_buffer[control_register_g] &= ~(1 << bit_g);
}
if (blue) {
g_led_control_registers[control_register_b] |= (1 << bit_b);
driver_buffers.led_control_buffer[control_register_b] |= (1 << bit_b);
} else {
g_led_control_registers[control_register_b] &= ~(1 << bit_b);
driver_buffers.led_control_buffer[control_register_b] &= ~(1 << bit_b);
}
g_led_control_registers_update_required = true;
driver_buffers.led_control_buffer_dirty = true;
}
void is31fl3218_update_pwm_buffers(void) {
if (g_pwm_buffer_update_required) {
if (driver_buffers.pwm_buffer_dirty) {
is31fl3218_write_pwm_buffer();
// Load PWM registers and LED Control register data
is31fl3218_write_register(IS31FL3218_REG_UPDATE, 0x01);
g_pwm_buffer_update_required = false;
driver_buffers.pwm_buffer_dirty = false;
}
}
void is31fl3218_update_led_control_registers(void) {
if (g_led_control_registers_update_required) {
if (driver_buffers.led_control_buffer_dirty) {
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]);
is31fl3218_write_register(IS31FL3218_REG_LED_CONTROL_1 + i, driver_buffers.led_control_buffer[i]);
}
g_led_control_registers_update_required = false;
driver_buffers.led_control_buffer_dirty = false;
}
}

View File

@ -50,11 +50,19 @@ const uint8_t i2c_addresses[IS31FL3731_DRIVER_COUNT] = {
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3731_write_pwm_buffer() but it's
// probably not worth the extra complexity.
uint8_t g_pwm_buffer[IS31FL3731_DRIVER_COUNT][IS31FL3731_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[IS31FL3731_DRIVER_COUNT] = {false};
typedef struct is31fl3731_driver_t {
uint8_t pwm_buffer[IS31FL3731_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t led_control_buffer[IS31FL3731_LED_CONTROL_REGISTER_COUNT];
bool led_control_buffer_dirty;
} PACKED is31fl3731_driver_t;
uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][IS31FL3731_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required[IS31FL3731_DRIVER_COUNT] = {false};
is31fl3731_driver_t driver_buffers[IS31FL3731_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.led_control_buffer = {0},
.led_control_buffer_dirty = false,
}};
void is31fl3731_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3731_I2C_PERSISTENCE > 0
@ -78,10 +86,10 @@ void is31fl3731_write_pwm_buffer(uint8_t index) {
for (uint8_t i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3731_I2C_PERSISTENCE > 0
for (uint8_t j = 0; j < IS31FL3731_I2C_PERSISTENCE; j++) {
if (i2c_write_register(i2c_addresses[index] << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, IS31FL3731_FRAME_REG_PWM + i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, IS31FL3731_FRAME_REG_PWM + i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3731_I2C_TIMEOUT);
#endif
}
}
@ -160,12 +168,12 @@ void is31fl3731_set_value(int index, uint8_t value) {
if (index >= 0 && index < IS31FL3731_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3731_leds[index]), sizeof(led));
if (g_pwm_buffer[led.driver][led.v] == value) {
if (driver_buffers[led.driver].pwm_buffer[led.v] == value) {
return;
}
g_pwm_buffer[led.driver][led.v] = value;
g_pwm_buffer_update_required[led.driver] = true;
driver_buffers[led.driver].pwm_buffer[led.v] = value;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -183,29 +191,29 @@ void is31fl3731_set_led_control_register(uint8_t index, bool value) {
uint8_t bit_value = led.v % 8;
if (value) {
g_led_control_registers[led.driver][control_register] |= (1 << bit_value);
driver_buffers[led.driver].led_control_buffer[control_register] |= (1 << bit_value);
} else {
g_led_control_registers[led.driver][control_register] &= ~(1 << bit_value);
driver_buffers[led.driver].led_control_buffer[control_register] &= ~(1 << bit_value);
}
g_led_control_registers_update_required[led.driver] = true;
driver_buffers[led.driver].led_control_buffer_dirty = true;
}
void is31fl3731_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3731_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3731_update_led_control_registers(uint8_t index) {
if (g_led_control_registers_update_required[index]) {
if (driver_buffers[index].led_control_buffer_dirty) {
for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3731_write_register(index, i, g_led_control_registers[index][i]);
is31fl3731_write_register(index, i, driver_buffers[index].led_control_buffer[i]);
}
g_led_control_registers_update_required[index] = false;
driver_buffers[index].led_control_buffer_dirty = false;
}
}

View File

@ -49,11 +49,19 @@ const uint8_t i2c_addresses[IS31FL3731_DRIVER_COUNT] = {
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3731_write_pwm_buffer() but it's
// probably not worth the extra complexity.
uint8_t g_pwm_buffer[IS31FL3731_DRIVER_COUNT][IS31FL3731_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[IS31FL3731_DRIVER_COUNT] = {false};
typedef struct is31fl3731_driver_t {
uint8_t pwm_buffer[IS31FL3731_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t led_control_buffer[IS31FL3731_LED_CONTROL_REGISTER_COUNT];
bool led_control_buffer_dirty;
} PACKED is31fl3731_driver_t;
uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][IS31FL3731_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required[IS31FL3731_DRIVER_COUNT] = {false};
is31fl3731_driver_t driver_buffers[IS31FL3731_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.led_control_buffer = {0},
.led_control_buffer_dirty = false,
}};
void is31fl3731_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3731_I2C_PERSISTENCE > 0
@ -77,10 +85,10 @@ void is31fl3731_write_pwm_buffer(uint8_t index) {
for (uint8_t i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3731_I2C_PERSISTENCE > 0
for (uint8_t j = 0; j < IS31FL3731_I2C_PERSISTENCE; j++) {
if (i2c_write_register(i2c_addresses[index] << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, IS31FL3731_FRAME_REG_PWM + i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, IS31FL3731_FRAME_REG_PWM + i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3731_I2C_TIMEOUT);
#endif
}
}
@ -159,14 +167,14 @@ void is31fl3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
if (index >= 0 && index < IS31FL3731_LED_COUNT) {
memcpy_P(&led, (&g_is31fl3731_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) {
if (driver_buffers[led.driver].pwm_buffer[led.r] == red && driver_buffers[led.driver].pwm_buffer[led.g] == green && driver_buffers[led.driver].pwm_buffer[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;
driver_buffers[led.driver].pwm_buffer[led.r] = red;
driver_buffers[led.driver].pwm_buffer[led.g] = green;
driver_buffers[led.driver].pwm_buffer[led.b] = blue;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -188,39 +196,39 @@ void is31fl3731_set_led_control_register(uint8_t index, bool red, bool green, bo
uint8_t bit_b = led.b % 8;
if (red) {
g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
driver_buffers[led.driver].led_control_buffer[control_register_r] |= (1 << bit_r);
} else {
g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
driver_buffers[led.driver].led_control_buffer[control_register_r] &= ~(1 << bit_r);
}
if (green) {
g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
driver_buffers[led.driver].led_control_buffer[control_register_g] |= (1 << bit_g);
} else {
g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
driver_buffers[led.driver].led_control_buffer[control_register_g] &= ~(1 << bit_g);
}
if (blue) {
g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
driver_buffers[led.driver].led_control_buffer[control_register_b] |= (1 << bit_b);
} else {
g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
driver_buffers[led.driver].led_control_buffer[control_register_b] &= ~(1 << bit_b);
}
g_led_control_registers_update_required[led.driver] = true;
driver_buffers[led.driver].led_control_buffer_dirty = true;
}
void is31fl3731_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3731_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3731_update_led_control_registers(uint8_t index) {
if (g_led_control_registers_update_required[index]) {
if (driver_buffers[index].led_control_buffer_dirty) {
for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3731_write_register(index, i, g_led_control_registers[index][i]);
is31fl3731_write_register(index, i, driver_buffers[index].led_control_buffer[i]);
}
g_led_control_registers_update_required[index] = false;
driver_buffers[index].led_control_buffer_dirty = false;
}
}

View File

@ -94,11 +94,19 @@ const uint8_t driver_sync[IS31FL3733_DRIVER_COUNT] = {
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3733_write_pwm_buffer() but it's
// probably not worth the extra complexity.
uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][IS31FL3733_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false};
typedef struct is31fl3733_driver_t {
uint8_t pwm_buffer[IS31FL3733_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t led_control_buffer[IS31FL3733_LED_CONTROL_REGISTER_COUNT];
bool led_control_buffer_dirty;
} PACKED is31fl3733_driver_t;
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};
is31fl3733_driver_t driver_buffers[IS31FL3733_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.led_control_buffer = {0},
.led_control_buffer_dirty = false,
}};
void is31fl3733_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3733_I2C_PERSISTENCE > 0
@ -123,10 +131,10 @@ void is31fl3733_write_pwm_buffer(uint8_t index) {
for (uint8_t i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3733_I2C_PERSISTENCE > 0
for (uint8_t j = 0; j < IS31FL3733_I2C_PERSISTENCE; j++) {
if (i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3733_I2C_TIMEOUT);
#endif
}
}
@ -191,12 +199,12 @@ void is31fl3733_set_value(int index, uint8_t value) {
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) {
if (driver_buffers[led.driver].pwm_buffer[led.v] == value) {
return;
}
g_pwm_buffer[led.driver][led.v] = value;
g_pwm_buffer_update_required[led.driver] = true;
driver_buffers[led.driver].pwm_buffer[led.v] = value;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -214,33 +222,33 @@ void is31fl3733_set_led_control_register(uint8_t index, bool value) {
uint8_t bit_value = led.v % 8;
if (value) {
g_led_control_registers[led.driver][control_register] |= (1 << bit_value);
driver_buffers[led.driver].led_control_buffer[control_register] |= (1 << bit_value);
} else {
g_led_control_registers[led.driver][control_register] &= ~(1 << bit_value);
driver_buffers[led.driver].led_control_buffer[control_register] &= ~(1 << bit_value);
}
g_led_control_registers_update_required[led.driver] = true;
driver_buffers[led.driver].led_control_buffer_dirty = true;
}
void is31fl3733_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3733_select_page(index, IS31FL3733_COMMAND_PWM);
is31fl3733_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3733_update_led_control_registers(uint8_t index) {
if (g_led_control_registers_update_required[index]) {
if (driver_buffers[index].led_control_buffer_dirty) {
is31fl3733_select_page(index, IS31FL3733_COMMAND_LED_CONTROL);
for (uint8_t i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3733_write_register(index, i, g_led_control_registers[index][i]);
is31fl3733_write_register(index, i, driver_buffers[index].led_control_buffer[i]);
}
g_led_control_registers_update_required[index] = false;
driver_buffers[index].led_control_buffer_dirty = false;
}
}

View File

@ -93,11 +93,19 @@ const uint8_t driver_sync[IS31FL3733_DRIVER_COUNT] = {
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3733_write_pwm_buffer() but it's
// probably not worth the extra complexity.
uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][IS31FL3733_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false};
typedef struct is31fl3733_driver_t {
uint8_t pwm_buffer[IS31FL3733_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t led_control_buffer[IS31FL3733_LED_CONTROL_REGISTER_COUNT];
bool led_control_buffer_dirty;
} PACKED is31fl3733_driver_t;
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};
is31fl3733_driver_t driver_buffers[IS31FL3733_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.led_control_buffer = {0},
.led_control_buffer_dirty = false,
}};
void is31fl3733_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3733_I2C_PERSISTENCE > 0
@ -122,10 +130,10 @@ void is31fl3733_write_pwm_buffer(uint8_t index) {
for (uint8_t i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3733_I2C_PERSISTENCE > 0
for (uint8_t j = 0; j < IS31FL3733_I2C_PERSISTENCE; j++) {
if (i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3733_I2C_TIMEOUT);
#endif
}
}
@ -190,14 +198,14 @@ void is31fl3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
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) {
if (driver_buffers[led.driver].pwm_buffer[led.r] == red && driver_buffers[led.driver].pwm_buffer[led.g] == green && driver_buffers[led.driver].pwm_buffer[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;
driver_buffers[led.driver].pwm_buffer[led.r] = red;
driver_buffers[led.driver].pwm_buffer[led.g] = green;
driver_buffers[led.driver].pwm_buffer[led.b] = blue;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -219,43 +227,43 @@ void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bo
uint8_t bit_b = led.b % 8;
if (red) {
g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
driver_buffers[led.driver].led_control_buffer[control_register_r] |= (1 << bit_r);
} else {
g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
driver_buffers[led.driver].led_control_buffer[control_register_r] &= ~(1 << bit_r);
}
if (green) {
g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
driver_buffers[led.driver].led_control_buffer[control_register_g] |= (1 << bit_g);
} else {
g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
driver_buffers[led.driver].led_control_buffer[control_register_g] &= ~(1 << bit_g);
}
if (blue) {
g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
driver_buffers[led.driver].led_control_buffer[control_register_b] |= (1 << bit_b);
} else {
g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
driver_buffers[led.driver].led_control_buffer[control_register_b] &= ~(1 << bit_b);
}
g_led_control_registers_update_required[led.driver] = true;
driver_buffers[led.driver].led_control_buffer_dirty = true;
}
void is31fl3733_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3733_select_page(index, IS31FL3733_COMMAND_PWM);
is31fl3733_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3733_update_led_control_registers(uint8_t index) {
if (g_led_control_registers_update_required[index]) {
if (driver_buffers[index].led_control_buffer_dirty) {
is31fl3733_select_page(index, IS31FL3733_COMMAND_LED_CONTROL);
for (uint8_t i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3733_write_register(index, i, g_led_control_registers[index][i]);
is31fl3733_write_register(index, i, driver_buffers[index].led_control_buffer[i]);
}
g_led_control_registers_update_required[index] = false;
driver_buffers[index].led_control_buffer_dirty = false;
}
}

View File

@ -65,11 +65,19 @@ const uint8_t i2c_addresses[IS31FL3736_DRIVER_COUNT] = {
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3736_write_pwm_buffer() but it's
// probably not worth the extra complexity.
uint8_t g_pwm_buffer[IS31FL3736_DRIVER_COUNT][IS31FL3736_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[IS31FL3736_DRIVER_COUNT] = {false};
typedef struct is31fl3736_driver_t {
uint8_t pwm_buffer[IS31FL3736_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t led_control_buffer[IS31FL3736_LED_CONTROL_REGISTER_COUNT];
bool led_control_buffer_dirty;
} PACKED is31fl3736_driver_t;
uint8_t g_led_control_registers[IS31FL3736_DRIVER_COUNT][IS31FL3736_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required[IS31FL3736_DRIVER_COUNT] = {false};
is31fl3736_driver_t driver_buffers[IS31FL3736_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.led_control_buffer = {0},
.led_control_buffer_dirty = false,
}};
void is31fl3736_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3736_I2C_PERSISTENCE > 0
@ -94,10 +102,10 @@ void is31fl3736_write_pwm_buffer(uint8_t index) {
for (uint8_t i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3736_I2C_PERSISTENCE > 0
for (uint8_t j = 0; j < IS31FL3736_I2C_PERSISTENCE; j++) {
if (i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3736_I2C_TIMEOUT);
#endif
}
}
@ -160,12 +168,12 @@ void is31fl3736_set_value(int index, uint8_t value) {
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) {
if (driver_buffers[led.driver].pwm_buffer[led.v] == value) {
return;
}
g_pwm_buffer[led.driver][led.v] = value;
g_pwm_buffer_update_required[led.driver] = true;
driver_buffers[led.driver].pwm_buffer[led.v] = value;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -189,33 +197,33 @@ void is31fl3736_set_led_control_register(uint8_t index, bool value) {
uint8_t bit_value = led.v % 8;
if (value) {
g_led_control_registers[led.driver][control_register] |= (1 << bit_value);
driver_buffers[led.driver].led_control_buffer[control_register] |= (1 << bit_value);
} else {
g_led_control_registers[led.driver][control_register] &= ~(1 << bit_value);
driver_buffers[led.driver].led_control_buffer[control_register] &= ~(1 << bit_value);
}
g_led_control_registers_update_required[led.driver] = true;
driver_buffers[led.driver].led_control_buffer_dirty = true;
}
void is31fl3736_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3736_select_page(index, IS31FL3736_COMMAND_PWM);
is31fl3736_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3736_update_led_control_registers(uint8_t index) {
if (g_led_control_registers_update_required[index]) {
if (driver_buffers[index].led_control_buffer_dirty) {
is31fl3736_select_page(index, IS31FL3736_COMMAND_LED_CONTROL);
for (uint8_t i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3736_write_register(index, i, g_led_control_registers[index][i]);
is31fl3736_write_register(index, i, driver_buffers[index].led_control_buffer[i]);
}
g_led_control_registers_update_required[index] = false;
driver_buffers[index].led_control_buffer_dirty = false;
}
}

View File

@ -65,11 +65,19 @@ const uint8_t i2c_addresses[IS31FL3736_DRIVER_COUNT] = {
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3736_write_pwm_buffer() but it's
// probably not worth the extra complexity.
uint8_t g_pwm_buffer[IS31FL3736_DRIVER_COUNT][IS31FL3736_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[IS31FL3736_DRIVER_COUNT] = {false};
typedef struct is31fl3736_driver_t {
uint8_t pwm_buffer[IS31FL3736_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t led_control_buffer[IS31FL3736_LED_CONTROL_REGISTER_COUNT];
bool led_control_buffer_dirty;
} PACKED is31fl3736_driver_t;
uint8_t g_led_control_registers[IS31FL3736_DRIVER_COUNT][IS31FL3736_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required[IS31FL3736_DRIVER_COUNT] = {false};
is31fl3736_driver_t driver_buffers[IS31FL3736_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.led_control_buffer = {0},
.led_control_buffer_dirty = false,
}};
void is31fl3736_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3736_I2C_PERSISTENCE > 0
@ -94,10 +102,10 @@ void is31fl3736_write_pwm_buffer(uint8_t index) {
for (uint8_t i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3736_I2C_PERSISTENCE > 0
for (uint8_t j = 0; j < IS31FL3736_I2C_PERSISTENCE; j++) {
if (i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3736_I2C_TIMEOUT);
#endif
}
}
@ -160,14 +168,14 @@ void is31fl3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
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) {
if (driver_buffers[led.driver].pwm_buffer[led.r] == red && driver_buffers[led.driver].pwm_buffer[led.g] == green && driver_buffers[led.driver].pwm_buffer[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;
driver_buffers[led.driver].pwm_buffer[led.r] = red;
driver_buffers[led.driver].pwm_buffer[led.g] = green;
driver_buffers[led.driver].pwm_buffer[led.b] = blue;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -196,43 +204,43 @@ void is31fl3736_set_led_control_register(uint8_t index, bool red, bool green, bo
uint8_t bit_b = led.b % 8;
if (red) {
g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
driver_buffers[led.driver].led_control_buffer[control_register_r] |= (1 << bit_r);
} else {
g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
driver_buffers[led.driver].led_control_buffer[control_register_r] &= ~(1 << bit_r);
}
if (green) {
g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
driver_buffers[led.driver].led_control_buffer[control_register_g] |= (1 << bit_g);
} else {
g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
driver_buffers[led.driver].led_control_buffer[control_register_g] &= ~(1 << bit_g);
}
if (blue) {
g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
driver_buffers[led.driver].led_control_buffer[control_register_b] |= (1 << bit_b);
} else {
g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
driver_buffers[led.driver].led_control_buffer[control_register_b] &= ~(1 << bit_b);
}
g_led_control_registers_update_required[led.driver] = true;
driver_buffers[led.driver].led_control_buffer_dirty = true;
}
void is31fl3736_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3736_select_page(index, IS31FL3736_COMMAND_PWM);
is31fl3736_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3736_update_led_control_registers(uint8_t index) {
if (g_led_control_registers_update_required[index]) {
if (driver_buffers[index].led_control_buffer_dirty) {
is31fl3736_select_page(index, IS31FL3736_COMMAND_LED_CONTROL);
for (uint8_t i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3736_write_register(index, i, g_led_control_registers[index][i]);
is31fl3736_write_register(index, i, driver_buffers[index].led_control_buffer[i]);
}
g_led_control_registers_update_required[index] = false;
driver_buffers[index].led_control_buffer_dirty = false;
}
}

View File

@ -67,12 +67,19 @@ const uint8_t i2c_addresses[IS31FL3737_DRIVER_COUNT] = {
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3737_write_pwm_buffer() but it's
// probably not worth the extra complexity.
typedef struct is31fl3737_driver_t {
uint8_t pwm_buffer[IS31FL3737_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t led_control_buffer[IS31FL3737_LED_CONTROL_REGISTER_COUNT];
bool led_control_buffer_dirty;
} PACKED is31fl3737_driver_t;
uint8_t g_pwm_buffer[IS31FL3737_DRIVER_COUNT][IS31FL3737_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[IS31FL3737_DRIVER_COUNT] = {false};
uint8_t g_led_control_registers[IS31FL3737_DRIVER_COUNT][IS31FL3737_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required[IS31FL3737_DRIVER_COUNT] = {false};
is31fl3737_driver_t driver_buffers[IS31FL3737_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.led_control_buffer = {0},
.led_control_buffer_dirty = false,
}};
void is31fl3737_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3737_I2C_PERSISTENCE > 0
@ -97,10 +104,10 @@ void is31fl3737_write_pwm_buffer(uint8_t index) {
for (uint8_t i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3737_I2C_PERSISTENCE > 0
for (uint8_t j = 0; j < IS31FL3737_I2C_PERSISTENCE; j++) {
if (i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3737_I2C_TIMEOUT);
#endif
}
}
@ -163,12 +170,12 @@ void is31fl3737_set_value(int index, uint8_t value) {
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) {
if (driver_buffers[led.driver].pwm_buffer[led.v] == value) {
return;
}
g_pwm_buffer[led.driver][led.v] = value;
g_pwm_buffer_update_required[led.driver] = true;
driver_buffers[led.driver].pwm_buffer[led.v] = value;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -186,33 +193,33 @@ void is31fl3737_set_led_control_register(uint8_t index, bool value) {
uint8_t bit_value = led.v % 8;
if (value) {
g_led_control_registers[led.driver][control_register] |= (1 << bit_value);
driver_buffers[led.driver].led_control_buffer[control_register] |= (1 << bit_value);
} else {
g_led_control_registers[led.driver][control_register] &= ~(1 << bit_value);
driver_buffers[led.driver].led_control_buffer[control_register] &= ~(1 << bit_value);
}
g_led_control_registers_update_required[led.driver] = true;
driver_buffers[led.driver].led_control_buffer_dirty = true;
}
void is31fl3737_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3737_select_page(index, IS31FL3737_COMMAND_PWM);
is31fl3737_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3737_update_led_control_registers(uint8_t index) {
if (g_led_control_registers_update_required[index]) {
if (driver_buffers[index].led_control_buffer_dirty) {
is31fl3737_select_page(index, IS31FL3737_COMMAND_LED_CONTROL);
for (uint8_t i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3737_write_register(index, i, g_led_control_registers[index][i]);
is31fl3737_write_register(index, i, driver_buffers[index].led_control_buffer[i]);
}
g_led_control_registers_update_required[index] = false;
driver_buffers[index].led_control_buffer_dirty = false;
}
}

View File

@ -67,12 +67,19 @@ const uint8_t i2c_addresses[IS31FL3737_DRIVER_COUNT] = {
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3737_write_pwm_buffer() but it's
// probably not worth the extra complexity.
typedef struct is31fl3737_driver_t {
uint8_t pwm_buffer[IS31FL3737_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t led_control_buffer[IS31FL3737_LED_CONTROL_REGISTER_COUNT];
bool led_control_buffer_dirty;
} PACKED is31fl3737_driver_t;
uint8_t g_pwm_buffer[IS31FL3737_DRIVER_COUNT][IS31FL3737_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[IS31FL3737_DRIVER_COUNT] = {false};
uint8_t g_led_control_registers[IS31FL3737_DRIVER_COUNT][IS31FL3737_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required[IS31FL3737_DRIVER_COUNT] = {false};
is31fl3737_driver_t driver_buffers[IS31FL3737_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.led_control_buffer = {0},
.led_control_buffer_dirty = false,
}};
void is31fl3737_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3737_I2C_PERSISTENCE > 0
@ -97,10 +104,10 @@ void is31fl3737_write_pwm_buffer(uint8_t index) {
for (uint8_t i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3737_I2C_PERSISTENCE > 0
for (uint8_t j = 0; j < IS31FL3737_I2C_PERSISTENCE; j++) {
if (i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3737_I2C_TIMEOUT);
#endif
}
}
@ -163,14 +170,14 @@ void is31fl3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
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) {
if (driver_buffers[led.driver].pwm_buffer[led.r] == red && driver_buffers[led.driver].pwm_buffer[led.g] == green && driver_buffers[led.driver].pwm_buffer[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;
driver_buffers[led.driver].pwm_buffer[led.r] = red;
driver_buffers[led.driver].pwm_buffer[led.g] = green;
driver_buffers[led.driver].pwm_buffer[led.b] = blue;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -192,43 +199,43 @@ void is31fl3737_set_led_control_register(uint8_t index, bool red, bool green, bo
uint8_t bit_b = led.b % 8;
if (red) {
g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
driver_buffers[led.driver].led_control_buffer[control_register_r] |= (1 << bit_r);
} else {
g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
driver_buffers[led.driver].led_control_buffer[control_register_r] &= ~(1 << bit_r);
}
if (green) {
g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
driver_buffers[led.driver].led_control_buffer[control_register_g] |= (1 << bit_g);
} else {
g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
driver_buffers[led.driver].led_control_buffer[control_register_g] &= ~(1 << bit_g);
}
if (blue) {
g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
driver_buffers[led.driver].led_control_buffer[control_register_b] |= (1 << bit_b);
} else {
g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
driver_buffers[led.driver].led_control_buffer[control_register_b] &= ~(1 << bit_b);
}
g_led_control_registers_update_required[led.driver] = true;
driver_buffers[led.driver].led_control_buffer_dirty = true;
}
void is31fl3737_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3737_select_page(index, IS31FL3737_COMMAND_PWM);
is31fl3737_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3737_update_led_control_registers(uint8_t index) {
if (g_led_control_registers_update_required[index]) {
if (driver_buffers[index].led_control_buffer_dirty) {
is31fl3737_select_page(index, IS31FL3737_COMMAND_LED_CONTROL);
for (uint8_t i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3737_write_register(index, i, g_led_control_registers[index][i]);
is31fl3737_write_register(index, i, driver_buffers[index].led_control_buffer[i]);
}
g_led_control_registers_update_required[index] = false;
driver_buffers[index].led_control_buffer_dirty = false;
}
}

View File

@ -71,11 +71,19 @@ const uint8_t i2c_addresses[IS31FL3741_DRIVER_COUNT] = {
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3741_write_pwm_buffer() but it's
// probably not worth the extra complexity.
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};
typedef struct is31fl3741_driver_t {
uint8_t pwm_buffer[IS31FL3741_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t scaling_buffer[IS31FL3741_SCALING_REGISTER_COUNT];
bool scaling_buffer_dirty;
} PACKED is31fl3741_driver_t;
uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_SCALING_REGISTER_COUNT];
is31fl3741_driver_t driver_buffers[IS31FL3741_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.scaling_buffer = {0},
.scaling_buffer_dirty = false,
}};
void is31fl3741_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3741_I2C_PERSISTENCE > 0
@ -102,20 +110,20 @@ void is31fl3741_write_pwm_buffer(uint8_t index) {
#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t j = 0; j < IS31FL3741_I2C_PERSISTENCE; j++) {
if (i2c_write_register(i2c_addresses[index] << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i % 180, driver_buffers[index].pwm_buffer + i, 18, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i % 180, driver_buffers[index].pwm_buffer + i, 18, IS31FL3741_I2C_TIMEOUT);
#endif
}
// transfer the left cause the total number is 351
#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
if (i2c_write_register(i2c_addresses[index] << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, 162, driver_buffers[index].pwm_buffer + 342, 9, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, 162, driver_buffers[index].pwm_buffer + 342, 9, IS31FL3741_I2C_TIMEOUT);
#endif
}
@ -166,12 +174,12 @@ void is31fl3741_set_value(int index, uint8_t value) {
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) {
if (driver_buffers[led.driver].pwm_buffer[led.v] == value) {
return;
}
g_pwm_buffer_update_required[led.driver] = true;
g_pwm_buffer[led.driver][led.v] = value;
driver_buffers[led.driver].pwm_buffer[led.v] = value;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -186,52 +194,52 @@ void is31fl3741_set_led_control_register(uint8_t index, bool value) {
memcpy_P(&led, (&g_is31fl3741_leds[index]), sizeof(led));
if (value) {
g_scaling_registers[led.driver][led.v] = 0xFF;
driver_buffers[led.driver].scaling_buffer[led.v] = 0xFF;
} else {
g_scaling_registers[led.driver][led.v] = 0x00;
driver_buffers[led.driver].scaling_buffer[led.v] = 0x00;
}
g_scaling_registers_update_required[led.driver] = true;
driver_buffers[led.driver].scaling_buffer_dirty = true;
}
void is31fl3741_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3741_select_page(index, IS31FL3741_COMMAND_PWM_0);
is31fl3741_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = 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_update_required[pled->driver] = true;
driver_buffers[pled->driver].pwm_buffer[pled->v] = value;
driver_buffers[pled->driver].pwm_buffer_dirty = true;
}
void is31fl3741_update_led_control_registers(uint8_t index) {
if (g_scaling_registers_update_required[index]) {
if (driver_buffers[index].scaling_buffer_dirty) {
is31fl3741_select_page(index, IS31FL3741_COMMAND_SCALING_0);
// CS1_SW1 to CS30_SW6 are on page 2
for (int i = CS1_SW1; i <= CS30_SW6; ++i) {
is31fl3741_write_register(index, i, g_scaling_registers[index][i]);
is31fl3741_write_register(index, i, driver_buffers[index].scaling_buffer[i]);
}
is31fl3741_select_page(index, IS31FL3741_COMMAND_SCALING_1);
// CS1_SW7 to CS39_SW9 are on page 3
for (int i = CS1_SW7; i <= CS39_SW9; ++i) {
is31fl3741_write_register(index, i - CS1_SW7, g_scaling_registers[index][i]);
is31fl3741_write_register(index, i - CS1_SW7, driver_buffers[index].scaling_buffer[i]);
}
g_scaling_registers_update_required[index] = false;
driver_buffers[index].scaling_buffer_dirty = false;
}
}
void is31fl3741_set_scaling_registers(const is31fl3741_led_t *pled, uint8_t value) {
g_scaling_registers[pled->driver][pled->v] = value;
g_scaling_registers_update_required[pled->driver] = true;
driver_buffers[pled->driver].scaling_buffer[pled->v] = value;
driver_buffers[pled->driver].scaling_buffer_dirty = true;
}
void is31fl3741_flush(void) {

View File

@ -71,11 +71,19 @@ const uint8_t i2c_addresses[IS31FL3741_DRIVER_COUNT] = {
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3741_write_pwm_buffer() but it's
// probably not worth the extra complexity.
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};
typedef struct is31fl3741_driver_t {
uint8_t pwm_buffer[IS31FL3741_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t scaling_buffer[IS31FL3741_SCALING_REGISTER_COUNT];
bool scaling_buffer_dirty;
} PACKED is31fl3741_driver_t;
uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_SCALING_REGISTER_COUNT];
is31fl3741_driver_t driver_buffers[IS31FL3741_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.scaling_buffer = {0},
.scaling_buffer_dirty = false,
}};
void is31fl3741_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3741_I2C_PERSISTENCE > 0
@ -102,20 +110,20 @@ void is31fl3741_write_pwm_buffer(uint8_t index) {
#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t j = 0; j < IS31FL3741_I2C_PERSISTENCE; j++) {
if (i2c_write_register(i2c_addresses[index] << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i % 180, driver_buffers[index].pwm_buffer + i, 18, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i % 180, driver_buffers[index].pwm_buffer + i, 18, IS31FL3741_I2C_TIMEOUT);
#endif
}
// transfer the left cause the total number is 351
#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
if (i2c_write_register(i2c_addresses[index] << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, 162, driver_buffers[index].pwm_buffer + 342, 9, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, 162, driver_buffers[index].pwm_buffer + 342, 9, IS31FL3741_I2C_TIMEOUT);
#endif
}
@ -166,14 +174,14 @@ void is31fl3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
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) {
if (driver_buffers[led.driver].pwm_buffer[led.r] == red && driver_buffers[led.driver].pwm_buffer[led.g] == green && driver_buffers[led.driver].pwm_buffer[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;
driver_buffers[led.driver].pwm_buffer[led.r] = red;
driver_buffers[led.driver].pwm_buffer[led.g] = green;
driver_buffers[led.driver].pwm_buffer[led.b] = blue;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -188,68 +196,68 @@ void is31fl3741_set_led_control_register(uint8_t index, bool red, bool green, bo
memcpy_P(&led, (&g_is31fl3741_leds[index]), sizeof(led));
if (red) {
g_scaling_registers[led.driver][led.r] = 0xFF;
driver_buffers[led.driver].scaling_buffer[led.r] = 0xFF;
} else {
g_scaling_registers[led.driver][led.r] = 0x00;
driver_buffers[led.driver].scaling_buffer[led.r] = 0x00;
}
if (green) {
g_scaling_registers[led.driver][led.g] = 0xFF;
driver_buffers[led.driver].scaling_buffer[led.g] = 0xFF;
} else {
g_scaling_registers[led.driver][led.g] = 0x00;
driver_buffers[led.driver].scaling_buffer[led.g] = 0x00;
}
if (blue) {
g_scaling_registers[led.driver][led.b] = 0xFF;
driver_buffers[led.driver].scaling_buffer[led.b] = 0xFF;
} else {
g_scaling_registers[led.driver][led.b] = 0x00;
driver_buffers[led.driver].scaling_buffer[led.b] = 0x00;
}
g_scaling_registers_update_required[led.driver] = true;
driver_buffers[led.driver].scaling_buffer_dirty = true;
}
void is31fl3741_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3741_select_page(index, IS31FL3741_COMMAND_PWM_0);
is31fl3741_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = 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_update_required[pled->driver] = true;
driver_buffers[pled->driver].pwm_buffer[pled->r] = red;
driver_buffers[pled->driver].pwm_buffer[pled->g] = green;
driver_buffers[pled->driver].pwm_buffer[pled->b] = blue;
driver_buffers[pled->driver].pwm_buffer_dirty = true;
}
void is31fl3741_update_led_control_registers(uint8_t index) {
if (g_scaling_registers_update_required[index]) {
if (driver_buffers[index].scaling_buffer_dirty) {
is31fl3741_select_page(index, IS31FL3741_COMMAND_SCALING_0);
// CS1_SW1 to CS30_SW6 are on page 2
for (int i = CS1_SW1; i <= CS30_SW6; ++i) {
is31fl3741_write_register(index, i, g_scaling_registers[index][i]);
is31fl3741_write_register(index, i, driver_buffers[index].scaling_buffer[i]);
}
is31fl3741_select_page(index, IS31FL3741_COMMAND_SCALING_1);
// CS1_SW7 to CS39_SW9 are on page 3
for (int i = CS1_SW7; i <= CS39_SW9; ++i) {
is31fl3741_write_register(index, i - CS1_SW7, g_scaling_registers[index][i]);
is31fl3741_write_register(index, i - CS1_SW7, driver_buffers[index].scaling_buffer[i]);
}
g_scaling_registers_update_required[index] = false;
driver_buffers[index].scaling_buffer_dirty = false;
}
}
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_update_required[pled->driver] = true;
driver_buffers[pled->driver].scaling_buffer[pled->r] = red;
driver_buffers[pled->driver].scaling_buffer[pled->g] = green;
driver_buffers[pled->driver].scaling_buffer[pled->b] = blue;
driver_buffers[pled->driver].scaling_buffer_dirty = true;
}
void is31fl3741_flush(void) {

View File

@ -66,11 +66,19 @@ const uint8_t i2c_addresses[IS31FL3742A_DRIVER_COUNT] = {
#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};
typedef struct is31fl3742a_driver_t {
uint8_t pwm_buffer[IS31FL3742A_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t scaling_buffer[IS31FL3742A_SCALING_REGISTER_COUNT];
bool scaling_buffer_dirty;
} PACKED is31fl3742a_driver_t;
uint8_t g_scaling_registers[IS31FL3742A_DRIVER_COUNT][IS31FL3742A_SCALING_REGISTER_COUNT];
is31fl3742a_driver_t driver_buffers[IS31FL3742A_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.scaling_buffer = {0},
.scaling_buffer_dirty = false,
}};
void is31fl3742a_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3742A_I2C_PERSISTENCE > 0
@ -95,10 +103,10 @@ void is31fl3742a_write_pwm_buffer(uint8_t index) {
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(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 30, IS31FL3742A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 30, IS31FL3742A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 30, IS31FL3742A_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 30, IS31FL3742A_I2C_TIMEOUT);
#endif
}
}
@ -155,12 +163,12 @@ void is31fl3742a_set_value(int index, uint8_t value) {
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) {
if (driver_buffers[led.driver].pwm_buffer[led.v] == value) {
return;
}
g_pwm_buffer[led.driver][led.v] = value;
g_pwm_buffer_update_required[led.driver] = true;
driver_buffers[led.driver].pwm_buffer[led.v] = value;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -174,29 +182,29 @@ 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;
driver_buffers[led.driver].scaling_buffer[led.v] = value;
driver_buffers[led.driver].scaling_buffer_dirty = true;
}
void is31fl3742a_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3742a_select_page(index, IS31FL3742A_COMMAND_PWM);
is31fl3742a_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3742a_update_scaling_registers(uint8_t index) {
if (g_scaling_registers_update_required[index]) {
if (driver_buffers[index].scaling_buffer_dirty) {
is31fl3742a_select_page(index, IS31FL3742A_COMMAND_SCALING);
for (uint8_t i = 0; i < IS31FL3742A_SCALING_REGISTER_COUNT; i++) {
is31fl3742a_write_register(index, i, g_scaling_registers[index][i]);
is31fl3742a_write_register(index, i, driver_buffers[index].scaling_buffer[i]);
}
g_scaling_registers_update_required[index] = false;
driver_buffers[index].scaling_buffer_dirty = false;
}
}

View File

@ -66,11 +66,19 @@ const uint8_t i2c_addresses[IS31FL3742A_DRIVER_COUNT] = {
#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};
typedef struct is31fl3742a_driver_t {
uint8_t pwm_buffer[IS31FL3742A_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t scaling_buffer[IS31FL3742A_SCALING_REGISTER_COUNT];
bool scaling_buffer_dirty;
} PACKED is31fl3742a_driver_t;
uint8_t g_scaling_registers[IS31FL3742A_DRIVER_COUNT][IS31FL3742A_SCALING_REGISTER_COUNT];
is31fl3742a_driver_t driver_buffers[IS31FL3742A_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.scaling_buffer = {0},
.scaling_buffer_dirty = false,
}};
void is31fl3742a_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3742A_I2C_PERSISTENCE > 0
@ -95,10 +103,10 @@ void is31fl3742a_write_pwm_buffer(uint8_t index) {
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(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 30, IS31FL3742A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 30, IS31FL3742A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 30, IS31FL3742A_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 30, IS31FL3742A_I2C_TIMEOUT);
#endif
}
}
@ -155,14 +163,14 @@ void is31fl3742a_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)
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) {
if (driver_buffers[led.driver].pwm_buffer[led.r] == red && driver_buffers[led.driver].pwm_buffer[led.g] == green && driver_buffers[led.driver].pwm_buffer[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;
driver_buffers[led.driver].pwm_buffer[led.r] = red;
driver_buffers[led.driver].pwm_buffer[led.g] = green;
driver_buffers[led.driver].pwm_buffer[led.b] = blue;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -176,31 +184,31 @@ void is31fl3742a_set_scaling_register(uint8_t index, uint8_t red, uint8_t green,
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;
driver_buffers[led.driver].scaling_buffer[led.r] = red;
driver_buffers[led.driver].scaling_buffer[led.g] = green;
driver_buffers[led.driver].scaling_buffer[led.b] = blue;
driver_buffers[led.driver].scaling_buffer_dirty = true;
}
void is31fl3742a_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3742a_select_page(index, IS31FL3742A_COMMAND_PWM);
is31fl3742a_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3742a_update_scaling_registers(uint8_t index) {
if (g_scaling_registers_update_required[index]) {
if (driver_buffers[index].scaling_buffer_dirty) {
is31fl3742a_select_page(index, IS31FL3742A_COMMAND_SCALING);
for (uint8_t i = 0; i < IS31FL3742A_SCALING_REGISTER_COUNT; i++) {
is31fl3742a_write_register(index, i, g_scaling_registers[index][i]);
is31fl3742a_write_register(index, i, driver_buffers[index].scaling_buffer[i]);
}
g_scaling_registers_update_required[index] = false;
driver_buffers[index].scaling_buffer_dirty = false;
}
}

View File

@ -88,11 +88,19 @@ const uint8_t driver_sync[IS31FL3743A_DRIVER_COUNT] = {
#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};
typedef struct is31fl3743a_driver_t {
uint8_t pwm_buffer[IS31FL3743A_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t scaling_buffer[IS31FL3743A_SCALING_REGISTER_COUNT];
bool scaling_buffer_dirty;
} PACKED is31fl3743a_driver_t;
uint8_t g_scaling_registers[IS31FL3743A_DRIVER_COUNT][IS31FL3743A_SCALING_REGISTER_COUNT];
is31fl3743a_driver_t driver_buffers[IS31FL3743A_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.scaling_buffer = {0},
.scaling_buffer_dirty = false,
}};
void is31fl3743a_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3743A_I2C_PERSISTENCE > 0
@ -117,10 +125,10 @@ void is31fl3743a_write_pwm_buffer(uint8_t index) {
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(i2c_addresses[index] << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3743A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i + 1, driver_buffers[index].pwm_buffer + i, 18, IS31FL3743A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3743A_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i + 1, driver_buffers[index].pwm_buffer + i, 18, IS31FL3743A_I2C_TIMEOUT);
#endif
}
}
@ -179,12 +187,12 @@ void is31fl3743a_set_value(int index, uint8_t value) {
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) {
if (driver_buffers[led.driver].pwm_buffer[led.v] == value) {
return;
}
g_pwm_buffer_update_required[led.driver] = true;
g_pwm_buffer[led.driver][led.v] = value;
driver_buffers[led.driver].pwm_buffer[led.v] = value;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -198,29 +206,29 @@ 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;
driver_buffers[led.driver].scaling_buffer[led.v] = value;
driver_buffers[led.driver].scaling_buffer_dirty = true;
}
void is31fl3743a_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3743a_select_page(index, IS31FL3743A_COMMAND_PWM);
is31fl3743a_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3743a_update_scaling_registers(uint8_t index) {
if (g_scaling_registers_update_required[index]) {
if (driver_buffers[index].scaling_buffer_dirty) {
is31fl3743a_select_page(index, IS31FL3743A_COMMAND_SCALING);
for (uint8_t i = 0; i < IS31FL3743A_SCALING_REGISTER_COUNT; i++) {
is31fl3743a_write_register(index, i + 1, g_scaling_registers[index][i]);
is31fl3743a_write_register(index, i + 1, driver_buffers[index].scaling_buffer[i]);
}
g_scaling_registers_update_required[index] = false;
driver_buffers[index].scaling_buffer_dirty = false;
}
}

View File

@ -88,11 +88,19 @@ const uint8_t driver_sync[IS31FL3743A_DRIVER_COUNT] = {
#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};
typedef struct is31fl3743a_driver_t {
uint8_t pwm_buffer[IS31FL3743A_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t scaling_buffer[IS31FL3743A_SCALING_REGISTER_COUNT];
bool scaling_buffer_dirty;
} PACKED is31fl3743a_driver_t;
uint8_t g_scaling_registers[IS31FL3743A_DRIVER_COUNT][IS31FL3743A_SCALING_REGISTER_COUNT];
is31fl3743a_driver_t driver_buffers[IS31FL3743A_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.scaling_buffer = {0},
.scaling_buffer_dirty = false,
}};
void is31fl3743a_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3743A_I2C_PERSISTENCE > 0
@ -117,10 +125,10 @@ void is31fl3743a_write_pwm_buffer(uint8_t index) {
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(i2c_addresses[index] << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3743A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i + 1, driver_buffers[index].pwm_buffer + i, 18, IS31FL3743A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3743A_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i + 1, driver_buffers[index].pwm_buffer + i, 18, IS31FL3743A_I2C_TIMEOUT);
#endif
}
}
@ -179,14 +187,14 @@ void is31fl3743a_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)
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) {
if (driver_buffers[led.driver].pwm_buffer[led.r] == red && driver_buffers[led.driver].pwm_buffer[led.g] == green && driver_buffers[led.driver].pwm_buffer[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;
driver_buffers[led.driver].pwm_buffer[led.r] = red;
driver_buffers[led.driver].pwm_buffer[led.g] = green;
driver_buffers[led.driver].pwm_buffer[led.b] = blue;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -200,31 +208,31 @@ void is31fl3743a_set_scaling_register(uint8_t index, uint8_t red, uint8_t green,
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;
driver_buffers[led.driver].scaling_buffer[led.r] = red;
driver_buffers[led.driver].scaling_buffer[led.g] = green;
driver_buffers[led.driver].scaling_buffer[led.b] = blue;
driver_buffers[led.driver].scaling_buffer_dirty = true;
}
void is31fl3743a_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3743a_select_page(index, IS31FL3743A_COMMAND_PWM);
is31fl3743a_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3743a_update_scaling_registers(uint8_t index) {
if (g_scaling_registers_update_required[index]) {
if (driver_buffers[index].scaling_buffer_dirty) {
is31fl3743a_select_page(index, IS31FL3743A_COMMAND_SCALING);
for (uint8_t i = 0; i < IS31FL3743A_SCALING_REGISTER_COUNT; i++) {
is31fl3743a_write_register(index, i + 1, g_scaling_registers[index][i]);
is31fl3743a_write_register(index, i + 1, driver_buffers[index].scaling_buffer[i]);
}
g_scaling_registers_update_required[index] = false;
driver_buffers[index].scaling_buffer_dirty = false;
}
}

View File

@ -88,11 +88,19 @@ const uint8_t driver_sync[IS31FL3745_DRIVER_COUNT] = {
#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};
typedef struct is31fl3745_driver_t {
uint8_t pwm_buffer[IS31FL3745_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t scaling_buffer[IS31FL3745_SCALING_REGISTER_COUNT];
bool scaling_buffer_dirty;
} PACKED is31fl3745_driver_t;
uint8_t g_scaling_registers[IS31FL3745_DRIVER_COUNT][IS31FL3745_SCALING_REGISTER_COUNT];
is31fl3745_driver_t driver_buffers[IS31FL3745_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.scaling_buffer = {0},
.scaling_buffer_dirty = false,
}};
void is31fl3745_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3745_I2C_PERSISTENCE > 0
@ -117,10 +125,10 @@ void is31fl3745_write_pwm_buffer(uint8_t index) {
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(i2c_addresses[index] << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3745_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i + 1, driver_buffers[index].pwm_buffer + i, 18, IS31FL3745_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3745_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i + 1, driver_buffers[index].pwm_buffer + i, 18, IS31FL3745_I2C_TIMEOUT);
#endif
}
}
@ -179,12 +187,12 @@ void is31fl3745_set_value(int index, uint8_t value) {
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) {
if (driver_buffers[led.driver].pwm_buffer[led.v] == value) {
return;
}
g_pwm_buffer_update_required[led.driver] = true;
g_pwm_buffer[led.driver][led.v] = value;
driver_buffers[led.driver].pwm_buffer[led.v] = value;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -198,29 +206,29 @@ 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;
driver_buffers[led.driver].scaling_buffer[led.v] = value;
driver_buffers[led.driver].scaling_buffer_dirty = true;
}
void is31fl3745_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3745_select_page(index, IS31FL3745_COMMAND_PWM);
is31fl3745_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3745_update_scaling_registers(uint8_t index) {
if (g_scaling_registers_update_required[index]) {
if (driver_buffers[index].scaling_buffer_dirty) {
is31fl3745_select_page(index, IS31FL3745_COMMAND_SCALING);
for (uint8_t i = 0; i < IS31FL3745_SCALING_REGISTER_COUNT; i++) {
is31fl3745_write_register(index, i + 1, g_scaling_registers[index][i]);
is31fl3745_write_register(index, i + 1, driver_buffers[index].scaling_buffer[i]);
}
g_scaling_registers_update_required[index] = false;
driver_buffers[index].scaling_buffer_dirty = false;
}
}

View File

@ -88,11 +88,19 @@ const uint8_t driver_sync[IS31FL3745_DRIVER_COUNT] = {
#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};
typedef struct is31fl3745_driver_t {
uint8_t pwm_buffer[IS31FL3745_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t scaling_buffer[IS31FL3745_SCALING_REGISTER_COUNT];
bool scaling_buffer_dirty;
} PACKED is31fl3745_driver_t;
uint8_t g_scaling_registers[IS31FL3745_DRIVER_COUNT][IS31FL3745_SCALING_REGISTER_COUNT];
is31fl3745_driver_t driver_buffers[IS31FL3745_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.scaling_buffer = {0},
.scaling_buffer_dirty = false,
}};
void is31fl3745_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3745_I2C_PERSISTENCE > 0
@ -117,10 +125,10 @@ void is31fl3745_write_pwm_buffer(uint8_t index) {
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(i2c_addresses[index] << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3745_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i + 1, driver_buffers[index].pwm_buffer + i, 18, IS31FL3745_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3745_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i + 1, driver_buffers[index].pwm_buffer + i, 18, IS31FL3745_I2C_TIMEOUT);
#endif
}
}
@ -179,14 +187,14 @@ void is31fl3745_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
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) {
if (driver_buffers[led.driver].pwm_buffer[led.r] == red && driver_buffers[led.driver].pwm_buffer[led.g] == green && driver_buffers[led.driver].pwm_buffer[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;
driver_buffers[led.driver].pwm_buffer[led.r] = red;
driver_buffers[led.driver].pwm_buffer[led.g] = green;
driver_buffers[led.driver].pwm_buffer[led.b] = blue;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -200,31 +208,31 @@ void is31fl3745_set_scaling_register(uint8_t index, uint8_t red, uint8_t green,
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;
driver_buffers[led.driver].scaling_buffer[led.r] = red;
driver_buffers[led.driver].scaling_buffer[led.g] = green;
driver_buffers[led.driver].scaling_buffer[led.b] = blue;
driver_buffers[led.driver].scaling_buffer_dirty = true;
}
void is31fl3745_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3745_select_page(index, IS31FL3745_COMMAND_PWM);
is31fl3745_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3745_update_scaling_registers(uint8_t index) {
if (g_scaling_registers_update_required[index]) {
if (driver_buffers[index].scaling_buffer_dirty) {
is31fl3745_select_page(index, IS31FL3745_COMMAND_SCALING);
for (uint8_t i = 0; i < IS31FL3745_SCALING_REGISTER_COUNT; i++) {
is31fl3745_write_register(index, i + 1, g_scaling_registers[index][i]);
is31fl3745_write_register(index, i + 1, driver_buffers[index].scaling_buffer[i]);
}
g_scaling_registers_update_required[index] = false;
driver_buffers[index].scaling_buffer_dirty = false;
}
}

View File

@ -66,11 +66,19 @@ const uint8_t i2c_addresses[IS31FL3746A_DRIVER_COUNT] = {
#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};
typedef struct is31fl3746a_driver_t {
uint8_t pwm_buffer[IS31FL3746A_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t scaling_buffer[IS31FL3746A_SCALING_REGISTER_COUNT];
bool scaling_buffer_dirty;
} PACKED is31fl3746a_driver_t;
uint8_t g_scaling_registers[IS31FL3746A_DRIVER_COUNT][IS31FL3746A_SCALING_REGISTER_COUNT];
is31fl3746a_driver_t driver_buffers[IS31FL3746A_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.scaling_buffer = {0},
.scaling_buffer_dirty = false,
}};
void is31fl3746a_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3746A_I2C_PERSISTENCE > 0
@ -95,10 +103,10 @@ void is31fl3746a_write_pwm_buffer(uint8_t index) {
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(i2c_addresses[index] << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3746A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i + 1, driver_buffers[index].pwm_buffer + i, 18, IS31FL3746A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3746A_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i + 1, driver_buffers[index].pwm_buffer + i, 18, IS31FL3746A_I2C_TIMEOUT);
#endif
}
}
@ -156,12 +164,12 @@ void is31fl3746a_set_value(int index, uint8_t value) {
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) {
if (driver_buffers[led.driver].pwm_buffer[led.v] == value) {
return;
}
g_pwm_buffer_update_required[led.driver] = true;
g_pwm_buffer[led.driver][led.v] = value;
driver_buffers[led.driver].pwm_buffer[led.v] = value;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -175,29 +183,29 @@ 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;
driver_buffers[led.driver].scaling_buffer[led.v] = value;
driver_buffers[led.driver].scaling_buffer_dirty = true;
}
void is31fl3746a_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3746a_select_page(index, IS31FL3746A_COMMAND_PWM);
is31fl3746a_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3746a_update_scaling_registers(uint8_t index) {
if (g_scaling_registers_update_required[index]) {
if (driver_buffers[index].scaling_buffer_dirty) {
is31fl3746a_select_page(index, IS31FL3746A_COMMAND_SCALING);
for (uint8_t i = 0; i < IS31FL3746A_SCALING_REGISTER_COUNT; i++) {
is31fl3746a_write_register(index, i + 1, g_scaling_registers[index][i]);
is31fl3746a_write_register(index, i + 1, driver_buffers[index].scaling_buffer[i]);
}
g_scaling_registers_update_required[index] = false;
driver_buffers[index].scaling_buffer_dirty = false;
}
}

View File

@ -66,11 +66,19 @@ const uint8_t i2c_addresses[IS31FL3746A_DRIVER_COUNT] = {
#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};
typedef struct is31fl3746a_driver_t {
uint8_t pwm_buffer[IS31FL3746A_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t scaling_buffer[IS31FL3746A_SCALING_REGISTER_COUNT];
bool scaling_buffer_dirty;
} PACKED is31fl3746a_driver_t;
uint8_t g_scaling_registers[IS31FL3746A_DRIVER_COUNT][IS31FL3746A_SCALING_REGISTER_COUNT];
is31fl3746a_driver_t driver_buffers[IS31FL3746A_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.scaling_buffer = {0},
.scaling_buffer_dirty = false,
}};
void is31fl3746a_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3746A_I2C_PERSISTENCE > 0
@ -95,10 +103,10 @@ void is31fl3746a_write_pwm_buffer(uint8_t index) {
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(i2c_addresses[index] << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3746A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i + 1, driver_buffers[index].pwm_buffer + i, 18, IS31FL3746A_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i + 1, g_pwm_buffer[index] + i, 18, IS31FL3746A_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i + 1, driver_buffers[index].pwm_buffer + i, 18, IS31FL3746A_I2C_TIMEOUT);
#endif
}
}
@ -156,14 +164,14 @@ void is31fl3746a_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)
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) {
if (driver_buffers[led.driver].pwm_buffer[led.r] == red && driver_buffers[led.driver].pwm_buffer[led.g] == green && driver_buffers[led.driver].pwm_buffer[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;
driver_buffers[led.driver].pwm_buffer[led.r] = red;
driver_buffers[led.driver].pwm_buffer[led.g] = green;
driver_buffers[led.driver].pwm_buffer[led.b] = blue;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -177,31 +185,31 @@ void is31fl3746a_set_scaling_register(uint8_t index, uint8_t red, uint8_t green,
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;
driver_buffers[led.driver].scaling_buffer[led.r] = red;
driver_buffers[led.driver].scaling_buffer[led.g] = green;
driver_buffers[led.driver].scaling_buffer[led.b] = blue;
driver_buffers[led.driver].scaling_buffer_dirty = true;
}
void is31fl3746a_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3746a_select_page(index, IS31FL3746A_COMMAND_PWM);
is31fl3746a_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3746a_update_scaling_registers(uint8_t index) {
if (g_scaling_registers_update_required[index]) {
if (driver_buffers[index].scaling_buffer_dirty) {
is31fl3746a_select_page(index, IS31FL3746A_COMMAND_SCALING);
for (uint8_t i = 0; i < IS31FL3746A_SCALING_REGISTER_COUNT; i++) {
is31fl3746a_write_register(index, i + 1, g_scaling_registers[index][i]);
is31fl3746a_write_register(index, i + 1, driver_buffers[index].scaling_buffer[i]);
}
g_scaling_registers_update_required[index] = false;
driver_buffers[index].scaling_buffer_dirty = false;
}
}

View File

@ -56,11 +56,19 @@ const uint8_t i2c_addresses[SNLED27351_DRIVER_COUNT] = {
// We could optimize this and take out the unused registers from these
// buffers and the transfers in snled27351_write_pwm_buffer() but it's
// probably not worth the extra complexity.
uint8_t g_pwm_buffer[SNLED27351_DRIVER_COUNT][SNLED27351_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[SNLED27351_DRIVER_COUNT] = {false};
typedef struct snled27351_driver_t {
uint8_t pwm_buffer[SNLED27351_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t led_control_buffer[SNLED27351_LED_CONTROL_REGISTER_COUNT];
bool led_control_buffer_dirty;
} PACKED snled27351_driver_t;
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};
snled27351_driver_t driver_buffers[SNLED27351_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.led_control_buffer = {0},
.led_control_buffer_dirty = false,
}};
void snled27351_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if SNLED27351_I2C_PERSISTENCE > 0
@ -84,10 +92,10 @@ void snled27351_write_pwm_buffer(uint8_t index) {
for (uint8_t i = 0; i < SNLED27351_PWM_REGISTER_COUNT; i += 16) {
#if SNLED27351_I2C_PERSISTENCE > 0
for (uint8_t j = 0; j < SNLED27351_I2C_PERSISTENCE; j++) {
if (i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, SNLED27351_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, SNLED27351_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, SNLED27351_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, SNLED27351_I2C_TIMEOUT);
#endif
}
}
@ -160,12 +168,12 @@ void snled27351_set_value(int index, uint8_t value) {
if (index >= 0 && index < SNLED27351_LED_COUNT) {
memcpy_P(&led, (&g_snled27351_leds[index]), sizeof(led));
if (g_pwm_buffer[led.driver][led.v] == value) {
if (driver_buffers[led.driver].pwm_buffer[led.v] == value) {
return;
}
g_pwm_buffer[led.driver][led.v] = value;
g_pwm_buffer_update_required[led.driver] = true;
driver_buffers[led.driver].pwm_buffer[led.v] = value;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -183,33 +191,33 @@ void snled27351_set_led_control_register(uint8_t index, bool value) {
uint8_t bit_value = led.v % 8;
if (value) {
g_led_control_registers[led.driver][control_register] |= (1 << bit_value);
driver_buffers[led.driver].led_control_buffer[control_register] |= (1 << bit_value);
} else {
g_led_control_registers[led.driver][control_register] &= ~(1 << bit_value);
driver_buffers[led.driver].led_control_buffer[control_register] &= ~(1 << bit_value);
}
g_led_control_registers_update_required[led.driver] = true;
driver_buffers[led.driver].led_control_buffer_dirty = true;
}
void snled27351_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
snled27351_select_page(index, SNLED27351_COMMAND_PWM);
snled27351_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void snled27351_update_led_control_registers(uint8_t index) {
if (g_led_control_registers_update_required[index]) {
if (driver_buffers[index].led_control_buffer_dirty) {
snled27351_select_page(index, SNLED27351_COMMAND_LED_CONTROL);
for (uint8_t i = 0; i < SNLED27351_LED_CONTROL_REGISTER_COUNT; i++) {
snled27351_write_register(index, i, g_led_control_registers[index][i]);
snled27351_write_register(index, i, driver_buffers[index].led_control_buffer[i]);
}
g_led_control_registers_update_required[index] = false;
driver_buffers[index].led_control_buffer_dirty = false;
}
}

View File

@ -56,11 +56,19 @@ const uint8_t i2c_addresses[SNLED27351_DRIVER_COUNT] = {
// We could optimize this and take out the unused registers from these
// buffers and the transfers in snled27351_write_pwm_buffer() but it's
// probably not worth the extra complexity.
uint8_t g_pwm_buffer[SNLED27351_DRIVER_COUNT][SNLED27351_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[SNLED27351_DRIVER_COUNT] = {false};
typedef struct snled27351_driver_t {
uint8_t pwm_buffer[SNLED27351_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t led_control_buffer[SNLED27351_LED_CONTROL_REGISTER_COUNT];
bool led_control_buffer_dirty;
} PACKED snled27351_driver_t;
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};
snled27351_driver_t driver_buffers[SNLED27351_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.led_control_buffer = {0},
.led_control_buffer_dirty = false,
}};
void snled27351_write_register(uint8_t index, uint8_t reg, uint8_t data) {
#if SNLED27351_I2C_PERSISTENCE > 0
@ -84,10 +92,10 @@ void snled27351_write_pwm_buffer(uint8_t index) {
for (uint8_t i = 0; i < SNLED27351_PWM_REGISTER_COUNT; i += 16) {
#if SNLED27351_I2C_PERSISTENCE > 0
for (uint8_t j = 0; j < SNLED27351_I2C_PERSISTENCE; j++) {
if (i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, SNLED27351_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, SNLED27351_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, SNLED27351_I2C_TIMEOUT);
i2c_write_register(i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, SNLED27351_I2C_TIMEOUT);
#endif
}
}
@ -160,14 +168,14 @@ void snled27351_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
if (index >= 0 && index < SNLED27351_LED_COUNT) {
memcpy_P(&led, (&g_snled27351_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) {
if (driver_buffers[led.driver].pwm_buffer[led.r] == red && driver_buffers[led.driver].pwm_buffer[led.g] == green && driver_buffers[led.driver].pwm_buffer[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;
driver_buffers[led.driver].pwm_buffer[led.r] = red;
driver_buffers[led.driver].pwm_buffer[led.g] = green;
driver_buffers[led.driver].pwm_buffer[led.b] = blue;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -189,43 +197,43 @@ void snled27351_set_led_control_register(uint8_t index, bool red, bool green, bo
uint8_t bit_b = led.b % 8;
if (red) {
g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
driver_buffers[led.driver].led_control_buffer[control_register_r] |= (1 << bit_r);
} else {
g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
driver_buffers[led.driver].led_control_buffer[control_register_r] &= ~(1 << bit_r);
}
if (green) {
g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
driver_buffers[led.driver].led_control_buffer[control_register_g] |= (1 << bit_g);
} else {
g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
driver_buffers[led.driver].led_control_buffer[control_register_g] &= ~(1 << bit_g);
}
if (blue) {
g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
driver_buffers[led.driver].led_control_buffer[control_register_b] |= (1 << bit_b);
} else {
g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
driver_buffers[led.driver].led_control_buffer[control_register_b] &= ~(1 << bit_b);
}
g_led_control_registers_update_required[led.driver] = true;
driver_buffers[led.driver].led_control_buffer_dirty = true;
}
void snled27351_update_pwm_buffers(uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
snled27351_select_page(index, SNLED27351_COMMAND_PWM);
snled27351_write_pwm_buffer(index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void snled27351_update_led_control_registers(uint8_t index) {
if (g_led_control_registers_update_required[index]) {
if (driver_buffers[index].led_control_buffer_dirty) {
snled27351_select_page(index, SNLED27351_COMMAND_LED_CONTROL);
for (uint8_t i = 0; i < SNLED27351_LED_CONTROL_REGISTER_COUNT; i++) {
snled27351_write_register(index, i, g_led_control_registers[index][i]);
snled27351_write_register(index, i, driver_buffers[index].led_control_buffer[i]);
}
g_led_control_registers_update_required[index] = false;
driver_buffers[index].led_control_buffer_dirty = false;
}
}

View File

@ -80,11 +80,19 @@ const uint8_t driver_sync[IS31FL3733_DRIVER_COUNT] = {
// We could optimize this and take out the unused registers from these
// buffers and the transfers in is31fl3733_write_pwm_buffer() but it's
// probably not worth the extra complexity.
uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][IS31FL3733_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false};
typedef struct is31fl3733_driver_t {
uint8_t pwm_buffer[IS31FL3733_PWM_REGISTER_COUNT];
bool pwm_buffer_dirty;
uint8_t led_control_buffer[IS31FL3733_LED_CONTROL_REGISTER_COUNT];
bool led_control_buffer_dirty;
} PACKED is31fl3733_driver_t;
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};
is31fl3733_driver_t driver_buffers[IS31FL3733_DRIVER_COUNT] = {{
.pwm_buffer = {0},
.pwm_buffer_dirty = false,
.led_control_buffer = {0},
.led_control_buffer_dirty = false,
}};
void is31fl3733_write_register(uint8_t bus, uint8_t index, uint8_t reg, uint8_t data) {
#if IS31FL3733_I2C_PERSISTENCE > 0
@ -109,10 +117,10 @@ void is31fl3733_write_pwm_buffer(uint8_t bus, uint8_t index) {
for (uint8_t i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
#if IS31FL3733_I2C_PERSISTENCE > 0
for (uint8_t j = 0; j < IS31FL3733_I2C_PERSISTENCE; j++) {
if (i2c_write_register(bus, i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_write_register(bus, i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_write_register(bus, i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT);
i2c_write_register(bus, i2c_addresses[index] << 1, i, driver_buffers[index].pwm_buffer + i, 16, IS31FL3733_I2C_TIMEOUT);
#endif
}
}
@ -180,14 +188,14 @@ void is31fl3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
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) {
if (driver_buffers[led.driver].pwm_buffer[led.r] == red && driver_buffers[led.driver].pwm_buffer[led.g] == green && driver_buffers[led.driver].pwm_buffer[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;
driver_buffers[led.driver].pwm_buffer[led.r] = red;
driver_buffers[led.driver].pwm_buffer[led.g] = green;
driver_buffers[led.driver].pwm_buffer[led.b] = blue;
driver_buffers[led.driver].pwm_buffer_dirty = true;
}
}
@ -209,43 +217,43 @@ void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bo
uint8_t bit_b = led.b % 8;
if (red) {
g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
driver_buffers[led.driver].led_control_buffer[control_register_r] |= (1 << bit_r);
} else {
g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
driver_buffers[led.driver].led_control_buffer[control_register_r] &= ~(1 << bit_r);
}
if (green) {
g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
driver_buffers[led.driver].led_control_buffer[control_register_g] |= (1 << bit_g);
} else {
g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
driver_buffers[led.driver].led_control_buffer[control_register_g] &= ~(1 << bit_g);
}
if (blue) {
g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
driver_buffers[led.driver].led_control_buffer[control_register_b] |= (1 << bit_b);
} else {
g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
driver_buffers[led.driver].led_control_buffer[control_register_b] &= ~(1 << bit_b);
}
g_led_control_registers_update_required[led.driver] = true;
driver_buffers[led.driver].led_control_buffer_dirty = true;
}
void is31fl3733_update_pwm_buffers(uint8_t bus, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
if (driver_buffers[index].pwm_buffer_dirty) {
is31fl3733_select_page(bus, index, IS31FL3733_COMMAND_PWM);
is31fl3733_write_pwm_buffer(bus, index);
g_pwm_buffer_update_required[index] = false;
driver_buffers[index].pwm_buffer_dirty = false;
}
}
void is31fl3733_update_led_control_registers(uint8_t bus, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
if (driver_buffers[index].led_control_buffer_dirty) {
is31fl3733_select_page(bus, index, IS31FL3733_COMMAND_LED_CONTROL);
for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3733_write_register(bus, index, i, g_led_control_registers[index][i]);
is31fl3733_write_register(bus, index, i, driver_buffers[index].led_control_buffer[i]);
}
g_led_control_registers_update_required[index] = false;
driver_buffers[index].led_control_buffer_dirty = false;
}
}