43 #include "sys/critical.h" 51 PROCESS(button_hal_process,
"Button HAL process");
65 #if GPIO_HAL_PORT_PIN_NUMBERING 66 #define BTN_PORT(b) (b)->port 68 #define BTN_PORT(b) GPIO_HAL_NULL_PORT 72 duration_exceeded_callback(
void *btn)
76 button->press_duration_seconds++;
78 duration_exceeded_callback, button);
83 debounce_handler(
void *btn)
107 if(button_state == BUTTON_HAL_STATE_PRESSED && expired) {
114 button->press_duration_seconds = 0;
117 duration_exceeded_callback, button);
119 }
else if(button_state == BUTTON_HAL_STATE_RELEASED && expired == 0) {
130 press_release_handler(
145 for(button = button_hal_buttons; *button != NULL; button++) {
146 if((*button)->unique_id == unique_id) {
161 return button_hal_buttons[index];
167 uint8_t pin_state = gpio_hal_arch_read_pin(BTN_PORT(button), button->pin);
169 if((pin_state == 0 && button->negative_logic ==
true) ||
170 (pin_state == 1 && button->negative_logic ==
false)) {
171 return BUTTON_HAL_STATE_PRESSED;
174 return BUTTON_HAL_STATE_RELEASED;
187 button_event_handler.pin_mask = 0;
188 button_event_handler.handler = press_release_handler;
190 for(button = button_hal_buttons; *button != NULL; button++) {
191 cfg = GPIO_HAL_PIN_CFG_EDGE_BOTH | GPIO_HAL_PIN_CFG_INT_ENABLE |
193 gpio_hal_arch_pin_set_input(BTN_PORT(*button), (*button)->pin);
194 gpio_hal_arch_pin_cfg_set(BTN_PORT(*button), (*button)->pin, cfg);
195 gpio_hal_arch_interrupt_enable(BTN_PORT(*button), (*button)->pin);
220 for(button = button_hal_buttons; *button != NULL; button++) {
232 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.
uint8_t gpio_hal_port_t
A data structure that represents ports.
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.
#define GPIO_HAL_PORT_PIN_NUMBERING
Specifies whether the HAL should support a port/pin convention.
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 process_start(struct process *p, process_data_t data)
Start a process.