test_i2c: whitespace cleanups

This commit is contained in:
Andrew Dennison 2023-09-04 11:16:49 +10:00
parent 643f3f9a93
commit 67e6614eb2
1 changed files with 17 additions and 17 deletions

View File

@ -29,11 +29,11 @@ class _MockTristateImpl(Module):
t.i_mock = Signal(reset=True) t.i_mock = Signal(reset=True)
self.comb += [ self.comb += [
If(t.oe, If(t.oe,
t.target.eq(t.o), t.target.eq(t.o),
t.i.eq(t.o), t.i.eq(t.o),
).Else( ).Else(
t.target.eq(t.i_mock), t.target.eq(t.i_mock),
t.i.eq(t.i_mock), t.i.eq(t.i_mock),
), ),
] ]
@ -68,6 +68,7 @@ class _MockTristate:
self.assertEqual((yield dut.scl_t.i), some_value) self.assertEqual((yield dut.scl_t.i), some_value)
""" """
@staticmethod @staticmethod
def lower(t): def lower(t):
return _MockTristateImpl(t) return _MockTristateImpl(t)
@ -105,14 +106,14 @@ class TestI2C(unittest.TestCase):
yield yield
def write_bit(value): def write_bit(value):
#print(f"write_bit:{value}") # print(f"write_bit:{value}")
yield from check_trans(scl=False, sda=value) yield from check_trans(scl=False, sda=value)
yield from check_trans(scl=True, sda=value) yield from check_trans(scl=True, sda=value)
def write_ack(value): def write_ack(value):
#print(f"write_ack:{value}") # print(f"write_ack:{value}")
yield from check_trans(scl=False, sda=not value) yield from check_trans(scl=False, sda=not value)
yield from check_trans(scl=True, sda=not value) yield from check_trans(scl=True, sda=not value)
yield from wait_idle() yield from wait_idle()
def read_bit(value): def read_bit(value):
@ -156,8 +157,8 @@ class TestI2C(unittest.TestCase):
def i2c_write(value, ack=True): def i2c_write(value, ack=True):
value = int(value) value = int(value)
test_bin = '{0:08b}'.format(value) test_bin = "{0:08b}".format(value)
#print(f"I2C_WRITE | {hex(value)}:0x{test_bin}") # print(f"I2C_WRITE | {hex(value)}:0x{test_bin}")
yield from dut.bus.write(I2C_XFER_ADDR, I2C_WRITE | value) yield from dut.bus.write(I2C_XFER_ADDR, I2C_WRITE | value)
for i in list(test_bin): for i in list(test_bin):
yield from write_bit(int(i)) yield from write_bit(int(i))
@ -165,31 +166,30 @@ class TestI2C(unittest.TestCase):
def i2c_read(value, ack=True): def i2c_read(value, ack=True):
value = int(value) value = int(value)
test_bin = '{0:08b}'.format(value) test_bin = "{0:08b}".format(value)
print(f"I2C_READ | {hex(value)}:0x{test_bin}") print(f"I2C_READ | {hex(value)}:0x{test_bin}")
yield from dut.bus.write(I2C_XFER_ADDR, I2C_READ | (I2C_ACK if ack else 0)) yield from dut.bus.write(I2C_XFER_ADDR, I2C_READ | (I2C_ACK if ack else 0))
for i in list(test_bin): for i in list(test_bin):
yield from read_bit(int(i)) yield from read_bit(int(i))
yield dut.sda_tristate.i_mock.eq(True) yield dut.sda_tristate.i_mock.eq(True)
data = (yield from dut.bus.read(I2C_XFER_ADDR)) & 0xff data = (yield from dut.bus.read(I2C_XFER_ADDR)) & 0xFF
self.assertEqual(data, value) self.assertEqual(data, value)
yield from write_ack(ack) yield from write_ack(ack)
def check(): def check():
yield from dut.bus.write(I2C_CONFIG_ADDR, 4) yield from dut.bus.write(I2C_CONFIG_ADDR, 4)
data = (yield from dut.bus.read(I2C_CONFIG_ADDR)) & 0xff data = (yield from dut.bus.read(I2C_CONFIG_ADDR)) & 0xFF
self.assertEqual(data, 4) self.assertEqual(data, 4)
print("write 1 byte 0x18 to address 0x41") print("write 1 byte 0x18 to address 0x41")
yield from i2c_start() yield from i2c_start()
yield from i2c_write(0x41<<1 | 0) yield from i2c_write(0x41 << 1 | 0)
yield from i2c_write(0x18, ack=False) yield from i2c_write(0x18, ack=False)
yield from i2c_stop() yield from i2c_stop()
print("read 1 byte from address 0x41") print("read 1 byte from address 0x41")
yield from i2c_start() yield from i2c_start()
yield from i2c_write(0x41<<1 | 1) yield from i2c_write(0x41 << 1 | 1)
yield from i2c_read(0x18, ack=False) yield from i2c_read(0x18, ack=False)
print("write 2 bytes 0x10 0x00 to address 0x11") print("write 2 bytes 0x10 0x00 to address 0x11")
@ -206,7 +206,7 @@ class TestI2C(unittest.TestCase):
print("read 2 bytes from address 0x55") print("read 2 bytes from address 0x55")
yield from i2c_restart() yield from i2c_restart()
yield from i2c_write(0x55<<1 | 1) yield from i2c_write(0x55 << 1 | 1)
yield from i2c_read(0xDE, ack=True) yield from i2c_read(0xDE, ack=True)
yield from i2c_read(0xAD, ack=False) yield from i2c_read(0xAD, ack=False)
yield from i2c_stop() yield from i2c_stop()