diff options
Diffstat (limited to 'quantum/split_common')
| -rw-r--r-- | quantum/split_common/transport.c | 94 |
1 files changed, 93 insertions, 1 deletions
diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index 467ff81a9..ae0c10b82 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,8 +28,20 @@ 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]; |
| 35 | # ifdef SPLIT_MODS_ENABLE | ||
| 36 | uint8_t real_mods; | ||
| 37 | uint8_t weak_mods; | ||
| 38 | # ifndef NO_ACTION_ONESHOT | ||
| 39 | uint8_t oneshot_mods; | ||
| 40 | # endif | ||
| 41 | # endif | ||
| 42 | # ifdef BACKLIGHT_ENABLE | ||
| 31 | uint8_t backlight_level; | 43 | uint8_t backlight_level; |
| 44 | # endif | ||
| 32 | # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) | 45 | # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) |
| 33 | rgblight_syncinfo_t rgblight_sync; | 46 | rgblight_syncinfo_t rgblight_sync; |
| 34 | # endif | 47 | # endif |
| @@ -42,8 +55,13 @@ typedef struct _I2C_slave_buffer_t { | |||
| 42 | 55 | ||
| 43 | static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg; | 56 | static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg; |
| 44 | 57 | ||
| 58 | # define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix) | ||
| 59 | # define I2C_REAL_MODS_START offsetof(I2C_slave_buffer_t, real_mods) | ||
| 60 | # define I2C_WEAK_MODS_START offsetof(I2C_slave_buffer_t, weak_mods) | ||
| 61 | # define I2C_ONESHOT_MODS_START offsetof(I2C_slave_buffer_t, oneshot_mods) | ||
| 45 | # define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level) | 62 | # define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level) |
| 46 | # define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) | 63 | # define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) |
| 64 | # define I2C_SYNC_TIME_START offsetof(I2C_slave_buffer_t, sync_timer) | ||
| 47 | # define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix) | 65 | # define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix) |
| 48 | # define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) | 66 | # define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) |
| 49 | # define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) | 67 | # define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) |
| @@ -91,10 +109,43 @@ bool transport_master(matrix_row_t matrix[]) { | |||
| 91 | } | 109 | } |
| 92 | } | 110 | } |
| 93 | # endif | 111 | # endif |
| 112 | |||
| 113 | # ifdef SPLIT_MODS_ENABLE | ||
| 114 | uint8_t real_mods = get_mods(); | ||
| 115 | if (real_mods != i2c_buffer->real_mods) { | ||
| 116 | if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_REAL_MODS_START, (void *)&real_mods, sizeof(real_mods), TIMEOUT) >= 0) { | ||
| 117 | i2c_buffer->real_mods = real_mods; | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | uint8_t weak_mods = get_weak_mods(); | ||
| 122 | if (weak_mods != i2c_buffer->weak_mods) { | ||
| 123 | if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_WEAK_MODS_START, (void *)&weak_mods, sizeof(weak_mods), TIMEOUT) >= 0) { | ||
| 124 | i2c_buffer->weak_mods = weak_mods; | ||
| 125 | } | ||
| 126 | } | ||
| 127 | |||
| 128 | # ifndef NO_ACTION_ONESHOT | ||
| 129 | uint8_t oneshot_mods = get_oneshot_mods(); | ||
| 130 | if (oneshot_mods != i2c_buffer->oneshot_mods) { | ||
| 131 | if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_ONESHOT_MODS_START, (void *)&oneshot_mods, sizeof(oneshot_mods), TIMEOUT) >= 0) { | ||
| 132 | i2c_buffer->oneshot_mods = oneshot_mods; | ||
| 133 | } | ||
| 134 | } | ||
| 135 | # endif | ||
| 136 | # endif | ||
| 137 | |||
| 138 | # ifndef DISABLE_SYNC_TIMER | ||
| 139 | i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; | ||
| 140 | i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT); | ||
| 141 | # endif | ||
| 94 | return true; | 142 | return true; |
| 95 | } | 143 | } |
| 96 | 144 | ||
| 97 | void transport_slave(matrix_row_t matrix[]) { | 145 | void transport_slave(matrix_row_t matrix[]) { |
| 146 | # ifndef DISABLE_SYNC_TIMER | ||
| 147 | sync_timer_update(i2c_buffer->sync_timer); | ||
| 148 | # endif | ||
| 98 | // Copy matrix to I2C buffer | 149 | // Copy matrix to I2C buffer |
| 99 | memcpy((void *)i2c_buffer->smatrix, (void *)matrix, sizeof(i2c_buffer->smatrix)); | 150 | memcpy((void *)i2c_buffer->smatrix, (void *)matrix, sizeof(i2c_buffer->smatrix)); |
| 100 | 151 | ||
| @@ -118,6 +169,14 @@ void transport_slave(matrix_row_t matrix[]) { | |||
| 118 | # ifdef WPM_ENABLE | 169 | # ifdef WPM_ENABLE |
| 119 | set_current_wpm(i2c_buffer->current_wpm); | 170 | set_current_wpm(i2c_buffer->current_wpm); |
| 120 | # endif | 171 | # endif |
| 172 | |||
| 173 | # ifdef SPLIT_MODS_ENABLE | ||
| 174 | set_mods(i2c_buffer->real_mods); | ||
| 175 | set_weak_mods(i2c_buffer->weak_mods); | ||
| 176 | # ifndef NO_ACTION_ONESHOT | ||
| 177 | set_oneshot_mods(i2c_buffer->oneshot_mods); | ||
| 178 | # endif | ||
| 179 | # endif | ||
| 121 | } | 180 | } |
| 122 | 181 | ||
| 123 | void transport_master_init(void) { i2c_init(); } | 182 | void transport_master_init(void) { i2c_init(); } |
| @@ -133,12 +192,22 @@ typedef struct _Serial_s2m_buffer_t { | |||
| 133 | matrix_row_t smatrix[ROWS_PER_HAND]; | 192 | matrix_row_t smatrix[ROWS_PER_HAND]; |
| 134 | 193 | ||
| 135 | # ifdef ENCODER_ENABLE | 194 | # ifdef ENCODER_ENABLE |
| 136 | uint8_t encoder_state[NUMBER_OF_ENCODERS]; | 195 | uint8_t encoder_state[NUMBER_OF_ENCODERS]; |
| 137 | # endif | 196 | # endif |
| 138 | 197 | ||
| 139 | } Serial_s2m_buffer_t; | 198 | } Serial_s2m_buffer_t; |
| 140 | 199 | ||
| 141 | typedef struct _Serial_m2s_buffer_t { | 200 | typedef struct _Serial_m2s_buffer_t { |
| 201 | # ifdef SPLIT_MODS_ENABLE | ||
| 202 | uint8_t real_mods; | ||
| 203 | uint8_t weak_mods; | ||
| 204 | # ifndef NO_ACTION_ONESHOT | ||
| 205 | uint8_t oneshot_mods; | ||
| 206 | # endif | ||
| 207 | # endif | ||
| 208 | # ifndef DISABLE_SYNC_TIMER | ||
| 209 | uint32_t sync_timer; | ||
| 210 | # endif | ||
| 142 | # ifdef BACKLIGHT_ENABLE | 211 | # ifdef BACKLIGHT_ENABLE |
| 143 | uint8_t backlight_level; | 212 | uint8_t backlight_level; |
| 144 | # endif | 213 | # endif |
| @@ -251,11 +320,26 @@ bool transport_master(matrix_row_t matrix[]) { | |||
| 251 | // Write wpm to slave | 320 | // Write wpm to slave |
| 252 | serial_m2s_buffer.current_wpm = get_current_wpm(); | 321 | serial_m2s_buffer.current_wpm = get_current_wpm(); |
| 253 | # endif | 322 | # endif |
| 323 | |||
| 324 | # ifdef SPLIT_MODS_ENABLE | ||
| 325 | serial_m2s_buffer.real_mods = get_mods(); | ||
| 326 | serial_m2s_buffer.weak_mods = get_weak_mods(); | ||
| 327 | # ifndef NO_ACTION_ONESHOT | ||
| 328 | serial_m2s_buffer.oneshot_mods = get_oneshot_mods(); | ||
| 329 | # endif | ||
| 330 | # endif | ||
| 331 | # ifndef DISABLE_SYNC_TIMER | ||
| 332 | serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; | ||
| 333 | # endif | ||
| 254 | return true; | 334 | return true; |
| 255 | } | 335 | } |
| 256 | 336 | ||
| 257 | void transport_slave(matrix_row_t matrix[]) { | 337 | void transport_slave(matrix_row_t matrix[]) { |
| 258 | transport_rgblight_slave(); | 338 | transport_rgblight_slave(); |
| 339 | # ifndef DISABLE_SYNC_TIMER | ||
| 340 | sync_timer_update(serial_m2s_buffer.sync_timer); | ||
| 341 | # endif | ||
| 342 | |||
| 259 | // TODO: if MATRIX_COLS > 8 change to pack() | 343 | // TODO: if MATRIX_COLS > 8 change to pack() |
| 260 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | 344 | for (int i = 0; i < ROWS_PER_HAND; ++i) { |
| 261 | serial_s2m_buffer.smatrix[i] = matrix[i]; | 345 | serial_s2m_buffer.smatrix[i] = matrix[i]; |
| @@ -271,6 +355,14 @@ void transport_slave(matrix_row_t matrix[]) { | |||
| 271 | # ifdef WPM_ENABLE | 355 | # ifdef WPM_ENABLE |
| 272 | set_current_wpm(serial_m2s_buffer.current_wpm); | 356 | set_current_wpm(serial_m2s_buffer.current_wpm); |
| 273 | # endif | 357 | # endif |
| 358 | |||
| 359 | # ifdef SPLIT_MODS_ENABLE | ||
| 360 | set_mods(serial_m2s_buffer.real_mods); | ||
| 361 | set_weak_mods(serial_m2s_buffer.weak_mods); | ||
| 362 | # ifndef NO_ACTION_ONESHOT | ||
| 363 | set_oneshot_mods(serial_m2s_buffer.oneshot_mods); | ||
| 364 | # endif | ||
| 365 | # endif | ||
| 274 | } | 366 | } |
| 275 | 367 | ||
| 276 | #endif | 368 | #endif |
