WXK
2024-12-16 78e84fcf264afd731cd66c807d9fcb690fe12126
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
/**************************************************************************
 * @file     pan_spi.h
 * @version  V1.10
 * $Revision: 2 $
 * $Date:    2023/11/08  $  
 * @brief    PAN series SPI driver header file
 *
 * @note
 * Copyright (C) 2023 Panchip Technology Corp. All rights reserved.
 *****************************************************************************/
 
#ifndef __PAN_SPI_H__
#define __PAN_SPI_H__
 
/**
 * @brief Spi Interface
 * @defgroup spi_interface Spi Interface
 * @{
 */
 
#ifdef __cplusplus
extern "C"
{
#endif
 
/**@defgroup SPI_IRQ_FLAG Spi interrupt event type
 * @brief       Spi interrupt event type constants definitions
 * @{ */ 
typedef enum SPI_Irq
{
    SPI_IRQ_TX_HALF_EMPTY   = 0x08,     //Transmit FIFO Half Empty Interrupt
    SPI_IRQ_RX_HALF_FULL    = 0x04,     //Receive FIFO Half Full Interrupt
    SPI_IRQ_RX_TIMEOUT      = 0x02,     //Receive FIFO Not Empty and No Read prior to Timeout Interrupt
    SPI_IRQ_RX_OVERRUN      = 0x01,     //Receive FIFO Overflow Interrupt
    SPI_IRQ_ALL             = 0x0f      //All interrupts
} SPI_IrqDef;
/**@} */
 
/**@defgroup SPI_WORK_MODE_FLAG Spi operating mode
 * @brief       Spi operating mode constants definitions
 * @{ */ 
typedef enum SPI_Role
{
    SPI_RoleMaster  = 0x0,
    SPI_RoleSlave   = 0x1
} SPI_RoleDef;  
/**@} */
 
#if 0
/*Transfer Mode. Selects the mode of transfer for serial communication. This field
does not affect the transfer duplicity. Only indicates whether the receive or transmit
data are valid.*/
typedef enum SPI_TransferMode
{
    Spi_dir_full_duplex = 0x0,
    Spi_dir_tx_only     = 0x1,
    Spi_dir_rx_only     = 0x2,
    Spi_dir_read_eeprom = 0x3
} SPI_TransferModeDef;
#endif
 
/**@defgroup SPI_DATA_SIZE_FLAG Spi data frame size
 * @brief       Spi data frame size constants definitions
 * @{ */ 
typedef enum SPI_DataFrameSize
{
    SPI_DataFrame_4b    = 0x03,
    SPI_DataFrame_5b    = 0x04,
    SPI_DataFrame_6b    = 0x05,
    SPI_DataFrame_7b    = 0x06,
    SPI_DataFrame_8b    = 0x07,
    SPI_DataFrame_9b    = 0x08,
    SPI_DataFrame_10b   = 0x09,
    SPI_DataFrame_11b   = 0x0a,
    SPI_DataFrame_12b   = 0x0b,
    SPI_DataFrame_13b   = 0x0c,
    SPI_DataFrame_14b   = 0x0d,
    SPI_DataFrame_15b   = 0x0e,
    SPI_DataFrame_16b   = 0x0f
} SPI_DataFrameSizeDef;
/**@} */
 
/**@defgroup SPI_BAUD_DIV_FLAG Spi baudrate divider
 * @brief       Spi baudrate divider constants definitions
 * @{ */
typedef enum SPI_BaudRateDiv
{
    SPI_BaudRateDiv_2   = 0x02,
    SPI_BaudRateDiv_4   = 0x04,
    SPI_BaudRateDiv_6   = 0x06,
    SPI_BaudRateDiv_8   = 0x08,
    SPI_BaudRateDiv_16  = 0x10,
    SPI_BaudRateDiv_32  = 0x20,
    SPI_BaudRateDiv_48  = 0x30,
    SPI_BaudRateDiv_64  = 0x40,
    SPI_BaudRateDiv_96  = 0x60,
    SPI_BaudRateDiv_128 = 0x80,
    SPI_BaudRateDiv_160 = 0xA0,
    SPI_BaudRateDiv_192 = 0xC0,
    SPI_BaudRateDiv_224 = 0xE0,
    SPI_BaudRateDiv_240 = 0xF0,
    SPI_BaudRateDiv_250 = 0xFA,
} SPI_BaudRateDivDef;
/**@} */
 
#define SPI_BAUD_RATE_DIV(x)    ((x)?(x):(256))
 
/**@defgroup SPI_POLARITY_FLAG Spi clock polarity
 * @brief       Spi clock polarity constants definitions,Serial Clock Polarity, Used to 
 *                            select the polarity of the inactive serial clock, which is held inactive when
 *                            the DW_apb_ssi master is not actively transferring data on the serial bus
 * @{ */
typedef enum SPI_ClockPol
{
    SPI_ClockPolarityLow    = 0x0,
    SPI_ClockPolarityHigh   = 0x1
} SPI_ClockPolDef;
/**@} */
 
/**@defgroup SPI_PHASE_FLAG Spi clock phase
 * @brief       Spi clock phase constants definitions
 * @{ */
typedef enum SPI_ClockPhase
{
    SPI_ClockPhaseFirstEdge     = 0x0,
    SPI_ClockPhaseSecondEdge    = 0x1
} SPI_ClockPhaseDef;
/**@} */
 
/**@defgroup SPI_FORMAT_FLAG Spi frame format
 * @brief       Spi frame format constants definitions
 * @{ */
typedef enum SPI_FrameFormat
{
    SPI_FormatMotorola     = 0x00,
    SPI_FormatTi           = 0x01,
    SPI_FormatMicrowire    = 0x02,
} SPI_FrameFormatDef;
/**@} */
 
/**
 * @brief Enumeration of SPI Wire Number.
 */
typedef enum SPI_WireNum
{
    SPI_WireNumThree  = 0x01, /*!< 3-wire SPI communication */
    SPI_WireNumFour   = 0x00  /*!< 4-wire SPI communication */
} SPI_WireNumDef;
 
/**
 * @brief Enumeration of SPI Command/Data Selection.
 */
typedef enum SPI_CmdDat
{
    SPI_CommandSelect  = 0x00, /*!< SPI command selection */
    SPI_DataSelect     = 0x01  /*!< SPI data selection */
} SPI_CmdDatDef;
 
 
/**
 * @brief Enumeration of SPI Write/Read Selection.
 */
typedef enum SPI_WriteReadSel
{
    SPI_3WireRead    = 0x00, /*!< 3-wire SPI read selection */
    SPI_3WireWrite   = 0x01  /*!< 3-wire SPI write selection */
} SPI_WriteReadSelDef;
 
/** 
 * @brief Structure with spi init feature.
 *
 * @param SPI_role                         Specifies the SPI operating mode.\ref SPI_WORK_MODE_FLAG
 * @param SPI_dataFrameSize        Specifies the SPI data size    \ref SPI_DATA_SIZE_FLAG
 * @param SPI_CPOL                        Specifies the SPI data size \ref SPI_POLARITY_FLAG
 * @param SPI_CPHA                        Specifies the clock active edge for the bit capture \ref SPI_PHASE_FLAG
 * @param SPI_baudRateDiv            Specifies the Baud Rate Divisor used to configure the transmit and receive
 *                                                                 SCK clock \ref SPI_BAUD_DIV_FLAG
 * @param SPI_format                    Specifies the SPI format \ref SPI_FORMAT_FLAG
 */
typedef struct
{
    SPI_RoleDef SPI_role;                       /*!< Specifies the SPI operating mode */
    SPI_DataFrameSizeDef SPI_dataFrameSize;     /*!< Specifies the SPI data size */
    SPI_ClockPolDef SPI_CPOL;                   /*!< Specifies the serial clock steady state */
    SPI_ClockPhaseDef SPI_CPHA;                 /*!< Specifies the clock active edge for the bit capture */
//    SPI_BaudRateDivDef SPI_baudRateDiv;         /*!< Specifies the Baud Rate Divisor used to configure the transmit and receive SCK clock. */
    uint16_t SPI_baudRateDiv;         /*!< Specifies the Baud Rate Divisor used to configure the transmit and receive SCK clock. */
    SPI_FrameFormatDef SPI_format;              /*!< Specifies the SPI format */
} SPI_InitTypeDef;
 
 
/**
  * @brief  Synchronous serial port enable
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval None
  */
__STATIC_INLINE void SPI_EnableSpi(SPI_T* SPIx)
{
    uint32_t tmpreg = 0;
 
    tmpreg = SPIx->CR1;
    tmpreg |= SPI_CR1_SSE_Msk;
    SPIx->CR1 = tmpreg;
}
 
/**
  * @brief  Synchronous serial port disable
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval None
  */
__STATIC_INLINE void SPI_DisableSpi(SPI_T* SPIx)
{
    uint32_t tmpreg = 0;
 
    tmpreg = SPIx->CR1;
    tmpreg &= ~SPI_CR1_SSE_Msk;
    SPIx->CR1 = tmpreg;
}
 
/**
  * @brief  get synchronous serial port status
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval true/false
  */
__STATIC_INLINE bool SPI_IsSpiEnabled(SPI_T* SPIx)
{
    uint32_t tmpreg = 0;
 
    tmpreg = SPIx->CR1;
    if(tmpreg & SPI_CR1_SSE_Msk)
        return true;
    else
        return false;
}
 
/**
  * @brief  DMA for the transmit FIFO is enabled
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval None
  */
__STATIC_INLINE void SPI_EnableDmaTx(SPI_T* SPIx)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->DMACR;
    tmpreg |= SPI_DMACR_TDMAE_Msk;
    SPIx->DMACR = tmpreg;
}
 
