Skip to content

Instantly share code, notes, and snippets.

@cfelton
Last active June 16, 2019 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfelton/6119313 to your computer and use it in GitHub Desktop.
Save cfelton/6119313 to your computer and use it in GitHub Desktop.
from myhdl import *
def top(sda, scl, sda_i, sda_o, scl_i, scl_o):
"""Simple I2C bi-dir converter.
This example will break the I2C bi-directional signals into
uni-dir explicit signals.
"""
sda_d = sda.driver()
scl_d = scl.driver()
@always_comb
def hdl():
sda_i.next = sda
sda_d.next = False if not sda_o else None
scl_i.next = scl
scl_d.next = False if not scl_o else None
return hdl
def convert():
clk = Signal(False)
rst = Signal(False)
sda = TristateSignal(True)
scl = TristateSignal(True)
sda_i = Signal(False)
sda_o = Signal(False)
scl_i = Signal(False)
scl_o = Signal(False)
toVerilog(top, sda, scl, sda_i, sda_o, scl_i, scl_o)
toVHDL(top, sda, scl, sda_i, sda_o, scl_i, scl_o)
if __name__ == '__main__':
convert()
@raaees
Copy link

raaees commented Jun 16, 2019

please some explain this code?

@raaees
Copy link

raaees commented Jun 16, 2019

is this code complete?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment