Use SPI transaction, if supported by SPI library
This commit is contained in:
parent
7c4424e08e
commit
aa404fdea8
12
SPIFlash.cpp
12
SPIFlash.cpp
|
|
@ -32,24 +32,36 @@ SPIFlash::SPIFlash(uint8_t slaveSelectPin, uint16_t jedecID) {
|
||||||
|
|
||||||
/// Select the flash chip
|
/// Select the flash chip
|
||||||
void SPIFlash::select() {
|
void SPIFlash::select() {
|
||||||
|
#ifdef SPI_HAS_TRANSACTION
|
||||||
|
SPI.beginTransaction(SPISettings(33000000, MSBFIRST, SPI_MODE0));
|
||||||
|
#else
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
|
#endif
|
||||||
digitalWrite(_slaveSelectPin, LOW);
|
digitalWrite(_slaveSelectPin, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// UNselect the flash chip
|
/// UNselect the flash chip
|
||||||
void SPIFlash::unselect() {
|
void SPIFlash::unselect() {
|
||||||
digitalWrite(_slaveSelectPin, HIGH);
|
digitalWrite(_slaveSelectPin, HIGH);
|
||||||
|
#ifdef SPI_HAS_TRANSACTION
|
||||||
|
SPI.endTransaction();
|
||||||
|
#else
|
||||||
interrupts();
|
interrupts();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// setup SPI, read device ID etc...
|
/// setup SPI, read device ID etc...
|
||||||
boolean SPIFlash::initialize()
|
boolean SPIFlash::initialize()
|
||||||
{
|
{
|
||||||
pinMode(_slaveSelectPin, OUTPUT);
|
pinMode(_slaveSelectPin, OUTPUT);
|
||||||
|
#ifdef SPI_HAS_TRANSACTION
|
||||||
|
digitalWrite(_slaveSelectPin, HIGH);
|
||||||
|
#else
|
||||||
unselect();
|
unselect();
|
||||||
SPI.setDataMode(SPI_MODE0);
|
SPI.setDataMode(SPI_MODE0);
|
||||||
SPI.setBitOrder(MSBFIRST);
|
SPI.setBitOrder(MSBFIRST);
|
||||||
SPI.setClockDivider(SPI_CLOCK_DIV2); //max speed, except on Due which can run at system clock speed
|
SPI.setClockDivider(SPI_CLOCK_DIV2); //max speed, except on Due which can run at system clock speed
|
||||||
|
#endif
|
||||||
SPI.begin();
|
SPI.begin();
|
||||||
|
|
||||||
if (_jedecID == 0 || readDeviceId() == _jedecID) {
|
if (_jedecID == 0 || readDeviceId() == _jedecID) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue