diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2013-06-15 10:56:08 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2013-06-15 10:56:08 -0600 |
commit | 123f7dc4f8825a277f2e416558bbb49fa19cc2b7 (patch) | |
tree | e54dd6223c6040d670644783235ae9ee6d96900f /nuttx/configs/sam4l-xplained/src | |
parent | 9c82995c7a5847034355250dd9438649151ca58c (diff) | |
download | px4-nuttx-123f7dc4f8825a277f2e416558bbb49fa19cc2b7.tar.gz px4-nuttx-123f7dc4f8825a277f2e416558bbb49fa19cc2b7.tar.bz2 px4-nuttx-123f7dc4f8825a277f2e416558bbb49fa19cc2b7.zip |
Add support for the SAM4L Xplained Pro I/O1 module
Diffstat (limited to 'nuttx/configs/sam4l-xplained/src')
-rw-r--r-- | nuttx/configs/sam4l-xplained/src/Makefile | 14 | ||||
-rw-r--r-- | nuttx/configs/sam4l-xplained/src/sam4l-xplained.h | 63 | ||||
-rw-r--r-- | nuttx/configs/sam4l-xplained/src/sam_buttons.c | 2 | ||||
-rw-r--r-- | nuttx/configs/sam4l-xplained/src/sam_spi.c | 54 |
4 files changed, 108 insertions, 25 deletions
diff --git a/nuttx/configs/sam4l-xplained/src/Makefile b/nuttx/configs/sam4l-xplained/src/Makefile index 01813faf4..3768f7ebb 100644 --- a/nuttx/configs/sam4l-xplained/src/Makefile +++ b/nuttx/configs/sam4l-xplained/src/Makefile @@ -40,7 +40,11 @@ CFLAGS += -I$(TOPDIR)/sched ASRCS = AOBJS = $(ASRCS:.S=$(OBJEXT)) -CSRCS = sam_boot.c sam_spi.c +CSRCS = sam_boot.c + +ifeq ($(CONFIG_SAM34_SPI),y) +CSRCS += sam_spi.c +endif ifeq ($(CONFIG_HAVE_CXX),y) CSRCS += sam_cxxinitialize.c @@ -56,6 +60,14 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += sam_buttons.c endif +ifeq ($(CONFIG_NSH_ARCHINIT),y) +CSRCS += sam_nsh.c +endif + +ifeq ($(CONFIG_SAM4L_XPLAINED_IOMODULE),y) +CSRCS += sam_mmcsd.c +endif + COBJS = $(CSRCS:.c=$(OBJEXT)) SRCS = $(ASRCS) $(CSRCS) diff --git a/nuttx/configs/sam4l-xplained/src/sam4l-xplained.h b/nuttx/configs/sam4l-xplained/src/sam4l-xplained.h index ba6978a82..9e7a0f4ac 100644 --- a/nuttx/configs/sam4l-xplained/src/sam4l-xplained.h +++ b/nuttx/configs/sam4l-xplained/src/sam4l-xplained.h @@ -99,10 +99,54 @@ * PC24 SW0 */ -#define GPIO_SW0 (GPIO_INPUT | GPIO_PULL_UP | GPIO_GLITCH_FILTER | \ +#define GPIO_SW0 (GPIO_INTERRUPT | GPIO_PULL_UP | GPIO_GLITCH_FILTER | \ GPIO_PORTC | GPIO_PIN24) #define IRQ_SW0 SAM_IRQ_PC24 +/* I/O1 + * + * Support for the microSD card slot on the I/O1 module. The I/O1 requires + * SPI support and two GPIOs. These two GPIOs will vary if the + * + * + * PIN EXT1 EXT2 Description + * --- -------------- --------------- ------------------------------------- + * 15 PC03 SPI/NPCS0 PB11 SPI/NPCS2 Active low chip select OUTPUT, pulled + * high on board. + * 10 PB13 SPI/NPCS1 10 PC09 GPIO Active low card detect INPUT, must + * use internal pull-up. + */ + +#ifdef CONFIG_SAM4L_XPLAINED_IOMODULE + +# ifndef CONFIG_SAM34_SPI +# error CONFIG_SAM34_SPI is required to use the I/O1 module +# endif + +# if defined(CONFIG_SAM4L_XPLAINED_IOMODULE_EXT1) + +# define GPIO_SD_CD (GPIO_INTERRUPT | GPIO_INT_CHANGE | GPIO_PULL_UP | \ + GPIO_GLITCH_FILTER | GPIO_PORTB | GPIO_PIN13) +# define IRQ_SD_CD SAM_IRQ_PB13 + +# define GPIO_SD_CS (GPIO_OUTPUT | GPIO_PULL_NONE | GPIO_OUTPUT_SET | \ + GPIO_PORTC | GPIO_PIN3) +# define SD_CSNO 0 + +# elif defined(CONFIG_SAM4L_XPLAINED_IOMODULE_EXT2) +# define GPIO_CD (GPIO_INTERRUPT | GPIO_INT_CHANGE | GPIO_PULL_UP | \ + GPIO_GLITCH_FILTER | GPIO_PORTC | GPIO_PIN9) +# define IRQ_CD SAM_IRQ_PC9 + +# define GPIO_SD_CS (GPIO_OUTPUT | GPIO_PULL_NONE | GPIO_OUTPUT_SET | \ + GPIO_PORTB | GPIO_PIN11) +# define SD_CSNO 2 + +# else +# error Which connector is the I/O1 module installed in? +# endif +#endif + /************************************************************************************ * Public Types ************************************************************************************/ @@ -127,9 +171,22 @@ void weak_function sam_spiinitialize(void); -/**************************************************************************** +/************************************************************************************ + * Name: sam_sdinitialize + * + * Description: + * Initialize the SPI-based SD card. Requires CONFIG_SAM4L_XPLAINED_IOMODULE=y, + * CONFIG_DISABLE_MOUNTPOINT=n, CONFIG_MMCSD=y, and CONFIG_SAM34_SPI=y + * + ************************************************************************************/ + +#ifdef CONFIG_SAM4L_XPLAINED_IOMODULE +int sam_sdinitialize(int minor); +#endif + +/************************************************************************************ * Name: up_ledinit - ****************************************************************************/ + ************************************************************************************/ #ifdef CONFIG_ARCH_LEDS void up_ledinit(void); diff --git a/nuttx/configs/sam4l-xplained/src/sam_buttons.c b/nuttx/configs/sam4l-xplained/src/sam_buttons.c index 2a5081a44..4c4b8cb83 100644 --- a/nuttx/configs/sam4l-xplained/src/sam_buttons.c +++ b/nuttx/configs/sam4l-xplained/src/sam_buttons.c @@ -59,7 +59,9 @@ * Private Data ****************************************************************************/ +#if defined(CONFIG_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) static xcpt_t g_irqsw0; +#endif /**************************************************************************** * Private Functions diff --git a/nuttx/configs/sam4l-xplained/src/sam_spi.c b/nuttx/configs/sam4l-xplained/src/sam_spi.c index 0bd7df9bb..b977db246 100644 --- a/nuttx/configs/sam4l-xplained/src/sam_spi.c +++ b/nuttx/configs/sam4l-xplained/src/sam_spi.c @@ -39,7 +39,6 @@ #include <nuttx/config.h> -#include <stdint.h> #include <stdbool.h> #include <debug.h> #include <errno.h> @@ -92,14 +91,15 @@ void weak_function sam_spiinitialize(void) { - /* The ZigBee module connects used NPCS0. However, there is not yet any - * ZigBee support. + /* The I/O module containing the SD connector may or may not be installed. And, if + * it is installed, it may be in connector EXT1 or EXT2. */ - /* The touchscreen connects using NPCS2 (PC14). */ +#ifdef CONFIG_SAM4L_XPLAINED_IOMODULE + /* TODO: enable interrupt on card detect */ -#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_ADS7843E) - sam_configgpio(GPIO_TSC_NPCS2); + sam_configgpio(GPIO_SD_CD); /* Card detect input */ + sam_configgpio(GPIO_SD_CS); /* Chip select output */ #endif } @@ -161,12 +161,12 @@ int sam_spicsnumber(enum spi_dev_e devid) { int cs = -EINVAL; -#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_ADS7843E) - if (devid == SPIDEV_TOUCHSCREEN) +#ifdef CONFIG_SAM4L_XPLAINED_IOMODULE + if (devid == SPIDEV_MMCSD) { - /* Assert the CS pin to the OLED display */ + /* Return the chip select number */ - cs = 2; + cs = SD_CSNO; } #endif @@ -201,18 +201,14 @@ int sam_spicsnumber(enum spi_dev_e devid) void sam_spiselect(enum spi_dev_e devid, bool selected) { - /* The touchscreen chip select is implemented as a GPIO OUTPUT that must - * be controlled by this function. This is because the ADS7843E driver - * must be able to sample the device BUSY GPIO input between SPI transfers. - * However, the AD7843E will tri-state the BUSY input whenever the chip - * select is de-asserted. So the only option is to control the chip select - * manually and hold it low throughout the SPI transfer. - */ +#ifdef CONFIG_SAM4L_XPLAINED_IOMODULE + /* Select/de-select the SD card */ -#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_ADS7843E) - if (devid == SPIDEV_TOUCHSCREEN) + if (devid == SPIDEV_MMCSD) { - sam_gpiowrite(GPIO_TSC_NPCS2, !selected); + /* Active low */ + + sam_gpiowrite(GPIO_SD_CS, !selected); } #endif } @@ -233,7 +229,23 @@ void sam_spiselect(enum spi_dev_e devid, bool selected) uint8_t sam_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid) { - return 0; + uint8_t ret = 0; + +#ifdef CONFIG_SAM4L_XPLAINED_IOMODULE + /* Check if an SD card is present in the microSD slot */ + + if (devid == SPIDEV_MMCSD) + { + /* Active low */ + + if (!sam_gpioread(GPIO_SD_CD)) + { + ret |= SPI_STATUS_PRESENT; + } + } +#endif + + return ret; } #endif /* CONFIG_SAM34_SPI */ |