64 lines
1.3 KiB
C++
64 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) by BlackMark 2016-2017
|
|
* Date 15/09/2017
|
|
* Version 1.3
|
|
*/
|
|
|
|
#ifndef SPI_H
|
|
#define SPI_H
|
|
|
|
#include <avr/io.h>
|
|
#include "../inout/inout.h"
|
|
|
|
class SPI
|
|
{
|
|
public:
|
|
enum class ClockDiv
|
|
{
|
|
CLKDIV_4 = 0,
|
|
CLKDIV_16 = 1,
|
|
CLKDIV_64 = 2,
|
|
CLKDIV_128 = 3,
|
|
|
|
CLKDIV_2X_2 = 4,
|
|
CLKDIV_2X_8 = 5,
|
|
CLKDIV_2X_32 = 6,
|
|
CLKDIV_2X_64 = 7
|
|
};
|
|
|
|
enum class Mode
|
|
{
|
|
MODE_0 = 0,
|
|
MODE_1 = 1,
|
|
MODE_2 = 2,
|
|
MODE_3 = 3
|
|
};
|
|
|
|
private:
|
|
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;
|
|
|
|
public:
|
|
static void init( ClockDiv enmClockDiv = ClockDiv::CLKDIV_128, Mode enmMode = Mode::MODE_0, bool bMaster = true, bool bLSBFirst = false );
|
|
static void deinit();
|
|
static void setClockDiv( ClockDiv enmClockDiv );
|
|
static void setMode( Mode enmMode );
|
|
static void setMaster( bool bMaster );
|
|
static void setBitOrder( bool bLSBFirst );
|
|
|
|
static uint8_t transfer( uint8_t ui8Data );
|
|
|
|
static void select( bool bSelect );
|
|
};
|
|
|
|
#endif |