Exemplo n.º 1
0
void setup_gpio(int gpio, int direction, int pud)
{
    int shift = GETPINPOSITION(gpio);

    set_pullupdn(gpio, pud);
    if (direction == OUTPUT)
        *(gpio_map+GETMODULEOFFSET(PIO_OER, gpio)) = shift;
    else  // direction == INPUT
        *(gpio_map+GETMODULEOFFSET(PIO_ODR, gpio)) = shift;
}
Exemplo n.º 2
0
// Sets a GPIO to either output or input (input can have an optional pullup
// or -down resistor).
void
setup_gpio(int gpio, int direction, int pud)
{
    int offset = OFFSET_FSEL + (gpio/10);
    int shift = (gpio%10)*3;

    set_pullupdn(gpio, pud);
    if (direction == OUTPUT)
        *(gpio_map+offset) = (*(gpio_map+offset) & ~(7<<shift)) | (1<<shift);
    else if (direction == ALT0)
        *(gpio_map+offset) = (*(gpio_map+offset) & ~(7<<shift)) | (4<<shift);
    else  // direction == INPUT
        *(gpio_map+offset) = (*(gpio_map+offset) & ~(7<<shift));
}
Exemplo n.º 3
0
// python function output(channel, value) without direction check
static PyObject*
py_set_pullupdn(PyObject *self, PyObject *args, PyObject *kwargs)
{
    int gpio, channel;
    int pud = PUD_OFF;

    static char *kwlist[] = {"channel", "pull_up_down", NULL};
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|ii", kwlist, &channel, &pud))
        return NULL;

    if ((gpio = channel_to_gpio(channel)) < 0)
        return NULL;

    // printf("Setting gpio %d PULLUPDN to %d", gpio, pud);
    set_pullupdn(gpio, pud);

    Py_INCREF(Py_None);
    return Py_None;
}