Align existing pca9555 driver to better match mcp23018 API (#16277)

This commit is contained in:
Joel Challis
2022-02-09 19:55:39 +00:00
committed by GitHub
parent 96afc7a03a
commit 1f67de2001
6 changed files with 113 additions and 62 deletions

View File

@@ -158,10 +158,12 @@ 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);
uint8_t state_1 = 0;
uint8_t state_2 = 0;
pca9555_readPins(IC2, PCA9555_PORT0, &state_1);
pca9555_readPins(IC2, PCA9555_PORT1, &state_2);
uint16_t state = ((state_1 & PORT0_COLS_MASK) << 3) | ((state_2 & PORT1_COLS_MASK));
uint16_t state = (((uint16_t)state_1 & PORT0_COLS_MASK) << 3) | (((uint16_t)state_2 & PORT1_COLS_MASK));
// A low pin indicates an active column
return (~state) & COLS_MASK;

View File

@@ -51,11 +51,14 @@ static void select_row(uint8_t row) {
static uint32_t read_cols(void) {
//Read column inputs. Pins 13-31 are used. Split across both ICs but they are sequential
uint32_t state_1 = pca9555_readPins(IC1, PCA9555_PORT1);
uint32_t state_2 = pca9555_readPins(IC2, PCA9555_PORT0);
uint32_t state_3 = pca9555_readPins(IC2, PCA9555_PORT1);
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);
uint32_t state = (((state_3 & 0b01111111) << 12) | (state_2 << 4) | ((state_1 & 0b11110000) >> 4));
uint32_t state = ((((uint32_t)state_3 & 0b01111111) << 12) | ((uint32_t)state_2 << 4) | (((uint32_t)state_1 & 0b11110000) >> 4));
return ~state;
}

View File

@@ -53,7 +53,8 @@ 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 = pca9555_readAllPins(IC2);
uint16_t state = 0;
pca9555_readPins_all(IC2, &state);
// For the XD84 all cols are on the same IC and mapped sequentially
// while this technically gives 16 column reads,

View File

@@ -50,13 +50,16 @@ static void select_row(uint8_t row) {
}
static uint32_t read_cols(void) {
uint32_t state_1 = pca9555_readPins(IC2, PCA9555_PORT0);
uint32_t state_2 = pca9555_readPins(IC2, PCA9555_PORT1);
uint32_t state_3 = pca9555_readPins(IC1, PCA9555_PORT1);
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);
// 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
uint32_t state = (((state_3 & 0b00001111) << 14) | ((state_2 & 0b00111111) << 8) | state_1);
uint32_t state = ((((uint32_t)state_3 & 0b00001111) << 14) | (((uint32_t)state_2 & 0b00111111) << 8) | (uint32_t)state_1);
return (~state) & 0b111111111111111111;
}