diff options
Diffstat (limited to 'quantum/split_common')
-rw-r--r-- | quantum/split_common/matrix.c | 3 | ||||
-rw-r--r-- | quantum/split_common/split_util.c | 70 | ||||
-rw-r--r-- | quantum/split_common/transport.c | 90 |
3 files changed, 104 insertions, 59 deletions
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index d6636b886..f8de17809 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c | |||
@@ -43,6 +43,7 @@ extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values | |||
43 | uint8_t thisHand, thatHand; | 43 | uint8_t thisHand, thatHand; |
44 | 44 | ||
45 | // user-defined overridable functions | 45 | // user-defined overridable functions |
46 | __attribute__((weak)) void matrix_slave_scan_kb(void) { matrix_slave_scan_user(); } | ||
46 | __attribute__((weak)) void matrix_slave_scan_user(void) {} | 47 | __attribute__((weak)) void matrix_slave_scan_user(void) {} |
47 | 48 | ||
48 | static inline void setPinOutput_writeLow(pin_t pin) { | 49 | static inline void setPinOutput_writeLow(pin_t pin) { |
@@ -284,7 +285,7 @@ bool matrix_post_scan(void) { | |||
284 | } else { | 285 | } else { |
285 | transport_slave(matrix + thatHand, matrix + thisHand); | 286 | transport_slave(matrix + thatHand, matrix + thisHand); |
286 | 287 | ||
287 | matrix_slave_scan_user(); | 288 | matrix_slave_scan_kb(); |
288 | } | 289 | } |
289 | 290 | ||
290 | return changed; | 291 | return changed; |
diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c index 2ae44e6e1..9e75e19ce 100644 --- a/quantum/split_common/split_util.c +++ b/quantum/split_common/split_util.c | |||
@@ -1,3 +1,18 @@ | |||
1 | /* Copyright 2021 QMK | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 3 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
1 | #include "split_util.h" | 16 | #include "split_util.h" |
2 | #include "matrix.h" | 17 | #include "matrix.h" |
3 | #include "keyboard.h" | 18 | #include "keyboard.h" |
@@ -6,14 +21,7 @@ | |||
6 | #include "transport.h" | 21 | #include "transport.h" |
7 | #include "quantum.h" | 22 | #include "quantum.h" |
8 | #include "wait.h" | 23 | #include "wait.h" |
9 | 24 | #include "usb_util.h" | |
10 | #ifdef PROTOCOL_LUFA | ||
11 | # include <LUFA/Drivers/USB/USB.h> | ||
12 | #endif | ||
13 | |||
14 | #ifdef PROTOCOL_VUSB | ||
15 | # include <usbdrv/usbdrv.h> | ||
16 | #endif | ||
17 | 25 | ||
18 | #ifdef EE_HANDS | 26 | #ifdef EE_HANDS |
19 | # include "eeconfig.h" | 27 | # include "eeconfig.h" |
@@ -31,56 +39,21 @@ | |||
31 | # define SPLIT_USB_TIMEOUT_POLL 10 | 39 | # define SPLIT_USB_TIMEOUT_POLL 10 |
32 | #endif | 40 | #endif |
33 | 41 | ||
34 | #ifdef PROTOCOL_CHIBIOS | ||
35 | # define SPLIT_USB_DETECT // Force this on for now | ||
36 | #endif | ||
37 | |||
38 | volatile bool isLeftHand = true; | 42 | volatile bool isLeftHand = true; |
39 | 43 | ||
40 | #if defined(SPLIT_USB_DETECT) | 44 | #if defined(SPLIT_USB_DETECT) |
41 | # if defined(PROTOCOL_LUFA) | 45 | static bool usbIsActive(void) { |
42 | static inline bool usbHasActiveConnection(void) { return USB_Device_IsAddressSet(); } | ||
43 | static inline void usbDisable(void) { | ||
44 | USB_Disable(); | ||
45 | USB_DeviceState = DEVICE_STATE_Unattached; | ||
46 | } | ||
47 | # elif defined(PROTOCOL_CHIBIOS) | ||
48 | static inline bool usbHasActiveConnection(void) { return usbGetDriverStateI(&USBD1) == USB_ACTIVE; } | ||
49 | static inline void usbDisable(void) { usbStop(&USBD1); } | ||
50 | # elif defined(PROTOCOL_VUSB) | ||
51 | static inline bool usbHasActiveConnection(void) { | ||
52 | usbPoll(); | ||
53 | return usbConfiguration; | ||
54 | } | ||
55 | static inline void usbDisable(void) { usbDeviceDisconnect(); } | ||
56 | # else | ||
57 | static inline bool usbHasActiveConnection(void) { return true; } | ||
58 | static inline void usbDisable(void) {} | ||
59 | # endif | ||
60 | |||
61 | bool usbIsActive(void) { | ||
62 | for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / SPLIT_USB_TIMEOUT_POLL); i++) { | 46 | for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / SPLIT_USB_TIMEOUT_POLL); i++) { |
63 | // This will return true if a USB connection has been established | 47 | // This will return true if a USB connection has been established |
64 | if (usbHasActiveConnection()) { | 48 | if (usb_connected_state()) { |
65 | return true; | 49 | return true; |
66 | } | 50 | } |
67 | wait_ms(SPLIT_USB_TIMEOUT_POLL); | 51 | wait_ms(SPLIT_USB_TIMEOUT_POLL); |
68 | } | 52 | } |
69 | |||
70 | // Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow | ||
71 | usbDisable(); | ||
72 | |||
73 | return false; | 53 | return false; |
74 | } | 54 | } |
75 | #elif defined(PROTOCOL_LUFA) && defined(OTGPADE) | ||
76 | static inline bool usbIsActive(void) { | ||
77 | USB_OTGPAD_On(); // enables VBUS pad | ||
78 | wait_us(5); | ||
79 | |||
80 | return USB_VBUS_GetStatus(); // checks state of VBUS | ||
81 | } | ||
82 | #else | 55 | #else |
83 | static inline bool usbIsActive(void) { return true; } | 56 | static inline bool usbIsActive(void) { return usb_vbus_state(); } |
84 | #endif | 57 | #endif |
85 | 58 | ||
86 | #ifdef SPLIT_HAND_MATRIX_GRID | 59 | #ifdef SPLIT_HAND_MATRIX_GRID |
@@ -126,6 +99,11 @@ __attribute__((weak)) bool is_keyboard_master(void) { | |||
126 | // only check once, as this is called often | 99 | // only check once, as this is called often |
127 | if (usbstate == UNKNOWN) { | 100 | if (usbstate == UNKNOWN) { |
128 | usbstate = usbIsActive() ? MASTER : SLAVE; | 101 | usbstate = usbIsActive() ? MASTER : SLAVE; |
102 | |||
103 | // Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow | ||
104 | if (usbstate == SLAVE) { | ||
105 | usb_disable(); | ||
106 | } | ||
129 | } | 107 | } |
130 | 108 | ||
131 | return (usbstate == MASTER); | 109 | return (usbstate == MASTER); |
diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index 61b61ea08..bf942c526 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 | ||
59 | static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg; | 74 | static 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 | ||
191 | void transport_master_init(void) { i2c_init(); } | 230 | void transport_master_init(void) { i2c_init(); } |
@@ -208,23 +247,31 @@ typedef struct _Serial_s2m_buffer_t { | |||
208 | 247 | ||
209 | typedef struct _Serial_m2s_buffer_t { | 248 | typedef 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_eeconfig; | ||
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 |