rt-thread/bsp/essemi/es8p508x/libraries/Library/Include/lib_spi.h

142 lines
3.6 KiB
C
Raw Normal View History

2019-11-07 10:00:14 +08:00
/***************************************************************
*Copyright (C), 2017, Shanghai Eastsoft Microelectronics Co., Ltd.
*<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lib_spi.h
*<EFBFBD><EFBFBD> <EFBFBD>ߣ<EFBFBD> Liut
*<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> V1.00
*<EFBFBD><EFBFBD> <EFBFBD>ڣ<EFBFBD> 2017/07/14
*<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> SPIģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
*<EFBFBD><EFBFBD> ע<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ES8P508xоƬ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧϰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾʹ<EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD>ջ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>κη<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ρ<EFBFBD>
***************************************************************/
#ifndef __LIBSPI_H__
#define __LIBSPI_H__
#include "system_ES8P508x.h"
#include "ES8P508x.h"
#include "type.h"
/* ͨ<><CDA8><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BD><EFBFBD>
}SPI_TYPE_DFS;
/* ͨѶģʽ */
typedef enum
{
SPI_Mode_Master = 0x0 , //ͨѶģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SPI_Mode_Slave = 0x1 , //ͨѶģʽ<C4A3><CABD><EFBFBD>Ӷ<EFBFBD>
}SPI_TYPE_MODE;
/* ADC<44><43>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ýṹ<C3BD><EFBFBD><E5B6A8> */
typedef struct
{
uint32_t SPI_Freq; //SPIƵ<49><C6B5>
SPI_TYPE_DFS SPI_Df; //ͨѶ<CDA8><D1B6><EFBFBD>ݸ<EFBFBD>ʽ
SPI_TYPE_MODE SPI_Mode; //ͨѶģʽ
uint8_t SPI_DW; //<2F><><EFBFBD><EFBFBD>֡λ<D6A1><CEBB>
TYPE_FUNCEN SPI_DelayRec; //<2F><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
TYPE_FUNCEN SPI_DelaySend; //<2F><><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ʹ<EFBFBD><CAB9>
uint8_t SPI_SendDelayPeroid;//<2F><><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}SPI_InitStruType;
/* <20><>־λ */
typedef enum
{
SPI_Flag_TB = 0x00000001,
SPI_Flag_RB = 0x00000002,
SPI_Flag_TE = 0x00000004,
SPI_Flag_RO = 0x00000008,
SPI_Flag_ID = 0x00000010,
SPI_Flag_NSSIF = 0x00000020,
SPI_Flag_TBWE = 0x00000040,
SPI_Flag_NSS = 0x00000080,
SPI_Flag_TBEF0 = 0x00000100,
SPI_Flag_TBEF1 = 0x00000200,
SPI_Flag_TBEF2 = 0x00000400,
SPI_Flag_TBEF3 = 0x00000800,
SPI_Flag_RBFF0 = 0x00001000,
SPI_Flag_RBFF1 = 0x00002000,
SPI_Flag_RBFF2 = 0x00004000,
SPI_Flag_RBFF3 = 0x00008000,
SPI_Flag_IDLE = 0x00010000,
SPI_Flag_TMS = 0x00020000,
}SPI_TYPE_FLAG;
/* <20>ж<EFBFBD>ģʽѡ<CABD><D1A1> */
typedef enum
{
SPI_IType_BYTE = 0x0 ,
SPI_IType_HALFWORD = 0x1 ,
SPI_IType_WORD = 0x2 ,
}SPI_TYPE_TRBIM;
/* SPI<50>ж<EFBFBD> */
typedef enum
{
SPI_IT_TB = 0x01 ,
SPI_IT_RB = 0x02 ,
SPI_IT_TE = 0x04 ,
SPI_IT_RO = 0x08 ,
SPI_IT_ID = 0x10 ,
SPI_IT_NSS = 0x20 ,
SPI_IT_TBWE = 0x40 ,
}SPI_TYPE_IT;
/* SPI<50><49><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־ */
typedef enum
{
SPI_Clr_TE = 0x04 ,
SPI_Clr_RO = 0x08 ,
SPI_Clr_ID = 0x10 ,
SPI_Clr_NSS = 0x20 ,
SPI_Clr_TBWE = 0x40 ,
}SPI_CLR_IF;
/************SPIģ<49><C4A3><EFBFBD><EFBFBD><EAB6A8>***********/
/* SPIʹ<49>ܿ<EFBFBD><DCBF><EFBFBD> */
#define SPI_Enable() (SPI0->CON.EN = 1)
#define SPI_Disable() (SPI0->CON.EN = 0)
/* SPI<50><49><EFBFBD><EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD> */
#define SPI_RecEnable() (SPI0->CON.REN = 1)
#define SPI_RecDisable() (SPI0->CON.REN = 0)
/* SPI<50><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ */
#define SPI_Rst() (SPI0->CON.RST = 1)
/* SPI<50><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define SPI_RX_CLR() (SPI0->CON.RXCLR = 1)
#define SPI_TX_CLR() (SPI0->CON.TXCLR = 1)
/************SPIģ<49><EFBFBD><E9BAAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>***********/
void SPI_Init(SPI_InitStruType* SPI_InitStruct);
void SPI_ITConfig(SPI_TYPE_IT SPI_IE,TYPE_FUNCEN NewState);
void SPI_DataFormatConfig(SPI_TYPE_DFS Type);
void SPI_SendByte(uint8_t Temp);
void SPI_SendHalfWord(uint16_t Temp);
void SPI_SendWord(uint32_t Temp);
uint8_t SPI_RecByte(void);
uint16_t SPI_RecHalfWord(void);
uint32_t SPI_RecWord(void);
void SPI_TBIMConfig(SPI_TYPE_TRBIM Type);
void SPI_RBIMConfig(SPI_TYPE_TRBIM Type);
FlagStatus SPI_GetFlagStatus(SPI_TYPE_FLAG Flag);
ITStatus SPI_GetITStatus(SPI_TYPE_IT Flag);
void SPI_ClearITPendingBit(SPI_CLR_IF Flag);
#endif
/*************************END OF FILE**********************/