From 5076c4bb878881610884750c5a8fd43bdf99c471 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 3 Dec 2010 01:37:56 +0000 Subject: Add cmddata method to the SPI interface git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3157 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/configs/mcu123-lpc214x/src/up_spi.c | 38 +++++++++++++++++++++++++++++++ nuttx/configs/olimex-strp711/src/up_spi.c | 38 +++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) (limited to 'nuttx/configs') diff --git a/nuttx/configs/mcu123-lpc214x/src/up_spi.c b/nuttx/configs/mcu123-lpc214x/src/up_spi.c index d8ae8baf8..0c32fc6db 100644 --- a/nuttx/configs/mcu123-lpc214x/src/up_spi.c +++ b/nuttx/configs/mcu123-lpc214x/src/up_spi.c @@ -129,6 +129,9 @@ static int spi_lock(FAR struct spi_dev_s *dev, bool lock); static void spi_select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev, uint32_t frequency); static uint8_t spi_status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +#ifdef CONFIG_SPI_CMDDATA +static int spi_cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif static uint16_t spi_send(FAR struct spi_dev_s *dev, uint16_t ch); static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const void *buffer, size_t nwords); static void spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer, size_t nwords); @@ -145,6 +148,9 @@ static const struct spi_ops_s g_spiops = .select = spi_select, .setfrequency = spi_setfrequency, .status = spi_status, +#ifdef CONFIG_SPI_CMDDATA + .cmddata = spi_cmddata, +#endif .send = spi_send, .sndblock = spi_sndblock, .recvblock = spi_recvblock, @@ -310,6 +316,38 @@ static uint8_t spi_status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) return SPI_STATUS_PRESENT; } +/**************************************************************************** + * Name: spi_cmddata + * + * Description: + * Some devices require and additional out-of-band bit to specify if the + * next word sent to the device is a command or data. This is typical, for + * example, in "9-bit" displays where the 9th bit is the CMD/DATA bit. + * This function provides selection of command or data. + * + * This "latches" the CMD/DATA state. It does not have to be called before + * every word is transferred; only when the CMD/DATA state changes. This + * method is required if CONFIG_SPI_CMDDATA is selected in the NuttX + * configuration + * + * Input Parameters: + * dev - Device-specific state data + * cmd - TRUE: The following word is a command; FALSE: the following words + * are data. + * + * Returned Value: + * OK unless an error occurs. Then a negated errno value is returned + * + ****************************************************************************/ + + #ifdef CONFIG_SPI_CMDDATA +static int spi_cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd) +{ +# error "spi_cmddata not implemented" + return -ENOSYS; +} +#endif + /**************************************************************************** * Name: spi_send * diff --git a/nuttx/configs/olimex-strp711/src/up_spi.c b/nuttx/configs/olimex-strp711/src/up_spi.c index 5ca35b72e..bbd046df7 100644 --- a/nuttx/configs/olimex-strp711/src/up_spi.c +++ b/nuttx/configs/olimex-strp711/src/up_spi.c @@ -396,6 +396,9 @@ static int spi_lock(FAR struct spi_dev_s *dev, bool lock); static void spi_select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev, uint32_t frequency); static uint8_t spi_status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +#ifdef CONFIG_SPI_CMDDATA +static int spi_cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif static uint16_t spi_send(FAR struct spi_dev_s *dev, uint16_t wd); static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const void *buffer, size_t buflen); static void spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer, size_t buflen); @@ -412,6 +415,9 @@ static const struct spi_ops_s g_spiops = .select = spi_select, .setfrequency = spi_setfrequency, .status = spi_status, +#ifdef CONFIG_SPI_CMDDATA + .cmddata = spi_cmddata, +#endif .send = spi_send, .sndblock = spi_sndblock, .recvblock = spi_recvblock, @@ -702,6 +708,38 @@ static uint8_t spi_status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) return ret; } +/**************************************************************************** + * Name: spi_cmddata + * + * Description: + * Some devices require and additional out-of-band bit to specify if the + * next word sent to the device is a command or data. This is typical, for + * example, in "9-bit" displays where the 9th bit is the CMD/DATA bit. + * This function provides selection of command or data. + * + * This "latches" the CMD/DATA state. It does not have to be called before + * every word is transferred; only when the CMD/DATA state changes. This + * method is required if CONFIG_SPI_CMDDATA is selected in the NuttX + * configuration + * + * Input Parameters: + * dev - Device-specific state data + * cmd - TRUE: The following word is a command; FALSE: the following words + * are data. + * + * Returned Value: + * OK unless an error occurs. Then a negated errno value is returned + * + ****************************************************************************/ + + #ifdef CONFIG_SPI_CMDDATA +static int spi_cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd) +{ +# error "spi_cmddata not implemented" + return -ENOSYS; +} +#endif + /**************************************************************************** * Name: spi_send * -- cgit v1.2.3