Completely separted driver from interface

This commit is contained in:
BlackMark 2020-02-21 17:29:45 +01:00
parent c73d83dff4
commit 4b644b22bf
2 changed files with 15 additions and 9 deletions

View File

@ -33,6 +33,19 @@ class Hardware {
SPCR |= (1 << SPE); SPCR |= (1 << SPE);
} }
static uint8_t transfer(uint8_t data)
{
SPDR = data;
while (!(SPSR & (1 << SPIF)))
;
return SPDR;
}
static void select(bool selectState)
{
sm_ss = !selectState;
}
private: private:
static io::Pin<io::P::B5> sm_sck; static io::Pin<io::P::B5> sm_sck;
static io::Pin<io::P::B4> sm_miso; static io::Pin<io::P::B4> sm_miso;

11
spi.hpp
View File

@ -17,22 +17,15 @@ class Spi {
static uint8_t transfer(uint8_t ui8Data) static uint8_t transfer(uint8_t ui8Data)
{ {
SPDR = ui8Data; return Driver::transfer(ui8Data);
while (!(SPSR & (1 << SPIF)))
;
return SPDR;
} }
static void select(bool bSelect) static void select(bool bSelect)
{ {
sm_cSS.write(!bSelect); Driver::select(bSelect);
} }
private: 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 } // namespace spi