Skip to content

Commit

Permalink
Update GPIO expander API naming (qmk#23375)
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark authored Mar 29, 2024
1 parent e891109 commit d0cf7b8
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 30 deletions.
8 changes: 4 additions & 4 deletions drivers/gpio/mcp23018.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,20 @@ bool mcp23018_set_output_all(uint8_t slave_addr, uint8_t confA, uint8_t confB) {
return true;
}

bool mcp23018_readPins(uint8_t slave_addr, mcp23018_port_t port, uint8_t* out) {
bool mcp23018_read_pins(uint8_t slave_addr, mcp23018_port_t port, uint8_t* out) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t cmd = port ? CMD_GPIOB : CMD_GPIOA;

i2c_status_t ret = i2c_read_register(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("mcp23018_readPins::FAILED::%u\n", ret);
dprintf("mcp23018_read_pins::FAILED::%u\n", ret);
return false;
}

return true;
}

bool mcp23018_readPins_all(uint8_t slave_addr, uint16_t* out) {
bool mcp23018_read_pins_all(uint8_t slave_addr, uint16_t* out) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);

typedef union {
Expand All @@ -99,7 +99,7 @@ bool mcp23018_readPins_all(uint8_t slave_addr, uint16_t* out) {

i2c_status_t ret = i2c_read_register(addr, CMD_GPIOA, &data.u8[0], sizeof(data), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("mcp23018_readPins::FAILED::%u\n", ret);
dprintf("mcp23018_read_pins_all::FAILED::%u\n", ret);
return false;
}

Expand Down
9 changes: 7 additions & 2 deletions drivers/gpio/mcp23018.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ bool mcp23018_set_output_all(uint8_t slave_addr, uint8_t confA, uint8_t confB);
/**
* Read state of a given port
*/
bool mcp23018_readPins(uint8_t slave_addr, mcp23018_port_t port, uint8_t* ret);
bool mcp23018_read_pins(uint8_t slave_addr, mcp23018_port_t port, uint8_t* ret);

/**
* Read state of both ports sequentially
*
* - slightly faster than multiple readPins
*/
bool mcp23018_readPins_all(uint8_t slave_addr, uint16_t* ret);
bool mcp23018_read_pins_all(uint8_t slave_addr, uint16_t* ret);

// DEPRECATED - DO NOT USE

#define mcp23018_readPins mcp23018_read_pins
#define mcp23018_readPins_all mcp23018_read_pins_all
4 changes: 2 additions & 2 deletions drivers/gpio/pca9505.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool pca9505_set_output(uint8_t slave_addr, pca9505_port_t port, uint8_t conf) {
return true;
}

bool pca9505_readPins(uint8_t slave_addr, pca9505_port_t port, uint8_t* out) {
bool pca9505_read_pins(uint8_t slave_addr, pca9505_port_t port, uint8_t* out) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t cmd = 0;
switch (port) {
Expand All @@ -156,7 +156,7 @@ bool pca9505_readPins(uint8_t slave_addr, pca9505_port_t port, uint8_t* out) {

i2c_status_t ret = i2c_read_register(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9505_readPins::FAILED\n");
print("pca9505_read_pins::FAILED\n");
return false;
}

Expand Down
6 changes: 5 additions & 1 deletion drivers/gpio/pca9505.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ bool pca9505_set_output(uint8_t slave_addr, pca9505_port_t port, uint8_t conf);
/**
* Read state of a given port
*/
bool pca9505_readPins(uint8_t slave_addr, pca9505_port_t port, uint8_t* ret);
bool pca9505_read_pins(uint8_t slave_addr, pca9505_port_t port, uint8_t* ret);

// DEPRECATED - DO NOT USE

#define pca9505_readPins pca9505_read_pins
8 changes: 4 additions & 4 deletions drivers/gpio/pca9555.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ bool pca9555_set_output_all(uint8_t slave_addr, uint8_t confA, uint8_t confB) {
return true;
}

bool pca9555_readPins(uint8_t slave_addr, pca9555_port_t port, uint8_t* out) {
bool pca9555_read_pins(uint8_t slave_addr, pca9555_port_t port, uint8_t* out) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t cmd = port ? CMD_INPUT_1 : CMD_INPUT_0;

i2c_status_t ret = i2c_read_register(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9555_readPins::FAILED\n");
print("pca9555_read_pins::FAILED\n");
return false;
}

return true;
}

bool pca9555_readPins_all(uint8_t slave_addr, uint16_t* out) {
bool pca9555_read_pins_all(uint8_t slave_addr, uint16_t* out) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);

typedef union {
Expand All @@ -95,7 +95,7 @@ bool pca9555_readPins_all(uint8_t slave_addr, uint16_t* out) {

i2c_status_t ret = i2c_read_register(addr, CMD_INPUT_0, &data.u8[0], sizeof(data), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9555_readPins_all::FAILED\n");
print("pca9555_read_pins_all::FAILED\n");
return false;
}

Expand Down
9 changes: 7 additions & 2 deletions drivers/gpio/pca9555.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,16 @@ bool pca9555_set_output_all(uint8_t slave_addr, uint8_t confA, uint8_t confB);
/**
* Read state of a given port
*/
bool pca9555_readPins(uint8_t slave_addr, pca9555_port_t port, uint8_t* ret);
bool pca9555_read_pins(uint8_t slave_addr, pca9555_port_t port, uint8_t* ret);

/**
* Read state of both ports sequentially
*
* - slightly faster than multiple readPins
*/
bool pca9555_readPins_all(uint8_t slave_addr, uint16_t* ret);
bool pca9555_read_pins_all(uint8_t slave_addr, uint16_t* ret);

// DEPRECATED - DO NOT USE

#define pca9555_readPins pca9555_read_pins
#define pca9555_readPins_all pca9555_read_pins_all
2 changes: 1 addition & 1 deletion keyboards/geistmaschine/macropod/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
pca9555_setup();
}
// Read the entire port into this byte, 1 = not pressed, 0 = pressed
bool ret = pca9555_readPins(IC1, PCA9555_PORT0, &pin_states);
bool ret = pca9555_read_pins(IC1, PCA9555_PORT0, &pin_states);

// Update state
if (ret) {
Expand Down
2 changes: 1 addition & 1 deletion keyboards/ktec/ergodone/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static matrix_row_t expander_read_row(void) {
}

uint8_t ret = 0xFF;
mcp23018_errors += !mcp23018_readPins(I2C_ADDR, mcp23018_PORTA, &ret);
mcp23018_errors += !mcp23018_read_pins(I2C_ADDR, mcp23018_PORTA, &ret);

ret = bitrev(~ret);
ret = ((ret & 0b11111000) >> 1) | (ret & 0b00000011);
Expand Down
2 changes: 1 addition & 1 deletion keyboards/mechwild/sugarglider/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static matrix_row_t read_cols(void) {
}

uint8_t ret = 0xFF; // sets all to 1
mcp23018_errors += !mcp23018_readPins(I2C_ADDR, mcp23018_PORTB, &ret); // will update with values 0 = pulled down by connection, 1 = pulled up by pullup resistors
mcp23018_errors += !mcp23018_read_pins(I2C_ADDR, mcp23018_PORTB, &ret); // will update with values 0 = pulled down by connection, 1 = pulled up by pullup resistors

return (~ret) & 0b00111111; // Clears out the two row bits in the B buffer.
}
Expand Down
4 changes: 2 additions & 2 deletions keyboards/moon/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ static void select_row(uint8_t row) {
static uint16_t read_cols(void) {
uint8_t state_1 = 0;
uint8_t state_2 = 0;
pca9555_readPins(IC2, PCA9555_PORT0, &state_1);
pca9555_readPins(IC2, PCA9555_PORT1, &state_2);
pca9555_read_pins(IC2, PCA9555_PORT0, &state_1);
pca9555_read_pins(IC2, PCA9555_PORT1, &state_2);

uint16_t state = (((uint16_t)state_1 & PORT0_COLS_MASK) << 3) | (((uint16_t)state_2 & PORT1_COLS_MASK));

Expand Down
6 changes: 3 additions & 3 deletions keyboards/switchplate/southpaw_65/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ static uint32_t read_cols(void) {
uint8_t state_1 = 0;
uint8_t state_2 = 0;
uint8_t state_3 = 0;
pca9555_readPins(IC1, PCA9555_PORT1, &state_1);
pca9555_readPins(IC2, PCA9555_PORT0, &state_2);
pca9555_readPins(IC2, PCA9555_PORT1, &state_3);
pca9555_read_pins(IC1, PCA9555_PORT1, &state_1);
pca9555_read_pins(IC2, PCA9555_PORT0, &state_2);
pca9555_read_pins(IC2, PCA9555_PORT1, &state_3);

uint32_t state = ((((uint32_t)state_3 & 0b01111111) << 12) | ((uint32_t)state_2 << 4) | (((uint32_t)state_1 & 0b11110000) >> 4));
return ~state;
Expand Down
2 changes: 1 addition & 1 deletion keyboards/viktus/sp111/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static void select_row_MCP23018(uint8_t row) {

static uint16_t read_cols_MCP23018(void) {
uint16_t tmp = 0xFFFF;
mcp23018_errors += !mcp23018_readPins_all(I2C_ADDR, &tmp);
mcp23018_errors += !mcp23018_read_pins_all(I2C_ADDR, &tmp);

uint16_t state = ((tmp & 0b11111111) << 2) | ((tmp & 0b0110000000000000) >> 13);
return (~state) & 0b1111111111;
Expand Down
6 changes: 3 additions & 3 deletions keyboards/xiudi/xd84/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ static void select_row(uint8_t row) {
}

static uint16_t read_cols(void) {
// uint16_t state_1 = pca9555_readPins(IC2, PCA9555_PORT0);
// uint16_t state_2 = pca9555_readPins(IC2, PCA9555_PORT1);
// uint16_t state_1 = pca9555_read_pins(IC2, PCA9555_PORT0);
// uint16_t state_2 = pca9555_read_pins(IC2, PCA9555_PORT1);
uint16_t state = 0;
pca9555_readPins_all(IC2, &state);
pca9555_read_pins_all(IC2, &state);

// For the XD84 all cols are on the same IC and mapped sequentially
// while this technically gives 16 column reads,
Expand Down
6 changes: 3 additions & 3 deletions keyboards/xiudi/xd96/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ static uint32_t read_cols(void) {
uint8_t state_1 = 0;
uint8_t state_2 = 0;
uint8_t state_3 = 0;
pca9555_readPins(IC2, PCA9555_PORT0, &state_1);
pca9555_readPins(IC2, PCA9555_PORT1, &state_2);
pca9555_readPins(IC1, PCA9555_PORT1, &state_3);
pca9555_read_pins(IC2, PCA9555_PORT0, &state_1);
pca9555_read_pins(IC2, PCA9555_PORT1, &state_2);
pca9555_read_pins(IC1, PCA9555_PORT1, &state_3);

// For the XD96 the pins are mapped to port expanders as follows:
// all 8 pins port 0 IC2, first 6 pins port 1 IC2, first 4 pins port 1 IC1
Expand Down

0 comments on commit d0cf7b8

Please sign in to comment.