From a27bc60703dda744309c5f13320f667f5c766260 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 2 Nov 2023 06:13:25 +1100 Subject: [PATCH] LED drivers: add defines for PWM and LED control register counts (#22383) --- drivers/led/issi/is31fl3218-simple.c | 15 +++++++++------ drivers/led/issi/is31fl3218.c | 15 +++++++++------ drivers/led/issi/is31fl3731-simple.c | 15 +++++++++------ drivers/led/issi/is31fl3731.c | 15 +++++++++------ drivers/led/issi/is31fl3733-simple.c | 17 ++++++++++------- drivers/led/issi/is31fl3733.c | 17 ++++++++++------- drivers/led/issi/is31fl3736-simple.c | 17 ++++++++++------- drivers/led/issi/is31fl3736.c | 17 ++++++++++------- drivers/led/issi/is31fl3737-simple.c | 17 ++++++++++------- drivers/led/issi/is31fl3737.c | 17 ++++++++++------- drivers/led/issi/is31fl3741-simple.c | 8 ++++---- drivers/led/issi/is31fl3741.c | 8 ++++---- drivers/led/snled27351-simple.c | 13 ++++++++----- drivers/led/snled27351.c | 13 ++++++++----- keyboards/input_club/k_type/is31fl3733-dual.c | 17 ++++++++++------- 15 files changed, 130 insertions(+), 91 deletions(-) diff --git a/drivers/led/issi/is31fl3218-simple.c b/drivers/led/issi/is31fl3218-simple.c index bdf3187fe1..ea9d76ddbb 100644 --- a/drivers/led/issi/is31fl3218-simple.c +++ b/drivers/led/issi/is31fl3218-simple.c @@ -24,6 +24,9 @@ #define IS31FL3218_REG_UPDATE 0x16 #define IS31FL3218_REG_RESET 0x17 +#define IS31FL3218_PWM_REGISTER_COUNT 18 +#define IS31FL3218_LED_CONTROL_REGISTER_COUNT 3 + #ifndef IS31FL3218_I2C_TIMEOUT # define IS31FL3218_I2C_TIMEOUT 100 #endif @@ -36,11 +39,11 @@ uint8_t g_twi_transfer_buffer[20]; // IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining. -uint8_t g_pwm_buffer[18]; +uint8_t g_pwm_buffer[IS31FL3218_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required = false; -uint8_t g_led_control_registers[3] = {0}; -bool g_led_control_registers_update_required = false; +uint8_t g_led_control_registers[IS31FL3218_LED_CONTROL_REGISTER_COUNT] = {0}; +bool g_led_control_registers_update_required = false; void is31fl3218_write_register(uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; @@ -77,12 +80,12 @@ void is31fl3218_init(void) { is31fl3218_write_register(IS31FL3218_REG_SHUTDOWN, 0x01); // Set all PWM values to zero - for (uint8_t i = 0; i < 18; i++) { + for (uint8_t i = 0; i < IS31FL3218_PWM_REGISTER_COUNT; i++) { is31fl3218_write_register(IS31FL3218_REG_PWM + i, 0x00); } // turn off all LEDs in the LED control register - for (uint8_t i = 0; i < 3; i++) { + for (uint8_t i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, 0x00); } @@ -142,7 +145,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 < 3; i++) { + for (int i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, g_led_control_registers[i]); } diff --git a/drivers/led/issi/is31fl3218.c b/drivers/led/issi/is31fl3218.c index 04523a3c01..357cb1ab55 100644 --- a/drivers/led/issi/is31fl3218.c +++ b/drivers/led/issi/is31fl3218.c @@ -24,6 +24,9 @@ #define IS31FL3218_REG_UPDATE 0x16 #define IS31FL3218_REG_RESET 0x17 +#define IS31FL3218_PWM_REGISTER_COUNT 18 +#define IS31FL3218_LED_CONTROL_REGISTER_COUNT 3 + #ifndef IS31FL3218_I2C_TIMEOUT # define IS31FL3218_I2C_TIMEOUT 100 #endif @@ -36,11 +39,11 @@ uint8_t g_twi_transfer_buffer[20]; // IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining. -uint8_t g_pwm_buffer[18]; +uint8_t g_pwm_buffer[IS31FL3218_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required = false; -uint8_t g_led_control_registers[3] = {0}; -bool g_led_control_registers_update_required = false; +uint8_t g_led_control_registers[IS31FL3218_LED_CONTROL_REGISTER_COUNT] = {0}; +bool g_led_control_registers_update_required = false; void is31fl3218_write_register(uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; @@ -77,12 +80,12 @@ void is31fl3218_init(void) { is31fl3218_write_register(IS31FL3218_REG_SHUTDOWN, 0x01); // Set all PWM values to zero - for (uint8_t i = 0; i < 18; i++) { + for (uint8_t i = 0; i < IS31FL3218_PWM_REGISTER_COUNT; i++) { is31fl3218_write_register(IS31FL3218_REG_PWM + i, 0x00); } // turn off all LEDs in the LED control register - for (uint8_t i = 0; i < 3; i++) { + for (uint8_t i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, 0x00); } @@ -158,7 +161,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 < 3; i++) { + for (int i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, g_led_control_registers[i]); } diff --git a/drivers/led/issi/is31fl3731-simple.c b/drivers/led/issi/is31fl3731-simple.c index 3663d30c10..c6f1da5789 100644 --- a/drivers/led/issi/is31fl3731-simple.c +++ b/drivers/led/issi/is31fl3731-simple.c @@ -42,6 +42,9 @@ #define IS31FL3731_COMMANDREGISTER 0xFD #define IS31FL3731_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine' +#define IS31FL3731_PWM_REGISTER_COUNT 144 +#define IS31FL3731_LED_CONTROL_REGISTER_COUNT 18 + #ifndef IS31FL3731_I2C_TIMEOUT # define IS31FL3731_I2C_TIMEOUT 100 #endif @@ -58,11 +61,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 is31fl3731_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[IS31FL3731_DRIVER_COUNT][144]; +uint8_t g_pwm_buffer[IS31FL3731_DRIVER_COUNT][IS31FL3731_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[IS31FL3731_DRIVER_COUNT] = {false}; -uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][18] = {0}; -bool g_led_control_registers_update_required[IS31FL3731_DRIVER_COUNT] = {false}; +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}; void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; @@ -86,7 +89,7 @@ void is31fl3731_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 < 144; i += 16) { + for (int i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i += 16) { // set the first register, e.g. 0x24, 0x34, 0x44, etc. g_twi_transfer_buffer[0] = 0x24 + i; // copy the data from i to i+15 @@ -163,7 +166,7 @@ void is31fl3731_init(uint8_t addr) { is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, 0); // turn off all LEDs in the LED control register - for (int i = 0x00; i <= 0x11; i++) { + for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3731_write_register(addr, i, 0x00); } @@ -235,7 +238,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 < 18; i++) { + for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3731_write_register(addr, i, g_led_control_registers[index][i]); } g_led_control_registers_update_required[index] = false; diff --git a/drivers/led/issi/is31fl3731.c b/drivers/led/issi/is31fl3731.c index 42abd8ed38..6a64d89ecf 100644 --- a/drivers/led/issi/is31fl3731.c +++ b/drivers/led/issi/is31fl3731.c @@ -41,6 +41,9 @@ #define IS31FL3731_COMMANDREGISTER 0xFD #define IS31FL3731_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine' +#define IS31FL3731_PWM_REGISTER_COUNT 144 +#define IS31FL3731_LED_CONTROL_REGISTER_COUNT 18 + #ifndef IS31FL3731_I2C_TIMEOUT # define IS31FL3731_I2C_TIMEOUT 100 #endif @@ -57,11 +60,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 is31fl3731_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[IS31FL3731_DRIVER_COUNT][144]; +uint8_t g_pwm_buffer[IS31FL3731_DRIVER_COUNT][IS31FL3731_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[IS31FL3731_DRIVER_COUNT] = {false}; -uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][18] = {0}; -bool g_led_control_registers_update_required[IS31FL3731_DRIVER_COUNT] = {false}; +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}; void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; @@ -83,7 +86,7 @@ void is31fl3731_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 < 144; i += 16) { + for (int i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i += 16) { // set the first register, e.g. 0x24, 0x34, 0x44, etc. g_twi_transfer_buffer[0] = 0x24 + i; // copy the data from i to i+15 @@ -160,7 +163,7 @@ void is31fl3731_init(uint8_t addr) { is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, 0); // turn off all LEDs in the LED control register - for (int i = 0x00; i <= 0x11; i++) { + for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3731_write_register(addr, i, 0x00); } @@ -247,7 +250,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 < 18; i++) { + for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3731_write_register(addr, i, g_led_control_registers[index][i]); } } diff --git a/drivers/led/issi/is31fl3733-simple.c b/drivers/led/issi/is31fl3733-simple.c index aa1b02450c..966a8d7cf2 100644 --- a/drivers/led/issi/is31fl3733-simple.c +++ b/drivers/led/issi/is31fl3733-simple.c @@ -39,6 +39,9 @@ #define IS31FL3733_REG_SWPULLUP 0x0F // PG3 #define IS31FL3733_REG_CSPULLUP 0x10 // PG3 +#define IS31FL3733_PWM_REGISTER_COUNT 192 +#define IS31FL3733_LED_CONTROL_REGISTER_COUNT 24 + #ifndef IS31FL3733_I2C_TIMEOUT # define IS31FL3733_I2C_TIMEOUT 100 #endif @@ -85,11 +88,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 is31fl3733_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][192]; +uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][IS31FL3733_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false}; -uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][24] = {0}; -bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false}; +uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][IS31FL3733_LED_CONTROL_REGISTER_COUNT] = {0}; +bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false}; bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // If the transaction fails function returns false. @@ -117,7 +120,7 @@ bool is31fl3733_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 < IS31FL3733_PWM_REGISTER_COUNT; i += 16) { g_twi_transfer_buffer[0] = i; // Copy the data from i to i+15. // Device will auto-increment register for data after the first byte @@ -182,7 +185,7 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) { // Select PG0 is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL); // Turn off all LEDs. - for (int i = 0x00; i <= 0x17; i++) { + for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3733_write_register(addr, i, 0x00); } @@ -193,7 +196,7 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) { is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. - for (int i = 0x00; i <= 0xBF; i++) { + for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i++) { is31fl3733_write_register(addr, i, 0x00); } @@ -270,7 +273,7 @@ void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) { // Firstly we need to unlock the command register and select PG0 is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5); is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL); - for (int i = 0; i < 24; i++) { + for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3733_write_register(addr, i, g_led_control_registers[index][i]); } g_led_control_registers_update_required[index] = false; diff --git a/drivers/led/issi/is31fl3733.c b/drivers/led/issi/is31fl3733.c index 24b0733030..729d2bc57c 100644 --- a/drivers/led/issi/is31fl3733.c +++ b/drivers/led/issi/is31fl3733.c @@ -38,6 +38,9 @@ #define IS31FL3733_REG_SWPULLUP 0x0F // PG3 #define IS31FL3733_REG_CSPULLUP 0x10 // PG3 +#define IS31FL3733_PWM_REGISTER_COUNT 192 +#define IS31FL3733_LED_CONTROL_REGISTER_COUNT 24 + #ifndef IS31FL3733_I2C_TIMEOUT # define IS31FL3733_I2C_TIMEOUT 100 #endif @@ -84,11 +87,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 is31fl3733_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][192]; +uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][IS31FL3733_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false}; -uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][24] = {0}; -bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false}; +uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][IS31FL3733_LED_CONTROL_REGISTER_COUNT] = {0}; +bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false}; bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) { // If the transaction fails function returns false. @@ -116,7 +119,7 @@ bool is31fl3733_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 < IS31FL3733_PWM_REGISTER_COUNT; i += 16) { g_twi_transfer_buffer[0] = i; // Copy the data from i to i+15. // Device will auto-increment register for data after the first byte @@ -181,7 +184,7 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) { // Select PG0 is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL); // Turn off all LEDs. - for (int i = 0x00; i <= 0x17; i++) { + for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3733_write_register(addr, i, 0x00); } @@ -192,7 +195,7 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) { is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. - for (int i = 0x00; i <= 0xBF; i++) { + for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i++) { is31fl3733_write_register(addr, i, 0x00); } @@ -285,7 +288,7 @@ void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) { // Firstly we need to unlock the command register and select PG0 is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5); is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL); - for (int i = 0; i < 24; i++) { + for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3733_write_register(addr, i, g_led_control_registers[index][i]); } g_led_control_registers_update_required[index] = false; diff --git a/drivers/led/issi/is31fl3736-simple.c b/drivers/led/issi/is31fl3736-simple.c index 2876533819..45daaf3187 100644 --- a/drivers/led/issi/is31fl3736-simple.c +++ b/drivers/led/issi/is31fl3736-simple.c @@ -36,6 +36,9 @@ #define IS31FL3736_REG_SWPULLUP 0x0F // PG3 #define IS31FL3736_REG_CSPULLUP 0x10 // PG3 +#define IS31FL3736_PWM_REGISTER_COUNT 192 // actually 96 +#define IS31FL3736_LED_CONTROL_REGISTER_COUNT 24 + #ifndef IS31FL3736_I2C_TIMEOUT # define IS31FL3736_I2C_TIMEOUT 100 #endif @@ -69,11 +72,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 is31fl3736_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[IS31FL3736_DRIVER_COUNT][192]; +uint8_t g_pwm_buffer[IS31FL3736_DRIVER_COUNT][IS31FL3736_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[IS31FL3736_DRIVER_COUNT] = {false}; -uint8_t g_led_control_registers[IS31FL3736_DRIVER_COUNT][24] = {0}; -bool g_led_control_registers_update_required[IS31FL3736_DRIVER_COUNT] = {false}; +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}; void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; @@ -95,7 +98,7 @@ void is31fl3736_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 < IS31FL3736_PWM_REGISTER_COUNT; i += 16) { g_twi_transfer_buffer[0] = i; // copy the data from i to i+15 // device will auto-increment register for data after the first byte @@ -154,7 +157,7 @@ void is31fl3736_init(uint8_t addr) { // Select PG0 is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_LEDCONTROL); // Turn off all LEDs. - for (int i = 0x00; i <= 0x17; i++) { + for (int i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3736_write_register(addr, i, 0x00); } @@ -165,7 +168,7 @@ void is31fl3736_init(uint8_t addr) { is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. - for (int i = 0x00; i <= 0xBF; i++) { + for (int i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i++) { is31fl3736_write_register(addr, i, 0x00); } @@ -244,7 +247,7 @@ void is31fl3736_update_led_control_registers(uint8_t addr, uint8_t index) { // Firstly we need to unlock the command register and select PG0 is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER_WRITELOCK, 0xC5); is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_LEDCONTROL); - for (int i = 0; i < 24; i++) { + for (int i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3736_write_register(addr, i, g_led_control_registers[index][i]); } g_led_control_registers_update_required[index] = false; diff --git a/drivers/led/issi/is31fl3736.c b/drivers/led/issi/is31fl3736.c index ad421e5cf2..36cd132d46 100644 --- a/drivers/led/issi/is31fl3736.c +++ b/drivers/led/issi/is31fl3736.c @@ -36,6 +36,9 @@ #define IS31FL3736_REG_SWPULLUP 0x0F // PG3 #define IS31FL3736_REG_CSPULLUP 0x10 // PG3 +#define IS31FL3736_PWM_REGISTER_COUNT 192 // actually 96 +#define IS31FL3736_LED_CONTROL_REGISTER_COUNT 24 + #ifndef IS31FL3736_I2C_TIMEOUT # define IS31FL3736_I2C_TIMEOUT 100 #endif @@ -69,11 +72,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 is31fl3736_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[IS31FL3736_DRIVER_COUNT][192]; +uint8_t g_pwm_buffer[IS31FL3736_DRIVER_COUNT][IS31FL3736_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[IS31FL3736_DRIVER_COUNT] = {false}; -uint8_t g_led_control_registers[IS31FL3736_DRIVER_COUNT][24] = {0}; -bool g_led_control_registers_update_required[IS31FL3736_DRIVER_COUNT] = {false}; +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}; void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; @@ -95,7 +98,7 @@ void is31fl3736_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 < IS31FL3736_PWM_REGISTER_COUNT; i += 16) { g_twi_transfer_buffer[0] = i; // copy the data from i to i+15 // device will auto-increment register for data after the first byte @@ -154,7 +157,7 @@ void is31fl3736_init(uint8_t addr) { // Select PG0 is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_LEDCONTROL); // Turn off all LEDs. - for (int i = 0x00; i <= 0x17; i++) { + for (int i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3736_write_register(addr, i, 0x00); } @@ -165,7 +168,7 @@ void is31fl3736_init(uint8_t addr) { is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. - for (int i = 0x00; i <= 0xBF; i++) { + for (int i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i++) { is31fl3736_write_register(addr, i, 0x00); } @@ -261,7 +264,7 @@ void is31fl3736_update_led_control_registers(uint8_t addr, uint8_t index) { // Firstly we need to unlock the command register and select PG0 is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER_WRITELOCK, 0xC5); is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_LEDCONTROL); - for (int i = 0; i < 24; i++) { + for (int i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3736_write_register(addr, i, g_led_control_registers[index][i]); } g_led_control_registers_update_required[index] = false; diff --git a/drivers/led/issi/is31fl3737-simple.c b/drivers/led/issi/is31fl3737-simple.c index aa6eba982c..0549af16f2 100644 --- a/drivers/led/issi/is31fl3737-simple.c +++ b/drivers/led/issi/is31fl3737-simple.c @@ -38,6 +38,9 @@ #define IS31FL3737_REG_SWPULLUP 0x0F // PG3 #define IS31FL3737_REG_CSPULLUP 0x10 // PG3 +#define IS31FL3737_PWM_REGISTER_COUNT 192 // actually 144 +#define IS31FL3737_LED_CONTROL_REGISTER_COUNT 24 + #ifndef IS31FL3737_I2C_TIMEOUT # define IS31FL3737_I2C_TIMEOUT 100 #endif @@ -72,11 +75,11 @@ uint8_t g_twi_transfer_buffer[20]; // buffers and the transfers in is31fl3737_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[IS31FL3737_DRIVER_COUNT][192]; +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][24] = {0}; -bool g_led_control_registers_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}; void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; @@ -98,7 +101,7 @@ void is31fl3737_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 < IS31FL3737_PWM_REGISTER_COUNT; i += 16) { g_twi_transfer_buffer[0] = i; // copy the data from i to i+15 // device will auto-increment register for data after the first byte @@ -157,7 +160,7 @@ void is31fl3737_init(uint8_t addr) { // Select PG0 is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_LEDCONTROL); // Turn off all LEDs. - for (int i = 0x00; i <= 0x17; i++) { + for (int i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3737_write_register(addr, i, 0x00); } @@ -168,7 +171,7 @@ void is31fl3737_init(uint8_t addr) { is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. - for (int i = 0x00; i <= 0xBF; i++) { + for (int i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i++) { is31fl3737_write_register(addr, i, 0x00); } @@ -241,7 +244,7 @@ void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index) { // Firstly we need to unlock the command register and select PG0 is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER_WRITELOCK, 0xC5); is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_LEDCONTROL); - for (int i = 0; i < 24; i++) { + for (int i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3737_write_register(addr, i, g_led_control_registers[index][i]); } g_led_control_registers_update_required[index] = false; diff --git a/drivers/led/issi/is31fl3737.c b/drivers/led/issi/is31fl3737.c index 75544231ec..1599e59058 100644 --- a/drivers/led/issi/is31fl3737.c +++ b/drivers/led/issi/is31fl3737.c @@ -38,6 +38,9 @@ #define IS31FL3737_REG_SWPULLUP 0x0F // PG3 #define IS31FL3737_REG_CSPULLUP 0x10 // PG3 +#define IS31FL3737_PWM_REGISTER_COUNT 192 // actually 144 +#define IS31FL3737_LED_CONTROL_REGISTER_COUNT 24 + #ifndef IS31FL3737_I2C_TIMEOUT # define IS31FL3737_I2C_TIMEOUT 100 #endif @@ -72,11 +75,11 @@ uint8_t g_twi_transfer_buffer[20]; // buffers and the transfers in is31fl3737_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[IS31FL3737_DRIVER_COUNT][192]; +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][24] = {0}; -bool g_led_control_registers_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}; void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; @@ -98,7 +101,7 @@ void is31fl3737_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 < IS31FL3737_PWM_REGISTER_COUNT; i += 16) { g_twi_transfer_buffer[0] = i; // copy the data from i to i+15 // device will auto-increment register for data after the first byte @@ -157,7 +160,7 @@ void is31fl3737_init(uint8_t addr) { // Select PG0 is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_LEDCONTROL); // Turn off all LEDs. - for (int i = 0x00; i <= 0x17; i++) { + for (int i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3737_write_register(addr, i, 0x00); } @@ -168,7 +171,7 @@ void is31fl3737_init(uint8_t addr) { is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. - for (int i = 0x00; i <= 0xBF; i++) { + for (int i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i++) { is31fl3737_write_register(addr, i, 0x00); } @@ -257,7 +260,7 @@ void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index) { // Firstly we need to unlock the command register and select PG0 is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER_WRITELOCK, 0xC5); is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_LEDCONTROL); - for (int i = 0; i < 24; i++) { + for (int i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3737_write_register(addr, i, g_led_control_registers[index][i]); } g_led_control_registers_update_required[index] = false; diff --git a/drivers/led/issi/is31fl3741-simple.c b/drivers/led/issi/is31fl3741-simple.c index 8e77a6446d..83a1f12f6f 100644 --- a/drivers/led/issi/is31fl3741-simple.c +++ b/drivers/led/issi/is31fl3741-simple.c @@ -40,6 +40,8 @@ #define IS31FL3741_REG_PWM_FREQUENCY 0x36 // PG4 #define IS31FL3741_REG_RESET 0x3F // PG4 +#define IS31FL3741_PWM_REGISTER_COUNT 351 + #ifndef IS31FL3741_I2C_TIMEOUT # define IS31FL3741_I2C_TIMEOUT 100 #endif @@ -68,8 +70,6 @@ # define IS31FL3741_GLOBALCURRENT 0xFF #endif -#define IS31FL3741_MAX_LEDS 351 - // Transfer buffer for TWITransmitData() uint8_t g_twi_transfer_buffer[20] = {0xFF}; @@ -79,11 +79,11 @@ uint8_t g_twi_transfer_buffer[20] = {0xFF}; // 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_MAX_LEDS]; +uint8_t g_pwm_buffer[IS31FL3741_DRIVER_COUNT][IS31FL3741_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[IS31FL3741_DRIVER_COUNT] = {false}; bool g_scaling_registers_update_required[IS31FL3741_DRIVER_COUNT] = {false}; -uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_MAX_LEDS]; +uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_PWM_REGISTER_COUNT]; void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; diff --git a/drivers/led/issi/is31fl3741.c b/drivers/led/issi/is31fl3741.c index f316b76157..214cccf2ca 100644 --- a/drivers/led/issi/is31fl3741.c +++ b/drivers/led/issi/is31fl3741.c @@ -40,6 +40,8 @@ #define IS31FL3741_REG_PWM_FREQUENCY 0x36 // PG4 #define IS31FL3741_REG_RESET 0x3F // PG4 +#define IS31FL3741_PWM_REGISTER_COUNT 351 + #ifndef IS31FL3741_I2C_TIMEOUT # define IS31FL3741_I2C_TIMEOUT 100 #endif @@ -68,8 +70,6 @@ # define IS31FL3741_GLOBALCURRENT 0xFF #endif -#define IS31FL3741_MAX_LEDS 351 - // Transfer buffer for TWITransmitData() uint8_t g_twi_transfer_buffer[20] = {0xFF}; @@ -79,11 +79,11 @@ uint8_t g_twi_transfer_buffer[20] = {0xFF}; // 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_MAX_LEDS]; +uint8_t g_pwm_buffer[IS31FL3741_DRIVER_COUNT][IS31FL3741_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[IS31FL3741_DRIVER_COUNT] = {false}; bool g_scaling_registers_update_required[IS31FL3741_DRIVER_COUNT] = {false}; -uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_MAX_LEDS]; +uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_PWM_REGISTER_COUNT]; void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; 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]); } } diff --git a/drivers/led/snled27351.c b/drivers/led/snled27351.c index 2746737a5a..de0c7b3239 100644 --- a/drivers/led/snled27351.c +++ b/drivers/led/snled27351.c @@ -17,6 +17,9 @@ #include "snled27351.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[65]; // 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. @@ -74,7 +77,7 @@ bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { // Transmit PWM registers in 3 transfers of 64 bytes. // Iterate over the pwm_buffer contents at 64 byte intervals. - for (uint8_t i = 0; i < 192; i += 64) { + for (uint8_t i = 0; i < SNLED27351_PWM_REGISTER_COUNT; i += 64) { g_twi_transfer_buffer[0] = i; // Copy the data from i to i+63. // Device will auto-increment register for data after the first byte @@ -239,7 +242,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]); } } diff --git a/keyboards/input_club/k_type/is31fl3733-dual.c b/keyboards/input_club/k_type/is31fl3733-dual.c index 0b6c6a607c..d9cf3b5170 100644 --- a/keyboards/input_club/k_type/is31fl3733-dual.c +++ b/keyboards/input_club/k_type/is31fl3733-dual.c @@ -36,6 +36,9 @@ #define IS31FL3733_REG_SWPULLUP 0x0F // PG3 #define IS31FL3733_REG_CSPULLUP 0x10 // PG3 +#define IS31FL3733_PWM_REGISTER_COUNT 192 +#define IS31FL3733_LED_CONTROL_REGISTER_COUNT 24 + #ifndef IS31FL3733_I2C_TIMEOUT # define IS31FL3733_I2C_TIMEOUT 100 #endif @@ -82,11 +85,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 is31fl3733_write_pwm_buffer() but it's // probably not worth the extra complexity. -uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][192]; +uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][IS31FL3733_PWM_REGISTER_COUNT]; bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false}; -uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][24] = {{0}, {0}}; -bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false}; +uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][IS31FL3733_LED_CONTROL_REGISTER_COUNT] = {0}; +bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false}; bool is31fl3733_write_register(uint8_t index, uint8_t addr, uint8_t reg, uint8_t data) { // If the transaction fails function returns false. @@ -114,7 +117,7 @@ bool is31fl3733_write_pwm_buffer(uint8_t index, uint8_t addr, uint8_t *pwm_buffe // 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 < IS31FL3733_PWM_REGISTER_COUNT; i += 16) { g_twi_transfer_buffer[0] = i; // Copy the data from i to i+15. // Device will auto-increment register for data after the first byte @@ -169,7 +172,7 @@ void is31fl3733_init(uint8_t bus, uint8_t addr, uint8_t sync) { // Select PG0 is31fl3733_write_register(bus, addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL); // Turn off all LEDs. - for (int i = 0x00; i <= 0x17; i++) { + for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3733_write_register(bus, addr, i, 0x00); } @@ -180,7 +183,7 @@ void is31fl3733_init(uint8_t bus, uint8_t addr, uint8_t sync) { is31fl3733_write_register(bus, addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. - for (int i = 0x00; i <= 0xBF; i++) { + for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i++) { is31fl3733_write_register(bus, addr, i, 0x00); } @@ -273,7 +276,7 @@ void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) { // Firstly we need to unlock the command register and select PG0 is31fl3733_write_register(index, addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5); is31fl3733_write_register(index, addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL); - for (int i = 0; i < 24; i++) { + for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3733_write_register(index, addr, i, g_led_control_registers[index][i]); } }