Skip to content

Commit

Permalink
LED drivers: change write_pwm_buffer() return type to void (qmk#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark authored and nuess0r committed Sep 8, 2024
1 parent 2356d88 commit 7df601e
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 112 deletions.
18 changes: 4 additions & 14 deletions drivers/led/issi/is31fl3733-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ void is31fl3733_select_page(uint8_t addr, uint8_t page) {
is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, page);
}

bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
void is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// Assumes page 1 is already selected.
// If any of the transactions fails function returns false.
// Transmit PWM registers in 12 transfers of 16 bytes.
// i2c_transfer_buffer[] is 20 bytes

Expand All @@ -111,17 +110,12 @@ bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {

#if IS31FL3733_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) == 0) break;
}
#else
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT);
#endif
}
return true;
}

void is31fl3733_init_drivers(void) {
Expand Down Expand Up @@ -232,11 +226,7 @@ void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
is31fl3733_select_page(addr, IS31FL3733_COMMAND_PWM);

// If any of the transactions fail we risk writing dirty page 0,
// refresh page 0 just in case.
if (!is31fl3733_write_pwm_buffer(addr, g_pwm_buffer[index])) {
g_led_control_registers_update_required[index] = true;
}
is31fl3733_write_pwm_buffer(addr, g_pwm_buffer[index]);

g_pwm_buffer_update_required[index] = false;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/led/issi/is31fl3733-mono.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void is31fl3733_init_drivers(void);
void is31fl3733_init(uint8_t addr, uint8_t sync);
void is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
void is31fl3733_select_page(uint8_t addr, uint8_t page);
bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
void is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);

void is31fl3733_set_value(int index, uint8_t value);
void is31fl3733_set_value_all(uint8_t value);
Expand Down
18 changes: 4 additions & 14 deletions drivers/led/issi/is31fl3733.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ void is31fl3733_select_page(uint8_t addr, uint8_t page) {
is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, page);
}

bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
void is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// Assumes page 1 is already selected.
// If any of the transactions fails function returns false.
// Transmit PWM registers in 12 transfers of 16 bytes.
// i2c_transfer_buffer[] is 20 bytes

Expand All @@ -110,17 +109,12 @@ bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {

#if IS31FL3733_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) == 0) break;
}
#else
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT);
#endif
}
return true;
}

void is31fl3733_init_drivers(void) {
Expand Down Expand Up @@ -247,11 +241,7 @@ void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
is31fl3733_select_page(addr, IS31FL3733_COMMAND_PWM);

// If any of the transactions fail we risk writing dirty page 0,
// refresh page 0 just in case.
if (!is31fl3733_write_pwm_buffer(addr, g_pwm_buffer[index])) {
g_led_control_registers_update_required[index] = true;
}
is31fl3733_write_pwm_buffer(addr, g_pwm_buffer[index]);

g_pwm_buffer_update_required[index] = false;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/led/issi/is31fl3733.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void is31fl3733_init_drivers(void);
void is31fl3733_init(uint8_t addr, uint8_t sync);
void is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
void is31fl3733_select_page(uint8_t addr, uint8_t page);
bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
void is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);

void is31fl3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void is31fl3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
Expand Down
20 changes: 5 additions & 15 deletions drivers/led/issi/is31fl3741-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void is31fl3741_select_page(uint8_t addr, uint8_t page) {
is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, page);
}

bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
void is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// Assume page 0 is already selected

for (int i = 0; i < 342; i += 18) {
Expand All @@ -98,14 +98,10 @@ bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {

#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) == 0) break;
}
#else
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
i2c_transmit(addr << 1, i2c_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT);
#endif
}

Expand All @@ -115,17 +111,11 @@ bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {

#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) break;
}
#else
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
i2c_transmit(addr << 1, i2c_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT);
#endif

return true;
}

