Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split - Avoid race condition during matrix_init_quantum #8235

Merged
merged 2 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion quantum/split_common/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,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) {
Expand Down Expand Up @@ -232,6 +232,8 @@ void matrix_init(void) {
debounce_init(ROWS_PER_HAND);

matrix_init_quantum();

split_post_init();
}

void matrix_post_scan(void) {
Expand Down
29 changes: 14 additions & 15 deletions quantum/split_common/split_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,8 @@ __attribute__((weak)) bool is_keyboard_master(void) {
return (usbstate == MASTER);
}

static void keyboard_master_setup(void) {
#if defined(USE_I2C)
# 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)
Expand All @@ -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();
}
}
3 changes: 2 additions & 1 deletion quantum/split_common/split_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);