Expose spi word size using both software and hardware backends

This commit is contained in:
BlackMark 2022-05-28 17:03:40 +02:00
parent f359f46ffc
commit 852ad5a318
3 changed files with 12 additions and 11 deletions

View File

@ -9,6 +9,8 @@ namespace spi {
template <class Cfg>
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)))

View File

@ -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<Cfg::BITS <= 8, uint8_t,
@ -32,7 +33,6 @@ class Software {
uint64_t>>>;
// clang-format on
public:
static void init()
{
sm_sck = ((Cfg::MODE == Mode::MODE_0 || Cfg::MODE == Mode::MODE_1) ? false : true);

17
spi.hpp
View File

@ -9,24 +9,23 @@
namespace spi {
template <class Driver>
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