I2C driver cleanup (#21273)
* remove i2c_start and i2c_stop from i2c drivers * remove static i2c_address variable from chibios i2c driver
This commit is contained in:
parent
2b0965944d
commit
e9bd7d7ad3
49 changed files with 280 additions and 603 deletions
|
@ -387,37 +387,13 @@ 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 status = i2c_start(address, 5);
|
||||
if (status < 0) {
|
||||
goto error;
|
||||
uint8_t data[MATRIX_ROWS + 1];
|
||||
i2c_status_t status = i2c_readReg(address, 0x01, data, (MATRIX_ROWS + 1), 5);
|
||||
|
||||
for (uint8_t i = 0; i < (MATRIX_ROWS) && status >= 0; i++) { //assemble slave matrix in main matrix
|
||||
matrix[i] &= mask; //mask bits to keep
|
||||
matrix[i] |= ((uint32_t)data[i+1] << (MATRIX_COLS_SCANNED + col_offset)); //add new bits at the end
|
||||
}
|
||||
|
||||
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 (status < 0) ? status : I2C_STATUS_SUCCESS;
|
||||
return status;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue