Advertisement
Guest User

Untitled

a guest
Jul 20th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. # custom board definition file
  2. from nmigen.build import *
  3. from nmigen.vendor.lattice_ice40 import *
  4. from nmigen_boards.resources import *
  5.  
  6.  
  7. __all__ = ["up5k_usbPlatform"]
  8.  
  9.  
  10. class up5k_usbPlatform(LatticeICE40Platform):
  11. device = "iCE40UP5K"
  12. package = "SG48"
  13. default_clk = "clk16"
  14. hfosc_div = 0
  15. resources = [
  16. Resource("clk16", 0, Pins("35", dir="i"),
  17. Clock(16e6), Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")),
  18. *LEDResources(pins="39 40 41", invert=True,
  19. attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
  20. Resource("led_g", 0, PinsN("39", dir="o"),
  21. Attrs(IO_STANDARD="SB_LVCMOS")),
  22. Resource("led_b", 0, PinsN("40", dir="o"),
  23. Attrs(IO_STANDARD="SB_LVCMOS")),
  24. Resource("led_r", 0, PinsN("41", dir="o"),
  25. Attrs(IO_STANDARD="SB_LVCMOS")),
  26. RGBLEDResource(0,
  27. r="39", g="40", b="41", invert=True,
  28. attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
  29.  
  30.  
  31. *SPIFlashResources(0,
  32. cs="16", clk="15", cipo="17", copi="14",
  33. attrs=Attrs(IO_STANDARD="SB_LVCMOS")
  34. ),
  35. ]
  36. connectors = [
  37. Connector("pmod", 0, " 6 3 48 46 - - 4 2 47 45 - -"), # PMOD J106
  38. Connector("pmod", 1, "42 37 34 31 - - 44 38 36 32 - -"), # PMOD J107
  39. Connector("pmod", 2, "27 25 21 19 - - 28 26 23 20 - -"), # PMOD J108
  40. ]
  41.  
  42. --------------snip------------------
  43.  
  44. # blink.py - blink test
  45. from nmigen import *
  46.  
  47.  
  48. class LEDBlinker(Elaboratable):
  49. def elaborate(self, platform):
  50. m = Module()
  51.  
  52. half_freq = int(platform.default_clk_frequency // 2)
  53. timer = Signal(range(half_freq + 1))
  54.  
  55. with m.If(timer == half_freq):
  56. m.d.sync += timer.eq(0)
  57. with m.Else():
  58. m.d.sync += timer.eq(timer + 1)
  59.  
  60. if 1:
  61. # use the raw pins - pushes a lot of current, very bright
  62. led = platform.request("rgb_led", 0)
  63. m.d.sync += led.r.eq(timer[-1])
  64. m.d.sync += led.g.eq(timer[-2])
  65. m.d.sync += led.b.eq(timer[-3])
  66. else:
  67. # instantiate the LED driver - generates warning and doesn't blink
  68. m.submodules.rgbdrv = Instance("SB_RGBA_DRV",
  69. i_CURREN = 1,
  70. i_RGBLEDEN = 1,
  71. i_RGB0PWM = timer[-1],
  72. i_RGB1PWM = timer[-2],
  73. i_RGB2PWM = timer[-3],
  74. o_RGB0 = rgb0,
  75. o_RGB1 = rgb1,
  76. o_RGB2 = rgb2,
  77. p_CURRENT_MODE = "0b1",
  78. p_RGB0_CURRENT = "0b000001",
  79. p_RGB1_CURRENT = "0b000001",
  80. p_RGB2_CURRENT = "0b000011"
  81. )
  82.  
  83. return m
  84.  
  85. from up5k_usb import *
  86. up5k_usbPlatform().build(LEDBlinker(), do_program=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement