Exemplo n.º 1
0
Arquivo: gpio.py Projeto: splhack/loam
class Clock(GPIO):
    IO = ['I', In(Bit), "O", Out(Bit)]

    def __init__(self, fpga, name):
        GPIO.__init__(self, fpga, name)
Exemplo n.º 2
0
class Joystick(Part):
    name = 'joystick'

    IO = [
        "SELECT",
        Out(Bit), "UP",
        Out(Bit), "DOWN",
        Out(Bit), "LEFT",
        Out(Bit), "RIGHT",
        Out(Bit)
    ]

    def __init__(self, name='Joystick', board=None):
        super(Joystick, self).__init__(name, board)

        self.select = True
        self.up = False
        self.down = False
        self.left = False
        self.right = False

        self.debounce = False

    def init(self,
             select=None,
             up=None,
             down=None,
             left=None,
             right=None,
             debounce=None):

        if select is not None:
            self.select = select
        if up is not None:
            self.up = up
        if down is not None:
            self.down = down
        if left is not None:
            self.left = left
        if right is not None:
            self.right = right
        if debounce is not None:
            self.debounce = debounce
        return self

    def on(self):

        if self.select:
            gpio = self.SELECT.getgpio()
            gpio.input().on()
        if self.up:
            gpio = self.UP.getgpio()
            gpio.input().on()
        if self.down:
            gpio = self.DOWN.getgpio()
            gpio.input().on()
        if self.left:
            gpio = self.LEFT.getgpio()
            gpio.input().on()
        if self.right:
            gpio = self.RIGHT.getgpio()
            gpio.input().on()

        Part.on(self)
        return self

    # need to turn on parts ...
    def setup(self, main):
        return

        if self.debounce:
            slow = Counter(16)
            if hasattr(main, 'SELECT'):
                main.SELECT = falling(debounce(main.SELECT, slow.COUT))
            if hasattr(main, 'UP'):
                main.UP = falling(debounce(main.UP, slow.COUT))
            if hasattr(main, 'DOWN'):
                main.DOWN = falling(debounce(main.DOWN, slow.COUT))
            if hasattr(main, 'LEFT'):
                main.LEFT = falling(debounce(main.LEFT, slow.COUT))
            if hasattr(main, 'RIGHT'):
                main.RIGHT = falling(debounce(main.RIGHT, slow.COUT))
Exemplo n.º 3
0
class USART(Peripheral):
    name = 'usart'
    IO = ["RX", In(Bit), "TX", Out(Bit)]

    def __init__(self, fpga, name='usart0'):
        super(USART,self).__init__(fpga, name)
Exemplo n.º 4
0
from magma import DefineCircuit, EndCircuit, In, Out, Bit, Clock

__all__ = ['DFF', 'FF']

_DFF = DefineCircuit('DFF', "D", In(Bit), "CLK", In(Clock), "Q", Out(Bit))
_DFF.verilog = '''\
    always @(posedge CLK) begin
        Q <= D;
    end'''
EndCircuit()


def DFF(init=0, has_ce=False, has_reset=False, has_set=False):
    ff = _DFF()

    #args = ['I', ff.D, 'CLK', ff.CLK]
    #if has_ce:
    #    args += ['CE', ff.E]
    #if has_reset:
    #    args += ['RESET', ff.R]
    #if has_set:
    #    args += ['SET', ff.S]
    #args += ['O', ff.Q]
    #return AnonymousCircuit(args)

    return ff


FF = DFF