Hello Wayne,
Nice analyses! And you are right. There is a flaw in the acquire
function.
I think the intent of the I2C
class designer was to allow connecting I2C
slaves using various clock frequencies to the same I2C bus (have a look at this bug). One solution could be to check the associated peripheral (I2C controller) in the aquire
member function.
For example as follows:
void I2C::aquire()
{
struct i2c_s *_owner_s = I2C_S(_owner);
struct i2c_s *this_s = I2C_S(this);
lock();
if (_owner != this) {
if (_owner_s->i2c == this_s->i2c) {
i2c_frequency(&_i2c, _hz);
}
_owner = this;
}
unlock();
}
NOTE: The same flaw is present in the SPI
class.