/**
  * @brief  DMA for the transmit FIFO is disabled
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval None
  */
__STATIC_INLINE void SPI_DisableDmaTx(SPI_T* SPIx)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->DMACR;
    tmpreg &= ~SPI_DMACR_TDMAE_Msk;
    SPIx->DMACR = tmpreg;
}
 
/**
  * @brief  get DMA for the transmit FIFO status
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval true/false
  */
__STATIC_INLINE bool SPI_IsDmaTxEnabled(SPI_T* SPIx)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->DMACR;
    if(tmpreg & SPI_DMACR_TDMAE_Msk)
        return true;
    else
        return false;
}
 
/**
  * @brief  DMA for the receive FIFO is enabled
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval None
  */
__STATIC_INLINE void SPI_EnableDmaRx(SPI_T* SPIx)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->DMACR;
    tmpreg |= SPI_DMACR_RDMAE_Msk;
    SPIx->DMACR = tmpreg;
}
 
/**
  * @brief  DMA for the receive FIFO is disabled
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval None
  */
__STATIC_INLINE void SPI_DisableDmaRx(SPI_T* SPIx)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->DMACR;
    tmpreg &= ~SPI_DMACR_RDMAE_Msk;
    SPIx->DMACR = tmpreg;
}
 
/**
  * @brief  get DMA for the receive FIFO status
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval true/false
  */
