Fax MCP23xxx and PCF8574 last device

This commit is contained in:
Theo Arends 2024-11-17 18:02:23 +01:00
parent 4e40bbf3b6
commit f3bf8998ae
2 changed files with 8 additions and 8 deletions

View File

@ -190,11 +190,11 @@ int Pcf8574Pin(uint32_t gpio, uint32_t index = 0);
int Pcf8574Pin(uint32_t gpio, uint32_t index) { int Pcf8574Pin(uint32_t gpio, uint32_t index) {
uint16_t real_gpio = gpio << 5; uint16_t real_gpio = gpio << 5;
uint16_t mask = 0xFFE0; uint16_t mask = 0xFFE0;
if (index < GPIO_ANY) { // if (index < GPIO_ANY) {
real_gpio += index; real_gpio += index;
mask = 0xFFFF; mask = 0xFFFF;
} // }
for (uint32_t i = 0; i < Pcf8574.max_connected_ports; i++) { for (uint32_t i = 0; i <= Pcf8574.max_connected_ports; i++) {
if ((Pcf8574_pin[i] & mask) == real_gpio) { if ((Pcf8574_pin[i] & mask) == real_gpio) {
return i; // Pin number configured for gpio return i; // Pin number configured for gpio
} }
@ -208,7 +208,7 @@ bool Pcf8574PinUsed(uint32_t gpio, uint32_t index) {
} }
uint32_t Pcf8574GetPin(uint32_t lpin) { uint32_t Pcf8574GetPin(uint32_t lpin) {
if (lpin < Pcf8574.max_connected_ports) { if (lpin <= Pcf8574.max_connected_ports) {
return Pcf8574_pin[lpin]; return Pcf8574_pin[lpin];
} else { } else {
return GPIO_NONE; return GPIO_NONE;

View File

@ -430,11 +430,11 @@ int MCP23xPin(uint32_t gpio, uint32_t index = 0);
int MCP23xPin(uint32_t gpio, uint32_t index) { int MCP23xPin(uint32_t gpio, uint32_t index) {
uint16_t real_gpio = gpio << 5; uint16_t real_gpio = gpio << 5;
uint16_t mask = 0xFFE0; uint16_t mask = 0xFFE0;
if (index < GPIO_ANY) { // if (index < GPIO_ANY) {
real_gpio += index; real_gpio += index;
mask = 0xFFFF; mask = 0xFFFF;
} // }
for (uint32_t i = 0; i < Mcp23x.max_pins; i++) { for (uint32_t i = 0; i <= Mcp23x.max_pins; i++) {
if ((Mcp23x_gpio_pin[i] & mask) == real_gpio) { if ((Mcp23x_gpio_pin[i] & mask) == real_gpio) {
return i; // Pin number configured for gpio return i; // Pin number configured for gpio
} }
@ -448,7 +448,7 @@ bool MCP23xPinUsed(uint32_t gpio, uint32_t index) {
} }
uint32_t MCP23xGetPin(uint32_t lpin) { uint32_t MCP23xGetPin(uint32_t lpin) {
if (lpin < Mcp23x.max_pins) { if (lpin <= Mcp23x.max_pins) {
return Mcp23x_gpio_pin[lpin]; return Mcp23x_gpio_pin[lpin];
} else { } else {
return GPIO_NONE; return GPIO_NONE;