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