123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- /*
- * 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 <stdio.h>
- #include <stdint.h>
- #include <stdbool.h>
- #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_High ((uint8_t)0<<4)
- #define SPI_CPOL_Active_Low ((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 Init 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 len */
-
- uint16_t SPI_RXlen; /*!< Specifies Rx DMA buff len */
- }SPI_InitTypeDef;
- void SPI_Init(SPI_InitTypeDef* SPI_InitStruct);
- void SPI_DeInit(void);
- void SPI_SendData(uint16_t Data);
- uint16_t SPI_ReadRegister(uint16_t RegAdr);
- void SPI_SendDataFromBuff(uint8_t *Buff, uint16_t Len);
- 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);
- #endif /* _SPI_H_ */
-
|