From 852ad5a3184ef6828e99b439fc078dd7ca83b5df Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sat, 28 May 2022 17:03:40 +0200 Subject: [PATCH] Expose spi word size using both software and hardware backends --- hardware.hpp | 4 +++- software.hpp | 2 +- spi.hpp | 17 ++++++++--------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/hardware.hpp b/hardware.hpp index 8ee6735..c7732b0 100644 --- a/hardware.hpp +++ b/hardware.hpp @@ -9,6 +9,8 @@ namespace spi { template class Hardware { public: + using word_t = uint8_t; + static void init() { if constexpr (Cfg::SIDE == Side::MASTER) { @@ -35,7 +37,7 @@ class Hardware { SPCR |= (1 << SPE); } - static uint8_t transfer(uint8_t data) + static word_t transfer(word_t data) { SPDR = data; while (!(SPSR & (1 << SPIF))) diff --git a/software.hpp b/software.hpp index fb8a3e5..cec67c7 100644 --- a/software.hpp +++ b/software.hpp @@ -24,6 +24,7 @@ class Software { return (delayUs > 0 ? delayUs : 0); } + public: static_assert(Cfg::BITS >= 1 && Cfg::BITS <= 64, "Word size must be in range [1-64]"); // clang-format off using word_t = util::conditional_t>>; // clang-format on - public: static void init() { sm_sck = ((Cfg::MODE == Mode::MODE_0 || Cfg::MODE == Mode::MODE_1) ? false : true); diff --git a/spi.hpp b/spi.hpp index e584567..e1e2122 100644 --- a/spi.hpp +++ b/spi.hpp @@ -9,24 +9,23 @@ namespace spi { template -class Spi { - public: - static void init() +struct Spi { + using word_t = typename Driver::word_t; + + static inline void init() { Driver::init(); } - static uint8_t transfer(uint8_t ui8Data) + static inline word_t transfer(const word_t data) { - return Driver::transfer(ui8Data); + return Driver::transfer(data); } - static void select(bool bSelect) + static inline void select(const bool selectState) { - Driver::select(bSelect); + Driver::select(selectState); } - - private: }; } // namespace spi