altos: Add button driver and sample user
authorKeith Packard <keithp@keithp.com>
Sun, 23 Oct 2011 21:08:59 +0000 (14:08 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 23 Oct 2011 21:08:59 +0000 (14:08 -0700)
Hook up the teleterra buttons and have them beep

Signed-off-by: Keith Packard <keithp@keithp.com>
src/cc1111/ao_arch.h
src/cc1111/ao_button.c [new file with mode: 0644]
src/cc1111/ao_usb.c
src/core/ao.h
src/product/ao_teleterra_0_2.c
src/product/ao_terraui.c [new file with mode: 0644]
src/teleterra-v0.2/Makefile
src/teleterra-v0.2/ao_pins.h

index 02e36189a46db634695f24432db10d12c4d04544..23589e660fb08a4fe9f26fb9ac46c8556591408b 100644 (file)
@@ -204,6 +204,21 @@ struct ao_adc {
 
 #define AO_ADC_RING    32
 
+/* ao_button.c */
+void
+ao_p2_isr(void);
+
+void
+ao_button_init(void);
+
+#if HAS_BUTTON_P0
+void
+ao_p0_isr(void) ao_arch_interrupt(13);
+#endif
+
+char
+ao_button_get(void) __critical;
+
 /* ao_string.c */
 
 void
diff --git a/src/cc1111/ao_button.c b/src/cc1111/ao_button.c
new file mode 100644 (file)
index 0000000..547d71a
--- /dev/null
@@ -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;
+}
index 08cb73900c6462fe52d7d8bfafe1b6a28ff47d90..35c9ac20e80fd07a4bd37ecd045a1eeef8210079 100644 (file)
@@ -62,6 +62,9 @@ ao_usb_isr(void) __interrupt 6
        ao_btm_isr();
 #endif
 #endif
+#if HAS_P2_ISR
+       ao_p2_isr();
+#endif
 }
 
 struct ao_usb_setup {
index c800f1fc56e16da4b6e0059da948d296ecdb2479..43d4e0e3ddf84242a7b5265314781986b9607b23 100644 (file)
@@ -1851,4 +1851,11 @@ ao_log_single(void);
 #define ao_xmemcmp(d,s,c) memcmp(d,s,c)
 #endif
 
+/*
+ * ao_terraui.c
+ */
+
+void
+ao_terraui_init(void);
+
 #endif /* _AO_H_ */
index 050858606c5f049de325cc10f52474b24bac6b46..b38f2907d7399d80767793abb7b5d442b55d8002 100644 (file)
@@ -37,5 +37,6 @@ main(void)
        ao_radio_init();
        ao_config_init();
        ao_lcd_init();
+       ao_terraui_init();
        ao_start_scheduler();
 }
diff --git a/src/product/ao_terraui.c b/src/product/ao_terraui.c
new file mode 100644 (file)
index 0000000..3885db4
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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"
+
+static void
+ao_terraui(void)
+{
+       for (;;) {
+               char    b = ao_button_get();
+               switch (b) {
+               case 1:
+                       ao_beep_for(AO_BEEP_LOW, AO_MS_TO_TICKS(200));
+                       break;
+               case 2:
+                       ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200));
+                       break;
+               case 3:
+                       ao_beep_for(AO_BEEP_HIGH, AO_MS_TO_TICKS(200));
+                       break;
+               }
+       }
+}
+
+__xdata static struct ao_task ao_terraui_task;
+
+void
+ao_terraui_init(void)
+{
+       ao_add_task(&ao_terraui_task, ao_terraui, "ui");
+}
index eda67a2a834e4e3299bac79e2b1407ba27e4c70a..8e4569a9a6ff8eecdcc9478541fc6276bbd47dbf 100644 (file)
@@ -33,6 +33,7 @@ CORE_SRC = \
 
 CC1111_SRC = \
        ao_beep.c \
+       ao_button.c \
        ao_dbg.c \
        ao_dma.c \
        ao_led.c \
@@ -54,7 +55,8 @@ DRIVER_SRC = \
        ao_gps_skytraq.c
 
 PRODUCT_SRC = \
-       ao_teleterra_0_2.c
+       ao_teleterra_0_2.c \
+       ao_terraui.c
 
 SRC = \
        $(CORE_SRC) \
index 671d3876766b3857723ad9943ccbb894a472ccb3..7b6f08b217e762be5446d70e5e828e5d336cf501 100644 (file)
        #define SPI_CS_ON_P0            0
        #define M25_CS_MASK             0x04
        #define M25_MAX_CHIPS           1
+
+       #define HAS_P2_ISR              1
+       #define HAS_BUTTON_P0           1
+       #define HAS_BUTTON_P2           1
 #endif
 
 #if DBG_ON_P1