Skip to content

Commit

Permalink
LED Matrix: driver naming cleanups (qmk#21580)
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark authored Jul 29, 2023
1 parent b4a7b92 commit 571b8ba
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 186 deletions.
16 changes: 8 additions & 8 deletions builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
endif

LED_MATRIX_ENABLE ?= no
VALID_LED_MATRIX_TYPES := IS31FL3731 IS31FL3742A IS31FL3743A IS31FL3745 IS31FL3746A CKLED2001 custom
# TODO: IS31FL3733 IS31FL3737 IS31FL3741
VALID_LED_MATRIX_TYPES := is31fl3731 is31fl3742a is31fl3743a is31fl3745 is31fl3746a ckled2001 custom
# TODO: is31fl3733 is31fl3737 is31fl3741

ifeq ($(strip $(LED_MATRIX_ENABLE)), yes)
ifeq ($(filter $(LED_MATRIX_DRIVER),$(VALID_LED_MATRIX_TYPES)),)
Expand All @@ -373,42 +373,42 @@ endif
SRC += $(LIB_PATH)/lib8tion/lib8tion.c
CIE1931_CURVE := yes

ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3731)
ifeq ($(strip $(LED_MATRIX_DRIVER)), is31fl3731)
OPT_DEFS += -DIS31FL3731 -DSTM32_I2C -DHAL_USE_I2C=TRUE
COMMON_VPATH += $(DRIVER_PATH)/led/issi
SRC += is31fl3731-simple.c
QUANTUM_LIB_SRC += i2c_master.c
endif

ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3742A)
ifeq ($(strip $(LED_MATRIX_DRIVER)), is31fl3742a)
OPT_DEFS += -DIS31FLCOMMON -DIS31FL3742A -DSTM32_I2C -DHAL_USE_I2C=TRUE
COMMON_VPATH += $(DRIVER_PATH)/led/issi
SRC += is31flcommon.c
QUANTUM_LIB_SRC += i2c_master.c
endif

ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3743A)
ifeq ($(strip $(LED_MATRIX_DRIVER)), is31fl3743a)
OPT_DEFS += -DIS31FLCOMMON -DIS31FL3743A -DSTM32_I2C -DHAL_USE_I2C=TRUE
COMMON_VPATH += $(DRIVER_PATH)/led/issi
SRC += is31flcommon.c
QUANTUM_LIB_SRC += i2c_master.c
endif

ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3745)
ifeq ($(strip $(LED_MATRIX_DRIVER)), is31fl3745)
OPT_DEFS += -DIS31FLCOMMON -DIS31FL3745 -DSTM32_I2C -DHAL_USE_I2C=TRUE
COMMON_VPATH += $(DRIVER_PATH)/led/issi
SRC += is31flcommon.c
QUANTUM_LIB_SRC += i2c_master.c
endif

ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3746A)
ifeq ($(strip $(LED_MATRIX_DRIVER)), is31fl3746a)
OPT_DEFS += -DIS31FLCOMMON -DIS31FL3746A -DSTM32_I2C -DHAL_USE_I2C=TRUE
COMMON_VPATH += $(DRIVER_PATH)/led/issi
SRC += is31flcommon.c
QUANTUM_LIB_SRC += i2c_master.c
endif

ifeq ($(strip $(LED_MATRIX_DRIVER)), CKLED2001)
ifeq ($(strip $(LED_MATRIX_DRIVER)), ckled2001)
OPT_DEFS += -DCKLED2001 -DSTM32_I2C -DHAL_USE_I2C=TRUE
COMMON_VPATH += $(DRIVER_PATH)/led
SRC += ckled2001-simple.c
Expand Down
2 changes: 1 addition & 1 deletion docs/feature_led_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ There is basic support for addressable LED matrix lighting with the I2C IS31FL37

```make
LED_MATRIX_ENABLE = yes
LED_MATRIX_DRIVER = IS31FL3731
LED_MATRIX_DRIVER = is31fl3731
```

