Update I2C API usage in keyboard code (#23360)
This commit is contained in:
parent
148d66fc9f
commit
01be746fc4
@ -138,14 +138,14 @@ uint8_t init_mcp23018(void) {
|
|||||||
// - input : input : 1
|
// - input : input : 1
|
||||||
// - driving : output : 0
|
// - driving : output : 0
|
||||||
uint8_t data[] = {0b00000000, 0b00111111};
|
uint8_t data[] = {0b00000000, 0b00111111};
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, IODIRA, data, 2, BAJJAK_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, IODIRA, data, 2, BAJJAK_EZ_I2C_TIMEOUT);
|
||||||
|
|
||||||
if (!mcp23018_status) {
|
if (!mcp23018_status) {
|
||||||
// set pull-up
|
// set pull-up
|
||||||
// - unused : on : 1
|
// - unused : on : 1
|
||||||
// - input : on : 1
|
// - input : on : 1
|
||||||
// - driving : off : 0
|
// - driving : off : 0
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, IODIRA, data, 2, BAJJAK_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, IODIRA, data, 2, BAJJAK_EZ_I2C_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LEFT_LEDS
|
#ifdef LEFT_LEDS
|
||||||
@ -172,7 +172,7 @@ uint8_t bajjak_left_leds_update(void) {
|
|||||||
uint8_t data[2];
|
uint8_t data[2];
|
||||||
data[0] = 0b11111111 & ~(bajjak_left_led_1<<LEFT_LED_1_SHIFT);
|
data[0] = 0b11111111 & ~(bajjak_left_led_1<<LEFT_LED_1_SHIFT);
|
||||||
data[1] = 0b11111111 & ~(bajjak_left_led_2<<LEFT_LED_2_SHIFT);
|
data[1] = 0b11111111 & ~(bajjak_left_led_2<<LEFT_LED_2_SHIFT);
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, OLATA, data, 2, BAJJAK_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, OLATA, data, 2, BAJJAK_EZ_I2C_TIMEOUT);
|
||||||
|
|
||||||
return mcp23018_status;
|
return mcp23018_status;
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ static void select_row(uint8_t row) {
|
|||||||
// set other rows hi-Z : 1
|
// set other rows hi-Z : 1
|
||||||
uint8_t data;
|
uint8_t data;
|
||||||
data = 0xFF & ~(1 << row);
|
data = 0xFF & ~(1 << row);
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, GPIOA, &data, 1, BAJJAK_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPIOA, &data, 1, BAJJAK_EZ_I2C_TIMEOUT);
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -388,7 +388,7 @@ static void unselect_cols(void)
|
|||||||
// Complete rows from other modules over i2c
|
// 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 i2c_transaction(uint8_t address, uint32_t mask, uint8_t col_offset) {
|
||||||
uint8_t data[MATRIX_ROWS + 1];
|
uint8_t data[MATRIX_ROWS + 1];
|
||||||
i2c_status_t status = i2c_readReg(address, 0x01, data, (MATRIX_ROWS + 1), 5);
|
i2c_status_t status = i2c_read_register(address, 0x01, data, (MATRIX_ROWS + 1), 5);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < (MATRIX_ROWS) && status >= 0; i++) { //assemble slave matrix in main matrix
|
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] &= mask; //mask bits to keep
|
||||||
|
@ -156,14 +156,14 @@ uint8_t init_mcp23018(void) {
|
|||||||
// - input : input : 1
|
// - input : input : 1
|
||||||
// - driving : output : 0
|
// - driving : output : 0
|
||||||
uint8_t data[] = {0b00000000, 0b00111111};
|
uint8_t data[] = {0b00000000, 0b00111111};
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, IODIRA, data, 2, ERGODOX_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, IODIRA, data, 2, ERGODOX_EZ_I2C_TIMEOUT);
|
||||||
|
|
||||||
if (!mcp23018_status) {
|
if (!mcp23018_status) {
|
||||||
// set pull-up
|
// set pull-up
|
||||||
// - unused : on : 1
|
// - unused : on : 1
|
||||||
// - input : on : 1
|
// - input : on : 1
|
||||||
// - driving : off : 0
|
// - driving : off : 0
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, GPPUA, data, 2, ERGODOX_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPPUA, data, 2, ERGODOX_EZ_I2C_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LEFT_LEDS
|
#ifdef LEFT_LEDS
|
||||||
@ -191,7 +191,7 @@ uint8_t ergodox_left_leds_update(void) {
|
|||||||
uint8_t data[2];
|
uint8_t data[2];
|
||||||
data[0] = 0b11111111 & ~(ergodox_left_led_3 << LEFT_LED_3_SHIFT);
|
data[0] = 0b11111111 & ~(ergodox_left_led_3 << LEFT_LED_3_SHIFT);
|
||||||
data[1] = 0b11111111 & ~(ergodox_left_led_2 << LEFT_LED_2_SHIFT) & ~(ergodox_left_led_1 << LEFT_LED_1_SHIFT);
|
data[1] = 0b11111111 & ~(ergodox_left_led_2 << LEFT_LED_2_SHIFT) & ~(ergodox_left_led_1 << LEFT_LED_1_SHIFT);
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, OLATA, data, 2, ERGODOX_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, OLATA, data, 2, ERGODOX_EZ_I2C_TIMEOUT);
|
||||||
|
|
||||||
return mcp23018_status;
|
return mcp23018_status;
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ static void select_row(uint8_t row) {
|
|||||||
// set other rows hi-Z : 1
|
// set other rows hi-Z : 1
|
||||||
uint8_t data;
|
uint8_t data;
|
||||||
data = 0xFF & ~(1 << row);
|
data = 0xFF & ~(1 << row);
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, GPIOA, &data, 1, ERGODOX_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPIOA, &data, 1, ERGODOX_EZ_I2C_TIMEOUT);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// select on teensy
|
// select on teensy
|
||||||
|
@ -77,7 +77,7 @@ uint8_t init_mcp23017(void) {
|
|||||||
// This means: we will write to the pins 0-4 on GPIOB (in select_rows)
|
// This means: we will write to the pins 0-4 on GPIOB (in select_rows)
|
||||||
uint8_t buf[] = {0b11111111, 0b11110000};
|
uint8_t buf[] = {0b11111111, 0b11110000};
|
||||||
print("before transmit\n");
|
print("before transmit\n");
|
||||||
mcp23017_status = i2c_writeReg(I2C_ADDR, IODIRA, buf, sizeof(buf), MCP23017_I2C_TIMEOUT)
|
mcp23017_status = i2c_write_register(I2C_ADDR, IODIRA, buf, sizeof(buf), MCP23017_I2C_TIMEOUT);
|
||||||
uprintf("after transmit %i\n", mcp23017_status);
|
uprintf("after transmit %i\n", mcp23017_status);
|
||||||
if (!mcp23017_status) {
|
if (!mcp23017_status) {
|
||||||
// set pull-up
|
// set pull-up
|
||||||
@ -86,7 +86,7 @@ uint8_t init_mcp23017(void) {
|
|||||||
// - driving : off : 0
|
// - driving : off : 0
|
||||||
// This means: we will read all the bits on GPIOA
|
// This means: we will read all the bits on GPIOA
|
||||||
// This means: we will write to the pins 0-4 on GPIOB (in select_rows)
|
// This means: we will write to the pins 0-4 on GPIOB (in select_rows)
|
||||||
mcp23017_status = i2c_writeReg(I2C_ADDR, GPPUA, buf, sizeof(buf), MCP23017_I2C_TIMEOUT)
|
mcp23017_status = i2c_write_register(I2C_ADDR, GPPUA, buf, sizeof(buf), MCP23017_I2C_TIMEOUT);
|
||||||
uprintf("after transmit2 %i\n", mcp23017_status);
|
uprintf("after transmit2 %i\n", mcp23017_status);
|
||||||
}
|
}
|
||||||
return mcp23017_status;
|
return mcp23017_status;
|
||||||
@ -191,7 +191,7 @@ static matrix_row_t read_cols(uint8_t row) {
|
|||||||
// The return value is a row as represented in the generic matrix code were the rightmost bits represent the lower columns and zeroes represent non-depressed keys while ones represent depressed keys.
|
// The return value is a row as represented in the generic matrix code were the rightmost bits represent the lower columns and zeroes represent non-depressed keys while ones represent depressed keys.
|
||||||
// Since the pins connected to eact columns are sequential, and counting from zero up (col 5 -> GPIOA0, col 6 -> GPIOA1 and so on), the only transformation needed is a bitwise not to swap all zeroes and ones.
|
// Since the pins connected to eact columns are sequential, and counting from zero up (col 5 -> GPIOA0, col 6 -> GPIOA1 and so on), the only transformation needed is a bitwise not to swap all zeroes and ones.
|
||||||
uint8_t data[] = {0};
|
uint8_t data[] = {0};
|
||||||
mcp23017_status = i2c_readReg(I2C_ADDR, MCP23017_GPIOA, data, sizeof(data), MCP23017_I2C_TIMEOUT);
|
mcp23017_status = i2c_read_register(I2C_ADDR, MCP23017_GPIOA, data, sizeof(data), MCP23017_I2C_TIMEOUT);
|
||||||
return ~data[0];
|
return ~data[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,7 +237,7 @@ static void select_row(uint8_t row) {
|
|||||||
// Select the desired row by writing a byte for the entire GPIOB bus where only the bit representing the row we want to select is a zero (write instruction) and every other bit is a one.
|
// Select the desired row by writing a byte for the entire GPIOB bus where only the bit representing the row we want to select is a zero (write instruction) and every other bit is a one.
|
||||||
// Note that the row - MATRIX_ROWS_PER_SIDE reflects the fact that being on the right hand, the columns are numbered from MATRIX_ROWS_PER_SIDE to MATRIX_ROWS, but the pins we want to write to are indexed from zero up on the GPIOB bus.
|
// Note that the row - MATRIX_ROWS_PER_SIDE reflects the fact that being on the right hand, the columns are numbered from MATRIX_ROWS_PER_SIDE to MATRIX_ROWS, but the pins we want to write to are indexed from zero up on the GPIOB bus.
|
||||||
uint8_t buf[] = {0xFF & ~(1 << (row - MATRIX_ROWS_PER_SIDE))};
|
uint8_t buf[] = {0xFF & ~(1 << (row - MATRIX_ROWS_PER_SIDE))};
|
||||||
mcp23017_status = i2c_writeReg(I2C_ADDR, MCP23017_GPIOB, buf, sizeof(buf), MCP23017_I2C_TIMEOUT);
|
mcp23017_status = i2c_write_register(I2C_ADDR, MCP23017_GPIOB, buf, sizeof(buf), MCP23017_I2C_TIMEOUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,14 +50,14 @@ uint8_t init_mcp23018(void) {
|
|||||||
// - input : input : 1
|
// - input : input : 1
|
||||||
// - driving : output : 0
|
// - driving : output : 0
|
||||||
uint8_t data[] = {0b00000000, 0b00111111};
|
uint8_t data[] = {0b00000000, 0b00111111};
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, IODIRA, data, sizeof(data), ERGODOX_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, IODIRA, data, sizeof(data), ERGODOX_EZ_I2C_TIMEOUT);
|
||||||
|
|
||||||
if (!mcp23018_status) {
|
if (!mcp23018_status) {
|
||||||
// set pull-up
|
// set pull-up
|
||||||
// - unused : on : 1
|
// - unused : on : 1
|
||||||
// - input : on : 1
|
// - input : on : 1
|
||||||
// - driving : off : 0
|
// - driving : off : 0
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, GPPUA, data, sizeof(data), ERGODOX_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPPUA, data, sizeof(data), ERGODOX_EZ_I2C_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SREG=sreg_prev;
|
// SREG=sreg_prev;
|
||||||
|
@ -234,7 +234,7 @@ static matrix_row_t read_cols(uint8_t row)
|
|||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
uint8_t data = 0;
|
uint8_t data = 0;
|
||||||
mcp23018_status = i2c_readReg(I2C_ADDR, GPIOB, &data, 1, ERGODOX_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_read_register(I2C_ADDR, GPIOB, &data, 1, ERGODOX_EZ_I2C_TIMEOUT);
|
||||||
data = (~((uint8_t)data) >> 2) & 0x01 ;
|
data = (~((uint8_t)data) >> 2) & 0x01 ;
|
||||||
#ifdef DEBUG_MATRIX
|
#ifdef DEBUG_MATRIX
|
||||||
if (data != 0x00) xprintf("I2C: %d\n", data);
|
if (data != 0x00) xprintf("I2C: %d\n", data);
|
||||||
@ -268,7 +268,7 @@ static void select_row(uint8_t row)
|
|||||||
// Read using bitmask
|
// Read using bitmask
|
||||||
} else { // set active row low : 0 // set other rows hi-Z : 1
|
} else { // set active row low : 0 // set other rows hi-Z : 1
|
||||||
uint8_t data = ~(1<<row);
|
uint8_t data = ~(1<<row);
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, GPIOA, &data, 1, ERGODOX_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPIOA, &data, 1, ERGODOX_EZ_I2C_TIMEOUT);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Output low(DDR:1, PORT:0) to select
|
// Output low(DDR:1, PORT:0) to select
|
||||||
|
@ -46,14 +46,14 @@ uint8_t init_mcp23018(void) {
|
|||||||
// - input : input : 1
|
// - input : input : 1
|
||||||
// - driving : output : 0
|
// - driving : output : 0
|
||||||
uint8_t data[] = {0b10000000, 0b11111111};
|
uint8_t data[] = {0b10000000, 0b11111111};
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, IODIRA, data, 2, ERGODOX_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, IODIRA, data, 2, ERGODOX_EZ_I2C_TIMEOUT);
|
||||||
|
|
||||||
if (!mcp23018_status) {
|
if (!mcp23018_status) {
|
||||||
// set pull-up
|
// set pull-up
|
||||||
// - unused : on : 1
|
// - unused : on : 1
|
||||||
// - input : on : 1
|
// - input : on : 1
|
||||||
// - driving : off : 0
|
// - driving : off : 0
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, GPPUA, data, 2, ERGODOX_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPPUA, data, 2, ERGODOX_EZ_I2C_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SREG=sreg_prev;
|
// SREG=sreg_prev;
|
||||||
|
@ -254,7 +254,7 @@ static matrix_row_t read_cols(uint8_t row)
|
|||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
uint8_t data = 0;
|
uint8_t data = 0;
|
||||||
mcp23018_status = i2c_readReg(I2C_ADDR, GPIOB, &data, 1, ERGODOX_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_read_register(I2C_ADDR, GPIOB, &data, 1, ERGODOX_EZ_I2C_TIMEOUT);
|
||||||
|
|
||||||
#ifdef DEBUG_MATRIX
|
#ifdef DEBUG_MATRIX
|
||||||
if (data != 0x00) xprintf("I2C: %d\n", data);
|
if (data != 0x00) xprintf("I2C: %d\n", data);
|
||||||
@ -298,7 +298,7 @@ static void select_row(uint8_t row)
|
|||||||
if (mcp23018_status) { // do nothing on error
|
if (mcp23018_status) { // do nothing on error
|
||||||
} else { // set active row low : 0 // set other rows hi-Z : 1
|
} else { // set active row low : 0 // set other rows hi-Z : 1
|
||||||
uint8_t data = 0xFF & ~(1<<row);
|
uint8_t data = 0xFF & ~(1<<row);
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, GPIOA, &data, 1, ERGODOX_EZ_I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPIOA, &data, 1, ERGODOX_EZ_I2C_TIMEOUT);
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -44,14 +44,14 @@ uint8_t init_mcp23018(void) {
|
|||||||
// - input : input : 1
|
// - input : input : 1
|
||||||
// - driving : output : 0
|
// - driving : output : 0
|
||||||
uint8_t data[] = {0b10000000, 0b11111111};
|
uint8_t data[] = {0b10000000, 0b11111111};
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, IODIRA, data, sizeof(data), I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, IODIRA, data, sizeof(data), I2C_TIMEOUT);
|
||||||
|
|
||||||
if (!mcp23018_status) {
|
if (!mcp23018_status) {
|
||||||
// set pull-up
|
// set pull-up
|
||||||
// - unused : on : 1
|
// - unused : on : 1
|
||||||
// - input : on : 1
|
// - input : on : 1
|
||||||
// - driving : off : 0
|
// - driving : off : 0
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, GPPUA, data, sizeof(data), I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPPUA, data, sizeof(data), I2C_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SREG=sreg_prev;
|
// SREG=sreg_prev;
|
||||||
|
@ -297,7 +297,7 @@ static matrix_row_t read_cols(uint8_t row) {
|
|||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
uint8_t data = 0;
|
uint8_t data = 0;
|
||||||
mcp23018_status = i2c_readReg(I2C_ADDR, GPIOB, &data, 1, I2C_TIMEOUT);
|
mcp23018_status = i2c_read_register(I2C_ADDR, GPIOB, &data, 1, I2C_TIMEOUT);
|
||||||
|
|
||||||
#ifdef DEBUG_MATRIX
|
#ifdef DEBUG_MATRIX
|
||||||
if (~data != 0x00) xprintf("I2C: %d\n", ~data);
|
if (~data != 0x00) xprintf("I2C: %d\n", ~data);
|
||||||
@ -344,7 +344,7 @@ static void select_row(uint8_t row)
|
|||||||
if (mcp23018_status) { // do nothing on error
|
if (mcp23018_status) { // do nothing on error
|
||||||
} else { // set active row low : 0 // set other rows hi-Z : 1
|
} else { // set active row low : 0 // set other rows hi-Z : 1
|
||||||
uint8_t data = 0xFF & ~(1<<row);
|
uint8_t data = 0xFF & ~(1<<row);
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, GPIOA, &data, 1, I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPIOA, &data, 1, I2C_TIMEOUT);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Output low(DDR:1, PORT:0) to select
|
// Output low(DDR:1, PORT:0) to select
|
||||||
|
@ -40,14 +40,14 @@ uint8_t init_mcp23018(void) {
|
|||||||
// - input : input : 1
|
// - input : input : 1
|
||||||
// - driving : output : 0
|
// - driving : output : 0
|
||||||
uint8_t data[] = {0b11000001, 0b11111111};
|
uint8_t data[] = {0b11000001, 0b11111111};
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, IODIRA, data, sizeof(data), I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, IODIRA, data, sizeof(data), I2C_TIMEOUT);
|
||||||
|
|
||||||
if (!mcp23018_status) {
|
if (!mcp23018_status) {
|
||||||
// set pull-up
|
// set pull-up
|
||||||
// - unused : on : 1
|
// - unused : on : 1
|
||||||
// - input : on : 1
|
// - input : on : 1
|
||||||
// - driving : off : 0
|
// - driving : off : 0
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, GPPUA, data, sizeof(data), I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPPUA, data, sizeof(data), I2C_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mcp23018_status;
|
return mcp23018_status;
|
||||||
|
@ -207,7 +207,7 @@ static void select_row(uint8_t row) {
|
|||||||
} else { // set active row low : 0 // set other rows hi-Z : 1
|
} else { // set active row low : 0 // set other rows hi-Z : 1
|
||||||
uint8_t data;
|
uint8_t data;
|
||||||
data = 0xFF & ~(1 << (row + 1));
|
data = 0xFF & ~(1 << (row + 1));
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, GPIOA, &data, 1, I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPIOA, &data, 1, I2C_TIMEOUT);
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -84,14 +84,14 @@ uint8_t init_mcp23018(void) {
|
|||||||
// - input : input : 1
|
// - input : input : 1
|
||||||
// - driving : output : 0
|
// - driving : output : 0
|
||||||
uint8_t data[] = {0b00000000, 0b00111111};
|
uint8_t data[] = {0b00000000, 0b00111111};
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, IODIRA, data, sizeof(data), I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, IODIRA, data, sizeof(data), I2C_TIMEOUT);
|
||||||
|
|
||||||
if (!mcp23018_status) {
|
if (!mcp23018_status) {
|
||||||
// set pull-up
|
// set pull-up
|
||||||
// - unused : on : 1
|
// - unused : on : 1
|
||||||
// - input : on : 1
|
// - input : on : 1
|
||||||
// - driving : off : 0
|
// - driving : off : 0
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, GPPUA, data, sizeof(data), I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPPUA, data, sizeof(data), I2C_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SREG=sreg_prev;
|
// SREG=sreg_prev;
|
||||||
|
@ -224,7 +224,7 @@ static matrix_row_t read_cols(uint8_t row)
|
|||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
uint8_t data = 0;
|
uint8_t data = 0;
|
||||||
mcp23018_status = i2c_readReg(I2C_ADDR, GPIOB, &data, 1, I2C_TIMEOUT);
|
mcp23018_status = i2c_read_register(I2C_ADDR, GPIOB, &data, 1, I2C_TIMEOUT);
|
||||||
|
|
||||||
return ~data;
|
return ~data;
|
||||||
}
|
}
|
||||||
@ -259,7 +259,7 @@ static void unselect_rows(void)
|
|||||||
// set all rows hi-Z : 1
|
// set all rows hi-Z : 1
|
||||||
uint8_t data;
|
uint8_t data;
|
||||||
data = 0xFF & ~(0<<8);
|
data = 0xFF & ~(0<<8);
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, GPIOA, &data, 1, I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPIOA, &data, 1, I2C_TIMEOUT);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ static void select_row(uint8_t row)
|
|||||||
// set active row low : 0
|
// set active row low : 0
|
||||||
// set other rows hi-Z : 1
|
// set other rows hi-Z : 1
|
||||||
uint8_t data = 0xFF & ~(1<<row) & ~(0<<8);
|
uint8_t data = 0xFF & ~(1<<row) & ~(0<<8);
|
||||||
mcp23018_status = i2c_writeReg(I2C_ADDR, GPIOA, &data, 1, I2C_TIMEOUT);
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPIOA, &data, 1, I2C_TIMEOUT);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// select on teensy
|
// select on teensy
|
||||||
|
@ -182,14 +182,14 @@ void init_expander(void) {
|
|||||||
uint8_t data[] = { expander_input_pin_mask, 0};
|
uint8_t data[] = { expander_input_pin_mask, 0};
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
expander_status = i2c_writeReg(I2C_ADDR, IODIRA, data, sizeof(data), I2C_TIMEOUT);
|
expander_status = i2c_write_register(I2C_ADDR, IODIRA, data, sizeof(data), I2C_TIMEOUT);
|
||||||
|
|
||||||
if (!expander_status) {
|
if (!expander_status) {
|
||||||
// set pull-up
|
// set pull-up
|
||||||
// - unused : off : 0
|
// - unused : off : 0
|
||||||
// - input : on : 1
|
// - input : on : 1
|
||||||
// - driving : off : 0
|
// - driving : off : 0
|
||||||
expander_status = i2c_writeReg(I2C_ADDR, GPPUA, data, sizeof(data), I2C_TIMEOUT);
|
expander_status = i2c_write_register(I2C_ADDR, GPPUA, data, sizeof(data), I2C_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -305,7 +305,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
|
|||||||
// Read columns from expander, unless it's in an error state
|
// Read columns from expander, unless it's in an error state
|
||||||
if (! expander_status) {
|
if (! expander_status) {
|
||||||
uint8_t data;
|
uint8_t data;
|
||||||
i2c_readReg(I2C_ADDR, EXPANDER_COL_REGISTER, &data, 1, I2C_TIMEOUT);
|
i2c_read_register(I2C_ADDR, EXPANDER_COL_REGISTER, &data, 1, I2C_TIMEOUT);
|
||||||
current_matrix[current_row] |= (~data) & expander_input_pin_mask;
|
current_matrix[current_row] |= (~data) & expander_input_pin_mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,7 +329,7 @@ static void select_row(uint8_t row) {
|
|||||||
// set active row low : 0
|
// set active row low : 0
|
||||||
// set other rows hi-Z : 1
|
// set other rows hi-Z : 1
|
||||||
uint8_t data = 0xFF & ~(1<<row);
|
uint8_t data = 0xFF & ~(1<<row);
|
||||||
i2c_writeReg(I2C_ADDR, EXPANDER_ROW_REGISTER, &data, 1, I2C_TIMEOUT);
|
i2c_write_register(I2C_ADDR, EXPANDER_ROW_REGISTER, &data, 1, I2C_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// select on teensy
|
// select on teensy
|
||||||
@ -385,7 +385,7 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_writeReg(I2C_ADDR, EXPANDER_ROW_REGISTER, &column_state, 1, I2C_TIMEOUT);
|
i2c_write_register(I2C_ADDR, EXPANDER_ROW_REGISTER, &column_state, 1, I2C_TIMEOUT);
|
||||||
column_state = ~column_state;
|
column_state = ~column_state;
|
||||||
} else {
|
} else {
|
||||||
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
|
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
|
||||||
|
@ -99,7 +99,7 @@ i2c_status_t left_write(uint8_t reg, uint8_t data)
|
|||||||
|
|
||||||
i2c_status_t ret;
|
i2c_status_t ret;
|
||||||
|
|
||||||
ret = i2c_writeReg(I2C_ADDR, reg, &data, sizeof(data), HOTDOX_I2C_TIMEOUT);
|
ret = i2c_write_register(I2C_ADDR, reg, &data, sizeof(data), HOTDOX_I2C_TIMEOUT);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ i2c_status_t left_read(uint8_t reg, uint8_t *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
i2c_status_t ret = 0;
|
i2c_status_t ret = 0;
|
||||||
ret = i2c_readReg(I2C_ADDR, reg, data, 1, HOTDOX_I2C_TIMEOUT);
|
ret = i2c_read_register(I2C_ADDR, reg, data, 1, HOTDOX_I2C_TIMEOUT);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ i2c_status_t usb7206_read_reg(struct USB7206* self, uint32_t addr, uint8_t* data
|
|||||||
|
|
||||||
uint16_t read = 0x0006; // Buffer address 6 to skip header
|
uint16_t read = 0x0006; // Buffer address 6 to skip header
|
||||||
uint8_t data_with_buffer_length[length];
|
uint8_t data_with_buffer_length[length];
|
||||||
status = i2c_readReg16((self->addr << 1), read, data_with_buffer_length, length, I2C_TIMEOUT);
|
status = i2c_read_register16((self->addr << 1), read, data_with_buffer_length, length, I2C_TIMEOUT);
|
||||||
|
|
||||||
for (uint16_t i = 0; i < (length - 1) && status >= 0; i++) {
|
for (uint16_t i = 0; i < (length - 1) && status >= 0; i++) {
|
||||||
data[i] = data_with_buffer_length[i+1];
|
data[i] = data_with_buffer_length[i+1];
|
||||||
|
@ -206,5 +206,5 @@ __attribute__((weak)) i2c_status_t i2c_ping_address(uint8_t address, uint16_t ti
|
|||||||
// Best effort instead tries reading register 0 which will either succeed or timeout.
|
// Best effort instead tries reading register 0 which will either succeed or timeout.
|
||||||
// This approach may produce false negative results for I2C devices that do not respond to a register 0 read request.
|
// This approach may produce false negative results for I2C devices that do not respond to a register 0 read request.
|
||||||
uint8_t data = 0;
|
uint8_t data = 0;
|
||||||
return i2c_readReg(address, 0, &data, sizeof(data), timeout);
|
return i2c_read_register(address, 0, &data, sizeof(data), timeout);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user