mirror of
https://github.com/arendst/Tasmota.git
synced 2025-08-05 17:07:42 +00:00
Prep for I2C Active control
Prep for I2C Active control
This commit is contained in:
parent
55ab9639e6
commit
702df2b29f
@ -1264,6 +1264,7 @@ void SetNextTimeInterval(unsigned long& timer, const unsigned long step)
|
|||||||
#ifdef USE_I2C
|
#ifdef USE_I2C
|
||||||
const uint8_t I2C_RETRY_COUNTER = 3;
|
const uint8_t I2C_RETRY_COUNTER = 3;
|
||||||
|
|
||||||
|
uint32_t i2c_active[4] = { 0 };
|
||||||
uint32_t i2c_buffer = 0;
|
uint32_t i2c_buffer = 0;
|
||||||
|
|
||||||
bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size)
|
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)
|
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++) {
|
for (uint8_t address = 1; address <= 127; address++) {
|
||||||
Wire.beginTransmission(address);
|
Wire.beginTransmission(address);
|
||||||
if (!Wire.endTransmission() && (address == addr)) {
|
if (!Wire.endTransmission() && (address == addr)) {
|
||||||
return true;
|
return true; // Report as present;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user