@@ -45,6 +45,7 @@ def __init__(self):
45
45
("data" , 8 ),
46
46
])
47
47
self .source = stream .Endpoint (i2c_stream_description )
48
+ self .i2c_error = Signal ()
48
49
49
50
def elaborate (self , platform ):
50
51
sink = self .sink
@@ -62,7 +63,10 @@ def elaborate(self, platform):
62
63
source .valid .eq (sink .valid ),
63
64
]
64
65
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"
66
70
67
71
with m .State ("CONTROL" ):
68
72
m .d .comb += [
@@ -85,6 +89,13 @@ def elaborate(self, platform):
85
89
with m .If (source .valid & source .ready & source .last ):
86
90
m .next = "ADDR"
87
91
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
+
88
99
return m
89
100
90
101
@@ -132,6 +143,7 @@ def __init__(self, width, height, por_init=True):
132
143
133
144
self .sink = stream .Endpoint ([("data" , 8 )])
134
145
self .source = stream .Endpoint (i2c_stream_description )
146
+ self .i2c_error = Signal ()
135
147
136
148
def elaborate (self , platform ):
137
149
sink = self .sink
@@ -183,6 +195,7 @@ def elaborate(self, platform):
183
195
# Instanciate the I2C address and control byte wrapper
184
196
m .submodules .wrapper = wrapper = SSD1306_Wrapper ()
185
197
m .d .comb += wrapper .source .connect (source )
198
+ m .d .comb += wrapper .i2c_error .eq (self .i2c_error )
186
199
187
200
cnt = Signal (range (self ._size ))
188
201
0 commit comments