tao_z
2022-06-11 d8a5f3225d105585a4f181ed884adb2a861e0d13
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
/**
  ******************************************************************************
  * @file     xl_spi.c
  * @author   xu.wang
  * @version  4.5.2
  * @date     Fri Mar 26 17:29:12 2021
  * @brief    This file provide function about spi firmware program 
  ******************************************************************************
  * @attention
    *
  * 2019 by Chipways Communications,Inc. All Rights Reserved.
  * This software is supplied under the terms of a license
  * agreement or non-disclosure agreement with Chipways.
  * Passing on and copying of this document,and communication
  * of its contents is not permitted without prior written
  * authorization.
  *
  * <h2><center>&copy; COPYRIGHT 2019 Chipways</center></h2>
  ******************************************************************************
  */
    
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
 
/* Includes ---------------------------------------------------------------*/
#include "xl_spi.h"
    /** @addtogroup XL6600_StdPeriph_Driver
  * @{
  */
 
/** @defgroup SPI  SPI Module
  * @brief SPI Driver Modules Library
  * @{
  */
    
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/    
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
    
/** @defgroup SPI_Private_Functions
  * @{
  */ 
 
/**
 * @brief SPIÍâÉè»Ö¸´³õʼ״̬
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @retval None
 */
void SPI_DeInit(SPI_Type *SPIx)
{
    /* Deinitializes to default reset values */
    SPIx->CTRLR0 = 0x0007u;
    SPIx->CTRLR1 = 0x0000u;
    SPIx->BAUDR  = 0x0000u; 
    SPIx->TXFTLR = 0x0000u;
    SPIx->RXFTLR = 0x0000u;
}
 
/**
 * @brief ÉèÖÃSPIµÄģʽ
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  SPI_MODEType: Ñ¡ÔñSPI¹¤×÷ģʽ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI_MODE_MASTER(0x00) £ºÖ÷»úģʽ
 *            @arg SPI_MODE_SLAVE (0x01) £º´Ó»úģʽ
 * @retval None
 */
void SPI_SetMode(SPI_Type *SPIx,SPI_MODETypeDef SPI_MODEType)
{
    if(SPI_MODEType != SPI_MODE_MASTER )
    {
        /* SLAVE SPI */
        SPIx->MODE |= SPI_MODE_MSTR_MASK;
    }
    else 
    {
        /* MASTER SPI */
        SPIx->MODE &= ~SPI_MODE_MSTR_MASK;
    }
}
 
/**
 * @brief ÉèÖÃSPI·¢ËÍÊý¾Ý°üµÄģʽ
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  SPI_PACKType: Êý¾Ý°üµÄģʽ£¬Ñ¡ÔñÊdz¤°ü·¢ËÍ»¹ÊǶ̰ü·¢ËÍ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI_PACK_CS_LOW(0x00) :ƬѡΪµÍ
 *            @arg SPI_PACK_CS_HIGHT (0x01):ƬѡΪ¸ß
 * @retval None
 */
void SPI_SetPackCS(SPI_Type *SPIx,SPI_PACKCSTypeDef SPI_PACKCSType)
{
    if(SPI_PACKCSType != SPI_PACK_CS_HIGHT )
    {
        /* SLAVE SPI */
        SPIx->MODE |= SPI_MODE_PACK_MASK;
    }
    else 
    {
        /* MASTER SPI */
        SPIx->MODE &= ~SPI_MODE_PACK_MASK;
    }
}
 
 
 
/**
 * @brief SPIΪÖ÷»úʱ³õʼ»¯
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  SPI_MasterInitStruct: ÐèÒª³õʼ»¯µÄ²ÎÊý½á¹¹Ìå
 * @retval None
 */
void SPI_MasterInit(SPI_Type* SPIx, const SPI_MsterInitTypeDef *SPI_MasterInitStruct)
{
    uint16_t slckdiv;
              
     /* Set the CTRLR0 */                
     /* Set the bit in CTRLR0 Register */
     SPIx->CTRLR0 = (SPI_MasterInitStruct->SPI_SRL | SPI_MasterInitStruct->SPI_TMOD | \
                      SPI_MasterInitStruct->SPI_SCPOL | SPI_MasterInitStruct->SPI_SCPH | \
                      SPI_MasterInitStruct->SPI_DFS);      
        
     /* Set the CTRLR1 Register bit*/                
      SPIx->CTRLR1 = SPI_MasterInitStruct->SPI_NDF;
        
     /* Set the BAUDR */
    slckdiv= (uint16_t)(SPI_MasterInitStruct->SPI_SourceClk/SPI_MasterInitStruct->SPI_BAUDR);
        
      SPIx->BAUDR = slckdiv;    
        
     /* Set the TXFTLR */                
      SPIx->TXFTLR = SPI_MasterInitStruct->SPI_TFT;            
 
     /* Set the RXFTLR */                
      SPIx->RXFTLR = SPI_MasterInitStruct->SPI_RFT;        
}    
 
