From f57f0df156da702ddf448147a79bf198b4f7e5be Mon Sep 17 00:00:00 2001 From: HaoRan Yue Date: Thu, 24 Sep 2020 00:15:07 -0500 Subject: [PATCH 1/2] Implementing return value for matrix_scan() --- keyboards/crkbd/rev1/legacy/matrix.c | 16 ++++++++++------ keyboards/crkbd/rev1/legacy/split_util.h | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/keyboards/crkbd/rev1/legacy/matrix.c b/keyboards/crkbd/rev1/legacy/matrix.c index 46dead369fa8..3bd7eb3f2b7a 100644 --- a/keyboards/crkbd/rev1/legacy/matrix.c +++ b/keyboards/crkbd/rev1/legacy/matrix.c @@ -155,6 +155,7 @@ void matrix_init(void) uint8_t _matrix_scan(void) { + bool changed = false; // Right hand is stored after the left in the matirx so, we need to offset it int offset = isLeftHand ? 0 : (ROWS_PER_HAND); @@ -163,6 +164,7 @@ uint8_t _matrix_scan(void) _delay_us(30); // without this wait read unstable value. matrix_row_t cols = read_cols(); if (matrix_debouncing[i+offset] != cols) { + changed = true; matrix_debouncing[i+offset] = cols; debouncing = DEBOUNCE; } @@ -179,7 +181,7 @@ uint8_t _matrix_scan(void) } } - return 1; + return changed; } #ifdef USE_MATRIX_I2C @@ -237,16 +239,17 @@ int serial_transaction(int master_changed) { uint8_t matrix_scan(void) { + bool changed = false; if (is_master) { - matrix_master_scan(); + changed |= matrix_master_scan(); }else{ - matrix_slave_scan(); + changed |= matrix_slave_scan(); int offset = (isLeftHand) ? ROWS_PER_HAND : 0; memcpy(&matrix[offset], (void *)serial_master_buffer, SERIAL_MASTER_BUFFER_LENGTH); matrix_scan_quantum(); } - return 1; + return (uint8_t) changed; } @@ -297,8 +300,8 @@ uint8_t matrix_master_scan(void) { return ret; } -void matrix_slave_scan(void) { - _matrix_scan(); +uint8_t matrix_slave_scan(void) { + int ret = _matrix_scan(); int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; @@ -322,6 +325,7 @@ void matrix_slave_scan(void) { slave_buffer_change_count += change; #endif #endif + return ret; } bool matrix_is_modified(void) diff --git a/keyboards/crkbd/rev1/legacy/split_util.h b/keyboards/crkbd/rev1/legacy/split_util.h index 414763bff268..b2ddc1f97a3d 100644 --- a/keyboards/crkbd/rev1/legacy/split_util.h +++ b/keyboards/crkbd/rev1/legacy/split_util.h @@ -27,7 +27,7 @@ along with this program. If not, see . extern volatile bool isLeftHand; // slave version of matix scan, defined in matrix.c -void matrix_slave_scan(void); +uint8_t matrix_slave_scan(void); void split_keyboard_setup(void); bool has_usb(void); From 99c6f944fdbb9bca32315a36015b4a5c05c3eb42 Mon Sep 17 00:00:00 2001 From: HaoRan Yue Date: Thu, 24 Sep 2020 01:11:39 -0500 Subject: [PATCH 2/2] coding conventions --- keyboards/crkbd/rev1/legacy/matrix.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/keyboards/crkbd/rev1/legacy/matrix.c b/keyboards/crkbd/rev1/legacy/matrix.c index 3bd7eb3f2b7a..8eb028137bd5 100644 --- a/keyboards/crkbd/rev1/legacy/matrix.c +++ b/keyboards/crkbd/rev1/legacy/matrix.c @@ -155,7 +155,7 @@ void matrix_init(void) uint8_t _matrix_scan(void) { - bool changed = false; + bool changed = false; // Right hand is stored after the left in the matirx so, we need to offset it int offset = isLeftHand ? 0 : (ROWS_PER_HAND); @@ -164,7 +164,7 @@ uint8_t _matrix_scan(void) _delay_us(30); // without this wait read unstable value. matrix_row_t cols = read_cols(); if (matrix_debouncing[i+offset] != cols) { - changed = true; + changed = true; matrix_debouncing[i+offset] = cols; debouncing = DEBOUNCE; } @@ -239,7 +239,7 @@ int serial_transaction(int master_changed) { uint8_t matrix_scan(void) { - bool changed = false; + bool changed = false; if (is_master) { changed |= matrix_master_scan(); }else{ @@ -317,7 +317,7 @@ uint8_t matrix_slave_scan(void) { for (int i = 0; i < ROWS_PER_HAND; ++i) { #ifdef SERIAL_USE_MULTI_TRANSACTION if( serial_slave_buffer[i] != matrix[offset+i] ) - change = 1; + change = 1; #endif serial_slave_buffer[i] = matrix[offset+i]; } @@ -325,7 +325,7 @@ uint8_t matrix_slave_scan(void) { slave_buffer_change_count += change; #endif #endif - return ret; + return ret; } bool matrix_is_modified(void)