Skip to content

Commit

Permalink
cores/lcd/ssd1306: detect bus error (device NAK)
Browse files Browse the repository at this point in the history
  • Loading branch information
povauboin committed Nov 18, 2024
1 parent 436687f commit e719732
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lambdalib/cores/lcd/ssd1306.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self):
("data", 8),
])
self.source = stream.Endpoint(i2c_stream_description)
self.i2c_error = Signal()

def elaborate(self, platform):
sink = self.sink
Expand All @@ -62,7 +63,10 @@ def elaborate(self, platform):
source.valid.eq(sink.valid),
]
with m.If(source.valid & source.ready):
m.next = "CONTROL"
with m.If(self.i2c_error):
m.next = "ERROR"
with m.Else():
m.next = "CONTROL"

with m.State("CONTROL"):
m.d.comb += [
Expand All @@ -85,6 +89,13 @@ def elaborate(self, platform):
with m.If(source.valid & source.ready & source.last):
m.next = "ADDR"

with m.State("ERROR"):
# The I2C target device is not present on the bus (NAK)
# drop the sink until `last`.
m.d.comb += sink.ready.eq(1)
with m.If(sink.valid & sink.last):
m.next = "ADDR"

return m


Expand Down Expand Up @@ -132,6 +143,7 @@ def __init__(self, width, height, por_init=True):

self.sink = stream.Endpoint([("data", 8)])
self.source = stream.Endpoint(i2c_stream_description)
self.i2c_error = Signal()

def elaborate(self, platform):
sink = self.sink
Expand Down Expand Up @@ -183,6 +195,7 @@ def elaborate(self, platform):
# Instanciate the I2C address and control byte wrapper
m.submodules.wrapper = wrapper = SSD1306_Wrapper()
m.d.comb += wrapper.source.connect(source)
m.d.comb += wrapper.i2c_error.eq(self.i2c_error)

cnt = Signal(range(self._size))

Expand Down

0 comments on commit e719732

Please sign in to comment.