hc32_ll_spi.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. /**
  2. *******************************************************************************
  3. * @file hc32_ll_spi.h
  4. * @brief This file contains all the functions prototypes of the SPI driver
  5. * library.
  6. @verbatim
  7. Change Logs:
  8. Date Author Notes
  9. 2022-12-31 CDT First version
  10. @endverbatim
  11. *******************************************************************************
  12. * Copyright (C) 2022, Xiaohua Semiconductor Co., Ltd. All rights reserved.
  13. *
  14. * This software component is licensed by XHSC under BSD 3-Clause license
  15. * (the "License"); You may not use this file except in compliance with the
  16. * License. You may obtain a copy of the License at:
  17. * opensource.org/licenses/BSD-3-Clause
  18. *
  19. *******************************************************************************
  20. */
  21. #ifndef __HC32_LL_SPI_H__
  22. #define __HC32_LL_SPI_H__
  23. /* C binding of definitions if building with C++ compiler */
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. /*******************************************************************************
  29. * Include files
  30. ******************************************************************************/
  31. #include "hc32_ll_def.h"
  32. #include "hc32f4xx.h"
  33. #include "hc32f4xx_conf.h"
  34. /**
  35. * @addtogroup LL_Driver
  36. * @{
  37. */
  38. /**
  39. * @addtogroup LL_SPI
  40. * @{
  41. */
  42. /*******************************************************************************
  43. * Global type definitions ('typedef')
  44. ******************************************************************************/
  45. /**
  46. * @defgroup SPI_Global_Types SPI Global Types
  47. * @{
  48. */
  49. /**
  50. * @brief Structure definition of SPI initialization.
  51. */
  52. typedef struct {
  53. uint32_t u32WireMode; /*!< SPI wire mode, 3 wire mode or 4 wire mode.
  54. This parameter can be a value of @ref SPI_Wire_Mode_Define */
  55. uint32_t u32TransMode; /*!< SPI transfer mode, send only or full duplex.
  56. This parameter can be a value of @ref SPI_Trans_Mode_Define */
  57. uint32_t u32MasterSlave; /*!< SPI master/slave mode.
  58. This parameter can be a value of @ref SPI_Master_Slave_Mode_Define */
  59. uint32_t u32ModeFaultDetect; /*!< SPI mode fault detect command.
  60. This parameter can be a value of @ref SPI_Mode_Fault_Detect_Command_Define */
  61. uint32_t u32Parity; /*!< SPI parity check selection.
  62. This parameter can be a value of @ref SPI_Parity_Check_Define */
  63. uint32_t u32SpiMode; /*!< SPI mode.
  64. This parameter can be a value of @ref SPI_Mode_Define */
  65. uint32_t u32BaudRatePrescaler; /*!< SPI baud rate prescaler.
  66. This parameter can be a value of @ref SPI_Baud_Rate_Prescaler_Define */
  67. uint32_t u32DataBits; /*!< SPI data bits, 4 bits ~ 32 bits.
  68. This parameter can be a value of @ref SPI_Data_Size_Define */
  69. uint32_t u32FirstBit; /*!< MSB first or LSB first.
  70. This parameter can be a value of @ref SPI_First_Bit_Define */
  71. uint32_t u32SuspendMode; /*!< SPI communication suspend function.
  72. This parameter can be a value of @ref SPI_Com_Suspend_Func_Define */
  73. uint32_t u32FrameLevel; /*!< SPI frame level, SPI_1_FRAME ~ SPI_4_FRAME.
  74. This parameter can be a value of @ref SPI_Frame_Level_Define */
  75. } stc_spi_init_t;
  76. /**
  77. * @brief Structure definition of SPI delay time configuration.
  78. */
  79. typedef struct {
  80. uint32_t u32IntervalDelay; /*!< SPI interval time delay (Next access delay time)
  81. This parameter can be a value of @ref SPI_Interval_Delay_Time_define */
  82. uint32_t u32ReleaseDelay; /*!< SPI release time delay (SCK invalid delay time)
  83. This parameter can be a value of @ref SPI_Release_Delay_Time_define */
  84. uint32_t u32SetupDelay; /*!< SPI Setup time delay (SCK valid delay time) define
  85. This parameter can be a value of @ref SPI_Setup_Delay_Time_define */
  86. } stc_spi_delay_t;
  87. /**
  88. * @}
  89. */
  90. /*******************************************************************************
  91. * Global pre-processor symbols/macros ('#define')
  92. ******************************************************************************/
  93. /**
  94. * @defgroup SPI_Global_Macros SPI Global Macros
  95. * @{
  96. */
  97. /**
  98. * @defgroup SPI_Wire_Mode_Define SPI Wire Mode Define
  99. * @{
  100. */
  101. #define SPI_4_WIRE (0UL)
  102. #define SPI_3_WIRE (SPI_CR_SPIMDS)
  103. /**
  104. * @}
  105. */
  106. /**
  107. * @defgroup SPI_Trans_Mode_Define SPI Transfer Mode Define
  108. * @{
  109. */
  110. #define SPI_FULL_DUPLEX (0UL) /*!< Full duplex. */
  111. #define SPI_SEND_ONLY (SPI_CR_TXMDS) /*!< Send only. */
  112. /**
  113. * @}
  114. */
  115. /**
  116. * @defgroup SPI_Master_Slave_Mode_Define SPI Master Slave Mode Define
  117. * @{
  118. */
  119. #define SPI_SLAVE (0UL)
  120. #define SPI_MASTER (SPI_CR_MSTR)
  121. /**
  122. * @}
  123. */
  124. /**
  125. * @defgroup SPI_Loopback_Selection_Define SPI Loopback Selection Define
  126. * @note Loopback mode is mainly used for parity self-diagnosis in 4-wire full-duplex mode.
  127. * @{
  128. */
  129. #define SPI_LOOPBACK_INVD (0UL)
  130. #define SPI_LOOPBACK_MOSI_INVT (SPI_CR_SPLPBK) /*!< MISO data is the inverse of the data output by MOSI. */
  131. #define SPI_LOOPBACK_MOSI (SPI_CR_SPLPBK2) /*!< MISO data is the data output by MOSI. */
  132. /**
  133. * @}
  134. */
  135. /**
  136. * @defgroup SPI_Int_Type_Define SPI Interrupt Type Define
  137. * @{
  138. */
  139. #define SPI_INT_ERR (SPI_CR_EIE) /*!< Including overload, underload and parity error. */
  140. #define SPI_INT_TX_BUF_EMPTY (SPI_CR_TXIE)
  141. #define SPI_INT_RX_BUF_FULL (SPI_CR_RXIE)
  142. #define SPI_INT_IDLE (SPI_CR_IDIE)
  143. #define SPI_IRQ_ALL (SPI_INT_ERR | SPI_INT_TX_BUF_EMPTY | SPI_INT_RX_BUF_FULL | SPI_INT_IDLE )
  144. /**
  145. * @}
  146. */
  147. /**
  148. * @defgroup SPI_Mode_Fault_Detect_Command_Define SPI Mode Fault Detect Command Define
  149. * @{
  150. */
  151. #define SPI_MD_FAULT_DETECT_DISABLE (0UL) /*!< Disable mode fault detection. */
  152. #define SPI_MD_FAULT_DETECT_ENABLE (SPI_CR_MODFE) /*!< Enable mode fault detection. */
  153. /**
  154. * @}
  155. */
  156. /**
  157. * @defgroup SPI_Parity_Check_Define SPI Parity Check Mode Define
  158. * @{
  159. */
  160. #define SPI_PARITY_INVD (0UL) /*!< Parity check invalid. */
  161. #define SPI_PARITY_EVEN (SPI_CR_PAE) /*!< Parity check selection even parity. */
  162. #define SPI_PARITY_ODD (SPI_CR_PAE | SPI_CR_PAOE) /*!< Parity check selection odd parity. */
  163. /**
  164. * @}
  165. */
  166. /**
  167. * @defgroup SPI_SS_Pin_Define SPI SSx Define
  168. * @{
  169. */
  170. #define SPI_PIN_SS0 (SPI_CFG1_SS0PV)
  171. #define SPI_PIN_SS1 (SPI_CFG1_SS1PV)
  172. #define SPI_PIN_SS2 (SPI_CFG1_SS2PV)
  173. #define SPI_PIN_SS3 (SPI_CFG1_SS3PV)
  174. /**
  175. * @}
  176. */
  177. /**
  178. * @defgroup SPI_Read_Target_Buf_Define SPI Read Data Register Target Buffer Define
  179. * @{
  180. */
  181. #define SPI_RD_TARGET_RD_BUF (0UL) /*!< Read RX buffer. */
  182. #define SPI_RD_TARGET_WR_BUF (SPI_CFG1_SPRDTD) /*!< Read TX buffer. */
  183. /**
  184. * @}
  185. */
  186. /**
  187. * @defgroup SPI_Frame_Level_Define SPI data frame level define, The Data in the SPI_DR register will be send to TX_BUFF
  188. * after enough data frame write to the SPI_DR
  189. * @{
  190. */
  191. #define SPI_1_FRAME (0UL) /*!< Data 1 frame */
  192. #define SPI_2_FRAME (SPI_CFG1_FTHLV_0) /*!< Data 2 frame.*/
  193. #define SPI_3_FRAME (SPI_CFG1_FTHLV_1) /*!< Data 3 frame.*/
  194. #define SPI_4_FRAME (SPI_CFG1_FTHLV_0 | SPI_CFG1_FTHLV_1) /*!< Data 4 frame.*/
  195. /**
  196. * @}
  197. */
  198. /**
  199. * @defgroup SPI_Interval_Delay_Time_define SPI Interval Time Delay (Next Access Delay Time) define
  200. * @{
  201. */
  202. #define SPI_INTERVAL_TIME_1SCK (0UL << SPI_CFG1_MIDI_POS) /*!< 1 SCK + 2 PCLK1 */
  203. #define SPI_INTERVAL_TIME_2SCK (1UL << SPI_CFG1_MIDI_POS) /*!< 2 SCK + 2 PCLK1 */
  204. #define SPI_INTERVAL_TIME_3SCK (2UL << SPI_CFG1_MIDI_POS) /*!< 3 SCK + 2 PCLK1 */
  205. #define SPI_INTERVAL_TIME_4SCK (3UL << SPI_CFG1_MIDI_POS) /*!< 4 SCK + 2 PCLK1 */
  206. #define SPI_INTERVAL_TIME_5SCK (4UL << SPI_CFG1_MIDI_POS) /*!< 5 SCK + 2 PCLK1 */
  207. #define SPI_INTERVAL_TIME_6SCK (5UL << SPI_CFG1_MIDI_POS) /*!< 6 SCK + 2 PCLK1 */
  208. #define SPI_INTERVAL_TIME_7SCK (6UL << SPI_CFG1_MIDI_POS) /*!< 7 SCK + 2 PCLK1 */
  209. #define SPI_INTERVAL_TIME_8SCK (7UL << SPI_CFG1_MIDI_POS) /*!< 8 SCK + 2 PCLK1 */
  210. /**
  211. * @}
  212. */
  213. /**
  214. * @defgroup SPI_Release_Delay_Time_define SPI Release Time Delay (SCK Invalid Delay Time) Define
  215. * @{
  216. */
  217. #define SPI_RELEASE_TIME_1SCK (0UL << SPI_CFG1_MSSDL_POS)
  218. #define SPI_RELEASE_TIME_2SCK (1UL << SPI_CFG1_MSSDL_POS)
  219. #define SPI_RELEASE_TIME_3SCK (2UL << SPI_CFG1_MSSDL_POS)
  220. #define SPI_RELEASE_TIME_4SCK (3UL << SPI_CFG1_MSSDL_POS)
  221. #define SPI_RELEASE_TIME_5SCK (4UL << SPI_CFG1_MSSDL_POS)
  222. #define SPI_RELEASE_TIME_6SCK (5UL << SPI_CFG1_MSSDL_POS)
  223. #define SPI_RELEASE_TIME_7SCK (6UL << SPI_CFG1_MSSDL_POS)
  224. #define SPI_RELEASE_TIME_8SCK (7UL << SPI_CFG1_MSSDL_POS)
  225. /**
  226. * @}
  227. */
  228. /**
  229. * @defgroup SPI_Setup_Delay_Time_define SPI Setup Time Delay (SCK Valid Delay Time) Define
  230. * @{
  231. */
  232. #define SPI_SETUP_TIME_1SCK (0UL << SPI_CFG1_MSSI_POS)
  233. #define SPI_SETUP_TIME_2SCK (1UL << SPI_CFG1_MSSI_POS)
  234. #define SPI_SETUP_TIME_3SCK (2UL << SPI_CFG1_MSSI_POS)
  235. #define SPI_SETUP_TIME_4SCK (3UL << SPI_CFG1_MSSI_POS)
  236. #define SPI_SETUP_TIME_5SCK (4UL << SPI_CFG1_MSSI_POS)
  237. #define SPI_SETUP_TIME_6SCK (5UL << SPI_CFG1_MSSI_POS)
  238. #define SPI_SETUP_TIME_7SCK (6UL << SPI_CFG1_MSSI_POS)
  239. #define SPI_SETUP_TIME_8SCK (7UL << SPI_CFG1_MSSI_POS)
  240. /**
  241. * @}
  242. */
  243. /**
  244. * @defgroup SPI_Com_Suspend_Func_Define SPI Communication Suspend Function Define
  245. * @{
  246. */
  247. #define SPI_COM_SUSP_FUNC_OFF (0UL)
  248. #define SPI_COM_SUSP_FUNC_ON (SPI_CR_CSUSPE)
  249. /**
  250. * @}
  251. */
  252. /**
  253. * @defgroup SPI_Mode_Define SPI Mode Define
  254. * @{
  255. */
  256. #define SPI_MD_0 (0UL) /*!< SCK pin output low in idle state; \
  257. MOSI/MISO pin data valid in odd edge, \
  258. MOSI/MISO pin data change in even edge */
  259. #define SPI_MD_1 (SPI_CFG2_CPHA) /*!< SCK pin output low in idle state; \
  260. MOSI/MISO pin data valid in even edge, \
  261. MOSI/MISO pin data change in odd edge */
  262. #define SPI_MD_2 (SPI_CFG2_CPOL) /*!< SCK pin output high in idle state; \
  263. MOSI/MISO pin data valid in odd edge, \
  264. MOSI/MISO pin data change in even edge */
  265. #define SPI_MD_3 (SPI_CFG2_CPOL | SPI_CFG2_CPHA) /*!< SCK pin output high in idle state; \
  266. MOSI/MISO pin data valid in even edge, \
  267. MOSI/MISO pin data change in odd edge */
  268. /**
  269. * @}
  270. */
  271. /**
  272. * @defgroup SPI_Baud_Rate_Prescaler_Define SPI Baudrate Prescaler Define
  273. * @{
  274. */
  275. #define SPI_BR_CLK_DIV2 (0UL) /*!< PCLK / 2 */
  276. #define SPI_BR_CLK_DIV4 (1UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 4 */
  277. #define SPI_BR_CLK_DIV6 (2UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 6 */
  278. #define SPI_BR_CLK_DIV8 (3UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 8 */
  279. #define SPI_BR_CLK_DIV10 (4UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 10 */
  280. #define SPI_BR_CLK_DIV12 (5UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 12 */
  281. #define SPI_BR_CLK_DIV14 (6UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 14 */
  282. #define SPI_BR_CLK_DIV16 (7UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 16 */
  283. #define SPI_BR_CLK_DIV18 (8UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 18 */
  284. #define SPI_BR_CLK_DIV20 (9UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 20 */
  285. #define SPI_BR_CLK_DIV22 (10UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 22 */
  286. #define SPI_BR_CLK_DIV24 (11UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 24 */
  287. #define SPI_BR_CLK_DIV26 (12UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 26 */
  288. #define SPI_BR_CLK_DIV28 (13UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 28 */
  289. #define SPI_BR_CLK_DIV30 (14UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 30 */
  290. #define SPI_BR_CLK_DIV32 (15UL << SPI_CFG1_CLKDIV_POS) /*!< PCLK / 32 */
  291. #define SPI_BR_CLK_DIV36 ((8UL << SPI_CFG1_CLKDIV_POS) | (1UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 36 */
  292. #define SPI_BR_CLK_DIV40 ((9UL << SPI_CFG1_CLKDIV_POS) | (1UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 40 */
  293. #define SPI_BR_CLK_DIV44 ((10UL << SPI_CFG1_CLKDIV_POS) | (1UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 44 */
  294. #define SPI_BR_CLK_DIV48 ((11UL << SPI_CFG1_CLKDIV_POS) | (1UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 48 */
  295. #define SPI_BR_CLK_DIV52 ((12UL << SPI_CFG1_CLKDIV_POS) | (1UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 52 */
  296. #define SPI_BR_CLK_DIV56 ((13UL << SPI_CFG1_CLKDIV_POS) | (1UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 56 */
  297. #define SPI_BR_CLK_DIV60 ((14UL << SPI_CFG1_CLKDIV_POS) | (1UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 60 */
  298. #define SPI_BR_CLK_DIV64 ((15UL << SPI_CFG1_CLKDIV_POS) | (1UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 64 */
  299. #define SPI_BR_CLK_DIV72 ((8UL << SPI_CFG1_CLKDIV_POS) | (2UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 72 */
  300. #define SPI_BR_CLK_DIV80 ((9UL << SPI_CFG1_CLKDIV_POS) | (2UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 80 */
  301. #define SPI_BR_CLK_DIV88 ((10UL << SPI_CFG1_CLKDIV_POS) | (2UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 88 */
  302. #define SPI_BR_CLK_DIV96 ((11UL << SPI_CFG1_CLKDIV_POS) | (2UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 96 */
  303. #define SPI_BR_CLK_DIV104 ((12UL << SPI_CFG1_CLKDIV_POS) | (2UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 104 */
  304. #define SPI_BR_CLK_DIV112 ((13UL << SPI_CFG1_CLKDIV_POS) | (2UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 112 */
  305. #define SPI_BR_CLK_DIV120 ((14UL << SPI_CFG1_CLKDIV_POS) | (2UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 120 */
  306. #define SPI_BR_CLK_DIV128 ((15UL << SPI_CFG1_CLKDIV_POS) | (2UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 128 */
  307. #define SPI_BR_CLK_DIV144 ((8UL << SPI_CFG1_CLKDIV_POS) | (3UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 144 */
  308. #define SPI_BR_CLK_DIV160 ((9UL << SPI_CFG1_CLKDIV_POS) | (3UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 160 */
  309. #define SPI_BR_CLK_DIV176 ((10UL << SPI_CFG1_CLKDIV_POS) | (3UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 176 */
  310. #define SPI_BR_CLK_DIV192 ((11UL << SPI_CFG1_CLKDIV_POS) | (3UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 192 */
  311. #define SPI_BR_CLK_DIV208 ((12UL << SPI_CFG1_CLKDIV_POS) | (3UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 208 */
  312. #define SPI_BR_CLK_DIV224 ((13UL << SPI_CFG1_CLKDIV_POS) | (3UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 224 */
  313. #define SPI_BR_CLK_DIV240 ((14UL << SPI_CFG1_CLKDIV_POS) | (3UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 240 */
  314. #define SPI_BR_CLK_DIV256 ((15UL << SPI_CFG1_CLKDIV_POS) | (3UL << SPI_CFG2_MBR_POS)) /*!< PCLK / 256 */
  315. /**
  316. * @}
  317. */
  318. /**
  319. * @defgroup SPI_Data_Size_Define SPI Data Size Define
  320. * @{
  321. */
  322. #define SPI_DATA_SIZE_4BIT (0UL << SPI_CFG2_DSIZE_POS)
  323. #define SPI_DATA_SIZE_5BIT (1UL << SPI_CFG2_DSIZE_POS)
  324. #define SPI_DATA_SIZE_6BIT (2UL << SPI_CFG2_DSIZE_POS)
  325. #define SPI_DATA_SIZE_7BIT (3UL << SPI_CFG2_DSIZE_POS)
  326. #define SPI_DATA_SIZE_8BIT (4UL << SPI_CFG2_DSIZE_POS)
  327. #define SPI_DATA_SIZE_9BIT (5UL << SPI_CFG2_DSIZE_POS)
  328. #define SPI_DATA_SIZE_10BIT (6UL << SPI_CFG2_DSIZE_POS)
  329. #define SPI_DATA_SIZE_11BIT (7UL << SPI_CFG2_DSIZE_POS)
  330. #define SPI_DATA_SIZE_12BIT (8UL << SPI_CFG2_DSIZE_POS)
  331. #define SPI_DATA_SIZE_13BIT (9UL << SPI_CFG2_DSIZE_POS)
  332. #define SPI_DATA_SIZE_14BIT (10UL << SPI_CFG2_DSIZE_POS)
  333. #define SPI_DATA_SIZE_15BIT (11UL << SPI_CFG2_DSIZE_POS)
  334. #define SPI_DATA_SIZE_16BIT (12UL << SPI_CFG2_DSIZE_POS)
  335. #define SPI_DATA_SIZE_20BIT (13UL << SPI_CFG2_DSIZE_POS)
  336. #define SPI_DATA_SIZE_24BIT (14UL << SPI_CFG2_DSIZE_POS)
  337. #define SPI_DATA_SIZE_32BIT (15UL << SPI_CFG2_DSIZE_POS)
  338. /**
  339. * @}
  340. */
  341. /**
  342. * @defgroup SPI_First_Bit_Define SPI First Bit Define
  343. * @{
  344. */
  345. #define SPI_FIRST_MSB (0UL)
  346. #define SPI_FIRST_LSB (SPI_CFG2_LSBF)
  347. /**
  348. * @}
  349. */
  350. /**
  351. * @defgroup SPI_Comm_Mode_Define SPI communication mode Define
  352. * @{
  353. */
  354. #define SPI_COMM_MD_NORMAL (0UL) /*!< Normal communication mode */
  355. #define SPI_COMM_MD_CONTINUE (SPI_CFG1_CTMDS) /*!< Continuous communication mode */
  356. /**
  357. * @}
  358. */
  359. /**
  360. * @defgroup SPI_State_Flag_Define SPI State Flag Define
  361. * @{
  362. */
  363. #define SPI_FLAG_OVERLOAD (SPI_SR_OVRERF)
  364. #define SPI_FLAG_IDLE (SPI_SR_IDLNF)
  365. #define SPI_FLAG_MD_FAULT (SPI_SR_MODFERF)
  366. #define SPI_FLAG_PARITY_ERR (SPI_SR_PERF)
  367. #define SPI_FLAG_UNDERLOAD (SPI_SR_UDRERF)
  368. #define SPI_FLAG_TX_BUF_EMPTY (SPI_SR_TDEF) /*!< This flag is set when the data in the data register \
  369. is copied into the shift register, but the transmission \
  370. of the data bit may not have been completed. */
  371. #define SPI_FLAG_RX_BUF_FULL (SPI_SR_RDFF) /*!< Indicates that a data was received. */
  372. #define SPI_FLAG_CLR_ALL (SPI_FLAG_OVERLOAD | SPI_FLAG_MD_FAULT | SPI_FLAG_PARITY_ERR | SPI_FLAG_UNDERLOAD)
  373. #define SPI_FLAG_ALL (SPI_FLAG_OVERLOAD | SPI_FLAG_IDLE | SPI_FLAG_MD_FAULT | SPI_FLAG_PARITY_ERR | \
  374. SPI_FLAG_UNDERLOAD | SPI_FLAG_TX_BUF_EMPTY | SPI_FLAG_RX_BUF_FULL)
  375. /**
  376. * @}
  377. */
  378. /**
  379. * @}
  380. */
  381. /*******************************************************************************
  382. * Global variable definitions ('extern')
  383. ******************************************************************************/
  384. /*******************************************************************************
  385. Global function prototypes (definition in C source)
  386. ******************************************************************************/
  387. /**
  388. * @addtogroup SPI_Global_Functions
  389. * @{
  390. */
  391. int32_t SPI_StructInit(stc_spi_init_t *pstcSpiInit);
  392. int32_t SPI_Init(CM_SPI_TypeDef *SPIx, const stc_spi_init_t *pstcSpiInit);
  393. void SPI_DeInit(CM_SPI_TypeDef *SPIx);
  394. void SPI_IntCmd(CM_SPI_TypeDef *SPIx, uint32_t u32IntType, en_functional_state_t enNewState);
  395. void SPI_Cmd(CM_SPI_TypeDef *SPIx, en_functional_state_t enNewState);
  396. void SPI_WriteData(CM_SPI_TypeDef *SPIx, uint32_t u32Data);
  397. uint32_t SPI_ReadData(const CM_SPI_TypeDef *SPIx);
  398. en_flag_status_t SPI_GetStatus(const CM_SPI_TypeDef *SPIx, uint32_t u32Flag);
  399. void SPI_ClearStatus(CM_SPI_TypeDef *SPIx, uint32_t u32Flag);
  400. void SPI_LoopbackModeConfig(CM_SPI_TypeDef *SPIx, uint32_t u32Mode);
  401. void SPI_ParityCheckCmd(CM_SPI_TypeDef *SPIx, en_functional_state_t enNewState);
  402. void SPI_SSValidLevelConfig(CM_SPI_TypeDef *SPIx, uint32_t u32SSPin, en_functional_state_t enNewState);
  403. int32_t SPI_DelayTimeConfig(CM_SPI_TypeDef *SPIx, const stc_spi_delay_t *pstcDelayConfig);
  404. void SPI_SSPinSelect(CM_SPI_TypeDef *SPIx, uint32_t u32SSPin);
  405. void SPI_ReadBufConfig(CM_SPI_TypeDef *SPIx, uint32_t u32ReadBuf);
  406. int32_t SPI_DelayStructInit(stc_spi_delay_t *pstcDelayConfig);
  407. void SPI_SetCommMode(CM_SPI_TypeDef *SPIx, uint32_t u32Mode);
  408. int32_t SPI_Trans(CM_SPI_TypeDef *SPIx, const void *pvTxBuf, uint32_t u32TxLen, uint32_t u32Timeout);
  409. int32_t SPI_Receive(CM_SPI_TypeDef *SPIx, void *pvRxBuf, uint32_t u32RxLen, uint32_t u32Timeout);
  410. int32_t SPI_TransReceive(CM_SPI_TypeDef *SPIx, const void *pvTxBuf, void *pvRxBuf, uint32_t u32Len, uint32_t u32Timeout);
  411. /**
  412. * @}
  413. */
  414. #endif /* LL_SPI_ENABLE */
  415. /**
  416. * @}
  417. */
  418. /**
  419. * @}
  420. */
  421. #ifdef __cplusplus
  422. }
  423. #endif
  424. /*******************************************************************************
  425. * EOF (not truncated)
  426. ******************************************************************************/