diff --git a/configs/avr32dev1/include/board.h b/configs/avr32dev1/include/board.h index 2ef9532f0f..c166cae053 100755 --- a/configs/avr32dev1/include/board.h +++ b/configs/avr32dev1/include/board.h @@ -87,6 +87,12 @@ #define LED_ASSERTION 2 /* ON ON ON OFF */ #define LED_PANIC 2 /* ON ON ON OFF */ +/* Button definitions ***************************************************************/ +/* The AVR32DEV1 board has 3 BUTTONs, two of which can be sensed through GPIO pins. */ + +#define BUTTON1 1 /* Bit 0: Button 1 */ +#define BUTTON2 2 /* Bit 1: Button 2 */ + /************************************************************************************ * Public Types ************************************************************************************/ @@ -120,6 +126,49 @@ extern "C" { EXTERN void avr32_boardinitialize(void); +/************************************************************************************ + * Name: up_buttoninit + * + * Description: + * up_buttoninit() must be called to initialize button resources. After that, + * up_buttons() may be called to collect the state of all buttons. up_buttons() + * returns an 8-bit bit set with each bit associated with a button. See the + * BUTTON* definitions above for the meaning of each bit in the returned value. + * + ************************************************************************************/ + +#ifdef CONFIG_ARCH_BUTTONS +EXTERN void up_buttoninit(void); + +/************************************************************************************ + * Name: up_buttons + * + * Description: + * After up_buttoninit() has been called, up_buttons() may be called to collect + * the state of all buttons. up_buttons() returns an 8-bit bit set with each bit + * associated with a button. See the BUTTON* definitions above for the meaning of + * each bit in the returned value. + * + ************************************************************************************/ + +EXTERN uint8_t up_buttons(void); + +/************************************************************************************ + * Name: up_irqbutton1/2 + * + * Description: + * These functions may be called to register an interrupt handler that will be + * called when BUTTON1/2 is depressed. The previous interrupt handler value is + * returned (so that it may restored, if so desired). + * + ************************************************************************************/ + +#ifdef CONFIG_GPIOB_IRQ +EXTERN xcpt_t up_irqbutton1(xcpt_t irqhandler); +EXTERN xcpt_t up_irqbutton2(xcpt_t irqhandler); +#endif +#endif /* CONFIG_ARCH_BUTTONS */ + #undef EXTERN #if defined(__cplusplus) } diff --git a/configs/avr32dev1/src/Makefile b/configs/avr32dev1/src/Makefile index 4edb47c81d..282aaa8aa6 100755 --- a/configs/avr32dev1/src/Makefile +++ b/configs/avr32dev1/src/Makefile @@ -38,7 +38,13 @@ CFLAGS += -I$(TOPDIR)/sched ASRCS = -CSRCS = up_boot.c up_leds.c +CSRCS = up_boot.c +ifeq ($(CONFIG_ARCH_LEDS),y) +CSRCS += up_leds.c +endif +ifeq ($(CONFIG_ARCH_BUTTONS),y) +CSRCS += up_buttons.c +endif AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/configs/avr32dev1/src/avr32dev1_internal.h b/configs/avr32dev1/src/avr32dev1_internal.h index 9a673ae0c4..f46ed5516f 100755 --- a/configs/avr32dev1/src/avr32dev1_internal.h +++ b/configs/avr32dev1/src/avr32dev1_internal.h @@ -60,16 +60,16 @@ #define PINMUX_GPIO_LED1 (GPIO_ENABLE | GPIO_OUTPUT | GPIO_LOW | GPIO_PORTA | 7) #define PINMUX_GPIO_LED2 (GPIO_ENABLE | GPIO_OUTPUT | GPIO_LOW | GPIO_PORTA | 8) -/* KEYs +/* BUTTONs * - * The AVR32DEV1 board has 3 KEYs, two of which can be sensed through GPIO pins. + * The AVR32DEV1 board has 3 BUTTONs, two of which can be sensed through GPIO pins. * * PIN 24 PB2 KEY1 * PIN 25 PB3 KEY2 */ -#define PINMUX_GPIO_KEY1 (GPIO_ENABLE | GPIO_INPUT | GPIO_PORTB | 2) -#define PINMUX_GPIO_KEY2 (GPIO_ENABLE | GPIO_INPUT | GPIO_PORTB | 3) +#define PINMUX_GPIO_BUTTON1 (GPIO_ENABLE | GPIO_INPUT | GPIO_PORTB | 2) +#define PINMUX_GPIO_BUTTON2 (GPIO_ENABLE | GPIO_INPUT | GPIO_PORTB | 3) /************************************************************************************ * Public Types diff --git a/configs/avr32dev1/src/up_buttons.c b/configs/avr32dev1/src/up_buttons.c new file mode 100755 index 0000000000..37434d6560 --- /dev/null +++ b/configs/avr32dev1/src/up_buttons.c @@ -0,0 +1,159 @@ +/**************************************************************************** + * configs/sam3u-ek/src/up_leds.c + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +#include +#include + +#include "at91uc3_internal.h" +#include "avr32dev1_internal.h" + +#ifdef CONFIG_ARCH_BUTTONS + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static xcpt_t g_irqbutton1; +static xcpt_t g_irqbutton2; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_buttoninit + ****************************************************************************/ + +void up_buttoninit(void) +{ + (void)at91uc3_configgpio(PINMUX_GPIO_BUTTON1); + (void)at91uc3_configgpio(PINMUX_GPIO_BUTTON2); +} + +/**************************************************************************** + * Name: up_buttons + ****************************************************************************/ + +uint8_t up_buttons(void) +{ + uint8_t retval; + + retval = at91uc3_gpioread(PINMUX_GPIO_BUTTON1) ? 0 : BUTTON1; + retval |= sat91uc3_gpioread(PINMUX_GPIO_BUTTON2) ? 0 : BUTTON2; + + return retval; +} + +/**************************************************************************** + * Name: up_irqbutton1 + ****************************************************************************/ + +#ifdef CONFIG_GPIOB_IRQ +xcpt_t up_irqbutton1(xcpt_t irqhandler) +{ + xcpt_t oldhandler; + irqstate_t flags; + + /* Disable interrupts until we are done */ + + flags = irqsave(); + + /* Get the old button interrupt handler and save the new one */ + + oldhandler = g_irqbutton1; + g_irqbutton1 = irqhandler; + + /* Configure and enable the interrupt */ + +#warning "Missing Logic" + + irqrestore(flags); + + /* Return the old button handler (so that it can be restored) */ + + return oldhandler; +} +#endif + +/**************************************************************************** + * Name: up_irqbutton2 + ****************************************************************************/ + +#ifdef CONFIG_GPIOB_IRQ +xcpt_t up_irqbutton2(xcpt_t irqhandler) +{ + xcpt_t oldhandler; + irqstate_t flags; + + /* Disable interrupts until we are done */ + + flags = irqsave(); + + /* Get the old button interrupt handler and save the new one */ + + oldhandler = g_irqbutton2; + g_irqbutton2 = irqhandler; + + /* Configure and enable the interrupt */ + +#warning "Missing Logic" + + irqrestore(flags); + + /* Return the old button handler (so that it can be restored) */ + + return oldhandler; +} +#endif + +#endif /* CONFIG_ARCH_BUTTONS */