summaryrefslogtreecommitdiff
path: root/quantum/split_common/transport.c
diff options
context:
space:
mode:
authorXScorpion2 <rcalt2vt@gmail.com>2020-12-01 12:04:42 -0600
committerGitHub <noreply@github.com>2020-12-01 10:04:42 -0800
commita8d0ec0749046b0ab89c18b1b7083b1e8674de2a (patch)
tree06c81bed47c6f4128bf0fc33697646994bffab00 /quantum/split_common/transport.c
parent9c03a8959621016d27fdd7cdfbabce28fd7d1757 (diff)
[Split] Sync Timer feature (#10997)
A timer that is kept in sync between the halves of a split keyboard
Diffstat (limited to 'quantum/split_common/transport.c')
-rw-r--r--quantum/split_common/transport.c26
1 files changed, 25 insertions, 1 deletions
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];