1 /******************************************************************************
\r
4 * @brief M2351 series SPI driver header file
\r
6 * @copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
\r
7 *****************************************************************************/
\r
17 /** @addtogroup Standard_Driver Standard Driver
\r
21 /** @addtogroup SPI_Driver SPI Driver
\r
25 /** @addtogroup SPI_EXPORTED_CONSTANTS SPI Exported Constants
\r
29 #define SPI_MODE_0 (SPI_CTL_TXNEG_Msk) /*!< CLKPOL=0; RXNEG=0; TXNEG=1 */
\r
30 #define SPI_MODE_1 (SPI_CTL_RXNEG_Msk) /*!< CLKPOL=0; RXNEG=1; TXNEG=0 */
\r
31 #define SPI_MODE_2 (SPI_CTL_CLKPOL_Msk | SPI_CTL_RXNEG_Msk) /*!< CLKPOL=1; RXNEG=1; TXNEG=0 */
\r
32 #define SPI_MODE_3 (SPI_CTL_CLKPOL_Msk | SPI_CTL_TXNEG_Msk) /*!< CLKPOL=1; RXNEG=0; TXNEG=1 */
\r
34 #define SPI_SLAVE (SPI_CTL_SLAVE_Msk) /*!< Set as slave */
\r
35 #define SPI_MASTER (0x0UL) /*!< Set as master */
\r
37 #define SPI_SS (SPI_SSCTL_SS_Msk) /*!< Set SS */
\r
38 #define SPI_SS_ACTIVE_HIGH (SPI_SSCTL_SSACTPOL_Msk) /*!< SS active high */
\r
39 #define SPI_SS_ACTIVE_LOW (0x0UL) /*!< SS active low */
\r
41 /* SPI Interrupt Mask */
\r
42 #define SPI_UNIT_INT_MASK (0x001UL) /*!< Unit transfer interrupt mask */
\r
43 #define SPI_SSACT_INT_MASK (0x002UL) /*!< Slave selection signal active interrupt mask */
\r
44 #define SPI_SSINACT_INT_MASK (0x004UL) /*!< Slave selection signal inactive interrupt mask */
\r
45 #define SPI_SLVUR_INT_MASK (0x008UL) /*!< Slave under run interrupt mask */
\r
46 #define SPI_SLVBE_INT_MASK (0x010UL) /*!< Slave bit count error interrupt mask */
\r
47 #define SPI_TXUF_INT_MASK (0x040UL) /*!< Slave TX underflow interrupt mask */
\r
48 #define SPI_FIFO_TXTH_INT_MASK (0x080UL) /*!< FIFO TX threshold interrupt mask */
\r
49 #define SPI_FIFO_RXTH_INT_MASK (0x100UL) /*!< FIFO RX threshold interrupt mask */
\r
50 #define SPI_FIFO_RXOV_INT_MASK (0x200UL) /*!< FIFO RX overrun interrupt mask */
\r
51 #define SPI_FIFO_RXTO_INT_MASK (0x400UL) /*!< FIFO RX time-out interrupt mask */
\r
53 /* SPI Status Mask */
\r
54 #define SPI_BUSY_MASK (0x01UL) /*!< Busy status mask */
\r
55 #define SPI_RX_EMPTY_MASK (0x02UL) /*!< RX empty status mask */
\r
56 #define SPI_RX_FULL_MASK (0x04UL) /*!< RX full status mask */
\r
57 #define SPI_TX_EMPTY_MASK (0x08UL) /*!< TX empty status mask */
\r
58 #define SPI_TX_FULL_MASK (0x10UL) /*!< TX full status mask */
\r
59 #define SPI_TXRX_RESET_MASK (0x20UL) /*!< TX or RX reset status mask */
\r
60 #define SPI_SPIEN_STS_MASK (0x40UL) /*!< SPIEN status mask */
\r
61 #define SPI_SSLINE_STS_MASK (0x80UL) /*!< SPIx_SS line status mask */
\r
64 /* I2S Data Width */
\r
65 #define SPII2S_DATABIT_8 (0UL << SPI_I2SCTL_WDWIDTH_Pos) /*!< I2S data width is 8-bit */
\r
66 #define SPII2S_DATABIT_16 (1UL << SPI_I2SCTL_WDWIDTH_Pos) /*!< I2S data width is 16-bit */
\r
67 #define SPII2S_DATABIT_24 (2UL << SPI_I2SCTL_WDWIDTH_Pos) /*!< I2S data width is 24-bit */
\r
68 #define SPII2S_DATABIT_32 (3UL << SPI_I2SCTL_WDWIDTH_Pos) /*!< I2S data width is 32-bit */
\r
70 /* I2S Audio Format */
\r
71 #define SPII2S_MONO SPI_I2SCTL_MONO_Msk /*!< Monaural channel */
\r
72 #define SPII2S_STEREO (0UL) /*!< Stereo channel */
\r
74 /* I2S Data Format */
\r
75 #define SPII2S_FORMAT_I2S (0UL << SPI_I2SCTL_FORMAT_Pos) /*!< I2S data format */
\r
76 #define SPII2S_FORMAT_MSB (1UL << SPI_I2SCTL_FORMAT_Pos) /*!< MSB justified data format */
\r
77 #define SPII2S_FORMAT_PCMA (2UL << SPI_I2SCTL_FORMAT_Pos) /*!< PCM mode A data format */
\r
78 #define SPII2S_FORMAT_PCMB (3UL << SPI_I2SCTL_FORMAT_Pos) /*!< PCM mode B data format */
\r
80 /* I2S Operation mode */
\r
81 #define SPII2S_MODE_SLAVE SPI_I2SCTL_SLAVE_Msk /*!< As slave mode */
\r
82 #define SPII2S_MODE_MASTER (0UL) /*!< As master mode */
\r
84 /* I2S TX FIFO Threshold */
\r
85 #define SPII2S_FIFO_TX_LEVEL_WORD_0 (0UL) /*!< TX threshold is 0 word */
\r
86 #define SPII2S_FIFO_TX_LEVEL_WORD_1 (1UL << SPI_FIFOCTL_TXTH_Pos) /*!< TX threshold is 1 word */
\r
87 #define SPII2S_FIFO_TX_LEVEL_WORD_2 (2UL << SPI_FIFOCTL_TXTH_Pos) /*!< TX threshold is 2 words */
\r
88 #define SPII2S_FIFO_TX_LEVEL_WORD_3 (3UL << SPI_FIFOCTL_TXTH_Pos) /*!< TX threshold is 3 words */
\r
89 /* I2S RX FIFO Threshold */
\r
90 #define SPII2S_FIFO_RX_LEVEL_WORD_1 (0UL) /*!< RX threshold is 1 word */
\r
91 #define SPII2S_FIFO_RX_LEVEL_WORD_2 (1UL << SPI_FIFOCTL_RXTH_Pos) /*!< RX threshold is 2 words */
\r
92 #define SPII2S_FIFO_RX_LEVEL_WORD_3 (2UL << SPI_FIFOCTL_RXTH_Pos) /*!< RX threshold is 3 words */
\r
93 #define SPII2S_FIFO_RX_LEVEL_WORD_4 (3UL << SPI_FIFOCTL_RXTH_Pos) /*!< RX threshold is 4 words */
\r
95 /* I2S Record Channel */
\r
96 #define SPII2S_MONO_RIGHT (0UL) /*!< Record mono right channel */
\r
97 #define SPII2S_MONO_LEFT SPI_I2SCTL_RXLCH_Msk /*!< Record mono left channel */
\r
100 #define SPII2S_RIGHT (0UL) /*!< Select right channel */
\r
101 #define SPII2S_LEFT (1UL) /*!< Select left channel */
\r
103 /* I2S Interrupt Mask */
\r
104 #define SPII2S_FIFO_TXTH_INT_MASK (0x01UL) /*!< TX FIFO threshold interrupt mask */
\r
105 #define SPII2S_FIFO_RXTH_INT_MASK (0x02UL) /*!< RX FIFO threshold interrupt mask */
\r
106 #define SPII2S_FIFO_RXOV_INT_MASK (0x04UL) /*!< RX FIFO overrun interrupt mask */
\r
107 #define SPII2S_FIFO_RXTO_INT_MASK (0x08UL) /*!< RX FIFO time-out interrupt mask */
\r
108 #define SPII2S_TXUF_INT_MASK (0x10UL) /*!< TX FIFO underflow interrupt mask */
\r
109 #define SPII2S_RIGHT_ZC_INT_MASK (0x20UL) /*!< Right channel zero cross interrupt mask */
\r
110 #define SPII2S_LEFT_ZC_INT_MASK (0x40UL) /*!< Left channel zero cross interrupt mask */
\r
112 /*@}*/ /* end of group SPI_EXPORTED_CONSTANTS */
\r
115 /** @addtogroup SPI_EXPORTED_FUNCTIONS SPI Exported Functions
\r
120 * @brief Clear the unit transfer interrupt flag.
\r
121 * @param[in] spi The pointer of the specified SPI module.
\r
123 * @details Write 1 to UNITIF bit of SPI_STATUS register to clear the unit transfer interrupt flag.
\r
125 #define SPI_CLR_UNIT_TRANS_INT_FLAG(spi) ( (spi)->STATUS = SPI_STATUS_UNITIF_Msk )
\r
128 * @brief Trigger RX PDMA function.
\r
129 * @param[in] spi The pointer of the specified SPI module.
\r
131 * @details Set RXPDMAEN bit of SPI_PDMACTL register to enable RX PDMA transfer function.
\r
133 #define SPI_TRIGGER_RX_PDMA(spi) ( (spi)->PDMACTL |= SPI_PDMACTL_RXPDMAEN_Msk )
\r
136 * @brief Trigger TX PDMA function.
\r
137 * @param[in] spi The pointer of the specified SPI module.
\r
139 * @details Set TXPDMAEN bit of SPI_PDMACTL register to enable TX PDMA transfer function.
\r
141 #define SPI_TRIGGER_TX_PDMA(spi) ( (spi)->PDMACTL |= SPI_PDMACTL_TXPDMAEN_Msk )
\r
144 * @brief Disable RX PDMA transfer.
\r
145 * @param[in] spi The pointer of the specified SPI module.
\r
147 * @details Clear RXPDMAEN bit of SPI_PDMACTL register to disable RX PDMA transfer function.
\r
149 #define SPI_DISABLE_RX_PDMA(spi) ( (spi)->PDMACTL &= ~SPI_PDMACTL_RXPDMAEN_Msk )
\r
152 * @brief Disable TX PDMA transfer.
\r
153 * @param[in] spi The pointer of the specified SPI module.
\r
155 * @details Clear TXPDMAEN bit of SPI_PDMACTL register to disable TX PDMA transfer function.
\r
157 #define SPI_DISABLE_TX_PDMA(spi) ( (spi)->PDMACTL &= ~SPI_PDMACTL_TXPDMAEN_Msk )
\r
160 * @brief Get the count of available data in RX FIFO.
\r
161 * @param[in] spi The pointer of the specified SPI module.
\r
162 * @return The count of available data in RX FIFO.
\r
163 * @details Read RXCNT (SPI_STATUS[27:24]) to get the count of available data in RX FIFO.
\r
165 #define SPI_GET_RX_FIFO_COUNT(spi) ( ((spi)->STATUS & SPI_STATUS_RXCNT_Msk) >> SPI_STATUS_RXCNT_Pos )
\r
168 * @brief Get the RX FIFO empty flag.
\r
169 * @param[in] spi The pointer of the specified SPI module.
\r
170 * @retval 0 RX FIFO is not empty.
\r
171 * @retval 1 RX FIFO is empty.
\r
172 * @details Read RXEMPTY bit of SPI_STATUS register to get the RX FIFO empty flag.
\r
174 #define SPI_GET_RX_FIFO_EMPTY_FLAG(spi) ( ((spi)->STATUS & SPI_STATUS_RXEMPTY_Msk) >> SPI_STATUS_RXEMPTY_Pos )
\r
177 * @brief Get the TX FIFO empty flag.
\r
178 * @param[in] spi The pointer of the specified SPI module.
\r
179 * @retval 0 TX FIFO is not empty.
\r
180 * @retval 1 TX FIFO is empty.
\r
181 * @details Read TXEMPTY bit of SPI_STATUS register to get the TX FIFO empty flag.
\r
183 #define SPI_GET_TX_FIFO_EMPTY_FLAG(spi) ( ((spi)->STATUS & SPI_STATUS_TXEMPTY_Msk) >> SPI_STATUS_TXEMPTY_Pos )
\r
186 * @brief Get the TX FIFO full flag.
\r
187 * @param[in] spi The pointer of the specified SPI module.
\r
188 * @retval 0 TX FIFO is not full.
\r
189 * @retval 1 TX FIFO is full.
\r
190 * @details Read TXFULL bit of SPI_STATUS register to get the TX FIFO full flag.
\r
192 #define SPI_GET_TX_FIFO_FULL_FLAG(spi) ( ((spi)->STATUS & SPI_STATUS_TXFULL_Msk) >> SPI_STATUS_TXFULL_Pos )
\r
195 * @brief Get the datum read from RX register.
\r
196 * @param[in] spi The pointer of the specified SPI module.
\r
197 * @return Data in RX register.
\r
198 * @details Read SPI_RX register to get the received datum.
\r
200 #define SPI_READ_RX(spi) ( (spi)->RX )
\r
203 * @brief Write datum to TX register.
\r
204 * @param[in] spi The pointer of the specified SPI module.
\r
205 * @param[in] u32TxData The datum which user attempt to transfer through SPI bus.
\r
207 * @details Write u32TxData to SPI_TX register.
\r
209 #define SPI_WRITE_TX(spi, u32TxData) ( (spi)->TX = (u32TxData) )
\r
212 * @brief Set SPIx_SS pin to high state.
\r
213 * @param[in] spi The pointer of the specified SPI module.
\r
215 * @details Disable automatic slave selection function and set SPIx_SS pin to high state.
\r
217 #define SPI_SET_SS_HIGH(spi) ( (spi)->SSCTL = ((spi)->SSCTL & (~SPI_SSCTL_AUTOSS_Msk)) | (SPI_SSCTL_SSACTPOL_Msk | SPI_SSCTL_SS_Msk) )
\r
220 * @brief Set SPIx_SS pin to low state.
\r
221 * @param[in] spi The pointer of the specified SPI module.
\r
223 * @details Disable automatic slave selection function and set SPIx_SS pin to low state.
\r
225 #define SPI_SET_SS_LOW(spi) ( (spi)->SSCTL = ((spi)->SSCTL & (~(SPI_SSCTL_AUTOSS_Msk | SPI_SSCTL_SSACTPOL_Msk))) | SPI_SSCTL_SS_Msk )
\r
228 * @brief Enable Byte Reorder function.
\r
229 * @param[in] spi The pointer of the specified SPI module.
\r
231 * @details Enable Byte Reorder function. The suspend interval depends on the setting of SUSPITV (SPI_CTL[7:4]).
\r
233 #define SPI_ENABLE_BYTE_REORDER(spi) ( (spi)->CTL |= SPI_CTL_REORDER_Msk )
\r
236 * @brief Disable Byte Reorder function.
\r
237 * @param[in] spi The pointer of the specified SPI module.
\r
239 * @details Clear REORDER bit field of SPI_CTL register to disable Byte Reorder function.
\r
241 #define SPI_DISABLE_BYTE_REORDER(spi) ( (spi)->CTL &= ~SPI_CTL_REORDER_Msk )
\r
244 * @brief Set the length of suspend interval.
\r
245 * @param[in] spi The pointer of the specified SPI module.
\r
246 * @param[in] u32SuspCycle Decides the length of suspend interval. It could be 0 ~ 15.
\r
248 * @details Set the length of suspend interval according to u32SuspCycle.
\r
249 * The length of suspend interval is ((u32SuspCycle + 0.5) * the length of one SPI bus clock cycle).
\r
251 #define SPI_SET_SUSPEND_CYCLE(spi, u32SuspCycle) ( (spi)->CTL = ((spi)->CTL & ~SPI_CTL_SUSPITV_Msk) | ((u32SuspCycle) << SPI_CTL_SUSPITV_Pos) )
\r
254 * @brief Set the SPI transfer sequence with LSB first.
\r
255 * @param[in] spi The pointer of the specified SPI module.
\r
257 * @details Set LSB bit of SPI_CTL register to set the SPI transfer sequence with LSB first.
\r
259 #define SPI_SET_LSB_FIRST(spi) ( (spi)->CTL |= SPI_CTL_LSB_Msk )
\r
262 * @brief Set the SPI transfer sequence with MSB first.
\r
263 * @param[in] spi The pointer of the specified SPI module.
\r
265 * @details Clear LSB bit of SPI_CTL register to set the SPI transfer sequence with MSB first.
\r
267 #define SPI_SET_MSB_FIRST(spi) ( (spi)->CTL &= ~SPI_CTL_LSB_Msk )
\r
270 * @brief Set the data width of a SPI transaction.
\r
271 * @param[in] spi The pointer of the specified SPI module.
\r
272 * @param[in] u32Width The bit width of one transaction.
\r
274 * @details The data width can be 8 ~ 32 bits.
\r
276 #define SPI_SET_DATA_WIDTH(spi, u32Width) ( (spi)->CTL = ((spi)->CTL & ~SPI_CTL_DWIDTH_Msk) | (((u32Width) & 0x1F) << SPI_CTL_DWIDTH_Pos) )
\r
279 * @brief Get the SPI busy state.
\r
280 * @param[in] spi The pointer of the specified SPI module.
\r
281 * @retval 0 SPI controller is not busy.
\r
282 * @retval 1 SPI controller is busy.
\r
283 * @details This macro will return the busy state of SPI controller.
\r
285 #define SPI_IS_BUSY(spi) ( ((spi)->STATUS & SPI_STATUS_BUSY_Msk) >> SPI_STATUS_BUSY_Pos )
\r
288 * @brief Enable SPI controller.
\r
289 * @param[in] spi The pointer of the specified SPI module.
\r
291 * @details Set SPIEN (SPI_CTL[0]) to enable SPI controller.
\r
293 #define SPI_ENABLE(spi) ( (spi)->CTL |= SPI_CTL_SPIEN_Msk )
\r
296 * @brief Disable SPI controller.
\r
297 * @param[in] spi The pointer of the specified SPI module.
\r
299 * @details Clear SPIEN (SPI_CTL[0]) to disable SPI controller.
\r
301 #define SPI_DISABLE(spi) ( (spi)->CTL &= ~SPI_CTL_SPIEN_Msk )
\r
303 /* Declare these inline functions here to avoid MISRA C 2004 rule 8.1 error */
\r
304 __STATIC_INLINE void SPII2S_ENABLE_TX_ZCD(SPI_T *i2s, uint32_t u32ChMask);
\r
305 __STATIC_INLINE void SPII2S_DISABLE_TX_ZCD(SPI_T *i2s, uint32_t u32ChMask);
\r
306 __STATIC_INLINE void SPII2S_SET_MONO_RX_CHANNEL(SPI_T *i2s, uint32_t u32Ch);
\r
309 * @brief Enable zero cross detection function.
\r
310 * @param[in] i2s The pointer of the specified I2S module.
\r
311 * @param[in] u32ChMask The mask for left or right channel. Valid values are:
\r
312 * - \ref SPII2S_RIGHT
\r
313 * - \ref SPII2S_LEFT
\r
315 * @details This function will set RZCEN or LZCEN bit of SPI_I2SCTL register to enable zero cross detection function.
\r
317 __STATIC_INLINE void SPII2S_ENABLE_TX_ZCD(SPI_T *i2s, uint32_t u32ChMask)
\r
319 if(u32ChMask == SPII2S_RIGHT)
\r
321 i2s->I2SCTL |= SPI_I2SCTL_RZCEN_Msk;
\r
325 i2s->I2SCTL |= SPI_I2SCTL_LZCEN_Msk;
\r
330 * @brief Disable zero cross detection function.
\r
331 * @param[in] i2s The pointer of the specified I2S module.
\r
332 * @param[in] u32ChMask The mask for left or right channel. Valid values are:
\r
333 * - \ref SPII2S_RIGHT
\r
334 * - \ref SPII2S_LEFT
\r
336 * @details This function will clear RZCEN or LZCEN bit of SPI_I2SCTL register to disable zero cross detection function.
\r
338 __STATIC_INLINE void SPII2S_DISABLE_TX_ZCD(SPI_T *i2s, uint32_t u32ChMask)
\r
340 if(u32ChMask == SPII2S_RIGHT)
\r
342 i2s->I2SCTL &= ~SPI_I2SCTL_RZCEN_Msk;
\r
346 i2s->I2SCTL &= ~SPI_I2SCTL_LZCEN_Msk;
\r
351 * @brief Enable I2S TX DMA function.
\r
352 * @param[in] i2s The pointer of the specified I2S module.
\r
354 * @details This macro will set TXPDMAEN bit of SPI_PDMACTL register to transmit data with PDMA.
\r
356 #define SPII2S_ENABLE_TXDMA(i2s) ( (i2s)->PDMACTL |= SPI_PDMACTL_TXPDMAEN_Msk )
\r
359 * @brief Disable I2S TX DMA function.
\r
360 * @param[in] i2s The pointer of the specified I2S module.
\r
362 * @details This macro will clear TXPDMAEN bit of SPI_PDMACTL register to disable TX DMA function.
\r
364 #define SPII2S_DISABLE_TXDMA(i2s) ( (i2s)->PDMACTL &= ~SPI_PDMACTL_TXPDMAEN_Msk )
\r
367 * @brief Enable I2S RX DMA function.
\r
368 * @param[in] i2s The pointer of the specified I2S module.
\r
370 * @details This macro will set RXPDMAEN bit of SPI_PDMACTL register to receive data with PDMA.
\r
372 #define SPII2S_ENABLE_RXDMA(i2s) ( (i2s)->PDMACTL |= SPI_PDMACTL_RXPDMAEN_Msk )
\r
375 * @brief Disable I2S RX DMA function.
\r
376 * @param[in] i2s The pointer of the specified I2S module.
\r
378 * @details This macro will clear RXPDMAEN bit of SPI_PDMACTL register to disable RX DMA function.
\r
380 #define SPII2S_DISABLE_RXDMA(i2s) ( (i2s)->PDMACTL &= ~SPI_PDMACTL_RXPDMAEN_Msk )
\r
383 * @brief Enable I2S TX function.
\r
384 * @param[in] i2s The pointer of the specified I2S module.
\r
386 * @details This macro will set TXEN bit of SPI_I2SCTL register to enable I2S TX function.
\r
388 #define SPII2S_ENABLE_TX(i2s) ( (i2s)->I2SCTL |= SPI_I2SCTL_TXEN_Msk )
\r
391 * @brief Disable I2S TX function.
\r
392 * @param[in] i2s The pointer of the specified I2S module.
\r
394 * @details This macro will clear TXEN bit of SPI_I2SCTL register to disable I2S TX function.
\r
396 #define SPII2S_DISABLE_TX(i2s) ( (i2s)->I2SCTL &= ~SPI_I2SCTL_TXEN_Msk )
\r
399 * @brief Enable I2S RX function.
\r
400 * @param[in] i2s The pointer of the specified I2S module.
\r
402 * @details This macro will set RXEN bit of SPI_I2SCTL register to enable I2S RX function.
\r
404 #define SPII2S_ENABLE_RX(i2s) ( (i2s)->I2SCTL |= SPI_I2SCTL_RXEN_Msk )
\r
407 * @brief Disable I2S RX function.
\r
408 * @param[in] i2s The pointer of the specified I2S module.
\r
410 * @details This macro will clear RXEN bit of SPI_I2SCTL register to disable I2S RX function.
\r
412 #define SPII2S_DISABLE_RX(i2s) ( (i2s)->I2SCTL &= ~SPI_I2SCTL_RXEN_Msk )
\r
415 * @brief Enable TX Mute function.
\r
416 * @param[in] i2s The pointer of the specified I2S module.
\r
418 * @details This macro will set MUTE bit of SPI_I2SCTL register to enable I2S TX mute function.
\r
420 #define SPII2S_ENABLE_TX_MUTE(i2s) ( (i2s)->I2SCTL |= SPI_I2SCTL_MUTE_Msk )
\r
423 * @brief Disable TX Mute function.
\r
424 * @param[in] i2s The pointer of the specified I2S module.
\r
426 * @details This macro will clear MUTE bit of SPI_I2SCTL register to disable I2S TX mute function.
\r
428 #define SPII2S_DISABLE_TX_MUTE(i2s) ( (i2s)->I2SCTL &= ~SPI_I2SCTL_MUTE_Msk )
\r
431 * @brief Clear TX FIFO.
\r
432 * @param[in] i2s The pointer of the specified I2S module.
\r
434 * @details This macro will clear TX FIFO. The internal TX FIFO pointer will be reset to FIFO start point.
\r
436 #define SPII2S_CLR_TX_FIFO(i2s) ( (i2s)->FIFOCTL |= SPI_FIFOCTL_TXFBCLR_Msk )
\r
439 * @brief Clear RX FIFO.
\r
440 * @param[in] i2s The pointer of the specified I2S module.
\r
442 * @details This macro will clear RX FIFO. The internal RX FIFO pointer will be reset to FIFO start point.
\r
444 #define SPII2S_CLR_RX_FIFO(i2s) ( (i2s)->FIFOCTL |= SPI_FIFOCTL_RXFBCLR_Msk )
\r
447 * @brief This function sets the recording source channel when mono mode is used.
\r
448 * @param[in] i2s The pointer of the specified I2S module.
\r
449 * @param[in] u32Ch left or right channel. Valid values are:
\r
450 * - \ref SPII2S_MONO_LEFT
\r
451 * - \ref SPII2S_MONO_RIGHT
\r
453 * @details This function selects the recording source channel of monaural mode.
\r
455 __STATIC_INLINE void SPII2S_SET_MONO_RX_CHANNEL(SPI_T *i2s, uint32_t u32Ch)
\r
457 u32Ch == SPII2S_MONO_LEFT ?
\r
458 (i2s->I2SCTL |= SPI_I2SCTL_RXLCH_Msk) :
\r
459 (i2s->I2SCTL &= ~SPI_I2SCTL_RXLCH_Msk);
\r
463 * @brief Write data to I2S TX FIFO.
\r
464 * @param[in] i2s The pointer of the specified I2S module.
\r
465 * @param[in] u32Data The value written to TX FIFO.
\r
467 * @details This macro will write a value to TX FIFO.
\r
469 #define SPII2S_WRITE_TX_FIFO(i2s, u32Data) ( (i2s)->TX = (u32Data) )
\r
472 * @brief Read RX FIFO.
\r
473 * @param[in] i2s The pointer of the specified I2S module.
\r
474 * @return The value read from RX FIFO.
\r
475 * @details This function will return a value read from RX FIFO.
\r
477 #define SPII2S_READ_RX_FIFO(i2s) ( (i2s)->RX )
\r
480 * @brief Get the interrupt flag.
\r
481 * @param[in] i2s The pointer of the specified I2S module.
\r
482 * @param[in] u32Mask The mask value for all interrupt flags.
\r
483 * @return The interrupt flags specified by the u32mask parameter.
\r
484 * @details This macro will return the combination interrupt flags of SPI_I2SSTS register. The flags are specified by the u32mask parameter.
\r
486 #define SPII2S_GET_INT_FLAG(i2s, u32Mask) ( (i2s)->I2SSTS & (u32Mask) )
\r
489 * @brief Clear the interrupt flag.
\r
490 * @param[in] i2s The pointer of the specified I2S module.
\r
491 * @param[in] u32Mask The mask value for all interrupt flags.
\r
493 * @details This macro will clear the interrupt flags specified by the u32mask parameter.
\r
494 * @note Except TX and RX FIFO threshold interrupt flags, the other interrupt flags can be cleared by writing 1 to itself.
\r
496 #define SPII2S_CLR_INT_FLAG(i2s, u32Mask) ( (i2s)->I2SSTS = (u32Mask) )
\r
499 * @brief Get transmit FIFO level
\r
500 * @param[in] i2s The pointer of the specified I2S module.
\r
501 * @return TX FIFO level
\r
502 * @details This macro will return the number of available words in TX FIFO.
\r
504 #define SPII2S_GET_TX_FIFO_LEVEL(i2s) ( ((i2s)->I2SSTS & SPI_I2SSTS_TXCNT_Msk) >> SPI_I2SSTS_TXCNT_Pos )
\r
507 * @brief Get receive FIFO level
\r
508 * @param[in] i2s The pointer of the specified I2S module.
\r
509 * @return RX FIFO level
\r
510 * @details This macro will return the number of available words in RX FIFO.
\r
512 #define SPII2S_GET_RX_FIFO_LEVEL(i2s) ( ((i2s)->I2SSTS & SPI_I2SSTS_RXCNT_Msk) >> SPI_I2SSTS_RXCNT_Pos )
\r
516 /* Function prototype declaration */
\r
517 uint32_t SPI_Open(SPI_T *spi, uint32_t u32MasterSlave, uint32_t u32SPIMode, uint32_t u32DataWidth, uint32_t u32BusClock);
\r
518 void SPI_Close(SPI_T *spi);
\r
519 void SPI_ClearRxFIFO(SPI_T *spi);
\r
520 void SPI_ClearTxFIFO(SPI_T *spi);
\r
521 void SPI_DisableAutoSS(SPI_T *spi);
\r
522 void SPI_EnableAutoSS(SPI_T *spi, uint32_t u32SSPinMask, uint32_t u32ActiveLevel);
\r
523 uint32_t SPI_SetBusClock(SPI_T *spi, uint32_t u32BusClock);
\r
524 void SPI_SetFIFO(SPI_T *spi, uint32_t u32TxThreshold, uint32_t u32RxThreshold);
\r
525 uint32_t SPI_GetBusClock(SPI_T *spi);
\r
526 void SPI_EnableInt(SPI_T *spi, uint32_t u32Mask);
\r
527 void SPI_DisableInt(SPI_T *spi, uint32_t u32Mask);
\r
528 uint32_t SPI_GetIntFlag(SPI_T *spi, uint32_t u32Mask);
\r
529 void SPI_ClearIntFlag(SPI_T *spi, uint32_t u32Mask);
\r
530 uint32_t SPI_GetStatus(SPI_T *spi, uint32_t u32Mask);
\r
532 uint32_t SPII2S_Open(SPI_T *i2s, uint32_t u32MasterSlave, uint32_t u32SampleRate, uint32_t u32WordWidth, uint32_t u32Channels, uint32_t u32DataFormat);
\r
533 void SPII2S_Close(SPI_T *i2s);
\r
534 void SPII2S_EnableInt(SPI_T *i2s, uint32_t u32Mask);
\r
535 void SPII2S_DisableInt(SPI_T *i2s, uint32_t u32Mask);
\r
536 uint32_t SPII2S_EnableMCLK(SPI_T *i2s, uint32_t u32BusClock);
\r
537 void SPII2S_DisableMCLK(SPI_T *i2s);
\r
538 void SPII2S_SetFIFO(SPI_T *i2s, uint32_t u32TxThreshold, uint32_t u32RxThreshold);
\r
541 /*@}*/ /* end of group SPI_EXPORTED_FUNCTIONS */
\r
543 /*@}*/ /* end of group SPI_Driver */
\r
545 /*@}*/ /* end of group Standard_Driver */
\r
551 #endif /* __SPI_H__ */
\r
553 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
\r