Last active
June 16, 2019 14:05
-
-
Save cfelton/6119313 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is this code complete?