/**
 * @brief SPIΪ´Ó»úʱµÄ³õʼ»¯
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  SPI_SlaveInitTypeDef: ÐèÒª³õʼ»¯µÄ²ÎÊý½á¹¹Ìå
 * @retval None
 */
void SPI_SlaveInit(SPI_Type* SPIx, const SPI_SlaveInitTypeDef *SPI_SlaveInitStruct)
{
    
        /* Set the CTRLR0 */                
        /* Set the bit in CTRLR0 Register */    
        SPIx->CTRLR0 = (SPI_SlaveInitStruct->SPI_SRL | SPI_SlaveInitStruct->SPI_TMOD | \
                                        SPI_SlaveInitStruct->SPI_SCPOL | SPI_SlaveInitStruct->SPI_SCPH | \
                                        SPI_SlaveInitStruct->SPI_DFS);
        
                /* check the slave output Enable */    
        if(SPI_SlaveInitStruct->SPI_SLVOE != DISABLE)
        {
            SPIx->CTRLR0 &= ~SPI_CTRLR0_SLVOE_MASK;
        }
        else
        {
            SPIx->CTRLR0 |= SPI_CTRLR0_SLVOE_MASK;
        }
            
        /* Set the TXFTLR */                
        SPIx->TXFTLR = SPI_SlaveInitStruct->SPI_TFT;            
 
        /* Set the RXFTLR */                
        SPIx->RXFTLR = SPI_SlaveInitStruct->SPI_RFT;        
}    
 
/**
 * @brief SPIʹÄÜ
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  NewState: Ê¹ÄܺÍʧÄÜÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg ENABLE £ºÊ¹ÄÜ
 *            @arg DISENABLE £ºÊ§ÄÜ
 * @retval None
 */
void SPI_EnableCmd(SPI_Type *SPIx,FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* Enable the SPI */
        SPIx->SPIENR |= SPI_SPIENR_SPIE_MASK;
    }
    else 
    {
        /* Disable the SPI */
        SPIx->SPIENR &= ~SPI_SPIENR_SPIE_MASK;
    }
}
 
/**
 * @brief  SPI×÷Ϊ´Ó»úʱʹÄÜÃüÁî
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  NewState: Ê¹ÄܺÍʧÄÜÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg ENABLE £ºÊ¹ÄÜ
 *            @arg DISENABLE £ºÊ§ÄÜ
 * @retval None
 */
void SPI_SlaveEnableCmd(SPI_Type *SPIx,FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* Enable the SPI Slave Select Output */
        SPIx->SER |= SPI_SER_SSEF_MASK;
    }
    else 
    {
        /* Disable the SPI Slave Select Output */
        SPIx->SER &= ~SPI_SER_SSEF_MASK;
    }
}
 
/**
 * @brief  SPI·¢ËÍÊý¾Ý
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  Data: ·¢Ë͵ÄÊý¾Ý
 * @retval None
 */
void SPI_SendData(SPI_Type *SPIx,uint16_t Data)
{
    /* Write in the DR register the data to be sent */
    SPIx->DR[0] = Data;
}
 
/**
 * @brief  SPI½ÓÊÕÊý¾Ý
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @retval Data£ºSPI½ÓÊÕµÄÊý¾Ý
 */
uint16_t SPI_ReceiveData(const SPI_Type *SPIx)
{
    uint16_t Data;        
    Data =(uint16_t)SPIx->DR[0];        
    /* Return the data in the DR register */    
    return Data;
}
 
