From 3fed8bced718e24e414c0d5736554d7988235b20 Mon Sep 17 00:00:00 2001 From: yiancar Date: Tue, 16 Feb 2021 03:36:58 +0200 Subject: Dc01 fixes (#11843) * dc01-fixes * dc01-fixes * Cleanup and add VIA * Updated JSONs * fix --- keyboards/dc01/left/matrix.c | 92 ++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 51 deletions(-) (limited to 'keyboards/dc01/left/matrix.c') diff --git a/keyboards/dc01/left/matrix.c b/keyboards/dc01/left/matrix.c index 0e7b591f82..9ae9b10987 100644 --- a/keyboards/dc01/left/matrix.c +++ b/keyboards/dc01/left/matrix.c @@ -31,14 +31,11 @@ along with this program. If not, see . #include "timer.h" #include "i2c_master.h" -#define SLAVE_I2C_ADDRESS_RIGHT 0x19 -#define SLAVE_I2C_ADDRESS_NUMPAD 0x21 -#define SLAVE_I2C_ADDRESS_ARROW 0x23 +#define SLAVE_I2C_ADDRESS_RIGHT 0x32 +#define SLAVE_I2C_ADDRESS_NUMPAD 0x36 +#define SLAVE_I2C_ADDRESS_ARROW 0x40 #define ERROR_DISCONNECT_COUNT 5 -static uint8_t error_count_right = 0; -static uint8_t error_count_numpad = 0; -static uint8_t error_count_arrow = 0; /* Set 0 if debouncing isn't needed */ @@ -210,38 +207,23 @@ uint8_t matrix_scan(void) } # endif - if (i2c_transaction(SLAVE_I2C_ADDRESS_RIGHT, 0x3F, 0)){ //error has occured for main right half - error_count_right++; - if (error_count_right > ERROR_DISCONNECT_COUNT){ //disconnect half - for (uint8_t i = 0; i < MATRIX_ROWS ; i++) { - matrix[i] &= 0x3F; //mask bits to keep - } - } - }else{ //no error - error_count_right = 0; +if (i2c_transaction(SLAVE_I2C_ADDRESS_RIGHT, 0x3F, 0)) { + for (uint8_t i = 0; i < MATRIX_ROWS ; i++) { + matrix[i] &= 0x3F; //mask bits to keep } +} - if (i2c_transaction(SLAVE_I2C_ADDRESS_ARROW, 0X3FFF, 8)){ //error has occured for arrow cluster - error_count_arrow++; - if (error_count_arrow > ERROR_DISCONNECT_COUNT){ //disconnect arrow cluster - for (uint8_t i = 0; i < MATRIX_ROWS ; i++) { - matrix[i] &= 0x3FFF; //mask bits to keep - } - } - }else{ //no error - error_count_arrow = 0; +if (i2c_transaction(SLAVE_I2C_ADDRESS_ARROW, 0X3FFF, 8)) { + for (uint8_t i = 0; i < MATRIX_ROWS ; i++) { + matrix[i] &= 0x3FFF; //mask bits to keep } +} - if (i2c_transaction(SLAVE_I2C_ADDRESS_NUMPAD, 0x1FFFF, 11)){ //error has occured for numpad - error_count_numpad++; - if (error_count_numpad > ERROR_DISCONNECT_COUNT){ //disconnect numpad - for (uint8_t i = 0; i < MATRIX_ROWS ; i++) { - matrix[i] &= 0x1FFFF; //mask bits to keep - } - } - }else{ //no error - error_count_numpad = 0; +if (i2c_transaction(SLAVE_I2C_ADDRESS_NUMPAD, 0x1FFFF, 11)) { + for (uint8_t i = 0; i < MATRIX_ROWS ; i++) { + matrix[i] &= 0x1FFFF; //mask bits to keep } +} matrix_scan_quantum(); return 1; @@ -436,29 +418,37 @@ static void unselect_cols(void) // Complete rows from other modules over i2c i2c_status_t i2c_transaction(uint8_t address, uint32_t mask, uint8_t col_offset) { - i2c_status_t err = i2c_start((address << 1) | I2C_WRITE, 10); - i2c_write(0x01, 10); //request data in address 1 + i2c_status_t status = i2c_start(address, 50); + if (status < 0) { + goto error; + } - i2c_start((address << 1) | I2C_READ, 5); + status = i2c_write(0x01, 50); + if (status < 0) { + goto error; + } - err = i2c_read_ack(10); - if (err == 0x55) { //synchronization byte + status = i2c_start(address | I2C_READ, 50); - for (uint8_t i = 0; i < MATRIX_ROWS-1 ; i++) { //assemble slave matrix in main matrix - matrix[i] &= mask; //mask bits to keep - err = i2c_read_ack(10); - matrix[i] |= ((uint32_t)err << (MATRIX_COLS_SCANNED + col_offset)); //add new bits at the end - } - //last read request must be followed by a NACK - matrix[MATRIX_ROWS - 1] &= mask; //mask bits to keep - err = i2c_read_nack(10); - matrix[MATRIX_ROWS - 1] |= ((uint32_t)err << (MATRIX_COLS_SCANNED + col_offset)); //add new bits at the end + status = i2c_read_ack(50); + if (status != 0x55) { //synchronization byte + goto error; + } - } else { - i2c_stop(); - return 1; + for (uint8_t i = 0; i < MATRIX_ROWS-1 && status >= 0; i++) { //assemble slave matrix in main matrix + matrix[i] &= mask; //mask bits to keep + status = i2c_read_ack(50); + matrix[i] |= ((uint32_t)status << (MATRIX_COLS_SCANNED + col_offset)); //add new bits at the end + } + //last read request must be followed by a NACK + if (status >= 0) { + matrix[MATRIX_ROWS - 1] &= mask; //mask bits to keep + status = i2c_read_nack(50); + matrix[MATRIX_ROWS - 1] |= ((uint32_t)status << (MATRIX_COLS_SCANNED + col_offset)); //add new bits at the end } +error: i2c_stop(); - return 0; + + return (status < 0) ? status : I2C_STATUS_SUCCESS; } \ No newline at end of file -- cgit v1.2.3