84 lines
3.2 KiB
C
84 lines
3.2 KiB
C
|
#ifndef __SWM320_SPI_H__
|
|||
|
#define __SWM320_SPI_H__
|
|||
|
|
|||
|
typedef struct {
|
|||
|
uint8_t FrameFormat; //֡<><D6A1>ʽ<EFBFBD><CABD>SPI_FORMAT_SPI<50><49>SPI_FORMAT_TI_SSI
|
|||
|
uint8_t SampleEdge; //<2F><>SPI֡<49><D6A1>ʽ<EFBFBD>£<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>SPI_FIRST_EDGE<47><45>SPI_SECOND_EDGE
|
|||
|
uint8_t IdleLevel; //<2F><>SPI֡<49><D6A1>ʽ<EFBFBD>£<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD><CAB1><EFBFBD>ߵĵ<DFB5>ƽ<EFBFBD><C6BD>SPI_LOW_LEVEL<45><4C>SPI_HIGH_LEVEL
|
|||
|
uint8_t WordSize; //<2F>ֳ<EFBFBD><D6B3><EFBFBD>, <20><>Чֵ4-16
|
|||
|
uint8_t Master; //1 <20><><EFBFBD><EFBFBD>ģʽ 0 <20>ӻ<EFBFBD>ģʽ
|
|||
|
uint8_t clkDiv; //SPI_CLK = SYS_CLK / clkDiv<69><76><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>SPI_CLKDIV_4<5F><34>SPI_CLKDIV_8<5F><38>... ... <20><>SPI_CLKDIV_512
|
|||
|
|
|||
|
uint8_t RXHFullIEn; //<2F><><EFBFBD><EFBFBD>FIFO<46><4F><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
|||
|
uint8_t TXEmptyIEn; //<2F><><EFBFBD><EFBFBD>FIFO <20><><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
|||
|
uint8_t TXCompleteIEn; //<2F><><EFBFBD><EFBFBD>FIFO <20><><EFBFBD>ҷ<EFBFBD><D2B7><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
|||
|
} SPI_InitStructure;
|
|||
|
|
|||
|
#define SPI_FORMAT_SPI 0 //Motorola SPI <20><>ʽ
|
|||
|
#define SPI_FORMAT_TI_SSI 1 //TI SSI <20><>ʽ
|
|||
|
|
|||
|
#define SPI_FIRST_EDGE 0 //<2F><>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1><EFBFBD>ؿ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
#define SPI_SECOND_EDGE 1 //<2F>ڶ<EFBFBD><DAB6><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ؿ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
#define SPI_LOW_LEVEL 0 //<2F><><EFBFBD><EFBFBD>ʱʱ<CAB1><CAB1><EFBFBD>߱<EFBFBD><DFB1>ֵ͵<D6B5>ƽ
|
|||
|
#define SPI_HIGH_LEVEL 1 //<2F><><EFBFBD><EFBFBD>ʱʱ<CAB1><CAB1><EFBFBD>߱<EFBFBD><DFB1>ָߵ<D6B8>ƽ
|
|||
|
|
|||
|
#define SPI_CLKDIV_4 0
|
|||
|
#define SPI_CLKDIV_8 1
|
|||
|
#define SPI_CLKDIV_16 2
|
|||
|
#define SPI_CLKDIV_32 3
|
|||
|
#define SPI_CLKDIV_64 4
|
|||
|
#define SPI_CLKDIV_128 5
|
|||
|
#define SPI_CLKDIV_256 6
|
|||
|
#define SPI_CLKDIV_512 7
|
|||
|
|
|||
|
|
|||
|
|
|||
|
void SPI_Init(SPI_TypeDef * SPIx, SPI_InitStructure * initStruct); //SPI<50><49>ʼ<EFBFBD><CABC>
|
|||
|
void SPI_Open(SPI_TypeDef * SPIx); //SPI<50><EFBFBD><F2BFAAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>շ<EFBFBD>
|
|||
|
void SPI_Close(SPI_TypeDef * SPIx); //SPI<50>رգ<D8B1><D5A3><EFBFBD>ֹ<EFBFBD>շ<EFBFBD>
|
|||
|
|
|||
|
uint32_t SPI_Read(SPI_TypeDef * SPIx);
|
|||
|
void SPI_Write(SPI_TypeDef * SPIx, uint32_t data);
|
|||
|
void SPI_WriteWithWait(SPI_TypeDef * SPIx, uint32_t data);
|
|||
|
uint32_t SPI_ReadWrite(SPI_TypeDef * SPIx, uint32_t data);
|
|||
|
|
|||
|
uint32_t SPI_IsRXEmpty(SPI_TypeDef * SPIx); //<2F><><EFBFBD><EFBFBD>FIFO<46>Ƿ<EFBFBD><C7B7>գ<EFBFBD><D5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>SPI_Read()
|
|||
|
uint32_t SPI_IsTXFull(SPI_TypeDef * SPIx); //<2F><><EFBFBD><EFBFBD>FIFO<46>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>SPI_Write()
|
|||
|
uint32_t SPI_IsTXEmpty(SPI_TypeDef * SPIx); //<2F><><EFBFBD><EFBFBD>FIFO<46>Ƿ<EFBFBD><C7B7><EFBFBD>
|
|||
|
|
|||
|
|
|||
|
void SPI_INTRXHalfFullEn(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTRXHalfFullDis(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTRXHalfFullClr(SPI_TypeDef * SPIx);
|
|||
|
uint32_t SPI_INTRXHalfFullStat(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTRXFullEn(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTRXFullDis(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTRXFullClr(SPI_TypeDef * SPIx);
|
|||
|
uint32_t SPI_INTRXFullStat(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTRXOverflowEn(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTRXOverflowDis(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTRXOverflowClr(SPI_TypeDef * SPIx);
|
|||
|
uint32_t SPI_INTRXOverflowStat(SPI_TypeDef * SPIx);
|
|||
|
|
|||
|
void SPI_INTTXHalfFullEn(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTTXHalfFullDis(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTTXHalfFullClr(SPI_TypeDef * SPIx);
|
|||
|
uint32_t SPI_INTTXHalfFullStat(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTTXEmptyEn(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTTXEmptyDis(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTTXEmptyClr(SPI_TypeDef * SPIx);
|
|||
|
uint32_t SPI_INTTXEmptyStat(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTTXCompleteEn(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTTXCompleteDis(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTTXCompleteClr(SPI_TypeDef * SPIx);
|
|||
|
uint32_t SPI_INTTXCompleteStat(SPI_TypeDef * SPIx);
|
|||
|
|
|||
|
void SPI_INTTXWordCompleteEn(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTTXWordCompleteDis(SPI_TypeDef * SPIx);
|
|||
|
void SPI_INTTXWordCompleteClr(SPI_TypeDef * SPIx);
|
|||
|
uint32_t SPI_INTTXWordCompleteStat(SPI_TypeDef * SPIx);
|
|||
|
|
|||
|
|
|||
|
#endif //__SWM320_SPI_H__
|