#pragma once #include "config.hpp" #include "hardware.hpp" #include "../io/io.hpp" namespace spi { template class Spi { public: static void init() { Driver::init(); } static void deinit() { SPCR = 0; sm_cSCK.dir(io::Dir::IN); sm_cMISO.dir(io::Dir::IN); sm_cMOSI.dir(io::Dir::IN); sm_cSS.dir(io::Dir::IN); } 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 sm_cSCK; static io::Pin sm_cMISO; static io::Pin sm_cMOSI; static io::Pin sm_cSS; }; } // namespace spi