void is31fl3741_init_drivers(void) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/led/issi/is31fl3741-mono.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void is31fl3741_init_drivers(void);
void is31fl3741_init(uint8_t addr);
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data);
void is31fl3741_select_page(uint8_t addr, uint8_t page);
bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
void is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);

void is31fl3741_set_value(int index, uint8_t value);
void is31fl3741_set_value_all(uint8_t value);
Expand Down
20 changes: 5 additions & 15 deletions drivers/led/issi/is31fl3741.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void is31fl3741_select_page(uint8_t addr, uint8_t page) {
is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, page);
}

bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
void is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// Assume page 0 is already selected

for (int i = 0; i < 342; i += 18) {
Expand All @@ -98,14 +98,10 @@ bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {

#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) == 0) break;
}
#else
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
i2c_transmit(addr << 1, i2c_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT);
#endif
}

Expand All @@ -115,17 +111,11 @@ bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {

#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) == 0) break;
}
#else
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
i2c_transmit(addr << 1, i2c_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT);
#endif

return true;
}

void is31fl3741_init_drivers(void) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/led/issi/is31fl3741.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void is31fl3741_init_drivers(void);
void is31fl3741_init(uint8_t addr);
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data);
void is31fl3741_select_page(uint8_t addr, uint8_t page);
bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
void is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);

void is31fl3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void is31fl3741_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
Expand Down
22 changes: 6 additions & 16 deletions drivers/led/snled27351-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ void snled27351_select_page(uint8_t addr, uint8_t page) {
snled27351_write_register(addr, SNLED27351_REG_COMMAND, page);
}

bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
void snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// Assumes PG1 is already selected.
// If any of the transactions fails function returns false.
// Transmit PWM registers in 12 transfers of 16 bytes.
// i2c_transfer_buffer[] is 20 bytes

Expand All @@ -86,17 +85,12 @@ bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {

#if SNLED27351_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < SNLED27351_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, SNLED27351_I2C_TIMEOUT) != 0) {
return false;
}
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, SNLED27351_I2C_TIMEOUT) == 0) break;
}
#else
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, SNLED27351_I2C_TIMEOUT) != 0) {
return false;
}
i2c_transmit(addr << 1, i2c_transfer_buffer, 17, SNLED27351_I2C_TIMEOUT);
#endif
}
return true;
}

void snled27351_init_drivers(void) {
Expand Down Expand Up @@ -216,14 +210,10 @@ void snled27351_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
snled27351_select_page(addr, SNLED27351_COMMAND_PWM);

// If any of the transactions fail we risk writing dirty PG0,
// refresh page 0 just in case.
if (!snled27351_write_pwm_buffer(addr, g_pwm_buffer[index])) {
g_pwm_buffer_update_required[index] = true;
}
}
snled27351_write_pwm_buffer(addr, g_pwm_buffer[index]);

g_pwm_buffer_update_required[index] = false;
g_pwm_buffer_update_required[index] = false;
}
}

void snled27351_update_led_control_registers(uint8_t addr, uint8_t index) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/led/snled27351-mono.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void snled27351_init_drivers(void);
void snled27351_init(uint8_t addr);
void snled27351_select_page(uint8_t addr, uint8_t page);
void snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data);
bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
void snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);

void snled27351_set_value(int index, uint8_t value);
void snled27351_set_value_all(uint8_t value);
Expand Down
22 changes: 6 additions & 16 deletions drivers/led/snled27351.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ void snled27351_select_page(uint8_t addr, uint8_t page) {
snled27351_write_register(addr, SNLED27351_REG_COMMAND, page);
}

bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
void snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// Assumes PG1 is already selected.
// If any of the transactions fails function returns false.
// Transmit PWM registers in 3 transfers of 64 bytes.

