Prep for I2C Active control

Prep for I2C Active control
This commit is contained in:
Theo Arends 2019-09-29 11:52:22 +02:00
parent 55ab9639e6
commit 702df2b29f

View File

@ -1264,6 +1264,7 @@ void SetNextTimeInterval(unsigned long& timer, const unsigned long step)
#ifdef USE_I2C
const uint8_t I2C_RETRY_COUNTER = 3;
uint32_t i2c_active[4] = { 0 };
uint32_t i2c_buffer = 0;
bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size)
@ -1457,12 +1458,35 @@ void I2cScan(char *devs, unsigned int devs_len)
}
}
void I2cSetActive(uint32_t addr, uint32_t count = 1)
{
addr &= 0x7F;
count &= 0x7F;
while (count-- && (addr < 128)) {
i2c_active[addr / 32] |= (1 << (addr % 32));
addr++;
}
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("I2C: Active %08X,%08X,%08X,%08X"), i2c_active[0], i2c_active[1], i2c_active[2], i2c_active[3]);
}
bool I2cActive(uint32_t addr)
{
addr &= 0x7F;
if (i2c_active[addr / 32] & (1 << (addr % 32))) {
return true;
}
return false;
}
bool I2cDevice(uint8_t addr)
{
if (I2cActive(addr)) {
return false; // If already active report as not present;
}
for (uint8_t address = 1; address <= 127; address++) {
Wire.beginTransmission(address);
if (!Wire.endTransmission() && (address == addr)) {
return true;
return true; // Report as present;
}
}
return false;