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