43#include "sys/critical.h"
51PROCESS(button_hal_process,
"Button HAL process");
58#if GPIO_HAL_PORT_PIN_NUMBERING
59static volatile uint8_t port_mask;
65#define PORT_UNUSED 0xFF
71#if GPIO_HAL_PORT_PIN_NUMBERING
72#define BTN_PORT(b) (b)->port
74#define BTN_PORT(b) GPIO_HAL_NULL_PORT
78duration_exceeded_callback(
void *btn)
82 button->press_duration_seconds++;
84 duration_exceeded_callback, button);
89debounce_handler(
void *btn)
113 if(button_state == BUTTON_HAL_STATE_PRESSED && expired) {
120 button->press_duration_seconds = 0;
123 duration_exceeded_callback, button);
125 }
else if(button_state == BUTTON_HAL_STATE_RELEASED && expired == 0) {
136press_release_handler(
143#if GPIO_HAL_PORT_PIN_NUMBERING
144 port_mask |= (1 << port);
150get_handler_by_port(uint8_t port)
152#if GPIO_HAL_PORT_PIN_NUMBERING
157 if(button_event_handlers[i].port == port) {
158 return &button_event_handlers[i];
164 if(button_event_handlers[i].port == PORT_UNUSED) {
165 return &button_event_handlers[i];
171 return &button_event_handlers[0];
180 for(button = button_hal_buttons; *button != NULL; button++) {
181 if((*button)->unique_id == unique_id) {
196 return button_hal_buttons[index];
202 uint8_t pin_state = gpio_hal_arch_read_pin(BTN_PORT(button), button->pin);
204 if((pin_state == 0 && button->negative_logic ==
true) ||
205 (pin_state == 1 && button->negative_logic ==
false)) {
206 return BUTTON_HAL_STATE_PRESSED;
209 return BUTTON_HAL_STATE_RELEASED;
225#if GPIO_HAL_PORT_PIN_NUMBERING
226 button_event_handlers[i].port = PORT_UNUSED;
228 button_event_handlers[i].pin_mask = 0;
229 button_event_handlers[i].handler = press_release_handler;
232 for(button = button_hal_buttons; *button != NULL; button++) {
233 cfg = GPIO_HAL_PIN_CFG_EDGE_BOTH | GPIO_HAL_PIN_CFG_INT_ENABLE |
235 gpio_hal_arch_pin_set_input(BTN_PORT(*button), (*button)->pin);
236 gpio_hal_arch_pin_cfg_set(BTN_PORT(*button), (*button)->pin, cfg);
237 gpio_hal_arch_interrupt_enable(BTN_PORT(*button), (*button)->pin);
239 handler = get_handler_by_port(BTN_PORT(*button));
242#if GPIO_HAL_PORT_PIN_NUMBERING
243 handler->port = BTN_PORT(*button);
261#if GPIO_HAL_PORT_PIN_NUMBERING
273#if GPIO_HAL_PORT_PIN_NUMBERING
279 for(button = button_hal_buttons; *button != NULL; button++) {
282 && ((1 << (*button)->port) & ports)
295 debounce_handler, *button);
Header file for the callback timer.
Header file for the GPIO HAL.
#define CLOCK_SECOND
A second, measured in system clock time.
static void critical_exit(int_master_status_t status)
Exit a critical section and restore the master interrupt.
static int_master_status_t critical_enter()
Enter a critical section.
void ctimer_stop(struct ctimer *c)
Stop a pending callback timer.
bool ctimer_expired(struct ctimer *c)
Check if a callback timer has expired.
static void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
void gpio_hal_register_handler(gpio_hal_event_handler_t *handler)
Register a function to be called whenever a pin triggers an event.
uint32_t gpio_hal_pin_mask_t
GPIO pin mask representation.
uint32_t gpio_hal_pin_cfg_t
GPIO pin configuration.
uint8_t gpio_hal_port_t
A data structure that represents ports.
#define gpio_hal_pin_to_mask(pin)
Convert a pin to a pin mask.
#define GPIO_HAL_PORT_PIN_NUMBERING
Specifies whether the HAL should support a port/pin convention.
uint32_t int_master_status_t
Master interrupt state representation data type.
#define PROCESS(name, strname)
Declare a process.
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.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_END()
Define the end of a process.
void process_start(struct process *p, process_data_t data)
Start a process.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
void process_poll(struct process *p)
Request a process to be polled.
Header file for the Contiki process interface.
Datatype for GPIO event handlers.