__STATIC_INLINE bool SPI_IsDmaRxEnabled(SPI_T* SPIx)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->DMACR;
    if(tmpreg & SPI_DMACR_RDMAE_Msk)
        return true;
    else
        return false;
}
 
/**
  * @brief  Send data,DR is the data register and is 16-bits wide
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval None
  */
__STATIC_INLINE void SPI_SendData(SPI_T* SPIx, uint32_t Data)
{
    SPIx->DR = Data;
}
 
/**
  * @brief  Receive data,DR is the data register and is 16-bits wide
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval None
  */
__STATIC_INLINE uint32_t SPI_ReceiveData(SPI_T* SPIx)
{
    return SPIx->DR;
}
 
/**
  * @brief  Interruput mask Enable
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @param  irq: where x can be 
  *          SPI_IRQ_TX_HALF_EMPTY 
  *          SPI_IRQ_RX_HALF_FULL 
  *          SPI_IRQ_RX_TIMEOUT
  *          SPI_IRQ_RX_OVERRUN
  *          SPI_IRQ_ALL 
  * @retval None
  */
__STATIC_INLINE void SPI_EnableIrq(SPI_T* SPIx, SPI_IrqDef irq)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->IMSC;
    tmpreg |= irq;
    SPIx->IMSC = tmpreg;
}
 
/**
  * @brief  Interruput mask Disable
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @param  irq: where x can be 
  *          \ref SPI_IRQ_TX_HALF_EMPTY 
  *          \ref SPI_IRQ_RX_HALF_FULL 
  *          \ref SPI_IRQ_RX_TIMEOUT
  *          \ref SPI_IRQ_RX_OVERRUN
  *          \ref SPI_IRQ_ALL 
  * @return None
  */
__STATIC_INLINE void SPI_DisableIrq(SPI_T* SPIx, SPI_IrqDef irq)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->IMSC;
    tmpreg &= ~irq;
    SPIx->IMSC = tmpreg;
}
 
/**
  * @brief  Get Interruput mask status
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @param  irq: where x can be 
  *          \ref SPI_IRQ_TX_HALF_EMPTY 
  *          \ref SPI_IRQ_RX_HALF_FULL 
  *          \ref SPI_IRQ_RX_TIMEOUT
  *          \ref SPI_IRQ_RX_OVERRUN
  *          \ref SPI_IRQ_ALL 
  * @return None
  */
