diff --git a/spi.cpp b/spi.cpp index ddc0e47..ebe0d9d 100644 --- a/spi.cpp +++ b/spi.cpp @@ -1,5 +1,11 @@ #include "spi.h" +////////////////////////////////////////////////////////////////////////// +InOutPin SPI::sm_cSCK; +InOutPin SPI::sm_cMISO; +InOutPin SPI::sm_cMOSI; +InOutPin SPI::sm_cSS; + ////////////////////////////////////////////////////////////////////////// void SPI::setCPOL( bool bCPOL ) { @@ -29,21 +35,26 @@ void SPI::setCPHA( bool bCPHA ) ////////////////////////////////////////////////////////////////////////// void SPI::init( ClockDiv enmClockDiv /* = ClockDiv::CLKDIV_128 */, Mode enmMode /* = Mode::MODE_0 */, bool bMaster /* = true */, bool bLSBFirst /* = false */ ) { + sm_cSCK.setPin( sm_enmSCK ); + sm_cMISO.setPin( sm_enmMISO ); + sm_cMOSI.setPin( sm_enmMOSI ); + sm_cSS.setPin( sm_enmSS ); + if( bMaster ) { - InOut::writePin( sm_enmSS, true ); + sm_cSS.write( true ); - InOut::setPinDirection( sm_enmSCK, InOut::Dir::D_OUT, false ); - InOut::setPinDirection( sm_enmMISO, InOut::Dir::D_IN, false ); - InOut::setPinDirection( sm_enmMOSI, InOut::Dir::D_OUT, false ); - InOut::setPinDirection( sm_enmSS, InOut::Dir::D_OUT, false ); + sm_cSCK.setDirection( InOut::Dir::D_OUT, false ); + sm_cMISO.setDirection( InOut::Dir::D_IN, false ); + sm_cMOSI.setDirection( InOut::Dir::D_OUT, false ); + sm_cSS.setDirection( InOut::Dir::D_OUT, false ); } else { - InOut::setPinDirection( sm_enmSCK, InOut::Dir::D_IN, false ); - InOut::setPinDirection( sm_enmMISO, InOut::Dir::D_OUT, false ); - InOut::setPinDirection( sm_enmMOSI, InOut::Dir::D_IN, false ); - InOut::setPinDirection( sm_enmSS, InOut::Dir::D_IN, true ); + 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 ); } setClockDiv( enmClockDiv ); @@ -146,5 +157,5 @@ uint8_t SPI::transfer( uint8_t ui8Data ) ////////////////////////////////////////////////////////////////////////// void SPI::select( bool bSelect ) { - InOut::writePin( sm_enmSS, !bSelect ); + sm_cSS.write( !bSelect ); } \ No newline at end of file diff --git a/spi.h b/spi.h index 5bcff36..7e902af 100644 --- a/spi.h +++ b/spi.h @@ -1,7 +1,7 @@ /* * Copyright (c) by BlackMark 2016-2017 * Date 14/09/2017 -* Version 1.1 +* Version 1.2 */ #ifndef SPI_H @@ -43,6 +43,11 @@ private: 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; + public: static void init( ClockDiv enmClockDiv = ClockDiv::CLKDIV_128, Mode enmMode = Mode::MODE_0, bool bMaster = true, bool bLSBFirst = false ); static void setClockDiv( ClockDiv enmClockDiv );