forked from M-Labs/artiq
1
0
Fork 0

test: I2C/PCA9548 unittest

This commit is contained in:
Sebastien Bourdeauducq 2016-03-05 19:01:35 +08:00
parent 36387afc12
commit 683716017b
2 changed files with 38 additions and 0 deletions

View File

@ -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):

View 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"))