mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-09-28 21:17:33 +00:00
Add SPI settings
This commit is contained in:
72
src/spi_settings.cpp
Normal file
72
src/spi_settings.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <sta/spi_settings.hpp>
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/lang.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
SpiClkPolarity getSpiClkPolarity(SpiMode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case SpiMode::MODE_0:
|
||||
case SpiMode::MODE_1:
|
||||
return SpiClkPolarity::LOW;
|
||||
|
||||
case SpiMode::MODE_2:
|
||||
case SpiMode::MODE_3:
|
||||
return SpiClkPolarity::HIGH;
|
||||
|
||||
default:
|
||||
// Unreachable case
|
||||
STA_ASSERT_MSG(false, "Case for SpiMode enum not handled");
|
||||
STA_UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
SpiClkPhase getSpiClkPhase(SpiMode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case SpiMode::MODE_0:
|
||||
case SpiMode::MODE_2:
|
||||
return SpiClkPhase::EDGE_1;
|
||||
|
||||
case SpiMode::MODE_1:
|
||||
case SpiMode::MODE_3:
|
||||
return SpiClkPhase::EDGE_2;
|
||||
|
||||
default:
|
||||
// Unreachable case
|
||||
STA_ASSERT_MSG(false, "Case for SpiMode enum not handled");
|
||||
STA_UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
SpiMode getSpiMode(SpiClkPolarity polarity, SpiClkPhase phase)
|
||||
{
|
||||
if (polarity == SpiClkPolarity::LOW)
|
||||
{
|
||||
if (phase == SpiClkPhase::EDGE_1)
|
||||
{
|
||||
return SpiMode::MODE_0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SpiMode::MODE_1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (phase == SpiClkPhase::EDGE_1)
|
||||
{
|
||||
return SpiMode::MODE_2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SpiMode::MODE_3;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace sta
|
Reference in New Issue
Block a user