Implement the new button HAL: Sensortag
This commit is contained in:
parent
f199ff0a5f
commit
8ac1cf92ce
@ -3,8 +3,8 @@ CFLAGS += -DBACKDOOR_IOID=0x00000000
|
|||||||
|
|
||||||
CONTIKI_TARGET_DIRS += sensortag common
|
CONTIKI_TARGET_DIRS += sensortag common
|
||||||
|
|
||||||
BOARD_SOURCEFILES += sensortag-sensors.c sensor-common.c
|
BOARD_SOURCEFILES += sensortag-sensors.c board-buttons.c sensor-common.c
|
||||||
BOARD_SOURCEFILES += bmp-280-sensor.c tmp-007-sensor.c opt-3001-sensor.c
|
BOARD_SOURCEFILES += bmp-280-sensor.c tmp-007-sensor.c opt-3001-sensor.c
|
||||||
BOARD_SOURCEFILES += hdc-1000-sensor.c mpu-9250-sensor.c button-sensor.c xmem.c
|
BOARD_SOURCEFILES += hdc-1000-sensor.c mpu-9250-sensor.c xmem.c
|
||||||
BOARD_SOURCEFILES += reed-relay.c ext-flash.c buzzer.c
|
BOARD_SOURCEFILES += ext-flash.c buzzer.c
|
||||||
BOARD_SOURCEFILES += board.c board-spi.c board-i2c.c
|
BOARD_SOURCEFILES += board.c board-spi.c board-i2c.c
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
|
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
@ -32,28 +33,30 @@
|
|||||||
* \addtogroup sensortag-cc26xx-peripherals
|
* \addtogroup sensortag-cc26xx-peripherals
|
||||||
* @{
|
* @{
|
||||||
*
|
*
|
||||||
* \defgroup sensortag-cc26xx-reed-relay SensorTag 2.0 Reed Relay
|
|
||||||
*
|
|
||||||
* The reed relay acts like a button without a button. To trigger the reed,
|
|
||||||
* approach a magnet to the sensortag and a sensors_changed event will be
|
|
||||||
* generated, in a fashion similar to as if a button had been pressed
|
|
||||||
*
|
|
||||||
* @{
|
|
||||||
*
|
|
||||||
* \file
|
* \file
|
||||||
* Header file for the Sensortag Reed Relay
|
* Defines Sensortag buttons for use with the button HAL
|
||||||
*/
|
*/
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#ifndef REED_RELAY_H
|
#include "contiki.h"
|
||||||
#define REED_RELAY_H
|
#include "dev/gpio-hal.h"
|
||||||
|
#include "dev/button-hal.h"
|
||||||
|
|
||||||
|
#include "ti-lib.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#include "lib/sensors.h"
|
BUTTON_HAL_BUTTON(reed_relay, "Reed Relay", BOARD_IOID_REED_RELAY, \
|
||||||
|
GPIO_HAL_PIN_CFG_PULL_DOWN, \
|
||||||
|
BOARD_BUTTON_HAL_INDEX_REED_RELAY, true);
|
||||||
|
|
||||||
|
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);
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
extern const struct sensors_sensor reed_relay_sensor;
|
BUTTON_HAL_BUTTONS(&reed_relay, &key_left, &key_right);
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#endif /* REED_RELAY_H */
|
/** @} */
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
* @}
|
|
||||||
*/
|
|
@ -53,7 +53,6 @@
|
|||||||
#include "opt-3001-sensor.h"
|
#include "opt-3001-sensor.h"
|
||||||
#include "hdc-1000-sensor.h"
|
#include "hdc-1000-sensor.h"
|
||||||
#include "mpu-9250-sensor.h"
|
#include "mpu-9250-sensor.h"
|
||||||
#include "reed-relay.h"
|
|
||||||
#include "buzzer.h"
|
#include "buzzer.h"
|
||||||
#include "ext-flash.h"
|
#include "ext-flash.h"
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
@ -1,288 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2014, 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 sensortag-cc26xx-button-sensor
|
|
||||||
* @{
|
|
||||||
*
|
|
||||||
* \file
|
|
||||||
* Driver for Sensortag buttons
|
|
||||||
*/
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#include "contiki.h"
|
|
||||||
#include "lib/sensors.h"
|
|
||||||
#include "sensortag/button-sensor.h"
|
|
||||||
#include "gpio-hal.h"
|
|
||||||
#include "sys/timer.h"
|
|
||||||
#include "lpm.h"
|
|
||||||
|
|
||||||
#include "ti-lib.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#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;
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Handler for Sensortag-CC26XX button presses
|
|
||||||
*/
|
|
||||||
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,
|
|
||||||
};
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Configuration function for the button sensor for all buttons.
|
|
||||||
*
|
|
||||||
* \param type This function does nothing unless type == SENSORS_ACTIVE
|
|
||||||
* \param c 0: disable the button, non-zero: enable
|
|
||||||
* \param key: One of BOARD_KEY_LEFT, BOARD_KEY_RIGHT etc
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Configuration function for the left button.
|
|
||||||
*
|
|
||||||
* Parameters are passed onto config_buttons, which does the actual
|
|
||||||
* configuration
|
|
||||||
* Parameters are ignored. They have been included because the prototype is
|
|
||||||
* dictated by the core sensor API. The return value is also required by
|
|
||||||
* the API but otherwise ignored.
|
|
||||||
*
|
|
||||||
* \param type passed to config_buttons as-is
|
|
||||||
* \param value passed to config_buttons as-is
|
|
||||||
*
|
|
||||||
* \return ignored
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
config_left(int type, int value)
|
|
||||||
{
|
|
||||||
config_buttons(type, value, BOARD_IOID_KEY_LEFT);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Configuration function for the right button.
|
|
||||||
*
|
|
||||||
* Parameters are passed onto config_buttons, which does the actual
|
|
||||||
* configuration
|
|
||||||
* Parameters are ignored. They have been included because the prototype is
|
|
||||||
* dictated by the core sensor api. The return value is also required by
|
|
||||||
* the API but otherwise ignored.
|
|
||||||
*
|
|
||||||
* \param type passed to config_buttons as-is
|
|
||||||
* \param value passed to config_buttons as-is
|
|
||||||
*
|
|
||||||
* \return ignored
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
config_right(int type, int value)
|
|
||||||
{
|
|
||||||
config_buttons(type, value, BOARD_IOID_KEY_RIGHT);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Status function for all buttons
|
|
||||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
|
||||||
* \param key_io_id BOARD_IOID_KEY_LEFT, BOARD_IOID_KEY_RIGHT etc
|
|
||||||
* \return 1 if the button's port interrupt is enabled (edge detect)
|
|
||||||
*
|
|
||||||
* This function will only be called by status_left, status_right and the
|
|
||||||
* called will pass the correct key_io_id
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
status(int type, uint32_t key_io_id)
|
|
||||||
{
|
|
||||||
switch(type) {
|
|
||||||
case SENSORS_ACTIVE:
|
|
||||||
case SENSORS_READY:
|
|
||||||
if(ti_lib_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;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Status function for the left button.
|
|
||||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
|
||||||
* \return 1 if the button's port interrupt is enabled (edge detect)
|
|
||||||
*
|
|
||||||
* This function will call status. It will pass type verbatim and it will also
|
|
||||||
* pass the correct key_io_id
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
status_left(int type)
|
|
||||||
{
|
|
||||||
return status(type, BOARD_IOID_KEY_LEFT);
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Status function for the right button.
|
|
||||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
|
||||||
* \return 1 if the button's port interrupt is enabled (edge detect)
|
|
||||||
*
|
|
||||||
* This function will call status. It will pass type verbatim and it will also
|
|
||||||
* pass the correct key_io_id
|
|
||||||
*/
|
|
||||||
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);
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/** @} */
|
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2014, 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 sensortag-cc26xx-peripherals
|
|
||||||
* @{
|
|
||||||
*
|
|
||||||
* \defgroup sensortag-cc26xx-button-sensor SensorTag 2.0 Button Sensor
|
|
||||||
*
|
|
||||||
* One of the buttons can be configured as general purpose or as an on/off key
|
|
||||||
* @{
|
|
||||||
*
|
|
||||||
* \file
|
|
||||||
* Header file for the Sensortag 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_ */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
* @}
|
|
||||||
*/
|
|
@ -238,6 +238,17 @@
|
|||||||
#define SMARTRF_SETTINGS_CONF_OVERRIDE_TRIM_OFFSET 0x00018883
|
#define SMARTRF_SETTINGS_CONF_OVERRIDE_TRIM_OFFSET 0x00018883
|
||||||
/** @} */
|
/** @} */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \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
|
||||||
|
#define BOARD_BUTTON_HAL_INDEX_REED_RELAY 0xFF
|
||||||
|
/** @} */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* \name Device string used on startup
|
* \name Device string used on startup
|
||||||
* @{
|
* @{
|
||||||
|
@ -218,6 +218,17 @@
|
|||||||
#define BOARD_IOID_AUDIO_CLK IOID_11
|
#define BOARD_IOID_AUDIO_CLK IOID_11
|
||||||
/** @} */
|
/** @} */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \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
|
||||||
|
#define BOARD_BUTTON_HAL_INDEX_REED_RELAY 0xFF
|
||||||
|
/** @} */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* \name Device string used on startup
|
* \name Device string used on startup
|
||||||
* @{
|
* @{
|
||||||
|
@ -1,145 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2014, 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 sensortag-cc26xx-reed-relay
|
|
||||||
* @{
|
|
||||||
*
|
|
||||||
* \file
|
|
||||||
* Driver for the Sensortag Reed Relay
|
|
||||||
*/
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#include "contiki.h"
|
|
||||||
#include "sys/clock.h"
|
|
||||||
#include "sys/timer.h"
|
|
||||||
#include "dev/gpio-hal.h"
|
|
||||||
#include "lib/sensors.h"
|
|
||||||
#include "sensortag/reed-relay.h"
|
|
||||||
#include "sys/timer.h"
|
|
||||||
|
|
||||||
#include "ti-lib.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static struct timer debouncetimer;
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#define REED_IO_CFG (IOC_CURRENT_2MA | IOC_STRENGTH_AUTO | \
|
|
||||||
IOC_IOPULL_DOWN | IOC_SLEW_DISABLE | \
|
|
||||||
IOC_HYST_DISABLE | IOC_BOTH_EDGES | \
|
|
||||||
IOC_INT_DISABLE | IOC_IOMODE_NORMAL | \
|
|
||||||
IOC_NO_WAKE_UP | IOC_INPUT_ENABLE)
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Handler for Sensortag-CC26XX reed interrupts
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
reed_interrupt_handler(gpio_hal_pin_mask_t pin_mask)
|
|
||||||
{
|
|
||||||
if(!timer_expired(&debouncetimer)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sensors_changed(&reed_relay_sensor);
|
|
||||||
timer_set(&debouncetimer, CLOCK_SECOND / 2);
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static int
|
|
||||||
value(int type)
|
|
||||||
{
|
|
||||||
return (int)ti_lib_gpio_read_dio(BOARD_IOID_REED_RELAY);
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static gpio_hal_event_handler_t event_handler = {
|
|
||||||
.next = NULL,
|
|
||||||
.handler = reed_interrupt_handler,
|
|
||||||
.pin_mask = gpio_hal_pin_to_mask(BOARD_IOID_REED_RELAY),
|
|
||||||
};
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Configuration function for the button sensor for all buttons.
|
|
||||||
*
|
|
||||||
* \param type SENSORS_HW_INIT: Initialise. SENSORS_ACTIVE: Enables/Disables
|
|
||||||
* depending on 'value'
|
|
||||||
* \param value 0: disable, non-zero: enable
|
|
||||||
* \return Always returns 1
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
configure(int type, int value)
|
|
||||||
{
|
|
||||||
switch(type) {
|
|
||||||
case SENSORS_HW_INIT:
|
|
||||||
ti_lib_ioc_int_disable(BOARD_IOID_REED_RELAY);
|
|
||||||
ti_lib_gpio_clear_event_dio(BOARD_IOID_REED_RELAY);
|
|
||||||
|
|
||||||
/* Enable the GPIO clock when the CM3 is running */
|
|
||||||
ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_GPIO);
|
|
||||||
|
|
||||||
/* S/W control, input, pull-down */
|
|
||||||
ti_lib_ioc_port_configure_set(BOARD_IOID_REED_RELAY, IOC_PORT_GPIO,
|
|
||||||
REED_IO_CFG);
|
|
||||||
|
|
||||||
gpio_hal_register_handler(&event_handler);
|
|
||||||
break;
|
|
||||||
case SENSORS_ACTIVE:
|
|
||||||
if(value) {
|
|
||||||
ti_lib_ioc_int_enable(BOARD_IOID_REED_RELAY);
|
|
||||||
} else {
|
|
||||||
ti_lib_ioc_int_disable(BOARD_IOID_REED_RELAY);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Status function for the reed
|
|
||||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
|
||||||
* \return 1 Interrupt enabled, 0: Disabled
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
status(int type)
|
|
||||||
{
|
|
||||||
switch(type) {
|
|
||||||
case SENSORS_ACTIVE:
|
|
||||||
case SENSORS_READY:
|
|
||||||
return (ti_lib_ioc_port_configure_get(BOARD_IOID_REED_RELAY)
|
|
||||||
& IOC_INT_ENABLE) == IOC_INT_ENABLE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
SENSORS_SENSOR(reed_relay_sensor, "REED", value, configure, status);
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/** @} */
|
|
@ -37,19 +37,16 @@
|
|||||||
*/
|
*/
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
#include "sensortag/button-sensor.h"
|
|
||||||
#include "sensortag/bmp-280-sensor.h"
|
#include "sensortag/bmp-280-sensor.h"
|
||||||
#include "sensortag/tmp-007-sensor.h"
|
#include "sensortag/tmp-007-sensor.h"
|
||||||
#include "sensortag/opt-3001-sensor.h"
|
#include "sensortag/opt-3001-sensor.h"
|
||||||
#include "sensortag/hdc-1000-sensor.h"
|
#include "sensortag/hdc-1000-sensor.h"
|
||||||
#include "sensortag/mpu-9250-sensor.h"
|
#include "sensortag/mpu-9250-sensor.h"
|
||||||
#include "sensortag/reed-relay.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \brief Exports a global symbol to be used by the sensor API */
|
/** \brief Exports a global symbol to be used by the sensor API */
|
||||||
SENSORS(&button_left_sensor, &button_right_sensor,
|
SENSORS(&bmp_280_sensor, &tmp_007_sensor, &opt_3001_sensor, &hdc_1000_sensor,
|
||||||
&bmp_280_sensor, &tmp_007_sensor, &opt_3001_sensor, &hdc_1000_sensor,
|
&mpu_9250_sensor);
|
||||||
&mpu_9250_sensor, &reed_relay_sensor);
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** @} */
|
/** @} */
|
||||||
|
Loading…
Reference in New Issue
Block a user