// Iterate over the pwm_buffer contents at 64 byte intervals.
Expand All @@ -85,17 +84,12 @@ bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {

#if SNLED27351_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < SNLED27351_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 65, SNLED27351_I2C_TIMEOUT) != 0) {
return false;
}
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 65, SNLED27351_I2C_TIMEOUT) == 0) break;
}
#else
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 65, SNLED27351_I2C_TIMEOUT) != 0) {
return false;
}
i2c_transmit(addr << 1, i2c_transfer_buffer, 65, SNLED27351_I2C_TIMEOUT);
#endif
}
return true;
}

void snled27351_init_drivers(void) {
Expand Down Expand Up @@ -231,14 +225,10 @@ void snled27351_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
snled27351_select_page(addr, SNLED27351_COMMAND_PWM);

// If any of the transactions fail we risk writing dirty PG0,
// refresh page 0 just in case.
if (!snled27351_write_pwm_buffer(addr, g_pwm_buffer[index])) {
g_pwm_buffer_update_required[index] = true;
}
}
snled27351_write_pwm_buffer(addr, g_pwm_buffer[index]);

g_pwm_buffer_update_required[index] = false;
g_pwm_buffer_update_required[index] = false;
}
}

void snled27351_update_led_control_registers(uint8_t addr, uint8_t index) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/led/snled27351.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void snled27351_init_drivers(void);
void snled27351_init(uint8_t addr);
void snled27351_select_page(uint8_t addr, uint8_t page);
void snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data);
bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
void snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);

void snled27351_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void snled27351_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
Expand Down
21 changes: 6 additions & 15 deletions keyboards/input_club/k_type/is31fl3733-dual.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ void is31fl3733_select_page(uint8_t index, uint8_t addr, uint8_t page) {
is31fl3733_write_register(index, addr, IS31FL3733_REG_COMMAND, page);
}

bool is31fl3733_write_pwm_buffer(uint8_t index, uint8_t addr, uint8_t *pwm_buffer) {
void is31fl3733_write_pwm_buffer(uint8_t index, uint8_t addr, uint8_t *pwm_buffer) {
// Assumes page 1 is already selected.
// If any of the transactions fails function returns false.
// Transmit PWM registers in 12 transfers of 16 bytes.
// i2c_transfer_buffer[] is 20 bytes

Expand All @@ -110,17 +109,12 @@ bool is31fl3733_write_pwm_buffer(uint8_t index, uint8_t addr, uint8_t *pwm_buffe

#if IS31FL3733_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
if (i2c_transmit(index, addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
if (i2c_transmit(index, addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) == 0) break;
}
#else
if (i2c_transmit(index, addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
i2c_transmit(index, addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT);
#endif
}
return true;
}

void is31fl3733_init_drivers(void) {
Expand Down Expand Up @@ -236,13 +230,10 @@ void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
is31fl3733_select_page(index, addr, IS31FL3733_COMMAND_PWM);

// If any of the transactions fail we risk writing dirty page 0,
// refresh page 0 just in case.
if (!is31fl3733_write_pwm_buffer(index, addr, g_pwm_buffer[index])) {
g_led_control_registers_update_required[index] = true;
}
is31fl3733_write_pwm_buffer(index, addr, g_pwm_buffer[index]);

g_pwm_buffer_update_required[index] = false;
}
g_pwm_buffer_update_required[index] = false;
}

void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) {
Expand Down
2 changes: 1 addition & 1 deletion keyboards/input_club/k_type/is31fl3733-dual.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void is31fl3733_init_drivers(void);
void is31fl3733_init(uint8_t bus, uint8_t addr, uint8_t sync);
void is31fl3733_write_register(uint8_t index, uint8_t addr, uint8_t reg, uint8_t data);
void is31fl3733_select_page(uint8_t index, uint8_t addr, uint8_t page);
bool is31fl3733_write_pwm_buffer(uint8_t index, uint8_t addr, uint8_t *pwm_buffer);
void is31fl3733_write_pwm_buffer(uint8_t index, uint8_t addr, uint8_t *pwm_buffer);

void is31fl3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void is31fl3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
Expand Down

0 comments on commit 7df601e

Please sign in to comment.