mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 03:08:27 +08:00
test: I2C/PCA9548 unittest
This commit is contained in:
parent
36387afc12
commit
683716017b
@ -46,6 +46,19 @@ class PCA9548:
|
||||
finally:
|
||||
i2c_stop(self.busno)
|
||||
|
||||
@kernel
|
||||
def readback(self):
|
||||
i2c_init(self.busno)
|
||||
i2c_start(self.busno)
|
||||
r = 0
|
||||
try:
|
||||
if not i2c_write(self.busno, self.address | 1):
|
||||
raise I2CError("PCA9548 failed to ack address")
|
||||
r = i2c_read(self.busno, False)
|
||||
finally:
|
||||
i2c_stop(self.busno)
|
||||
return r
|
||||
|
||||
|
||||
class TCA6424A:
|
||||
def __init__(self, dmgr, busno=0, address=0x44):
|
||||
|
25
artiq/test/coredevice/test_i2c.py
Normal file
25
artiq/test/coredevice/test_i2c.py
Normal file
@ -0,0 +1,25 @@
|
||||
import os, unittest
|
||||
|
||||
from artiq.experiment import *
|
||||
from artiq.test.hardware_testbench import ExperimentCase
|
||||
|
||||
|
||||
class I2CSwitch(EnvExperiment):
|
||||
def build(self):
|
||||
self.setattr_device("core")
|
||||
self.setattr_device("i2c_switch")
|
||||
|
||||
@kernel
|
||||
def run(self):
|
||||
passed = True
|
||||
for i in range(8):
|
||||
self.i2c_switch.set(i)
|
||||
if self.i2c_switch.readback() != 1 << i:
|
||||
passed = False
|
||||
self.set_dataset("passed", passed)
|
||||
|
||||
|
||||
class I2CTest(ExperimentCase):
|
||||
def test_i2c_switch(self):
|
||||
self.execute(I2CSwitch)
|
||||
self.assertTrue(self.dataset_mgr.get("passed"))
|
Loading…
Reference in New Issue
Block a user