Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LED drivers: add defines for PWM and LED control register counts #22383

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions drivers/led/issi/is31fl3218-simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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]);
}

Expand Down
15 changes: 9 additions & 6 deletions drivers/led/issi/is31fl3218.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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]);
}

Expand Down
15 changes: 9 additions & 6 deletions drivers/led/issi/is31fl3731-simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions drivers/led/issi/is31fl3731.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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]);
}
}
Expand Down
17 changes: 10 additions & 7 deletions drivers/led/issi/is31fl3733-simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
17 changes: 10 additions & 7 deletions drivers/led/issi/is31fl3733.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
17 changes: 10 additions & 7 deletions drivers/led/issi/is31fl3736-simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
Loading