diff options
Diffstat (limited to 'drivers/led/issi/is31fl3741.c')
-rw-r--r-- | drivers/led/issi/is31fl3741.c | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/drivers/led/issi/is31fl3741.c b/drivers/led/issi/is31fl3741.c index efcfa77b46..3ee75572fa 100644 --- a/drivers/led/issi/is31fl3741.c +++ b/drivers/led/issi/is31fl3741.c @@ -56,7 +56,7 @@ uint8_t g_twi_transfer_buffer[20] = {0xFF}; // These buffers match the IS31FL3741 and IS31FL3741A PWM registers. -// The scaling buffers match the PG2 and PG3 LED On/Off registers. +// The scaling buffers match the page 2 and 3 LED On/Off registers. // Storing them like this is optimal for I2C transfers to the registers. // We could optimize this and take out the unused registers from these // buffers and the transfers in is31fl3741_write_pwm_buffer() but it's @@ -80,14 +80,17 @@ void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) { #endif } +void is31fl3741_select_page(uint8_t addr, uint8_t page) { + is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC); + is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, page); +} + bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) { - // Assume PG0 is already selected + // Assume page 0 is already selected for (int i = 0; i < 342; i += 18) { if (i == 180) { - // unlock the command register and select PG1 - is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC); - is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_PWM_1); + is31fl3741_select_page(addr, IS31FL3741_COMMAND_PWM_1); } g_twi_transfer_buffer[0] = i % 180; @@ -162,11 +165,7 @@ void is31fl3741_init(uint8_t addr) { // then disable software shutdown. // Unlock the command register. - // Unlock the command register. - is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC); - - // Select PG4 - is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_FUNCTION); + is31fl3741_select_page(addr, IS31FL3741_COMMAND_FUNCTION); // Set to Normal operation is31fl3741_write_register(addr, IS31FL3741_FUNCTION_REG_CONFIGURATION, IS31FL3741_CONFIGURATION); @@ -232,9 +231,7 @@ void is31fl3741_set_led_control_register(uint8_t index, bool red, bool green, bo void is31fl3741_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { - // unlock the command register and select PG2 - is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC); - is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_PWM_0); + is31fl3741_select_page(addr, IS31FL3741_COMMAND_PWM_0); is31fl3741_write_pwm_buffer(addr, g_pwm_buffer[index]); } @@ -252,20 +249,16 @@ void is31fl3741_set_pwm_buffer(const is31fl3741_led_t *pled, uint8_t red, uint8_ void is31fl3741_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_scaling_registers_update_required[index]) { - // unlock the command register and select PG2 - is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC); - is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_SCALING_0); + is31fl3741_select_page(addr, IS31FL3741_COMMAND_SCALING_0); - // CS1_SW1 to CS30_SW6 are on PG2 + // CS1_SW1 to CS30_SW6 are on page 2 for (int i = CS1_SW1; i <= CS30_SW6; ++i) { is31fl3741_write_register(addr, i, g_scaling_registers[index][i]); } - // unlock the command register and select PG3 - is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC); - is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, IS31FL3741_COMMAND_SCALING_1); + is31fl3741_select_page(addr, IS31FL3741_COMMAND_SCALING_1); - // CS1_SW7 to CS39_SW9 are on PG3 + // CS1_SW7 to CS39_SW9 are on page 3 for (int i = CS1_SW7; i <= CS39_SW9; ++i) { is31fl3741_write_register(addr, i - CS1_SW7, g_scaling_registers[index][i]); } |