aboutsummaryrefslogtreecommitdiff
path: root/quantum/split_common
diff options
context:
space:
mode:
authorCasey Webster <casey.webster@gmail.com>2020-12-16 23:21:26 -0600
committerGitHub <noreply@github.com>2020-12-17 16:21:26 +1100
commit5e2b53541bef9b380380286724b321cc8a0ac413 (patch)
tree6ed28de5191d7edb6266deb44f45e8d6fa7dd8e8 /quantum/split_common
parent9c205d4a29f03430c8256459b71a38d7b4caa100 (diff)
downloadqmk_firmware-5e2b53541bef9b380380286724b321cc8a0ac413.tar.gz
qmk_firmware-5e2b53541bef9b380380286724b321cc8a0ac413.zip
Add modifier state to the split keyboard transport (#10400)
* Add modifier state to the split transport This adds modifier state to the i2c and serial transport for split keyboards. The purpose of this is to allow e.g. displaying modifier state on the slave side of a split keyboard on an oled. This adds one byte to the data transferred between halves. This also fixes a missing ifdef guard for BLACKLIGHT_ENABLE. Break modifiers into real/weak/oneshot Fix incorrect slave serial mod setting Fix typo in serial weal mod setter Fix build errors for the I2C code that I introduced Code cleanup and formatting per project preferences Correctly get oneshot mods Fix missing braces Remove unneeded ifdef guard Make the added state transport optional Add documentation for the new define to enable this feature Fix stray grave mark * Fix error introduced in conflict resolution
Diffstat (limited to 'quantum/split_common')
-rw-r--r--quantum/split_common/transport.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c
index 6856b6055..ae0c10b82 100644
--- a/quantum/split_common/transport.c
+++ b/quantum/split_common/transport.c
@@ -32,7 +32,16 @@ typedef struct _I2C_slave_buffer_t {
32 uint32_t sync_timer; 32 uint32_t sync_timer;
33# endif 33# endif
34 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
35 uint8_t backlight_level; 43 uint8_t backlight_level;
44# endif
36# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) 45# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
37 rgblight_syncinfo_t rgblight_sync; 46 rgblight_syncinfo_t rgblight_sync;
38# endif 47# endif
@@ -46,6 +55,10 @@ typedef struct _I2C_slave_buffer_t {
46 55
47static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg; 56static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg;
48 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)
49# define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level) 62# define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level)
50# define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) 63# define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync)
51# define I2C_SYNC_TIME_START offsetof(I2C_slave_buffer_t, sync_timer) 64# define I2C_SYNC_TIME_START offsetof(I2C_slave_buffer_t, sync_timer)
@@ -97,6 +110,31 @@ bool transport_master(matrix_row_t matrix[]) {
97 } 110 }
98# endif 111# endif
99 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
100# ifndef DISABLE_SYNC_TIMER 138# ifndef DISABLE_SYNC_TIMER
101 i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; 139 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); 140 i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT);
@@ -131,6 +169,14 @@ void transport_slave(matrix_row_t matrix[]) {
131# ifdef WPM_ENABLE 169# ifdef WPM_ENABLE
132 set_current_wpm(i2c_buffer->current_wpm); 170 set_current_wpm(i2c_buffer->current_wpm);
133# 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
134} 180}
135 181
136void transport_master_init(void) { i2c_init(); } 182void transport_master_init(void) { i2c_init(); }
@@ -152,6 +198,13 @@ typedef struct _Serial_s2m_buffer_t {
152} Serial_s2m_buffer_t; 198} Serial_s2m_buffer_t;
153 199
154typedef struct _Serial_m2s_buffer_t { 200typedef 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
155# ifndef DISABLE_SYNC_TIMER 208# ifndef DISABLE_SYNC_TIMER
156 uint32_t sync_timer; 209 uint32_t sync_timer;
157# endif 210# endif
@@ -268,6 +321,13 @@ bool transport_master(matrix_row_t matrix[]) {
268 serial_m2s_buffer.current_wpm = get_current_wpm(); 321 serial_m2s_buffer.current_wpm = get_current_wpm();
269# endif 322# endif
270 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
271# ifndef DISABLE_SYNC_TIMER 331# ifndef DISABLE_SYNC_TIMER
272 serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; 332 serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET;
273# endif 333# endif
@@ -295,6 +355,14 @@ void transport_slave(matrix_row_t matrix[]) {
295# ifdef WPM_ENABLE 355# ifdef WPM_ENABLE
296 set_current_wpm(serial_m2s_buffer.current_wpm); 356 set_current_wpm(serial_m2s_buffer.current_wpm);
297# 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
298} 366}
299 367
300#endif 368#endif