expand and fix digitalIO class

This commit is contained in:
Emanuele Trabattoni
2025-07-24 13:51:21 +02:00
parent 71c7ff8756
commit 07dd200de8
12 changed files with 403 additions and 81 deletions

View File

@@ -53,6 +53,12 @@ namespace drivers
return setPort(newState);
}
const bool TCA9554PWR::toggleOut(const uint8_t channel)
{
bool value;
return readOut(channel, value) && setOut(channel, value);
}
const bool TCA9554PWR::setPort(const uint8_t state)
{
if (writeRegister(TCA9554_OUTPUT_REG, state))
@@ -61,7 +67,7 @@ namespace drivers
return false;
}
const bool TCA9554PWR::readOut(const uint8_t ch)
const bool TCA9554PWR::readOut(const uint8_t ch, bool &state)
{
uint8_t currState(0);
if (ch < DO1 || ch > DO8)
@@ -71,12 +77,13 @@ namespace drivers
}
if (!readPort(currState))
return false;
return (currState && (High >> ch));
state = (currState && (High << ch));
return true;
}
const bool TCA9554PWR::readPort(uint8_t &state)
{
if (readRegister(TCA9554_INPUT_REG, state))
if (readRegister(TCA9554_OUTPUT_REG, state))
return true;
LOG_ERROR("Unable to read IO port: state[%02x]", state);
return false;

View File

@@ -42,9 +42,10 @@ namespace drivers
~TCA9554PWR();
const bool setOut(const uint8_t channel, const bool state);
const bool toggleOut(const uint8_t channel);
const bool setPort(const uint8_t state);
const bool readOut(const uint8_t channel);
const bool readOut(const uint8_t channel, bool &state);
const bool readPort(uint8_t &state);
private: