From a27bc60703dda744309c5f13320f667f5c766260 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 2 Nov 2023 06:13:25 +1100 Subject: LED drivers: add defines for PWM and LED control register counts (#22383) --- drivers/led/snled27351-simple.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'drivers/led/snled27351-simple.c') diff --git a/drivers/led/snled27351-simple.c b/drivers/led/snled27351-simple.c index c274506f83..847cdb7715 100644 --- a/drivers/led/snled27351-simple.c +++ b/drivers/led/snled27351-simple.c @@ -17,6 +17,9 @@ #include "snled27351-simple.h" #include "i2c_master.h" +#define SNLED27351_PWM_REGISTER_COUNT 192 +#define SNLED27351_LED_CONTROL_REGISTER_COUNT 24 + #ifndef SNLED27351_I2C_TIMEOUT # define SNLED27351_I2C_TIMEOUT 100 #endif @@ -43,11 +46,11 @@ uint8_t g_twi_transfer_buffer[20]; // 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][192]; +uint8_t g_pwm_buffer[SNLED27351_DRIVER_COUNT][SNLED27351_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[SNLED27351_DRIVER_COUNT] = {false}; -uint8_t g_led_control_registers[SNLED27351_DRIVER_COUNT][24] = {0}; -bool g_led_control_registers_update_required[SNLED27351_DRIVER_COUNT] = {false}; +uint8_t g_led_control_registers[SNLED27351_DRIVER_COUNT][SNLED27351_LED_CONTROL_REGISTER_COUNT] = {0}; +bool g_led_control_registers_update_required[SNLED27351_DRIVER_COUNT] = {false}; bool snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // If the transaction fails function returns false. @@ -75,7 +78,7 @@ bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // g_twi_transfer_buffer[] is 20 bytes // Iterate over the pwm_buffer contents at 16 byte intervals. - for (int i = 0; i < 192; i += 16) { + for (int i = 0; i < SNLED27351_PWM_REGISTER_COUNT; i += 16) { g_twi_transfer_buffer[0] = i; // Copy the data from i to i+15. // Device will auto-increment register for data after the first byte @@ -224,7 +227,7 @@ void snled27351_update_pwm_buffers(uint8_t addr, uint8_t index) { void snled27351_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_led_control_registers_update_required[index]) { snled27351_write_register(addr, SNLED27351_REG_CONFIGURE_CMD_PAGE, SNLED27351_LED_CONTROL_PAGE); - for (int i = 0; i < 24; i++) { + for (int i = 0; i < SNLED27351_LED_CONTROL_REGISTER_COUNT; i++) { snled27351_write_register(addr, i, g_led_control_registers[index][i]); } } -- cgit v1.2.3