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 | |
| 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>
| -rw-r--r-- | src/cc1111/ao_arch.h | 15 | ||||
| -rw-r--r-- | src/cc1111/ao_button.c | 86 | ||||
| -rw-r--r-- | src/cc1111/ao_usb.c | 3 | ||||
| -rw-r--r-- | src/core/ao.h | 7 | ||||
| -rw-r--r-- | src/product/ao_teleterra_0_2.c | 1 | ||||
| -rw-r--r-- | src/product/ao_terraui.c | 45 | ||||
| -rw-r--r-- | src/teleterra-v0.2/Makefile | 4 | ||||
| -rw-r--r-- | src/teleterra-v0.2/ao_pins.h | 4 | 
8 files changed, 164 insertions, 1 deletions
| diff --git a/src/cc1111/ao_arch.h b/src/cc1111/ao_arch.h index 02e36189..23589e66 100644 --- a/src/cc1111/ao_arch.h +++ b/src/cc1111/ao_arch.h @@ -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 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; +} diff --git a/src/cc1111/ao_usb.c b/src/cc1111/ao_usb.c index 08cb7390..35c9ac20 100644 --- a/src/cc1111/ao_usb.c +++ b/src/cc1111/ao_usb.c @@ -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 { diff --git a/src/core/ao.h b/src/core/ao.h index c800f1fc..43d4e0e3 100644 --- a/src/core/ao.h +++ b/src/core/ao.h @@ -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_ */ diff --git a/src/product/ao_teleterra_0_2.c b/src/product/ao_teleterra_0_2.c index 05085860..b38f2907 100644 --- a/src/product/ao_teleterra_0_2.c +++ b/src/product/ao_teleterra_0_2.c @@ -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 index 00000000..3885db4e --- /dev/null +++ b/src/product/ao_terraui.c @@ -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"); +} diff --git a/src/teleterra-v0.2/Makefile b/src/teleterra-v0.2/Makefile index eda67a2a..8e4569a9 100644 --- a/src/teleterra-v0.2/Makefile +++ b/src/teleterra-v0.2/Makefile @@ -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) \ diff --git a/src/teleterra-v0.2/ao_pins.h b/src/teleterra-v0.2/ao_pins.h index 671d3876..7b6f08b2 100644 --- a/src/teleterra-v0.2/ao_pins.h +++ b/src/teleterra-v0.2/ao_pins.h @@ -53,6 +53,10 @@  	#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 | 
