From 71cc2db867263c63497344795a0f50f875cf3941 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 16 May 2013 17:43:20 +0200 Subject: [PATCH] Add GPIO buttons and LEDs --- milkymist/gpio/__init__.py | 20 ++++++++++++++++++++ top.py | 7 ++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 milkymist/gpio/__init__.py diff --git a/milkymist/gpio/__init__.py b/milkymist/gpio/__init__.py new file mode 100644 index 00000000..f2ac9abe --- /dev/null +++ b/milkymist/gpio/__init__.py @@ -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 4b8c4b87..3ea99a6f 100644 --- 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]) -- 2.30.2