From dce152b348d19505ed2fcdee1adafa8b503cd050 Mon Sep 17 00:00:00 2001 From: Andrew Dennison Date: Mon, 28 Aug 2023 14:26:59 +1000 Subject: [PATCH] soc/cores/i2c: change SDA 1 or 2 cycles earlier * update 'only change SDA when SCL is stable' to max 1 sys_clk delay --- litex/soc/cores/i2c.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/litex/soc/cores/i2c.py b/litex/soc/cores/i2c.py index 56d325cbb..4a932acc4 100644 --- a/litex/soc/cores/i2c.py +++ b/litex/soc/cores/i2c.py @@ -232,18 +232,22 @@ class I2CMaster(LiteXModule): self.sda_t = TSTriple() self.sda_tristate = self.sda_t.get_tristate(pads.sda) - self.comb += [ - self.sda_t.o.eq(0), - i2c.sda_i.eq(self.sda_t.i), - ] - # only change SDA when SCL is stable - self.scl_i_n = Signal() # previous scl_i + self.scl_i_n = Signal() # previous scl_t.i + self.sda_oe_n = Signal() # previous sda_t.oe self.sync += [ self.scl_i_n.eq(self.scl_t.i), + self.sda_oe_n.eq(self.sda_t.oe), + ] + + self.comb += [ + self.sda_t.oe.eq(self.sda_oe_n), + # only change SDA when SCL is stable If(self.scl_i_n == i2c.scl_o, self.sda_t.oe.eq(~i2c.sda_o), ), + self.sda_t.o.eq(0), + i2c.sda_i.eq(self.sda_t.i), ] # Event Manager.