/**
 * @brief  µÃµ½SPIÖÐFIFOÓÐЧÊý¾ÝµÄ¸öÊý
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param FIFOLevelDef: FIFOÀàÐÍ£¬·¢ËÍFIFO»ò½ÓÊÕFIFO
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI_TransmitFIFOLevel (0x00), ·¢ËÍFIFO
 *            @arg SPI_ReceiveFIFOLevel  (0x01)  ½ÓÊÕFIFO
 * @retval fifolevel£ºSPIµÄFIFOÖеÃÓÐЧÊý¾Ý¸öÊý
 */
uint8_t SPI_GetFIFOLevel(const SPI_Type *SPIx,SPI_TXRXFIFOLevelDef FIFOLevelDef)
{
    uint8_t fifolevel;
     
    /* Get the Transmit FIFO Level */
    if(FIFOLevelDef==SPI_TransmitFIFOLevel)
    {
        fifolevel=(uint8_t)(SPIx->TXFLR &SPI_TXFLR_TFL_MASK);
    }
    /* Get the Receive FIFO Level */
    else
    {
        fifolevel=(uint8_t)(SPIx->RXFLR &SPI_RXFLR_RFL_MASK);        
    }
    
    /* return the fifolevel Value */
    return fifolevel;      
}
 
/**
 * @brief  µÃµ½SPI״̬
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  SPI_StatusTypeDef ½«Òª»ñÈ¡µÄ״̬ÀàÐÍÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI_SPIBusyFlagStatus £º           SPI·±Ã¦±ê־λ
 *            @arg SPI_TransmitFIFONotFullStatus£º    ·¢ËÍFIFOδÂú
 *            @arg SPI_TransmitFIFOEmptyStatus£º      ·¢ËÍFIFOΪ¿Õ
 *            @arg SPI_ReceiveFIFONotEmptyStatus£º    ½ÓÊÕFIFO²»Îª¿Õ
 *            @arg SPI_ReceiveFIFOFullStatus£º        ½ÓÊÕFIFOÒÑÂú
 *            @arg SPI_TransmissionErrorStatus£º      Êý¾Ý·¢ËÍ´íÎó£¬Ö»ÓÐSPIΪ´Ó»úʱ²ÅÄÜʹÓô˹¦ÄÜ
 *            @arg SPI_DataCollisionErrorStatus£º     Êý¾Ý³åÍ»´íÎó£¬Ö»ÓÐSPIΪÖ÷»úʱ²ÅÓд˹¦ÄÜ
 * @retval SPI_Status£ºSPI״̬µÄÀàÐÍ
 *            @arg 0:¶ÔӦ״̬δ²úÉú
 *            @arg 1:¶ÔӦ״̬²úÉú
 */
uint8_t SPI_GetStatus(const SPI_Type *SPIx,SPI_StatusTypeDef SPI_StatusType)
{
    uint8_t StatusTemp;
 
    /* Get all the status */
    StatusTemp = (uint8_t)(SPIx->SR);
 
    /* get the selected status */
    return (StatusTemp &    (uint8_t)(1u<<(uint8_t)SPI_StatusType));
}
 
/**
 * @brief  SPIÖжÏʹÄÜ
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  SPI_InterruptTypeDef Ê¹ÄÜÖжÏÀàÐÍ£¬ÆäÖµÈçÏ£º
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI_TransmitFIFOEmptyIT£º           ·¢ËÍFIFOÒѿյÄÖжÏÑÚÂë
 *            @arg SPI_TransmitFIFOOverflowIT£º        ·¢ËÍFIFOÒç³öµÄÖжÏÑÚÂë
 *            @arg SPI_ReceiveFIFOUnderflowIT£º        ½ÓÊÕFIFOÏÂÒçµÄÖжÏÑÚÂë
 *            @arg SPI_ReceiveFIFOOverflowIT£º         ½ÓÊÕFIFOÒç³öµÄÖжÏÑÚÂë
 *            @arg SPI_ReceiveFIFOFullIT £º            ½ÓÊÕFIFOÒÑÂúµÄÖжÏÑÚÂë
 *            @arg SPI_ALLIT £º                        ËùÓеÄÑÚÂë
 * @param  NewState: ×´Ì¬Ñ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg ENABLE £ºÊ¹ÄÜ
 *            @arg DISENABLE £ºÊ§ÄÜ
 * @retval None
 */
