Add a general bit-bang SPI lower-half driver and implement the bit-bang driver for the Arduino ITEAD TFT shield
This commit is contained in:
parent
a82077e0fc
commit
5f066efd2d
@ -890,55 +890,70 @@ Configuration sub-directories
|
||||
This configuration directory will built the NuttShell. See NOTES above.
|
||||
|
||||
NOTES:
|
||||
1. The configuration configuration can be modified to include support
|
||||
for the on-board SRAM (1MB).
|
||||
1. If the ITEAD TFT shield is connected to the Arduino Due, then
|
||||
support for the SD card slot can be enabled by making the following
|
||||
changes to the configuration:
|
||||
|
||||
System Type -> External Memory Configuration
|
||||
CONFIG_ARCH_EXTSRAM0=y : Select SRAM on CS0
|
||||
CONFIG_ARCH_EXTSRAM0SIZE=1048576 : Size=1MB
|
||||
Board Selection -> Peripheral
|
||||
CONFIG_SAM34_UART0=n : Disable UART0. Can't use with this shield
|
||||
CONFIG_SAM34_USART0=y : Enable USART0
|
||||
CONFIG_USART0_ISUART=y
|
||||
|
||||
Now what are you going to do with the SRAM. There are two choices:
|
||||
Device Drivers -> Serial
|
||||
CONFIG_USART0_SERIAL_CONSOLE=y : Configure the console on USART0
|
||||
CONFIG_USART0_RXBUFSIZE=256
|
||||
CONFIG_USART0_TXBUFSIZE=256
|
||||
CONFIG_USART0_BAUD=115200
|
||||
CONFIG_USART0_BITS=8
|
||||
CONFIG_USART0_PARITY=0
|
||||
CONFIG_USART0_2STOP=0
|
||||
|
||||
a) To enable the NuttX RAM test that may be used to verify the
|
||||
external SRAM:
|
||||
NOTE: USART0 TTL levels are available on COMM 5 (TXD0) and
|
||||
COMM 6 (RXD0)
|
||||
|
||||
System Type -> External Memory Configuration
|
||||
CONFIG_ARCH_EXTSRAM0HEAP=n : Don't add to heap
|
||||
Board Selection -> Board-Specific Options:
|
||||
CONFIG_ARCH_LEDS=n : Can't support LEDs with this shield installed
|
||||
CONFIG_ARDUINO_ITHEAD_TFT=y : Enable support for the Shield
|
||||
|
||||
Application Configuration -> System NSH Add-Ons
|
||||
CONFIG_SYSTEM_RAMTEST=y : Enable the RAM test built-in
|
||||
NOTE: You cannot use UART0 or LEDs with this ITEAD module.
|
||||
|
||||
In this configuration, the SDRAM is not added to heap and so is
|
||||
not excessible to the applications. So the RAM test can be
|
||||
freely executed against the SRAM memory beginning at address
|
||||
0x6000:0000 (CS0).
|
||||
File Systems:
|
||||
CONFIG_DISABLE_MOUNTPOINT=n : Mountpoint support is needed
|
||||
CONFIG_FS_FAT=y : Enable the FAT file system
|
||||
CONFIG_FAT_LCNAMES=y : Enable upper/lower case 8.3 file names (Optional, see below)
|
||||
CONFIG_FAT_LFN=y : Enable long file named (Optional, see below)
|
||||
CONFIG_FAT_MAXFNAME=32 : Maximum supported file name length
|
||||
|
||||
nsh> ramtest -h
|
||||
Usage: <noname> [-w|h|b] <hex-address> <decimal-size>
|
||||
There are issues related to patents that Microsoft holds on FAT long
|
||||
file name technologies. See the top level COPYING file for further
|
||||
details.
|
||||
|
||||
Where:
|
||||
<hex-address> starting address of the test.
|
||||
<decimal-size> number of memory locations (in bytes).
|
||||
-w Sets the width of a memory location to 32-bits.
|
||||
-h Sets the width of a memory location to 16-bits (default).
|
||||
-b Sets the width of a memory location to 8-bits.
|
||||
System Type -> Peripherals:
|
||||
CONFIG_SAM34_SPI0=y : Enable the SAM4L SPI peripheral
|
||||
|
||||
To test the entire external SRAM:
|
||||
Device Drivers
|
||||
CONFIG_SPI=y : Enable SPI support
|
||||
CONFIG_SPI_EXCHANGE=y : The exchange() method is supported
|
||||
CONFIG_SPI_OWNBUS=y : Smaller code if this is the only SPI device
|
||||
CONFIG_SPI_BITBANG=y : Enable SPI bit-bang support
|
||||
|
||||
nsh> ramtest 60000000 1048576
|
||||
RAMTest: Marching ones: 60000000 1048576
|
||||
RAMTest: Marching zeroes: 60000000 1048576
|
||||
RAMTest: Pattern test: 60000000 1048576 55555555 aaaaaaaa
|
||||
RAMTest: Pattern test: 60000000 1048576 66666666 99999999
|
||||
RAMTest: Pattern test: 60000000 1048576 33333333 cccccccc
|
||||
RAMTest: Address-in-address test: 60000000 1048576
|
||||
CONFIG_MMCSD=y : Enable MMC/SD support
|
||||
CONFIG_MMCSD_NSLOTS=1 : Only one MMC/SD card slot
|
||||
CONFIG_MMCSD_MULTIBLOCK_DISABLE=n : Should not need to disable multi-block transfers
|
||||
CONFIG_MMCSD_HAVECARDDETECT=y : I/O1 module as a card detect GPIO
|
||||
CONFIG_MMCSD_SPI=y : Use the SPI interface to the MMC/SD card
|
||||
CONFIG_MMCSD_SPICLOCK=20000000 : This is a guess for the optimal MMC/SD frequency
|
||||
CONFIG_MMCSD_SPIMODE=0 : Mode 0 is required
|
||||
|
||||
b) To add this RAM to the NuttX heap, you would need to change the
|
||||
configuration as follows:
|
||||
Board Selection -> Common Board Options
|
||||
CONFIG_NSH_ARCHINIT=y : Initialize the MMC/SD slot when NSH starts
|
||||
CONFIG_NSH_MMCSDSLOTNO=0 : Only one MMC/SD slot, slot 0
|
||||
CONFIG_NSH_MMCSDSPIPORTNO=0 : (does not really matter in this case)
|
||||
|
||||
System Type -> External Memory Configuration
|
||||
CONFIG_ARCH_EXTSRAM0HEAP=y : Add external RAM to heap
|
||||
Board Selection -> SAM4L Xplained Pro Modules
|
||||
CONFIG_SAM4L_XPLAINED_IOMODULE=y : I/O1 module is connected
|
||||
CONFIG_SAM4L_XPLAINED_IOMODULE_EXT1=y : In EXT1, or EXT2
|
||||
CONFIG_SAM4L_XPLAINED_IOMODULE_EXT2=y
|
||||
|
||||
Memory Management
|
||||
-CONFIG_MM_REGIONS=1 : Only the internal SRAM
|
||||
+CONFIG_MM_REGIONS=2 : Also include external SRAM
|
||||
Application Configuration -> NSH Library
|
||||
CONFIG_NSH_ARCHINIT=y : Board has architecture-specific initialization
|
||||
|
@ -69,7 +69,10 @@ fi
|
||||
# toolchain.
|
||||
export TOOLCHAIN_BIN="${WD}/../misc/buildroot/build_arm_nofpu/staging_dir/bin"
|
||||
|
||||
# This is the Cygwin path to the location where I have the Arduino BOSSA program
|
||||
export BOSSA_BIN="/cygdrive/c/Program Files (x86)/Arduino/arduino-1.5.2/hardware/tools"
|
||||
|
||||
# Add the path to the toolchain to the PATH varialble
|
||||
export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
|
||||
export PATH="${TOOLCHAIN_BIN}:${BOSSA_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
|
||||
|
||||
echo "PATH : ${PATH}"
|
||||
|
@ -69,7 +69,10 @@ fi
|
||||
# toolchain.
|
||||
export TOOLCHAIN_BIN="${WD}/../misc/buildroot/build_arm_nofpu/staging_dir/bin"
|
||||
|
||||
# This is the Cygwin path to the location where I have the Arduino BOSSA program
|
||||
export BOSSA_BIN="/cygdrive/c/Program Files (x86)/Arduino/arduino-1.5.2/hardware/tools"
|
||||
|
||||
# Add the path to the toolchain to the PATH varialble
|
||||
export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
|
||||
export PATH="${TOOLCHAIN_BIN}:${BOSSA_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
|
||||
|
||||
echo "PATH : ${PATH}"
|
||||
|
@ -55,7 +55,7 @@ endif
|
||||
ifeq ($(CONFIG_ARDUINO_ITHEAD_TFT),y)
|
||||
|
||||
ifeq ($(CONFIG_SPI_BITBANG),y)
|
||||
ifeq ($(CONFIG_MMC_SPI),y)
|
||||
ifeq ($(CONFIG_MMCSD_SPI),y)
|
||||
CSRCS += sam_mmcsd.c
|
||||
endif
|
||||
|
||||
@ -69,6 +69,10 @@ CSRCS += sam_lcd.c
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NSH_ARCHINIT),y)
|
||||
CSRCS += sam_nsh.c
|
||||
endif
|
||||
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
|
@ -173,7 +173,7 @@
|
||||
* SPI bit-bang driver as well as support for SPI-based MMC/SD cards.
|
||||
*/
|
||||
|
||||
# if defined(CONFIG_SPI_BITBANG) && defined(CONFIG_MMC_SPI)
|
||||
# if defined(CONFIG_SPI_BITBANG) && defined(CONFIG_MMCSD_SPI)
|
||||
|
||||
/* The SD slot shares the pin with LED "L" so LED support must be disabled
|
||||
* to use the MMC/SD card on the ITEAD shield.
|
||||
@ -183,13 +183,13 @@
|
||||
# error LEDs may not be used with the ITEAD SD card
|
||||
# endif
|
||||
|
||||
# define GPIO_SD_SCK (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_SD_SCK (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOB | GPIO_PIN27)
|
||||
# define GPIO_SD_MISO (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_SD_MISO (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOD | GPIO_PIN8)
|
||||
# define GPIO_SD_MOSI (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_SD_MOSI (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOD | GPIO_PIN7)
|
||||
# define GPIO_SD_CS (GPIO_OUTPUT | GPIO_CFG_PULLUP | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_SD_CS (GPIO_OUTPUT | GPIO_CFG_PULLUP | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIO? | GPIO_PIN?)
|
||||
# endif
|
||||
|
||||
@ -198,13 +198,13 @@
|
||||
*/
|
||||
|
||||
# if defined(CONFIG_SPI_BITBANG) && defined(CONFIG_INPUT)
|
||||
# define GPIO_TSC_SCK (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_TSC_SCK (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOA | GPIO_PIN24)
|
||||
# define GPIO_TSC_MISO (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_TSC_MISO (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOC | GPIO_PIN21)
|
||||
# define GPIO_TSC_MOSI (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_TSC_MOSI (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOA | GPIO_PIN16)
|
||||
# define GPIO_TSC_CS (GPIO_OUTPUT | GPIO_CFG_PULLUP | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_TSC_CS (GPIO_OUTPUT | GPIO_CFG_PULLUP | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIO? | GPIO_PIN?)
|
||||
# define GPIO_TSC_IRQ (GPIO_INPUT | GPIO_CFG_PULLUP | GPIO_INT_BOTHEDGES | \
|
||||
GPIO_PORT_PIOC | GPIO_PIN22)
|
||||
@ -227,29 +227,29 @@
|
||||
* either inputs or outputs as needed.
|
||||
*/
|
||||
|
||||
# define GPIO_LCD_D0IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_LCD_D0IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOA | GPIO_PIN8)
|
||||
# define GPIO_LCD_D1IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_LCD_D1IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOA | GPIO_PIN9)
|
||||
# define GPIO_LCD_D2IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_LCD_D2IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOB | GPIO_PIN25)
|
||||
# define GPIO_LCD_D3IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_LCD_D3IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOC | GPIO_PIN28)
|
||||
# define GPIO_LCD_D4IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_LCD_D4IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOC | GPIO_PIN26)
|
||||
# define GPIO_LCD_D5IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_LCD_D5IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOC | GPIO_PIN25)
|
||||
# define GPIO_LCD_D6IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_LCD_D6IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOC | GPIO_PIN24)
|
||||
# define GPIO_LCD_D7IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_LCD_D7IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOC | GPIO_PIN23)
|
||||
# define GPIO_LCD_D7IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_LCD_D7IN (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOC | GPIO_PIN23)
|
||||
# define GPIO_LCD_CS (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_LCD_CS (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOA | GPIO_PIN22)
|
||||
# define GPIO_LCD_WR (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_LCD_WR (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOA | GPIO_PIN6)
|
||||
# define GPIO_LCD_RS (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLR | \
|
||||
# define GPIO_LCD_RS (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOA | GPIO_PIN4)
|
||||
# endif
|
||||
#endif
|
||||
@ -288,6 +288,20 @@ void sam_sram_initialize(void);
|
||||
void up_ledinit(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_sdinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the SPI-based SD card.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_ARDUINO_ITHEAD_TFT) && defined(CONFIG_SPI_BITBANG) && \
|
||||
defined(CONFIG_MMCSD_SPI)
|
||||
int sam_sdinitialize(int minor);
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __CONFIGS_ARDUINO_DUE_SRC_ARDUNO_DUE_H */
|
||||
|
||||
|
266
configs/arduino-due/src/sam_mmcsd.c
Normal file
266
configs/arduino-due/src/sam_mmcsd.c
Normal file
@ -0,0 +1,266 @@
|
||||
/****************************************************************************
|
||||
* configs/sam3u-ek/src/up_mmcsd.c
|
||||
*
|
||||
* Copyright (C) 2010, 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/mmcsd.h>
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <nuttx/spi/spi_bitbang.h>
|
||||
|
||||
#include "up_arch.h"
|
||||
#include "sam_gpio.h"
|
||||
#include "chip/sam3u_pio.h"
|
||||
|
||||
#include "arduino-due.h"
|
||||
|
||||
/* In order to use the SD card on the ITEAD shield, you must enable the SPI bit-bang
|
||||
* driver as well as support for SPI-based MMC/SD cards.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_ARDUINO_ITHEAD_TFT) && defined(CONFIG_SPI_BITBANG) && \
|
||||
defined(CONFIG_MMCSD_SPI)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifdef CONFIG_DISABLE_MOUNTPOINT
|
||||
# error Mountpoints are disabled (CONFIG_DISABLE_MOUNTPOINT=y)
|
||||
#endif
|
||||
|
||||
/* Definitions for include/nuttx/spi/spi_bitbang.c. */
|
||||
|
||||
#define SPI_SETSCK putreg32(1 << 27, SAM_PIOB_SODR)
|
||||
#define SPI_CLRSCK putreg32(1 << 27, SAM_PIOB_CODR)
|
||||
#define SPI_SETMOSI putreg32(1 << 7, SAM_PIOD_SODR)
|
||||
#define SPI_CLRMOSI putreg32(1 << 7, SAM_PIOD_CODR)
|
||||
#define SPI_GETMISO ((getreg32(SAM_PIOD_PDSR) >> 8) & 1)
|
||||
|
||||
/* SPI_PERBIT_NSEC is the minimum time to transfer one bit. This determines
|
||||
* the maximum frequency and is also used to calculate delays to achieve
|
||||
* other SPI frequencies.
|
||||
*
|
||||
* This value came from selecting 400KHz and increasing SPI_PERBIT_NSEC
|
||||
* until a frequency close to 400KHz was achieved. This is what was
|
||||
* reported by the software: frequency=400000 holdtime=1 actual=298507.
|
||||
* I measured a frequency of approximately 305KHz.
|
||||
*
|
||||
* NOTE that there are really only two frequencies possible: hold time=1
|
||||
* (305KHz) and hold time = 0 (probably around 781KHz)
|
||||
*/
|
||||
|
||||
#define SPI_PERBIT_NSEC 1350 /* Calibrated at 400KHz */
|
||||
|
||||
/* Misc definitions */
|
||||
|
||||
#define SAM34_MMCSDSLOTNO 0 /* There is only one slot */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void spi_select(FAR struct spi_bitbang_s *priv, enum spi_dev_e devid,
|
||||
bool selected);
|
||||
static uint8_t spi_status(FAR struct spi_bitbang_s *priv, enum spi_dev_e devid);
|
||||
#ifdef CONFIG_SPI_CMDDATA
|
||||
static int spi_cmddata(FAR struct spi_bitbang_s *priv, enum spi_dev_e devid,
|
||||
bool cmd);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Include the bit-band skeleton logic
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/spi/spi_bitbang.c>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_mmcsd_spiinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the SPI bitband driver
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* A non-NULL reference to the SPI driver on success
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void spi_select(FAR struct spi_bitbang_s *priv, enum spi_dev_e devid,
|
||||
bool selected)
|
||||
{
|
||||
# warning Still need CS GPIO pin
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_mmcsd_spiinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the SPI bitband driver
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* A non-NULL reference to the SPI driver on success
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static uint8_t spi_status(FAR struct spi_bitbang_s *priv, enum spi_dev_e devid)
|
||||
{
|
||||
if (devid = SPIDEV_MMCSD)
|
||||
{
|
||||
return SPI_STATUS_PRESENT;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: spi_cmddata
|
||||
*
|
||||
* Description:
|
||||
* If there were was a CMD/DATA line, this function would manage it
|
||||
*
|
||||
* Input Parameters:
|
||||
* priv - An instance of the bit-bang driver structure
|
||||
* devid - The device to use
|
||||
* cmd - True=MCD false=DATA
|
||||
*
|
||||
* Returned Value:
|
||||
* OK
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SPI_CMDDATA
|
||||
static int spi_cmddata(FAR struct spi_bitbang_s *priv, enum spi_dev_e devid,
|
||||
bool cmd)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_mmcsd_spiinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the SPI bitband driver
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* A non-NULL reference to the SPI driver on success
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static FAR struct spi_dev_s *sam_mmcsd_spiinitialize(void)
|
||||
{
|
||||
/* Initialize GPIOs */
|
||||
|
||||
sam_configgpio(GPIO_SD_SCK);
|
||||
sam_configgpio(GPIO_SD_MISO);
|
||||
sam_configgpio(GPIO_SD_MOSI);
|
||||
// sam_configgpio(GPIO_SD_CS);
|
||||
# warning Still need CS GPIO pin
|
||||
|
||||
/* Create the SPI driver instance */
|
||||
|
||||
return spi_create_bitbang(&g_spiops);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_sdinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the SPI-based SD card.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
int sam_sdinitialize(int minor)
|
||||
{
|
||||
FAR struct spi_dev_s *spi;
|
||||
int ret;
|
||||
|
||||
/* Get the SPI driver instance for the SD chip select */
|
||||
|
||||
fvdbg("Initializing bit bang SPI for the MMC/SD slot\n");
|
||||
|
||||
spi = sam_mmcsd_spiinitialize();
|
||||
if (!spi)
|
||||
{
|
||||
fdbg("Failed to bit bang SPI for the MMC/SD slot\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
fvdbg("Successfully initialized bit bang SPI for the MMC/SD slot\n");
|
||||
|
||||
/* Bind the SPI device for the chip select to the slot */
|
||||
|
||||
fvdbg("Binding bit bang SPI device to MMC/SD slot %d\n",
|
||||
SAM34_MMCSDSLOTNO);
|
||||
|
||||
ret = mmcsd_spislotinitialize(minor, SAM34_MMCSDSLOTNO, spi);
|
||||
if (ret < 0)
|
||||
{
|
||||
fdbg("Failed to bind bit bang SPI device to MMC/SD slot %d: %d\n",
|
||||
SAM34_MMCSDSLOTNO, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
fvdbg("Successfuly bound bit bang SPI device to MMC/SD slot %d\n",
|
||||
SAM34_MMCSDSLOTNO);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_ARDUINO_ITHEAD_TFT && CONFIG_SPI_BITBANG && CONFIG_MMC_SPI */
|
115
configs/arduino-due/src/sam_nsh.c
Normal file
115
configs/arduino-due/src/sam_nsh.c
Normal file
@ -0,0 +1,115 @@
|
||||
/****************************************************************************
|
||||
* config/arduino-due/src/sam_nsh.c
|
||||
*
|
||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include "arduino-due.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_ARDUINO_ITHEAD_TFT) && defined(CONFIG_SPI_BITBANG) && \
|
||||
defined(CONFIG_MMCSD_SPI)
|
||||
/* Support for the SD card slot on the ITEAD TFT shield */
|
||||
/* Verify NSH PORT and SLOT settings */
|
||||
|
||||
# define SAM34_MMCSDSLOTNO 0 /* There is only one slot */
|
||||
|
||||
# if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != SAM34_MMCSDSLOTNO
|
||||
# error Only one MMC/SD slot: Slot 0 (CONFIG_NSH_MMCSDSLOTNO)
|
||||
# endif
|
||||
|
||||
/* Default MMC/SD minor number */
|
||||
|
||||
# ifndef CONFIG_NSH_MMCSDMINOR
|
||||
# define CONFIG_NSH_MMCSDMINOR 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Debug ********************************************************************/
|
||||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lowsyslog(__VA_ARGS__)
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lowsyslog
|
||||
# else
|
||||
# define message printf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nsh_archinitialize
|
||||
*
|
||||
* Description:
|
||||
* Perform architecture specific initialization
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int nsh_archinitialize(void)
|
||||
{
|
||||
#if defined(CONFIG_ARDUINO_ITHEAD_TFT) && defined(CONFIG_SPI_BITBANG) && \
|
||||
defined(CONFIG_MMCSD_SPI)
|
||||
/* Initialize the SPI-based MMC/SD slot */
|
||||
|
||||
{
|
||||
int ret = sam_sdinitialize(CONFIG_NSH_MMCSDMINOR);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nsh_archinitialize: Failed to initialize MMC/SD slot: %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* config/shenzhou/src/sam_nsh.c
|
||||
* config/sam4l-xplained/src/sam_nsh.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
Loading…
Reference in New Issue
Block a user