spi/spi.hpp

39 lines
559 B
C++
Raw Normal View History

2020-02-21 16:48:31 +01:00
#pragma once
2020-02-21 16:47:47 +01:00
2020-02-21 17:10:49 +01:00
#include "config.hpp"
#include "hardware.hpp"
2020-02-21 16:49:22 +01:00
2020-02-21 17:10:49 +01:00
#include "../io/io.hpp"
2020-02-21 16:47:47 +01:00
2020-02-21 16:49:22 +01:00
namespace spi {
2020-02-21 17:10:49 +01:00
template <class Driver>
2020-02-21 16:49:22 +01:00
class Spi {
2020-02-21 16:47:47 +01:00
public:
2020-02-21 17:26:14 +01:00
static void init()
{
2020-02-21 17:26:14 +01:00
Driver::init();
2020-02-21 16:47:47 +01:00
}
static uint8_t transfer(uint8_t ui8Data)
{
SPDR = ui8Data;
while (!(SPSR & (1 << SPIF)))
;
return SPDR;
2020-02-21 16:47:47 +01:00
}
static void select(bool bSelect)
{
sm_cSS.write(!bSelect);
2020-02-21 16:47:47 +01:00
}
2020-02-21 17:26:14 +01:00
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;
};
2020-02-21 16:49:22 +01:00
} // namespace spi