/******************************************************************************
;  *   	@MCU				 : MC51F003A4
;  *   	@Create Date         : 2021.10.11
;  *   	@Author/Corporation  : Martin/SinoMCU
;  *   	@晟矽微技术支持QQ 	 : 2048615934
;  *    @晟矽微官网		     : http://www.sinomcu.com/
;  *   	@Copyright           : 2020 SINOMCU Corporation,All Rights Reserved.
;  *----------------------Abstract Description---------------------------------
;  *			          定义                              		
******************************************************************************/

#ifndef SPI_LIB_H__
#define SPI_LIB_H__

#include "MC51F003A4_COMMON.h"

#define SPI_EN                  DEF_SET_BIT7
#define SPI_IE_ADDR             DEF_SET_BIT5

#define SPI_FLAG_DATA_COMPLETION     DEF_SET_BIT6    //数据传送完成
#define SPI_FLAG_IF                  DEF_SET_BIT6    //数据传送完成
#define SPI_FLAG_MODE_FAOLURE        DEF_SET_BIT5    //模式故障
#define SPI_FLAG_WRITE_CONFLICT      DEF_SET_BIT4    //写冲突
#define SPI_FLAG_RECEIV_OVERRUN      DEF_SET_BIT5    //接收超限

#define SPI_FIRST_BIT_MSB       0
#define SPI_FIRST_BIT_LSB       DEF_SET_BIT7

#define SPI_MODE_SLAVE          0
#define SPI_MODE_MASTER         DEF_SET_BIT6

#define SPI_CPHA_1EDGE          0
#define SPI_CPHA_2EDGE          DEF_SET_BIT5

#define SPI_CPOL_LOW            0
#define SPI_CPOL_HIGH           DEF_SET_BIT4

#define SPI_NSS_ENABLE          0
#define SPI_NSS_DISABLE         DEF_SET_BIT3

#define SPI_CLK_DIV_2           0
#define SPI_CLK_DIV_4           0x01
#define SPI_CLK_DIV_8           0x02
#define SPI_CLK_DIV_16          0x03
#define SPI_CLK_DIV_32          0x04
#define SPI_CLK_DIV_64          0x05
#define SPI_CLK_DIV_128         0x06
#define SPI_CLK_DIV_256         0x07

typedef struct
{
    uint8_t SPI_mode;                   //SPI模式，主/从机
    uint8_t SPI_CPOL;                   //空闲模式SCK  H/L
    uint8_t SPI_CPHA;                   //SPI周期第几个上升沿采集数据
    uint8_t SPI_NSS;                    //片选信号
    uint8_t SPI_clock_division;         //时钟分频
    uint8_t SPI_first_bit;              //发送从MSB/LSB
    uint8_t SPI_interrupt;             //SPI中断
    uint8_t SPI_interrupt_priority;    //SPI中断优先级
} SPI_InitTypeDef;

void SPI_Init(SPI_InitTypeDef *SPI);
void SPI_Cmd(uint8_t newstate);
flagstatus SPI_Get_FlagStatus(uint8_t SPI_flag);
void SPI_Clear_FlagStatus(uint8_t SPI_flag);
uint8_t SPI_Receive_Data(void);
void SPI_Send_Data(uint8_t dat);



#endif

/**************************** end of file *********************************************/
