2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 volatile __xdata struct ao_fifo ao_button_fifo;
22 #define BUTTON_1_PIN (P0_4)
23 #define BUTTON_1_MASK (1 << 4) /* P0_4 */
25 #define BUTTON_2_PIN (P2_3)
26 #define BUTTON_2_MASK (1 << 3) /* P2_3 */
28 #define BUTTON_3_PIN (P2_4)
29 #define BUTTON_3_MASK (1 << 4) /* P2_4 */
32 ao_button_insert(char n)
34 ao_fifo_insert(ao_button_fifo, n);
35 ao_wakeup(&ao_button_fifo);
39 ao_button_get(void) __critical
43 while (ao_fifo_empty(ao_button_fifo))
44 ao_sleep(&ao_button_fifo);
45 ao_fifo_remove(ao_button_fifo, b);
52 if (P2IFG & BUTTON_2_MASK)
54 if (P2IFG & BUTTON_3_MASK)
60 ao_p0_isr(void) ao_arch_interrupt(13)
63 if (P0IFG & BUTTON_1_MASK)
71 /* Pins are configured as inputs with pull-up by default */
73 /* Enable interrupts for P2_0 - P2_4
74 * Enable interrupts for P0_4 - P0_7
75 * Set P2 interrupts to falling edge
76 * Set P0 interrupts to falling edge
79 PICTL |= PICTL_P2IEN | PICTL_P0IENH | PICTL_P2ICON | PICTL_P0ICON;
81 /* Enable interrupts for P0 inputs */
84 /* Enable interrupts for P2 inputs */