32 #include "dev/button.h"
33 #include "isr_compat.h"
38 static struct button_msg button_msg;
40 static struct process *selecting_proc;
43 button_init(
struct process *proc)
45 button_msg.type = BUTTON_MSG_TYPE;
47 P2DIR &= ~BV(BUTTON_PIN);
48 P2SEL &= ~BV(BUTTON_PIN);
50 P2IES |= BV(BUTTON_PIN);
51 P2IFG &= ~BV(BUTTON_PIN);
53 selecting_proc = proc;
55 P2IE |= BV(BUTTON_PIN);
57 P2IE &= ~BV(BUTTON_PIN);
60 ISR(PORT2, __button_interrupt)
62 static struct timer debouncetimer;
64 P2IFG &= ~BV(BUTTON_PIN);
66 button_msg.value = P2IN & BV(BUTTON_PIN);
68 if(selecting_proc !=
NULL) {
69 process_post(selecting_proc, PROCESS_EVENT_MSG, &button_msg);
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
#define NULL
The null pointer.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
int timer_expired(struct timer *t)
Check if a timer has expired.
#define CLOCK_SECOND
A second, measured in system clock time.