PAN1080 Peripheral API
pan_spi.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Panchip Technology Corp. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
14#ifndef __PAN_SPI_H__
15#define __PAN_SPI_H__
16
23#ifdef __cplusplus
24extern "C"
25{
26#endif
27
31typedef enum SPI_Irq
32{
37 SPI_IRQ_ALL = 0x0f
44typedef enum SPI_Role
45{
47 SPI_RoleSlave = 0x1
56{
76typedef enum SPI_BaudRateDiv
77{
96#define SPI_BAUD_RATE_DIV(x) ((x)?(x):(256))
103typedef enum SPI_ClockPol
104{
113typedef enum SPI_ClockPhase
114{
123typedef enum SPI_FrameFormat
124{
147typedef struct
148{
165__STATIC_INLINE void SPI_EnableSpi(SPI_T* SPIx)
166{
167 uint32_t tmpreg = 0;
168
169 tmpreg = SPIx->CR1;
170 tmpreg |= SPI_CR1_SSE_Msk;
171 SPIx->CR1 = tmpreg;
172}
173
180__STATIC_INLINE void SPI_DisableSpi(SPI_T* SPIx)
181{
182 uint32_t tmpreg = 0;
183
184 tmpreg = SPIx->CR1;
185 tmpreg &= ~SPI_CR1_SSE_Msk;
186 SPIx->CR1 = tmpreg;
187}
188
195__STATIC_INLINE bool SPI_IsSpiEnabled(SPI_T* SPIx)
196{
197 uint32_t tmpreg = 0;
198
199 tmpreg = SPIx->CR1;
200 if(tmpreg & SPI_CR1_SSE_Msk)
201 return true;
202 else
203 return false;
204}
205
212__STATIC_INLINE void SPI_EnableDmaTx(SPI_T* SPIx)
213{
214 uint32_t tmpreg = 0x00;
215
216 tmpreg = SPIx->DMACR;
217 tmpreg |= SPI_DMACR_TDMAE_Msk;
218 SPIx->DMACR = tmpreg;
219}
220
227__STATIC_INLINE void SPI_DisableDmaTx(SPI_T* SPIx)
228{
229 uint32_t tmpreg = 0x00;
230
231 tmpreg = SPIx->DMACR;
232 tmpreg &= ~SPI_DMACR_TDMAE_Msk;
233 SPIx->DMACR = tmpreg;
234}
235
242__STATIC_INLINE bool SPI_IsDmaTxEnabled(SPI_T* SPIx)
243{
244 uint32_t tmpreg = 0x00;
245
246 tmpreg = SPIx->DMACR;
247 if(tmpreg & SPI_DMACR_TDMAE_Msk)
248 return true;
249 else
250 return false;
251}
252
259__STATIC_INLINE void SPI_EnableDmaRx(SPI_T* SPIx)
260{
261 uint32_t tmpreg = 0x00;
262
263 tmpreg = SPIx->DMACR;
264 tmpreg |= SPI_DMACR_RDMAE_Msk;
265 SPIx->DMACR = tmpreg;
266}
267
274__STATIC_INLINE void SPI_DisableDmaRx(SPI_T* SPIx)
275{
276 uint32_t tmpreg = 0x00;
277
278 tmpreg = SPIx->DMACR;
279 tmpreg &= ~SPI_DMACR_RDMAE_Msk;
280 SPIx->DMACR = tmpreg;
281}
282
289__STATIC_INLINE bool SPI_IsDmaRxEnabled(SPI_T* SPIx)
290{
291 uint32_t tmpreg = 0x00;
292
293 tmpreg = SPIx->DMACR;
294 if(tmpreg & SPI_DMACR_RDMAE_Msk)
295 return true;
296 else
297 return false;
298}
299
306__STATIC_INLINE void SPI_SendData(SPI_T* SPIx, uint32_t Data)
307{
308 SPIx->DR = Data;
309}
310
317__STATIC_INLINE uint32_t SPI_ReceiveData(SPI_T* SPIx)
318{
319 return SPIx->DR;
320}
321
334__STATIC_INLINE void SPI_EnableIrq(SPI_T* SPIx, SPI_IrqDef irq)
335{
336 uint32_t tmpreg = 0x00;
337
338 tmpreg = SPIx->IMSC;
339 tmpreg |= irq;
340 SPIx->IMSC = tmpreg;
341}
342
355__STATIC_INLINE void SPI_DisableIrq(SPI_T* SPIx, SPI_IrqDef irq)
356{
357 uint32_t tmpreg = 0x00;
358
359 tmpreg = SPIx->IMSC;
360 tmpreg &= ~irq;
361 SPIx->IMSC = tmpreg;
362}
363
376__STATIC_INLINE bool SPI_IsIrqEnabled(SPI_T* SPIx, SPI_IrqDef irq)
377{
378 uint32_t tmpreg;
379
380 tmpreg = SPIx->IMSC;
381 if(tmpreg & irq )
382 return true;
383 else
384 return false;
385}
386
398__STATIC_INLINE SPI_IrqDef SPI_GetMskedActiveIrq(SPI_T* SPIx)
399{
400 uint32_t tmpreg = 0x00;
401
402 tmpreg = SPIx->MIS;
403 tmpreg &= SPI_IRQ_ALL;
404
405 return (SPI_IrqDef)tmpreg;
406}
407
420__STATIC_INLINE bool SPI_IsIrqActive(SPI_T * SPIx, SPI_IrqDef irq)
421{
422 uint32_t tmpreg = 0x00;
423
424 tmpreg = SPIx->MIS;
425 if(tmpreg & irq )
426 return true;
427 else
428 return false;
429}
430
443__STATIC_INLINE bool SPI_IsRawIrqActive(SPI_T * SPIx, SPI_IrqDef irq)
444{
445 uint32_t tmpreg = 0x00;
446
447 tmpreg = SPIx->RIS;
448 if(tmpreg & irq )
449 return true;
450 else
451 return false;
452}
453
463__STATIC_INLINE void SPI_ClearIrq(SPI_T * SPIx, SPI_IrqDef irq)
464{
465 uint32_t tmpreg = 0x00;
466
467 tmpreg = SPIx->ICR;
468 tmpreg |= irq ;
469 SPIx->ICR = tmpreg;
470}
482__STATIC_INLINE SPI_IrqDef SPI_GetRawActiveIrq(SPI_T* SPIx)
483{
484 uint32_t tmpreg = 0x00;
485
486 tmpreg = SPIx->RIS;
487 tmpreg &= SPI_IRQ_ALL;
488
489 return (SPI_IrqDef)tmpreg;
490}
491
498__STATIC_INLINE bool SPI_IsTxFifoEmpty(SPI_T* SPIx)
499{
500 uint32_t tmpreg = 0x00;
501 tmpreg = SPIx->SR;
502
503 if(tmpreg & SPI_SR_TFE_Msk)
504 return true;
505 else
506 return false;
507}
514__STATIC_INLINE bool SPI_IsTxFifoFull(SPI_T* SPIx)
515{
516 uint32_t tmpreg = 0x00;
517
518 tmpreg = SPIx->SR;
519
520 if(tmpreg & SPI_SR_TFNF_Msk)
521 return false;
522 else
523 return true;
524}
531__STATIC_INLINE bool SPI_IsRxFifoEmpty(SPI_T* SPIx)
532{
533 uint32_t tmpreg = 0x00;
534
535 tmpreg = SPIx->SR;
536
537 if(tmpreg & SPI_SR_RFNE_Msk)
538 return false;
539 else
540 return true;
541
542}
549__STATIC_INLINE bool SPI_IsRxFifoFull(SPI_T* SPIx)
550{
551 uint32_t tmpreg = 0x00;
552
553 tmpreg = SPIx->SR;
554
555 if(tmpreg & SPI_SR_RFF_Msk)
556 return true;
557 else
558 return false;
559
560}
567__STATIC_INLINE bool SPI_IsBusy(SPI_T* SPIx)
568{
569 uint32_t tmpreg = 0x00;
570
571 tmpreg = SPIx->SR;
572 if(tmpreg & SPI_SR_BUSY_Msk)
573 return true;
574 else
575 return false;
576}
577
584__STATIC_INLINE void SPI_TxLsbEnable(SPI_T* SPIx,bool enable)
585{
586 (enable) ? (SPIx->CR1 |= SPI_CR1_TX_LSB_EN_Msk) : (SPIx->CR1 &= ~SPI_CR1_TX_LSB_EN_Msk);
587}
588
595__STATIC_INLINE void SPI_RxLsbEnable(SPI_T* SPIx,bool enable)
596{
597 (enable) ? (SPIx->CR1 |= SPI_CR1_RX_LSB_EN_Msk) : (SPIx->CR1 &= ~SPI_CR1_RX_LSB_EN_Msk);
598}
608void SPI_Init(SPI_T* SPIx, SPI_InitTypeDef* SPI_InitStruct);
609
612#ifdef __cplusplus
613}
614#endif
615
616#endif /* __PAN_SPI_H__ */
617
enum SPI_BaudRateDiv SPI_BaudRateDivDef
SPI_BaudRateDiv
Definition: pan_spi.h:77
@ SPI_BaudRateDiv_192
Definition: pan_spi.h:89
@ SPI_BaudRateDiv_4
Definition: pan_spi.h:79
@ SPI_BaudRateDiv_96
Definition: pan_spi.h:86
@ SPI_BaudRateDiv_250
Definition: pan_spi.h:92
@ SPI_BaudRateDiv_32
Definition: pan_spi.h:83
@ SPI_BaudRateDiv_64
Definition: pan_spi.h:85
@ SPI_BaudRateDiv_16
Definition: pan_spi.h:82
@ SPI_BaudRateDiv_240
Definition: pan_spi.h:91
@ SPI_BaudRateDiv_8
Definition: pan_spi.h:81
@ SPI_BaudRateDiv_48
Definition: pan_spi.h:84
@ SPI_BaudRateDiv_2
Definition: pan_spi.h:78
@ SPI_BaudRateDiv_6
Definition: pan_spi.h:80
@ SPI_BaudRateDiv_128
Definition: pan_spi.h:87
@ SPI_BaudRateDiv_224
Definition: pan_spi.h:90
@ SPI_BaudRateDiv_160
Definition: pan_spi.h:88
enum SPI_DataFrameSize SPI_DataFrameSizeDef
SPI_DataFrameSize
Definition: pan_spi.h:56
@ SPI_DataFrame_10b
Definition: pan_spi.h:63
@ SPI_DataFrame_15b
Definition: pan_spi.h:68
@ SPI_DataFrame_13b
Definition: pan_spi.h:66
@ SPI_DataFrame_7b
Definition: pan_spi.h:60
@ SPI_DataFrame_14b
Definition: pan_spi.h:67
@ SPI_DataFrame_8b
Definition: pan_spi.h:61
@ SPI_DataFrame_16b
Definition: pan_spi.h:69
@ SPI_DataFrame_9b
Definition: pan_spi.h:62
@ SPI_DataFrame_11b
Definition: pan_spi.h:64
@ SPI_DataFrame_5b
Definition: pan_spi.h:58
@ SPI_DataFrame_4b
Definition: pan_spi.h:57
@ SPI_DataFrame_12b
Definition: pan_spi.h:65
@ SPI_DataFrame_6b
Definition: pan_spi.h:59
enum SPI_FrameFormat SPI_FrameFormatDef
SPI_FrameFormat
Definition: pan_spi.h:124
@ SPI_FormatMicrowire
Definition: pan_spi.h:127
@ SPI_FormatTi
Definition: pan_spi.h:126
@ SPI_FormatMotorola
Definition: pan_spi.h:125
enum SPI_Irq SPI_IrqDef
SPI_Irq
Definition: pan_spi.h:32
@ SPI_IRQ_RX_OVERRUN
Definition: pan_spi.h:36
@ SPI_IRQ_RX_HALF_FULL
Definition: pan_spi.h:34
@ SPI_IRQ_TX_HALF_EMPTY
Definition: pan_spi.h:33
@ SPI_IRQ_RX_TIMEOUT
Definition: pan_spi.h:35
@ SPI_IRQ_ALL
Definition: pan_spi.h:37
SPI_ClockPhase
Definition: pan_spi.h:114
enum SPI_ClockPhase SPI_ClockPhaseDef
@ SPI_ClockPhaseSecondEdge
Definition: pan_spi.h:116
@ SPI_ClockPhaseFirstEdge
Definition: pan_spi.h:115
SPI_ClockPol
Definition: pan_spi.h:104
enum SPI_ClockPol SPI_ClockPolDef
@ SPI_ClockPolarityHigh
Definition: pan_spi.h:106
@ SPI_ClockPolarityLow
Definition: pan_spi.h:105
enum SPI_Role SPI_RoleDef
SPI_Role
Definition: pan_spi.h:45
@ SPI_RoleMaster
Definition: pan_spi.h:46
@ SPI_RoleSlave
Definition: pan_spi.h:47
__STATIC_INLINE void SPI_EnableDmaTx(SPI_T *SPIx)
DMA for the transmit FIFO is enabled.
Definition: pan_spi.h:212
__STATIC_INLINE bool SPI_IsRxFifoFull(SPI_T *SPIx)
Get Tx FIFO full status.
Definition: pan_spi.h:549
__STATIC_INLINE bool SPI_IsIrqEnabled(SPI_T *SPIx, SPI_IrqDef irq)
Get Interruput mask status.
Definition: pan_spi.h:376
__STATIC_INLINE void SPI_DisableIrq(SPI_T *SPIx, SPI_IrqDef irq)
Interruput mask Disable.
Definition: pan_spi.h:355
__STATIC_INLINE void SPI_EnableDmaRx(SPI_T *SPIx)
DMA for the receive FIFO is enabled.
Definition: pan_spi.h:259
__STATIC_INLINE SPI_IrqDef SPI_GetRawActiveIrq(SPI_T *SPIx)
Get Raw Interruput status.
Definition: pan_spi.h:482
__STATIC_INLINE bool SPI_IsTxFifoFull(SPI_T *SPIx)
Get Tx FIFO full status.
Definition: pan_spi.h:514
__STATIC_INLINE void SPI_TxLsbEnable(SPI_T *SPIx, bool enable)
Tx Lsb Send function control.
Definition: pan_spi.h:584
__STATIC_INLINE void SPI_RxLsbEnable(SPI_T *SPIx, bool enable)
Rx Lsb Send function control.
Definition: pan_spi.h:595
__STATIC_INLINE void SPI_DisableDmaTx(SPI_T *SPIx)
DMA for the transmit FIFO is disabled.
Definition: pan_spi.h:227
__STATIC_INLINE void SPI_DisableDmaRx(SPI_T *SPIx)
DMA for the receive FIFO is disabled.
Definition: pan_spi.h:274
__STATIC_INLINE bool SPI_IsBusy(SPI_T *SPIx)
Get Synchronous serial port busy status.
Definition: pan_spi.h:567
__STATIC_INLINE uint32_t SPI_ReceiveData(SPI_T *SPIx)
Receive data,DR is the data register and is 16-bits wide.
Definition: pan_spi.h:317
__STATIC_INLINE SPI_IrqDef SPI_GetMskedActiveIrq(SPI_T *SPIx)
Get Masked Interruput status.
Definition: pan_spi.h:398
__STATIC_INLINE void SPI_ClearIrq(SPI_T *SPIx, SPI_IrqDef irq)
clear Interruput status
Definition: pan_spi.h:463
__STATIC_INLINE void SPI_EnableSpi(SPI_T *SPIx)
Synchronous serial port enable.
Definition: pan_spi.h:165
__STATIC_INLINE bool SPI_IsDmaTxEnabled(SPI_T *SPIx)
get DMA for the transmit FIFO status
Definition: pan_spi.h:242
__STATIC_INLINE void SPI_DisableSpi(SPI_T *SPIx)
Synchronous serial port disable.
Definition: pan_spi.h:180
__STATIC_INLINE bool SPI_IsSpiEnabled(SPI_T *SPIx)
get synchronous serial port status
Definition: pan_spi.h:195
__STATIC_INLINE void SPI_EnableIrq(SPI_T *SPIx, SPI_IrqDef irq)
Interruput mask Enable.
Definition: pan_spi.h:334
__STATIC_INLINE bool SPI_IsTxFifoEmpty(SPI_T *SPIx)
Get Tx FIFO empty status.
Definition: pan_spi.h:498
__STATIC_INLINE bool SPI_IsRawIrqActive(SPI_T *SPIx, SPI_IrqDef irq)
Get raw Interruput status.
Definition: pan_spi.h:443
__STATIC_INLINE void SPI_SendData(SPI_T *SPIx, uint32_t Data)
Send data,DR is the data register and is 16-bits wide.
Definition: pan_spi.h:306
__STATIC_INLINE bool SPI_IsDmaRxEnabled(SPI_T *SPIx)
get DMA for the receive FIFO status
Definition: pan_spi.h:289
__STATIC_INLINE bool SPI_IsRxFifoEmpty(SPI_T *SPIx)
Get Tx FIFO empty status.
Definition: pan_spi.h:531
void SPI_Init(SPI_T *SPIx, SPI_InitTypeDef *SPI_InitStruct)
Initializes the SPIx peripheral according to the specified parameters in the SPI_InitStruct .
__STATIC_INLINE bool SPI_IsIrqActive(SPI_T *SPIx, SPI_IrqDef irq)
Get Masked Interruput status.
Definition: pan_spi.h:420
SPI Init Structure definition.
Definition: pan_spi.h:148
SPI_FrameFormatDef SPI_format
Definition: pan_spi.h:154
SPI_RoleDef SPI_role
Definition: pan_spi.h:149
SPI_DataFrameSizeDef SPI_dataFrameSize
Definition: pan_spi.h:150
SPI_ClockPolDef SPI_CPOL
Definition: pan_spi.h:151
SPI_ClockPhaseDef SPI_CPHA
Definition: pan_spi.h:152
uint16_t SPI_baudRateDiv
Definition: pan_spi.h:153