Expose spi word size using both software and hardware backends
This commit is contained in:
parent
f359f46ffc
commit
852ad5a318
@ -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)))
|
||||
|
@ -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
17
spi.hpp
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user