spi/spi.h

64 lines
1.3 KiB
C
Raw Normal View History

/*
* Copyright (c) by BlackMark 2016-2017
2017-09-15 15:36:16 +02:00
* Date 15/09/2017
* Version 1.3
*/
2016-05-26 21:40:24 +02:00
#ifndef SPI_H
#define SPI_H
#include <avr/io.h>
#include "../inout/inout.h"
2016-05-26 21:40:24 +02:00
class SPI
2016-05-26 21:40:24 +02:00
{
public:
enum class ClockDiv
{
CLKDIV_4 = 0,
CLKDIV_16 = 1,
CLKDIV_64 = 2,
CLKDIV_128 = 3,
2016-05-26 21:40:24 +02:00
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
};
2016-05-26 21:40:24 +02:00
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;
2017-09-14 12:06:08 +02:00
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 );
2017-09-15 15:36:16 +02:00
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 );
};
2016-05-26 21:40:24 +02:00
#endif