Skip to content
Snippets Groups Projects
Unverified Commit 5c9785a7 authored by George Oikonomou's avatar George Oikonomou Committed by GitHub
Browse files

Merge branch 'develop' into bugfix/zoul-pm

parents 58ab4c0e ff709d29
Branches
Tags
No related merge requests found
Showing
with 831 additions and 169 deletions
...@@ -69,8 +69,10 @@ ...@@ -69,8 +69,10 @@
#define MUTEX_CONF_ARCH_HEADER_PATH "mutex-cortex.h" #define MUTEX_CONF_ARCH_HEADER_PATH "mutex-cortex.h"
#define ATOMIC_CONF_ARCH_HEADER_PATH "atomic-cortex.h" #define ATOMIC_CONF_ARCH_HEADER_PATH "atomic-cortex.h"
#define MEMORY_BARRIER_CONF_ARCH_HEADER_PATH "memory-barrier-cortex.h" #define MEMORY_BARRIER_CONF_ARCH_HEADER_PATH "memory-barrier-cortex.h"
/*---------------------------------------------------------------------------*/
#define GPIO_HAL_CONF_ARCH_HDR_PATH "dev/gpio-hal-arch.h" #define GPIO_HAL_CONF_ARCH_HDR_PATH "dev/gpio-hal-arch.h"
#define GPIO_HAL_CONF_ARCH_SW_TOGGLE 1
#define GPIO_HAL_CONF_PORT_PIN_NUMBERING 0
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#endif /* CC2538_DEF_H_ */ #endif /* CC2538_DEF_H_ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
#include <stdint.h> #include <stdint.h>
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) gpio_hal_arch_no_port_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
{ {
uint8_t port, pin_num, pin_mask; uint8_t port, pin_num, pin_mask;
uint32_t port_base; uint32_t port_base;
...@@ -94,7 +94,7 @@ gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) ...@@ -94,7 +94,7 @@ gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
gpio_hal_pin_cfg_t gpio_hal_pin_cfg_t
gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin) gpio_hal_arch_no_port_pin_cfg_get(gpio_hal_pin_t pin)
{ {
uint8_t port, pin_num, pin_mask; uint8_t port, pin_num, pin_mask;
uint32_t port_base; uint32_t port_base;
...@@ -145,17 +145,17 @@ gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin) ...@@ -145,17 +145,17 @@ gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_write_pin(gpio_hal_pin_t pin, uint8_t value) gpio_hal_arch_no_port_write_pin(gpio_hal_pin_t pin, uint8_t value)
{ {
if(value == 1) { if(value == 1) {
gpio_hal_arch_set_pin(pin); gpio_hal_arch_set_pin(GPIO_HAL_NULL_PORT, pin);
return; return;
} }
gpio_hal_arch_clear_pin(pin); gpio_hal_arch_clear_pin(GPIO_HAL_NULL_PORT, pin);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_set_pins(gpio_hal_pin_mask_t pins) gpio_hal_arch_no_port_set_pins(gpio_hal_pin_mask_t pins)
{ {
GPIO_SET_PIN(GPIO_A_BASE, pins & 0xFF); GPIO_SET_PIN(GPIO_A_BASE, pins & 0xFF);
GPIO_SET_PIN(GPIO_B_BASE, (pins >> 8) & 0xFF); GPIO_SET_PIN(GPIO_B_BASE, (pins >> 8) & 0xFF);
...@@ -164,7 +164,7 @@ gpio_hal_arch_set_pins(gpio_hal_pin_mask_t pins) ...@@ -164,7 +164,7 @@ gpio_hal_arch_set_pins(gpio_hal_pin_mask_t pins)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_clear_pins(gpio_hal_pin_mask_t pins) gpio_hal_arch_no_port_clear_pins(gpio_hal_pin_mask_t pins)
{ {
GPIO_CLR_PIN(GPIO_A_BASE, pins & 0xFF); GPIO_CLR_PIN(GPIO_A_BASE, pins & 0xFF);
GPIO_CLR_PIN(GPIO_B_BASE, (pins >> 8) & 0xFF); GPIO_CLR_PIN(GPIO_B_BASE, (pins >> 8) & 0xFF);
...@@ -173,7 +173,7 @@ gpio_hal_arch_clear_pins(gpio_hal_pin_mask_t pins) ...@@ -173,7 +173,7 @@ gpio_hal_arch_clear_pins(gpio_hal_pin_mask_t pins)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
gpio_hal_pin_mask_t gpio_hal_pin_mask_t
gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins) gpio_hal_arch_no_port_read_pins(gpio_hal_pin_mask_t pins)
{ {
gpio_hal_pin_mask_t rv = 0; gpio_hal_pin_mask_t rv = 0;
...@@ -186,7 +186,8 @@ gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins) ...@@ -186,7 +186,8 @@ gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_write_pins(gpio_hal_pin_mask_t pins, gpio_hal_pin_mask_t value) gpio_hal_arch_no_port_write_pins(gpio_hal_pin_mask_t pins,
gpio_hal_pin_mask_t value)
{ {
GPIO_WRITE_PIN(GPIO_A_BASE, pins & 0xFF, value & 0xFF); GPIO_WRITE_PIN(GPIO_A_BASE, pins & 0xFF, value & 0xFF);
GPIO_WRITE_PIN(GPIO_B_BASE, (pins >> 8) & 0xFF, (value >> 8) & 0xFF); GPIO_WRITE_PIN(GPIO_B_BASE, (pins >> 8) & 0xFF, (value >> 8) & 0xFF);
......
...@@ -58,31 +58,31 @@ ...@@ -58,31 +58,31 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define gpio_hal_arch_init() do { /* Do nothing */ } while(0) #define gpio_hal_arch_init() do { /* Do nothing */ } while(0)
#define gpio_hal_arch_interrupt_enable(p) do { \ #define gpio_hal_arch_interrupt_enable(port, p) do { \
GPIO_ENABLE_INTERRUPT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \ GPIO_ENABLE_INTERRUPT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
NVIC_EnableIRQ(PIN_TO_PORT(p)); \ NVIC_EnableIRQ(PIN_TO_PORT(p)); \
} while(0); } while(0);
#define gpio_hal_arch_interrupt_disable(p) \ #define gpio_hal_arch_interrupt_disable(port, p) \
GPIO_DISABLE_INTERRUPT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)) GPIO_DISABLE_INTERRUPT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8))
#define gpio_hal_arch_pin_set_input(p) do { \ #define gpio_hal_arch_pin_set_input(port, p) do { \
GPIO_SOFTWARE_CONTROL(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \ GPIO_SOFTWARE_CONTROL(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
GPIO_SET_INPUT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \ GPIO_SET_INPUT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
} while(0); } while(0);
#define gpio_hal_arch_pin_set_output(p) do { \ #define gpio_hal_arch_pin_set_output(port, p) do { \
GPIO_SOFTWARE_CONTROL(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \ GPIO_SOFTWARE_CONTROL(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
GPIO_SET_OUTPUT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \ GPIO_SET_OUTPUT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
} while(0); } while(0);
#define gpio_hal_arch_set_pin(p) \ #define gpio_hal_arch_set_pin(port, p) \
GPIO_SET_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)) GPIO_SET_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8))
#define gpio_hal_arch_clear_pin(p) \ #define gpio_hal_arch_clear_pin(port, p) \
GPIO_CLR_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)) GPIO_CLR_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8))
#define gpio_hal_arch_read_pin(p) \ #define gpio_hal_arch_read_pin(port, p) \
(GPIO_READ_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)) == 0 ? 0 : 1) (GPIO_READ_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)) == 0 ? 0 : 1)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#endif /* GPIO_HAL_ARCH_H_ */ #endif /* GPIO_HAL_ARCH_H_ */
......
...@@ -137,10 +137,10 @@ ...@@ -137,10 +137,10 @@
#define MUTEX_CONF_ARCH_HEADER_PATH "mutex-cortex.h" #define MUTEX_CONF_ARCH_HEADER_PATH "mutex-cortex.h"
#define ATOMIC_CONF_ARCH_HEADER_PATH "atomic-cortex.h" #define ATOMIC_CONF_ARCH_HEADER_PATH "atomic-cortex.h"
#define MEMORY_BARRIER_CONF_ARCH_HEADER_PATH "memory-barrier-cortex.h" #define MEMORY_BARRIER_CONF_ARCH_HEADER_PATH "memory-barrier-cortex.h"
#define GPIO_HAL_CONF_ARCH_HDR_PATH "dev/gpio-hal-arch.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define GPIO_HAL_CONF_ARCH_SW_TOGGLE 0 #define GPIO_HAL_CONF_ARCH_HDR_PATH "dev/gpio-hal-arch.h"
#define GPIO_HAL_CONF_ARCH_SW_TOGGLE 0
#define GPIO_HAL_CONF_PORT_PIN_NUMBERING 0
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define SPI_CONF_CONTROLLER_COUNT 2 #define SPI_CONF_CONTROLLER_COUNT 2
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#define CONFIG_MASK (IOC_IOPULL_M | IOC_INT_M | IOC_IOMODE_OPEN_SRC_INV) #define CONFIG_MASK (IOC_IOPULL_M | IOC_INT_M | IOC_IOMODE_OPEN_SRC_INV)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) gpio_hal_arch_no_port_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
{ {
uint32_t config; uint32_t config;
gpio_hal_pin_cfg_t tmp; gpio_hal_pin_cfg_t tmp;
...@@ -86,7 +86,7 @@ gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) ...@@ -86,7 +86,7 @@ gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
gpio_hal_pin_cfg_t gpio_hal_pin_cfg_t
gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin) gpio_hal_arch_no_port_pin_cfg_get(gpio_hal_pin_t pin)
{ {
gpio_hal_pin_cfg_t cfg; gpio_hal_pin_cfg_t cfg;
uint32_t tmp; uint32_t tmp;
...@@ -129,7 +129,7 @@ gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin) ...@@ -129,7 +129,7 @@ gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
gpio_hal_pin_mask_t gpio_hal_pin_mask_t
gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins) gpio_hal_arch_no_port_read_pins(gpio_hal_pin_mask_t pins)
{ {
gpio_hal_pin_mask_t oe_pins; gpio_hal_pin_mask_t oe_pins;
...@@ -143,7 +143,7 @@ gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins) ...@@ -143,7 +143,7 @@ gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
uint8_t uint8_t
gpio_hal_arch_read_pin(gpio_hal_pin_t pin) gpio_hal_arch_no_port_read_pin(gpio_hal_pin_t pin)
{ {
if(ti_lib_gpio_get_output_enable_dio(pin)) { if(ti_lib_gpio_get_output_enable_dio(pin)) {
return (HWREG(GPIO_BASE + GPIO_O_DOUT31_0) >> pin) & 1; return (HWREG(GPIO_BASE + GPIO_O_DOUT31_0) >> pin) & 1;
......
...@@ -54,21 +54,21 @@ ...@@ -54,21 +54,21 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define gpio_hal_arch_init() do { /* Do nothing */ } while(0) #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_enable(port, pin) interrupt_enable(pin)
#define gpio_hal_arch_interrupt_disable(port, pin) ti_lib_ioc_int_disable(pin)
#define gpio_hal_arch_interrupt_disable(p) ti_lib_ioc_int_disable(p) #define gpio_hal_arch_pin_set_input(port, pin) ti_lib_ioc_pin_type_gpio_input(pin)
#define gpio_hal_arch_pin_set_input(p) ti_lib_ioc_pin_type_gpio_input(p) #define gpio_hal_arch_pin_set_output(port, pin) ti_lib_ioc_pin_type_gpio_output(pin)
#define gpio_hal_arch_pin_set_output(p) ti_lib_ioc_pin_type_gpio_output(p)
#define gpio_hal_arch_set_pin(p) ti_lib_gpio_set_dio(p) #define gpio_hal_arch_set_pin(port, pin) ti_lib_gpio_set_dio(pin)
#define gpio_hal_arch_clear_pin(p) ti_lib_gpio_clear_dio(p) #define gpio_hal_arch_clear_pin(port, pin) ti_lib_gpio_clear_dio(pin)
#define gpio_hal_arch_toggle_pin(p) ti_lib_gpio_toggle_dio(p) #define gpio_hal_arch_toggle_pin(port, pin) ti_lib_gpio_toggle_dio(pin)
#define gpio_hal_arch_write_pin(p, v) ti_lib_gpio_write_dio(p, v) #define gpio_hal_arch_write_pin(port, pin, v) ti_lib_gpio_write_dio(pin, v)
#define gpio_hal_arch_set_pins(p) ti_lib_gpio_set_multi_dio(p) #define gpio_hal_arch_set_pins(port, pin) ti_lib_gpio_set_multi_dio(pin)
#define gpio_hal_arch_clear_pins(p) ti_lib_gpio_clear_multi_dio(p) #define gpio_hal_arch_clear_pins(port, pin) ti_lib_gpio_clear_multi_dio(pin)
#define gpio_hal_arch_toggle_pins(p) ti_lib_gpio_toggle_multi_dio(p) #define gpio_hal_arch_toggle_pins(port, pin) ti_lib_gpio_toggle_multi_dio(pin)
#define gpio_hal_arch_write_pins(p, v) ti_lib_gpio_write_multi_dio(p, v) #define gpio_hal_arch_write_pins(port, pin, v) ti_lib_gpio_write_multi_dio(pin, v)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static inline void static inline void
interrupt_enable(gpio_hal_pin_t pin) interrupt_enable(gpio_hal_pin_t pin)
......
...@@ -49,7 +49,7 @@ gpio_hal_arch_init(void) ...@@ -49,7 +49,7 @@ gpio_hal_arch_init(void)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_interrupt_enable(gpio_hal_pin_t pin) gpio_hal_arch_no_port_interrupt_enable(gpio_hal_pin_t pin)
{ {
if(pin >= GPIO_HAL_PIN_COUNT) { if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin); LOG_ERR("Pin %u out of bounds\n", pin);
...@@ -60,7 +60,7 @@ gpio_hal_arch_interrupt_enable(gpio_hal_pin_t pin) ...@@ -60,7 +60,7 @@ gpio_hal_arch_interrupt_enable(gpio_hal_pin_t pin)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_interrupt_disable(gpio_hal_pin_t pin) gpio_hal_arch_no_port_interrupt_disable(gpio_hal_pin_t pin)
{ {
if(pin >= GPIO_HAL_PIN_COUNT) { if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin); LOG_ERR("Pin %u out of bounds\n", pin);
...@@ -71,7 +71,7 @@ gpio_hal_arch_interrupt_disable(gpio_hal_pin_t pin) ...@@ -71,7 +71,7 @@ gpio_hal_arch_interrupt_disable(gpio_hal_pin_t pin)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) gpio_hal_arch_no_port_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
{ {
if(pin >= GPIO_HAL_PIN_COUNT) { if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin); LOG_ERR("Pin %u out of bounds\n", pin);
...@@ -83,7 +83,7 @@ gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) ...@@ -83,7 +83,7 @@ gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
gpio_hal_pin_cfg_t gpio_hal_pin_cfg_t
gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin) gpio_hal_arch_no_port_pin_cfg_get(gpio_hal_pin_t pin)
{ {
if(pin >= GPIO_HAL_PIN_COUNT) { if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin); LOG_ERR("Pin %u out of bounds\n", pin);
...@@ -95,7 +95,7 @@ gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin) ...@@ -95,7 +95,7 @@ gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_pin_set_input(gpio_hal_pin_t pin) gpio_hal_arch_no_port_pin_set_input(gpio_hal_pin_t pin)
{ {
if(pin >= GPIO_HAL_PIN_COUNT) { if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin); LOG_ERR("Pin %u out of bounds\n", pin);
...@@ -106,7 +106,7 @@ gpio_hal_arch_pin_set_input(gpio_hal_pin_t pin) ...@@ -106,7 +106,7 @@ gpio_hal_arch_pin_set_input(gpio_hal_pin_t pin)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_pin_set_output(gpio_hal_pin_t pin) gpio_hal_arch_no_port_pin_set_output(gpio_hal_pin_t pin)
{ {
if(pin >= GPIO_HAL_PIN_COUNT) { if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin); LOG_ERR("Pin %u out of bounds\n", pin);
...@@ -117,7 +117,7 @@ gpio_hal_arch_pin_set_output(gpio_hal_pin_t pin) ...@@ -117,7 +117,7 @@ gpio_hal_arch_pin_set_output(gpio_hal_pin_t pin)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_set_pin(gpio_hal_pin_t pin) gpio_hal_arch_no_port_set_pin(gpio_hal_pin_t pin)
{ {
if(pin >= GPIO_HAL_PIN_COUNT) { if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin); LOG_ERR("Pin %u out of bounds\n", pin);
...@@ -129,7 +129,7 @@ gpio_hal_arch_set_pin(gpio_hal_pin_t pin) ...@@ -129,7 +129,7 @@ gpio_hal_arch_set_pin(gpio_hal_pin_t pin)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_clear_pin(gpio_hal_pin_t pin) gpio_hal_arch_no_port_clear_pin(gpio_hal_pin_t pin)
{ {
if(pin >= GPIO_HAL_PIN_COUNT) { if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin); LOG_ERR("Pin %u out of bounds\n", pin);
...@@ -141,7 +141,7 @@ gpio_hal_arch_clear_pin(gpio_hal_pin_t pin) ...@@ -141,7 +141,7 @@ gpio_hal_arch_clear_pin(gpio_hal_pin_t pin)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
uint8_t uint8_t
gpio_hal_arch_read_pin(gpio_hal_pin_t pin) gpio_hal_arch_no_port_read_pin(gpio_hal_pin_t pin)
{ {
if(pin >= GPIO_HAL_PIN_COUNT) { if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin); LOG_ERR("Pin %u out of bounds\n", pin);
...@@ -153,7 +153,7 @@ gpio_hal_arch_read_pin(gpio_hal_pin_t pin) ...@@ -153,7 +153,7 @@ gpio_hal_arch_read_pin(gpio_hal_pin_t pin)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_write_pin(gpio_hal_pin_t pin, uint8_t value) gpio_hal_arch_no_port_write_pin(gpio_hal_pin_t pin, uint8_t value)
{ {
if(pin >= GPIO_HAL_PIN_COUNT) { if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin); LOG_ERR("Pin %u out of bounds\n", pin);
...@@ -165,7 +165,7 @@ gpio_hal_arch_write_pin(gpio_hal_pin_t pin, uint8_t value) ...@@ -165,7 +165,7 @@ gpio_hal_arch_write_pin(gpio_hal_pin_t pin, uint8_t value)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_set_pins(gpio_hal_pin_mask_t pins) gpio_hal_arch_no_port_set_pins(gpio_hal_pin_mask_t pins)
{ {
gpio_hal_pin_t pin; gpio_hal_pin_t pin;
...@@ -179,7 +179,7 @@ gpio_hal_arch_set_pins(gpio_hal_pin_mask_t pins) ...@@ -179,7 +179,7 @@ gpio_hal_arch_set_pins(gpio_hal_pin_mask_t pins)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_clear_pins(gpio_hal_pin_mask_t pins) gpio_hal_arch_no_port_clear_pins(gpio_hal_pin_mask_t pins)
{ {
gpio_hal_pin_t pin; gpio_hal_pin_t pin;
...@@ -193,7 +193,7 @@ gpio_hal_arch_clear_pins(gpio_hal_pin_mask_t pins) ...@@ -193,7 +193,7 @@ gpio_hal_arch_clear_pins(gpio_hal_pin_mask_t pins)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
gpio_hal_pin_mask_t gpio_hal_pin_mask_t
gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins) gpio_hal_arch_no_port_read_pins(gpio_hal_pin_mask_t pins)
{ {
gpio_hal_pin_t pin; gpio_hal_pin_t pin;
gpio_hal_pin_mask_t state = 0; gpio_hal_pin_mask_t state = 0;
...@@ -207,7 +207,8 @@ gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins) ...@@ -207,7 +207,8 @@ gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_write_pins(gpio_hal_pin_mask_t pins, gpio_hal_pin_mask_t value) gpio_hal_arch_no_port_write_pins(gpio_hal_pin_mask_t pins,
gpio_hal_pin_mask_t value)
{ {
gpio_hal_pin_t pin; gpio_hal_pin_t pin;
......
...@@ -32,7 +32,8 @@ ...@@ -32,7 +32,8 @@
#ifndef NATIVE_DEF_H_ #ifndef NATIVE_DEF_H_
#define NATIVE_DEF_H_ #define NATIVE_DEF_H_
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define GPIO_HAL_CONF_ARCH_SW_TOGGLE 1 #define GPIO_HAL_CONF_ARCH_SW_TOGGLE 1
#define GPIO_HAL_CONF_PORT_PIN_NUMBERING 0
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#endif /* NATIVE_DEF_H_ */ #endif /* NATIVE_DEF_H_ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
...@@ -61,15 +61,6 @@ ...@@ -61,15 +61,6 @@
#define BOARD_CONF_SENSORS_DISABLE 0 #define BOARD_CONF_SENSORS_DISABLE 0
#endif #endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/**
* \name GPIO HAL configuration.
*
* @{
*/
#define GPIO_HAL_CONF_ARCH_SW_TOGGLE 0
#define GPIO_HAL_CONF_ARCH_HDR_PATH "dev/gpio-hal-arch.h"
/** @} */
/*---------------------------------------------------------------------------*/
/** /**
* \name Watchdog Configuration. * \name Watchdog Configuration.
* *
......
...@@ -130,6 +130,11 @@ ...@@ -130,6 +130,11 @@
#define ATOMIC_CONF_ARCH_HEADER_PATH "atomic-cortex.h" #define ATOMIC_CONF_ARCH_HEADER_PATH "atomic-cortex.h"
#define MEMORY_BARRIER_CONF_ARCH_HEADER_PATH "memory-barrier-cortex.h" #define MEMORY_BARRIER_CONF_ARCH_HEADER_PATH "memory-barrier-cortex.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* GPIO HAL configuration */
#define GPIO_HAL_CONF_ARCH_HDR_PATH "dev/gpio-hal-arch.h"
#define GPIO_HAL_CONF_ARCH_SW_TOGGLE 0
#define GPIO_HAL_CONF_PORT_PIN_NUMBERING 0
/*---------------------------------------------------------------------------*/
#endif /* CC13XX_CC26XX_DEF_H_ */ #endif /* CC13XX_CC26XX_DEF_H_ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** @} */ /** @} */
...@@ -147,7 +147,7 @@ gpio_hal_arch_init(void) ...@@ -147,7 +147,7 @@ gpio_hal_arch_init(void)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_interrupt_enable(gpio_hal_pin_t pin) gpio_hal_arch_no_port_interrupt_enable(gpio_hal_pin_t pin)
{ {
PIN_Config pin_cfg; PIN_Config pin_cfg;
PIN_Config irq_cfg; PIN_Config irq_cfg;
...@@ -160,7 +160,7 @@ gpio_hal_arch_interrupt_enable(gpio_hal_pin_t pin) ...@@ -160,7 +160,7 @@ gpio_hal_arch_interrupt_enable(gpio_hal_pin_t pin)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_interrupt_disable(gpio_hal_pin_t pin) gpio_hal_arch_no_port_interrupt_disable(gpio_hal_pin_t pin)
{ {
PIN_add(pin_handle, PIN_getConfig(pin)); PIN_add(pin_handle, PIN_getConfig(pin));
...@@ -168,7 +168,7 @@ gpio_hal_arch_interrupt_disable(gpio_hal_pin_t pin) ...@@ -168,7 +168,7 @@ gpio_hal_arch_interrupt_disable(gpio_hal_pin_t pin)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) gpio_hal_arch_no_port_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
{ {
PIN_add(pin_handle, PIN_getConfig(pin)); PIN_add(pin_handle, PIN_getConfig(pin));
...@@ -182,7 +182,7 @@ gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) ...@@ -182,7 +182,7 @@ gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
gpio_hal_pin_cfg_t gpio_hal_pin_cfg_t
gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin) gpio_hal_arch_no_port_pin_cfg_get(gpio_hal_pin_t pin)
{ {
PIN_Config pin_cfg = PIN_getConfig(pin); PIN_Config pin_cfg = PIN_getConfig(pin);
gpio_hal_pin_cfg_t cfg = 0; gpio_hal_pin_cfg_t cfg = 0;
...@@ -193,7 +193,7 @@ gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin) ...@@ -193,7 +193,7 @@ gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
gpio_hal_pin_mask_t gpio_hal_pin_mask_t
gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins) gpio_hal_arch_no_port_read_pins(gpio_hal_pin_mask_t pins)
{ {
/* For pins configured as output we need to read DOUT31_0 */ /* For pins configured as output we need to read DOUT31_0 */
gpio_hal_pin_mask_t oe_pins = GPIO_getOutputEnableMultiDio(pins); gpio_hal_pin_mask_t oe_pins = GPIO_getOutputEnableMultiDio(pins);
...@@ -205,7 +205,7 @@ gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins) ...@@ -205,7 +205,7 @@ gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
uint8_t uint8_t
gpio_hal_arch_read_pin(gpio_hal_pin_t pin) gpio_hal_arch_no_port_read_pin(gpio_hal_pin_t pin)
{ {
return (GPIO_getOutputEnableDio(pin)) return (GPIO_getOutputEnableDio(pin))
? PINCC26XX_getOutputValue(pin) ? PINCC26XX_getOutputValue(pin)
......
...@@ -53,20 +53,20 @@ ...@@ -53,20 +53,20 @@
#include <ti/drivers/pin/PINCC26XX.h> #include <ti/drivers/pin/PINCC26XX.h>
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define gpio_hal_arch_pin_set_input(p) PINCC26XX_setOutputEnable(p, false) #define gpio_hal_arch_pin_set_input(port, pin) PINCC26XX_setOutputEnable(pin, false)
#define gpio_hal_arch_pin_set_output(p) PINCC26XX_setOutputEnable(p, true) #define gpio_hal_arch_pin_set_output(port, pin) PINCC26XX_setOutputEnable(pin, true)
#define gpio_hal_arch_set_pin(p) PINCC26XX_setOutputValue(p, 1) #define gpio_hal_arch_set_pin(port, pin) PINCC26XX_setOutputValue(pin, 1)
#define gpio_hal_arch_clear_pin(p) PINCC26XX_setOutputValue(p, 0) #define gpio_hal_arch_clear_pin(port, pin) PINCC26XX_setOutputValue(pin, 0)
#define gpio_hal_arch_toggle_pin(p) PINCC26XX_setOutputValue(p, \ #define gpio_hal_arch_toggle_pin(port, pin) PINCC26XX_setOutputValue(pin, \
PINCC26XX_getOutputValue(p) \ PINCC26XX_getOutputValue(pin) \
? 0 : 1) ? 0 : 1)
#define gpio_hal_arch_write_pin(p, v) PINCC26XX_setOutputValue(p, v) #define gpio_hal_arch_write_pin(port, pin, v) PINCC26XX_setOutputValue(pin, v)
#define gpio_hal_arch_set_pins(p) GPIO_setMultiDio(p) #define gpio_hal_arch_set_pins(port, pin) GPIO_setMultiDio(pin)
#define gpio_hal_arch_clear_pins(p) GPIO_clearMultiDio(p) #define gpio_hal_arch_clear_pins(port, pin) GPIO_clearMultiDio(pin)
#define gpio_hal_arch_toggle_pins(p) GPIO_toggleMultiDio(p) #define gpio_hal_arch_toggle_pins(port, pin) GPIO_toggleMultiDio(pin)
#define gpio_hal_arch_write_pins(p, v) GPIO_writeMultiDio(p, v) #define gpio_hal_arch_write_pins(port, pin, v) GPIO_writeMultiDio(pin, v)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#endif /* GPIO_HAL_ARCH_H_ */ #endif /* GPIO_HAL_ARCH_H_ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
......
...@@ -100,6 +100,12 @@ ...@@ -100,6 +100,12 @@
#define VERIFY_PART_OK 1 #define VERIFY_PART_OK 1
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static const spi_device_t flash_spi_configuration_default = { static const spi_device_t flash_spi_configuration_default = {
#if GPIO_HAL_PORT_PIN_NUMBERING
.port_spi_sck = EXT_FLASH_SPI_PORT_SCK,
.port_spi_miso = EXT_FLASH_SPI_PORT_MISO,
.port_spi_mosi = EXT_FLASH_SPI_PORT_MOSI,
.port_spi_cs = EXT_FLASH_SPI_PORT_CS,
#endif
.spi_controller = EXT_FLASH_SPI_CONTROLLER, .spi_controller = EXT_FLASH_SPI_CONTROLLER,
.pin_spi_sck = EXT_FLASH_SPI_PIN_SCK, .pin_spi_sck = EXT_FLASH_SPI_PIN_SCK,
.pin_spi_miso = EXT_FLASH_SPI_PIN_MISO, .pin_spi_miso = EXT_FLASH_SPI_PIN_MISO,
......
...@@ -74,14 +74,14 @@ config(int type, int enable) ...@@ -74,14 +74,14 @@ config(int type, int enable)
return init(); return init();
case SENSORS_ACTIVE: case SENSORS_ACTIVE:
gpio_hal_arch_pin_set_output(Board_ALS_PWR); PINCC26XX_setOutputEnable(Board_ALS_PWR, true);
gpio_hal_arch_pin_set_input(Board_ALS_OUT); PINCC26XX_setOutputEnable(Board_ALS_OUT, false);
if(enable) { if(enable) {
gpio_hal_arch_set_pin(Board_ALS_PWR); PINCC26XX_setOutputValue(Board_ALS_PWR, 1);
clock_delay_usec(2000); clock_delay_usec(2000);
} else { } else {
gpio_hal_arch_clear_pin(Board_ALS_PWR); PINCC26XX_setOutputValue(Board_ALS_PWR, 0);
} }
break; break;
......
...@@ -8,7 +8,9 @@ developing a new port. ...@@ -8,7 +8,9 @@ developing a new port.
This example assumes a device with: This example assumes a device with:
* 3 output pins (e.g. LEDs). * 3 output pins (e.g. LEDs). If the platform uses the port/pin GPIO numbering
scheme then this example assumes that at least 2 of those pins are part of
the same port.
* 1 button. * 1 button.
# Supported devices # Supported devices
...@@ -34,3 +36,10 @@ board that you wish to test with the example. For example, if you have a LED ...@@ -34,3 +36,10 @@ board that you wish to test with the example. For example, if you have a LED
connected to pin 20, then you will need to connected to pin 20, then you will need to
gpio_hal_pin_t out_pin1 = 20; gpio_hal_pin_t out_pin1 = 20;
If the platform uses the port/pin GPIO numbering scheme then you will also
need to provide definitions for the following variables:
* `out_port1` and `out_port2_3`. `out_port2_3` corresponds to the port that
`out_pin2` and `out_pin3` are members of.
* `btn_port` for the button pin's port.
...@@ -40,6 +40,15 @@ ...@@ -40,6 +40,15 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
extern gpio_hal_pin_t out_pin1, out_pin2, out_pin3; extern gpio_hal_pin_t out_pin1, out_pin2, out_pin3;
extern gpio_hal_pin_t btn_pin; extern gpio_hal_pin_t btn_pin;
#if GPIO_HAL_PORT_PIN_NUMBERING
extern gpio_hal_port_t out_port1, out_port2_3;
extern gpio_hal_port_t btn_port;
#else
#define out_port1 GPIO_HAL_NULL_PORT
#define out_port2_3 GPIO_HAL_NULL_PORT
#define btn_port GPIO_HAL_NULL_PORT
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static struct etimer et; static struct etimer et;
static uint8_t counter; static uint8_t counter;
...@@ -69,70 +78,70 @@ PROCESS_THREAD(gpio_hal_example, ev, data) ...@@ -69,70 +78,70 @@ PROCESS_THREAD(gpio_hal_example, ev, data)
if(ev == PROCESS_EVENT_TIMER && data == &et) { if(ev == PROCESS_EVENT_TIMER && data == &et) {
if((counter & 7) == 0) { if((counter & 7) == 0) {
/* Set output and test write, high */ /* Set output and test write, high */
gpio_hal_arch_pin_set_output(out_pin1); gpio_hal_arch_pin_set_output(out_port1, out_pin1);
gpio_hal_arch_pin_set_output(out_pin2); gpio_hal_arch_pin_set_output(out_port2_3, out_pin2);
gpio_hal_arch_pin_set_output(out_pin3); gpio_hal_arch_pin_set_output(out_port2_3, out_pin3);
gpio_hal_arch_write_pin(out_pin1, 1); gpio_hal_arch_write_pin(out_port1, out_pin1, 1);
gpio_hal_arch_write_pins( gpio_hal_arch_write_pins(out_port2_3,
gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3), gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3),
gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3)); gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3));
} else if((counter & 7) == 1) { } else if((counter & 7) == 1) {
/* Test write, low */ /* Test write, low */
gpio_hal_arch_write_pin(out_pin1, 0); gpio_hal_arch_write_pin(out_port1, out_pin1, 0);
gpio_hal_arch_write_pins( gpio_hal_arch_write_pins(out_port2_3,
gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3), 0); gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3), 0);
} else if((counter & 7) == 2) { } else if((counter & 7) == 2) {
/* Test set */ /* Test set */
gpio_hal_arch_set_pin(out_pin1); gpio_hal_arch_set_pin(out_port1, out_pin1);
gpio_hal_arch_set_pins( gpio_hal_arch_set_pins(out_port2_3,
gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3)); gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3));
} else if((counter & 7) == 3) { } else if((counter & 7) == 3) {
/* Test clear */ /* Test clear */
gpio_hal_arch_clear_pin(out_pin1); gpio_hal_arch_clear_pin(out_port1, out_pin1);
gpio_hal_arch_clear_pins( gpio_hal_arch_clear_pins(out_port2_3,
gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3)); gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3));
} else if((counter & 7) == 4) { } else if((counter & 7) == 4) {
/* Test toggle (should go high) */ /* Test toggle (should go high) */
gpio_hal_arch_toggle_pin(out_pin1); gpio_hal_arch_toggle_pin(out_port1, out_pin1);
gpio_hal_arch_toggle_pins( gpio_hal_arch_toggle_pins(out_port2_3,
gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3)); gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3));
} else if((counter & 7) == 5) { } else if((counter & 7) == 5) {
/* Test toggle (should go low) */ /* Test toggle (should go low) */
gpio_hal_arch_toggle_pin(out_pin1); gpio_hal_arch_toggle_pin(out_port1, out_pin1);
gpio_hal_arch_toggle_pins( gpio_hal_arch_toggle_pins(out_port2_3,
gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3)); gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3));
} else if((counter & 7) == 6) { } else if((counter & 7) == 6) {
/* Set to input and then set. Should stay off */ /* Set to input and then set. Should stay off */
gpio_hal_arch_pin_set_input(out_pin1); gpio_hal_arch_pin_set_input(out_port1, out_pin1);
gpio_hal_arch_pin_set_input(out_pin2); gpio_hal_arch_pin_set_input(out_port2_3, out_pin2);
gpio_hal_arch_pin_set_input(out_pin3); gpio_hal_arch_pin_set_input(out_port2_3, out_pin3);
gpio_hal_arch_set_pin(out_pin1); gpio_hal_arch_set_pin(out_port1, out_pin1);
gpio_hal_arch_set_pins( gpio_hal_arch_set_pins(out_port2_3,
gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3)); gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3));
} else if((counter & 7) == 7) { } else if((counter & 7) == 7) {
/* Toggle button interrupt */ /* Toggle button interrupt */
gpio_hal_pin_cfg_t interrupt; gpio_hal_pin_cfg_t interrupt;
interrupt = gpio_hal_arch_pin_cfg_get(btn_pin) & interrupt = gpio_hal_arch_pin_cfg_get(btn_port, btn_pin) &
GPIO_HAL_PIN_CFG_INT_ENABLE; GPIO_HAL_PIN_CFG_INT_ENABLE;
if(interrupt == 0) { if(interrupt == 0) {
printf("Enabling button interrupt\n"); printf("Enabling button interrupt\n");
gpio_hal_arch_interrupt_enable(btn_pin); gpio_hal_arch_interrupt_enable(btn_port, btn_pin);
} else { } else {
printf("Disabling button interrupt\n"); printf("Disabling button interrupt\n");
gpio_hal_arch_interrupt_disable(btn_pin); gpio_hal_arch_interrupt_disable(btn_port, btn_pin);
} }
} }
/* Test read */ /* Test read */
printf("%u: Pins are 1-%u, 2=%u, 3=%u, mask=" PIN_MASK_FMT "\n", printf("%u: Pins are 1-%u, 2=%u, 3=%u, mask=" PIN_MASK_FMT "\n",
counter & 7, counter & 7,
gpio_hal_arch_read_pin(out_pin1), gpio_hal_arch_read_pin(out_port1, out_pin1),
gpio_hal_arch_read_pin(out_pin2), gpio_hal_arch_read_pin(out_port2_3, out_pin2),
gpio_hal_arch_read_pin(out_pin3), gpio_hal_arch_read_pin(out_port2_3, out_pin3),
gpio_hal_arch_read_pins(gpio_hal_pin_to_mask(out_pin1) | gpio_hal_arch_read_pins(out_port2_3,
gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin2) |
gpio_hal_pin_to_mask(out_pin3))); gpio_hal_pin_to_mask(out_pin3)));
......
...@@ -62,6 +62,12 @@ extern button_hal_button_t *button_hal_buttons[]; ...@@ -62,6 +62,12 @@ extern button_hal_button_t *button_hal_buttons[];
/* Common handler for all handler events, and register it with the GPIO HAL */ /* Common handler for all handler events, and register it with the GPIO HAL */
static gpio_hal_event_handler_t button_event_handler; static gpio_hal_event_handler_t button_event_handler;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if GPIO_HAL_PORT_PIN_NUMBERING
#define BTN_PORT(b) (b)->port
#else
#define BTN_PORT(b) GPIO_HAL_NULL_PORT
#endif
/*---------------------------------------------------------------------------*/
static void static void
duration_exceeded_callback(void *btn) duration_exceeded_callback(void *btn)
{ {
...@@ -121,7 +127,11 @@ debounce_handler(void *btn) ...@@ -121,7 +127,11 @@ debounce_handler(void *btn)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
press_release_handler(gpio_hal_pin_mask_t pin_mask) press_release_handler(
#if GPIO_HAL_PORT_PIN_NUMBERING
gpio_hal_port_t port,
#endif
gpio_hal_pin_mask_t pin_mask)
{ {
pmask |= pin_mask; pmask |= pin_mask;
process_poll(&button_hal_process); process_poll(&button_hal_process);
...@@ -154,7 +164,7 @@ button_hal_get_by_index(uint8_t index) ...@@ -154,7 +164,7 @@ button_hal_get_by_index(uint8_t index)
uint8_t uint8_t
button_hal_get_state(button_hal_button_t *button) button_hal_get_state(button_hal_button_t *button)
{ {
uint8_t pin_state = gpio_hal_arch_read_pin(button->pin); uint8_t pin_state = gpio_hal_arch_read_pin(BTN_PORT(button), button->pin);
if((pin_state == 0 && button->negative_logic == true) || if((pin_state == 0 && button->negative_logic == true) ||
(pin_state == 1 && button->negative_logic == false)) { (pin_state == 1 && button->negative_logic == false)) {
...@@ -180,9 +190,9 @@ button_hal_init() ...@@ -180,9 +190,9 @@ button_hal_init()
for(button = button_hal_buttons; *button != NULL; button++) { for(button = button_hal_buttons; *button != NULL; button++) {
cfg = GPIO_HAL_PIN_CFG_EDGE_BOTH | GPIO_HAL_PIN_CFG_INT_ENABLE | cfg = GPIO_HAL_PIN_CFG_EDGE_BOTH | GPIO_HAL_PIN_CFG_INT_ENABLE |
(*button)->pull; (*button)->pull;
gpio_hal_arch_pin_set_input((*button)->pin); gpio_hal_arch_pin_set_input(BTN_PORT(*button), (*button)->pin);
gpio_hal_arch_pin_cfg_set((*button)->pin, cfg); gpio_hal_arch_pin_cfg_set(BTN_PORT(*button), (*button)->pin, cfg);
gpio_hal_arch_interrupt_enable((*button)->pin); gpio_hal_arch_interrupt_enable(BTN_PORT(*button), (*button)->pin);
button_event_handler.pin_mask |= gpio_hal_pin_to_mask((*button)->pin); button_event_handler.pin_mask |= gpio_hal_pin_to_mask((*button)->pin);
} }
......
...@@ -151,6 +151,11 @@ struct button_hal_button_s { ...@@ -151,6 +151,11 @@ struct button_hal_button_s {
/** True if the button uses negative logic (active: low) */ /** True if the button uses negative logic (active: low) */
const bool negative_logic; const bool negative_logic;
#if GPIO_HAL_PORT_PIN_NUMBERING
/** The gpio port connected to the button */
gpio_hal_port_t port;
#endif
/** The gpio pin connected to the button */ /** The gpio pin connected to the button */
const gpio_hal_pin_t pin; const gpio_hal_pin_t pin;
...@@ -172,23 +177,36 @@ struct button_hal_button_s { ...@@ -172,23 +177,36 @@ struct button_hal_button_s {
}; };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if BUTTON_HAL_WITH_DESCRIPTION #if BUTTON_HAL_WITH_DESCRIPTION
#if GPIO_HAL_PORT_PIN_NUMBERING
/** /**
* \brief Define a button to be used by the HAL * \brief Define a button to be used by the HAL
* \param name The variable name for the button * \param name The variable name for the button
* \param descr A textual description * \param descr A textual description
* \param p The pin connected to the button * \param po The port connected to the button
* \param pi The pin connected to the button
* \param nl True if the button is connected using negative logic * \param nl True if the button is connected using negative logic
* \param u The button's pull configuration * \param u The button's pull configuration
* \param id A unique numeric identifier * \param id A unique numeric identifier
*/ */
#define BUTTON_HAL_BUTTON(name, descr, p, u, id, nl) \ #define BUTTON_HAL_BUTTON(name, descr, po, pi, u, id, nl) \
static button_hal_button_t name = { \ static button_hal_button_t name = { \
.description = descr, \ .description = descr, \
.pin = p, \ .port = po, \
.pin = pi, \
.pull = u, \ .pull = u, \
.unique_id = id, \ .unique_id = id, \
.negative_logic = nl, \ .negative_logic = nl, \
} }
#else /* GPIO_HAL_PORT_PIN_NUMBERING */
#define BUTTON_HAL_BUTTON(name, descr, pi, u, id, nl) \
static button_hal_button_t name = { \
.description = descr, \
.pin = pi, \
.pull = u, \
.unique_id = id, \
.negative_logic = nl, \
}
#endif /* GPIO_HAL_PORT_PIN_NUMBERING */
/** /**
* \brief Retrieve the textual description of a button * \brief Retrieve the textual description of a button
...@@ -198,17 +216,30 @@ struct button_hal_button_s { ...@@ -198,17 +216,30 @@ struct button_hal_button_s {
* BUTTON_HAL_WITH_DESCRIPTION is 0 then this macro will return "" * BUTTON_HAL_WITH_DESCRIPTION is 0 then this macro will return ""
*/ */
#define BUTTON_HAL_GET_DESCRIPTION(b) (b)->description #define BUTTON_HAL_GET_DESCRIPTION(b) (b)->description
#else
#define BUTTON_HAL_BUTTON(name, descr, p, u, id, nl) \ #else /* BUTTON_HAL_WITH_DESCRIPTION */
#if GPIO_HAL_PORT_PIN_NUMBERING
#define BUTTON_HAL_BUTTON(name, descr, po, pi, u, id, nl) \
static button_hal_button_t name = { \
.port = po, \
.pin = pi, \
.pull = u, \
.unique_id = id, \
.negative_logic = nl, \
}
#else /* GPIO_HAL_PORT_PIN_NUMBERING */
#define BUTTON_HAL_BUTTON(name, descr, pi, u, id, nl) \
static button_hal_button_t name = { \ static button_hal_button_t name = { \
.pin = p, \ .pin = pi, \
.pull = u, \ .pull = u, \
.unique_id = id, \ .unique_id = id, \
.negative_logic = nl, \ .negative_logic = nl, \
} }
#endif /* GPIO_HAL_PORT_PIN_NUMBERING */
#define BUTTON_HAL_GET_DESCRIPTION(b) "" #define BUTTON_HAL_GET_DESCRIPTION(b) ""
#endif #endif /* BUTTON_HAL_WITH_DESCRIPTION */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define BUTTON_HAL_BUTTONS(...) \ #define BUTTON_HAL_BUTTONS(...) \
button_hal_button_t *button_hal_buttons[] = {__VA_ARGS__, NULL}; \ button_hal_button_t *button_hal_buttons[] = {__VA_ARGS__, NULL}; \
......
...@@ -57,6 +57,24 @@ gpio_hal_register_handler(gpio_hal_event_handler_t *handler) ...@@ -57,6 +57,24 @@ gpio_hal_register_handler(gpio_hal_event_handler_t *handler)
list_add(handlers, handler); list_add(handlers, handler);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if GPIO_HAL_PORT_PIN_NUMBERING
/*---------------------------------------------------------------------------*/
void
gpio_hal_event_handler(gpio_hal_port_t port, gpio_hal_pin_mask_t pins)
{
gpio_hal_event_handler_t *this;
for(this = list_head(handlers); this != NULL; this = this->next) {
if((port == this->port) && (pins & this->pin_mask)) {
if(this->handler != NULL) {
this->handler(port, pins & this->pin_mask);
}
}
}
}
/*---------------------------------------------------------------------------*/
#else
/*---------------------------------------------------------------------------*/
void void
gpio_hal_event_handler(gpio_hal_pin_mask_t pins) gpio_hal_event_handler(gpio_hal_pin_mask_t pins)
{ {
...@@ -71,6 +89,8 @@ gpio_hal_event_handler(gpio_hal_pin_mask_t pins) ...@@ -71,6 +89,8 @@ gpio_hal_event_handler(gpio_hal_pin_mask_t pins)
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#endif /* GPIO_HAL_PORT_PIN_NUMBERING */
/*---------------------------------------------------------------------------*/
void void
gpio_hal_init() gpio_hal_init()
{ {
...@@ -81,20 +101,35 @@ gpio_hal_init() ...@@ -81,20 +101,35 @@ gpio_hal_init()
#if GPIO_HAL_ARCH_SW_TOGGLE #if GPIO_HAL_ARCH_SW_TOGGLE
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_toggle_pin(gpio_hal_pin_t pin) gpio_hal_arch_port_toggle_pin(gpio_hal_port_t port, gpio_hal_pin_t pin)
{
gpio_hal_arch_write_pin(port, pin, gpio_hal_arch_read_pin(port, pin) ^ 1);
}
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_port_toggle_pins(gpio_hal_port_t port, gpio_hal_pin_mask_t pins)
{
gpio_hal_arch_write_pins(port, pins, ~gpio_hal_arch_read_pins(port, pins));
}
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_no_port_toggle_pin(gpio_hal_pin_t pin)
{ {
if(pin >= GPIO_HAL_PIN_COUNT) { if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin); LOG_ERR("Pin %u out of bounds\n", pin);
return; return;
} }
gpio_hal_arch_write_pin(pin, gpio_hal_arch_read_pin(pin) ^ 1); gpio_hal_arch_write_pin(GPIO_HAL_NULL_PORT, pin,
gpio_hal_arch_read_pin(GPIO_HAL_NULL_PORT, pin) ^ 1);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
gpio_hal_arch_toggle_pins(gpio_hal_pin_mask_t pins) gpio_hal_arch_no_port_toggle_pins(gpio_hal_pin_mask_t pins)
{ {
gpio_hal_arch_write_pins(pins, ~gpio_hal_arch_read_pins(pins)); gpio_hal_arch_write_pins(GPIO_HAL_NULL_PORT, pins,
~gpio_hal_arch_read_pins(GPIO_HAL_NULL_PORT,
pins));
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#endif /* GPIO_HAL_ARCH_SW_TOGGLE */ #endif /* GPIO_HAL_ARCH_SW_TOGGLE */
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment