Skip to content

Commit

Permalink
LED drivers: remove PWM register offsets (qmk#22897)
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark authored Jan 13, 2024
1 parent db8c254 commit eb7ecae
Show file tree
Hide file tree
Showing 24 changed files with 464 additions and 458 deletions.
12 changes: 6 additions & 6 deletions drivers/led/issi/is31fl3218-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,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 - IS31FL3218_REG_PWM] == value) {
if (g_pwm_buffer[led.v] == value) {
return;
}

g_pwm_buffer[led.v - IS31FL3218_REG_PWM] = value;
g_pwm_buffer_update_required = true;
g_pwm_buffer[led.v] = value;
g_pwm_buffer_update_required = true;
}
}

Expand All @@ -109,8 +109,8 @@ void is31fl3218_set_led_control_register(uint8_t index, bool value) {
is31fl3218_led_t led;
memcpy_P(&led, (&g_is31fl3218_leds[index]), sizeof(led));

uint8_t control_register = (led.v - IS31FL3218_REG_PWM) / 6;
uint8_t bit_value = (led.v - IS31FL3218_REG_PWM) % 6;
uint8_t control_register = led.v / 6;
uint8_t bit_value = led.v % 6;

if (value) {
g_led_control_registers[control_register] |= (1 << bit_value);
Expand All @@ -133,7 +133,7 @@ void is31fl3218_update_pwm_buffers(void) {

void is31fl3218_update_led_control_registers(void) {
if (g_led_control_registers_update_required) {
for (int i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
for (uint8_t i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3218_write_register(IS31FL3218_REG_LED_CONTROL_1 + i, g_led_control_registers[i]);
}

Expand Down
36 changes: 18 additions & 18 deletions drivers/led/issi/is31fl3218-mono.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ void is31fl3218_update_pwm_buffers(void);

void is31fl3218_update_led_control_registers(void);

#define OUT1 0x01
#define OUT2 0x02
#define OUT3 0x03
#define OUT4 0x04
#define OUT5 0x05
#define OUT6 0x06
#define OUT7 0x07
#define OUT8 0x08
#define OUT9 0x09
#define OUT10 0x0A
#define OUT11 0x0B
#define OUT12 0x0C
#define OUT13 0x0D
#define OUT14 0x0E
#define OUT15 0x0F
#define OUT16 0x10
#define OUT17 0x11
#define OUT18 0x12
#define OUT1 0x00
#define OUT2 0x01
#define OUT3 0x02
#define OUT4 0x03
#define OUT5 0x04
#define OUT6 0x05
#define OUT7 0x06
#define OUT8 0x07
#define OUT9 0x08
#define OUT10 0x09
#define OUT11 0x0A
#define OUT12 0x0B
#define OUT13 0x0C
#define OUT14 0x0D
#define OUT15 0x0E
#define OUT16 0x0F
#define OUT17 0x10
#define OUT18 0x11
24 changes: 12 additions & 12 deletions drivers/led/issi/is31fl3218.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,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 - IS31FL3218_REG_PWM] == red && g_pwm_buffer[led.g - IS31FL3218_REG_PWM] == green && g_pwm_buffer[led.b - IS31FL3218_REG_PWM] == blue) {
if (g_pwm_buffer[led.r] == red && g_pwm_buffer[led.g] == green && g_pwm_buffer[led.b] == blue) {
return;
}

g_pwm_buffer[led.r - IS31FL3218_REG_PWM] = red;
g_pwm_buffer[led.g - IS31FL3218_REG_PWM] = green;
g_pwm_buffer[led.b - IS31FL3218_REG_PWM] = blue;
g_pwm_buffer_update_required = true;
g_pwm_buffer[led.r] = red;
g_pwm_buffer[led.g] = green;
g_pwm_buffer[led.b] = blue;
g_pwm_buffer_update_required = true;
}
}

Expand All @@ -111,12 +111,12 @@ void is31fl3218_set_led_control_register(uint8_t index, bool red, bool green, bo
is31fl3218_led_t led;
memcpy_P(&led, (&g_is31fl3218_leds[index]), sizeof(led));

uint8_t control_register_r = (led.r - IS31FL3218_REG_PWM) / 6;
uint8_t control_register_g = (led.g - IS31FL3218_REG_PWM) / 6;
uint8_t control_register_b = (led.b - IS31FL3218_REG_PWM) / 6;
uint8_t bit_r = (led.r - IS31FL3218_REG_PWM) % 6;
uint8_t bit_g = (led.g - IS31FL3218_REG_PWM) % 6;
uint8_t bit_b = (led.b - IS31FL3218_REG_PWM) % 6;
uint8_t control_register_r = led.r / 6;
uint8_t control_register_g = led.g / 6;
uint8_t control_register_b = led.b / 6;
uint8_t bit_r = led.r % 6;
uint8_t bit_g = led.g % 6;
uint8_t bit_b = led.b % 6;

if (red) {
g_led_control_registers[control_register_r] |= (1 << bit_r);
Expand Down Expand Up @@ -149,7 +149,7 @@ void is31fl3218_update_pwm_buffers(void) {

void is31fl3218_update_led_control_registers(void) {
if (g_led_control_registers_update_required) {
for (int i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
for (uint8_t i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3218_write_register(IS31FL3218_REG_LED_CONTROL_1 + i, g_led_control_registers[i]);
}

Expand Down
36 changes: 18 additions & 18 deletions drivers/led/issi/is31fl3218.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ void is31fl3218_update_pwm_buffers(void);

void is31fl3218_update_led_control_registers(void);

#define OUT1 0x01
#define OUT2 0x02
#define OUT3 0x03
#define OUT4 0x04
#define OUT5 0x05
#define OUT6 0x06
#define OUT7 0x07
#define OUT8 0x08
#define OUT9 0x09
#define OUT10 0x0A
#define OUT11 0x0B
#define OUT12 0x0C
#define OUT13 0x0D
#define OUT14 0x0E
#define OUT15 0x0F
#define OUT16 0x10
#define OUT17 0x11
#define OUT18 0x12
#define OUT1 0x00
#define OUT2 0x01
#define OUT3 0x02
#define OUT4 0x03
#define OUT5 0x04
#define OUT6 0x05
#define OUT7 0x06
#define OUT8 0x07
#define OUT9 0x08
#define OUT10 0x09
#define OUT11 0x0A
#define OUT12 0x0B
#define OUT13 0x0C
#define OUT14 0x0D
#define OUT15 0x0E
#define OUT16 0x0F
#define OUT17 0x10
#define OUT18 0x11
27 changes: 13 additions & 14 deletions drivers/led/issi/is31fl3731-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
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_writeReg(addr << 1, 0x24 + i, pwm_buffer + i, 16, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
if (i2c_writeReg(addr << 1, IS31FL3731_FRAME_REG_PWM + i, pwm_buffer + i, 16, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
}
#else
i2c_writeReg(addr << 1, 0x24 + i, pwm_buffer + i, 16, IS31FL3731_I2C_TIMEOUT);
i2c_writeReg(addr << 1, IS31FL3731_FRAME_REG_PWM + i, pwm_buffer + i, 16, IS31FL3731_I2C_TIMEOUT);
#endif
}
}
Expand Down Expand Up @@ -130,18 +130,18 @@ void is31fl3731_init(uint8_t addr) {
is31fl3731_select_page(addr, IS31FL3731_COMMAND_FRAME_1);

// turn off all LEDs in the LED control register
for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3731_write_register(addr, i, 0x00);
for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_LED_CONTROL + i, 0x00);
}

// turn off all LEDs in the blink control register (not really needed)
for (int i = 0x12; i <= 0x23; i++) {
is31fl3731_write_register(addr, i, 0x00);
for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_BLINK_CONTROL + i, 0x00);
}

// set PWM on all LEDs to 0
for (int i = 0x24; i <= 0xB3; i++) {
is31fl3731_write_register(addr, i, 0x00);
for (uint8_t i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i++) {
is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_PWM + i, 0x00);
}

is31fl3731_select_page(addr, IS31FL3731_COMMAND_FUNCTION);
Expand All @@ -161,12 +161,11 @@ 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));

// Subtract 0x24 to get the second index of g_pwm_buffer
if (g_pwm_buffer[led.driver][led.v - 0x24] == value) {
if (g_pwm_buffer[led.driver][led.v] == value) {
return;
}

g_pwm_buffer[led.driver][led.v - 0x24] = value;
g_pwm_buffer[led.driver][led.v] = value;
g_pwm_buffer_update_required[led.driver] = true;
}
}
Expand All @@ -181,8 +180,8 @@ void is31fl3731_set_led_control_register(uint8_t index, bool value) {
is31fl3731_led_t led;
memcpy_P(&led, (&g_is31fl3731_leds[index]), sizeof(led));

uint8_t control_register = (led.v - 0x24) / 8;
uint8_t bit_value = (led.v - 0x24) % 8;
uint8_t control_register = led.v / 8;
uint8_t bit_value = led.v % 8;

if (value) {
g_led_control_registers[led.driver][control_register] |= (1 << bit_value);
Expand All @@ -203,7 +202,7 @@ void is31fl3731_update_pwm_buffers(uint8_t addr, uint8_t index) {

void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
is31fl3731_write_register(addr, i, g_led_control_registers[index][i]);
}

Expand Down
Loading

0 comments on commit eb7ecae

Please sign in to comment.