diff --git a/arch/arm/src/efm32/efm32_spi.c b/arch/arm/src/efm32/efm32_spi.c index 117e6646689..0bf2c31a86a 100644 --- a/arch/arm/src/efm32/efm32_spi.c +++ b/arch/arm/src/efm32/efm32_spi.c @@ -1082,6 +1082,7 @@ static void spi_setbits(struct spi_dev_s *dev, int nbits) #ifdef CONFIG_SPI_HWFEATURES static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features) { +#ifdef CONFIG_SPI_BITORDER struct efm32_spidev_s *priv = (struct efm32_spidev_s *)dev; const struct efm32_spiconfig_s *config; uint32_t regval; @@ -1124,6 +1125,9 @@ static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features) /* Other H/W features are not supported */ return ((features & ~HWFEAT_LSBFIRST) == 0) ? OK : -ENOSYS; +#else + return -ENOSYS; +#endif } #endif diff --git a/arch/arm/src/samv7/sam_spi.c b/arch/arm/src/samv7/sam_spi.c index df176330991..06c18b70f13 100644 --- a/arch/arm/src/samv7/sam_spi.c +++ b/arch/arm/src/samv7/sam_spi.c @@ -1221,6 +1221,7 @@ static int spi_setdelay(struct spi_dev_s *dev, uint32_t startdelay, #ifdef CONFIG_SPI_HWFEATURES static int spi_hwfeatures(struct spi_dev_s *dev, uint8_t features) { +#ifdef CONFIG_SPI_CS_CONTROL struct sam_spics_s *spics = (struct sam_spics_s *)dev; struct sam_spidev_s *spi = spi_device(spics); uint32_t regval; @@ -1280,7 +1281,10 @@ static int spi_hwfeatures(struct spi_dev_s *dev, uint8_t features) spi->escape_lastxfer = false; } - return 0; + return ((features & ~HWFEAT_FORCE_CS_CONTROL_MASK) == 0) ? OK : -ENOSYS; +#else + return -ENOSYS; +#endif } #endif diff --git a/arch/arm/src/stm32/stm32_spi.c b/arch/arm/src/stm32/stm32_spi.c index 363d85dbca3..a4af7d36079 100644 --- a/arch/arm/src/stm32/stm32_spi.c +++ b/arch/arm/src/stm32/stm32_spi.c @@ -1198,6 +1198,7 @@ static void spi_setbits(FAR struct spi_dev_s *dev, int nbits) #ifdef CONFIG_SPI_HWFEATURES static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features) { +#ifdef CONFIG_SPI_BITORDER FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)dev; uint16_t setbits; uint16_t clrbits; @@ -1224,6 +1225,9 @@ static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features) /* Other H/W features are not supported */ return ((features & ~HWFEAT_LSBFIRST) == 0) ? OK : -ENOSYS; +#else + return -ENOSYS; +#endif } #endif diff --git a/arch/arm/src/stm32f7/stm32_spi.c b/arch/arm/src/stm32f7/stm32_spi.c index a2b2651ef68..4b0fceba541 100644 --- a/arch/arm/src/stm32f7/stm32_spi.c +++ b/arch/arm/src/stm32f7/stm32_spi.c @@ -1301,6 +1301,7 @@ static void spi_setbits(FAR struct spi_dev_s *dev, int nbits) #ifdef CONFIG_SPI_HWFEATURES static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features) { +#ifdef CONFIG_SPI_BITORDER FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)dev; uint16_t setbitscr1; uint16_t clrbitscr1; @@ -1330,6 +1331,9 @@ static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features) /* Other H/W features are not supported */ return ((features & ~HWFEAT_LSBFIRST) == 0) ? OK : -ENOSYS; +#else + return -ENOSYS; +#endif } #endif diff --git a/arch/arm/src/stm32l4/stm32l4_spi.c b/arch/arm/src/stm32l4/stm32l4_spi.c index b77a4892f23..a241f63ce29 100644 --- a/arch/arm/src/stm32l4/stm32l4_spi.c +++ b/arch/arm/src/stm32l4/stm32l4_spi.c @@ -1165,6 +1165,7 @@ static void spi_setbits(FAR struct spi_dev_s *dev, int nbits) #ifdef CONFIG_SPI_HWFEATURES static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features) { +#ifdef CONFIG_SPI_BITORDER FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)dev; uint16_t setbits; uint16_t clrbits; @@ -1191,6 +1192,9 @@ static int spi_hwfeatures(FAR struct spi_dev_s *dev, spi_hwfeatures_t features) /* Other H/W features are not supported */ return ((features & ~HWFEAT_LSBFIRST) == 0) ? OK : -ENOSYS; +#else + return -ENOSYS; +#endif } #endif diff --git a/drivers/lcd/memlcd.c b/drivers/lcd/memlcd.c index e79f9cb7768..128aa889870 100644 --- a/drivers/lcd/memlcd.c +++ b/drivers/lcd/memlcd.c @@ -59,10 +59,12 @@ * Pre-processor Definitions ****************************************************************************/ -/* H/W features must be enabled in order to support LSB first operation */ +/* Bit order H/W feature must be enabled in order to support LSB first + * operation. + */ -#ifndef CONFIG_SPI_HWFEATURES -# error CONFIG_SPI_HWFEATURES=y required by this driver +#if !defined(CONFIG_SPI_HWFEATURES) || !defined(CONFIG_SPI_BITORDER) +# error CONFIG_SPI_HWFEATURES=y and CONFIG_SPI_BITORDER=y required by this driver #endif /* Cisplay resolution */ diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index b08c18fdba2..bc04dacde46 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -72,6 +72,14 @@ config SPI_CS_CONTROL Enables possibilities to define the behavior of CS. Also enables the hwfeatures() interface method. +config SPI_BITORDER + bool "SPI Bit Order Control" + default n + select SPI_HWFEATURES + ---help--- + Enables capability to select MSB- or LSB-first hardware feature for + data transfers. + config SPI_CS_DELAY_CONTROL bool "SPI CS Delay Control" default n diff --git a/drivers/wireless/pn532.c b/drivers/wireless/pn532.c index 1a499d70e86..4285307532b 100644 --- a/drivers/wireless/pn532.c +++ b/drivers/wireless/pn532.c @@ -57,10 +57,12 @@ ****************************************************************************/ /* Configuration ************************************************************/ -/* H/W features must be enabled in order to support LSB first operation */ +/* Bit order H/W feature must be enabled in order to support LSB first + * operation. + */ -#ifndef CONFIG_SPI_HWFEATURES -# error CONFIG_SPI_HWFEATURES=y required by this driver +#if !defined(CONFIG_SPI_HWFEATURES) || !defined(CONFIG_SPI_BITORDER) +# error CONFIG_SPI_HWFEATURES=y and CONFIG_SPI_BITORDER=y required by this driver #endif #ifdef CONFIG_WL_PN532_DEBUG diff --git a/include/nuttx/spi/spi.h b/include/nuttx/spi/spi.h index 9ef9dc40ded..578738108e1 100644 --- a/include/nuttx/spi/spi.h +++ b/include/nuttx/spi/spi.h @@ -232,13 +232,16 @@ # endif # ifdef CONFIG_SPI_CS_CONTROL +# define HWFEAT_FORCE_CS_CONTROL_MASK (7 << 1) # define HWFEAT_FORCE_CS_INACTIVE_AFTER_TRANSFER (1 << 1) # define HWFEAT_FORCE_CS_ACTIVE_AFTER_TRANSFER (1 << 2) # define HWFEAT_ESCAPE_LASTXFER (1 << 3) # endif -# define HWFEAT_MSBFIRST (0 << 4) -# define HWFEAT_LSBFIRST (1 << 4) +# ifdef CONFIG_SPI_BITORDER +# define HWFEAT_MSBFIRST (0 << 4) +# define HWFEAT_LSBFIRST (1 << 4) +# endif #else /* Any attempt to select hardware features with CONFIG_SPI_HWFEATURES