You can use between 1 and 4 IS31FL3731 IC's. Do not specify `LED_DRIVER_ADDR_<N>` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`:
Expand Down
76 changes: 38 additions & 38 deletions drivers/led/ckled2001-simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ uint8_t g_twi_transfer_buffer[20];
// The control buffers match the PG0 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 CKLED2001_write_pwm_buffer() but it's
// buffers and the transfers in ckled2001_write_pwm_buffer() but it's
// probably not worth the extra complexity.
uint8_t g_pwm_buffer[DRIVER_COUNT][192];
bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};

uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0};
bool g_led_control_registers_update_required[DRIVER_COUNT] = {false};

bool CKLED2001_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
bool ckled2001_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
// If the transaction fails function returns false.
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
Expand All @@ -69,7 +69,7 @@ bool CKLED2001_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
return true;
}

bool CKLED2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
bool ckled2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// Assumes PG1 is already selected.
// If any of the transactions fails function returns false.
// Transmit PWM registers in 12 transfers of 16 bytes.
Expand Down Expand Up @@ -100,53 +100,53 @@ bool CKLED2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
return true;
}

void CKLED2001_init(uint8_t addr) {
void ckled2001_init(uint8_t addr) {
// Select to function page
CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE);
ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE);
// Setting LED driver to shutdown mode
CKLED2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE);
ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE);
// Setting internal channel pulldown/pullup
CKLED2001_write_register(addr, PDU_REG, MSKSET_CA_CB_CHANNEL);
ckled2001_write_register(addr, PDU_REG, MSKSET_CA_CB_CHANNEL);
// Select number of scan phase
CKLED2001_write_register(addr, SCAN_PHASE_REG, PHASE_CHANNEL);
ckled2001_write_register(addr, SCAN_PHASE_REG, PHASE_CHANNEL);
// Setting PWM Delay Phase
CKLED2001_write_register(addr, SLEW_RATE_CONTROL_MODE1_REG, MSKPWM_DELAY_PHASE_ENABLE);
ckled2001_write_register(addr, SLEW_RATE_CONTROL_MODE1_REG, MSKPWM_DELAY_PHASE_ENABLE);
// Setting Driving/Sinking Channel Slew Rate
CKLED2001_write_register(addr, SLEW_RATE_CONTROL_MODE2_REG, MSKDRIVING_SINKING_CHHANNEL_SLEWRATE_ENABLE);
ckled2001_write_register(addr, SLEW_RATE_CONTROL_MODE2_REG, MSKDRIVING_SINKING_CHHANNEL_SLEWRATE_ENABLE);
// Setting Iref
CKLED2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_DISABLE);
ckled2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_DISABLE);
// Set LED CONTROL PAGE (Page 0)
CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE);
ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE);
for (int i = 0; i < LED_CONTROL_ON_OFF_LENGTH; i++) {
CKLED2001_write_register(addr, i, 0x00);
ckled2001_write_register(addr, i, 0x00);
}

// Set PWM PAGE (Page 1)
CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE);
ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE);
for (int i = 0; i < LED_CURRENT_TUNE_LENGTH; i++) {
CKLED2001_write_register(addr, i, 0x00);
ckled2001_write_register(addr, i, 0x00);
}

// Set CURRENT PAGE (Page 4)
uint8_t current_tuen_reg_list[LED_CURRENT_TUNE_LENGTH] = CKLED2001_CURRENT_TUNE;
CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, CURRENT_TUNE_PAGE);
ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, CURRENT_TUNE_PAGE);
for (int i = 0; i < LED_CURRENT_TUNE_LENGTH; i++) {
CKLED2001_write_register(addr, i, current_tuen_reg_list[i]);
ckled2001_write_register(addr, i, current_tuen_reg_list[i]);
}

// Enable LEDs ON/OFF
CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE);
ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE);
for (int i = 0; i < LED_CONTROL_ON_OFF_LENGTH; i++) {
CKLED2001_write_register(addr, i, 0xFF);
ckled2001_write_register(addr, i, 0xFF);
}

// Select to function page
CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE);
ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE);
// Setting LED driver to normal mode
CKLED2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE);
ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE);
}

