From 38f250cde3889dbc50f4f3f931876d67a340a8c3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 4 Mar 2015 06:52:46 -0600 Subject: [PATCH] Add missing SPI callback functions to the STM32 SPI driver. From Freddie Chopin --- arch/arm/src/stm32/stm32_spi.c | 36 +++++++++++++++++++---- arch/arm/src/stm32/stm32_spi.h | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 6 deletions(-) diff --git a/arch/arm/src/stm32/stm32_spi.c b/arch/arm/src/stm32/stm32_spi.c index 6cbdff6ec9..8ba8692405 100644 --- a/arch/arm/src/stm32/stm32_spi.c +++ b/arch/arm/src/stm32/stm32_spi.c @@ -285,7 +285,11 @@ static const struct spi_ops_s g_sp1iops = .sndblock = spi_sndblock, .recvblock = spi_recvblock, #endif - .registercallback = 0, +#ifdef CONFIG_SPI_CALLBACK + .registercallback = stm32_spi1register, /* provided externally */ +#else + .registercallback = 0, /* not implemented */ +#endif }; static struct stm32_spidev_s g_spi1dev = @@ -324,7 +328,11 @@ static const struct spi_ops_s g_sp2iops = .sndblock = spi_sndblock, .recvblock = spi_recvblock, #endif - .registercallback = 0, +#ifdef CONFIG_SPI_CALLBACK + .registercallback = stm32_spi2register, /* provided externally */ +#else + .registercallback = 0, /* not implemented */ +#endif }; static struct stm32_spidev_s g_spi2dev = @@ -363,7 +371,11 @@ static const struct spi_ops_s g_sp3iops = .sndblock = spi_sndblock, .recvblock = spi_recvblock, #endif - .registercallback = 0, +#ifdef CONFIG_SPI_CALLBACK + .registercallback = stm32_spi3register, /* provided externally */ +#else + .registercallback = 0, /* not implemented */ +#endif }; static struct stm32_spidev_s g_spi3dev = @@ -402,7 +414,11 @@ static const struct spi_ops_s g_sp4iops = .sndblock = spi_sndblock, .recvblock = spi_recvblock, #endif - .registercallback = 0, +#ifdef CONFIG_SPI_CALLBACK + .registercallback = stm32_spi4register, /* provided externally */ +#else + .registercallback = 0, /* not implemented */ +#endif }; static struct stm32_spidev_s g_spi4dev = @@ -441,7 +457,11 @@ static const struct spi_ops_s g_sp5iops = .sndblock = spi_sndblock, .recvblock = spi_recvblock, #endif - .registercallback = 0, +#ifdef CONFIG_SPI_CALLBACK + .registercallback = stm32_spi5register, /* provided externally */ +#else + .registercallback = 0, /* not implemented */ +#endif }; static struct stm32_spidev_s g_spi5dev = @@ -480,7 +500,11 @@ static const struct spi_ops_s g_sp6iops = .sndblock = spi_sndblock, .recvblock = spi_recvblock, #endif - .registercallback = 0, +#ifdef CONFIG_SPI_CALLBACK + .registercallback = stm32_spi6register, /* provided externally */ +#else + .registercallback = 0, /* not implemented */ +#endif }; static struct stm32_spidev_s g_spi6dev = diff --git a/arch/arm/src/stm32/stm32_spi.h b/arch/arm/src/stm32/stm32_spi.h index 2ee090958f..ddcc0f083c 100644 --- a/arch/arm/src/stm32/stm32_spi.h +++ b/arch/arm/src/stm32/stm32_spi.h @@ -136,6 +136,58 @@ uint8_t stm32_spi6status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); int stm32_spi6cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); #endif +/**************************************************************************** + * Name: stm32_spi1/2/...register + * + * Description: + * If the board supports a card detect callback to inform the SPI-based + * MMC/SD drvier when an SD card is inserted or removed, then + * CONFIG_SPI_CALLBACK should be defined and the following function(s) must + * be implemented. These functiosn implements the registercallback method + * of the SPI interface (see include/nuttx/spi/spi.h for details) + * + * Input Parameters: + * dev - Device-specific state data + * callback - The funtion to call on the media change + * arg - A caller provided value to return with the callback + * + * Returned Value: + * 0 on success; negated errno on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_SPI_CALLBACK +#ifdef CONFIG_STM32_SPI1 +EXTERN int stm32_spi1register(FAR struct spi_dev_s *dev, + spi_mediachange_t callback, void *arg); +#endif + +#ifdef CONFIG_STM32_SPI2 +EXTERN int stm32_spi2register(FAR struct spi_dev_s *dev, + spi_mediachange_t callback, void *arg); +#endif + +#ifdef CONFIG_STM32_SPI3 +EXTERN int stm32_spi3register(FAR struct spi_dev_s *dev, + spi_mediachange_t callback, void *arg); +#endif + +#ifdef CONFIG_STM32_SPI4 +EXTERN int stm32_spi4register(FAR struct spi_dev_s *dev, + spi_mediachange_t callback, void *arg); +#endif + +#ifdef CONFIG_STM32_SPI5 +EXTERN int stm32_spi5register(FAR struct spi_dev_s *dev, + spi_mediachange_t callback, void *arg); +#endif + +#ifdef CONFIG_STM32_SPI6 +EXTERN int stm32_spi6register(FAR struct spi_dev_s *dev, + spi_mediachange_t callback, void *arg); +#endif +#endif + #undef EXTERN #if defined(__cplusplus) }