void SPI_InterruptEn(SPI_Type *SPIx, SPI_InterruptTypeDef SPI_Interrupt, FunctionalState NewState)
{
  uint8_t itmask;
    if(SPI_Interrupt == SPI_ALLIT)
    {
        if (NewState != DISABLE)
        {
            /* Enable the selected SPI interrupts */
            SPIx->IMR = 0xFFFFFFFFu;
        }
        else
        {
            /* Disable the selected SPI interrupts */
            SPIx->IMR = 0u;
        }
    }
    else
    {
        /* Get the interrupt enable index */
        itmask = (uint8_t)(1u<<(uint8_t)SPI_Interrupt);
 
        if (NewState != DISABLE)
        {
            /* Enable the selected SPI interrupts */
            SPIx->IMR |= itmask;
        }
        else
        {
            /* Disable the selected SPI interrupts */
            SPIx->IMR &= ~itmask;
        }
    }
}
 
/**
 * @brief  SPIÇå³ýÖжÏ
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  SPI_InterruptClearDef Çå³ýÖжϵÄÀàÐÍ£¬ÆäÖµÈçÏ£º
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI_TransmitFIFOOverflowITClear£º      Çå¿Õ·¢ËÍFIFOÒç³öÖжϼĴæÆ÷
 *            @arg SPI_ReceiveFIFOOverflowITClear£º       Çå¿Õ½ÓÊÕFIFOÒç³öÖжϼĴæÆ÷
 *            @arg SPI_ReceiveFIFOUnderflowITClear£º      Çå¿Õ½ÓÊÕFIFOÏÂÒçÖжϼĴæÆ÷
 *            @arg SPI_ALLITClear£º                       Çå¿ÕËùÓÐ״̬
 * @retval ÖжÏÀàÐÍ
 */
uint8_t SPI_ClearInterrupt(const SPI_Type *SPIx, SPI_InterruptClearDef SPI_Interrupt2Clear)
{
    uint8_t interrupt2clear;
     
    /* Clear Transmit FIFO Overflow Interrupt */
    if(SPI_Interrupt2Clear==SPI_TransmitFIFOOverflowITClear)
    {
        interrupt2clear=(uint8_t)(SPIx->TXOICR);
    }
    /* Clear Receive FIFO Overflow Interrupt */
    else if(SPI_Interrupt2Clear==SPI_ReceiveFIFOOverflowITClear)
    {
        interrupt2clear=(uint8_t)(SPIx->RXOICR);        
    }
    /* Clear Receive FIFO Underflow Interrupt */
    else if(SPI_Interrupt2Clear==SPI_ReceiveFIFOUnderflowITClear)
    {
        interrupt2clear=(uint8_t)(SPIx->RXUICR);    
    }
    /* Clear Interrupt */
    else
    {
        interrupt2clear=(uint8_t)(SPIx->ICR);            
    }
    
    /* return the interrupt type */
    return interrupt2clear;      
}
 
/**
 * @brief  µÃµ½SPIÖжÏ״̬£¬ÖÐ¶ÏÆÁ±ÎºóµÄ״̬
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  SPI_ITStatusMaskedDef »ñÈ¡µÄÖжÏÀàÐÍ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI_TransmitFIFOEmptyITStatus £º       ·¢ËÍFIFO¿ÕÖжÏ״̬
 *            @arg SPI_TransmitFIFOOverflowITStatus£º     ·¢ËÍFIFOÒç³öÖжÏ״̬
 *            @arg SPI_ReceiveFIFOUnderflowITStatus£º     ½ÓÊÕFIFOÏÂÒçÖжÏ״̬
 *            @arg SPI_ReceiveFIFOOverflowITStatus£º      ½ÓÊÕFIFOÒç³öÖжÏ״̬
 *            @arg SPI_ReceiveFIFOFullITStatus£º          ½ÓÊÕFIFOÒÑÂúÖжÏ״̬
 * @retval ÖжÏ״̬
 */
uint8_t SPI_GetIntMaskedStatus(const SPI_Type *SPIx,SPI_ITStatusMaskedDef SPI_IntStatusType)
{
    uint8_t IntStatusTemp;
 
    /* Get all the interrupt status */
    IntStatusTemp = (uint8_t)(SPIx->ISR);
    
    /* get the selected interrupt status */
    return (IntStatusTemp &(uint8_t)(1u<<(uint8_t)SPI_IntStatusType));
}
 
