|
|
|
@ -35,18 +35,18 @@ typedef enum{
|
|
|
|
|
} spi_mode_t;
|
|
|
|
|
|
|
|
|
|
typedef enum{
|
|
|
|
|
NONINVERTED,
|
|
|
|
|
INVERTED
|
|
|
|
|
SPI_NONINVERTED,
|
|
|
|
|
SPI_INVERTED
|
|
|
|
|
}spi_clkPol_t;
|
|
|
|
|
|
|
|
|
|
typedef enum{
|
|
|
|
|
CAPTURE_ON_FIRST_CLK_TRANSITION,
|
|
|
|
|
CAPTURE_ON_SECCOND_CLK_TRANSITION
|
|
|
|
|
SPI_CAPTURE_ON_FIRST_CLK_TRANSITION,
|
|
|
|
|
SPI_CAPTURE_ON_SECCOND_CLK_TRANSITION
|
|
|
|
|
} spi_phase_t;
|
|
|
|
|
|
|
|
|
|
typedef enum{
|
|
|
|
|
MSB_FIRST,
|
|
|
|
|
LSB_FIRST
|
|
|
|
|
SPI_MSB_FIRST,
|
|
|
|
|
SPI_LSB_FIRST
|
|
|
|
|
}spi_framef_t;
|
|
|
|
|
|
|
|
|
|
typedef enum{
|
|
|
|
@ -61,8 +61,6 @@ typedef enum{
|
|
|
|
|
typedef struct{
|
|
|
|
|
pinNo_t pin; /*!< pin number */
|
|
|
|
|
spiCH_t spi; /*!< spi hardware channel number */
|
|
|
|
|
spi_framef_t format; /*!< spi format */
|
|
|
|
|
spi_clkPol_t clkPol; /*!< spi clock polarity*/
|
|
|
|
|
}spi_ch_t;
|
|
|
|
|
|
|
|
|
|
typedef uint8_t (*readReg_t) (uint8_t);
|
|
|
|
@ -74,11 +72,13 @@ typedef uint8_t (*readReg_t) (uint8_t);
|
|
|
|
|
* @brief This is the spi hardware channel class
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
*/
|
|
|
|
|
void spiInitMaster(spiCH_t spi_hw_ch,
|
|
|
|
|
spi_clkPol_t clockPolarity,
|
|
|
|
|
spi_phase_t phase,
|
|
|
|
|
spi_framef_t frameFormat,
|
|
|
|
|
uint32_t prescaler);
|
|
|
|
|
void spiInitMaster(
|
|
|
|
|
spiCH_t spi_hw_ch,
|
|
|
|
|
spi_clkPol_t clockPolarity,
|
|
|
|
|
spi_phase_t phase,
|
|
|
|
|
spi_framef_t frameFormat,
|
|
|
|
|
spi_comMode_t comMode,
|
|
|
|
|
uint32_t prescaler);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -89,7 +89,10 @@ void spiInitMaster(spiCH_t spi_hw_ch,
|
|
|
|
|
* \param spi_hw_ch SPI hardware channel
|
|
|
|
|
* \param chipslectPin designated pin for chipslect
|
|
|
|
|
*/
|
|
|
|
|
void spiSetupCH(spi_ch_t *ch, spiCH_t spi_hw_ch, pinNo_t chipselectPin);
|
|
|
|
|
void spiSetupCH(
|
|
|
|
|
spi_ch_t *ch,
|
|
|
|
|
spiCH_t spi_hw_ch,
|
|
|
|
|
pinNo_t chipselectPin);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Read register
|
|
|
|
@ -98,8 +101,9 @@ void spiSetupCH(spi_ch_t *ch, spiCH_t spi_hw_ch, pinNo_t chipselectPin);
|
|
|
|
|
* \param reg_address register address
|
|
|
|
|
* \return register content
|
|
|
|
|
*/
|
|
|
|
|
uint8_t spiReadReg(spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t reg_address);
|
|
|
|
|
uint8_t spiReadReg(
|
|
|
|
|
spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t reg_address);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Read Block
|
|
|
|
@ -111,10 +115,11 @@ uint8_t spiReadReg(spi_ch_t *spi_ch,
|
|
|
|
|
* \param *buffer pointer to the buffer in which the read content is written into
|
|
|
|
|
* \param buf_len length of buffer
|
|
|
|
|
*/
|
|
|
|
|
void spiAutoReadBlock(spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t start_address,
|
|
|
|
|
uint8_t* buffer,
|
|
|
|
|
uint8_t buf_len);
|
|
|
|
|
void spiAutoReadBlock(
|
|
|
|
|
spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t start_address,
|
|
|
|
|
uint8_t* buffer,
|
|
|
|
|
uint8_t buf_len);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Write register
|
|
|
|
@ -124,9 +129,10 @@ void spiAutoReadBlock(spi_ch_t *spi_ch,
|
|
|
|
|
* \param data data byte to be written into register
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void spiWriteReg(spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t reg_address,
|
|
|
|
|
uint8_t data);
|
|
|
|
|
void spiWriteReg(
|
|
|
|
|
spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t reg_address,
|
|
|
|
|
uint8_t data);
|
|
|
|
|
/**
|
|
|
|
|
* \brief Write data block
|
|
|
|
|
* Write a block of data starting at a given start address.
|
|
|
|
@ -137,56 +143,63 @@ void spiWriteReg(spi_ch_t *spi_ch,
|
|
|
|
|
* \param *data pointer to data to be written
|
|
|
|
|
* \param data_len length of data to be written
|
|
|
|
|
*/
|
|
|
|
|
void spiWriteBlock(spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t start_address,
|
|
|
|
|
const uint8_t *data,
|
|
|
|
|
uint8_t data_len);
|
|
|
|
|
void spiWriteBlock(
|
|
|
|
|
spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t start_address,
|
|
|
|
|
const uint8_t *data,
|
|
|
|
|
uint8_t data_len);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief write 8 bits
|
|
|
|
|
* \param bits 8 bits
|
|
|
|
|
*/
|
|
|
|
|
void spiWrite8bit(spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t bits);
|
|
|
|
|
void spiWrite8bit(
|
|
|
|
|
spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t bits);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief read and write simultainously 8 bits
|
|
|
|
|
* \param bits 8 bits
|
|
|
|
|
* \return 8 bits
|
|
|
|
|
*/
|
|
|
|
|
uint8_t spiReadWrite8bit(spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t bits);
|
|
|
|
|
uint8_t spiReadWrite8bit(
|
|
|
|
|
spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t bits);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief write 16 bits
|
|
|
|
|
* \param bits 16 bits
|
|
|
|
|
*/
|
|
|
|
|
void spiWrite16bit(spi_ch_t *spi_ch,
|
|
|
|
|
uint16_t bits);
|
|
|
|
|
void spiWrite16bit(
|
|
|
|
|
spi_ch_t *spi_ch,
|
|
|
|
|
uint16_t bits);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief read and write simultainously 16 bits
|
|
|
|
|
* \param bits 16 bits
|
|
|
|
|
* \return 16 bits
|
|
|
|
|
*/
|
|
|
|
|
uint16_t spiReadWrite16bit(spi_ch_t *spi_ch,
|
|
|
|
|
uint16_t bits);
|
|
|
|
|
uint16_t spiReadWrite16bit(
|
|
|
|
|
spi_ch_t *spi_ch,
|
|
|
|
|
uint16_t bits);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief write 32 bits
|
|
|
|
|
* \param bits 32 bits
|
|
|
|
|
*/
|
|
|
|
|
void spiWrite32bit(spi_ch_t *spi_ch,
|
|
|
|
|
uint32_t bits);
|
|
|
|
|
void spiWrite32bit(
|
|
|
|
|
spi_ch_t *spi_ch,
|
|
|
|
|
uint32_t bits);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief read and write simultainously 32 bits
|
|
|
|
|
* \param bits 32 bits
|
|
|
|
|
* \return 32 bits
|
|
|
|
|
*/
|
|
|
|
|
uint32_t spiReadWrite32bit(spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t bits);
|
|
|
|
|
uint32_t spiReadWrite32bit(
|
|
|
|
|
spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t bits);
|
|
|
|
|
|
|
|
|
|
//implementation
|
|
|
|
|
|
|
|
|
@ -194,60 +207,72 @@ uint32_t spiReadWrite32bit(spi_ch_t *spi_ch,
|
|
|
|
|
* @brief SPI hardware peripheral reset
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
*/
|
|
|
|
|
void spiReset(spiCH_t spi_hw_ch);
|
|
|
|
|
void spiReset(
|
|
|
|
|
spiCH_t spi_hw_ch);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Enable Bus for SPI
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
*/
|
|
|
|
|
void spiEnableBus(spiCH_t spi_hw_ch);
|
|
|
|
|
void spiEnableBus(
|
|
|
|
|
spiCH_t spi_hw_ch);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Enable SPI hardware channel
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
*/
|
|
|
|
|
void spiEnable(spiCH_t spi_hw_ch);
|
|
|
|
|
void spiEnable(
|
|
|
|
|
spiCH_t spi_hw_ch);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Dissable SPI hardware channel
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
*/
|
|
|
|
|
void spiDissable(spiCH_t spi_hw_ch);
|
|
|
|
|
void spiDissable(
|
|
|
|
|
spiCH_t spi_hw_ch);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set SPI operation mode (MASTER or SLAVE)
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @param mode
|
|
|
|
|
*/
|
|
|
|
|
void spiSetMode(spiCH_t spi_hw_ch, spi_mode_t mode);
|
|
|
|
|
void spiSetMode(
|
|
|
|
|
spiCH_t spi_hw_ch,
|
|
|
|
|
spi_mode_t mode);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set SPI clock polarity
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @param clkPol Clock polarity
|
|
|
|
|
*/
|
|
|
|
|
void spiSetPolarity(spiCH_t spi_hw_ch, spi_clkPol_t clkPol);
|
|
|
|
|
void spiSetPolarity(
|
|
|
|
|
spiCH_t spi_hw_ch,
|
|
|
|
|
spi_clkPol_t clkPol);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @breif Get SPI polarity
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @return polarity
|
|
|
|
|
*/
|
|
|
|
|
spi_clkPol_t spiGetPolarity(spiCH_t spi_hw_ch);
|
|
|
|
|
spi_clkPol_t spiGetPolarity(
|
|
|
|
|
spiCH_t spi_hw_ch);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set SPI clock phase
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @param phase
|
|
|
|
|
*/
|
|
|
|
|
void spiSetPhase(spiCH_t spi_hw_ch, spi_phase_t phase);
|
|
|
|
|
void spiSetPhase(
|
|
|
|
|
spiCH_t spi_hw_ch,
|
|
|
|
|
spi_phase_t phase);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Get SPI clock phase
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @return phase
|
|
|
|
|
*/
|
|
|
|
|
spi_phase_t spiGetPhase(spiCH_t spi_hw_ch);
|
|
|
|
|
spi_phase_t spiGetPhase(
|
|
|
|
|
spiCH_t spi_hw_ch);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -255,14 +280,17 @@ spi_phase_t spiGetPhase(spiCH_t spi_hw_ch);
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @param framef Frame format
|
|
|
|
|
*/
|
|
|
|
|
void spiSetFrameFormat(spiCH_t spi_hw_ch, spi_framef_t framef);
|
|
|
|
|
void spiSetFrameFormat(
|
|
|
|
|
spiCH_t spi_hw_ch,
|
|
|
|
|
spi_framef_t framef);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Get SPI frame format
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @return Frame format
|
|
|
|
|
*/
|
|
|
|
|
spi_framef_t spiGetFrameFormat(spiCH_t spi_hw_ch);
|
|
|
|
|
spi_framef_t spiGetFrameFormat(
|
|
|
|
|
spiCH_t spi_hw_ch);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set Clock Prescaler
|
|
|
|
@ -271,21 +299,26 @@ spi_framef_t spiGetFrameFormat(spiCH_t spi_hw_ch);
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @param clkDiv
|
|
|
|
|
*/
|
|
|
|
|
void spiSetClockPrescaler(spiCH_t spi_hw_ch,uint32_t clkDiv);
|
|
|
|
|
void spiSetClockPrescaler(
|
|
|
|
|
spiCH_t spi_hw_ch,
|
|
|
|
|
uint32_t clkDiv);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set communication Mode
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @param comMode
|
|
|
|
|
*/
|
|
|
|
|
void spiSetComMode(spiCH_t spi_hw_ch, spi_comMode_t comMode);
|
|
|
|
|
void spiSetComMode(
|
|
|
|
|
spiCH_t spi_hw_ch,
|
|
|
|
|
spi_comMode_t comMode);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Get Clock Prescaler
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @return prescaler
|
|
|
|
|
*/
|
|
|
|
|
uint32_t spiGetClockPrescaler(spiCH_t spi_hw_ch);
|
|
|
|
|
uint32_t spiGetClockPrescaler(
|
|
|
|
|
spiCH_t spi_hw_ch);
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
/**
|
|
|
|
@ -298,9 +331,11 @@ void spiSetSoftwareSlaveManagement(spiCH_t spi_hw_ch, uint8_t logic);
|
|
|
|
|
/**
|
|
|
|
|
* @brief Enable software slave management
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @param logic Slave management done by software... 1 = enables / 0 = dissabledi
|
|
|
|
|
* @param logic Slave management done by software... 1 = enables / 0 = dissabled
|
|
|
|
|
*/
|
|
|
|
|
void spiSetSoftwareSlaveManagement(spiCH_t spi_hw_ch, uint8_t logic);
|
|
|
|
|
void spiSetSoftwareSlaveManagement(
|
|
|
|
|
spiCH_t spi_hw_ch,
|
|
|
|
|
uint8_t logic);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -308,7 +343,9 @@ void spiSetSoftwareSlaveManagement(spiCH_t spi_hw_ch, uint8_t logic);
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @param logic 1 = enable / 0 = dissable
|
|
|
|
|
*/
|
|
|
|
|
void spiSetInternalSlaveSelect(spiCH_tspi_hw_ch, uint8_t logic);
|
|
|
|
|
void spiSetInternalSlaveSelect(
|
|
|
|
|
spiCH_t spi_hw_ch,
|
|
|
|
|
uint8_t logic);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Transmits and receives on byte of data
|
|
|
|
@ -316,7 +353,9 @@ void spiSetInternalSlaveSelect(spiCH_tspi_hw_ch, uint8_t logic);
|
|
|
|
|
* @param tx_data 'tx_data' The byte to be transmitted"
|
|
|
|
|
* @return The received data
|
|
|
|
|
*/
|
|
|
|
|
uint8_t spiTrx(spiCH_t spi_hw_ch, uint8_t tx_data);
|
|
|
|
|
uint8_t spiTrx(
|
|
|
|
|
spiCH_t spi_hw_ch,
|
|
|
|
|
uint8_t tx_data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|