View on Github

GPIO

GPIO driver support for hardware abstraction layer

Minimalist code

// port
rt_dev_t port;
port = gpio_port(GPIO_PORTA);
gpio_setPortConfig(port, GPIO_OUTPUT);
gpio_writePort(port, 0xA5);

// bit
rt_dev_t btn, led;
btn = gpio_pin(GPIO_PORTF, 8);
gpio_setBitConfig(btn, GPIO_INPUT | GPIO_PULLUP);

led = gpio_pin(GPIO_PORTE, 4);
gpio_setBitConfig(btn, GPIO_OUTPUT);

while (true)
{
    gpio_writeBit(led, gpio_readBit(btn));
}

API

GPIO bit access and settings

gpio_pin

rt_dev_t gpio_pin(port, pin);

Macro to choose a bit of a port

gpio_setBitConfig

int gpio_setBitConfig(rt_dev_t device, uint16_t config);

Set GPIO bit configuration (input / output / open-drain / pull-up / pull-down / change notification)

gpio_setBit

void gpio_setBit(rt_dev_t device);

Set a bit of a GPIO to 1 (HIGH)

gpio_clearBit

void gpio_clearBit(rt_dev_t device);

Set a bit of a GPIO to 0 (LOW)

gpio_toggleBit

void gpio_toggleBit(rt_dev_t device);

Toggle (invert) a bit of a GPIO from 1 to 0 or from 0 to 1

gpio_writeBit

void gpio_writeBit(rt_dev_t device, GPIO_VALUE value);

Write a specific value of a bit of a GPIO

gpio_readBit

GPIO_VALUE gpio_readBit(rt_dev_t device);

Read a bit of a GPIO

GPIO port access and settings

gpio_port

rt_dev_t gpio_port(port);

Macro to choose a whole port

gpio_setPortConfig

int gpio_setPortConfig(rt_dev_t device, uint16_t config);

Set GPIO port configuration (input / output only)

gpio_writePort

void gpio_writePort(rt_dev_t device, port_type value);

Set GPIO port value (complete port)

gpio_readPort

port_type gpio_readPort(rt_dev_t device);

Read GPIO port value (complete port)

GPIO port change handler

int gpio_setChangeHandler(rt_dev_t device, void (*handler)(GPIO_VALUE));

Add a callback to a port. If one bit of the port configured as CN positive and/or negative, handler function will be called.

Development status

Device assignation, configuration, write and read data fully functional

TODO

Supported architectures

Header file : gpio.h