1
0
Fork 0

Merge branch 'master' into develop

This commit is contained in:
Joshua Diamond 2021-02-15 20:55:54 -05:00
commit d36dbe66e1
60 changed files with 979 additions and 968 deletions

View file

@ -31,14 +31,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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_start((address << 1) | I2C_READ, 5);
err = i2c_read_ack(10);
if (err == 0x55) { //synchronization byte
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
} else {
i2c_stop();
return 1;
i2c_status_t status = i2c_start(address, 50);
if (status < 0) {
goto error;
}
status = i2c_write(0x01, 50);
if (status < 0) {
goto error;
}
status = i2c_start(address | I2C_READ, 50);
status = i2c_read_ack(50);
if (status != 0x55) { //synchronization byte
goto error;
}
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;
}