GPIO driver support for hardware abstraction layer
// 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));
}
rt_dev_t gpio_pin(port, pin);
Macro to choose a bit of a port
int gpio_setBitConfig(rt_dev_t device, uint16_t config);
Set GPIO bit configuration (input / output / open-drain / pull-up / pull-down / change notification)
void gpio_setBit(rt_dev_t device);
Set a bit of a GPIO to 1 (HIGH)
void gpio_clearBit(rt_dev_t device);
Set a bit of a GPIO to 0 (LOW)
void gpio_toggleBit(rt_dev_t device);
Toggle (invert) a bit of a GPIO from 1 to 0 or from 0 to 1
void gpio_writeBit(rt_dev_t device, GPIO_VALUE value);
Write a specific value of a bit of a GPIO
GPIO_VALUE gpio_readBit(rt_dev_t device);
Read a bit of a GPIO
rt_dev_t gpio_port(port);
Macro to choose a whole port
int gpio_setPortConfig(rt_dev_t device, uint16_t config);
Set GPIO port configuration (input / output only)
void gpio_writePort(rt_dev_t device, port_type value);
Set GPIO port value (complete port)
port_type gpio_readPort(rt_dev_t device);
Read GPIO port value (complete port)
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.
Device assignation, configuration, write and read data fully functional
Header file : gpio.h