43 #include "sys/critical.h" 51 PROCESS(button_hal_process,
"Button HAL process");
66 duration_exceeded_callback(
void *btn)
70 button->press_duration_seconds++;
72 duration_exceeded_callback, button);
77 debounce_handler(
void *btn)
101 if(button_state == BUTTON_HAL_STATE_PRESSED && expired) {
108 button->press_duration_seconds = 0;
111 duration_exceeded_callback, button);
113 }
else if(button_state == BUTTON_HAL_STATE_RELEASED && expired == 0) {
135 for(button = button_hal_buttons; *button != NULL; button++) {
136 if((*button)->unique_id == unique_id) {
151 return button_hal_buttons[index];
157 uint8_t pin_state = gpio_hal_arch_read_pin(button->pin);
159 if((pin_state == 0 && button->negative_logic ==
true) ||
160 (pin_state == 1 && button->negative_logic ==
false)) {
161 return BUTTON_HAL_STATE_PRESSED;
164 return BUTTON_HAL_STATE_RELEASED;
177 button_event_handler.pin_mask = 0;
178 button_event_handler.handler = press_release_handler;
180 for(button = button_hal_buttons; *button != NULL; button++) {
181 cfg = GPIO_HAL_PIN_CFG_EDGE_BOTH | GPIO_HAL_PIN_CFG_INT_ENABLE |
183 gpio_hal_arch_pin_set_input((*button)->pin);
185 gpio_hal_arch_interrupt_enable((*button)->pin);
210 for(button = button_hal_buttons; *button != NULL; button++) {
222 debounce_handler, *button);
Datatype for GPIO event handlers.
int ctimer_expired(struct ctimer *c)
Check if a callback timer has expired.
#define PROCESS(name, strname)
Declare a process.
void ctimer_stop(struct ctimer *c)
Stop a pending callback timer.
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
#define PROCESS_BEGIN()
Define the beginning of a process.
static void critical_exit(int_master_status_t status)
Exit a critical section and restore the master interrupt.
#define PROCESS_END()
Define the end of a process.
static int_master_status_t critical_enter()
Enter a critical section.
void gpio_hal_register_handler(gpio_hal_event_handler_t *handler)
Register a function to be called whenever a pin triggers an event.
INT_MASTER_STATUS_DATATYPE int_master_status_t
Master interrupt state representation data type.
#define CLOCK_SECOND
A second, measured in system clock time.
Header file for the callback timer
void process_poll(struct process *p)
Request a process to be polled.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
Header file for the Contiki process interface.
process_event_t process_alloc_event(void)
Allocate a global event number.
uint32_t gpio_hal_pin_mask_t
GPIO pin mask representation.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
#define gpio_hal_pin_to_mask(pin)
Convert a pin to a pin mask.
Header file for the GPIO HAL.
uint32_t gpio_hal_pin_cfg_t
GPIO pin configuration.
void gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
Configure a gpio pin.
void process_start(struct process *p, process_data_t data)
Start a process.