1
0
Fork 0

[Split] Sync Timer feature (#10997)

A timer that is kept in sync between the halves of a split keyboard
This commit is contained in:
XScorpion2 2020-12-01 12:04:42 -06:00 committed by GitHub
parent 9c03a89596
commit a8d0ec0749
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 154 additions and 15 deletions

View file

@ -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];