Fixed GPIO HAL for srf06-cc26xx

This commit is contained in:
Edvard Pettersen 2018-07-17 19:09:38 +02:00
parent 8fb9b62140
commit a18cac1e0c
3 changed files with 44 additions and 51 deletions

View File

@ -47,6 +47,18 @@
#define CONFIG_MASK (IOC_IOPULL_M | IOC_INT_M | IOC_IOMODE_OPEN_SRC_INV)
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_interrupt_enable(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
{
gpio_hal_pin_cfg_t config = gpio_hal_arch_pin_cfg_get(pin);
config &= ~GPIO_HAL_PIN_BM_INT;
config |= cfg;
gpio_hal_arch_pin_cfg_set(pin, cfg);
ti_lib_gpio_clear_event_dio(pin);
ti_lib_rom_ioc_int_enable(pin);
}
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
{
uint32_t config;
@ -56,31 +68,24 @@ gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
config = ti_lib_rom_ioc_port_configure_get(pin);
config &= ~CONFIG_MASK;
tmp = cfg & GPIO_HAL_PIN_CFG_EDGE_BOTH;
if(tmp == GPIO_HAL_PIN_CFG_EDGE_NONE) {
config |= IOC_NO_EDGE;
} else if(tmp == GPIO_HAL_PIN_CFG_EDGE_RISING) {
config |= IOC_RISING_EDGE;
} else if(tmp == GPIO_HAL_PIN_CFG_EDGE_FALLING) {
config |= IOC_FALLING_EDGE;
} else if(tmp == GPIO_HAL_PIN_CFG_EDGE_BOTH) {
config |= IOC_BOTH_EDGES;
}
tmp = cfg & GPIO_HAL_PIN_CFG_PULL_MASK;
if(tmp == GPIO_HAL_PIN_CFG_PULL_NONE) {
config |= IOC_NO_IOPULL;
} else if(tmp == GPIO_HAL_PIN_CFG_PULL_DOWN) {
config |= IOC_IOPULL_DOWN;
} else if(tmp == GPIO_HAL_PIN_CFG_PULL_UP) {
config |= IOC_IOPULL_UP;
}
tmp = cfg & GPIO_HAL_PIN_CFG_INT_MASK;
tmp = cfg & GPIO_HAL_PIN_BM_INT;
if(tmp == GPIO_HAL_PIN_CFG_INT_DISABLE) {
config |= IOC_INT_DISABLE;
} else if(tmp == GPIO_HAL_PIN_CFG_INT_ENABLE) {
config |= IOC_INT_ENABLE;
config |= (IOC_NO_EDGE | IOC_INT_DISABLE);
} else if(tmp == GPIO_HAL_PIN_CFG_INT_RISING) {
config |= (IOC_RISING_EDGE | IOC_INT_ENABLE);
} else if(tmp == GPIO_HAL_PIN_CFG_INT_FALLING) {
config |= (IOC_FALLING_EDGE | IOC_INT_ENABLE);
} else if(tmp == GPIO_HAL_PIN_CFG_INT_BOTH) {
config |= (IOC_BOTH_EDGES | IOC_INT_ENABLE);
}
tmp = cfg & GPIO_HAL_PIN_BM_INPUT;
if(tmp == GPIO_HAL_PIN_CFG_INPUT_NOPULL) {
config |= IOC_NO_IOPULL;
} else if(tmp == GPIO_HAL_PIN_CFG_INPUT_PULLDOWN) {
config |= IOC_IOPULL_DOWN;
} else if(tmp == GPIO_HAL_PIN_CFG_INPUT_PULLUP) {
config |= IOC_IOPULL_UP;
}
ti_lib_rom_ioc_port_configure_set(pin, IOC_PORT_GPIO, config);
@ -99,31 +104,27 @@ gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin)
/* Pull */
tmp = config & IOC_IOPULL_M;
if(tmp == IOC_IOPULL_UP) {
cfg |= GPIO_HAL_PIN_CFG_PULL_UP;
cfg |= GPIO_HAL_PIN_CFG_INPUT_PULLUP;
} else if(tmp == IOC_IOPULL_DOWN) {
cfg |= GPIO_HAL_PIN_CFG_PULL_DOWN;
cfg |= GPIO_HAL_PIN_CFG_INPUT_PULLDOWN;
} else if(tmp == IOC_NO_IOPULL) {
cfg |= GPIO_HAL_PIN_CFG_PULL_NONE;
cfg |= GPIO_HAL_PIN_CFG_INPUT_NOPULL;
}
/* Interrupt enable/disable */
tmp = config & IOC_INT_ENABLE;
if(tmp == IOC_INT_DISABLE) {
cfg |= GPIO_HAL_PIN_CFG_INT_DISABLE;
} else if(tmp == IOC_INT_ENABLE) {
cfg |= GPIO_HAL_PIN_CFG_INT_ENABLE;
}
/* Edge detection */
tmp = config & IOC_BOTH_EDGES;
if(tmp == IOC_NO_EDGE) {
cfg |= GPIO_HAL_PIN_CFG_EDGE_NONE;
} else if(tmp == IOC_FALLING_EDGE) {
cfg |= GPIO_HAL_PIN_CFG_EDGE_FALLING;
} else if(tmp == IOC_RISING_EDGE) {
cfg |= GPIO_HAL_PIN_CFG_EDGE_RISING;
} else if(tmp == IOC_BOTH_EDGES) {
cfg |= GPIO_HAL_PIN_CFG_EDGE_BOTH;
} else {
/* Edge detection */
tmp = config & IOC_BOTH_EDGES;
if(tmp == IOC_FALLING_EDGE) {
cfg |= GPIO_HAL_PIN_CFG_INT_FALLING;
} else if(tmp == IOC_RISING_EDGE) {
cfg |= GPIO_HAL_PIN_CFG_INT_RISING;
} else if(tmp == IOC_BOTH_EDGES) {
cfg |= GPIO_HAL_PIN_CFG_INT_BOTH;
}
}
return cfg;

View File

@ -54,7 +54,6 @@
#include <stdint.h>
/*---------------------------------------------------------------------------*/
#define gpio_hal_arch_init() do { /* do nothing */ } while (0)
#define gpio_hal_arch_interrupt_enable(p) interrupt_enable(p)
#define gpio_hal_arch_interrupt_disable(p) ti_lib_rom_ioc_int_disable(p)
#define gpio_hal_arch_pin_set_input(p) ti_lib_rom_ioc_pin_type_gpio_input(p)
@ -70,13 +69,6 @@
#define gpio_hal_arch_toggle_pins(p) ti_lib_gpio_toggle_multi_dio(p)
#define gpio_hal_arch_write_pins(p, v) ti_lib_gpio_write_multi_dio(p, v)
/*---------------------------------------------------------------------------*/
static inline void
interrupt_enable(gpio_hal_pin_t pin)
{
ti_lib_gpio_clear_event_dio(pin);
ti_lib_rom_ioc_int_enable(pin);
}
/*---------------------------------------------------------------------------*/
#endif /* GPIO_HAL_ARCH_H_ */
/*---------------------------------------------------------------------------*/
/**

View File

@ -43,11 +43,11 @@
#include "ti-lib.h"
/*---------------------------------------------------------------------------*/
BUTTON_HAL_BUTTON(key_left, "Key Left", BOARD_IOID_KEY_LEFT, \
GPIO_HAL_PIN_CFG_PULL_UP, BOARD_BUTTON_HAL_INDEX_KEY_LEFT, \
GPIO_HAL_PIN_CFG_INPUT_PULLUP, BOARD_BUTTON_HAL_INDEX_KEY_LEFT, \
true);
BUTTON_HAL_BUTTON(key_right, "Key Right", BOARD_IOID_KEY_RIGHT, \
GPIO_HAL_PIN_CFG_PULL_UP, BOARD_BUTTON_HAL_INDEX_KEY_RIGHT, \
GPIO_HAL_PIN_CFG_INPUT_PULLUP, BOARD_BUTTON_HAL_INDEX_KEY_RIGHT, \
true);
/*---------------------------------------------------------------------------*/
BUTTON_HAL_BUTTONS(&key_left, &key_right);