gd32f30x_spi.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*!
  2. \file gd32f30x_spi.h
  3. \brief definitions for the SPI
  4. \version 2017-02-10, V1.0.0, firmware for GD32F30x
  5. \version 2018-10-10, V1.1.0, firmware for GD32F30x
  6. \version 2018-12-25, V2.0.0, firmware for GD32F30x
  7. \version 2020-09-30, V2.1.0, firmware for GD32F30x
  8. */
  9. /*
  10. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  11. Redistribution and use in source and binary forms, with or without modification,
  12. are permitted provided that the following conditions are met:
  13. 1. Redistributions of source code must retain the above copyright notice, this
  14. list of conditions and the following disclaimer.
  15. 2. Redistributions in binary form must reproduce the above copyright notice,
  16. this list of conditions and the following disclaimer in the documentation
  17. and/or other materials provided with the distribution.
  18. 3. Neither the name of the copyright holder nor the names of its contributors
  19. may be used to endorse or promote products derived from this software without
  20. specific prior written permission.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  25. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. OF SUCH DAMAGE.
  31. */
  32. #ifndef GD32F30X_SPI_H
  33. #define GD32F30X_SPI_H
  34. #include "gd32f30x.h"
  35. /* SPIx(x=0,1,2) definitions */
  36. #define SPI0 (SPI_BASE + 0x0000F800U)
  37. #define SPI1 SPI_BASE
  38. #define SPI2 (SPI_BASE + 0x00000400U)
  39. /* SPI registers definitions */
  40. #define SPI_CTL0(spix) REG32((spix) + 0x00U) /*!< SPI control register 0 */
  41. #define SPI_CTL1(spix) REG32((spix) + 0x04U) /*!< SPI control register 1*/
  42. #define SPI_STAT(spix) REG32((spix) + 0x08U) /*!< SPI status register */
  43. #define SPI_DATA(spix) REG32((spix) + 0x0CU) /*!< SPI data register */
  44. #define SPI_CRCPOLY(spix) REG32((spix) + 0x10U) /*!< SPI CRC polynomial register */
  45. #define SPI_RCRC(spix) REG32((spix) + 0x14U) /*!< SPI receive CRC register */
  46. #define SPI_TCRC(spix) REG32((spix) + 0x18U) /*!< SPI transmit CRC register */
  47. #define SPI_I2SCTL(spix) REG32((spix) + 0x1CU) /*!< SPI I2S control register */
  48. #define SPI_I2SPSC(spix) REG32((spix) + 0x20U) /*!< SPI I2S clock prescaler register */
  49. #define SPI_QCTL(spix) REG32((spix) + 0x80U) /*!< SPI quad mode control register(only SPI0) */
  50. /* bits definitions */
  51. /* SPI_CTL0 */
  52. #define SPI_CTL0_CKPH BIT(0) /*!< clock phase selection*/
  53. #define SPI_CTL0_CKPL BIT(1) /*!< clock polarity selection */
  54. #define SPI_CTL0_MSTMOD BIT(2) /*!< master mode enable */
  55. #define SPI_CTL0_PSC BITS(3,5) /*!< master clock prescaler selection */
  56. #define SPI_CTL0_SPIEN BIT(6) /*!< SPI enable*/
  57. #define SPI_CTL0_LF BIT(7) /*!< LSB first mode */
  58. #define SPI_CTL0_SWNSS BIT(8) /*!< NSS pin selection in NSS software mode */
  59. #define SPI_CTL0_SWNSSEN BIT(9) /*!< NSS software mode selection */
  60. #define SPI_CTL0_RO BIT(10) /*!< receive only */
  61. #define SPI_CTL0_FF16 BIT(11) /*!< data frame size */
  62. #define SPI_CTL0_CRCNT BIT(12) /*!< CRC next transfer */
  63. #define SPI_CTL0_CRCEN BIT(13) /*!< CRC calculation enable */
  64. #define SPI_CTL0_BDOEN BIT(14) /*!< bidirectional transmit output enable*/
  65. #define SPI_CTL0_BDEN BIT(15) /*!< bidirectional enable */
  66. /* SPI_CTL1 */
  67. #define SPI_CTL1_DMAREN BIT(0) /*!< receive buffer dma enable */
  68. #define SPI_CTL1_DMATEN BIT(1) /*!< transmit buffer dma enable */
  69. #define SPI_CTL1_NSSDRV BIT(2) /*!< drive NSS output */
  70. #define SPI_CTL1_NSSP BIT(3) /*!< SPI NSS pulse mode enable */
  71. #define SPI_CTL1_TMOD BIT(4) /*!< SPI TI mode enable */
  72. #define SPI_CTL1_ERRIE BIT(5) /*!< errors interrupt enable */
  73. #define SPI_CTL1_RBNEIE BIT(6) /*!< receive buffer not empty interrupt enable */
  74. #define SPI_CTL1_TBEIE BIT(7) /*!< transmit buffer empty interrupt enable */
  75. /* SPI_STAT */
  76. #define SPI_STAT_RBNE BIT(0) /*!< receive buffer not empty */
  77. #define SPI_STAT_TBE BIT(1) /*!< transmit buffer empty */
  78. #define SPI_STAT_I2SCH BIT(2) /*!< I2S channel side */
  79. #define SPI_STAT_TXURERR BIT(3) /*!< I2S transmission underrun error bit */
  80. #define SPI_STAT_CRCERR BIT(4) /*!< SPI CRC error bit */
  81. #define SPI_STAT_CONFERR BIT(5) /*!< SPI configuration error bit */
  82. #define SPI_STAT_RXORERR BIT(6) /*!< SPI reception overrun error bit */
  83. #define SPI_STAT_TRANS BIT(7) /*!< transmitting on-going bit */
  84. #define SPI_STAT_FERR BIT(8) /*!< format error bit */
  85. /* SPI_DATA */
  86. #define SPI_DATA_DATA BITS(0,15) /*!< data transfer register */
  87. /* SPI_CRCPOLY */
  88. #define SPI_CRCPOLY_CPR BITS(0,15) /*!< CRC polynomial register */
  89. /* SPI_RCRC */
  90. #define SPI_RCRC_RCR BITS(0,15) /*!< RX CRC register */
  91. /* SPI_TCRC */
  92. #define SPI_TCRC_TCR BITS(0,15) /*!< TX CRC register */
  93. /* SPI_I2SCTL */
  94. #define SPI_I2SCTL_CHLEN BIT(0) /*!< channel length */
  95. #define SPI_I2SCTL_DTLEN BITS(1,2) /*!< data length */
  96. #define SPI_I2SCTL_CKPL BIT(3) /*!< idle state clock polarity */
  97. #define SPI_I2SCTL_I2SSTD BITS(4,5) /*!< I2S standard selection */
  98. #define SPI_I2SCTL_PCMSMOD BIT(7) /*!< PCM frame synchronization mode */
  99. #define SPI_I2SCTL_I2SOPMOD BITS(8,9) /*!< I2S operation mode */
  100. #define SPI_I2SCTL_I2SEN BIT(10) /*!< I2S enable */
  101. #define SPI_I2SCTL_I2SSEL BIT(11) /*!< I2S mode selection */
  102. /* SPI_I2SPSC */
  103. #define SPI_I2SPSC_DIV BITS(0,7) /*!< dividing factor for the prescaler */
  104. #define SPI_I2SPSC_OF BIT(8) /*!< odd factor for the prescaler */
  105. #define SPI_I2SPSC_MCKOEN BIT(9) /*!< I2S MCK output enable */
  106. /* SPI_QCTL(only for SPI0) */
  107. #define SPI_QCTL_QMOD BIT(0) /*!< quad-SPI mode enable */
  108. #define SPI_QCTL_QRD BIT(1) /*!< quad-SPI mode read select */
  109. #define SPI_QCTL_IO23_DRV BIT(2) /*!< drive SPI_IO2 and SPI_IO3 enable */
  110. /* constants definitions */
  111. /* SPI and I2S parameter struct definitions */
  112. typedef struct
  113. {
  114. uint32_t device_mode; /*!< SPI master or slave */
  115. uint32_t trans_mode; /*!< SPI transtype */
  116. uint32_t frame_size; /*!< SPI frame size */
  117. uint32_t nss; /*!< SPI NSS control by handware or software */
  118. uint32_t endian; /*!< SPI big endian or little endian */
  119. uint32_t clock_polarity_phase; /*!< SPI clock phase and polarity */
  120. uint32_t prescale; /*!< SPI prescale factor */
  121. }spi_parameter_struct;
  122. /* SPI mode definitions */
  123. #define SPI_MASTER (SPI_CTL0_MSTMOD | SPI_CTL0_SWNSS) /*!< SPI as master */
  124. #define SPI_SLAVE ((uint32_t)0x00000000U) /*!< SPI as slave */
  125. /* SPI bidirectional transfer direction */
  126. #define SPI_BIDIRECTIONAL_TRANSMIT SPI_CTL0_BDOEN /*!< SPI work in transmit-only mode */
  127. #define SPI_BIDIRECTIONAL_RECEIVE (~SPI_CTL0_BDOEN) /*!< SPI work in receive-only mode */
  128. /* SPI transmit type */
  129. #define SPI_TRANSMODE_FULLDUPLEX ((uint32_t)0x00000000U) /*!< SPI receive and send data at fullduplex communication */
  130. #define SPI_TRANSMODE_RECEIVEONLY SPI_CTL0_RO /*!< SPI only receive data */
  131. #define SPI_TRANSMODE_BDRECEIVE SPI_CTL0_BDEN /*!< bidirectional receive data */
  132. #define SPI_TRANSMODE_BDTRANSMIT (SPI_CTL0_BDEN | SPI_CTL0_BDOEN) /*!< bidirectional transmit data*/
  133. /* SPI frame size */
  134. #define SPI_FRAMESIZE_16BIT SPI_CTL0_FF16 /*!< SPI frame size is 16 bits */
  135. #define SPI_FRAMESIZE_8BIT ((uint32_t)0x00000000U) /*!< SPI frame size is 8 bits */
  136. /* SPI NSS control mode */
  137. #define SPI_NSS_SOFT SPI_CTL0_SWNSSEN /*!< SPI NSS control by sofrware */
  138. #define SPI_NSS_HARD ((uint32_t)0x00000000U) /*!< SPI NSS control by hardware */
  139. /* SPI transmit way */
  140. #define SPI_ENDIAN_MSB ((uint32_t)0x00000000U) /*!< SPI transmit way is big endian: transmit MSB first */
  141. #define SPI_ENDIAN_LSB SPI_CTL0_LF /*!< SPI transmit way is little endian: transmit LSB first */
  142. /* SPI clock phase and polarity */
  143. #define SPI_CK_PL_LOW_PH_1EDGE ((uint32_t)0x00000000U) /*!< SPI clock polarity is low level and phase is first edge */
  144. #define SPI_CK_PL_HIGH_PH_1EDGE SPI_CTL0_CKPL /*!< SPI clock polarity is high level and phase is first edge */
  145. #define SPI_CK_PL_LOW_PH_2EDGE SPI_CTL0_CKPH /*!< SPI clock polarity is low level and phase is second edge */
  146. #define SPI_CK_PL_HIGH_PH_2EDGE (SPI_CTL0_CKPL | SPI_CTL0_CKPH) /*!< SPI clock polarity is high level and phase is second edge */
  147. /* SPI clock prescale factor */
  148. #define CTL0_PSC(regval) (BITS(3,5) & ((uint32_t)(regval) << 3))
  149. #define SPI_PSC_2 CTL0_PSC(0) /*!< SPI clock prescale factor is 2 */
  150. #define SPI_PSC_4 CTL0_PSC(1) /*!< SPI clock prescale factor is 4 */
  151. #define SPI_PSC_8 CTL0_PSC(2) /*!< SPI clock prescale factor is 8 */
  152. #define SPI_PSC_16 CTL0_PSC(3) /*!< SPI clock prescale factor is 16 */
  153. #define SPI_PSC_32 CTL0_PSC(4) /*!< SPI clock prescale factor is 32 */
  154. #define SPI_PSC_64 CTL0_PSC(5) /*!< SPI clock prescale factor is 64 */
  155. #define SPI_PSC_128 CTL0_PSC(6) /*!< SPI clock prescale factor is 128 */
  156. #define SPI_PSC_256 CTL0_PSC(7) /*!< SPI clock prescale factor is 256 */
  157. /* I2S audio sample rate */
  158. #define I2S_AUDIOSAMPLE_8K ((uint32_t)8000U) /*!< I2S audio sample rate is 8KHz */
  159. #define I2S_AUDIOSAMPLE_11K ((uint32_t)11025U) /*!< I2S audio sample rate is 11KHz */
  160. #define I2S_AUDIOSAMPLE_16K ((uint32_t)16000U) /*!< I2S audio sample rate is 16KHz */
  161. #define I2S_AUDIOSAMPLE_22K ((uint32_t)22050U) /*!< I2S audio sample rate is 22KHz */
  162. #define I2S_AUDIOSAMPLE_32K ((uint32_t)32000U) /*!< I2S audio sample rate is 32KHz */
  163. #define I2S_AUDIOSAMPLE_44K ((uint32_t)44100U) /*!< I2S audio sample rate is 44KHz */
  164. #define I2S_AUDIOSAMPLE_48K ((uint32_t)48000U) /*!< I2S audio sample rate is 48KHz */
  165. #define I2S_AUDIOSAMPLE_96K ((uint32_t)96000U) /*!< I2S audio sample rate is 96KHz */
  166. #define I2S_AUDIOSAMPLE_192K ((uint32_t)192000U) /*!< I2S audio sample rate is 192KHz */
  167. /* I2S frame format */
  168. #define I2SCTL_DTLEN(regval) (BITS(1,2) & ((uint32_t)(regval) << 1))
  169. #define I2S_FRAMEFORMAT_DT16B_CH16B I2SCTL_DTLEN(0) /*!< I2S data length is 16 bit and channel length is 16 bit */
  170. #define I2S_FRAMEFORMAT_DT16B_CH32B (I2SCTL_DTLEN(0) | SPI_I2SCTL_CHLEN) /*!< I2S data length is 16 bit and channel length is 32 bit */
  171. #define I2S_FRAMEFORMAT_DT24B_CH32B (I2SCTL_DTLEN(1) | SPI_I2SCTL_CHLEN) /*!< I2S data length is 24 bit and channel length is 32 bit */
  172. #define I2S_FRAMEFORMAT_DT32B_CH32B (I2SCTL_DTLEN(2) | SPI_I2SCTL_CHLEN) /*!< I2S data length is 32 bit and channel length is 32 bit */
  173. /* I2S master clock output */
  174. #define I2S_MCKOUT_DISABLE ((uint32_t)0x00000000U) /*!< I2S master clock output disable */
  175. #define I2S_MCKOUT_ENABLE SPI_I2SPSC_MCKOEN /*!< I2S master clock output enable */
  176. /* I2S operation mode */
  177. #define I2SCTL_I2SOPMOD(regval) (BITS(8,9) & ((uint32_t)(regval) << 8))
  178. #define I2S_MODE_SLAVETX I2SCTL_I2SOPMOD(0) /*!< I2S slave transmit mode */
  179. #define I2S_MODE_SLAVERX I2SCTL_I2SOPMOD(1) /*!< I2S slave receive mode */
  180. #define I2S_MODE_MASTERTX I2SCTL_I2SOPMOD(2) /*!< I2S master transmit mode */
  181. #define I2S_MODE_MASTERRX I2SCTL_I2SOPMOD(3) /*!< I2S master receive mode */
  182. /* I2S standard */
  183. #define I2SCTL_I2SSTD(regval) (BITS(4,5) & ((uint32_t)(regval) << 4))
  184. #define I2S_STD_PHILLIPS I2SCTL_I2SSTD(0) /*!< I2S phillips standard */
  185. #define I2S_STD_MSB I2SCTL_I2SSTD(1) /*!< I2S MSB standard */
  186. #define I2S_STD_LSB I2SCTL_I2SSTD(2) /*!< I2S LSB standard */
  187. #define I2S_STD_PCMSHORT I2SCTL_I2SSTD(3) /*!< I2S PCM short standard */
  188. #define I2S_STD_PCMLONG (I2SCTL_I2SSTD(3) | SPI_I2SCTL_PCMSMOD) /*!< I2S PCM long standard */
  189. /* I2S clock polarity */
  190. #define I2S_CKPL_LOW ((uint32_t)0x00000000U) /*!< I2S clock polarity low level */
  191. #define I2S_CKPL_HIGH SPI_I2SCTL_CKPL /*!< I2S clock polarity high level */
  192. /* SPI DMA constants definitions */
  193. #define SPI_DMA_TRANSMIT ((uint8_t)0x00U) /*!< SPI transmit data use DMA */
  194. #define SPI_DMA_RECEIVE ((uint8_t)0x01U) /*!< SPI receive data use DMA */
  195. /* SPI CRC constants definitions */
  196. #define SPI_CRC_TX ((uint8_t)0x00U) /*!< SPI transmit CRC value */
  197. #define SPI_CRC_RX ((uint8_t)0x01U) /*!< SPI receive CRC value */
  198. /* SPI/I2S interrupt enable/disable constants definitions */
  199. #define SPI_I2S_INT_TBE ((uint8_t)0x00U) /*!< transmit buffer empty interrupt */
  200. #define SPI_I2S_INT_RBNE ((uint8_t)0x01U) /*!< receive buffer not empty interrupt */
  201. #define SPI_I2S_INT_ERR ((uint8_t)0x02U) /*!< error interrupt */
  202. /* SPI/I2S interrupt flag constants definitions */
  203. #define SPI_I2S_INT_FLAG_TBE ((uint8_t)0x00U) /*!< transmit buffer empty interrupt flag */
  204. #define SPI_I2S_INT_FLAG_RBNE ((uint8_t)0x01U) /*!< receive buffer not empty interrupt flag */
  205. #define SPI_I2S_INT_FLAG_RXORERR ((uint8_t)0x02U) /*!< overrun interrupt flag */
  206. #define SPI_INT_FLAG_CONFERR ((uint8_t)0x03U) /*!< config error interrupt flag */
  207. #define SPI_INT_FLAG_CRCERR ((uint8_t)0x04U) /*!< CRC error interrupt flag */
  208. #define I2S_INT_FLAG_TXURERR ((uint8_t)0x05U) /*!< underrun error interrupt flag */
  209. #define SPI_I2S_INT_FLAG_FERR ((uint8_t)0x06U) /*!< format error interrupt flag */
  210. /* SPI/I2S flag definitions */
  211. #define SPI_FLAG_RBNE SPI_STAT_RBNE /*!< receive buffer not empty flag */
  212. #define SPI_FLAG_TBE SPI_STAT_TBE /*!< transmit buffer empty flag */
  213. #define SPI_FLAG_CRCERR SPI_STAT_CRCERR /*!< CRC error flag */
  214. #define SPI_FLAG_CONFERR SPI_STAT_CONFERR /*!< mode config error flag */
  215. #define SPI_FLAG_RXORERR SPI_STAT_RXORERR /*!< receive overrun error flag */
  216. #define SPI_FLAG_TRANS SPI_STAT_TRANS /*!< transmit on-going flag */
  217. #define SPI_FLAG_FERR SPI_STAT_FERR /*!< format error flag */
  218. #define I2S_FLAG_RBNE SPI_STAT_RBNE /*!< receive buffer not empty flag */
  219. #define I2S_FLAG_TBE SPI_STAT_TBE /*!< transmit buffer empty flag */
  220. #define I2S_FLAG_CH SPI_STAT_I2SCH /*!< channel side flag */
  221. #define I2S_FLAG_TXURERR SPI_STAT_TXURERR /*!< underrun error flag */
  222. #define I2S_FLAG_RXORERR SPI_STAT_RXORERR /*!< overrun error flag */
  223. #define I2S_FLAG_TRANS SPI_STAT_TRANS /*!< transmit on-going flag */
  224. #define I2S_FLAG_FERR SPI_STAT_FERR /*!< format error flag */
  225. /* function declarations */
  226. /* SPI/I2S deinitialization and initialization functions */
  227. /* reset SPI and I2S */
  228. void spi_i2s_deinit(uint32_t spi_periph);
  229. /* initialize the parameters of SPI struct with the default values */
  230. void spi_struct_para_init(spi_parameter_struct* spi_struct);
  231. /* initialize SPI parameter */
  232. void spi_init(uint32_t spi_periph, spi_parameter_struct* spi_struct);
  233. /* enable SPI */
  234. void spi_enable(uint32_t spi_periph);
  235. /* disable SPI */
  236. void spi_disable(uint32_t spi_periph);
  237. /* initialize I2S parameter */
  238. void i2s_init(uint32_t spi_periph, uint32_t i2s_mode, uint32_t i2s_standard, uint32_t i2s_ckpl);
  239. /* configure I2S prescaler */
  240. void i2s_psc_config(uint32_t spi_periph, uint32_t i2s_audiosample, uint32_t i2s_frameformat, uint32_t i2s_mckout);
  241. /* enable I2S */
  242. void i2s_enable(uint32_t spi_periph);
  243. /* disable I2S */
  244. void i2s_disable(uint32_t spi_periph);
  245. /* NSS functions */
  246. /* enable SPI NSS output */
  247. void spi_nss_output_enable(uint32_t spi_periph);
  248. /* disable SPI NSS output */
  249. void spi_nss_output_disable(uint32_t spi_periph);
  250. /* SPI NSS pin high level in software mode */
  251. void spi_nss_internal_high(uint32_t spi_periph);
  252. /* SPI NSS pin low level in software mode */
  253. void spi_nss_internal_low(uint32_t spi_periph);
  254. /* SPI DMA functions */
  255. /* enable SPI DMA */
  256. void spi_dma_enable(uint32_t spi_periph, uint8_t dma);
  257. /* disable SPI DMA */
  258. void spi_dma_disable(uint32_t spi_periph, uint8_t dma);
  259. /* SPI/I2S transfer functions */
  260. /* configure SPI/I2S data frame format */
  261. void spi_i2s_data_frame_format_config(uint32_t spi_periph, uint16_t frame_format);
  262. /* SPI transmit data */
  263. void spi_i2s_data_transmit(uint32_t spi_periph, uint16_t data);
  264. /* SPI receive data */
  265. uint16_t spi_i2s_data_receive(uint32_t spi_periph);
  266. /* configure SPI bidirectional transfer direction */
  267. void spi_bidirectional_transfer_config(uint32_t spi_periph, uint32_t transfer_direction);
  268. /* clear TI Mode Format Error flag status */
  269. void spi_i2s_format_error_clear(uint32_t spi_periph, uint32_t flag);
  270. /* SPI CRC functions */
  271. /* set SPI CRC polynomial */
  272. void spi_crc_polynomial_set(uint32_t spi_periph, uint16_t crc_poly);
  273. /* get SPI CRC polynomial */
  274. uint16_t spi_crc_polynomial_get(uint32_t spi_periph);
  275. /* turn on SPI CRC function */
  276. void spi_crc_on(uint32_t spi_periph);
  277. /* turn off SPI CRC function */
  278. void spi_crc_off(uint32_t spi_periph);
  279. /* SPI next data is CRC value */
  280. void spi_crc_next(uint32_t spi_periph);
  281. /* get SPI CRC send value or receive value */
  282. uint16_t spi_crc_get(uint32_t spi_periph, uint8_t crc);
  283. /* clear SPI CRC error flag status */
  284. void spi_crc_error_clear(uint32_t spi_periph);
  285. /* SPI TI mode functions */
  286. /* enable SPI TI mode */
  287. void spi_ti_mode_enable(uint32_t spi_periph);
  288. /* disable SPI TI mode */
  289. void spi_ti_mode_disable(uint32_t spi_periph);
  290. /* SPI NSS pulse mode functions */
  291. /* enable SPI NSS pulse mode */
  292. void spi_nssp_mode_enable(uint32_t spi_periph);
  293. /* disable SPI NSS pulse mode */
  294. void spi_nssp_mode_disable(uint32_t spi_periph);
  295. /* quad wire SPI functions */
  296. /* enable quad wire SPI */
  297. void spi_quad_enable(uint32_t spi_periph);
  298. /* disable quad wire SPI */
  299. void spi_quad_disable(uint32_t spi_periph);
  300. /* enable quad wire SPI write */
  301. void spi_quad_write_enable(uint32_t spi_periph);
  302. /* enable quad wire SPI read */
  303. void spi_quad_read_enable(uint32_t spi_periph);
  304. /* enable quad wire SPI_IO2 and SPI_IO3 pin output */
  305. void spi_quad_io23_output_enable(uint32_t spi_periph);
  306. /* disable quad wire SPI_IO2 and SPI_IO3 pin output */
  307. void spi_quad_io23_output_disable(uint32_t spi_periph);
  308. /* flag and interrupt functions */
  309. /* enable SPI and I2S interrupt */
  310. void spi_i2s_interrupt_enable(uint32_t spi_periph, uint8_t interrupt);
  311. /* disable SPI and I2S interrupt */
  312. void spi_i2s_interrupt_disable(uint32_t spi_periph, uint8_t interrupt);
  313. /* get SPI and I2S interrupt status */
  314. FlagStatus spi_i2s_interrupt_flag_get(uint32_t spi_periph, uint8_t interrupt);
  315. /* get SPI and I2S flag status */
  316. FlagStatus spi_i2s_flag_get(uint32_t spi_periph, uint32_t flag);
  317. #endif /* GD32F30X_SPI_H */