Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # custom board definition file
- from nmigen.build import *
- from nmigen.vendor.lattice_ice40 import *
- from nmigen_boards.resources import *
- __all__ = ["up5k_usbPlatform"]
- class up5k_usbPlatform(LatticeICE40Platform):
- device = "iCE40UP5K"
- package = "SG48"
- default_clk = "clk16"
- hfosc_div = 0
- resources = [
- Resource("clk16", 0, Pins("35", dir="i"),
- Clock(16e6), Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")),
- *LEDResources(pins="39 40 41", invert=True,
- attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
- Resource("led_g", 0, PinsN("39", dir="o"),
- Attrs(IO_STANDARD="SB_LVCMOS")),
- Resource("led_b", 0, PinsN("40", dir="o"),
- Attrs(IO_STANDARD="SB_LVCMOS")),
- Resource("led_r", 0, PinsN("41", dir="o"),
- Attrs(IO_STANDARD="SB_LVCMOS")),
- RGBLEDResource(0,
- r="39", g="40", b="41", invert=True,
- attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
- *SPIFlashResources(0,
- cs="16", clk="15", cipo="17", copi="14",
- attrs=Attrs(IO_STANDARD="SB_LVCMOS")
- ),
- ]
- connectors = [
- Connector("pmod", 0, " 6 3 48 46 - - 4 2 47 45 - -"), # PMOD J106
- Connector("pmod", 1, "42 37 34 31 - - 44 38 36 32 - -"), # PMOD J107
- Connector("pmod", 2, "27 25 21 19 - - 28 26 23 20 - -"), # PMOD J108
- ]
- --------------snip------------------
- # blink.py - blink test
- from nmigen import *
- class LEDBlinker(Elaboratable):
- def elaborate(self, platform):
- m = Module()
- half_freq = int(platform.default_clk_frequency // 2)
- timer = Signal(range(half_freq + 1))
- with m.If(timer == half_freq):
- m.d.sync += timer.eq(0)
- with m.Else():
- m.d.sync += timer.eq(timer + 1)
- if 1:
- # use the raw pins - pushes a lot of current, very bright
- led = platform.request("rgb_led", 0)
- m.d.sync += led.r.eq(timer[-1])
- m.d.sync += led.g.eq(timer[-2])
- m.d.sync += led.b.eq(timer[-3])
- else:
- # instantiate the LED driver - generates warning and doesn't blink
- m.submodules.rgbdrv = Instance("SB_RGBA_DRV",
- i_CURREN = 1,
- i_RGBLEDEN = 1,
- i_RGB0PWM = timer[-1],
- i_RGB1PWM = timer[-2],
- i_RGB2PWM = timer[-3],
- o_RGB0 = rgb0,
- o_RGB1 = rgb1,
- o_RGB2 = rgb2,
- p_CURRENT_MODE = "0b1",
- p_RGB0_CURRENT = "0b000001",
- p_RGB1_CURRENT = "0b000001",
- p_RGB2_CURRENT = "0b000011"
- )
- return m
- from up5k_usb import *
- up5k_usbPlatform().build(LEDBlinker(), do_program=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement