From f9910ab2428e79d39061cd58971a19b77523e389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Fri, 15 Jun 2018 19:35:01 +0200 Subject: [PATCH] i2c: support selecting multiple or no channels closes #1054 --- artiq/coredevice/i2c.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/artiq/coredevice/i2c.py b/artiq/coredevice/i2c.py index 92d66b8dd..44b3f9094 100644 --- a/artiq/coredevice/i2c.py +++ b/artiq/coredevice/i2c.py @@ -48,23 +48,28 @@ class PCA9548: self.address = address @kernel - def set(self, channel): - """Select one channel. + def select(self, mask): + """Enable/disable channels. - Selecting multiple channels at the same time is not supported by this - driver. - - :param channel: channel number (0-7) + :param mask: Bit mask of enabled channels """ i2c_start(self.busno) try: if not i2c_write(self.busno, self.address): raise I2CError("PCA9548 failed to ack address") - if not i2c_write(self.busno, 1 << channel): + if not i2c_write(self.busno, mask): raise I2CError("PCA9548 failed to ack control word") finally: i2c_stop(self.busno) + @kernel + def set(self, channel): + """Enable one channel. + + :param channel: channel number (0-7) + """ + self.select(1 << channel) + @kernel def readback(self): i2c_start(self.busno)