mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-12 01:25:59 +00:00
115 lines
2.2 KiB
C++
115 lines
2.2 KiB
C++
/**
|
|
* @file
|
|
* @brief SPI settings.
|
|
*/
|
|
#ifndef STA_CORE_SPI_SETTINGS_HPP
|
|
#define STA_CORE_SPI_SETTINGS_HPP
|
|
|
|
/**
|
|
* @defgroup staCoreSPI SPI
|
|
* @ingroup staCore
|
|
* @brief SPI interface.
|
|
*/
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
namespace sta
|
|
{
|
|
/**
|
|
* @ingroup staCoreSPI
|
|
* @{
|
|
*/
|
|
|
|
|
|
/**
|
|
* @brief SPI clock polarity.
|
|
*/
|
|
enum class SpiClkPolarity
|
|
{
|
|
LOW, /**< Low idle clock */
|
|
HIGH /**< High idle clock */
|
|
};
|
|
|
|
/**
|
|
* @brief SPI clock phase.
|
|
*/
|
|
enum class SpiClkPhase
|
|
{
|
|
EDGE_1, /**< Sample on first edge, shift out on second edge */
|
|
EDGE_2 /**< Shift out on first edge, sample on second edge */
|
|
};
|
|
|
|
/**
|
|
* @brief SPI clock mode.
|
|
*/
|
|
enum class SpiMode
|
|
{
|
|
MODE_0, /**< Low idle clock, sample on rising edge, shift out on falling edge */
|
|
MODE_1, /**< Low idle clock, sample on falling edge, shift out on rising edge */
|
|
MODE_2, /**< High idle clock, sample on rising edge, shift out on falling edge */
|
|
MODE_3 /**< High idle clock, sample on falling edge, shift out on rising edge */
|
|
};
|
|
|
|
/**
|
|
* @brief SPI data size.
|
|
*/
|
|
enum class SpiDataSize
|
|
{
|
|
SIZE_8, /**< 8-bit data size */
|
|
SIZE_16 /**< 16-bit data size */
|
|
};
|
|
|
|
/**
|
|
* @brief SPI bit order.
|
|
*/
|
|
enum class SpiBitOrder
|
|
{
|
|
MSB, /**< Send most significant bit first */
|
|
LSB /**< Send least significant bit first */
|
|
};
|
|
|
|
|
|
/**
|
|
* @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_CORE_SPI_SETTINGS_HPP
|