diff --git a/spi.hpp b/spi.hpp index f5267ac..d6e5c65 100644 --- a/spi.hpp +++ b/spi.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../inout/inout.h" +#include "../io/io.hpp" #include @@ -26,15 +26,10 @@ class Spi { static void setCPOL(bool bCPOL); static void setCPHA(bool bCPHA); - static constexpr InOut::Pin sm_enmSCK = InOut::Pin::P_B5; - static constexpr InOut::Pin sm_enmMISO = InOut::Pin::P_B4; - static constexpr InOut::Pin sm_enmMOSI = InOut::Pin::P_B3; - static constexpr InOut::Pin sm_enmSS = InOut::Pin::P_B2; - - static InOutPin sm_cSCK; - static InOutPin sm_cMISO; - static InOutPin sm_cMOSI; - static InOutPin sm_cSS; + static io::Pin sm_cSCK; + static io::Pin sm_cMISO; + static io::Pin sm_cMOSI; + static io::Pin sm_cSS; public: static void init(ClockDiv enmClockDiv = ClockDiv::CLKDIV_128, Mode enmMode = Mode::MODE_0, bool bMaster = true, @@ -50,12 +45,6 @@ class Spi { static void select(bool bSelect); }; -////////////////////////////////////////////////////////////////////////// -InOutPin Spi::sm_cSCK; -InOutPin Spi::sm_cMISO; -InOutPin Spi::sm_cMOSI; -InOutPin Spi::sm_cSS; - ////////////////////////////////////////////////////////////////////////// void Spi::setCPOL(bool bCPOL) { @@ -80,23 +69,20 @@ void Spi::setCPHA(bool bCPHA) void Spi::init(ClockDiv enmClockDiv /* = ClockDiv::CLKDIV_128 */, Mode enmMode /* = Mode::MODE_0 */, bool bMaster /* = true */, bool bLSBFirst /* = false */, bool bMISOPullup /* = false */) { - sm_cSCK.setPin(sm_enmSCK); - sm_cMISO.setPin(sm_enmMISO); - sm_cMOSI.setPin(sm_enmMOSI); - sm_cSS.setPin(sm_enmSS); - if (bMaster) { sm_cSS.write(true); - sm_cSCK.setDirection(InOut::Dir::D_OUT, false); - sm_cMISO.setDirection(InOut::Dir::D_IN, bMISOPullup); - sm_cMOSI.setDirection(InOut::Dir::D_OUT, false); - sm_cSS.setDirection(InOut::Dir::D_OUT, false); + sm_cSCK.dir(io::Dir::OUT); + sm_cMISO.dir(io::Dir::IN); + sm_cMISO.pullup(bMISOPullup); + sm_cMOSI.dir(io::Dir::OUT); + sm_cSS.dir(io::Dir::OUT); } else { - sm_cSCK.setDirection(InOut::Dir::D_IN, false); - sm_cMISO.setDirection(InOut::Dir::D_OUT, false); - sm_cMOSI.setDirection(InOut::Dir::D_IN, false); - sm_cSS.setDirection(InOut::Dir::D_IN, true); + sm_cSCK.dir(io::Dir::IN); + sm_cMISO.dir(io::Dir::OUT); + sm_cMOSI.dir(io::Dir::IN); + sm_cSS.dir(io::Dir::IN); + sm_cSS.pullup(true); } setClockDiv(enmClockDiv); @@ -112,10 +98,10 @@ void Spi::deinit() { SPCR = 0; - sm_cSCK.setDirection(InOut::Dir::D_IN, false); - sm_cMISO.setDirection(InOut::Dir::D_IN, false); - sm_cMOSI.setDirection(InOut::Dir::D_IN, false); - sm_cSS.setDirection(InOut::Dir::D_IN, false); + sm_cSCK.dir(io::Dir::IN); + sm_cMISO.dir(io::Dir::IN); + sm_cMOSI.dir(io::Dir::IN); + sm_cSS.dir(io::Dir::IN); } //////////////////////////////////////////////////////////////////////////