void CKLED2001_set_value(int index, uint8_t value) {
void ckled2001_set_value(int index, uint8_t value) {
ckled2001_led led;
if (index >= 0 && index < LED_MATRIX_LED_COUNT) {
memcpy_P(&led, (&g_ckled2001_leds[index]), sizeof(led));
Expand All @@ -159,13 +159,13 @@ void CKLED2001_set_value(int index, uint8_t value) {
}
}

void CKLED2001_set_value_all(uint8_t value) {
void ckled2001_set_value_all(uint8_t value) {
for (int i = 0; i < LED_MATRIX_LED_COUNT; i++) {
CKLED2001_set_value(i, value);
ckled2001_set_value(i, value);
}
}

void CKLED2001_set_led_control_register(uint8_t index, bool value) {
void ckled2001_set_led_control_register(uint8_t index, bool value) {
ckled2001_led led;
memcpy_P(&led, (&g_ckled2001_leds[index]), sizeof(led));

Expand All @@ -181,41 +181,41 @@ void CKLED2001_set_led_control_register(uint8_t index, bool value) {
g_led_control_registers_update_required[led.driver] = true;
}

void CKLED2001_update_pwm_buffers(uint8_t addr, uint8_t index) {
void ckled2001_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE);
ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE);

// If any of the transactions fail we risk writing dirty PG0,
// refresh page 0 just in case.
if (!CKLED2001_write_pwm_buffer(addr, g_pwm_buffer[index])) {
if (!ckled2001_write_pwm_buffer(addr, g_pwm_buffer[index])) {
g_led_control_registers_update_required[index] = true;
}
}
g_pwm_buffer_update_required[index] = false;
}

void CKLED2001_update_led_control_registers(uint8_t addr, uint8_t index) {
void ckled2001_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE);
ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE);
for (int i = 0; i < 24; i++) {
CKLED2001_write_register(addr, i, g_led_control_registers[index][i]);
ckled2001_write_register(addr, i, g_led_control_registers[index][i]);
}
}
g_led_control_registers_update_required[index] = false;
}

void CKLED2001_sw_return_normal(uint8_t addr) {
void ckled2001_sw_return_normal(uint8_t addr) {
// Select to function page
CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE);
ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE);
// Setting LED driver to normal mode
CKLED2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE);
ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE);
}

void CKLED2001_sw_shutdown(uint8_t addr) {
void ckled2001_sw_shutdown(uint8_t addr) {
// Select to function page
CKLED2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE);
ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE);
// Setting LED driver to shutdown mode
CKLED2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE);
ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE);
// Write SW Sleep Register
CKLED2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_ENABLE);
ckled2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_ENABLE);
}
20 changes: 10 additions & 10 deletions drivers/led/ckled2001-simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ typedef struct ckled2001_led {

extern const ckled2001_led PROGMEM g_ckled2001_leds[LED_MATRIX_LED_COUNT];

void CKLED2001_init(uint8_t addr);
bool CKLED2001_write_register(uint8_t addr, uint8_t reg, uint8_t data);
bool CKLED2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
void ckled2001_init(uint8_t addr);
bool ckled2001_write_register(uint8_t addr, uint8_t reg, uint8_t data);
bool ckled2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);

void CKLED2001_set_value(int index, uint8_t value);
void CKLED2001_set_value_all(uint8_t value);
void ckled2001_set_value(int index, uint8_t value);
void ckled2001_set_value_all(uint8_t value);

void CKLED2001_set_led_control_register(uint8_t index, bool value);
void ckled2001_set_led_control_register(uint8_t index, bool value);

// This should not be called from an interrupt
// (eg. from a timer interrupt).
// Call this while idle (in between matrix scans).
// If the buffer is dirty, it will update the driver with the buffer.
void CKLED2001_update_pwm_buffers(uint8_t addr, uint8_t index);
void CKLED2001_update_led_control_registers(uint8_t addr, uint8_t index);
void ckled2001_update_pwm_buffers(uint8_t addr, uint8_t index);
void ckled2001_update_led_control_registers(uint8_t addr, uint8_t index);

void CKLED2001_sw_return_normal(uint8_t addr);
void CKLED2001_sw_shutdown(uint8_t addr);
void ckled2001_sw_return_normal(uint8_t addr);
void ckled2001_sw_shutdown(uint8_t addr);

// Registers Page Define
#define CONFIGURE_CMD_PAGE 0xFD
Expand Down
Loading

0 comments on commit 571b8ba

Please sign in to comment.