PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/arch/arm/src/stm32/stm32_spi.h

https://bitbucket.org/hg42/nuttx
C Header | 215 lines | 79 code | 30 blank | 106 comment | 0 complexity | 0c006c9a6b1c12319ac3eaf7ba3371c6 MD5 | raw file
Possible License(s): 0BSD
  1. /************************************************************************************
  2. * arch/arm/src/stm32/stm32_spi.h
  3. *
  4. * Copyright (C) 2009, 2015 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ************************************************************************************/
  35. #ifndef __ARCH_ARM_STC_STM32_STM32_SPI_H
  36. #define __ARCH_ARM_STC_STM32_STM32_SPI_H
  37. /************************************************************************************
  38. * Included Files
  39. ************************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <nuttx/spi/spi.h>
  42. #include "chip.h"
  43. #include "chip/stm32_spi.h"
  44. /************************************************************************************
  45. * Pre-processor Definitions
  46. ************************************************************************************/
  47. #ifndef __ASSEMBLY__
  48. #undef EXTERN
  49. #if defined(__cplusplus)
  50. #define EXTERN extern "C"
  51. extern "C"
  52. {
  53. #else
  54. #define EXTERN extern
  55. #endif
  56. /************************************************************************************
  57. * Public Data
  58. ************************************************************************************/
  59. struct spi_dev_s;
  60. /************************************************************************************
  61. * Public Functions
  62. ************************************************************************************/
  63. /************************************************************************************
  64. * Name: stm32_spibus_initialize
  65. *
  66. * Description:
  67. * Initialize the selected SPI bus
  68. *
  69. * Input Parameters:
  70. * bus number (for hardware that has mutiple SPI interfaces)
  71. *
  72. * Returned Value:
  73. * Valid SPI device structure reference on succcess; a NULL on failure
  74. *
  75. ************************************************************************************/
  76. FAR struct spi_dev_s *stm32_spibus_initialize(int bus);
  77. /************************************************************************************
  78. * Name: stm32_spi1/2/...select and stm32_spi1/2/...status
  79. *
  80. * Description:
  81. * The external functions, stm32_spi1/2/...select, stm32_spi1/2/...status, and
  82. * stm32_spi1/2/...cmddata must be provided by board-specific logic. These are
  83. * implementations of the select, status, and cmddata methods of the SPI interface
  84. * defined by struct spi_ops_s (see include/nuttx/spi/spi.h). All other methods
  85. * (including stm32_spibus_initialize()) are provided by common STM32 logic. To use this
  86. * common SPI logic on your board:
  87. *
  88. * 1. Provide logic in stm32_boardinitialize() to configure SPI chip select
  89. * pins.
  90. * 2. Provide stm32_spi1/2/...select() and stm32_spi1/2/...status() functions in your
  91. * board-specific logic. These functions will perform chip selection and
  92. * status operations using GPIOs in the way your board is configured.
  93. * 3. If CONFIG_SPI_CMDDATA is defined in your NuttX configuration file, then
  94. * provide stm32_spi1/2/...cmddata() functions in your board-specific logic.
  95. * These functions will perform cmd/data selection operations using GPIOs in the
  96. * way your board is configured.
  97. * 4. Add a calls to stm32_spibus_initialize() in your low level application
  98. * initialization logic
  99. * 5. The handle returned by stm32_spibus_initialize() may then be used to bind the
  100. * SPI driver to higher level logic (e.g., calling
  101. * mmcsd_spislotinitialize(), for example, will bind the SPI driver to
  102. * the SPI MMC/SD driver).
  103. *
  104. ************************************************************************************/
  105. #ifdef CONFIG_STM32_SPI1
  106. void stm32_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
  107. uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, uint32_t devid);
  108. int stm32_spi1cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
  109. #endif
  110. #ifdef CONFIG_STM32_SPI2
  111. void stm32_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
  112. uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, uint32_t devid);
  113. int stm32_spi2cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
  114. #endif
  115. #ifdef CONFIG_STM32_SPI3
  116. void stm32_spi3select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
  117. uint8_t stm32_spi3status(FAR struct spi_dev_s *dev, uint32_t devid);
  118. int stm32_spi3cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
  119. #endif
  120. #ifdef CONFIG_STM32_SPI4
  121. void stm32_spi4select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
  122. uint8_t stm32_spi4status(FAR struct spi_dev_s *dev, uint32_t devid);
  123. int stm32_spi4cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
  124. #endif
  125. #ifdef CONFIG_STM32_SPI5
  126. void stm32_spi5select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
  127. uint8_t stm32_spi5status(FAR struct spi_dev_s *dev, uint32_t devid);
  128. int stm32_spi5cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
  129. #endif
  130. #ifdef CONFIG_STM32_SPI6
  131. void stm32_spi6select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected);
  132. uint8_t stm32_spi6status(FAR struct spi_dev_s *dev, uint32_t devid);
  133. int stm32_spi6cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd);
  134. #endif
  135. /************************************************************************************
  136. * Name: stm32_spi1/2/...register
  137. *
  138. * Description:
  139. * If the board supports a card detect callback to inform the SPI-based MMC/SD
  140. * driver when an SD card is inserted or removed, then CONFIG_SPI_CALLBACK should
  141. * be defined and the following function(s) must be implemented. These functions
  142. * implements the registercallback method of the SPI interface (see
  143. * include/nuttx/spi/spi.h for details)
  144. *
  145. * Input Parameters:
  146. * dev - Device-specific state data
  147. * callback - The function to call on the media change
  148. * arg - A caller provided value to return with the callback
  149. *
  150. * Returned Value:
  151. * 0 on success; negated errno on failure.
  152. *
  153. ****************************************************************************/
  154. #ifdef CONFIG_SPI_CALLBACK
  155. #ifdef CONFIG_STM32_SPI1
  156. int stm32_spi1register(FAR struct spi_dev_s *dev, spi_mediachange_t callback,
  157. FAR void *arg);
  158. #endif
  159. #ifdef CONFIG_STM32_SPI2
  160. int stm32_spi2register(FAR struct spi_dev_s *dev, spi_mediachange_t callback,
  161. FAR void *arg);
  162. #endif
  163. #ifdef CONFIG_STM32_SPI3
  164. int stm32_spi3register(FAR struct spi_dev_s *dev, spi_mediachange_t callback,
  165. FAR void *arg);
  166. #endif
  167. #ifdef CONFIG_STM32_SPI4
  168. int stm32_spi4register(FAR struct spi_dev_s *dev, spi_mediachange_t callback,
  169. FAR void *arg);
  170. #endif
  171. #ifdef CONFIG_STM32_SPI5
  172. int stm32_spi5register(FAR struct spi_dev_s *dev, spi_mediachange_t callback,
  173. FAR void *arg);
  174. #endif
  175. #ifdef CONFIG_STM32_SPI6
  176. int stm32_spi6register(FAR struct spi_dev_s *dev, spi_mediachange_t callback,
  177. FAR void *arg);
  178. #endif
  179. #endif
  180. #undef EXTERN
  181. #if defined(__cplusplus)
  182. }
  183. #endif
  184. #endif /* __ASSEMBLY__ */
  185. #endif /* __ARCH_ARM_STC_STM32_STM32_SPI_H */