#ifndef _SR_BSP_SPI_H
#define _SR_BSP_SPI_H

#include "sr_config.h"

#ifdef SR_USE_SPI

//原厂头文件
#include "stm32f4xx_hal.h"

//配置参数枚举直接赋值为原厂值，省去参数转换

#define BSP_SPI_MASTER      SPI_MODE_MASTER   /*!< 主机*/
#define BSP_SPI_SLAVE       SPI_MODE_SLAVE    /*!< 从机*/

#define BSP_SPI_CPOL_LOW    SPI_POLARITY_LOW  /*!< 空闲状态是低电平*/  
#define BSP_SPI_CPOL_HIGH   SPI_POLARITY_HIGH /*!< 空闲状态是高电平*/ 

#define BSP_SPI_CPHA_1EDGE  SPI_PHASE_1EDGE   /*!< 奇数边沿采样*/            
#define BSP_SPI_CPHA_2EDGE  SPI_PHASE_2EDGE   /*!< 偶数边沿采样*/ 

#define BSP_SPI_MSB         SPI_FIRSTBIT_MSB  /*!< MSB优先*/
#define BSP_SPI_LSB         SPI_FIRSTBIT_LSB  /*!< LSB优先*/

#define BSP_SPI_DW_8BIT     SPI_DATASIZE_8BIT  /*!< 8bit*/
#define BSP_SPI_DW_16BIT    SPI_DATASIZE_16BIT /*!< 16bit*/


/**
 * @brief 朝阳应用使用的SPI的ID号
 */
typedef enum
{
  SR_SPI1 = 1,
  SR_SPI2 = 2,

} SR_SPI_ID_E;



/**
 * @brief SPI设备信息结构体
 */
typedef struct BSP_SPI_INFO
{
  const char *name;  /*!< spi设备的名字*/
  void *trdHandle;   /*!< 第三方平台使用的句柄指针*/
  SPI_TypeDef  *instance;  /*!< ST平台HAL库变量，对应SPI寄存器地址*/
  int8_t srId;       /*!< 朝阳使用的ID*/

} BSP_SPI_INFO_T;


SR_DEVICE_T *BspSpiOpen(SR_SPI_ID_E spiId);
int BspSpiClose(SR_DEVICE_T *dev);
int BspSpiConfig(SR_DEVICE_T *dev, SR_SPI_CFG_T *cfg);
int BspSpiReadReg(SR_DEVICE_T *dev, uint32_t reg,uint16_t regLen, uint8_t *buff, uint16_t buffLen);
int BspSpiWriteReg(SR_DEVICE_T *dev, uint32_t reg,uint16_t regLen,uint8_t *buff, uint16_t buffLen);
int BspSpiWriteRead(SR_DEVICE_T *dev,uint8_t *txBuf,uint8_t *rxBuf,uint16_t len,uint8_t csCtrl);


#endif  // end of SR_USE_SPI


#endif

