2015-09-22 12:36:47 -04:00
|
|
|
from migen import *
|
2013-05-16 11:43:20 -04:00
|
|
|
from migen.genlib.cdc import MultiReg
|
|
|
|
from migen.bank.description import *
|
|
|
|
|
2015-04-13 10:47:22 -04:00
|
|
|
|
2013-05-16 11:43:20 -04:00
|
|
|
class GPIOIn(Module, AutoCSR):
|
2015-04-13 10:19:55 -04:00
|
|
|
def __init__(self, signal):
|
|
|
|
self._in = CSRStatus(flen(signal))
|
|
|
|
self.specials += MultiReg(signal, self._in.status)
|
2013-05-16 11:43:20 -04:00
|
|
|
|
2015-04-13 10:47:22 -04:00
|
|
|
|
2013-05-16 11:43:20 -04:00
|
|
|
class GPIOOut(Module, AutoCSR):
|
2015-04-13 10:19:55 -04:00
|
|
|
def __init__(self, signal):
|
|
|
|
self._out = CSRStorage(flen(signal))
|
|
|
|
self.comb += signal.eq(self._out.storage)
|
2013-05-16 11:43:20 -04:00
|
|
|
|
2015-04-13 10:47:22 -04:00
|
|
|
|
2013-12-05 18:06:53 -05:00
|
|
|
class GPIOInOut(Module):
|
2015-04-13 10:19:55 -04:00
|
|
|
def __init__(self, in_signal, out_signal):
|
|
|
|
self.submodules.gpio_in = GPIOIn(in_signal)
|
|
|
|
self.submodules.gpio_out = GPIOOut(out_signal)
|
2013-12-05 18:06:53 -05:00
|
|
|
|
2015-04-13 10:19:55 -04:00
|
|
|
def get_csrs(self):
|
|
|
|
return self.gpio_in.get_csrs() + self.gpio_out.get_csrs()
|
2013-12-05 18:06:53 -05:00
|
|
|
|
2015-04-13 10:47:22 -04:00
|
|
|
|
2013-05-16 11:43:20 -04:00
|
|
|
class Blinker(Module):
|
2015-04-13 10:19:55 -04:00
|
|
|
def __init__(self, signal, divbits=26):
|
|
|
|
counter = Signal(divbits)
|
|
|
|
self.comb += signal.eq(counter[divbits-1])
|
|
|
|
self.sync += counter.eq(counter + 1)
|