diff --git a/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad b/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad index 224f0c2c5..f10f979da 100644 --- a/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad +++ b/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad @@ -2,7 +2,7 @@ CFLAGS += -DBOARD_LAUNCHPAD=1 CONTIKI_TARGET_DIRS += launchpad common -BOARD_SOURCEFILES += board.c launchpad-sensors.c button-sensor.c xmem.c +BOARD_SOURCEFILES += board.c board-buttons.c xmem.c BOARD_SOURCEFILES += ext-flash.c board-spi.c ### Signal that we can be programmed with cc2538-bsl diff --git a/arch/platform/srf06-cc26xx/launchpad/launchpad-sensors.c b/arch/platform/srf06-cc26xx/launchpad/board-buttons.c similarity index 73% rename from arch/platform/srf06-cc26xx/launchpad/launchpad-sensors.c rename to arch/platform/srf06-cc26xx/launchpad/board-buttons.c index c940ec68c..f07fff09e 100644 --- a/arch/platform/srf06-cc26xx/launchpad/launchpad-sensors.c +++ b/arch/platform/srf06-cc26xx/launchpad/board-buttons.c @@ -1,10 +1,11 @@ /* - * Copyright (c) 2015, Texas Instruments Incorporated - http://www.ti.com/ + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -29,19 +30,26 @@ */ /*---------------------------------------------------------------------------*/ /** - * \addtogroup launchpad-peripherals + * \addtogroup launchpad-cc26xx-peripherals * @{ * * \file - * Generic module controlling LaunchPad sensors + * Defines CC13xx/CC26xx Launchpad buttons for use with the button HAL */ /*---------------------------------------------------------------------------*/ #include "contiki.h" -#include "launchpad/button-sensor.h" +#include "dev/button-hal.h" -#include +#include "ti-lib.h" /*---------------------------------------------------------------------------*/ -/** \brief Exports a global symbol to be used by the sensor API */ -SENSORS(&button_left_sensor, &button_right_sensor); +BUTTON_HAL_BUTTON(key_left, "Key Left", BOARD_IOID_KEY_LEFT, \ + GPIO_HAL_PIN_CFG_PULL_UP, 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, \ + true); +/*---------------------------------------------------------------------------*/ +BUTTON_HAL_BUTTONS(&key_left, &key_right); /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/arch/platform/srf06-cc26xx/launchpad/board-peripherals.h b/arch/platform/srf06-cc26xx/launchpad/board-peripherals.h index 3e1220234..0ad9c6b68 100644 --- a/arch/platform/srf06-cc26xx/launchpad/board-peripherals.h +++ b/arch/platform/srf06-cc26xx/launchpad/board-peripherals.h @@ -48,6 +48,8 @@ /*---------------------------------------------------------------------------*/ #include "ext-flash.h" /*---------------------------------------------------------------------------*/ +#define BOARD_CONF_HAS_SENSORS 0 +/*---------------------------------------------------------------------------*/ #endif /* BOARD_PERIPHERALS_H_ */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/launchpad/board.c b/arch/platform/srf06-cc26xx/launchpad/board.c index 74b12bd3d..7baf71d47 100644 --- a/arch/platform/srf06-cc26xx/launchpad/board.c +++ b/arch/platform/srf06-cc26xx/launchpad/board.c @@ -37,7 +37,6 @@ */ /*---------------------------------------------------------------------------*/ #include "contiki.h" -#include "lib/sensors.h" #include "lpm.h" #include "ti-lib.h" #include "board-peripherals.h" diff --git a/arch/platform/srf06-cc26xx/launchpad/button-sensor.c b/arch/platform/srf06-cc26xx/launchpad/button-sensor.c deleted file mode 100644 index 43d07ad9c..000000000 --- a/arch/platform/srf06-cc26xx/launchpad/button-sensor.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (c) 2015, Texas Instruments Incorporated - http://www.ti.com/ - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*---------------------------------------------------------------------------*/ -/** - * \addtogroup launchpad-button-sensor - * @{ - * - * \file - * Driver for LaunchPad buttons - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "lib/sensors.h" -#include "launchpad/button-sensor.h" -#include "gpio-hal.h" -#include "sys/timer.h" -#include "lpm.h" - -#include "ti-lib.h" - -#include -/*---------------------------------------------------------------------------*/ -#ifdef BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN -#define BUTTON_SENSOR_ENABLE_SHUTDOWN BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN -#else -#define BUTTON_SENSOR_ENABLE_SHUTDOWN 1 -#endif -/*---------------------------------------------------------------------------*/ -#define BUTTON_GPIO_CFG (IOC_CURRENT_2MA | IOC_STRENGTH_AUTO | \ - IOC_IOPULL_UP | IOC_SLEW_DISABLE | \ - IOC_HYST_DISABLE | IOC_BOTH_EDGES | \ - IOC_INT_ENABLE | IOC_IOMODE_NORMAL | \ - IOC_NO_WAKE_UP | IOC_INPUT_ENABLE) -/*---------------------------------------------------------------------------*/ -#define DEBOUNCE_DURATION (CLOCK_SECOND >> 5) - -struct btn_timer { - struct timer debounce; - clock_time_t start; - clock_time_t duration; -}; - -static struct btn_timer left_timer, right_timer; -/*---------------------------------------------------------------------------*/ -static void -button_press_handler(gpio_hal_pin_mask_t pin_mask) -{ - if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_LEFT)) { - if(!timer_expired(&left_timer.debounce)) { - return; - } - - timer_set(&left_timer.debounce, DEBOUNCE_DURATION); - - /* - * Start press duration counter on press (falling), notify on release - * (rising) - */ - if(ti_lib_gpio_read_dio(BOARD_IOID_KEY_LEFT) == 0) { - left_timer.start = clock_time(); - left_timer.duration = 0; - } else { - left_timer.duration = clock_time() - left_timer.start; - sensors_changed(&button_left_sensor); - } - } - - if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_RIGHT)) { - if(BUTTON_SENSOR_ENABLE_SHUTDOWN == 0) { - if(!timer_expired(&right_timer.debounce)) { - return; - } - - timer_set(&right_timer.debounce, DEBOUNCE_DURATION); - - /* - * Start press duration counter on press (falling), notify on release - * (rising) - */ - if(ti_lib_gpio_read_dio(BOARD_IOID_KEY_RIGHT) == 0) { - right_timer.start = clock_time(); - right_timer.duration = 0; - } else { - right_timer.duration = clock_time() - right_timer.start; - sensors_changed(&button_right_sensor); - } - } else { - lpm_shutdown(BOARD_IOID_KEY_RIGHT, IOC_IOPULL_UP, IOC_WAKE_ON_LOW); - } - } -} -/*---------------------------------------------------------------------------*/ -static gpio_hal_event_handler_t press_handler = { - .next = NULL, - .handler = button_press_handler, - .pin_mask = 0, -}; -/*---------------------------------------------------------------------------*/ -static void -config_buttons(int type, int c, uint32_t key) -{ - switch(type) { - case SENSORS_HW_INIT: - ti_lib_gpio_clear_event_dio(key); - ti_lib_rom_ioc_pin_type_gpio_input(key); - ti_lib_rom_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG); - press_handler.pin_mask |= gpio_hal_pin_to_mask(key); - gpio_hal_register_handler(&press_handler); - break; - case SENSORS_ACTIVE: - if(c) { - ti_lib_gpio_clear_event_dio(key); - ti_lib_rom_ioc_pin_type_gpio_input(key); - ti_lib_rom_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG); - ti_lib_rom_ioc_int_enable(key); - } else { - ti_lib_rom_ioc_int_disable(key); - } - break; - default: - break; - } -} -/*---------------------------------------------------------------------------*/ -static int -config_left(int type, int value) -{ - config_buttons(type, value, BOARD_IOID_KEY_LEFT); - - return 1; -} -/*---------------------------------------------------------------------------*/ -static int -config_right(int type, int value) -{ - config_buttons(type, value, BOARD_IOID_KEY_RIGHT); - - return 1; -} -/*---------------------------------------------------------------------------*/ -static int -status(int type, uint32_t key_io_id) -{ - switch(type) { - case SENSORS_ACTIVE: - case SENSORS_READY: - if(ti_lib_rom_ioc_port_configure_get(key_io_id) & IOC_INT_ENABLE) { - return 1; - } - break; - default: - break; - } - return 0; -} -/*---------------------------------------------------------------------------*/ -static int -value_left(int type) -{ - if(type == BUTTON_SENSOR_VALUE_STATE) { - return ti_lib_gpio_read_dio(BOARD_IOID_KEY_LEFT) == 0 ? - BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED; - } else if(type == BUTTON_SENSOR_VALUE_DURATION) { - return (int)left_timer.duration; - } - return 0; -} -/*---------------------------------------------------------------------------*/ -static int -value_right(int type) -{ - if(type == BUTTON_SENSOR_VALUE_STATE) { - return ti_lib_gpio_read_dio(BOARD_IOID_KEY_RIGHT) == 0 ? - BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED; - } else if(type == BUTTON_SENSOR_VALUE_DURATION) { - return (int)right_timer.duration; - } - return 0; -} -/*---------------------------------------------------------------------------*/ -static int -status_left(int type) -{ - return status(type, BOARD_IOID_KEY_LEFT); -} -/*---------------------------------------------------------------------------*/ -static int -status_right(int type) -{ - return status(type, BOARD_IOID_KEY_RIGHT); -} -/*---------------------------------------------------------------------------*/ -SENSORS_SENSOR(button_left_sensor, BUTTON_SENSOR, value_left, config_left, - status_left); -SENSORS_SENSOR(button_right_sensor, BUTTON_SENSOR, value_right, config_right, - status_right); -/*---------------------------------------------------------------------------*/ -/** @} */ diff --git a/arch/platform/srf06-cc26xx/launchpad/button-sensor.h b/arch/platform/srf06-cc26xx/launchpad/button-sensor.h deleted file mode 100644 index 0c945d3f7..000000000 --- a/arch/platform/srf06-cc26xx/launchpad/button-sensor.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2015, Texas Instruments Incorporated - http://www.ti.com/ - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*---------------------------------------------------------------------------*/ -/** - * \addtogroup launchpad-peripherals - * @{ - * - * \defgroup launchpad-button-sensor LaunchPad Button Driver - * - * One of the buttons can be configured as general purpose or as an on/off key - * @{ - * - * \file - * Header file for the LaunchPad Button Driver - */ -/*---------------------------------------------------------------------------*/ -#ifndef BUTTON_SENSOR_H_ -#define BUTTON_SENSOR_H_ -/*---------------------------------------------------------------------------*/ -#include "lib/sensors.h" -/*---------------------------------------------------------------------------*/ -#define BUTTON_SENSOR "Button" -/*---------------------------------------------------------------------------*/ -#define BUTTON_SENSOR_VALUE_STATE 0 -#define BUTTON_SENSOR_VALUE_DURATION 1 - -#define BUTTON_SENSOR_VALUE_RELEASED 0 -#define BUTTON_SENSOR_VALUE_PRESSED 1 -/*---------------------------------------------------------------------------*/ -extern const struct sensors_sensor button_left_sensor; -extern const struct sensors_sensor button_right_sensor; -/*---------------------------------------------------------------------------*/ -#endif /* BUTTON_SENSOR_H_ */ -/*---------------------------------------------------------------------------*/ -/** - * @} - * @} - */ diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h b/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h index d8a87e53a..d97086415 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h @@ -188,6 +188,16 @@ } /** @} */ /*---------------------------------------------------------------------------*/ +/** + * \brief Board indices for the button HAL + * + * Those values are not meant to be modified by the user + * @{ + */ +#define BOARD_BUTTON_HAL_INDEX_KEY_LEFT 0x00 +#define BOARD_BUTTON_HAL_INDEX_KEY_RIGHT 0x01 +/** @} */ +/*---------------------------------------------------------------------------*/ /** * \name Device string used on startup * @{ diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h b/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h index c80fb1326..72a7a180f 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h @@ -205,6 +205,16 @@ } /** @} */ /*---------------------------------------------------------------------------*/ +/** + * \brief Board indices for the button HAL + * + * Those values are not meant to be modified by the user + * @{ + */ +#define BOARD_BUTTON_HAL_INDEX_KEY_LEFT 0x00 +#define BOARD_BUTTON_HAL_INDEX_KEY_RIGHT 0x01 +/** @} */ +/*---------------------------------------------------------------------------*/ /** * \name Device string used on startup * @{ diff --git a/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h b/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h index 1ea40957a..deb79a7b1 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h @@ -189,6 +189,16 @@ } /** @} */ /*---------------------------------------------------------------------------*/ +/** + * \brief Board indices for the button HAL + * + * Those values are not meant to be modified by the user + * @{ + */ +#define BOARD_BUTTON_HAL_INDEX_KEY_LEFT 0x00 +#define BOARD_BUTTON_HAL_INDEX_KEY_RIGHT 0x01 +/** @} */ +/*---------------------------------------------------------------------------*/ /** * \name Device string used on startup * @{