diff options
| author | Joshua Diamond <josh@windowoffire.com> | 2021-02-15 20:55:54 -0500 |
|---|---|---|
| committer | Joshua Diamond <josh@windowoffire.com> | 2021-02-15 20:55:54 -0500 |
| commit | d36dbe66e1b9146df85586b46c58e51a3dbb3653 (patch) | |
| tree | f1e8f2e518e7583b7fc4162c7f06c1193844d927 /keyboards/dc01/left/matrix.c | |
| parent | b0e161e33d8ec030c6965daa57a76ec70b1a1122 (diff) | |
| parent | 3fed8bced718e24e414c0d5736554d7988235b20 (diff) | |
| download | qmk_firmware-d36dbe66e1b9146df85586b46c58e51a3dbb3653.tar.gz qmk_firmware-d36dbe66e1b9146df85586b46c58e51a3dbb3653.zip | |
Merge branch 'master' into develop
Diffstat (limited to 'keyboards/dc01/left/matrix.c')
| -rw-r--r-- | keyboards/dc01/left/matrix.c | 92 |
1 files changed, 41 insertions, 51 deletions
diff --git a/keyboards/dc01/left/matrix.c b/keyboards/dc01/left/matrix.c index 41ecb8e17..c3b3b39a4 100644 --- a/keyboards/dc01/left/matrix.c +++ b/keyboards/dc01/left/matrix.c | |||
| @@ -31,14 +31,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 31 | #include "timer.h" | 31 | #include "timer.h" |
| 32 | #include "i2c_master.h" | 32 | #include "i2c_master.h" |
| 33 | 33 | ||
| 34 | #define SLAVE_I2C_ADDRESS_RIGHT 0x19 | 34 | #define SLAVE_I2C_ADDRESS_RIGHT 0x32 |
| 35 | #define SLAVE_I2C_ADDRESS_NUMPAD 0x21 | 35 | #define SLAVE_I2C_ADDRESS_NUMPAD 0x36 |
| 36 | #define SLAVE_I2C_ADDRESS_ARROW 0x23 | 36 | #define SLAVE_I2C_ADDRESS_ARROW 0x40 |
| 37 | 37 | ||
| 38 | #define ERROR_DISCONNECT_COUNT 5 | 38 | #define ERROR_DISCONNECT_COUNT 5 |
| 39 | static uint8_t error_count_right = 0; | ||
| 40 | static uint8_t error_count_numpad = 0; | ||
| 41 | static uint8_t error_count_arrow = 0; | ||
| 42 | 39 | ||
| 43 | /* Set 0 if debouncing isn't needed */ | 40 | /* Set 0 if debouncing isn't needed */ |
| 44 | 41 | ||
| @@ -210,38 +207,23 @@ uint8_t matrix_scan(void) | |||
| 210 | } | 207 | } |
| 211 | # endif | 208 | # endif |
| 212 | 209 | ||
| 213 | if (i2c_transaction(SLAVE_I2C_ADDRESS_RIGHT, 0x3F, 0)){ //error has occured for main right half | 210 | if (i2c_transaction(SLAVE_I2C_ADDRESS_RIGHT, 0x3F, 0)) { |
| 214 | error_count_right++; | 211 | for (uint8_t i = 0; i < MATRIX_ROWS ; i++) { |
| 215 | if (error_count_right > ERROR_DISCONNECT_COUNT){ //disconnect half | 212 | matrix[i] &= 0x3F; //mask bits to keep |
| 216 | for (uint8_t i = 0; i < MATRIX_ROWS ; i++) { | ||
| 217 | matrix[i] &= 0x3F; //mask bits to keep | ||
| 218 | } | ||
| 219 | } | ||
| 220 | }else{ //no error | ||
| 221 | error_count_right = 0; | ||
| 222 | } | 213 | } |
| 214 | } | ||
| 223 | 215 | ||
| 224 | if (i2c_transaction(SLAVE_I2C_ADDRESS_ARROW, 0X3FFF, 8)){ //error has occured for arrow cluster | 216 | if (i2c_transaction(SLAVE_I2C_ADDRESS_ARROW, 0X3FFF, 8)) { |
| 225 | error_count_arrow++; | 217 | for (uint8_t i = 0; i < MATRIX_ROWS ; i++) { |
| 226 | if (error_count_arrow > ERROR_DISCONNECT_COUNT){ //disconnect arrow cluster | 218 | matrix[i] &= 0x3FFF; //mask bits to keep |
| 227 | for (uint8_t i = 0; i < MATRIX_ROWS ; i++) { | ||
| 228 | matrix[i] &= 0x3FFF; //mask bits to keep | ||
| 229 | } | ||
| 230 | } | ||
| 231 | }else{ //no error | ||
| 232 | error_count_arrow = 0; | ||
| 233 | } | 219 | } |
| 220 | } | ||
| 234 | 221 | ||
| 235 | if (i2c_transaction(SLAVE_I2C_ADDRESS_NUMPAD, 0x1FFFF, 11)){ //error has occured for numpad | 222 | if (i2c_transaction(SLAVE_I2C_ADDRESS_NUMPAD, 0x1FFFF, 11)) { |
| 236 | error_count_numpad++; | 223 | for (uint8_t i = 0; i < MATRIX_ROWS ; i++) { |
| 237 | if (error_count_numpad > ERROR_DISCONNECT_COUNT){ //disconnect numpad | 224 | matrix[i] &= 0x1FFFF; //mask bits to keep |
| 238 | for (uint8_t i = 0; i < MATRIX_ROWS ; i++) { | ||
| 239 | matrix[i] &= 0x1FFFF; //mask bits to keep | ||
| 240 | } | ||
| 241 | } | ||
| 242 | }else{ //no error | ||
| 243 | error_count_numpad = 0; | ||
| 244 | } | 225 | } |
| 226 | } | ||
| 245 | 227 | ||
| 246 | matrix_scan_quantum(); | 228 | matrix_scan_quantum(); |
| 247 | return 1; | 229 | return 1; |
| @@ -436,29 +418,37 @@ static void unselect_cols(void) | |||
| 436 | 418 | ||
| 437 | // Complete rows from other modules over i2c | 419 | // Complete rows from other modules over i2c |
| 438 | i2c_status_t i2c_transaction(uint8_t address, uint32_t mask, uint8_t col_offset) { | 420 | i2c_status_t i2c_transaction(uint8_t address, uint32_t mask, uint8_t col_offset) { |
| 439 | i2c_status_t err = i2c_start((address << 1) | I2C_WRITE, 10); | 421 | i2c_status_t status = i2c_start(address, 50); |
| 440 | i2c_write(0x01, 10); //request data in address 1 | 422 | if (status < 0) { |
| 423 | goto error; | ||
| 424 | } | ||
| 441 | 425 | ||
| 442 | i2c_start((address << 1) | I2C_READ, 5); | 426 | status = i2c_write(0x01, 50); |
| 427 | if (status < 0) { | ||
| 428 | goto error; | ||
| 429 | } | ||
| 443 | 430 | ||
| 444 | err = i2c_read_ack(10); | 431 | status = i2c_start(address | I2C_READ, 50); |
| 445 | if (err == 0x55) { //synchronization byte | ||
| 446 | 432 | ||
| 447 | for (uint8_t i = 0; i < MATRIX_ROWS-1 ; i++) { //assemble slave matrix in main matrix | 433 | status = i2c_read_ack(50); |
| 448 | matrix[i] &= mask; //mask bits to keep | 434 | if (status != 0x55) { //synchronization byte |
| 449 | err = i2c_read_ack(10); | 435 | goto error; |
| 450 | matrix[i] |= ((uint32_t)err << (MATRIX_COLS_SCANNED + col_offset)); //add new bits at the end | 436 | } |
| 451 | } | ||
| 452 | //last read request must be followed by a NACK | ||
| 453 | matrix[MATRIX_ROWS - 1] &= mask; //mask bits to keep | ||
| 454 | err = i2c_read_nack(10); | ||
| 455 | matrix[MATRIX_ROWS - 1] |= ((uint32_t)err << (MATRIX_COLS_SCANNED + col_offset)); //add new bits at the end | ||
| 456 | 437 | ||
| 457 | } else { | 438 | for (uint8_t i = 0; i < MATRIX_ROWS-1 && status >= 0; i++) { //assemble slave matrix in main matrix |
| 458 | i2c_stop(); | 439 | matrix[i] &= mask; //mask bits to keep |
| 459 | return 1; | 440 | status = i2c_read_ack(50); |
| 441 | matrix[i] |= ((uint32_t)status << (MATRIX_COLS_SCANNED + col_offset)); //add new bits at the end | ||
| 442 | } | ||
| 443 | //last read request must be followed by a NACK | ||
| 444 | if (status >= 0) { | ||
| 445 | matrix[MATRIX_ROWS - 1] &= mask; //mask bits to keep | ||
| 446 | status = i2c_read_nack(50); | ||
| 447 | matrix[MATRIX_ROWS - 1] |= ((uint32_t)status << (MATRIX_COLS_SCANNED + col_offset)); //add new bits at the end | ||
| 460 | } | 448 | } |
| 461 | 449 | ||
| 450 | error: | ||
| 462 | i2c_stop(); | 451 | i2c_stop(); |
| 463 | return 0; | 452 | |
| 453 | return (status < 0) ? status : I2C_STATUS_SUCCESS; | ||
| 464 | } \ No newline at end of file | 454 | } \ No newline at end of file |