__STATIC_INLINE bool SPI_IsIrqEnabled(SPI_T* SPIx, SPI_IrqDef irq)
{
    uint32_t tmpreg;
 
    tmpreg = SPIx->IMSC;
    if(tmpreg & irq )
        return true;
    else
        return false;
}
 
/**
  * @brief  Get Masked Interruput status
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral. 
  * @retval SPI_IrqDef: where return value can be 
  *          SPI_IRQ_TX_HALF_EMPTY 
  *          SPI_IRQ_RX_HALF_FULL 
  *          SPI_IRQ_RX_TIMEOUT
  *          SPI_IRQ_RX_OVERRUN
  *          SPI_IRQ_ALL 
  */
__STATIC_INLINE SPI_IrqDef SPI_GetMskedActiveIrq(SPI_T* SPIx)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->MIS;
    tmpreg &= SPI_IRQ_ALL;
 
    return (SPI_IrqDef)tmpreg;
}
 
/**
  * @brief  Get Masked Interruput status
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @param  irq: where x can be 
  *          \ref SPI_IRQ_TX_HALF_EMPTY 
  *          \ref SPI_IRQ_RX_HALF_FULL 
  *          \ref SPI_IRQ_RX_TIMEOUT
  *          \ref SPI_IRQ_RX_OVERRUN
  *          \ref SPI_IRQ_ALL 
  * @return true/false
  */
__STATIC_INLINE bool SPI_IsIrqActive(SPI_T * SPIx, SPI_IrqDef irq)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->MIS;
    if(tmpreg & irq )
        return true;
    else
        return false;
}
 
/**
  * @brief  Get raw Interruput status
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @param  irq: where x can be 
  *          \ref SPI_IRQ_TX_HALF_EMPTY 
  *          \ref SPI_IRQ_RX_HALF_FULL 
  *          \ref SPI_IRQ_RX_TIMEOUT
  *          \ref SPI_IRQ_RX_OVERRUN
  *          \ref SPI_IRQ_ALL 
  * @return true/false
  */
__STATIC_INLINE bool SPI_IsRawIrqActive(SPI_T * SPIx, SPI_IrqDef irq)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->RIS;
    if(tmpreg & irq )
        return true;
    else
        return false;
}
 
/**
  * @brief  clear Interruput status
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @param  irq: can be 
  *          \ref SPI_IRQ_RX_TIMEOUT
  *          \ref SPI_IRQ_RX_OVERRUN
  * @return None
  */
__STATIC_INLINE void SPI_ClearIrq(SPI_T * SPIx, SPI_IrqDef irq)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->ICR;
    tmpreg |= irq ;
    SPIx->ICR = tmpreg;
}
/**
  * @brief  Get Raw Interruput status
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral. 
  * @return SPI_IrqDef: where return value can be 
  *          \ref SPI_IRQ_TX_HALF_EMPTY 
  *          \ref SPI_IRQ_RX_HALF_FULL 
  *          \ref SPI_IRQ_RX_TIMEOUT
  *          \ref SPI_IRQ_RX_OVERRUN
  *          \ref SPI_IRQ_ALL 
  */
__STATIC_INLINE SPI_IrqDef SPI_GetRawActiveIrq(SPI_T* SPIx)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->RIS;
    tmpreg &= SPI_IRQ_ALL;
 
    return (SPI_IrqDef)tmpreg;
}
 
/**
  * @brief  Get Tx FIFO empty status
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval true/false
  */
__STATIC_INLINE bool SPI_IsTxFifoEmpty(SPI_T* SPIx)
{
    uint32_t tmpreg = 0x00;
    tmpreg = SPIx->SR;
 
    if(tmpreg & SPI_SR_TFE_Msk)
        return true;
    else
        return false;
}
/**
  * @brief  Get Tx FIFO full status
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval true/false
  */
__STATIC_INLINE bool SPI_IsTxFifoFull(SPI_T* SPIx)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->SR;
 
    if(tmpreg & SPI_SR_TFNF_Msk)
        return false;
    else
        return true;
}
/**
  * @brief  Get Tx FIFO empty status
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval true/false
  */
__STATIC_INLINE bool SPI_IsRxFifoEmpty(SPI_T* SPIx)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->SR;
 
    if(tmpreg & SPI_SR_RFNE_Msk)
        return false;
    else
        return true;
 
}
/**
  * @brief  Get Tx FIFO full status
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval true/false
  */
