2021-05-15 06:52:30 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "../../bsp/include/gpio.h"
|
|
|
|
#include "../../bsp/include/utils.h"
|
|
|
|
|
2021-08-13 01:35:56 +00:00
|
|
|
void gpio_set_mode(gpio_e gpio, gpio_mode_e mode)
|
2021-05-15 06:52:30 +00:00
|
|
|
{
|
2021-09-10 01:56:21 +00:00
|
|
|
GPIO_REG(GPIO_IO_MODE_REG_OFFSET) &= ~(0x3 << (gpio << 1));
|
|
|
|
GPIO_REG(GPIO_IO_MODE_REG_OFFSET) |= ((uint8_t)mode) << (gpio << 1);
|
2021-05-15 06:52:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 01:35:56 +00:00
|
|
|
uint8_t gpio_get_input_data(gpio_e gpio)
|
2021-05-15 06:52:30 +00:00
|
|
|
{
|
2021-08-13 01:35:56 +00:00
|
|
|
if (GPIO_REG(GPIO_DATA_REG_OFFSET) & (1 << gpio))
|
2021-05-15 06:52:30 +00:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-13 01:35:56 +00:00
|
|
|
void gpio_set_output_data(gpio_e gpio, uint8_t data)
|
2021-05-15 06:52:30 +00:00
|
|
|
{
|
|
|
|
if (data)
|
2021-08-13 01:35:56 +00:00
|
|
|
GPIO_REG(GPIO_DATA_REG_OFFSET) |= 1 << gpio;
|
|
|
|
else
|
|
|
|
GPIO_REG(GPIO_DATA_REG_OFFSET) &= ~(1 << gpio);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gpio_set_output_toggle(gpio_e gpio)
|
|
|
|
{
|
|
|
|
GPIO_REG(GPIO_DATA_REG_OFFSET) ^= 1 << gpio;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gpio_set_input_filter_enable(gpio_e gpio, uint8_t en)
|
|
|
|
{
|
|
|
|
if (en)
|
|
|
|
GPIO_REG(GPIO_FILTER_REG_OFFSET) |= 1 << gpio;
|
2021-05-15 06:52:30 +00:00
|
|
|
else
|
2021-08-13 01:35:56 +00:00
|
|
|
GPIO_REG(GPIO_FILTER_REG_OFFSET) &= ~(1 << gpio);
|
2021-05-15 06:52:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 01:35:56 +00:00
|
|
|
void gpio_set_interrupt_mode(gpio_e gpio, gpio_intr_mode_e mode)
|
2021-05-15 06:52:30 +00:00
|
|
|
{
|
2021-09-10 01:56:21 +00:00
|
|
|
GPIO_REG(GPIO_INT_MODE_REG_OFFSET) &= ~(0x3 << (gpio << 1));
|
|
|
|
GPIO_REG(GPIO_INT_MODE_REG_OFFSET) |= ((uint8_t)mode) << (gpio << 1);
|
2021-08-13 01:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gpio_clear_intr_pending(gpio_e gpio)
|
|
|
|
{
|
2021-09-10 01:56:21 +00:00
|
|
|
GPIO_REG(GPIO_INT_PENDING_REG_OFFSET) |= 1 << gpio;
|
2021-08-13 01:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t gpio_get_intr_pending(gpio_e gpio)
|
|
|
|
{
|
2021-09-10 01:56:21 +00:00
|
|
|
if (GPIO_REG(GPIO_INT_PENDING_REG_OFFSET) & (1 << gpio))
|
2021-08-13 01:35:56 +00:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
2021-05-15 06:52:30 +00:00
|
|
|
}
|