[docs]classPCF8574A:"""Driver for the PCF8574 I2C remote 8-bit I/O expander. I2C transactions not real-time, and are performed by the CPU without involving RTIO. """def__init__(self,dmgr,busno=0,address=0x7c,core_device="core"):self.core=dmgr.get(core_device)self.busno=busnoself.address=address@kernel
[docs]defset(self,data):"""Drive data on the quasi-bidirectional pins. :param data: Pin data. High bits are weakly driven high (and thus inputs), low bits are strongly driven low. """i2c_start(self.busno)try:ifnoti2c_write(self.busno,self.address):raiseI2CError("PCF8574A failed to ack address")ifnoti2c_write(self.busno,data):raiseI2CError("PCF8574A failed to ack data")finally:i2c_stop(self.busno)
@kernel
[docs]defget(self):"""Retrieve quasi-bidirectional pin input data. :return: Pin data """i2c_start(self.busno)ret=0try:ifnoti2c_write(self.busno,self.address|1):raiseI2CError("PCF8574A failed to ack address")ret=i2c_read(self.busno,False)finally:i2c_stop(self.busno)returnret