Reorganize resource taxonomy.
[nmigen-boards.git] / nmigen_boards / icestick.py
1 import os
2 import subprocess
3
4 from nmigen.build import *
5 from nmigen.vendor.lattice_ice40 import *
6 from .resources import *
7
8
9 __all__ = ["ICEStickPlatform"]
10
11
12 class ICEStickPlatform(LatticeICE40Platform):
13 device = "iCE40HX1K"
14 package = "TQ144"
15 default_clk = "clk12"
16 resources = [
17 Resource("clk12", 0, Pins("21", dir="i"),
18 Clock(12e6), Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")),
19
20 *LEDResources(pins="99 98 97 96 95", attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
21
22 UARTResource(0,
23 rx="9", tx="8", rts="7", cts="4", dtr="3", dsr="2", dcd="1",
24 attrs=Attrs(IO_STANDARD="SB_LVTTL", PULLUP=1)
25 ),
26
27 IrDAResource(0,
28 rx="106", tx="105", sd="107",
29 attrs=Attrs(IO_STANDARD="SB_LVCMOS")
30 ),
31
32 *SPIFlashResources(0,
33 cs="71", clk="70", mosi="67", miso="68",
34 attrs=Attrs(IO_STANDARD="SB_LVCMOS")
35 ),
36 ]
37 connectors = [
38 Connector("pmod", 0, "78 79 80 81 - - 87 88 90 91 - -"), # J2
39
40 Connector("j", 1, "- - 112 113 114 115 116 117 118 119"), # J1
41 Connector("j", 3, "- - 62 61 60 56 48 47 45 44"), # J3
42 ]
43
44 def toolchain_program(self, products, name):
45 iceprog = os.environ.get("ICEPROG", "iceprog")
46 with products.extract("{}.bin".format(name)) as bitstream_filename:
47 subprocess.check_call([iceprog, bitstream_filename])
48
49
50 if __name__ == "__main__":
51 from .test.blinky import *
52 ICEStickPlatform().build(Blinky(), do_program=True)