40 #include "lib/sensors.h"
50 #ifdef BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN
51 #define BUTTON_SENSOR_ENABLE_SHUTDOWN BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN
53 #define BUTTON_SENSOR_ENABLE_SHUTDOWN 1
56 #define BUTTON_GPIO_CFG (IOC_CURRENT_2MA | IOC_STRENGTH_AUTO | \
57 IOC_IOPULL_UP | IOC_SLEW_DISABLE | \
58 IOC_HYST_DISABLE | IOC_BOTH_EDGES | \
59 IOC_INT_ENABLE | IOC_IOMODE_NORMAL | \
60 IOC_NO_WAKE_UP | IOC_INPUT_ENABLE)
62 #define DEBOUNCE_DURATION (CLOCK_SECOND >> 5)
65 struct timer debounce;
67 clock_time_t duration;
70 static struct btn_timer left_timer, right_timer;
75 if(ioid == BOARD_IOID_KEY_LEFT) {
86 if(ti_lib_gpio_pin_read(BOARD_KEY_LEFT) == 0) {
88 left_timer.duration = 0;
90 left_timer.duration =
clock_time() - left_timer.start;
95 if(ioid == BOARD_IOID_KEY_RIGHT) {
96 if(BUTTON_SENSOR_ENABLE_SHUTDOWN == 0) {
107 if(ti_lib_gpio_pin_read(BOARD_KEY_RIGHT) == 0) {
109 right_timer.duration = 0;
111 right_timer.duration =
clock_time() - right_timer.start;
112 sensors_changed(&button_right_sensor);
115 lpm_shutdown(BOARD_IOID_KEY_RIGHT, IOC_IOPULL_UP, IOC_WAKE_ON_LOW);
124 case SENSORS_HW_INIT:
125 ti_lib_gpio_event_clear(1 << key);
126 ti_lib_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG);
127 ti_lib_gpio_dir_mode_set((1 << key), GPIO_DIR_MODE_IN);
132 ti_lib_gpio_event_clear(1 << key);
133 ti_lib_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG);
134 ti_lib_gpio_dir_mode_set((1 << key), GPIO_DIR_MODE_IN);
135 ti_lib_ioc_int_enable(key);
137 ti_lib_ioc_int_disable(key);
162 status(
int type, uint32_t key_io_id)
167 if(ti_lib_ioc_port_configure_get(key_io_id) & IOC_INT_ENABLE) {
181 return ti_lib_gpio_pin_read(BOARD_KEY_LEFT) == 0 ?
182 BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
184 return (
int)left_timer.duration;
190 value_right(
int type)
193 return ti_lib_gpio_pin_read(BOARD_KEY_RIGHT) == 0 ?
194 BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
196 return (
int)right_timer.duration;
204 return status(type, BOARD_IOID_KEY_LEFT);
210 return status(type, BOARD_IOID_KEY_RIGHT);
215 SENSORS_SENSOR(button_right_sensor, BUTTON_SENSOR, value_right,
config_right,
#define DEBOUNCE_DURATION
Delay before button state is assumed to be stable.
static void start(void)
Start measurement.
const struct sensors_sensor button_left_sensor
Exports a global symbol to be used by the sensor API.
Header file with macros which rename TI CC26xxware functions.
void lpm_shutdown(uint32_t wakeup_pin, uint32_t io_pull, uint32_t wake_on)
Put the chip in shutdown power mode.
Timer library header file.
CCIF clock_time_t clock_time(void)
Get the current clock time.
#define BUTTON_SENSOR_VALUE_DURATION
Can be passed to value() function to get low state duration.
static void button_press_handler(uint8_t ioid)
Handler for Sensortag-CC26XX button presses.
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
Header file for the CC13xx/CC26xx GPIO interrupt management.
static int config_right(int type, int value)
Init function for the right button.
#define BUTTON_SENSOR_VALUE_STATE
Can be passed to value() function to get current button state.
static int status_left(int type)
Status function for the left button.
void gpio_interrupt_register_handler(uint8_t ioid, gpio_interrupt_handler_t f)
Register a GPIO interrupt handler.
Header file for the LaunchPad Button Driver.
static void config_buttons(int type, int c, uint32_t key)
Configuration function for the button sensor for all buttons.
static int config_left(int type, int value)
Init function for the left button.
static int value(int type, nrf_drv_gpiote_pin_t pin)
Return current state of a button.
static int status_right(int type)
Status function for the right button.
int timer_expired(struct timer *t)
Check if a timer has expired.