mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-12 01:25:59 +00:00
113 lines
1.6 KiB
C++
113 lines
1.6 KiB
C++
/**
|
|
* @brief SPI setting types.
|
|
*/
|
|
#ifndef STA_SPI_SETTINGS_HPP
|
|
#define STA_SPI_SETTINGS_HPP
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
namespace sta
|
|
{
|
|
/**
|
|
* @brief SPI clock polarity.
|
|
*/
|
|
enum class SpiClkPolarity
|
|
{
|
|
LOW,
|
|
HIGH
|
|
};
|
|
|
|
/**
|
|
* @brief SPI clock phase.
|
|
*/
|
|
enum class SpiClkPhase
|
|
{
|
|
EDGE_1,
|
|
EDGE_2
|
|
};
|
|
|
|
/**
|
|
* @brief SPI clock mode.
|
|
*/
|
|
enum class SpiMode
|
|
{
|
|
MODE_0,
|
|
MODE_1,
|
|
MODE_2,
|
|
MODE_3
|
|
};
|
|
|
|
/**
|
|
* @brief SPI data size.
|
|
*/
|
|
enum class SpiDataSize
|
|
{
|
|
SIZE_8,
|
|
SIZE_16
|
|
};
|
|
|
|
/**
|
|
* @brief SPI bit order.
|
|
*/
|
|
enum class SpiBitOrder
|
|
{
|
|
MSB,
|
|
LSB
|
|
};
|
|
|
|
/**
|
|
* @brief Spi baud rate prescaler.
|
|
*/
|
|
enum class SpiBaudRatePrescaler
|
|
{
|
|
DIV_2,
|
|
DIV_4,
|
|
DIV_8,
|
|
DIV_16,
|
|
DIV_32,
|
|
DIV_64,
|
|
DIV_128,
|
|
DIV_256
|
|
};
|
|
|
|
|
|
/**
|
|
* @brief SPI settings.
|
|
*/
|
|
struct SpiSettings
|
|
{
|
|
SpiMode mode; /**< SPI clock mode */
|
|
SpiDataSize dataSize; /**< SPI data size */
|
|
SpiBitOrder bitOrder; /**< SPI bit order */
|
|
uint32_t clkSpeed; /**< SPI clock speed */
|
|
};
|
|
|
|
|
|
/**
|
|
* @brief Get SPI clock polarity from clock mode.
|
|
*
|
|
* @param mode SPI clock mode
|
|
* @return SPI clock polarity
|
|
*/
|
|
SpiClkPolarity getSpiClkPolarity(SpiMode mode);
|
|
/**
|
|
* @brief Get SPI clock phase from clock mode.
|
|
*
|
|
* @param mode SPI clock mode
|
|
* @return SPI clock phase
|
|
*/
|
|
SpiClkPhase getSpiClkPhase(SpiMode mode);
|
|
/**
|
|
* @brief Get SPI clock mode from clock phase and polarity.
|
|
*
|
|
* @param polarity SPI clock polarity
|
|
* @param phase SPI clock phase
|
|
* @return SPI clock mode
|
|
*/
|
|
SpiMode getSpiMode(SpiClkPolarity polarity, SpiClkPhase phase);
|
|
} // namespace sta
|
|
|
|
|
|
#endif // STA_SPI_SETTINGS_HPP
|