6 #include <hal_devices/i2c_tca9548.h>
26 if (m_cb_count > 0)
return false;
27 return m_parent->
write(m_devaddr, 0, 0, 1, &mask);
32 return (m_cb_count > 0) || m_parent->
busy();
36 u8 regbytes, u32 regaddr, u8 nread,
40 if (m_cb_count >= SATCAT5_I2C_MAXCMD)
return false;
43 m_cb_queue[cb_wridx()] = callback;
44 bool ok = m_parent->
read(devaddr, regbytes, regaddr, nread,
this);
52 u8 regbytes, u32 regaddr, u8 nwrite,
const u8* data,
56 if (m_cb_count >= SATCAT5_I2C_MAXCMD)
return false;
59 m_cb_queue[cb_wridx()] = callback;
60 bool ok = m_parent->
write(devaddr, regbytes, regaddr, nwrite, data,
this);
67 void Tca9548::i2c_done(
68 bool noack,
const I2cAddr& devaddr,
69 u32 regaddr,
unsigned nread,
const u8* rdata)
73 m_cb_rdidx = modulo_add_uns(m_cb_rdidx + 1, SATCAT5_I2C_MAXCMD);
77 if (cb) cb->i2c_done(noack, devaddr, regaddr, nread, rdata);
Callback interface for cfg::I2cGeneric events.
Polymorphic API for a generic I2C interface.
virtual bool busy()=0
Is the I2C controller currently busy?
virtual bool read(const satcat5::util::I2cAddr &devaddr, u8 regbytes, u32 regaddr, u8 nread, satcat5::cfg::I2cEventListener *callback=0)=0
Add a read operation to the queue.
virtual bool write(const satcat5::util::I2cAddr &devaddr, u8 regbytes, u32 regaddr, u8 nwrite, const u8 *data, satcat5::cfg::I2cEventListener *callback=0)=0
Add a write operation to the queue.
Device driver for PCA9548A / TCA9548A I2C switches.
bool write(const satcat5::util::I2cAddr &devaddr, u8 regbytes, u32 regaddr, u8 nwrite, const u8 *data, satcat5::cfg::I2cEventListener *callback=0) override
Add a write operation to the queue.
bool select_mask(u8 mask)
Select a channel or channel(s).
bool busy() override
Is the I2C controller currently busy?
bool read(const satcat5::util::I2cAddr &devaddr, u8 regbytes, u32 regaddr, u8 nread, satcat5::cfg::I2cEventListener *callback=0) override
Add a read operation to the queue.
Conversion function for I2C device addresses.
constexpr unsigned modulo_add_uns(unsigned sum, unsigned m)
Modulo addition function.