47 #include "dev/button-sensor.h"
55 #define BUTTON_USER_PORT_BASE GPIO_PORT_TO_BASE(BUTTON_USER_PORT)
56 #define BUTTON_USER_PIN_MASK GPIO_PIN_MASK(BUTTON_USER_PIN)
58 #define DEBOUNCE_DURATION (CLOCK_SECOND >> 4)
60 static struct timer debouncetimer;
62 static clock_time_t press_duration = 0;
63 static struct ctimer press_counter;
64 static uint8_t press_event_counter;
66 process_event_t button_press_duration_exceeded;
69 duration_exceeded_callback(
void *data)
71 press_event_counter++;
72 process_post(PROCESS_BROADCAST, button_press_duration_exceeded,
73 &press_event_counter);
74 ctimer_set(&press_counter, press_duration, duration_exceeded_callback,
89 case BUTTON_SENSOR_VALUE_TYPE_LEVEL:
90 return GPIO_READ_PIN(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
91 case BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION:
92 return press_event_counter;
115 press_event_counter = 0;
116 if(
value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) == BUTTON_SENSOR_PRESSED_LEVEL) {
117 ctimer_set(&press_counter, press_duration, duration_exceeded_callback,
139 case SENSORS_HW_INIT:
167 case BUTTON_SENSOR_CONFIG_TYPE_INTERVAL:
168 press_duration = (clock_time_t)value;
#define DEBOUNCE_DURATION
Delay before button state is assumed to be stable.
#define GPIO_ENABLE_INTERRUPT(PORT_BASE, PIN_MASK)
Enable interrupt triggering for pins with PIN_MASK of port with PORT_BASE.
#define GPIO_SET_INPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to input.
#define IOC_OVERRIDE_PUE
Pull Up Enable.
#define GPIO_DETECT_EDGE(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to detect edge.
Timer library header file.
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
Header file for the ARM Nested Vectored Interrupt Controller.
static int config_user(int type, int value)
Init function for the User button.
static void btn_callback(uint8_t port, uint8_t pin)
Callback registered with the GPIO module.
#define GPIO_READ_PIN(PORT_BASE, PIN_MASK)
Read pins with PIN_MASK of port with PORT_BASE.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
process_event_t process_alloc_event(void)
Allocate a global event number.
const struct sensors_sensor button_sensor
Copyright (c) 2014, Analog Devices, Inc.
Header file for the callback timer
#define NULL
The null pointer.
Header file with declarations for the I/O Control module.
static int value(int type)
Retrieves the value of the button pin.
#define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK)
Configure the pin to be software controlled with PIN_MASK of port with PORT_BASE. ...
#define BUTTON_USER_PORT
BUTTON_USER -> PC3.
#define GPIO_TRIGGER_BOTH_EDGES(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to trigger an interrupt on both edges.
Header file for the Contiki process interface.
void nvic_interrupt_enable(uint32_t intr)
Enables interrupt intr.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
void nvic_interrupt_disable(uint32_t intr)
Disables interrupt intr.
#define GPIO_DISABLE_INTERRUPT(PORT_BASE, PIN_MASK)
Disable interrupt triggering for pins with PIN_MASK of port with PORT_BASE.
void ctimer_stop(struct ctimer *c)
Stop a pending callback timer.
void ioc_set_over(uint8_t port, uint8_t pin, uint8_t over)
Set Port:Pin override function.
void gpio_register_callback(gpio_callback_t f, uint8_t port, uint8_t pin)
Register GPIO callback.
int timer_expired(struct timer *t)
Check if a timer has expired.