Crkbd implementing return value for matrix_scan() (#10422)

master
yhr0x43 2020-10-01 13:41:21 -05:00 committed by GitHub
parent 45f044907c
commit 7a2124db6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -155,6 +155,7 @@ void matrix_init(void)
uint8_t _matrix_scan(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 // Right hand is stored after the left in the matirx so, we need to offset it
int offset = isLeftHand ? 0 : (ROWS_PER_HAND); 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. _delay_us(30); // without this wait read unstable value.
matrix_row_t cols = read_cols(); matrix_row_t cols = read_cols();
if (matrix_debouncing[i+offset] != cols) { if (matrix_debouncing[i+offset] != cols) {
changed = true;
matrix_debouncing[i+offset] = cols; matrix_debouncing[i+offset] = cols;
debouncing = DEBOUNCE; debouncing = DEBOUNCE;
} }
@ -179,7 +181,7 @@ uint8_t _matrix_scan(void)
} }
} }
return 1; return changed;
} }
#ifdef USE_MATRIX_I2C #ifdef USE_MATRIX_I2C
@ -237,16 +239,17 @@ int serial_transaction(int master_changed) {
uint8_t matrix_scan(void) uint8_t matrix_scan(void)
{ {
bool changed = false;
if (is_master) { if (is_master) {
matrix_master_scan(); changed |= matrix_master_scan();
}else{ }else{
matrix_slave_scan(); changed |= matrix_slave_scan();
int offset = (isLeftHand) ? ROWS_PER_HAND : 0; int offset = (isLeftHand) ? ROWS_PER_HAND : 0;
memcpy(&matrix[offset], memcpy(&matrix[offset],
(void *)serial_master_buffer, SERIAL_MASTER_BUFFER_LENGTH); (void *)serial_master_buffer, SERIAL_MASTER_BUFFER_LENGTH);
matrix_scan_quantum(); matrix_scan_quantum();
} }
return 1; return (uint8_t) changed;
} }
@ -297,8 +300,8 @@ uint8_t matrix_master_scan(void) {
return ret; return ret;
} }
void matrix_slave_scan(void) { uint8_t matrix_slave_scan(void) {
_matrix_scan(); int ret = _matrix_scan();
int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; int offset = (isLeftHand) ? 0 : ROWS_PER_HAND;
@ -314,7 +317,7 @@ void matrix_slave_scan(void) {
for (int i = 0; i < ROWS_PER_HAND; ++i) { for (int i = 0; i < ROWS_PER_HAND; ++i) {
#ifdef SERIAL_USE_MULTI_TRANSACTION #ifdef SERIAL_USE_MULTI_TRANSACTION
if( serial_slave_buffer[i] != matrix[offset+i] ) if( serial_slave_buffer[i] != matrix[offset+i] )
change = 1; change = 1;
#endif #endif
serial_slave_buffer[i] = matrix[offset+i]; serial_slave_buffer[i] = matrix[offset+i];
} }
@ -322,6 +325,7 @@ void matrix_slave_scan(void) {
slave_buffer_change_count += change; slave_buffer_change_count += change;
#endif #endif
#endif #endif
return ret;
} }
bool matrix_is_modified(void) bool matrix_is_modified(void)

View File

@ -27,7 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern volatile bool isLeftHand; extern volatile bool isLeftHand;
// slave version of matix scan, defined in matrix.c // 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); void split_keyboard_setup(void);
bool has_usb(void); bool has_usb(void);