Selaa lähdekoodia

Optimize ESP8266 SPI performance

main
Bill Greiman 8 vuotta sitten
vanhempi
commit
d58f5b4f48
4 muutettua tiedostoa jossa 103 lisäystä ja 11 poistoa
  1. +1
    -3
      SdFat/src/FreeStack.h
  2. +1
    -0
      SdFat/src/SdFatConfig.h
  3. +0
    -8
      SdFat/src/SdSpiCard/SdSpi.h
  4. +101
    -0
      SdFat/src/SdSpiCard/SdSpiESP8266.cpp

+ 1
- 3
SdFat/src/FreeStack.h Näytä tiedosto

@@ -23,7 +23,6 @@
* \file
* \brief FreeStack() function.
*/
#if defined(__AVR__) || defined(DOXYGEN)
/** boundary between stack and heap. */
extern char *__brkval;
@@ -35,7 +34,7 @@ extern char __bss_end;
static int FreeStack() {
char top;
return __brkval ? &top - __brkval : &top - &__bss_end;
}
}
#elif defined(PLATFORM_ID) // Particle board
static int FreeStack() {
return System.freeMemory();
@@ -46,7 +45,6 @@ static int FreeStack() {
char top;
return &top - reinterpret_cast<char*>(sbrk(0));
}

#else
#warning FreeStack is not defined for this system.
static int FreeStack() {

+ 1
- 0
SdFat/src/SdFatConfig.h Näytä tiedosto

@@ -189,6 +189,7 @@ const uint8_t SPI_SCK_INIT_DIVISOR = 128;
|| (defined(__arm__) && defined(CORE_TEENSY))\
|| defined(__STM32F1__)\
|| defined(PLATFORM_ID)\
|| defined(ESP8266)\
|| defined(DOXYGEN)
// Use custom fast implementation.
#define SD_HAS_CUSTOM_SPI 1

+ 0
- 8
SdFat/src/SdSpiCard/SdSpi.h Näytä tiedosto

@@ -206,16 +206,12 @@ class SdSpiLib {
*
* \return Zero for no error or nonzero error code.
*/
#if defined(PLATFORM_ID) && USE_SPI_LIB_DMA
uint8_t receive(uint8_t* buf, size_t n);
#else // defined(PLATFORM_ID) && USE_SPI_LIB_DMA
uint8_t receive(uint8_t* buf, size_t n) {
for (size_t i = 0; i < n; i++) {
buf[i] = SPI.transfer(0XFF);
}
return 0;
}
#endif // defined(PLATFORM_ID) && USE_SPI_LIB_DMA
/** Send a byte.
*
* \param[in] b Byte to send
@@ -228,15 +224,11 @@ class SdSpiLib {
* \param[in] buf Buffer for data to be sent.
* \param[in] n Number of bytes to send.
*/
#if defined(PLATFORM_ID) && USE_SPI_LIB_DMA
void send(const uint8_t* buf , size_t n);
#else // defined(PLATFORM_ID) && USE_SPI_LIB_DMA
void send(const uint8_t* buf , size_t n) {
for (size_t i = 0; i < n; i++) {
SPI.transfer(buf[i]);
}
}
#endif // defined(PLATFORM_ID) && USE_SPI_LIB_DMA
};
//------------------------------------------------------------------------------
#if SD_SPI_CONFIGURATION > 1 || defined(DOXYGEN)

+ 101
- 0
SdFat/src/SdSpiCard/SdSpiESP8266.cpp Näytä tiedosto

@@ -0,0 +1,101 @@
/* Arduino SdSpi Library
* Copyright (C) 2016 by William Greiman
*
* STM32F1 code for Maple and Maple Mini support, 2015 by Victor Perez
*
* This file is part of the Arduino SdSpi Library
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the Arduino SdSpi Library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#if defined(ESP8266)
#include "SdSpi.h"
//------------------------------------------------------------------------------
/** Initialize the SPI bus.
*
* \param[in] chipSelectPin SD card chip select pin.
*/
void SdSpi::begin(uint8_t chipSelectPin) {
pinMode(chipSelectPin, OUTPUT);
digitalWrite(chipSelectPin, HIGH);
SPI.begin();
}
//------------------------------------------------------------------------------
/** Set SPI options for access to SD/SDHC cards.
*
* \param[in] divisor SCK clock divider relative to the system clock.
*/
void SdSpi::beginTransaction(uint8_t divisor) {
#if ENABLE_SPI_TRANSACTIONS
// Note: ESP8266 beginTransaction does not protect for interrupts.
SPISettings settings(F_CPU/(divisor ? divisor : 1), MSBFIRST, SPI_MODE0);
SPI.beginTransaction(settings);
#else // ENABLE_SPI_TRANSACTIONS
// Note: ESP8266 beginTransaction is the same as following code.
SPI.setFrequency(F_CPU/(divisor ? divisor : 1));
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
#endif // ENABLE_SPI_TRANSACTIONS
}
//------------------------------------------------------------------------------
void SdSpi::endTransaction() {
#if ENABLE_SPI_TRANSACTIONS
// Note: endTransaction is an empty function on ESP8266.
SPI.endTransaction();
#endif // ENABLE_SPI_TRANSACTIONS
}
//------------------------------------------------------------------------------
/** Receive a byte.
*
* \return The byte.
*/
uint8_t SdSpi::receive() {
return SPI.transfer(0XFF);
}
//------------------------------------------------------------------------------
/** Receive multiple bytes.
*
* \param[out] buf Buffer to receive the data.
* \param[in] n Number of bytes to receive.
*
* \return Zero for no error or nonzero error code.
*/
uint8_t SdSpi::receive(uint8_t* buf, size_t n) {
// Works without 32-bit alignment of buf.
SPI.transferBytes(0, buf, n);
return 0;
}
//------------------------------------------------------------------------------
/** Send a byte.
*
* \param[in] b Byte to send
*/
void SdSpi::send(uint8_t b) {
SPI.transfer(b);
}
//------------------------------------------------------------------------------
/** Send multiple bytes.
*
* \param[in] buf Buffer for data to be sent.
* \param[in] n Number of bytes to send.
*/
void SdSpi::send(const uint8_t* buf , size_t n) {
// Adjust to 32-bit alignmented.
while ((reinterpret_cast<uintptr_t>(buf) & 0X3) && n) {
SPI.transfer(*buf++);
n--;
}
SPI.transferBytes(const_cast<uint8_t*>(buf), 0, n);
}
#endif // defined(ESP8266)

Loading…
Peruuta
Tallenna