diff options
-rw-r--r-- | nuttx/ChangeLog | 2 | ||||
-rw-r--r-- | nuttx/Documentation/NuttX.html | 2 | ||||
-rwxr-xr-x | nuttx/arch/z80/src/ez80/ez80_spi.c | 56 | ||||
-rw-r--r-- | nuttx/arch/z80/src/ez80/ez80f91_spi.h | 4 | ||||
-rw-r--r-- | nuttx/configs/mcu123-lpc214x/src/up_spi.c | 8 | ||||
-rw-r--r-- | nuttx/configs/olimex-strp711/src/up_spi.c | 8 | ||||
-rw-r--r-- | nuttx/include/nuttx/spi.h | 38 |
7 files changed, 102 insertions, 16 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 6a506625a..94676ceff 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -686,3 +686,5 @@ * Add an enumeration argument to the SPI chip select and status methods so that the interface can handle more than one device. * eZ80Acclaim!: Add a generic SPI driver for all eZ80 boards. + * Add a setmode() method to the SPI interface to handle parts with differing + mode requirements. diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index db4da8152..e8e9e3e62 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -1359,6 +1359,8 @@ nuttx-0.4.5 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> * Add an enumeration argument to the SPI chip select and status methods so that the interface can handle more than one device. * eZ80Acclaim!: Add a generic SPI driver for all eZ80 boards. + * Add a setmode() method to the SPI interface to handle parts with differing + mode requirements. pascal-0.1.3 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/arch/z80/src/ez80/ez80_spi.c b/nuttx/arch/z80/src/ez80/ez80_spi.c index aea2947d7..5af30fd06 100755 --- a/nuttx/arch/z80/src/ez80/ez80_spi.c +++ b/nuttx/arch/z80/src/ez80/ez80_spi.c @@ -66,6 +66,7 @@ ****************************************************************************/ static uint32 spi_setfrequency(FAR struct spi_dev_s *dev, uint32 frequency); +static void spi_setmode(FAR struct spi_dev_s *dev, enum spi_mode_e mode); static ubyte spi_sndbyte(FAR struct spi_dev_s *dev, ubyte ch); static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const ubyte *buffer, size_t buflen); static void spi_recvblock(FAR struct spi_dev_s *dev, FAR ubyte *buffer, size_t buflen); @@ -78,6 +79,7 @@ static const struct spi_ops_s g_spiops = { ez80_spiselect, /* Provided externally by board logic */ spi_setfrequency, + spi_setmode, ez80_spistatus, /* Provided externally by board logic */ spi_sndbyte, spi_sndblock, @@ -149,6 +151,58 @@ static uint32 spi_setfrequency(FAR struct spi_dev_s *dev, uint32 frequency) } /**************************************************************************** + * Name: spi_setmode + * + * Description: + * Set the SPI mode. Optional. See enum spi_mode_e for mode definitions + * + * Input Parameters: + * dev - Device-specific state data + * mode - The SPI mode requested + * + * Returned Value: + * none + * + ****************************************************************************/ + +static void spi_setmode(FAR struct spi_dev_s *dev, enum spi_mode_e mode) +{ + ubyte modebits; + ubyte regval; + + /* Select the CTL register bits based on the selected mode */ + + switch (mode) + { + case SPIDEV_MODE0: /* CPOL=0 CHPHA=0 */ + modebits = 0; + break; + + case SPIDEV_MODE1: /* CPOL=0 CHPHA=1 */ + modebits = SPI_CTL_CPHA; + break; + + case SPIDEV_MODE2: /* CPOL=1 CHPHA=0 */ + modebits = SPI_CTL_CPOL; + break; + + case SPIDEV_MODE3: /* CPOL=1 CHPHA=1 */ + modebits = (SPI_CTL_CPOL|SPI_CTL_CPHA); + break; + + default: + return; + } + + /* Then set those bits in the CTL register */ + + regval = inp(EZ80_SPI_CTL); + regval &= ~(SPI_CTL_CPOL|SPI_CTL_CPHA); + regval |= modebits; + outp(EZ80_SPI_CTL, regval); +} + +/**************************************************************************** * Name: spi_waitspif * * Description: @@ -367,7 +421,7 @@ FAR struct spi_dev_s *up_spiinitialize(int port) /* Enable the SPI. * NOTE 1: Interrupts are not used in this driver version. - * NOTE 2: Certain devices may need changes to SCK polarity settings. + * NOTE 2: Initial mode is mode=0. */ outp(EZ80_SPI_CTL, SPI_CTL_SPIEN|SPI_CTL_MASTEREN); diff --git a/nuttx/arch/z80/src/ez80/ez80f91_spi.h b/nuttx/arch/z80/src/ez80/ez80f91_spi.h index 1d03c10cd..3334e472b 100644 --- a/nuttx/arch/z80/src/ez80/ez80f91_spi.h +++ b/nuttx/arch/z80/src/ez80/ez80f91_spi.h @@ -113,8 +113,8 @@ extern "C" { * will bind the SPI driver to the SPI MMC/SD driver. */ -EXTERN void ez80_spiselect(FAR struct spi_dev_s *dev, enum spidev_e devid, boolean selected); -EXTERN ubyte ez80_spistatus(FAR struct spi_dev_s *dev, enum spidev_e devid); +EXTERN void ez80_spiselect(FAR struct spi_dev_s *dev, enum spi_dev_e devid, boolean selected); +EXTERN ubyte ez80_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid); #undef EXTERN #ifdef __cplusplus diff --git a/nuttx/configs/mcu123-lpc214x/src/up_spi.c b/nuttx/configs/mcu123-lpc214x/src/up_spi.c index 210f3d736..a33b0ea76 100644 --- a/nuttx/configs/mcu123-lpc214x/src/up_spi.c +++ b/nuttx/configs/mcu123-lpc214x/src/up_spi.c @@ -86,9 +86,9 @@ * Private Function Prototypes ****************************************************************************/ -static void spi_select(FAR struct spi_dev_s *dev, enum spidev_e devid, boolean selected); +static void spi_select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, boolean selected); static uint32 spi_setfrequency(FAR struct spi_dev_s *dev, uint32 frequency); -static ubyte spi_status(FAR struct spi_dev_s *dev, enum spidev_e devid); +static ubyte spi_status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); static ubyte spi_sndbyte(FAR struct spi_dev_s *dev, ubyte ch); static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const ubyte *buffer, size_t buflen); static void spi_recvblock(FAR struct spi_dev_s *dev, FAR ubyte *buffer, size_t buflen); @@ -135,7 +135,7 @@ static struct spi_dev_s g_spidev = { &g_spiops }; * ****************************************************************************/ -static void spi_select(FAR struct spi_dev_s *dev, enum spidev_e devid, boolean selected) +static void spi_select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, boolean selected) { uint32 bit = 1 << 20; @@ -222,7 +222,7 @@ static uint32 spi_setfrequency(FAR struct spi_dev_s *dev, uint32 frequency) * ****************************************************************************/ -static ubyte spi_status(FAR struct spi_dev_s *dev, enum spidev_e devid) +static ubyte spi_status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) { /* I don't think there is anyway to determine these things on the mcu123.com * board. diff --git a/nuttx/configs/olimex-strp711/src/up_spi.c b/nuttx/configs/olimex-strp711/src/up_spi.c index c7cfa0a27..33b3a8717 100644 --- a/nuttx/configs/olimex-strp711/src/up_spi.c +++ b/nuttx/configs/olimex-strp711/src/up_spi.c @@ -263,9 +263,9 @@ static inline void spi_putreg(FAR struct str71x_spidev_s *priv, ubyte offset, /* SPI methods */ -static void spi_select(FAR struct spi_dev_s *dev, enum spidev_e devid, boolean selected); +static void spi_select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, boolean selected); static uint32 spi_setfrequency(FAR struct spi_dev_s *dev, uint32 frequency); -static ubyte spi_status(FAR struct spi_dev_s *dev, enum spidev_e devid); +static ubyte spi_status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); static ubyte spi_sndbyte(FAR struct spi_dev_s *dev, ubyte ch); static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const ubyte *buffer, size_t buflen); static void spi_recvblock(FAR struct spi_dev_s *dev, FAR ubyte *buffer, size_t buflen); @@ -369,7 +369,7 @@ static inline void spi_putreg(FAR struct str71x_spidev_s *priv, ubyte offset, ui * ****************************************************************************/ -static void spi_select(FAR struct spi_dev_s *dev, enum spidev_e devid, boolean selected) +static void spi_select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, boolean selected) { FAR struct str71x_spidev_s *priv = (FAR struct str71x_spidev_s *)dev; uint16 reg16; @@ -499,7 +499,7 @@ static uint32 spi_setfrequency(FAR struct spi_dev_s *dev, uint32 frequency) * ****************************************************************************/ -static ubyte spi_status(FAR struct spi_dev_s *dev, enum spidev_e devid) +static ubyte spi_status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) { ubyte ret = 0; uint16 reg16 = getreg16(STR71X_GPIO1_PD); diff --git a/nuttx/include/nuttx/spi.h b/nuttx/include/nuttx/spi.h index e07ca6123..57da34304 100644 --- a/nuttx/include/nuttx/spi.h +++ b/nuttx/include/nuttx/spi.h @@ -1,7 +1,7 @@ /**************************************************************************** - * drivers/usbdev/spi.h + * include/nuttx/spi.h * - * Copyright(C) 2008 Gregory Nutt. All rights reserved. + * Copyright(C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -88,6 +88,23 @@ #define SPI_SETFREQUENCY(d,f) ((d)->ops->setfrequency(d,f)) /**************************************************************************** + * Name: SPI_SETMODE + * + * Description: + * Set the SPI mode. Optional. See enum spi_mode_e for mode definitions + * + * Input Parameters: + * dev - Device-specific state data + * mode - The SPI mode requested + * + * Returned Value: + * none + * + ****************************************************************************/ + +#define SPI_SETMODE(d,m) ((d)->ops->mode(d,m)) + +/**************************************************************************** * Name: SPI_STATUS * * Description: @@ -198,21 +215,32 @@ typedef void (*mediachange_t)(void *arg); * which is selected or de-seleted. */ -enum spidev_e +enum spi_dev_e { SPIDEV_NONE = 0, /* Not a valid value */ SPIDEV_MMCSD, /* Select SPI MMC/SD device */ SPIDEV_ETHERNET /* Select SPI ethernet device */ }; +/* Certain SPI devices may required differnt clocking modes */ + +enum spi_mode_e +{ + SPIDEV_MODE0 = 0, /* CPOL=0 CHPHA=0 */ + SPIDEV_MODE1, /* CPOL=0 CHPHA=1 */ + SPIDEV_MODE2, /* CPOL=1 CHPHA=0 */ + SPIDEV_MODE3 /* CPOL=1 CHPHA=1 */ +}; + /* The SPI vtable */ struct spi_dev_s; struct spi_ops_s { - void (*select)(FAR struct spi_dev_s *dev, enum spidev_e devid, boolean selected); + void (*select)(FAR struct spi_dev_s *dev, enum spi_dev_e devid, boolean selected); uint32 (*setfrequency)(FAR struct spi_dev_s *dev, uint32 frequency); - ubyte (*status)(FAR struct spi_dev_s *dev, enum spidev_e devid); + void (*setmode)(FAR struct spi_dev_s *dev, enum spi_mode_e mode); + ubyte (*status)(FAR struct spi_dev_s *dev, enum spi_dev_e devid); ubyte (*sndbyte)(FAR struct spi_dev_s *dev, ubyte ch); void (*sndblock)(FAR struct spi_dev_s *dev, FAR const ubyte *buffer, size_t buflen); void (*recvblock)(FAR struct spi_dev_s *dev, FAR ubyte *buffer, size_t buflen); |