aboutsummaryrefslogtreecommitdiff
path: root/amaranth_boards/icebreaker_bitsy.py
blob: 16c3a1c6ee007b8016149bd9d4ebc2d44a84f9e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import subprocess

from amaranth.build import *
from amaranth.vendor.lattice_ice40 import *
from .resources import *


__all__ = ["ICEBreakerBitsyPlatform"]


class ICEBreakerBitsyPlatform(LatticeICE40Platform):
    device      = "iCE40UP5K"
    package     = "SG48"
    default_clk = "clk12"
    resources   = [
        Resource("clk12", 0, Pins("35", dir="i"),
                 Clock(12e6), Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")),

        DirectUSBResource(0, d_p="42", d_n="38", pullup="37",
            attrs=Attrs(IO_STANDARD="SB_LVCMOS")),

        *SPIFlashResources(0,
            cs_n="16", clk="15", copi="14", cipo="17", wp_n="18", hold_n="19",
            attrs=Attrs(IO_STANDARD="SB_LVCMOS")
        ),

        RGBLEDResource(0, r="39", g="40", b="41", invert=True,
            attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
        *LEDResources(pins="25 6", invert=True, attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
        Resource("led_r", 0, PinsN("25", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
        Resource("led_g", 0, PinsN("6", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),

        *ButtonResources(pins="2", invert=True, attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
    ]
    connectors = [
        Connector("edge", 0,  # Pins bottom P0 - P12,
            "47 44 48 45  4  3  9 10 11 12 21 13"
            "20 25 23 27 26 28 31 32 34 36 43 46"
        )
    ]

    def toolchain_program(self, products, name, run_vid=None, run_pid=None, dfu_vid="1d50", dfu_pid="6146", reset=True):
        dfu_util = os.environ.get("DFU_UTIL", "dfu-util")

        # Construct the device runtime and DFU vid pid string
        dev_str = ""
        if run_vid or run_pid:
            dev_str = "{}:{}".format(run_vid or "", run_pid or "")
        dev_str += ",{}:{}".format(dfu_vid or "", dfu_pid or "")

        # Construct the argument list for dfu-util
        args = [dfu_util, "-d", dev_str, "-a", "0"]
        if reset: args.append("-R")
        args.append("-D")

        # Run dfu-util
        with products.extract("{}.bin".format(name)) as bitstream_filename:
            args.append(bitstream_filename)
            subprocess.check_call(args)


if __name__ == "__main__":
    from .test.blinky import *
    ICEBreakerBitsyPlatform().build(Blinky(), do_program=True)