summaryrefslogtreecommitdiff
path: root/quantum/split_common
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/split_common')
-rw-r--r--quantum/split_common/matrix.c46
-rw-r--r--quantum/split_common/transport.c136
-rw-r--r--quantum/split_common/transport.h4
3 files changed, 158 insertions, 28 deletions
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c
index 51bf8b1095..d6636b886a 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;
}
@@ -245,48 +251,62 @@ 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(matrix + thisHand, 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();
} else {
- transport_slave(matrix + thisHand);
+ transport_slave(matrix + thatHand, 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);
}
diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c
index 467ff81a97..61b61ea08c 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,8 +28,23 @@ 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
+# ifdef SPLIT_TRANSPORT_MIRROR
+ matrix_row_t mmatrix[ROWS_PER_HAND];
+# endif
matrix_row_t smatrix[ROWS_PER_HAND];
- uint8_t backlight_level;
+# 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
@@ -42,9 +58,14 @@ 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_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)
# define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level)
# define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync)
-# 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)
@@ -55,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
@@ -91,12 +115,48 @@ 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);
+# endif
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
@@ -118,6 +178,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(); }
@@ -139,11 +207,24 @@ 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
+# 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;
@@ -221,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;
@@ -235,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
@@ -249,16 +333,34 @@ 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();
+# 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
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);
+# 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];
+ 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);
@@ -271,6 +373,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
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[]);