Add GPIO buttons and LEDs
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 16 May 2013 15:43:20 +0000 (17:43 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 16 May 2013 15:43:20 +0000 (17:43 +0200)
milkymist/gpio/__init__.py [new file with mode: 0644]
top.py

diff --git a/milkymist/gpio/__init__.py b/milkymist/gpio/__init__.py
new file mode 100644 (file)
index 0000000..f2ac9ab
--- /dev/null
@@ -0,0 +1,20 @@
+from migen.fhdl.structure import *
+from migen.fhdl.module import Module
+from migen.genlib.cdc import MultiReg
+from migen.bank.description import *
+
+class GPIOIn(Module, AutoCSR):
+       def __init__(self, signal):
+               self._r_in = CSRStatus(len(signal))
+               self.specials += MultiReg(signal, self._r_in.status)
+
+class GPIOOut(Module, AutoCSR):
+       def __init__(self, signal):
+               self._r_out = CSRStorage(len(signal))
+               self.comb += signal.eq(self._r_out.storage)
+
+class Blinker(Module):
+       def __init__(self, signal, divbits=26):
+               counter = Signal(divbits)
+               self.comb += signal.eq(counter[divbits-1])
+               self.sync += counter.eq(counter + 1)
diff --git a/top.py b/top.py
index 4b8c4b8736c5f4b4e43e389b3f0855455e293f42..3ea99a6f92aa6155b16522ea85a2a62ae83fb75b 100644 (file)
--- a/top.py
+++ b/top.py
@@ -8,7 +8,8 @@ from migen.bus import wishbone, wishbone2asmi, csr, wishbone2csr, dfi
 from migen.bank import csrgen
 
 from milkymist import m1crg, lm32, norflash, uart, s6ddrphy, dfii, asmicon, \
-       identifier, timer, minimac3, framebuffer, asmiprobe, dvisampler, counteradc
+       identifier, timer, minimac3, framebuffer, asmiprobe, dvisampler, \
+       counteradc, gpio
 from cif import get_macros
 
 version = get_macros("common/version.h")["VERSION"][1:-1]
@@ -78,6 +79,8 @@ class SoC(Module):
                "dvisampler1":                  10,
                "dvisampler1_edid_mem": 11,
                "pots":                                 12,
+               "buttons":                              13,
+               "leds":                                 14
        }
 
        interrupt_map = {
@@ -152,6 +155,8 @@ class SoC(Module):
                pots_pads = platform.request("dvi_pots")
                self.submodules.pots = counteradc.CounterADC(pots_pads.charge,
                        [pots_pads.blackout, pots_pads.crossfade])
+               self.submodules.buttons = gpio.GPIOIn(Cat(platform.request("user_btn", 0), platform.request("user_btn", 2)))
+               self.submodules.leds = gpio.GPIOOut(Cat(*[platform.request("user_led", i) for i in range(2)]))
 
                self.submodules.csrbankarray = csrgen.BankArray(self,
                        lambda name, memory: self.csr_map[name if memory is None else name + "_" + memory.name_override])