@@ -45,6 +45,7 @@ def __init__(self):
4545 ("data" , 8 ),
4646 ])
4747 self .source = stream .Endpoint (i2c_stream_description )
48+ self .i2c_error = Signal ()
4849
4950 def elaborate (self , platform ):
5051 sink = self .sink
@@ -62,7 +63,10 @@ def elaborate(self, platform):
6263 source .valid .eq (sink .valid ),
6364 ]
6465 with m .If (source .valid & source .ready ):
65- m .next = "CONTROL"
66+ with m .If (self .i2c_error ):
67+ m .next = "ERROR"
68+ with m .Else ():
69+ m .next = "CONTROL"
6670
6771 with m .State ("CONTROL" ):
6872 m .d .comb += [
@@ -85,6 +89,13 @@ def elaborate(self, platform):
8589 with m .If (source .valid & source .ready & source .last ):
8690 m .next = "ADDR"
8791
92+ with m .State ("ERROR" ):
93+ # The I2C target device is not present on the bus (NAK)
94+ # drop the sink until `last`.
95+ m .d .comb += sink .ready .eq (1 )
96+ with m .If (sink .valid & sink .last ):
97+ m .next = "ADDR"
98+
8899 return m
89100
90101
@@ -132,6 +143,7 @@ def __init__(self, width, height, por_init=True):
132143
133144 self .sink = stream .Endpoint ([("data" , 8 )])
134145 self .source = stream .Endpoint (i2c_stream_description )
146+ self .i2c_error = Signal ()
135147
136148 def elaborate (self , platform ):
137149 sink = self .sink
@@ -183,6 +195,7 @@ def elaborate(self, platform):
183195 # Instanciate the I2C address and control byte wrapper
184196 m .submodules .wrapper = wrapper = SSD1306_Wrapper ()
185197 m .d .comb += wrapper .source .connect (source )
198+ m .d .comb += wrapper .i2c_error .eq (self .i2c_error )
186199
187200 cnt = Signal (range (self ._size ))
188201
0 commit comments