/**
 * @brief  »ñµÃSPIÖжÏǰ״̬£¬ÔÚÆÁ±Î֮ǰSPIÖжϵÄ״̬
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  SPI_RawITStatusTypeDef »ñÈ¡µÄÖжÏÀàÐÍ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI_TransmitFIFOEmptyRawITStatus£º        ·¢ËÍFIFOԭʼÖжÏΪ¿Õ״̬
 *            @arg SPI_TransmitFIFOOverflowRawITStatus£º     ·¢ËÍFIFOԭʼÖжÏÒç³ö״̬
 *            @arg SPI_ReceiveFIFOUnderflowRawITStatus£º     ½ÓÊÕFIFOԭʼÖжÏÏÂÒç״̬
 *            @arg SPI_ReceiveFIFOOverflowRawITStatus£º      ½ÓÊÕFIFOԭʼÖжÏÒç³ö״̬
 *            @arg SPI_ReceiveFIFOFullRawITStatus£º          ½ÓÊÕFIFOԭʼÖжÏÒÑÂú״̬
 * @retval Ô­Ê¼ÖжÏ״̬
 */
uint8_t SPI_GetRawIntStatus(const SPI_Type *SPIx,SPI_RawITStatusTypeDef SPI_RawIntStatusType)
{
    uint8_t RawIntStatusTemp;
    /* Get all the Raw interrupt status */
    RawIntStatusTemp =(uint8_t)(SPIx->RISR);
    
    /* get the selected Raw interrupt status */
    return (RawIntStatusTemp &(uint8_t)(1u<<(uint8_t)SPI_RawIntStatusType));
}
 
/**
 * @brief  SPIÉèÖÃDMA·¢ËÍÊý¾ÝµÄ³¤¶È
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  lenght £ºÊý¾Ý³¤¶È
 * @retval None
 */
void SPI_SetDMATxDataLenght(SPI_Type *SPIx,uint8_t lenght)
{
    SPIx->DMATDLR = lenght;
}
/**
 * @brief  SPIÉèÖÃDMA½ÓÊÕÊý¾Ý³¤¶È
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  lenght £ºÊý¾Ý³¤¶È
 * @retval None
 */
void SPI_SetDMARxDataLenght(SPI_Type *SPIx,uint8_t lenght)
{
    SPIx->DMARDLR = lenght;
}
/**
 * @brief  SPIÉèÖÃDMA·¢ËÍʹÄÜ
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  NewState: ×´Ì¬Ñ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg ENABLE £ºÊ¹ÄÜ
 *            @arg DISENABLE £ºÊ§ÄÜ
 * @retval None
 */
void SPI_DMATxEnableCmd(SPI_Type *SPIx,FunctionalState NewState)
{
    if (NewState != DISABLE)
    {
        /* Enable the selected SPI interrupts */
        SPIx->DMACR |= SPI_DMACR_TDMAE_MASK;
    }
    else
    {
        /* Disable the selected SPI interrupts */
        SPIx->DMACR &= ~SPI_DMACR_TDMAE_MASK;
    }
}
/**
 * @brief  SPIÉèÖÃDMA½ÓÊÕʹÄÜ
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  NewState: ×´Ì¬Ñ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg ENABLE £ºÊ¹ÄÜ
 *            @arg DISENABLE £ºÊ§ÄÜ
 * @retval None
 */
void SPI_DMARxEnableCmd(SPI_Type *SPIx,FunctionalState NewState)
{
    if (NewState != DISABLE)
    {
        /* Enable the selected SPI interrupts */
        SPIx->DMACR |= SPI_DMACR_RDMAE_MASK;
    }
    else
    {
        /* Disable the selected SPI interrupts */
        SPIx->DMACR &= ~SPI_DMACR_RDMAE_MASK;
    }
}
/**
 * @brief  SPIÉèÖÃÑÓʱ²ÉÑùʱ¼ä
 * @param  SPIx: SPIÍâÉèµÄÑ¡Ôñ
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg SPI0 £ºSPI0ÍâÉè
 *            @arg SPI1 £ºSPI1ÍâÉè
 * @param  nclock £ºÑÓʱµÄʱ¼ä,ȡֵ(0-255)
 * @retval None
 */
void SPI_DelaySampling(SPI_Type *SPIx,uint32_t nclock)
{
    SPIx->DLY  = nclock;
}
 
 
/**
  * @}
  */
 
/**
  * @}
  */
 
/**
  * @}
  */
#ifdef __cplusplus
}
#endif /* __cplusplus */