__STATIC_INLINE bool SPI_IsRxFifoFull(SPI_T* SPIx)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->SR;
 
    if(tmpreg & SPI_SR_RFF_Msk)
        return true;
    else
        return false;
 
}
/**
  * @brief  Get Synchronous serial port busy status
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval true/false
  */
__STATIC_INLINE bool SPI_IsBusy(SPI_T* SPIx)
{
    uint32_t tmpreg = 0x00;
 
    tmpreg = SPIx->SR;
    if(tmpreg & SPI_SR_BUSY_Msk)
        return true;
    else
        return false;
}
 
/**
  * @brief  Tx Lsb Send function control
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval none
  */
__STATIC_INLINE void SPI_TxLsbEnable(SPI_T* SPIx,bool enable)
{
    (enable) ? (SPIx->CR1 |= SPI_CR1_TX_LSB_EN_Msk) : (SPIx->CR1 &= ~SPI_CR1_TX_LSB_EN_Msk);
}
 
/**
  * @brief  Rx Lsb Send function control
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @retval none
  */
__STATIC_INLINE void SPI_RxLsbEnable(SPI_T* SPIx,bool enable)
{
    (enable) ? (SPIx->CR1 |= SPI_CR1_RX_LSB_EN_Msk) : (SPIx->CR1 &= ~SPI_CR1_RX_LSB_EN_Msk);
}
 
/**
  * @brief  set spi wire number,which controlled the spi work mode
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @param  num: where num can be 
  *             SPI_WireNumThree
  *             SPI_WireNumFour
  * @retval none
  */
__STATIC_INLINE void SPI_SetWireNum(SPI_T* SPIx,SPI_WireNumDef num)
{
    (num == SPI_WireNumThree) ? (SPIx->CR1 |= SPI_CR1_SPI_MODE_SEL_Msk) : (SPIx->CR1 &= ~SPI_CR1_SPI_MODE_SEL_Msk);
}
 
/**
  * @brief  Distinguish whether there is a DC output line in 3-wire SPI mode, 
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @param  NewState: new state of spi dc output line state
  *                 enable-> dc output line
  *                 disable-> no dc output line
  * @retval none
  */
__STATIC_INLINE void SPI_DataCmdLineEnable(SPI_T* SPIx, FunctionalState NewState)
{
    (NewState == ENABLE) ? (SPIx->CR1 |= SPI_CR1_CMD_DAT_EN_Msk) : (SPIx->CR1 &= ~SPI_CR1_CMD_DAT_EN_Msk);
}
 
 
/**
  * @brief  Write read control in 3-wire SPI mode, 
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @param  cmdDat: where cmdDat can be 
  *             SPI_DataSelect
  *             SPI_CommandSelect
  * @retval none
  */
__STATIC_INLINE void SPI_DataCmdSelCmdDat(SPI_T* SPIx, SPI_CmdDatDef cmdDat)
{
    (cmdDat == SPI_DataSelect) ? (SPIx->CR1 |= SPI_CR1_CMD_DAT_CTRL_Msk) : (SPIx->CR1 &= ~SPI_CR1_CMD_DAT_CTRL_Msk);
}
 
/**
  * @brief  Write read control in 3-wire SPI mode 
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @param  wr: where wr can be 
  *             SPI_3WireRead
  *             SPI_3WireWrite
  * @retval none
  */
__STATIC_INLINE void SPI_WriteReadCtrl(SPI_T* SPIx, SPI_WriteReadSelDef wr)
{
    (wr == SPI_3WireWrite) ? (SPIx->CR1 |= SPI_CR1_WR_CTRL_Msk) : (SPIx->CR1 &= ~SPI_CR1_WR_CTRL_Msk);
}
 
 
/**
  * @brief  Initializes the SPIx peripheral according to the specified
  *         parameters in the SPI_InitStruct .
  * @param  SPIx: where x can be 1, 2 to select the
  *         SPI peripheral.
  * @param  SPI_InitStruct: pointer to a SPI_InitTypeDef structure that contains
  *         the configuration information for the specified SPI peripheral.
  * @return None
  */
void SPI_Init(SPI_T* SPIx, SPI_InitTypeDef* SPI_InitStruct);
 
/**@} */
 
#ifdef __cplusplus
}
#endif
 
#endif //__PAN_SPI_H__
 
/*** (C) COPYRIGHT 2023 Panchip Technology Corp. ***/