rt-thread-official/bsp/CME_M7/StdPeriph_Driver/inc/cmem7_spi.h

168 lines
6.1 KiB
C
Raw Normal View History

2014-08-30 00:19:16 +08:00
/**
2023-04-05 11:26:18 +08:00
*****************************************************************************
* @file cmem7_spi.h
*
* @brief CMEM7 SPI header file
*
*
* @version V1.0
* @date 3. September 2013
*
* @note
*
*****************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, CAPITAL-MICRO SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2013 Capital-micro </center></h2>
*****************************************************************************
*/
2014-08-30 00:19:16 +08:00
#ifndef __CMEM7_SPI_H
#define __CMEM7_SPI_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "cmem7.h"
#include "cmem7_conf.h"
#define IS_SPI_ALL_PERIPH(PERIPH) (((PERIPH) == SPI0) || \
((PERIPH) == SPI1))
/** @defgroup SPI_MODE
* @{
*/
2023-04-05 11:26:18 +08:00
#define SPI_MODE_CPOL_0_CPHA_0 0 /*!< CPOL : Idle clock level is low level.
CPHA : Capture data at the first edge */
#define SPI_MODE_CPOL_0_CPHA_1 1 /*!< CPOL : Idle clock level is low level.
CPHA : Capture data at the second edge */
#define SPI_MODE_CPOL_1_CPHA_0 2 /*!< CPOL : Idle clock level is high level.
CPHA : Capture data at the first edge */
#define SPI_MODE_CPOL_1_CPHA_1 3 /*!< CPOL : Idle clock level is high level.
CPHA : Capture data at the first edge */
2014-08-30 00:19:16 +08:00
#define IS_SPI_MODE(MODE) (((MODE) == SPI_MODE_CPOL_0_CPHA_0) || \
((MODE) == SPI_MODE_CPOL_0_CPHA_1) || \
((MODE) == SPI_MODE_CPOL_1_CPHA_0) || \
2023-04-05 11:26:18 +08:00
((MODE) == SPI_MODE_CPOL_1_CPHA_1))
2014-08-30 00:19:16 +08:00
/**
* @}
*/
/** @defgroup SPI_INT
* @{
2023-04-05 11:26:18 +08:00
*/
#define SPI_INT_RX_FIFO_UNDERFLOW 0x00000001
2014-08-30 00:19:16 +08:00
#define SPI_INT_RX_FIFO_OVERFLOW 0x00000002
#define SPI_INT_RX_FIFO_ALMOST_FULL 0x00000004
2023-04-05 11:26:18 +08:00
#define SPI_INT_TX_FIFO_UNDERFLOW 0x00000008
2014-08-30 00:19:16 +08:00
#define SPI_INT_TX_FIFO_OVERFLOW 0x00000010
#define SPI_INT_TX_FIFO_ALMOST_FULL 0x00000020
#define SPI_INT_DONE 0x00000040
#define SPI_INT_ALL 0x0000007F
#define IS_SPI_INT(INT) (((INT) != 0) && (((INT) & ~SPI_INT_ALL) == 0))
/**
* @}
*/
/**
* @brief SPI initialization structure
2023-04-05 11:26:18 +08:00
*/
2014-08-30 00:19:16 +08:00
typedef struct
{
uint8_t SPI_Mode; /*!< indicates SPI's CPOL and CPHA, ref as @ref SPI_MODE */
BOOL SPI_RxEn; /*!< indicates if SPI receiver is enabled or not */
uint8_t SPI_BitLength; /*!< bit length while transmitting and receiving */
2023-04-05 11:26:18 +08:00
uint8_t SPI_Gap; /*!< cycle number between continuous data frame */
uint8_t SPI_ClockDividor; /*!< SPI clock dividor, 1 / ((1 + DIV) * 2) */
2014-08-30 00:19:16 +08:00
} SPI_InitTypeDef;
/**
* @}
*/
/**
* @brief SPI initialization
* @note This function should be called at first before any other interfaces.
2023-04-05 11:26:18 +08:00
* @param[in] SPIx SPI peripheral, which is SPI0 or SPI1
* @param[in] init A pointer to structure SPI_InitTypeDef
2014-08-30 00:19:16 +08:00
* @retval None
2023-04-05 11:26:18 +08:00
*/
2014-08-30 00:19:16 +08:00
void SPI_Init(SPI0_Type* SPIx, SPI_InitTypeDef *init);
/**
2023-04-05 11:26:18 +08:00
* @brief Enable or disable SPI.
* @param[in] SPIx SPI peripheral, which is SPI0 or SPI1
* @param[in] Enable The bit indicates if the specific SPI is enable or not
2014-08-30 00:19:16 +08:00
* @retval None
2023-04-05 11:26:18 +08:00
*/
2014-08-30 00:19:16 +08:00
void SPI_Enable(SPI0_Type* SPIx, BOOL enable);
/**
2023-04-05 11:26:18 +08:00
* @brief Enable or disable SPI interrupt.
* @param[in] SPIx SPI peripheral, which is SPI0 or SPI1
* @param[in] Int interrupt mask bits, which can be the combination of @ref SPI_Int
* @param[in] Enable The bit indicates if specific interrupts are enable or not
2014-08-30 00:19:16 +08:00
* @retval None
2023-04-05 11:26:18 +08:00
*/
2014-08-30 00:19:16 +08:00
void SPI_EnableInt(SPI0_Type* SPIx, uint32_t Int, BOOL enable);
/**
2023-04-05 11:26:18 +08:00
* @brief Check specific interrupts are set or not
* @param[in] SPIx SPI peripheral, which is SPI0 or SPI1
* @param[in] Int interrupt mask bits, which can be the combination of @ref SPI_Int
2014-08-30 00:19:16 +08:00
* @retval BOOL The bit indicates if specific interrupts are set or not
2023-04-05 11:26:18 +08:00
*/
2014-08-30 00:19:16 +08:00
BOOL SPI_GetIntStatus(SPI0_Type* SPIx, uint32_t Int);
/**
* @brief Clear specific interrupts
2023-04-05 11:26:18 +08:00
* @param[in] SPIx SPI peripheral, which is SPI0 or SPI1
* @param[in] Int interrupt mask bits, which can be the combination of @ref SPI_Int
2014-08-30 00:19:16 +08:00
* @retval None
2023-04-05 11:26:18 +08:00
*/
2014-08-30 00:19:16 +08:00
void SPI_ClearInt(SPI0_Type* SPIx, uint32_t Int);
/**
* @brief Read data from SPI FIFO
2023-04-05 11:26:18 +08:00
* @param[in] SPIx SPI peripheral, which is SPI0 or SPI1
* @param[in] size Expected data size to be read
* @param[out] data A user-allocated buffer to fetch data to be read
2014-08-30 00:19:16 +08:00
* @retval uint8_t Actual read data size
2023-04-05 11:26:18 +08:00
*/
2014-08-30 00:19:16 +08:00
uint8_t SPI_ReadFifo(SPI0_Type* SPIx, uint8_t size, uint32_t* data);
/**
* @brief Write data to SPI FIFO
2023-04-05 11:26:18 +08:00
* @param[in] SPIx SPI peripheral, which is SPI0 or SPI1
* @param[in] size Expected data size to be written
* @param[in] data A pointer to the data to be written
2014-08-30 00:19:16 +08:00
* @retval uint8_t Actual written data size
2023-04-05 11:26:18 +08:00
*/
2014-08-30 00:19:16 +08:00
uint8_t SPI_WriteFifo(SPI0_Type* SPIx, uint8_t Size, uint32_t* data);
/**
2023-04-05 11:26:18 +08:00
* @brief send a SPI transcation request
* @param[in] SPIx SPI peripheral, which is SPI0 or SPI1
* @param[in] size Expected data size to be written and read
* @retval BOOL The bit indicates if the request is sent
*/
2014-08-30 00:19:16 +08:00
BOOL SPI_Transcation(SPI0_Type* SPIx, uint8_t size);
#ifdef __cplusplus
}
#endif
#endif /*__CMEM7_SPI_H */