39 lines
559 B
C++
39 lines
559 B
C++
#pragma once
|
|
|
|
#include "config.hpp"
|
|
#include "hardware.hpp"
|
|
|
|
#include "../io/io.hpp"
|
|
|
|
namespace spi {
|
|
|
|
template <class Driver>
|
|
class Spi {
|
|
public:
|
|
static void init()
|
|
{
|
|
Driver::init();
|
|
}
|
|
|
|
static uint8_t transfer(uint8_t ui8Data)
|
|
{
|
|
SPDR = ui8Data;
|
|
while (!(SPSR & (1 << SPIF)))
|
|
;
|
|
return SPDR;
|
|
}
|
|
|
|
static void select(bool bSelect)
|
|
{
|
|
sm_cSS.write(!bSelect);
|
|
}
|
|
|
|
private:
|
|
static io::Pin<io::P::B5> sm_cSCK;
|
|
static io::Pin<io::P::B4> sm_cMISO;
|
|
static io::Pin<io::P::B3> sm_cMOSI;
|
|
static io::Pin<io::P::B2> sm_cSS;
|
|
};
|
|
|
|
} // namespace spi
|