aboutsummaryrefslogtreecommitdiff
path: root/quantum/split_common/transport.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/split_common/transport.c')
-rw-r--r--quantum/split_common/transport.c90
1 files changed, 78 insertions, 12 deletions
diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c
index 61b61ea08..9b3f70ed0 100644
--- a/quantum/split_common/transport.c
+++ b/quantum/split_common/transport.c
@@ -22,6 +22,13 @@ static pin_t encoders_pad[] = ENCODERS_PAD_A;
22# define NUMBER_OF_ENCODERS (sizeof(encoders_pad) / sizeof(pin_t)) 22# define NUMBER_OF_ENCODERS (sizeof(encoders_pad) / sizeof(pin_t))
23#endif 23#endif
24 24
25#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
26# include "led_matrix.h"
27#endif
28#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
29# include "rgb_matrix.h"
30#endif
31
25#if defined(USE_I2C) 32#if defined(USE_I2C)
26 33
27# include "i2c_master.h" 34# include "i2c_master.h"
@@ -54,6 +61,14 @@ typedef struct _I2C_slave_buffer_t {
54# ifdef WPM_ENABLE 61# ifdef WPM_ENABLE
55 uint8_t current_wpm; 62 uint8_t current_wpm;
56# endif 63# endif
64# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
65 led_eeconfig_t led_matrix;
66 bool led_suspend_state;
67# endif
68# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
69 rgb_config_t rgb_matrix;
70 bool rgb_suspend_state;
71# endif
57} I2C_slave_buffer_t; 72} I2C_slave_buffer_t;
58 73
59static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg; 74static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg;
@@ -68,6 +83,10 @@ static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_re
68# define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) 83# define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync)
69# define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) 84# define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state)
70# define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) 85# define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm)
86# define I2C_LED_MATRIX_START offsetof(I2C_slave_buffer_t, led_matrix)
87# define I2C_LED_SUSPEND_START offsetof(I2C_slave_buffer_t, led_suspend_state)
88# define I2C_RGB_MATRIX_START offsetof(I2C_slave_buffer_t, rgb_matrix)
89# define I2C_RGB_SUSPEND_START offsetof(I2C_slave_buffer_t, rgb_suspend_state)
71 90
72# define TIMEOUT 100 91# define TIMEOUT 100
73 92
@@ -141,6 +160,17 @@ bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
141# endif 160# endif
142# endif 161# endif
143 162
163# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
164 i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_LED_MATRIX_START, (void *)led_matrix_eeconfig, sizeof(i2c_buffer->led_matrix), TIMEOUT);
165 bool suspend_state = led_matrix_get_suspend_state();
166 i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_LED_SUSPEND_START, (void *)suspend_state, sizeof(i2c_buffer->led_suspend_state), TIMEOUT);
167# endif
168# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
169 i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_MATRIX_START, (void *)rgb_matrix_config, sizeof(i2c_buffer->rgb_matrix), TIMEOUT);
170 bool suspend_state = rgb_matrix_get_suspend_state();
171 i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_SUSPEND_START, (void *)suspend_state, sizeof(i2c_buffer->rgb_suspend_state), TIMEOUT);
172# endif
173
144# ifndef DISABLE_SYNC_TIMER 174# ifndef DISABLE_SYNC_TIMER
145 i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; 175 i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET;
146 i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT); 176 i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT);
@@ -186,6 +216,15 @@ void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
186 set_oneshot_mods(i2c_buffer->oneshot_mods); 216 set_oneshot_mods(i2c_buffer->oneshot_mods);
187# endif 217# endif
188# endif 218# endif
219
220# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
221 memcpy((void *)i2c_buffer->led_matrix, (void *)led_matrix_eeconfig, sizeof(i2c_buffer->led_matrix));
222 led_matrix_set_suspend_state(i2c_buffer->led_suspend_state);
223# endif
224# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
225 memcpy((void *)i2c_buffer->rgb_matrix, (void *)rgb_matrix_config, sizeof(i2c_buffer->rgb_matrix));
226 rgb_matrix_set_suspend_state(i2c_buffer->rgb_suspend_state);
227# endif
189} 228}
190 229
191void transport_master_init(void) { i2c_init(); } 230void transport_master_init(void) { i2c_init(); }
@@ -208,23 +247,31 @@ typedef struct _Serial_s2m_buffer_t {
208 247
209typedef struct _Serial_m2s_buffer_t { 248typedef struct _Serial_m2s_buffer_t {
210# ifdef SPLIT_MODS_ENABLE 249# ifdef SPLIT_MODS_ENABLE
211 uint8_t real_mods; 250 uint8_t real_mods;
212 uint8_t weak_mods; 251 uint8_t weak_mods;
213# ifndef NO_ACTION_ONESHOT 252# ifndef NO_ACTION_ONESHOT
214 uint8_t oneshot_mods; 253 uint8_t oneshot_mods;
215# endif 254# endif
216# endif 255# endif
217# ifndef DISABLE_SYNC_TIMER 256# ifndef DISABLE_SYNC_TIMER
218 uint32_t sync_timer; 257 uint32_t sync_timer;
219# endif 258# endif
220# ifdef SPLIT_TRANSPORT_MIRROR 259# ifdef SPLIT_TRANSPORT_MIRROR
221 matrix_row_t mmatrix[ROWS_PER_HAND]; 260 matrix_row_t mmatrix[ROWS_PER_HAND];
222# endif 261# endif
223# ifdef BACKLIGHT_ENABLE 262# ifdef BACKLIGHT_ENABLE
224 uint8_t backlight_level; 263 uint8_t backlight_level;
225# endif 264# endif
226# ifdef WPM_ENABLE 265# ifdef WPM_ENABLE
227 uint8_t current_wpm; 266 uint8_t current_wpm;
267# endif
268# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
269 led_eeconfig_t led_matrix;
270 bool led_suspend_state;
271# endif
272# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
273 rgb_config_t rgb_matrix;
274 bool rgb_suspend_state;
228# endif 275# endif
229} Serial_m2s_buffer_t; 276} Serial_m2s_buffer_t;
230 277
@@ -333,18 +380,28 @@ bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
333 380
334# ifdef WPM_ENABLE 381# ifdef WPM_ENABLE
335 // Write wpm to slave 382 // Write wpm to slave
336 serial_m2s_buffer.current_wpm = get_current_wpm(); 383 serial_m2s_buffer.current_wpm = get_current_wpm();
337# endif 384# endif
338 385
339# ifdef SPLIT_MODS_ENABLE 386# ifdef SPLIT_MODS_ENABLE
340 serial_m2s_buffer.real_mods = get_mods(); 387 serial_m2s_buffer.real_mods = get_mods();
341 serial_m2s_buffer.weak_mods = get_weak_mods(); 388 serial_m2s_buffer.weak_mods = get_weak_mods();
342# ifndef NO_ACTION_ONESHOT 389# ifndef NO_ACTION_ONESHOT
343 serial_m2s_buffer.oneshot_mods = get_oneshot_mods(); 390 serial_m2s_buffer.oneshot_mods = get_oneshot_mods();
344# endif 391# endif
345# endif 392# endif
393
394# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
395 serial_m2s_buffer.led_matrix = led_matrix_econfig;
396 serial_m2s_buffer.led_suspend_state = led_matrix_get_suspend_state();
397# endif
398# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
399 serial_m2s_buffer.rgb_matrix = rgb_matrix_config;
400 serial_m2s_buffer.rgb_suspend_state = rgb_matrix_get_suspend_state();
401# endif
402
346# ifndef DISABLE_SYNC_TIMER 403# ifndef DISABLE_SYNC_TIMER
347 serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; 404 serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET;
348# endif 405# endif
349 return true; 406 return true;
350} 407}
@@ -381,6 +438,15 @@ void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
381 set_oneshot_mods(serial_m2s_buffer.oneshot_mods); 438 set_oneshot_mods(serial_m2s_buffer.oneshot_mods);
382# endif 439# endif
383# endif 440# endif
441
442# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
443 led_matrix_eeconfig = serial_m2s_buffer.led_matrix;
444 led_matrix_set_suspend_state(serial_m2s_buffer.led_suspend_state);
445# endif
446# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
447 rgb_matrix_config = serial_m2s_buffer.rgb_matrix;
448 rgb_matrix_set_suspend_state(serial_m2s_buffer.rgb_suspend_state);
449# endif
384} 450}
385 451
386#endif 452#endif