From a8d0ec0749046b0ab89c18b1b7083b1e8674de2a Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Tue, 1 Dec 2020 12:04:42 -0600 Subject: [Split] Sync Timer feature (#10997) A timer that is kept in sync between the halves of a split keyboard --- quantum/split_common/transport.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'quantum/split_common') diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index 467ff81a97..6856b60558 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c @@ -6,6 +6,7 @@ #include "quantum.h" #define ROWS_PER_HAND (MATRIX_ROWS / 2) +#define SYNC_TIMER_OFFSET 2 #ifdef RGBLIGHT_ENABLE # include "rgblight.h" @@ -27,6 +28,9 @@ static pin_t encoders_pad[] = ENCODERS_PAD_A; # include "i2c_slave.h" typedef struct _I2C_slave_buffer_t { +# ifndef DISABLE_SYNC_TIMER + uint32_t sync_timer; +# endif matrix_row_t smatrix[ROWS_PER_HAND]; uint8_t backlight_level; # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) @@ -44,6 +48,7 @@ static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_re # define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level) # define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) +# define I2C_SYNC_TIME_START offsetof(I2C_slave_buffer_t, sync_timer) # define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix) # define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) # define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) @@ -91,10 +96,18 @@ bool transport_master(matrix_row_t matrix[]) { } } # endif + +# ifndef DISABLE_SYNC_TIMER + i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; + i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT); +# endif return true; } void transport_slave(matrix_row_t matrix[]) { +# ifndef DISABLE_SYNC_TIMER + sync_timer_update(i2c_buffer->sync_timer); +# endif // Copy matrix to I2C buffer memcpy((void *)i2c_buffer->smatrix, (void *)matrix, sizeof(i2c_buffer->smatrix)); @@ -133,12 +146,15 @@ typedef struct _Serial_s2m_buffer_t { matrix_row_t smatrix[ROWS_PER_HAND]; # ifdef ENCODER_ENABLE - uint8_t encoder_state[NUMBER_OF_ENCODERS]; + uint8_t encoder_state[NUMBER_OF_ENCODERS]; # endif } Serial_s2m_buffer_t; typedef struct _Serial_m2s_buffer_t { +# ifndef DISABLE_SYNC_TIMER + uint32_t sync_timer; +# endif # ifdef BACKLIGHT_ENABLE uint8_t backlight_level; # endif @@ -251,11 +267,19 @@ bool transport_master(matrix_row_t matrix[]) { // Write wpm to slave serial_m2s_buffer.current_wpm = get_current_wpm(); # endif + +# ifndef DISABLE_SYNC_TIMER + serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; +# endif return true; } void transport_slave(matrix_row_t matrix[]) { transport_rgblight_slave(); +# ifndef DISABLE_SYNC_TIMER + sync_timer_update(serial_m2s_buffer.sync_timer); +# endif + // TODO: if MATRIX_COLS > 8 change to pack() for (int i = 0; i < ROWS_PER_HAND; ++i) { serial_s2m_buffer.smatrix[i] = matrix[i]; -- cgit v1.2.3 From 5e2b53541bef9b380380286724b321cc8a0ac413 Mon Sep 17 00:00:00 2001 From: Casey Webster Date: Wed, 16 Dec 2020 23:21:26 -0600 Subject: Add modifier state to the split keyboard transport (#10400) * Add modifier state to the split transport This adds modifier state to the i2c and serial transport for split keyboards. The purpose of this is to allow e.g. displaying modifier state on the slave side of a split keyboard on an oled. This adds one byte to the data transferred between halves. This also fixes a missing ifdef guard for BLACKLIGHT_ENABLE. Break modifiers into real/weak/oneshot Fix incorrect slave serial mod setting Fix typo in serial weal mod setter Fix build errors for the I2C code that I introduced Code cleanup and formatting per project preferences Correctly get oneshot mods Fix missing braces Remove unneeded ifdef guard Make the added state transport optional Add documentation for the new define to enable this feature Fix stray grave mark * Fix error introduced in conflict resolution --- quantum/split_common/transport.c | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'quantum/split_common') diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index 6856b60558..ae0c10b827 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c @@ -32,7 +32,16 @@ typedef struct _I2C_slave_buffer_t { uint32_t sync_timer; # endif matrix_row_t smatrix[ROWS_PER_HAND]; +# ifdef SPLIT_MODS_ENABLE + uint8_t real_mods; + uint8_t weak_mods; +# ifndef NO_ACTION_ONESHOT + uint8_t oneshot_mods; +# endif +# endif +# ifdef BACKLIGHT_ENABLE uint8_t backlight_level; +# endif # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) rgblight_syncinfo_t rgblight_sync; # endif @@ -46,6 +55,10 @@ typedef struct _I2C_slave_buffer_t { static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg; +# define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix) +# define I2C_REAL_MODS_START offsetof(I2C_slave_buffer_t, real_mods) +# define I2C_WEAK_MODS_START offsetof(I2C_slave_buffer_t, weak_mods) +# define I2C_ONESHOT_MODS_START offsetof(I2C_slave_buffer_t, oneshot_mods) # define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level) # define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) # define I2C_SYNC_TIME_START offsetof(I2C_slave_buffer_t, sync_timer) @@ -97,6 +110,31 @@ bool transport_master(matrix_row_t matrix[]) { } # endif +# ifdef SPLIT_MODS_ENABLE + uint8_t real_mods = get_mods(); + if (real_mods != i2c_buffer->real_mods) { + if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_REAL_MODS_START, (void *)&real_mods, sizeof(real_mods), TIMEOUT) >= 0) { + i2c_buffer->real_mods = real_mods; + } + } + + uint8_t weak_mods = get_weak_mods(); + if (weak_mods != i2c_buffer->weak_mods) { + if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_WEAK_MODS_START, (void *)&weak_mods, sizeof(weak_mods), TIMEOUT) >= 0) { + i2c_buffer->weak_mods = weak_mods; + } + } + +# ifndef NO_ACTION_ONESHOT + uint8_t oneshot_mods = get_oneshot_mods(); + if (oneshot_mods != i2c_buffer->oneshot_mods) { + if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_ONESHOT_MODS_START, (void *)&oneshot_mods, sizeof(oneshot_mods), TIMEOUT) >= 0) { + i2c_buffer->oneshot_mods = oneshot_mods; + } + } +# endif +# endif + # ifndef DISABLE_SYNC_TIMER i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT); @@ -131,6 +169,14 @@ void transport_slave(matrix_row_t matrix[]) { # ifdef WPM_ENABLE set_current_wpm(i2c_buffer->current_wpm); # endif + +# ifdef SPLIT_MODS_ENABLE + set_mods(i2c_buffer->real_mods); + set_weak_mods(i2c_buffer->weak_mods); +# ifndef NO_ACTION_ONESHOT + set_oneshot_mods(i2c_buffer->oneshot_mods); +# endif +# endif } void transport_master_init(void) { i2c_init(); } @@ -152,6 +198,13 @@ typedef struct _Serial_s2m_buffer_t { } Serial_s2m_buffer_t; typedef struct _Serial_m2s_buffer_t { +# ifdef SPLIT_MODS_ENABLE + uint8_t real_mods; + uint8_t weak_mods; +# ifndef NO_ACTION_ONESHOT + uint8_t oneshot_mods; +# endif +# endif # ifndef DISABLE_SYNC_TIMER uint32_t sync_timer; # endif @@ -268,6 +321,13 @@ bool transport_master(matrix_row_t matrix[]) { serial_m2s_buffer.current_wpm = get_current_wpm(); # endif +# ifdef SPLIT_MODS_ENABLE + serial_m2s_buffer.real_mods = get_mods(); + serial_m2s_buffer.weak_mods = get_weak_mods(); +# ifndef NO_ACTION_ONESHOT + serial_m2s_buffer.oneshot_mods = get_oneshot_mods(); +# endif +# endif # ifndef DISABLE_SYNC_TIMER serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; # endif @@ -295,6 +355,14 @@ void transport_slave(matrix_row_t matrix[]) { # ifdef WPM_ENABLE set_current_wpm(serial_m2s_buffer.current_wpm); # endif + +# ifdef SPLIT_MODS_ENABLE + set_mods(serial_m2s_buffer.real_mods); + set_weak_mods(serial_m2s_buffer.weak_mods); +# ifndef NO_ACTION_ONESHOT + set_oneshot_mods(serial_m2s_buffer.oneshot_mods); +# endif +# endif } #endif -- cgit v1.2.3 From 115b60b0e11f8661385b2219ce5ddbf2982b1f8c Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 18 Dec 2020 02:49:24 +1100 Subject: Fix duplicate I2C_KEYMAP_START define (#11237) --- quantum/split_common/transport.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'quantum/split_common') diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index ae0c10b827..e601fb4df5 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c @@ -55,14 +55,13 @@ typedef struct _I2C_slave_buffer_t { static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg; +# define I2C_SYNC_TIME_START offsetof(I2C_slave_buffer_t, sync_timer) # define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix) # define I2C_REAL_MODS_START offsetof(I2C_slave_buffer_t, real_mods) # define I2C_WEAK_MODS_START offsetof(I2C_slave_buffer_t, weak_mods) # define I2C_ONESHOT_MODS_START offsetof(I2C_slave_buffer_t, oneshot_mods) # define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level) # define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) -# define I2C_SYNC_TIME_START offsetof(I2C_slave_buffer_t, sync_timer) -# define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix) # define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) # define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) -- cgit v1.2.3 From 79d1db332477963555416d9fff82ecac4399bd52 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Tue, 12 Jan 2021 19:48:24 +1100 Subject: Keep track of last matrix activity (#10730) * Allow recording of the last matrix activity time, to simplify implementation of display timeouts and the like. * Add requested changes from code review. * Simplify split matrix last changed. --- quantum/split_common/matrix.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'quantum/split_common') diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index 51bf8b1095..06bab734e7 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c @@ -245,48 +245,59 @@ void matrix_init(void) { split_post_init(); } -void matrix_post_scan(void) { +bool matrix_post_scan(void) { + bool changed = false; if (is_keyboard_master()) { static uint8_t error_count; - if (!transport_master(matrix + thatHand)) { + matrix_row_t slave_matrix[ROWS_PER_HAND] = {0}; + if (!transport_master(slave_matrix)) { error_count++; if (error_count > ERROR_DISCONNECT_COUNT) { // reset other half if disconnected for (int i = 0; i < ROWS_PER_HAND; ++i) { - matrix[thatHand + i] = 0; + slave_matrix[i] = 0; } } } else { error_count = 0; } + for (int i = 0; i < ROWS_PER_HAND; ++i) { + if (matrix[thatHand + i] != slave_matrix[i]) { + matrix[thatHand + i] = slave_matrix[i]; + changed = true; + } + } + matrix_scan_quantum(); } else { transport_slave(matrix + thisHand); matrix_slave_scan_user(); } + + return changed; } uint8_t matrix_scan(void) { - bool changed = false; + bool local_changed = false; #if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) // Set row, read cols for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) { - changed |= read_cols_on_row(raw_matrix, current_row); + local_changed |= read_cols_on_row(raw_matrix, current_row); } #elif (DIODE_DIRECTION == ROW2COL) // Set col, read rows for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { - changed |= read_rows_on_col(raw_matrix, current_col); + local_changed |= read_rows_on_col(raw_matrix, current_col); } #endif - debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, changed); + debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, local_changed); - matrix_post_scan(); - return (uint8_t)changed; + bool remote_changed = matrix_post_scan(); + return (uint8_t)(local_changed || remote_changed); } -- cgit v1.2.3 From 302b35c2a0ac90208e523944e8cc4b44a793d8d5 Mon Sep 17 00:00:00 2001 From: Takeshi ISHII <2170248+mtei@users.noreply.github.com> Date: Wed, 13 Jan 2021 10:46:22 +0900 Subject: fix matrix_io_delay() timing in quantum/matrix.c (#9603) * fix matrix_io_delay() timing in quantum/matrix.c * Updated comments explaining the need for matrix_io_delay() in quantum/matrix.c * fix matrix_io_delay() timing in quantum/split_common/matrix.c * Update quantum/matrix.c Co-authored-by: Ryan * Update quantum/split_common/matrix.c Co-authored-by: Ryan * Update quantum/matrix.c Co-authored-by: Ryan * Update quantum/split_common/matrix.c Co-authored-by: Ryan * add waitOutputPinValid() and wait_cpuclock() into quantum/quantum.h and tmk_core/common/wait.h * add matrix_output_select_delay() and matrix_output_unselect_delay() * fix quantum/matrix_common.c, tmk_core/common/matrix.h * fix tmk_core/common/wait.h * fix quantum/quantum.h, tmk_core/common/wait.h * waitOutputPinValid() rename to waitInputPinDelay() in quantum/quantum.h. * waitOutputPinValid() rename to waitInputPinDelay() in quantum/matrix_common.c * update tmk_core/common/wait.h * update comment in quantum/matrix.c, quantum/split_common/matrix.c * update quantum/quantum.h: Make more margin in the GPIO_INPUT_PIN_DELAY default value. Co-authored-by: Ryan --- quantum/split_common/matrix.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'quantum/split_common') diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index 06bab734e7..067815c991 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c @@ -114,9 +114,9 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) // Start with a clear matrix row matrix_row_t current_row_value = 0; - // Select row and wait for row selecton to stabilize + // Select row select_row(current_row); - matrix_io_delay(); + matrix_output_select_delay(); // For each col... for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { @@ -129,6 +129,9 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) // Unselect row unselect_row(current_row); + if (current_row + 1 < MATRIX_ROWS) { + matrix_output_unselect_delay(); // wait for row signal to go HIGH + } // If the row has changed, store the row and return the changed flag. if (current_matrix[current_row] != current_row_value) { @@ -160,9 +163,9 @@ static void init_pins(void) { static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { bool matrix_changed = false; - // Select col and wait for col selecton to stabilize + // Select col select_col(current_col); - matrix_io_delay(); + matrix_output_select_delay(); // For each row... for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) { @@ -188,6 +191,9 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) // Unselect col unselect_col(current_col); + if (current_col + 1 < MATRIX_COLS) { + matrix_output_unselect_delay(); // wait for col signal to go HIGH + } return matrix_changed; } -- cgit v1.2.3 From ab375d3d075c105f09a1ddd0e155f178225518bc Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Fri, 15 Jan 2021 06:55:07 +1100 Subject: Revert "Keep track of last matrix activity (#10730)" This reverts commit 79d1db332477963555416d9fff82ecac4399bd52. --- quantum/split_common/matrix.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'quantum/split_common') diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index 067815c991..22ff89bfc6 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c @@ -251,59 +251,48 @@ void matrix_init(void) { split_post_init(); } -bool matrix_post_scan(void) { - bool changed = false; +void matrix_post_scan(void) { if (is_keyboard_master()) { static uint8_t error_count; - matrix_row_t slave_matrix[ROWS_PER_HAND] = {0}; - if (!transport_master(slave_matrix)) { + if (!transport_master(matrix + thatHand)) { error_count++; if (error_count > ERROR_DISCONNECT_COUNT) { // reset other half if disconnected for (int i = 0; i < ROWS_PER_HAND; ++i) { - slave_matrix[i] = 0; + matrix[thatHand + i] = 0; } } } else { error_count = 0; } - for (int i = 0; i < ROWS_PER_HAND; ++i) { - if (matrix[thatHand + i] != slave_matrix[i]) { - matrix[thatHand + i] = slave_matrix[i]; - changed = true; - } - } - matrix_scan_quantum(); } else { transport_slave(matrix + thisHand); matrix_slave_scan_user(); } - - return changed; } uint8_t matrix_scan(void) { - bool local_changed = false; + bool changed = false; #if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) // Set row, read cols for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) { - local_changed |= read_cols_on_row(raw_matrix, current_row); + changed |= read_cols_on_row(raw_matrix, current_row); } #elif (DIODE_DIRECTION == ROW2COL) // Set col, read rows for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { - local_changed |= read_rows_on_col(raw_matrix, current_col); + changed |= read_rows_on_col(raw_matrix, current_col); } #endif - debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, local_changed); + debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, changed); - bool remote_changed = matrix_post_scan(); - return (uint8_t)(local_changed || remote_changed); + matrix_post_scan(); + return (uint8_t)changed; } -- cgit v1.2.3 From e702c7f1b4cfa8fe1579498ef2877994baa64056 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Mon, 18 Jan 2021 05:01:38 +1100 Subject: Keep track of last matrix activity. (#11552) Co-authored-by: Dasky Co-authored-by: Dasky --- quantum/split_common/matrix.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'quantum/split_common') diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index 22ff89bfc6..631e960ead 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c @@ -251,21 +251,33 @@ void matrix_init(void) { split_post_init(); } -void matrix_post_scan(void) { +bool matrix_post_scan(void) { + bool changed = false; if (is_keyboard_master()) { static uint8_t error_count; - if (!transport_master(matrix + thatHand)) { + matrix_row_t slave_matrix[ROWS_PER_HAND] = {0}; + if (!transport_master(slave_matrix)) { error_count++; if (error_count > ERROR_DISCONNECT_COUNT) { // reset other half if disconnected for (int i = 0; i < ROWS_PER_HAND; ++i) { matrix[thatHand + i] = 0; + slave_matrix[i] = 0; } + + changed = true; } } else { error_count = 0; + + for (int i = 0; i < ROWS_PER_HAND; ++i) { + if (matrix[thatHand + i] != slave_matrix[i]) { + matrix[thatHand + i] = slave_matrix[i]; + changed = true; + } + } } matrix_scan_quantum(); @@ -274,25 +286,27 @@ void matrix_post_scan(void) { matrix_slave_scan_user(); } + + return changed; } uint8_t matrix_scan(void) { - bool changed = false; + bool local_changed = false; #if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) // Set row, read cols for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) { - changed |= read_cols_on_row(raw_matrix, current_row); + local_changed |= read_cols_on_row(raw_matrix, current_row); } #elif (DIODE_DIRECTION == ROW2COL) // Set col, read rows for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { - changed |= read_rows_on_col(raw_matrix, current_col); + local_changed |= read_rows_on_col(raw_matrix, current_col); } #endif - debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, changed); + debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, local_changed); - matrix_post_scan(); - return (uint8_t)changed; + bool remote_changed = matrix_post_scan(); + return (uint8_t)(local_changed || remote_changed); } -- cgit v1.2.3 From 31c57aab35e6fd49c4c8336f449419afe7630e93 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Mon, 18 Jan 2021 05:12:15 +1100 Subject: `qmk cformat` --- quantum/split_common/matrix.c | 2 +- quantum/split_common/transport.c | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'quantum/split_common') diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index 631e960ead..bad762b493 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c @@ -264,7 +264,7 @@ bool matrix_post_scan(void) { // reset other half if disconnected for (int i = 0; i < ROWS_PER_HAND; ++i) { matrix[thatHand + i] = 0; - slave_matrix[i] = 0; + slave_matrix[i] = 0; } changed = true; diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index e601fb4df5..b45ba92c3b 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c @@ -40,7 +40,7 @@ typedef struct _I2C_slave_buffer_t { # endif # endif # ifdef BACKLIGHT_ENABLE - uint8_t backlight_level; + uint8_t backlight_level; # endif # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) rgblight_syncinfo_t rgblight_sync; @@ -172,9 +172,9 @@ void transport_slave(matrix_row_t matrix[]) { # ifdef SPLIT_MODS_ENABLE set_mods(i2c_buffer->real_mods); set_weak_mods(i2c_buffer->weak_mods); -# ifndef NO_ACTION_ONESHOT +# ifndef NO_ACTION_ONESHOT set_oneshot_mods(i2c_buffer->oneshot_mods); -# endif +# endif # endif } @@ -191,27 +191,27 @@ typedef struct _Serial_s2m_buffer_t { matrix_row_t smatrix[ROWS_PER_HAND]; # ifdef ENCODER_ENABLE - uint8_t encoder_state[NUMBER_OF_ENCODERS]; + uint8_t encoder_state[NUMBER_OF_ENCODERS]; # endif } Serial_s2m_buffer_t; typedef struct _Serial_m2s_buffer_t { # ifdef SPLIT_MODS_ENABLE - uint8_t real_mods; - uint8_t weak_mods; + uint8_t real_mods; + uint8_t weak_mods; # ifndef NO_ACTION_ONESHOT - uint8_t oneshot_mods; + uint8_t oneshot_mods; # endif # endif # ifndef DISABLE_SYNC_TIMER uint32_t sync_timer; # endif # ifdef BACKLIGHT_ENABLE - uint8_t backlight_level; + uint8_t backlight_level; # endif # ifdef WPM_ENABLE - uint8_t current_wpm; + uint8_t current_wpm; # endif } Serial_m2s_buffer_t; @@ -317,18 +317,18 @@ bool transport_master(matrix_row_t matrix[]) { # ifdef WPM_ENABLE // Write wpm to slave - serial_m2s_buffer.current_wpm = get_current_wpm(); + serial_m2s_buffer.current_wpm = get_current_wpm(); # endif # ifdef SPLIT_MODS_ENABLE - serial_m2s_buffer.real_mods = get_mods(); - serial_m2s_buffer.weak_mods = get_weak_mods(); + serial_m2s_buffer.real_mods = get_mods(); + serial_m2s_buffer.weak_mods = get_weak_mods(); # ifndef NO_ACTION_ONESHOT serial_m2s_buffer.oneshot_mods = get_oneshot_mods(); # endif # endif # ifndef DISABLE_SYNC_TIMER - serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; + serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; # endif return true; } -- cgit v1.2.3 From d1806a26e4ad75fa0e0405283803eba22c1a49ba Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Mon, 15 Feb 2021 18:30:33 -0600 Subject: Split transport mirror (#11046) * Split transport mirror support * Updated RGB Matrix to respond to electrical events instead of key events * split matrix slave fix --- quantum/split_common/matrix.c | 4 ++-- quantum/split_common/transport.c | 37 ++++++++++++++++++++++++++++--------- quantum/split_common/transport.h | 4 ++-- 3 files changed, 32 insertions(+), 13 deletions(-) (limited to 'quantum/split_common') diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index bad762b493..d6636b886a 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c @@ -257,7 +257,7 @@ bool matrix_post_scan(void) { static uint8_t error_count; matrix_row_t slave_matrix[ROWS_PER_HAND] = {0}; - if (!transport_master(slave_matrix)) { + if (!transport_master(matrix + thisHand, slave_matrix)) { error_count++; if (error_count > ERROR_DISCONNECT_COUNT) { @@ -282,7 +282,7 @@ bool matrix_post_scan(void) { matrix_scan_quantum(); } else { - transport_slave(matrix + thisHand); + transport_slave(matrix + thatHand, matrix + thisHand); matrix_slave_scan_user(); } diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index b45ba92c3b..977b5dc33e 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c @@ -30,6 +30,9 @@ static pin_t encoders_pad[] = ENCODERS_PAD_A; typedef struct _I2C_slave_buffer_t { # ifndef DISABLE_SYNC_TIMER uint32_t sync_timer; +# endif +# ifdef SPLIT_TRANSPORT_MIRROR + matrix_row_t mmatrix[ROWS_PER_HAND]; # endif matrix_row_t smatrix[ROWS_PER_HAND]; # ifdef SPLIT_MODS_ENABLE @@ -56,7 +59,8 @@ typedef struct _I2C_slave_buffer_t { static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg; # define I2C_SYNC_TIME_START offsetof(I2C_slave_buffer_t, sync_timer) -# define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix) +# define I2C_KEYMAP_MASTER_START offsetof(I2C_slave_buffer_t, mmatrix) +# define I2C_KEYMAP_SLAVE_START offsetof(I2C_slave_buffer_t, smatrix) # define I2C_REAL_MODS_START offsetof(I2C_slave_buffer_t, real_mods) # define I2C_WEAK_MODS_START offsetof(I2C_slave_buffer_t, weak_mods) # define I2C_ONESHOT_MODS_START offsetof(I2C_slave_buffer_t, oneshot_mods) @@ -72,8 +76,11 @@ static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_re # endif // Get rows from other half over i2c -bool transport_master(matrix_row_t matrix[]) { - i2c_readReg(SLAVE_I2C_ADDRESS, I2C_KEYMAP_START, (void *)matrix, sizeof(i2c_buffer->smatrix), TIMEOUT); +bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + i2c_readReg(SLAVE_I2C_ADDRESS, I2C_KEYMAP_SLAVE_START, (void *)slave_matrix, sizeof(i2c_buffer->smatrix), TIMEOUT); +#ifdef SPLIT_TRANSPORT_MIRROR + i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_KEYMAP_MASTER_START, (void *)master_matrix, sizeof(i2c_buffer->mmatrix), TIMEOUT); +#endif // write backlight info # ifdef BACKLIGHT_ENABLE @@ -141,12 +148,15 @@ bool transport_master(matrix_row_t matrix[]) { return true; } -void transport_slave(matrix_row_t matrix[]) { +void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { # ifndef DISABLE_SYNC_TIMER sync_timer_update(i2c_buffer->sync_timer); # endif // Copy matrix to I2C buffer - memcpy((void *)i2c_buffer->smatrix, (void *)matrix, sizeof(i2c_buffer->smatrix)); + memcpy((void*)i2c_buffer->smatrix, (void *)slave_matrix, sizeof(i2c_buffer->smatrix)); +#ifdef SPLIT_TRANSPORT_MIRROR + memcpy((void*)master_matrix, (void *)i2c_buffer->mmatrix, sizeof(i2c_buffer->mmatrix)); +#endif // Read Backlight Info # ifdef BACKLIGHT_ENABLE @@ -207,6 +217,9 @@ typedef struct _Serial_m2s_buffer_t { # ifndef DISABLE_SYNC_TIMER uint32_t sync_timer; # endif +# ifdef SPLIT_TRANSPORT_MIRROR + matrix_row_t mmatrix[ROWS_PER_HAND]; +# endif # ifdef BACKLIGHT_ENABLE uint8_t backlight_level; # endif @@ -289,7 +302,7 @@ void transport_rgblight_slave(void) { # define transport_rgblight_slave() # endif -bool transport_master(matrix_row_t matrix[]) { +bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { # ifndef SERIAL_USE_MULTI_TRANSACTION if (soft_serial_transaction() != TRANSACTION_END) { return false; @@ -303,7 +316,10 @@ bool transport_master(matrix_row_t matrix[]) { // TODO: if MATRIX_COLS > 8 change to unpack() for (int i = 0; i < ROWS_PER_HAND; ++i) { - matrix[i] = serial_s2m_buffer.smatrix[i]; + slave_matrix[i] = serial_s2m_buffer.smatrix[i]; +#ifdef SPLIT_TRANSPORT_MIRROR + serial_m2s_buffer.mmatrix[i] = master_matrix[i]; +#endif } # ifdef BACKLIGHT_ENABLE @@ -333,7 +349,7 @@ bool transport_master(matrix_row_t matrix[]) { return true; } -void transport_slave(matrix_row_t matrix[]) { +void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { transport_rgblight_slave(); # ifndef DISABLE_SYNC_TIMER sync_timer_update(serial_m2s_buffer.sync_timer); @@ -341,7 +357,10 @@ void transport_slave(matrix_row_t matrix[]) { // TODO: if MATRIX_COLS > 8 change to pack() for (int i = 0; i < ROWS_PER_HAND; ++i) { - serial_s2m_buffer.smatrix[i] = matrix[i]; + serial_s2m_buffer.smatrix[i] = slave_matrix[i]; +#ifdef SPLIT_TRANSPORT_MIRROR + master_matrix[i] = serial_m2s_buffer.mmatrix[i]; +#endif } # ifdef BACKLIGHT_ENABLE backlight_set(serial_m2s_buffer.backlight_level); diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h index c667bfab85..a9f66301bf 100644 --- a/quantum/split_common/transport.h +++ b/quantum/split_common/transport.h @@ -6,5 +6,5 @@ void transport_master_init(void); void transport_slave_init(void); // returns false if valid data not received from slave -bool transport_master(matrix_row_t matrix[]); -void transport_slave(matrix_row_t matrix[]); +bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]); +void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]); -- cgit v1.2.3 From b0e161e33d8ec030c6965daa57a76ec70b1a1122 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 16 Feb 2021 11:33:03 +1100 Subject: Format code according to conventions (#11928) Co-authored-by: QMK Bot --- quantum/split_common/transport.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'quantum/split_common') diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index 977b5dc33e..61b61ea08c 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c @@ -78,9 +78,9 @@ static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_re // Get rows from other half over i2c bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { i2c_readReg(SLAVE_I2C_ADDRESS, I2C_KEYMAP_SLAVE_START, (void *)slave_matrix, sizeof(i2c_buffer->smatrix), TIMEOUT); -#ifdef SPLIT_TRANSPORT_MIRROR +# ifdef SPLIT_TRANSPORT_MIRROR i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_KEYMAP_MASTER_START, (void *)master_matrix, sizeof(i2c_buffer->mmatrix), TIMEOUT); -#endif +# endif // write backlight info # ifdef BACKLIGHT_ENABLE @@ -153,10 +153,10 @@ void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) sync_timer_update(i2c_buffer->sync_timer); # endif // Copy matrix to I2C buffer - memcpy((void*)i2c_buffer->smatrix, (void *)slave_matrix, sizeof(i2c_buffer->smatrix)); -#ifdef SPLIT_TRANSPORT_MIRROR - memcpy((void*)master_matrix, (void *)i2c_buffer->mmatrix, sizeof(i2c_buffer->mmatrix)); -#endif + memcpy((void *)i2c_buffer->smatrix, (void *)slave_matrix, sizeof(i2c_buffer->smatrix)); +# ifdef SPLIT_TRANSPORT_MIRROR + memcpy((void *)master_matrix, (void *)i2c_buffer->mmatrix, sizeof(i2c_buffer->mmatrix)); +# endif // Read Backlight Info # ifdef BACKLIGHT_ENABLE @@ -208,23 +208,23 @@ typedef struct _Serial_s2m_buffer_t { typedef struct _Serial_m2s_buffer_t { # ifdef SPLIT_MODS_ENABLE - uint8_t real_mods; - uint8_t weak_mods; + uint8_t real_mods; + uint8_t weak_mods; # ifndef NO_ACTION_ONESHOT - uint8_t oneshot_mods; + uint8_t oneshot_mods; # endif # endif # ifndef DISABLE_SYNC_TIMER - uint32_t sync_timer; + uint32_t sync_timer; # endif # ifdef SPLIT_TRANSPORT_MIRROR matrix_row_t mmatrix[ROWS_PER_HAND]; # endif # ifdef BACKLIGHT_ENABLE - uint8_t backlight_level; + uint8_t backlight_level; # endif # ifdef WPM_ENABLE - uint8_t current_wpm; + uint8_t current_wpm; # endif } Serial_m2s_buffer_t; @@ -316,10 +316,10 @@ bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) // TODO: if MATRIX_COLS > 8 change to unpack() for (int i = 0; i < ROWS_PER_HAND; ++i) { - slave_matrix[i] = serial_s2m_buffer.smatrix[i]; -#ifdef SPLIT_TRANSPORT_MIRROR + slave_matrix[i] = serial_s2m_buffer.smatrix[i]; +# ifdef SPLIT_TRANSPORT_MIRROR serial_m2s_buffer.mmatrix[i] = master_matrix[i]; -#endif +# endif } # ifdef BACKLIGHT_ENABLE @@ -358,9 +358,9 @@ void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) // TODO: if MATRIX_COLS > 8 change to pack() for (int i = 0; i < ROWS_PER_HAND; ++i) { serial_s2m_buffer.smatrix[i] = slave_matrix[i]; -#ifdef SPLIT_TRANSPORT_MIRROR - master_matrix[i] = serial_m2s_buffer.mmatrix[i]; -#endif +# ifdef SPLIT_TRANSPORT_MIRROR + master_matrix[i] = serial_m2s_buffer.mmatrix[i]; +# endif } # ifdef BACKLIGHT_ENABLE backlight_set(serial_m2s_buffer.backlight_level); -- cgit v1.2.3