/* * Copyright 2016, yichip Semiconductor(shenzhen office) * All Rights Reserved. * * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Yichip Semiconductor; * the contents of this file may not be disclosed to third parties, copied * or duplicated in any form, in whole or in part, without the prior * written permission of Yichip Semiconductor. */ /** @file * * spi support for application */ #ifndef _SPI_H_ #define _SPI_H_ #include #include #include //#include "yc11xx.h" #include "yc_drv_common.h" /** @ * @defgroup SPI_Mode */ #define SPI_Mode_Four_Wire 4 #define SPI_Mode_Three_Wire 3 #define SPI_Mode_Two_Wire 2 #define IS_SPI_MODE(MODE) (((MODE) == SPI_Mode_Two_Wire) || \ ((MODE) == SPI_Mode_Three_Wire)) || \ ((MODE) == SPI_Mode_Four_Wire) /** @ * @defgroup SPI_CPOL */ #define SPI_CPOL_Active_Low ((uint8_t)0<<4) #define SPI_CPOL_Active_High ((uint8_t)1<<4) #define IS_SPI_CPOL(CPOL) (((CPOL) == SPI_CPOL_Active_High) || \ ((CPOL) == SPI_CPOL_Active_Low)) /** @ * @defgroup SPI_CPHA */ #define SPI_CPHA_First_Edge ((uint8_t)0<<5) #define SPI_CPHA_Second_Edge ((uint8_t)1<<5) #define IS_SPI_CPHA(CPHA) (((CPHA) == SPI_CPHA_First_Edge) || \ ((CPHA) == SPI_CPHA_Second_Edge)) /** @ * @defgroup SPI_BaudSpeed */ #define SPI_BAUDSPEED_2MHz 4 #define SPI_BAUDSPEED_750KHz 5 #define SPI_BAUDSPEED_375KHz 6 #define SPI_BAUDSPEED_187KHz 7 #define IS_SPI_BAUDSPEED(BAUDSPEED) (((BAUDSPEED) >=SPI_BAUDSPEED_2MHz) && ((BAUDSPEED) <= SPI_BAUDSPEED_187KHz)) /** @defgroup SPI_TXLen * @{ */ #define IS_SPI_TXLen(TxLen) (TxLen != 0) /** * @} */ /** @defgroup SPI_RXlen * @{ */ #define IS_SPI_RXLen(RxLen) (RxLen != 0) /** * @} */ /** *@brief SPI initialized structure definition. */ typedef struct { uint16_t SPI_Mode; /*!< Specifies the SPI operating mode. This parameter can be a value of @ref SPI_mode */ uint16_t SPI_CPOL; /*!< Specifies the serial clock steady state. This parameter can be a value of @ref SPI_Clock_Polarity */ uint16_t SPI_CPHA; /*!< Specifies the clock active edge for the bit capture. This parameter can be a value of @ref SPI_Clock_Phase */ uint16_t SPI_BaudSpeed; /*!< Specifies the Baud Rate prescaler value which will be used to configure the transmit and receive SCK clock. This parameter can be a value of @ref SPI_BaudRate_Prescaler. @note The communication clock is derived from the master clock. The slave clock does not need to be set. */ uint16_t SPI_TXLen; /*!< Specifies Tx DMA buff length */ uint16_t SPI_RXlen; /*!< Specifies Rx DMA buff length */ }SPI_InitTypeDef; /** *@brief SPI initialization. *@param SPI_InitStruct SPI initializing structure.@ref SPI_InitTypeDef *@return None. */ void SPI_Init(SPI_InitTypeDef* SPI_InitStruct); /** *@brief cancel SPI initialization. *@param None. *@return None. */ void SPI_DeInit(void); /** *@brief This function can send data through SPI bus. *@param Data the data will be send. *@return None. */ uint8_t SPI_Flash_SendByte(uint8_t Data); uint8_t SPI_Flash_RecvByte(uint8_t Data); void Spi_SendReceDataToBuff(uint8_t *txdata,int txlen,uint8_t *rxbuf,int rxlen); void SPI_SendData(uint16_t Data); /** *@brief The function is used to read the value of the SPI register. *@param RegAdr address of the register to read. *@return SPI current read pointer. */ uint16_t SPI_ReadRegister(uint16_t RegAdr); /** *@brief This function can send a set of data through SPI bus. *@param Buff the pointer of data that will be send. *@param Len the number of byte to be send. *@return None. */ void SPI_SendDataFromBuff(uint8_t *Buff, uint16_t Len); /** *@brief This function can receive a set of data through SPI bus. *@param TxBuff the pointer of data that will be send. *@param TxLen the number of byte to be send. *@param RxBuff the pointer that the read data is stored. *@param RxLen the number of byte received. *@return None. */ void SPI_ReceiveDataToBuff(uint8_t *TxBuff, uint16_t TxLen, uint8_t *RxBuff, uint16_t RxLen); void SPI_ReceiveDataToBuff2(uint8_t *TxBuff, uint16_t TxLen, uint8_t *RxBuff, uint16_t RxLen); void SPI_SendDataFromBuffWithoutDMAdone(uint8_t *Buff, uint16_t Len); bool SPI_WaitDone(void); void SPI_FLASH_Init(void); void Soft_SPI_Write(uint8_t a); uint8_t Soft_SPI_Read(void); void Soft_WaitFlahTobeReady(void); void Soft_Flash_chipErase(uint32_t addr); void Soft_SPIFlashPageWrite(uint8_t *Writebuffer, uint32_t Writeaddr, uint16_t NumberbiteToWrite); void Soft_SPIFlashRead(uint8_t *Readbuffer, uint32_t Readaddr, uint16_t NumberbiteToRead); uint32_t Soft_SPIFlashIDRead(void); #endif /* _SPI_H_ */