Added objects for all SPI pins

This commit is contained in:
BlackMark 2017-09-14 12:06:08 +02:00
parent 32b8e7bb3a
commit 8230df10a1
2 changed files with 27 additions and 11 deletions

31
spi.cpp
View File

@ -1,5 +1,11 @@
#include "spi.h" #include "spi.h"
//////////////////////////////////////////////////////////////////////////
InOutPin SPI::sm_cSCK;
InOutPin SPI::sm_cMISO;
InOutPin SPI::sm_cMOSI;
InOutPin SPI::sm_cSS;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void SPI::setCPOL( bool bCPOL ) 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 */ ) 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 ) if( bMaster )
{ {
InOut::writePin( sm_enmSS, true ); sm_cSS.write( true );
InOut::setPinDirection( sm_enmSCK, InOut::Dir::D_OUT, false ); sm_cSCK.setDirection( InOut::Dir::D_OUT, false );
InOut::setPinDirection( sm_enmMISO, InOut::Dir::D_IN, false ); sm_cMISO.setDirection( InOut::Dir::D_IN, false );
InOut::setPinDirection( sm_enmMOSI, InOut::Dir::D_OUT, false ); sm_cMOSI.setDirection( InOut::Dir::D_OUT, false );
InOut::setPinDirection( sm_enmSS, InOut::Dir::D_OUT, false ); sm_cSS.setDirection( InOut::Dir::D_OUT, false );
} }
else else
{ {
InOut::setPinDirection( sm_enmSCK, InOut::Dir::D_IN, false ); sm_cSCK.setDirection( InOut::Dir::D_IN, false );
InOut::setPinDirection( sm_enmMISO, InOut::Dir::D_OUT, false ); sm_cMISO.setDirection( InOut::Dir::D_OUT, false );
InOut::setPinDirection( sm_enmMOSI, InOut::Dir::D_IN, false ); sm_cMOSI.setDirection( InOut::Dir::D_IN, false );
InOut::setPinDirection( sm_enmSS, InOut::Dir::D_IN, true ); sm_cSS.setDirection( InOut::Dir::D_IN, true );
} }
setClockDiv( enmClockDiv ); setClockDiv( enmClockDiv );
@ -146,5 +157,5 @@ uint8_t SPI::transfer( uint8_t ui8Data )
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void SPI::select( bool bSelect ) void SPI::select( bool bSelect )
{ {
InOut::writePin( sm_enmSS, !bSelect ); sm_cSS.write( !bSelect );
} }

7
spi.h
View File

@ -1,7 +1,7 @@
/* /*
* Copyright (c) by BlackMark 2016-2017 * Copyright (c) by BlackMark 2016-2017
* Date 14/09/2017 * Date 14/09/2017
* Version 1.1 * Version 1.2
*/ */
#ifndef SPI_H #ifndef SPI_H
@ -43,6 +43,11 @@ private:
static constexpr InOut::Pin sm_enmMOSI = InOut::Pin::P_B3; static constexpr InOut::Pin sm_enmMOSI = InOut::Pin::P_B3;
static constexpr InOut::Pin sm_enmSS = InOut::Pin::P_B2; 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: public:
static void init( ClockDiv enmClockDiv = ClockDiv::CLKDIV_128, Mode enmMode = Mode::MODE_0, bool bMaster = true, bool bLSBFirst = false ); static void init( ClockDiv enmClockDiv = ClockDiv::CLKDIV_128, Mode enmMode = Mode::MODE_0, bool bMaster = true, bool bLSBFirst = false );
static void setClockDiv( ClockDiv enmClockDiv ); static void setClockDiv( ClockDiv enmClockDiv );