From 358bc8eac8e74eb79cd876bc41f3992da2bfcaf3 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 4 Dec 2023 17:52:40 +1100 Subject: LED drivers: refactor page selection (#22518) --- keyboards/input_club/k_type/is31fl3733-dual.c | 35 +++++++++------------ keyboards/input_club/k_type/is31fl3733-dual.h | 1 + .../k_type/keymaps/andrew-fahmy/config.h | 36 ++-------------------- 3 files changed, 17 insertions(+), 55 deletions(-) (limited to 'keyboards/input_club') diff --git a/keyboards/input_club/k_type/is31fl3733-dual.c b/keyboards/input_club/k_type/is31fl3733-dual.c index e471cf0b71..baa3e70833 100644 --- a/keyboards/input_club/k_type/is31fl3733-dual.c +++ b/keyboards/input_club/k_type/is31fl3733-dual.c @@ -64,7 +64,7 @@ uint8_t g_twi_transfer_buffer[20]; // These buffers match the IS31FL3733 PWM registers. -// The control buffers match the PG0 LED On/Off registers. +// The control buffers match the page 0 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 is31fl3733_write_pwm_buffer() but it's @@ -94,8 +94,13 @@ bool is31fl3733_write_register(uint8_t index, uint8_t addr, uint8_t reg, uint8_t return true; } +void is31fl3733_select_page(uint8_t index, uint8_t addr, uint8_t page) { + is31fl3733_write_register(index, addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC); + is31fl3733_write_register(index, addr, IS31FL3733_REG_COMMAND, page); +} + bool is31fl3733_write_pwm_buffer(uint8_t index, uint8_t addr, uint8_t *pwm_buffer) { - // Assumes PG1 is already selected. + // Assumes page 1 is already selected. // If any of the transactions fails function returns false. // Transmit PWM registers in 12 transfers of 16 bytes. // g_twi_transfer_buffer[] is 20 bytes @@ -150,32 +155,23 @@ void is31fl3733_init(uint8_t bus, uint8_t addr, uint8_t sync) { // then disable software shutdown. // Sync is passed so set it according to the datasheet. - // Unlock the command register. - is31fl3733_write_register(bus, addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC); + is31fl3733_select_page(bus, addr, IS31FL3733_COMMAND_LED_CONTROL); - // Select PG0 - is31fl3733_write_register(bus, addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_LED_CONTROL); // Turn off all LEDs. for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3733_write_register(bus, addr, i, 0x00); } - // Unlock the command register. - is31fl3733_write_register(bus, addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC); + is31fl3733_select_page(bus, addr, IS31FL3733_COMMAND_PWM); - // Select PG1 - is31fl3733_write_register(bus, addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_PWM); // Set PWM on all LEDs to 0 // No need to setup Breath registers to PWM as that is the default. for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i++) { is31fl3733_write_register(bus, addr, i, 0x00); } - // Unlock the command register. - is31fl3733_write_register(bus, addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC); + is31fl3733_select_page(bus, addr, IS31FL3733_COMMAND_FUNCTION); - // Select PG3 - is31fl3733_write_register(bus, addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_FUNCTION); // Set de-ghost pull-up resistors (SWx) is31fl3733_write_register(bus, addr, IS31FL3733_FUNCTION_REG_SW_PULLUP, IS31FL3733_SW_PULLUP); // Set de-ghost pull-down resistors (CSx) @@ -242,11 +238,9 @@ void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bo void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) { if (g_pwm_buffer_update_required[index]) { - // Firstly we need to unlock the command register and select PG1. - is31fl3733_write_register(index, addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC); - is31fl3733_write_register(index, addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_PWM); + is31fl3733_select_page(index, addr, IS31FL3733_COMMAND_PWM); - // If any of the transactions fail we risk writing dirty PG0, + // 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; @@ -257,9 +251,8 @@ void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) { void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) { if (g_led_control_registers_update_required[index]) { - // Firstly we need to unlock the command register and select PG0 - is31fl3733_write_register(index, addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC); - is31fl3733_write_register(index, addr, IS31FL3733_REG_COMMAND, IS31FL3733_COMMAND_LED_CONTROL); + is31fl3733_select_page(index, addr, IS31FL3733_COMMAND_LED_CONTROL); + for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) { is31fl3733_write_register(index, addr, i, g_led_control_registers[index][i]); } diff --git a/keyboards/input_club/k_type/is31fl3733-dual.h b/keyboards/input_club/k_type/is31fl3733-dual.h index 2f7d58f7e7..e0fc5fd3b9 100644 --- a/keyboards/input_club/k_type/is31fl3733-dual.h +++ b/keyboards/input_club/k_type/is31fl3733-dual.h @@ -70,6 +70,7 @@ extern const is31fl3733_led_t PROGMEM g_is31fl3733_leds[IS31FL3733_LED_COUNT]; void is31fl3733_init_drivers(void); void is31fl3733_init(uint8_t bus, uint8_t addr, uint8_t sync); bool 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_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); diff --git a/keyboards/input_club/k_type/keymaps/andrew-fahmy/config.h b/keyboards/input_club/k_type/keymaps/andrew-fahmy/config.h index c40495c8de..5052271687 100644 --- a/keyboards/input_club/k_type/keymaps/andrew-fahmy/config.h +++ b/keyboards/input_club/k_type/keymaps/andrew-fahmy/config.h @@ -16,37 +16,5 @@ #pragma once - -#ifdef RGB_MATRIX_ENABLE -// # define RGB_MATRIX_FRAMEBUFFER_EFFECTS -// # define RGB_MATRIX_KEYPRESSES -# define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_RAINDROPS - -// # define DEBUG_MATRIX_SCAN_RATE - -# define RGB_MATRIX_LED_FLUSH_LIMIT 100 -// # define RGB_MATRIX_LED_PROCESS_LIMIT 2 - -// i2c_master defines -# define I2C_COUNT 2 - -# define I2C1_BANK GPIOB -# define I2C1_SCL 0 // A2 on pinout = B0 -# define I2C1_SDA 1 // A2 on pinout = B1 -# define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2 -# define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2 - -# define USE_I2C2 -# define I2C2_BANK GPIOC -# define I2C2_SCL 10 // A2 on pinout = C10 -# define I2C2_SDA 11 // A2 on pinout = C11 -# define I2C2_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2 -# define I2C2_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2 - -# define DRIVER_ADDR_1 0b1010000 -# define DRIVER_ADDR_2 0b1010000 -# define DRIVER_COUNT 2 -# define DRIVER_1_LED_TOTAL 64 -# define DRIVER_2_LED_TOTAL 55 -# define RGB_MATRIX_LED_COUNT (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL) -#endif +#define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_RAINDROPS +#define RGB_MATRIX_LED_FLUSH_LIMIT 100 -- cgit v1.2.3