summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2020-02-25 14:10:04 +0000
committerDrashna Jael're <drashna@live.com>2020-03-26 00:42:13 -0700
commit28f45b8ff4073528ad8a665e1471ca5e927759e8 (patch)
treea2ab1f05330add6f6d441c557337d8ffb42b3f33
parentebb243aacee704cf5bbb63b65439c06703ba5bc1 (diff)
Split - Avoid race condition during matrix_init_quantum (#8235)
* Avoid race condition during matrix_init_quantum * spelling is hard
-rw-r--r--quantum/split_common/matrix.c4
-rw-r--r--quantum/split_common/split_util.c29
-rw-r--r--quantum/split_common/split_util.h3
3 files changed, 19 insertions, 17 deletions
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c
index a82334128b..8b91f8ca83 100644
--- a/quantum/split_common/matrix.c
+++ b/quantum/split_common/matrix.c
@@ -190,7 +190,7 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
#endif
void matrix_init(void) {
- keyboard_split_setup();
+ split_pre_init();
// Set pinout for right half if pinout for that half is defined
if (!isLeftHand) {
@@ -231,6 +231,8 @@ void matrix_init(void) {
debounce_init(ROWS_PER_HAND);
matrix_init_quantum();
+
+ split_post_init();
}
void matrix_post_scan(void) {
diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c
index 07d3bb36ad..fb6a3b85af 100644
--- a/quantum/split_common/split_util.c
+++ b/quantum/split_common/split_util.c
@@ -81,19 +81,8 @@ __attribute__((weak)) bool is_keyboard_master(void) {
return (usbstate == MASTER);
}
-static void keyboard_master_setup(void) {
-#if defined(USE_I2C) || defined(EH)
-# ifdef SSD1306OLED
- matrix_master_OLED_init();
-# endif
-#endif
- transport_master_init();
-}
-
-static void keyboard_slave_setup(void) { transport_slave_init(); }
-
// this code runs before the keyboard is fully initialized
-void keyboard_split_setup(void) {
+void split_pre_init(void) {
isLeftHand = is_keyboard_left();
#if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
@@ -106,8 +95,18 @@ void keyboard_split_setup(void) {
#endif
if (is_keyboard_master()) {
- keyboard_master_setup();
- } else {
- keyboard_slave_setup();
+#if defined(USE_I2C) && defined(SSD1306OLED)
+ matrix_master_OLED_init();
+#endif
+ transport_master_init();
+ }
+}
+
+// this code runs after the keyboard is fully initialized
+// - avoids race condition during matrix_init_quantum where slave can start
+// receiving before the init process has completed
+void split_post_init(void) {
+ if (!is_keyboard_master()) {
+ transport_slave_init();
}
}
diff --git a/quantum/split_common/split_util.h b/quantum/split_common/split_util.h
index 5d9c523400..a4c12519e0 100644
--- a/quantum/split_common/split_util.h
+++ b/quantum/split_common/split_util.h
@@ -8,4 +8,5 @@
extern volatile bool isLeftHand;
void matrix_master_OLED_init(void);
-void keyboard_split_setup(void);
+void split_pre_init(void);
+void split_post_init(void);