mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-29 18:52:13 +01:00
Renaming SPI constants to better match general style. Renaming setDataOrder() to setBitOrder(), and using existing LSBFIRST and MSBFIRST constants for it.
This commit is contained in:
parent
3899ffc75d
commit
08feacbb40
@ -37,51 +37,23 @@ SPIClass::SPIClass()
|
||||
SPCR = _BV(SPE) | _BV(MSTR);
|
||||
}
|
||||
|
||||
void SPIClass::setDataOrder(SPIDataOrder _d)
|
||||
void SPIClass::setBitOrder(uint8_t bitOrder)
|
||||
{
|
||||
if (_d == SPI_DataOrder_LSB)
|
||||
SPCR |= _BV(DORD); // LSB
|
||||
else
|
||||
SPCR &= ~_BV(DORD); // MSB
|
||||
}
|
||||
|
||||
void SPIClass::setSPIMode(SPIMode _d)
|
||||
{
|
||||
switch (_d) {
|
||||
case SPI_Mode_SampleRising:
|
||||
SPCR &= ~(_BV(CPOL) | _BV(CPHA));
|
||||
break;
|
||||
case SPI_Mode_SetupRising:
|
||||
SPCR &= ~_BV(CPOL);
|
||||
SPCR |= _BV(CPHA);
|
||||
break;
|
||||
case SPI_Mode_SampleFalling:
|
||||
SPCR &= ~_BV(CPHA);
|
||||
SPCR |= _BV(CPOL);
|
||||
break;
|
||||
case SPI_Mode_SetupFalling:
|
||||
SPCR |= _BV(CPOL) | _BV(CPHA);
|
||||
break;
|
||||
if(bitOrder == LSBFIRST) {
|
||||
SPCR |= _BV(DORD);
|
||||
} else {
|
||||
SPCR &= ~(_BV(DORD));
|
||||
}
|
||||
}
|
||||
|
||||
void SPIClass::setClockDivider(SPIClockDivider _d)
|
||||
void SPIClass::setDataMode(uint8_t mode)
|
||||
{
|
||||
switch (_d) {
|
||||
case SPI_ClkDiv_4:
|
||||
SPCR &= ~(_BV(SPR1) | _BV(SPR0));
|
||||
break;
|
||||
case SPI_ClkDiv_16:
|
||||
SPCR &= ~_BV(SPR1);
|
||||
SPCR |= _BV(SPR0);
|
||||
break;
|
||||
case SPI_ClkDiv_64:
|
||||
SPCR |= _BV(SPR1);
|
||||
SPCR &= ~_BV(SPR0);
|
||||
break;
|
||||
case SPI_ClkDiv_128:
|
||||
SPCR |= _BV(SPR1) | _BV(SPR0);
|
||||
break;
|
||||
}
|
||||
SPCR = (SPCR & ~SPI_MODE_MASK) | mode;
|
||||
}
|
||||
|
||||
void SPIClass::setClockDivider(uint8_t rate)
|
||||
{
|
||||
SPCR = (SPCR & ~SPI_CLOCK_MASK) | (rate & SPI_CLOCK_MASK);
|
||||
SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | (rate & SPI_2XCLOCK_MASK);
|
||||
}
|
||||
|
||||
|
@ -15,24 +15,23 @@
|
||||
#include <WProgram.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
enum SPIClockDivider {
|
||||
SPI_ClkDiv_4,
|
||||
SPI_ClkDiv_16,
|
||||
SPI_ClkDiv_64,
|
||||
SPI_ClkDiv_128,
|
||||
};
|
||||
#define SPI_CLOCK_DIV4 0x00
|
||||
#define SPI_CLOCK_DIV16 0x01
|
||||
#define SPI_CLOCK_DIV64 0x02
|
||||
#define SPI_CLOCK_DIV128 0x03
|
||||
#define SPI_CLOCK_DIV2 0x04
|
||||
#define SPI_CLOCK_DIV8 0x05
|
||||
#define SPI_CLOCK_DIV32 0x06
|
||||
#define SPI_CLOCK_DIV64 0x07
|
||||
|
||||
enum SPIDataOrder {
|
||||
SPI_DataOrder_LSB,
|
||||
SPI_DataOrder_MSB,
|
||||
};
|
||||
#define SPI_MODE0 0x00
|
||||
#define SPI_MODE1 0x04
|
||||
#define SPI_MODE2 0x08
|
||||
#define SPI_MODE3 0x0C
|
||||
|
||||
enum SPIMode {
|
||||
SPI_Mode_SampleRising,
|
||||
SPI_Mode_SetupRising,
|
||||
SPI_Mode_SampleFalling,
|
||||
SPI_Mode_SetupFalling,
|
||||
};
|
||||
#define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR
|
||||
#define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR
|
||||
#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR
|
||||
|
||||
class SPIClass {
|
||||
public:
|
||||
@ -48,13 +47,9 @@ public:
|
||||
inline static void begin(); // Default
|
||||
inline static void end();
|
||||
|
||||
static void setDataOrder(SPIDataOrder);
|
||||
|
||||
static void setSPIMode(SPIMode);
|
||||
|
||||
static void setClockDivider(SPIClockDivider);
|
||||
inline static void doubleSpeed();
|
||||
inline static void noDoubleSpeed(); // Default
|
||||
static void setBitOrder(uint8_t);
|
||||
static void setDataMode(uint8_t);
|
||||
static void setClockDivider(uint8_t);
|
||||
};
|
||||
|
||||
extern SPIClass SPI;
|
||||
@ -82,12 +77,4 @@ void SPIClass::end() {
|
||||
SPCR &= ~_BV(SPE);
|
||||
}
|
||||
|
||||
void SPIClass::doubleSpeed() {
|
||||
SPSR |= _BV(SPI2X);
|
||||
}
|
||||
|
||||
void SPIClass::noDoubleSpeed() {
|
||||
SPSR &= ~_BV(SPI2X);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -11,41 +11,26 @@ SPI KEYWORD1
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
send KEYWORD2
|
||||
sendInt16 KEYWORD2
|
||||
sendInt32 KEYWORD2
|
||||
initSS KEYWORD2
|
||||
setSS KEYWORD2
|
||||
resetSS KEYWORD2
|
||||
initSS2 KEYWORD2
|
||||
setSS2 KEYWORD2
|
||||
resetSS2 KEYWORD2
|
||||
initSS3 KEYWORD2
|
||||
setSS3 KEYWORD2
|
||||
resetSS3 KEYWORD2
|
||||
initSS4 KEYWORD2
|
||||
setSS4 KEYWORD2
|
||||
resetSS4 KEYWORD2
|
||||
|
||||
enableInterrupt KEYWORD2
|
||||
disableInterrupt KEYWORD2
|
||||
enable KEYWORD2
|
||||
disable KEYWORD2
|
||||
dataOrderLSB KEYWORD2
|
||||
dataOrderMSB KEYWORD2
|
||||
setSPIMode0 KEYWORD2
|
||||
setSPIMode1 KEYWORD2
|
||||
setSPIMode2 KEYWORD2
|
||||
setSPIMode3 KEYWORD2
|
||||
setClockDividerTo2 KEYWORD2
|
||||
setClockDividerTo4 KEYWORD2
|
||||
setClockDividerTo8 KEYWORD2
|
||||
setClockDividerTo16 KEYWORD2
|
||||
setClockDividerTo32 KEYWORD2
|
||||
setClockDividerTo64 KEYWORD2
|
||||
setClockDividerTo128 KEYWORD2
|
||||
begin KEYWORD2
|
||||
end KEYWORD2
|
||||
transfer KEYWORD2
|
||||
setBitOrder KEYWORD2
|
||||
setDataMode KEYWORD2
|
||||
setClockDivider KEYWORD2
|
||||
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
SPI_CLOCK_DIV4 LITERAL1
|
||||
SPI_CLOCK_DIV16 LITERAL1
|
||||
SPI_CLOCK_DIV64 LITERAL1
|
||||
SPI_CLOCK_DIV128 LITERAL1
|
||||
SPI_CLOCK_DIV2 LITERAL1
|
||||
SPI_CLOCK_DIV8 LITERAL1
|
||||
SPI_CLOCK_DIV32 LITERAL1
|
||||
SPI_CLOCK_DIV64 LITERAL1
|
||||
SPI_MODE0 LITERAL1
|
||||
SPI_MODE1 LITERAL1
|
||||
SPI_MODE2 LITERAL1
|
||||
SPI_MODE3 LITERAL1
|
Loading…
x
Reference in New Issue
Block a user