diff options
author | Keith Packard <keithp@keithp.com> | 2011-10-23 14:08:59 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2011-10-23 14:08:59 -0700 |
commit | 7e7a10c06a0486e9f869e361e46f2c98db9897b0 (patch) | |
tree | fda3c3f704dcf30b75154853f7fdc19902346a8b /src/cc1111/ao_button.c | |
parent | 8e2736226fcd7c1ab1ba93a5ebac9b285ebf4733 (diff) |
altos: Add button driver and sample user
Hook up the teleterra buttons and have them beep
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/cc1111/ao_button.c')
-rw-r--r-- | src/cc1111/ao_button.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/cc1111/ao_button.c b/src/cc1111/ao_button.c new file mode 100644 index 00000000..547d71ac --- /dev/null +++ b/src/cc1111/ao_button.c @@ -0,0 +1,86 @@ +/* + * Copyright © 2011 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include "ao.h" + +volatile __xdata struct ao_fifo ao_button_fifo; + +#define BUTTON_1_PIN (P0_4) +#define BUTTON_1_MASK (1 << 4) /* P0_4 */ + +#define BUTTON_2_PIN (P2_3) +#define BUTTON_2_MASK (1 << 3) /* P2_3 */ + +#define BUTTON_3_PIN (P2_4) +#define BUTTON_3_MASK (1 << 4) /* P2_4 */ + +static void +ao_button_insert(char n) +{ + ao_fifo_insert(ao_button_fifo, n); + ao_wakeup(&ao_button_fifo); +} + +char +ao_button_get(void) __critical +{ + char b; + + while (ao_fifo_empty(ao_button_fifo)) + ao_sleep(&ao_button_fifo); + ao_fifo_remove(ao_button_fifo, b); + return b; +} + +void +ao_p2_isr(void) +{ + if (P2IFG & BUTTON_2_MASK) + ao_button_insert(2); + if (P2IFG & BUTTON_3_MASK) + ao_button_insert(3); + P2IFG = 0; +} + +void +ao_p0_isr(void) ao_arch_interrupt(13) +{ + P0IF = 0; + if (P0IFG & BUTTON_1_MASK) + ao_button_insert(1); + P0IFG = 0; +} + +void +ao_button_init(void) +{ + /* Pins are configured as inputs with pull-up by default */ + + /* Enable interrupts for P2_0 - P2_4 + * Enable interrupts for P0_4 - P0_7 + * Set P2 interrupts to falling edge + * Set P0 interrupts to falling edge + */ + + PICTL |= PICTL_P2IEN | PICTL_P0IENH | PICTL_P2ICON | PICTL_P0ICON; + + /* Enable interrupts for P0 inputs */ + IEN1 |= IEN1_P0IE; + + /* Enable interrupts for P2 inputs */ + IEN2 |= IEN2_P2IE; +} |