Misc fixes, add button support, GPIO interrupt support

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2523 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2010-01-23 03:05:05 +00:00
parent 5b4390533f
commit 46e0644193
5 changed files with 145 additions and 20 deletions

View File

@ -250,19 +250,22 @@ SAM3U-EK-specific Configuration Options
Individual subsystems can be enabled:
CONFIG_SAM3U_UART=y
CONFIG_SAM3U_USART0=n
CONFIG_SAM3U_USART1=n
CONFIG_SAM3U_USART2=n
CONFIG_SAM3U_USART3=n
CONFIG_SAM3U_UART
CONFIG_SAM3U_USART0
CONFIG_SAM3U_USART1
CONFIG_SAM3U_USART2
CONFIG_SAM3U_USART3
Some subsystems can be configured to operate in different ways. The drivers
need to know how to configure the subsystem.
CONFIG_USART0_ISUART=y
CONFIG_USART1_ISUART=y
CONFIG_USART2_ISUART=y
CONFIG_USART3_ISUART=y
CONFIG_GPIOA_IRQ
CONFIG_GPIOB_IRQ
CONFIG_GPIOC_IRQ
CONFIG_USART0_ISUART
CONFIG_USART1_ISUART
CONFIG_USART2_ISUART
CONFIG_USART3_ISUART
AT91SAM3U specific device driver settings

View File

@ -42,12 +42,15 @@
************************************************************************************/
#include <nuttx/config.h>
#ifndef __ASSEMBLY__
# include <stdint.h>
#endif
#include "sam3u_internal.h"
#ifndef __ASSEMBLY__
# include <stdint.h>
# ifdef CONFIG_GPIO_IRQ
# include <arch/irq.h>
# endif
#endif
/************************************************************************************
* Definitions
************************************************************************************/
@ -94,7 +97,12 @@
#define LED_INIRQ 4 /* LED0=XXX LED1=TOG LED2=XXX */
#define LED_SIGNAL 5 /* LED0=XXX LED1=XXX LED2=TOG */
#define LED_ASSERTION 6 /* LED0=TOG LED1=XXX LED2=XXX */
#define LED_PANIC 7 /* LED0=TOG LED1=XXX LED2=XXX*/
#define LED_PANIC 7 /* LED0=TOG LED1=XXX LED2=XXX */
/* Button definitions ***************************************************************/
#define BUTTON1 1 /* Bit 0: Button 1 */
#define BUTTON2 2 /* Bit 1: Button 2 */
/************************************************************************************
* Public Data
@ -126,20 +134,47 @@ extern "C" {
EXTERN void sam3u_boardinitialize(void);
/************************************************************************************
* Button support.
* 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_* and JOYSTICK_* definitions above for the meaning of each bit.
* 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_GPIOA_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)

View File

@ -74,7 +74,7 @@ CONFIG_ARCH_ARM=y
CONFIG_ARCH_CORTEXM3=y
CONFIG_ARCH_CHIP=sam3u
CONFIG_ARCH_CHIP_AT91SAM3U4=y
CONFIG_ARCH_BOARD=sam3u_ek
CONFIG_ARCH_BOARD=sam3u-ek
CONFIG_ARCH_BOARD_SAM3UEK=y
CONFIG_BOARD_LOOPSPERMSEC=5483
CONFIG_DRAM_SIZE=0x00010000
@ -85,7 +85,7 @@ CONFIG_ARCH_INTERRUPTSTACK=n
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARCH_BOOTLOADER=n
CONFIG_ARCH_LEDS=y
CONFIG_ARCH_BUTTONS=n
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CALIBRATION=n
CONFIG_ARCH_DMA=n
@ -110,6 +110,10 @@ CONFIG_SAM3U_USART3=n
# Some subsystems can be configured to operate in different ways..
# The drivers need to know how to configure the subsystem.
#
CONFIG_GPIOA_IRQ=n
CONFIG_GPIOB_IRQ=n
CONFIG_GPIOC_IRQ=n
CONFIG_USART0_ISUART=y
CONFIG_USART1_ISUART=y
CONFIG_USART2_ISUART=y

View File

@ -43,6 +43,7 @@
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <nuttx/irq.h>
#include <stdint.h>
/************************************************************************************
@ -64,6 +65,9 @@
#define GPIO_BUTTON1 (GPIO_INPUT|GPIO_CFG_PULLUP|GPIO_CFG_DEGLITCH|GPIO_PORT_PIOA|GPIO_PIN18)
#define GPIO_BUTTON2 (GPIO_INPUT|GPIO_CFG_PULLUP|GPIO_CFG_DEGLITCH|GPIO_PORT_PIOA|GPIO_PIN19)
#define IRQ_BUTTON1 SAM3U_IRQ_PA18
#define IRQ_BUTTON2 SAM3U_IRQ_PA19
/* SPI Chip Selects */
/************************************************************************************

View File

@ -1,7 +1,7 @@
/****************************************************************************
* configs/sam3u-ek/src/up_leds.c
*
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -41,7 +41,12 @@
#include <stdint.h>
#include <nuttx/irq.h>
#include <arch/irq.h>
#include <arch/board/board.h>
#include "sam3u_internal.h"
#include "sam3uek_internal.h"
#ifdef CONFIG_ARCH_BUTTONS
@ -54,6 +59,9 @@
* Private Data
****************************************************************************/
static xcpt_t g_irqbutton1;
static xcpt_t g_irqbutton2;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -68,6 +76,8 @@
void up_buttoninit(void)
{
(void)sam3u_configgpio(GPIO_BUTTON1);
(void)sam3u_configgpio(GPIO_BUTTON2);
}
/****************************************************************************
@ -76,7 +86,76 @@ void up_buttoninit(void)
uint8_t up_buttons(void)
{
return 0;
uint8_t retval;
retval = sam3u_gpioread(GPIO_BUTTON1) ? 0 : GPIO_BUTTON1;
retval |= sam3u_gpioread(GPIO_BUTTON2) ? 0 : GPIO_BUTTON2;
return retval;
}
/****************************************************************************
* Name: up_irqbutton1
****************************************************************************/
#ifdef CONFIG_GPIOA_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 the interrupt */
sam3u_gpioirq(IRQ_BUTTON1);
(void)irq_attach(IRQ_BUTTON1, irqhandler);
sam3u_gpioirqenable(IRQ_BUTTON1);
irqrestore(flags);
/* Return the old button handler (so that it can be restored) */
return oldhandler;
}
#endif
/****************************************************************************
* Name: up_irqbutton2
****************************************************************************/
#ifdef CONFIG_GPIOA_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 the interrupt */
sam3u_gpioirq(IRQ_BUTTON2);
(void)irq_attach(IRQ_BUTTON2, irqhandler);
sam3u_gpioirqenable(IRQ_BUTTON2);
irqrestore(flags);
/* Return the old button handler (so that it can be restored) */
return oldhandler;
}
#endif
#endif /* CONFIG_ARCH_BUTTONS */