From 2b918ac6f726c9ecc1143584ed72ef10bd1cbd01 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 25 Feb 2022 19:01:14 +0800 Subject: [PATCH] coredevice: merge pcf8574a into i2c --- artiq/coredevice/i2c.py | 43 ++++++++++++++++++++++++ artiq/coredevice/pcf8574a.py | 47 --------------------------- doc/manual/core_drivers_reference.rst | 7 ---- 3 files changed, 43 insertions(+), 54 deletions(-) delete mode 100644 artiq/coredevice/pcf8574a.py diff --git a/artiq/coredevice/i2c.py b/artiq/coredevice/i2c.py index 61be474e4..3608f4dc8 100644 --- a/artiq/coredevice/i2c.py +++ b/artiq/coredevice/i2c.py @@ -207,3 +207,46 @@ class TCA6424A: self._write24(0x8c, 0) # set all directions to output self._write24(0x84, outputs_le) # set levels + +class PCF8574A: + """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 = busno + self.address = address + + @kernel + def set(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: + if not i2c_write(self.busno, self.address): + raise I2CError("PCF8574A failed to ack address") + if not i2c_write(self.busno, data): + raise I2CError("PCF8574A failed to ack data") + finally: + i2c_stop(self.busno) + + @kernel + def get(self): + """Retrieve quasi-bidirectional pin input data. + + :return: Pin data + """ + i2c_start(self.busno) + ret = 0 + try: + if not i2c_write(self.busno, self.address | 1): + raise I2CError("PCF8574A failed to ack address") + ret = i2c_read(self.busno, False) + finally: + i2c_stop(self.busno) + return ret diff --git a/artiq/coredevice/pcf8574a.py b/artiq/coredevice/pcf8574a.py deleted file mode 100644 index ed11cc311..000000000 --- a/artiq/coredevice/pcf8574a.py +++ /dev/null @@ -1,47 +0,0 @@ -from artiq.experiment import kernel -from artiq.coredevice.i2c import ( - i2c_start, i2c_write, i2c_read, i2c_stop, I2CError) - - -class PCF8574A: - """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 = busno - self.address = address - - @kernel - def set(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: - if not i2c_write(self.busno, self.address): - raise I2CError("PCF8574A failed to ack address") - if not i2c_write(self.busno, data): - raise I2CError("PCF8574A failed to ack data") - finally: - i2c_stop(self.busno) - - @kernel - def get(self): - """Retrieve quasi-bidirectional pin input data. - - :return: Pin data - """ - i2c_start(self.busno) - ret = 0 - try: - if not i2c_write(self.busno, self.address | 1): - raise I2CError("PCF8574A failed to ack address") - ret = i2c_read(self.busno, False) - finally: - i2c_stop(self.busno) - return ret diff --git a/doc/manual/core_drivers_reference.rst b/doc/manual/core_drivers_reference.rst index 0fc5a8e8f..175039862 100644 --- a/doc/manual/core_drivers_reference.rst +++ b/doc/manual/core_drivers_reference.rst @@ -65,13 +65,6 @@ Digital I/O drivers .. automodule:: artiq.coredevice.i2c :members: -:mod:`artiq.coredevice.pcf8574a` module -+++++++++++++++++++++++++++++++++++++++ - -.. automodule:: artiq.coredevice.pcf8574a - :members: - - RF generation drivers ---------------------