Quellcode durchsuchen

ESP8266 Software SPI and yield mods

main
Bill Greiman vor 8 Jahren
Ursprung
Commit
49127b29b6
5 geänderte Dateien mit 85 neuen und 59 gelöschten Zeilen
  1. +1
    -1
      SdFat/src/SdFat.h
  2. +13
    -0
      SdFat/src/SdFatConfig.h
  3. +63
    -57
      SdFat/src/SdSpiCard/DigitalPin.h
  4. +1
    -1
      SdFat/src/SdSpiCard/SdSpi.h
  5. +7
    -0
      SdFat/src/SdSpiCard/SdSpiCard.cpp

+ 1
- 1
SdFat/src/SdFat.h Datei anzeigen

@@ -32,7 +32,7 @@
#endif // ARDUINO
//------------------------------------------------------------------------------
/** SdFat version YYYYMMDD */
#define SD_FAT_VERSION 20160212
#define SD_FAT_VERSION 20160411
//==============================================================================
/**
* \class SdBaseFile

+ 13
- 0
SdFat/src/SdFatConfig.h Datei anzeigen

@@ -117,6 +117,19 @@ uint8_t const SOFT_SPI_SCK_PIN = 13;
*/
#define ENABLE_SPI_TRANSACTIONS 0
//------------------------------------------------------------------------------
/**
* Handle Watchdog Timer for WiFi modules.
*
* Yield will be called before accessing the SPI bus if it has been more
* than WDT_YIELD_TIME_MICROS microseconds since the last yield call by SdFat.
*/
#if defined(PLATFORM_ID) || defined(ESP8266)
// If Particle device or ESP8266 call yield.
#define WDT_YIELD_TIME_MICROS 100000
#else
#define WDT_YIELD_TIME_MICROS 0
#endif
//------------------------------------------------------------------------------
/**
* Set FAT12_SUPPORT nonzero to enable use if FAT12 volumes.
* FAT12 has not been well tested and requires additional flash.

+ 63
- 57
SdFat/src/SdSpiCard/DigitalPin.h Datei anzeigen

@@ -28,62 +28,7 @@
#ifndef DigitalPin_h
#define DigitalPin_h
#include "SystemInclude.h"
#ifdef __arm__
#ifdef CORE_TEENSY
//------------------------------------------------------------------------------
/** read pin value
* @param[in] pin Arduino pin number
* @return value read
*/
static inline __attribute__((always_inline))
bool fastDigitalRead(uint8_t pin) {
return *portInputRegister(pin);
}
//------------------------------------------------------------------------------
/** Set pin value
* @param[in] pin Arduino pin number
* @param[in] level value to write
*/
static inline __attribute__((always_inline))
void fastDigitalWrite(uint8_t pin, bool value) {
if (value) {
*portSetRegister(pin) = 1;
} else {
*portClearRegister(pin) = 1;
}
}
#else // CORE_TEENSY
//------------------------------------------------------------------------------
/** read pin value
* @param[in] pin Arduino pin number
* @return value read
*/
static inline __attribute__((always_inline))
bool fastDigitalRead(uint8_t pin) {
return g_APinDescription[pin].pPort->PIO_PDSR & g_APinDescription[pin].ulPin;
}
//------------------------------------------------------------------------------
/** Set pin value
* @param[in] pin Arduino pin number
* @param[in] level value to write
*/
static inline __attribute__((always_inline))
void fastDigitalWrite(uint8_t pin, bool value) {
if (value) {
g_APinDescription[pin].pPort->PIO_SODR = g_APinDescription[pin].ulPin;
} else {
g_APinDescription[pin].pPort->PIO_CODR = g_APinDescription[pin].ulPin;
}
}
#endif // CORE_TEENSY
//------------------------------------------------------------------------------
inline void fastDigitalToggle(uint8_t pin) {
fastDigitalWrite(pin, !fastDigitalRead(pin));
}
//------------------------------------------------------------------------------
inline void fastPinMode(uint8_t pin, uint8_t mode) {pinMode(pin, mode);}
#else // __arm__
//==============================================================================
#if defined(__AVR__)
#include <avr/io.h>
/** GpioPinMap type */
struct GpioPinMap_t {
@@ -233,7 +178,68 @@ void fastPinMode(uint8_t pin, uint8_t mode) {
fastDigitalWrite(pin, mode == INPUT_PULLUP);
}
}
#endif // __arm__
#else // defined(__AVR__)
#if defined(CORE_TEENSY)
//------------------------------------------------------------------------------
/** read pin value
* @param[in] pin Arduino pin number
* @return value read
*/
static inline __attribute__((always_inline))
bool fastDigitalRead(uint8_t pin) {
return *portInputRegister(pin);
}
//------------------------------------------------------------------------------
/** Set pin value
* @param[in] pin Arduino pin number
* @param[in] level value to write
*/
static inline __attribute__((always_inline))
void fastDigitalWrite(uint8_t pin, bool value) {
if (value) {
*portSetRegister(pin) = 1;
} else {
*portClearRegister(pin) = 1;
}
}
#elif defined(__SAM3X8E__) || defined(__SAM3X8H__)
//------------------------------------------------------------------------------
/** read pin value
* @param[in] pin Arduino pin number
* @return value read
*/
static inline __attribute__((always_inline))
bool fastDigitalRead(uint8_t pin) {
return g_APinDescription[pin].pPort->PIO_PDSR & g_APinDescription[pin].ulPin;
}
//------------------------------------------------------------------------------
/** Set pin value
* @param[in] pin Arduino pin number
* @param[in] level value to write
*/
static inline __attribute__((always_inline))
void fastDigitalWrite(uint8_t pin, bool value) {
if (value) {
g_APinDescription[pin].pPort->PIO_SODR = g_APinDescription[pin].ulPin;
} else {
g_APinDescription[pin].pPort->PIO_CODR = g_APinDescription[pin].ulPin;
}
}
#else // CORE_TEENSY
//------------------------------------------------------------------------------
inline void fastDigitalWrite(uint8_t pin, bool value) {
digitalWrite(pin, value);
}
//------------------------------------------------------------------------------
inline bool fastDigitalRead(uint8_t pin) {return digitalRead(pin);}
#endif // CORE_TEENSY
//------------------------------------------------------------------------------
inline void fastDigitalToggle(uint8_t pin) {
fastDigitalWrite(pin, !fastDigitalRead(pin));
}
//------------------------------------------------------------------------------
inline void fastPinMode(uint8_t pin, uint8_t mode) {pinMode(pin, mode);}
#endif // __AVR__
//------------------------------------------------------------------------------
/** set pin configuration
* @param[in] pin Arduino pin number

+ 1
- 1
SdFat/src/SdSpiCard/SdSpi.h Datei anzeigen

@@ -160,7 +160,7 @@ class SdSpiLib {
#else // ENABLE_SPI_TRANSACTIONS
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
#endif // ENABLE_SPI_TRANSACTIONS
#endif // ENABLE_SPI_TRANSACTIONS
#ifndef SPI_CLOCK_DIV128
SPI.setClockDivider(divisor);
#else // SPI_CLOCK_DIV128

+ 7
- 0
SdFat/src/SdSpiCard/SdSpiCard.cpp Datei anzeigen

@@ -281,6 +281,13 @@ void SdSpiCard::chipSelectHigh() {
}
//------------------------------------------------------------------------------
void SdSpiCard::chipSelectLow() {
#if WDT_YIELD_TIME_MICROS
static uint32_t last;
if ((micros() - last) > WDT_YIELD_TIME_MICROS) {
SysCall::yield();
last = micros();
}
#endif // WDT_YIELD_TIME_MICROS
if (m_selected) {
SD_CS_DBG("chipSelectLow error");
return;

Laden…
Abbrechen
Speichern