22 #ifndef __utl_com_spi_bb_h__ 23 #define __utl_com_spi_bb_h__ 52 template <
typename impl_t,
70 :
nsec_ {1000000000/(2*clk)} {
77 template <spi::bitOrder B =BitOrder> constexpr
79 template <spi::bitOrder B =BitOrder> constexpr
81 template <spi::cpol C =CPOL>
static constexpr
bool clkHigh () {
82 return !
static_cast<bool>(C);
84 template <spi::cpol C =CPOL>
static constexpr
bool clkLow () {
85 return static_cast<bool>(C);
99 void MOSI (
bool st) { impl().MOSI(st); }
100 bool MISO () {
return impl().MISO(); }
101 void SCLK (
bool st) { impl().SCLK (st); }
102 void delay (uint32_t nsec) { impl().delay (nsec); }
115 template <spi::cpha C =CPHA>
117 template <spi::cpha C =CPHA>
135 template <
typename impl_t, spi::cpol CPOL, spi::cpha CPHA, spi::bitOrder BitOrder>
136 template <spi::cpha C>
141 for (uint8_t bit {
static_cast<uint8_t
>(BitOrder)} ; bit ; shift (bit)) {
145 in |= (MISO ()) ? bit : 0;
159 template <
typename impl_t, spi::cpol CPOL, spi::cpha CPHA, spi::bitOrder BitOrder>
160 template <spi::cpha C>
165 for (uint8_t bit {
static_cast<uint8_t
>(BitOrder)} ; bit ; shift (bit)) {
171 in |= (MISO ()) ? bit : 0;
202 :
nsec_ {1000000000/(2*clk)} {
209 template <spi::bitOrder B =BitOrder> constexpr
211 template <spi::bitOrder B =BitOrder> constexpr
213 template <spi::cpol C =CPOL>
static constexpr
bool clkHigh () {
214 return !
static_cast<bool>(C);
216 template <spi::cpol C =CPOL>
static constexpr
bool clkLow () {
217 return static_cast<bool>(C);
227 virtual void MOSI (
bool) =0;
228 virtual bool MISO () =0;
229 virtual void SCLK (
bool) =0;
230 virtual void delay (uint32_t) =0;
243 template <spi::cpha C =CPHA>
245 template <spi::cpha C =CPHA>
263 template <spi::cpol CPOL, spi::cpha CPHA, spi::bitOrder BitOrder>
264 template <spi::cpha C>
269 for (uint8_t bit {
static_cast<uint8_t
>(BitOrder)} ; bit ;
shift (bit)) {
273 in |= (
MISO ()) ? bit : 0;
287 template <spi::cpol CPOL, spi::cpha CPHA, spi::bitOrder BitOrder>
288 template <spi::cpha C>
293 for (uint8_t bit {
static_cast<uint8_t
>(BitOrder)} ; bit ;
shift (bit)) {
299 in |= (
MISO ()) ? bit : 0;
306 #endif //#ifndef __spi_bb_h__ bool MISO()
Implementers's MISO pin function.
static constexpr bool clkLow()
static constexpr bool clkHigh()
meta::enable_if_t<(C==spi::cpha::LOW), byte_t > _tx_data_impl(byte_t out)
_tx_data implementation for CPHA == LOW Out at preceding clock trailing edge, In at leading clock edg...
static constexpr bool clkLow()
void delay(uint32_t nsec)
An Abstract base class interface for the spi bus.
A virtual base class implementation.
constexpr meta::enable_if_t<(B==spi::bitOrder::LSB_First), void > shift(byte_t &b)
static constexpr bool clkL_
STL's core language concepts.
constexpr meta::enable_if_t<(B==spi::bitOrder::MSB_First), void > shift(byte_t &b)
A bit banking implementation of spi bus inherited from spi_i base class.
spi_bb_i(uint32_t clk) noexcept
A default constructor.
A virtual base class interface specialization. Using the private virtual interface we provide the int...
static constexpr bool clkHigh()
static constexpr bool clkH_
void SCLK(bool st)
Implementers's SCLK pin function.
uint8_t byte_t
8 bits wide
byte_t _tx_data(byte_t out) final
void _clock(uint32_t c) final
Set the clock frequency of the bus.
void MOSI(bool st)
Implementers's MOSI pin function.
constexpr meta::enable_if_t<(B==spi::bitOrder::LSB_First), void > shift(byte_t &b)
constexpr meta::enable_if_t<(B==spi::bitOrder::MSB_First), void > shift(byte_t &b)
Implementation detail main forward header.
byte_t _tx_data(byte_t out)
uint32_t _clock() const final
Read the clock frequency of the bus.