#include #include #include 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