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 sel_timer, left_timer, right_timer, up_timer,
79 if(ioid == BOARD_IOID_KEY_SELECT) {
90 if(ti_lib_gpio_pin_read(BOARD_KEY_SELECT) == 0) {
92 sel_timer.duration = 0;
94 sel_timer.duration =
clock_time() - sel_timer.start;
99 if(ioid == BOARD_IOID_KEY_LEFT) {
110 if(ti_lib_gpio_pin_read(BOARD_KEY_LEFT) == 0) {
112 left_timer.duration = 0;
114 left_timer.duration =
clock_time() - left_timer.start;
119 if(ioid == BOARD_IOID_KEY_RIGHT) {
120 if(BUTTON_SENSOR_ENABLE_SHUTDOWN == 0) {
131 if(ti_lib_gpio_pin_read(BOARD_KEY_RIGHT) == 0) {
133 right_timer.duration = 0;
135 right_timer.duration =
clock_time() - right_timer.start;
136 sensors_changed(&button_right_sensor);
139 lpm_shutdown(BOARD_IOID_KEY_RIGHT, IOC_IOPULL_UP, IOC_WAKE_ON_LOW);
143 if(ioid == BOARD_IOID_KEY_UP) {
154 if(ti_lib_gpio_pin_read(BOARD_KEY_UP) == 0) {
156 up_timer.duration = 0;
158 up_timer.duration =
clock_time() - up_timer.start;
159 sensors_changed(&button_up_sensor);
163 if(ioid == BOARD_IOID_KEY_DOWN) {
174 if(ti_lib_gpio_pin_read(BOARD_KEY_DOWN) == 0) {
176 down_timer.duration = 0;
178 down_timer.duration =
clock_time() - down_timer.start;
179 sensors_changed(&button_down_sensor);
195 case SENSORS_HW_INIT:
196 ti_lib_gpio_event_clear(1 << key);
197 ti_lib_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG);
198 ti_lib_gpio_dir_mode_set((1 << key), GPIO_DIR_MODE_IN);
203 ti_lib_gpio_event_clear(1 << key);
204 ti_lib_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG);
205 ti_lib_gpio_dir_mode_set((1 << key), GPIO_DIR_MODE_IN);
206 ti_lib_ioc_int_enable(key);
208 ti_lib_ioc_int_disable(key);
327 value_select(
int type)
330 return ti_lib_gpio_pin_read(BOARD_KEY_SELECT) == 0 ?
331 BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
333 return (
int)sel_timer.duration;
342 return ti_lib_gpio_pin_read(BOARD_KEY_LEFT) == 0 ?
343 BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
345 return (
int)left_timer.duration;
351 value_right(
int type)
354 return ti_lib_gpio_pin_read(BOARD_KEY_RIGHT) == 0 ?
355 BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
357 return (
int)right_timer.duration;
366 return ti_lib_gpio_pin_read(BOARD_KEY_UP) == 0 ?
367 BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
369 return (
int)up_timer.duration;
378 return ti_lib_gpio_pin_read(BOARD_KEY_DOWN) == 0 ?
379 BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
381 return (
int)down_timer.duration;
401 if(ti_lib_ioc_port_configure_get(key_io_id) & IOC_INT_ENABLE) {
422 return status(type, BOARD_IOID_KEY_SELECT);
436 return status(type, BOARD_IOID_KEY_LEFT);
450 return status(type, BOARD_IOID_KEY_RIGHT);
464 return status(type, BOARD_IOID_KEY_UP);
478 return status(type, BOARD_IOID_KEY_DOWN);
485 SENSORS_SENSOR(button_right_sensor, BUTTON_SENSOR, value_right,
config_right,
488 SENSORS_SENSOR(button_down_sensor, BUTTON_SENSOR, value_down,
config_down,
#define DEBOUNCE_DURATION
Delay before button state is assumed to be stable.
static int status_right(int type)
Status function for the right button.
static void button_press_handler(uint8_t ioid)
Handler for SmartRF button presses.
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.
Header file for the SmartRF06EB + CC13xx/CC26xxEM Button Driver.
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.
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
static void config_buttons(int type, int c, uint32_t key)
Configuration function for the button sensor for all buttons.
static int status_down(int type)
Status function for the down button.
static int status_up(int type)
Status function for the up button.
static int status_left(int type)
Status function for the left button.
Header file for the CC13xx/CC26xx GPIO interrupt management.
static int config_down(int type, int value)
Configuration function for the down button.
static int status_select(int type)
Status function for the select button.
#define BUTTON_SENSOR_VALUE_STATE
Can be passed to value() function to get current button state.
void gpio_interrupt_register_handler(uint8_t ioid, gpio_interrupt_handler_t f)
Register a GPIO interrupt handler.
const struct sensors_sensor button_select_sensor
Exports a global symbol to be used by the sensor API.
static int config_up(int type, int value)
Configuration function for the up button.
static int config_left(int type, int value)
Configuration function for the left button.
static int config_right(int type, int value)
Configuration function for the right button.
static int status(int type, uint32_t key_io_id)
Status function for all buttons.
static int value(int type, nrf_drv_gpiote_pin_t pin)
Return current state of a button.
int timer_expired(struct timer *t)
Check if a timer has expired.
static int config_select(int type, int value)
Configuration function for the select button.