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 Matrix: Split #12633

Merged
merged 1 commit into from
Apr 22, 2021
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
33 changes: 27 additions & 6 deletions quantum/led_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ static uint32_t led_timer_buffer;
static last_hit_t last_hit_buffer;
#endif // LED_MATRIX_KEYREACTIVE_ENABLED

// split led matrix
#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT;
#endif

void eeconfig_read_led_matrix(void) { eeprom_read_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); }

void eeconfig_update_led_matrix(void) { eeprom_update_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); }
Expand Down Expand Up @@ -128,22 +133,38 @@ uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *l
void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); }

void led_matrix_set_value(int index, uint8_t value) {
#ifdef USE_CIE1931_CURVE
led_matrix_driver.set_value(index, pgm_read_byte(&CIE1931_CURVE[value]));
#else
led_matrix_driver.set_value(index, value);
#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
if (!is_keyboard_left() && index >= k_led_matrix_split[0])
# ifdef USE_CIE1931_CURVE
led_matrix_driver.set_value(index - k_led_matrix_split[0], pgm_read_byte(&CIE1931_CURVE[value]));
# else
led_matrix_driver.set_value(index - k_led_matrix_split[0], value);
# endif
else if (is_keyboard_left() && index < k_led_matrix_split[0])
#endif
# ifdef USE_CIE1931_CURVE
led_matrix_driver.set_value(index, pgm_read_byte(&CIE1931_CURVE[value]));
# else
led_matrix_driver.set_value(index, value);
# endif
}

void led_matrix_set_value_all(uint8_t value) {
#ifdef USE_CIE1931_CURVE
led_matrix_driver.set_value_all(pgm_read_byte(&CIE1931_CURVE[value]));
#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) led_matrix_set_value(i, value);
#else
# ifdef USE_CIE1931_CURVE
led_matrix_driver.set_value_all(pgm_read_byte(&CIE1931_CURVE[value]));
# else
led_matrix_driver.set_value_all(value);
# endif
#endif
}

void process_led_matrix(uint8_t row, uint8_t col, bool pressed) {
#ifndef LED_MATRIX_SPLIT
if (!is_keyboard_master()) return;
#endif
#if LED_DISABLE_TIMEOUT > 0
led_anykey_timer = 0;
#endif // LED_DISABLE_TIMEOUT > 0
Expand Down
29 changes: 29 additions & 0 deletions quantum/split_common/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ static pin_t encoders_pad[] = ENCODERS_PAD_A;
# define NUMBER_OF_ENCODERS (sizeof(encoders_pad) / sizeof(pin_t))
#endif

#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
# include "led_matrix.h"
#endif
#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
# include "rgb_matrix.h"
#endif
Expand Down Expand Up @@ -58,6 +61,10 @@ typedef struct _I2C_slave_buffer_t {
# ifdef WPM_ENABLE
uint8_t current_wpm;
# endif
# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
led_eeconfig_t led_matrix;
bool led_suspend_state;
# endif
# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
rgb_config_t rgb_matrix;
bool rgb_suspend_state;
Expand All @@ -76,6 +83,8 @@ static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_re
# define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync)
# define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state)
# define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm)
# define I2C_LED_MATRIX_START offsetof(I2C_slave_buffer_t, led_matrix)
# define I2C_LED_SUSPEND_START offsetof(I2C_slave_buffer_t, led_suspend_state)
# define I2C_RGB_MATRIX_START offsetof(I2C_slave_buffer_t, rgb_matrix)
# define I2C_RGB_SUSPEND_START offsetof(I2C_slave_buffer_t, rgb_suspend_state)

Expand Down Expand Up @@ -151,6 +160,10 @@ bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
# endif
# endif

# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_LED_MATRIX_START, (void *)led_matrix_eeconfig, sizeof(i2c_buffer->led_matrix), TIMEOUT);
i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_LED_SUSPEND_START, (void *)g_suspend_state, sizeof(i2c_buffer->led_suspend_state), TIMEOUT);
# endif
# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_MATRIX_START, (void *)rgb_matrix_config, sizeof(i2c_buffer->rgb_matrix), TIMEOUT);
i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_SUSPEND_START, (void *)g_suspend_state, sizeof(i2c_buffer->rgb_suspend_state), TIMEOUT);
Expand Down Expand Up @@ -202,6 +215,10 @@ void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
# endif
# endif

# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
memcpy((void*)i2c_buffer->led_matrix, (void *)led_matrix_eeconfig, sizeof(i2c_buffer->led_matrix));
memcpy((void*)i2c_buffer->led_suspend_state, (void *)g_suspend_state, sizeof(i2c_buffer->led_suspend_state));
# endif
# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
memcpy((void *)i2c_buffer->rgb_matrix, (void *)rgb_matrix_config, sizeof(i2c_buffer->rgb_matrix));
memcpy((void *)i2c_buffer->rgb_suspend_state, (void *)g_suspend_state, sizeof(i2c_buffer->rgb_suspend_state));
Expand Down Expand Up @@ -246,6 +263,10 @@ typedef struct _Serial_m2s_buffer_t {
# ifdef WPM_ENABLE
uint8_t current_wpm;
# endif
# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
led_eeconfig_t led_matrix;
bool led_suspend_state;
# endif
# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
rgb_config_t rgb_matrix;
bool rgb_suspend_state;
Expand Down Expand Up @@ -368,6 +389,10 @@ bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
# endif
# endif

# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
serial_m2s_buffer.led_matrix = led_matrix_econfig;
serial_m2s_buffer.led_suspend_state = g_suspend_state;
# endif
# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
serial_m2s_buffer.rgb_matrix = rgb_matrix_config;
serial_m2s_buffer.rgb_suspend_state = g_suspend_state;
Expand Down Expand Up @@ -412,6 +437,10 @@ void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
# endif
# endif

# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
led_matrix_eeconfig = serial_m2s_buffer.led_matrix;
g_suspend_state = serial_m2s_buffer.led_suspend_state;
# endif
# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
rgb_matrix_config = serial_m2s_buffer.rgb_matrix;
g_suspend_state = serial_m2s_buffer.rgb_suspend_state;
Expand Down