#ifndef __SPI_H
#define __SPI_H

uint32_t SPI_MasterOpen(OB_SPI_Type *pSPI, uint32_t nSPICapability, uint32_t Length, uint32_t nBusClock);
void     SPI_Close(OB_SPI_Type *pSPI);
void     SPI_EnableINT(OB_SPI_Type *pSPI, uint32_t nINTSel);
void     SPI_DisableINT(OB_SPI_Type *pSPI, uint32_t nINTSel);
void     SPI_ClearRxFIFO(OB_SPI_Type *pSPI);
void     SPI_ClearTxFIFO(OB_SPI_Type *pSPI);
uint32_t SPI_SetBusClock(OB_SPI_Type *pSPI, uint32_t BusClock);
uint32_t SPI_GetBusClock(OB_SPI_Type *pSPI);

#define SPI_SIZE_4BIT           (0x03)
#define SPI_SIZE_5BIT           (0x04)
#define SPI_SIZE_6BIT           (0x05)
#define SPI_SIZE_7BIT           (0x06)
#define SPI_SIZE_8BIT           (0x07)
#define SPI_SIZE_9BIT           (0x08)
#define SPI_SIZE_10BIT          (0x09)
#define SPI_SIZE_11BIT          (0x0A)
#define SPI_SIZE_12BIT          (0x0B)
#define SPI_SIZE_13BIT          (0x0C)
#define SPI_SIZE_14BIT          (0x0D)
#define SPI_SIZE_15BIT          (0x0E)
#define SPI_SIZE_16BIT          (0x0F)
#define SPI_SIZE_17BIT          (0x10)
#define SPI_SIZE_18BIT          (0x11)
#define SPI_SIZE_19BIT          (0x12)
#define SPI_SIZE_20BIT          (0x13)
#define SPI_SIZE_21BIT          (0x14)
#define SPI_SIZE_22BIT          (0x15)
#define SPI_SIZE_23BIT          (0x16)
#define SPI_SIZE_24BIT          (0x17)
#define SPI_SIZE_25BIT          (0x18)
#define SPI_SIZE_26BIT          (0x19)
#define SPI_SIZE_27BIT          (0x1A)
#define SPI_SIZE_28BIT          (0x1B)
#define SPI_SIZE_29BIT          (0x1C)
#define SPI_SIZE_30BIT          (0x1D)
#define SPI_SIZE_31BIT          (0x1E)
#define SPI_SIZE_32BIT          (0x1F)

#define SPI_FORMAT_SPI          (0 << 0x04)
#define SPI_FORMAT_TI           (1 << 0x04)
#define SPI_FORMAT_MICROWIRE    (2 << 0x04)

#define SPI_OUT_POLARITY_HI     (0 << 0x06)
#define SPI_OUT_POLARITY_LO     (1 << 0x06)

#define SPI_OUT_PHASE_FIRST     (0 << 0x07)
#define SPI_OUT_PHASE_SECOND    (1 << 0x07)

#define SPI_INT_RORIM       (0x01 << 0x00)
#define SPI_INT_RTIM        (0x01 << 0x01)
#define SPI_INT_RXIM        (0x01 << 0x02)
#define SPI_INT_TXIM        (0x01 << 0x03)

#define SPI_FIRST_MSB        (0x00 << 8)
#define SPI_FIRST_LSB        (0x01 << 8)

#define SPI_RX_SiZE  20

#define SPI_CAPTURE_DELAY_2  (0x02 << 16)

extern volatile uint32_t g_SPIRxCounter;
extern volatile uint32_t g_SPIRxData[SPI_RX_SiZE];
#endif
