diff options
Diffstat (limited to 'quantum/split_common')
-rw-r--r-- | quantum/split_common/transport.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index 467ff81a9..6856b6055 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include "quantum.h" | 6 | #include "quantum.h" |
7 | 7 | ||
8 | #define ROWS_PER_HAND (MATRIX_ROWS / 2) | 8 | #define ROWS_PER_HAND (MATRIX_ROWS / 2) |
9 | #define SYNC_TIMER_OFFSET 2 | ||
9 | 10 | ||
10 | #ifdef RGBLIGHT_ENABLE | 11 | #ifdef RGBLIGHT_ENABLE |
11 | # include "rgblight.h" | 12 | # include "rgblight.h" |
@@ -27,6 +28,9 @@ static pin_t encoders_pad[] = ENCODERS_PAD_A; | |||
27 | # include "i2c_slave.h" | 28 | # include "i2c_slave.h" |
28 | 29 | ||
29 | typedef struct _I2C_slave_buffer_t { | 30 | typedef struct _I2C_slave_buffer_t { |
31 | # ifndef DISABLE_SYNC_TIMER | ||
32 | uint32_t sync_timer; | ||
33 | # endif | ||
30 | matrix_row_t smatrix[ROWS_PER_HAND]; | 34 | matrix_row_t smatrix[ROWS_PER_HAND]; |
31 | uint8_t backlight_level; | 35 | uint8_t backlight_level; |
32 | # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) | 36 | # 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 | |||
44 | 48 | ||
45 | # define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level) | 49 | # define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level) |
46 | # define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) | 50 | # define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) |
51 | # define I2C_SYNC_TIME_START offsetof(I2C_slave_buffer_t, sync_timer) | ||
47 | # define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix) | 52 | # define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix) |
48 | # define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) | 53 | # define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) |
49 | # define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) | 54 | # define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) |
@@ -91,10 +96,18 @@ bool transport_master(matrix_row_t matrix[]) { | |||
91 | } | 96 | } |
92 | } | 97 | } |
93 | # endif | 98 | # endif |
99 | |||
100 | # ifndef DISABLE_SYNC_TIMER | ||
101 | i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; | ||
102 | i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT); | ||
103 | # endif | ||
94 | return true; | 104 | return true; |
95 | } | 105 | } |
96 | 106 | ||
97 | void transport_slave(matrix_row_t matrix[]) { | 107 | void transport_slave(matrix_row_t matrix[]) { |
108 | # ifndef DISABLE_SYNC_TIMER | ||
109 | sync_timer_update(i2c_buffer->sync_timer); | ||
110 | # endif | ||
98 | // Copy matrix to I2C buffer | 111 | // Copy matrix to I2C buffer |
99 | memcpy((void *)i2c_buffer->smatrix, (void *)matrix, sizeof(i2c_buffer->smatrix)); | 112 | memcpy((void *)i2c_buffer->smatrix, (void *)matrix, sizeof(i2c_buffer->smatrix)); |
100 | 113 | ||
@@ -133,12 +146,15 @@ typedef struct _Serial_s2m_buffer_t { | |||
133 | matrix_row_t smatrix[ROWS_PER_HAND]; | 146 | matrix_row_t smatrix[ROWS_PER_HAND]; |
134 | 147 | ||
135 | # ifdef ENCODER_ENABLE | 148 | # ifdef ENCODER_ENABLE |
136 | uint8_t encoder_state[NUMBER_OF_ENCODERS]; | 149 | uint8_t encoder_state[NUMBER_OF_ENCODERS]; |
137 | # endif | 150 | # endif |
138 | 151 | ||
139 | } Serial_s2m_buffer_t; | 152 | } Serial_s2m_buffer_t; |
140 | 153 | ||
141 | typedef struct _Serial_m2s_buffer_t { | 154 | typedef struct _Serial_m2s_buffer_t { |
155 | # ifndef DISABLE_SYNC_TIMER | ||
156 | uint32_t sync_timer; | ||
157 | # endif | ||
142 | # ifdef BACKLIGHT_ENABLE | 158 | # ifdef BACKLIGHT_ENABLE |
143 | uint8_t backlight_level; | 159 | uint8_t backlight_level; |
144 | # endif | 160 | # endif |
@@ -251,11 +267,19 @@ bool transport_master(matrix_row_t matrix[]) { | |||
251 | // Write wpm to slave | 267 | // Write wpm to slave |
252 | serial_m2s_buffer.current_wpm = get_current_wpm(); | 268 | serial_m2s_buffer.current_wpm = get_current_wpm(); |
253 | # endif | 269 | # endif |
270 | |||
271 | # ifndef DISABLE_SYNC_TIMER | ||
272 | serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; | ||
273 | # endif | ||
254 | return true; | 274 | return true; |
255 | } | 275 | } |
256 | 276 | ||
257 | void transport_slave(matrix_row_t matrix[]) { | 277 | void transport_slave(matrix_row_t matrix[]) { |
258 | transport_rgblight_slave(); | 278 | transport_rgblight_slave(); |
279 | # ifndef DISABLE_SYNC_TIMER | ||
280 | sync_timer_update(serial_m2s_buffer.sync_timer); | ||
281 | # endif | ||
282 | |||
259 | // TODO: if MATRIX_COLS > 8 change to pack() | 283 | // TODO: if MATRIX_COLS > 8 change to pack() |
260 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | 284 | for (int i = 0; i < ROWS_PER_HAND; ++i) { |
261 | serial_s2m_buffer.smatrix[i] = matrix[i]; | 285 | serial_s2m_buffer.smatrix[i] = matrix[i]; |