2020-08-09 02:03:47 +08:00
|
|
|
from humpback import HumpbackPlatform
|
|
|
|
from migen.fhdl.module import Module
|
|
|
|
|
|
|
|
class UrukulConnector(Module):
|
|
|
|
def __init__(self, platform):
|
|
|
|
# Request EEM I/O & SPI
|
2020-08-12 17:34:50 +08:00
|
|
|
eem = platform.request("eem", 0)
|
2020-08-09 02:03:47 +08:00
|
|
|
spi = platform.request("spi")
|
2020-08-20 09:53:39 +08:00
|
|
|
led = platform.request("user_led")
|
2020-08-09 02:03:47 +08:00
|
|
|
|
|
|
|
# Assert signal length
|
|
|
|
assert len(eem.p) == 8
|
|
|
|
assert len(eem.n) == 8
|
|
|
|
assert len(spi.sclk) == 1
|
|
|
|
assert len(spi.mosi) == 1
|
|
|
|
assert len(spi.miso) == 1
|
|
|
|
assert len(spi.cs) == 3
|
|
|
|
|
2020-08-20 09:53:39 +08:00
|
|
|
# Flip positive signal as negative output, maybe only do it for FPGA outputs
|
|
|
|
# self.comb += eem.n.eq(~eem.p)
|
2020-08-09 02:03:47 +08:00
|
|
|
|
|
|
|
# Link EEM to SPI
|
|
|
|
self.comb += [
|
2020-08-20 09:53:39 +08:00
|
|
|
|
2020-08-09 02:03:47 +08:00
|
|
|
eem.p[0].eq(spi.sclk),
|
2020-08-20 09:53:39 +08:00
|
|
|
eem.n[0].eq(~spi.sclk),
|
|
|
|
|
2020-08-09 02:03:47 +08:00
|
|
|
eem.p[1].eq(spi.mosi),
|
2020-08-20 09:53:39 +08:00
|
|
|
eem.n[1].eq(~spi.mosi),
|
|
|
|
|
2020-08-09 18:46:06 +08:00
|
|
|
spi.miso.eq(eem.p[2]),
|
2020-08-20 09:53:39 +08:00
|
|
|
|
2020-08-09 02:03:47 +08:00
|
|
|
eem.p[3].eq(spi.cs[0]),
|
2020-08-20 09:53:39 +08:00
|
|
|
eem.n[3].eq(~spi.cs[0]),
|
|
|
|
|
2020-08-09 02:03:47 +08:00
|
|
|
eem.p[4].eq(spi.cs[1]),
|
2020-08-20 09:53:39 +08:00
|
|
|
eem.n[4].eq(~spi.cs[1]),
|
|
|
|
|
2020-08-09 02:03:47 +08:00
|
|
|
eem.p[5].eq(spi.cs[2]),
|
2020-08-20 09:53:39 +08:00
|
|
|
eem.n[5].eq(~spi.cs[2]),
|
|
|
|
|
|
|
|
led.eq(1)
|
2020-08-09 02:03:47 +08:00
|
|
|
]
|
|
|
|
|
2020-08-09 18:46:06 +08:00
|
|
|
# Debug purposes: Tie EEM MISO to EEM MOSI
|
2020-08-20 09:53:39 +08:00
|
|
|
# self.comb += eem.p[2].eq(eem.p[1])
|
2020-08-09 13:42:18 +08:00
|
|
|
|
2020-08-09 02:03:47 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
platform = HumpbackPlatform()
|
|
|
|
platform.build(UrukulConnector(platform))
|