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;
78 if(ioid == BOARD_IOID_KEY_LEFT) {
89 if(ti_lib_gpio_pin_read(BOARD_KEY_LEFT) == 0) {
91 left_timer.duration = 0;
93 left_timer.duration =
clock_time() - left_timer.start;
98 if(ioid == BOARD_IOID_KEY_RIGHT) {
99 if(BUTTON_SENSOR_ENABLE_SHUTDOWN == 0) {
110 if(ti_lib_gpio_pin_read(BOARD_KEY_RIGHT) == 0) {
112 right_timer.duration = 0;
114 right_timer.duration =
clock_time() - right_timer.start;
115 sensors_changed(&button_right_sensor);
118 lpm_shutdown(BOARD_IOID_KEY_RIGHT, IOC_IOPULL_UP, IOC_WAKE_ON_LOW);
134 case SENSORS_HW_INIT:
135 ti_lib_gpio_event_clear(1 << key);
136 ti_lib_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG);
137 ti_lib_gpio_dir_mode_set((1 << key), GPIO_DIR_MODE_IN);
142 ti_lib_gpio_event_clear(1 << key);
143 ti_lib_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG);
144 ti_lib_gpio_dir_mode_set((1 << key), GPIO_DIR_MODE_IN);
145 ti_lib_ioc_int_enable(key);
147 ti_lib_ioc_int_disable(key);
214 if(ti_lib_ioc_port_configure_get(key_io_id) & IOC_INT_ENABLE) {
228 return ti_lib_gpio_pin_read(BOARD_KEY_LEFT) == 0 ?
229 BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
231 return (
int)left_timer.duration;
237 value_right(
int type)
240 return ti_lib_gpio_pin_read(BOARD_KEY_RIGHT) == 0 ?
241 BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
243 return (
int)right_timer.duration;
259 return status(type, BOARD_IOID_KEY_LEFT);
273 return status(type, BOARD_IOID_KEY_RIGHT);
278 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.
static int config_right(int type, int value)
Configuration function for the right button.
static int config_left(int type, int value)
Configuration function for the left button.
static int status(int type, uint32_t key_io_id)
Status function for all buttons.
Header file for the CC13xx/CC26xx GPIO interrupt management.
Header file for the Sensortag-CC26xx Button Driver.
#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.
static void config_buttons(int type, int c, uint32_t key)
Configuration function for the button sensor for all buttons.
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.