|
|
|
@ -25,16 +25,31 @@ extern "C" {
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include "hardwareDescription.h"
|
|
|
|
|
|
|
|
|
|
typedef enum{
|
|
|
|
|
SPI_SLAVE,
|
|
|
|
|
SPI_MASTER
|
|
|
|
|
} spi_mode_t;
|
|
|
|
|
|
|
|
|
|
typedef enum{
|
|
|
|
|
NONINVERTED,
|
|
|
|
|
INVERTED
|
|
|
|
|
}spi_clkPol_t;
|
|
|
|
|
|
|
|
|
|
typedef enum{
|
|
|
|
|
CAPTURE_ON_FIRST_CLK_TRANSITION,
|
|
|
|
|
CAPTURE_ON_SECCOND_CLK_TRANSITION
|
|
|
|
|
} spi_phase_t;
|
|
|
|
|
|
|
|
|
|
typedef enum{
|
|
|
|
|
MSB_FIRST,
|
|
|
|
|
LSB_FIRST
|
|
|
|
|
}spi_framef_t;
|
|
|
|
|
|
|
|
|
|
typedef enum{
|
|
|
|
|
SPI_DOUPLEX,
|
|
|
|
|
SPI_SIMPLEX
|
|
|
|
|
}spi_comMode_t;
|
|
|
|
|
|
|
|
|
|
/*! \brief SPI cannel class
|
|
|
|
|
* This class cpntains the pin and spi channel number
|
|
|
|
|
* select.
|
|
|
|
@ -50,6 +65,19 @@ typedef uint8_t (*readReg_t) (uint8_t);
|
|
|
|
|
|
|
|
|
|
// generic code
|
|
|
|
|
|
|
|
|
|
/** TODO: setup init with all attributes
|
|
|
|
|
* TODO: setup auto pin set alternate function
|
|
|
|
|
* @brief This is the spi hardware channel class
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
*/
|
|
|
|
|
void spiInit(spiCH_t spi_ch,
|
|
|
|
|
spi_mode_t mode,
|
|
|
|
|
spi_clkPol_t clockPolarity,
|
|
|
|
|
spi_phase_t phase,
|
|
|
|
|
spi_framef_t frameFormat,
|
|
|
|
|
uint32_t prescaler);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Set up SPI channel
|
|
|
|
|
* Set up a SPI channel by passig a hardware SPI channel and a chipselect pin.
|
|
|
|
@ -157,43 +185,82 @@ void spiWrite32bit(spi_ch_t *spi_ch,
|
|
|
|
|
uint32_t spiReadWrite32bit(spi_ch_t *spi_ch,
|
|
|
|
|
uint8_t bits);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//implementation
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief This is the spi hardware channel class
|
|
|
|
|
* @brief SPI hardware peripheral reset
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
*/
|
|
|
|
|
void spiInit(spiCH_t spi_hw_ch);
|
|
|
|
|
void spiReset(spiCH_t spi_hw_ch);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief SPI hardware peripheral reset
|
|
|
|
|
* @brief Enable Bus for SPI
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
*/
|
|
|
|
|
void spiReset(spiCH_t spi_hw_ch);
|
|
|
|
|
void spiEnableBus(spiCH_t spi_hw_ch);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Enable spi hardware channel
|
|
|
|
|
* @brief Enable SPI hardware channel
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
*/
|
|
|
|
|
void spiEnable(spiCH_t spi_hw_ch);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief set SPI clock polarity
|
|
|
|
|
* @brief Dissable SPI hardware channel
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @breif Get SPI polarity
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @return polarity
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Get SPI clock phase
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @return phase
|
|
|
|
|
*/
|
|
|
|
|
spi_phase_t spiGetPhase(spiCH_t spi_hw_ch);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set SPI frame format
|
|
|
|
|
* @param spi_hw_ch SPI hardware cannel
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @param framef Frame format
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set Clock Prescaler
|
|
|
|
|
* This is dependent on your target device. Please enter in the correct value.
|
|
|
|
@ -203,6 +270,21 @@ void spiSetFrameFormat(spiCH_t spi_hw_ch, spi_framef_t framef);
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Get Clock Prescaler
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|
* @return prescaler
|
|
|
|
|
*/
|
|
|
|
|
uint32_t spiGetClockPrescaler(spiCH_t spi_hw_ch);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Transmits and receives on byte of data
|
|
|
|
|
* @param spi_hw_ch SPI hardware channel
|
|
|
|
|