Skip to content

Commit

Permalink
improve ESP8266 performance
Browse files Browse the repository at this point in the history
  • Loading branch information
moononournation committed Dec 27, 2020
1 parent 8a4e06b commit 53ba4bb
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 193 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=GFX Library for Arduino
version=1.0.1
version=1.0.3
author=Moon On Our Nation <[email protected]>
maintainer=Moon On Our Nation <[email protected]>
sentence=Arduino graphics library for various displays with various data bus interfaces
Expand Down
50 changes: 25 additions & 25 deletions src/databus/Arduino_HWSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,7 @@ void Arduino_HWSPI::begin(int32_t speed, int8_t dataMode)

#if defined(USE_FAST_PINIO)
#if defined(HAS_PORT_SET_CLR)
#if defined(CORE_TEENSY)
#if !defined(KINETISK)
dcPinMask = digitalPinToBitMask(_dc);
#endif
dcPortSet = portSetRegister(_dc);
dcPortClr = portClearRegister(_dc);
if (_cs >= 0)
{
#if !defined(KINETISK)
csPinMask = digitalPinToBitMask(_cs);
#endif
csPortSet = portSetRegister(_cs);
csPortClr = portClearRegister(_cs);
}
else
{
#if !defined(KINETISK)
csPinMask = 0;
#endif
csPortSet = dcPortSet;
csPortClr = dcPortClr;
}
#elif defined(ESP32)
#if defined(ESP32)
dcPinMask = digitalPinToBitMask(_dc);
if (_dc >= 32)
{
Expand Down Expand Up @@ -113,6 +91,28 @@ void Arduino_HWSPI::begin(int32_t speed, int8_t dataMode)
csPortClr = (PORTreg_t)dcPortClr;
csPinMask = 0;
}
#elif defined(CORE_TEENSY)
#if !defined(KINETISK)
dcPinMask = digitalPinToBitMask(_dc);
#endif
dcPortSet = portSetRegister(_dc);
dcPortClr = portClearRegister(_dc);
if (_cs >= 0)
{
#if !defined(KINETISK)
csPinMask = digitalPinToBitMask(_cs);
#endif
csPortSet = portSetRegister(_cs);
csPortClr = portClearRegister(_cs);
}
else
{
#if !defined(KINETISK)
csPinMask = 0;
#endif
csPortSet = dcPortSet;
csPortClr = dcPortClr;
}
#else // !CORE_TEENSY
dcPinMask = digitalPinToBitMask(_dc);
dcPortSet = &(PORT->Group[g_APinDescription[_dc].ulPort].OUTSET.reg);
Expand Down Expand Up @@ -438,15 +438,15 @@ void Arduino_HWSPI::writePattern(uint8_t *data, uint8_t len, uint32_t repeat)
{
#if defined(ESP8266) || defined(ESP32)
HWSPI.writePattern(data, len, repeat);
#else
#else // !(defined(ESP8266) || defined(ESP32))
while (repeat--)
{
for (uint8_t i = 0; i < len; i++)
{
write(data[i]);
}
}
#endif
#endif // !(defined(ESP8266) || defined(ESP32))
}

/******** low level bit twiddling **********/
Expand Down
50 changes: 26 additions & 24 deletions src/databus/Arduino_HWSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,53 @@
// HARDWARE CONFIG ---------------------------------------------------------

#if defined(__AVR__)
typedef uint8_t ARDUINOGFX_PORT_t; ///< PORT values are 8-bit
#define USE_FAST_PINIO ///< Use direct PORT register access
#elif defined(ARDUINO_STM32_FEATHER) // WICED
typedef class HardwareSPI SPIClass; ///< SPI is a bit odd on WICED
typedef uint32_t ARDUINOGFX_PORT_t; ///< PORT values are 32-bit
typedef uint8_t ARDUINOGFX_PORT_t;
#define USE_FAST_PINIO ///< Use direct PORT register access
#elif defined(ESP32)
typedef uint32_t ARDUINOGFX_PORT_t;
#define USE_FAST_PINIO ///< Use direct PORT register access
#define HAS_PORT_SET_CLR ///< PORTs have set & clear registers
#elif defined(ESP8266)
typedef uint32_t ARDUINOGFX_PORT_t;
#define USE_FAST_PINIO ///< Use direct PORT register access
#elif defined(ARDUINO_STM32_FEATHER)
typedef uint32_t ARDUINOGFX_PORT_t;
#elif defined(__arm__)
#if defined(ARDUINO_ARCH_SAMD)
// Adafruit M0, M4
typedef uint32_t ARDUINOGFX_PORT_t; ///< PORT values are 32-bit
typedef uint32_t ARDUINOGFX_PORT_t;
#define USE_FAST_PINIO ///< Use direct PORT register access
#define HAS_PORT_SET_CLR ///< PORTs have set & clear registers
#elif defined(CORE_TEENSY)
#if defined(__IMXRT1052__) || defined(__IMXRT1062__)
// PJRC Teensy 4.x
#if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x
typedef uint32_t ARDUINOGFX_PORT_t; ///< PORT values are 32-bit
// PJRC Teensy 3.x
typedef uint32_t ARDUINOGFX_PORT_t;
#else
typedef uint8_t ARDUINOGFX_PORT_t; ///< PORT values are 8-bit
// PJRC Teensy 3.x
typedef uint8_t ARDUINOGFX_PORT_t;
#endif
#define USE_FAST_PINIO ///< Use direct PORT register access
#define HAS_PORT_SET_CLR ///< PORTs have set & clear registers
#else
// Arduino Due?
typedef uint32_t ARDUINOGFX_PORT_t; ///< PORT values are 32-bit
// USE_FAST_PINIO not available here (yet)...Due has a totally different
// GPIO register set and will require some changes elsewhere (e.g. in
// constructors especially).
#endif
#elif defined(ESP32)
typedef uint32_t ARDUINOGFX_PORT_t;
#define USE_FAST_PINIO ///< Use direct PORT register access
#define HAS_PORT_SET_CLR ///< PORTs have set & clear registers
#else // !ARM
// Probably ESP8266. USE_FAST_PINIO is not available here (yet)
// USE_FAST_PINIO not available here (yet)...Due has a totally different
// GPIO register set and will require some changes elsewhere (e.g. in
// constructors especially).
#endif
#else // !ARM
// Unknow architecture, USE_FAST_PINIO is not available here (yet)
// but don't worry about it too much...the digitalWrite() implementation
// on these platforms is reasonably efficient and already RAM-resident,
// only gotcha then is no parallel connection support for now.
typedef uint32_t ARDUINOGFX_PORT_t; ///< PORT values are 32-bit
#endif // end !ARM
typedef volatile ARDUINOGFX_PORT_t *PORTreg_t; ///< PORT register type
typedef uint32_t ARDUINOGFX_PORT_t;
#endif // end !ARM
typedef volatile ARDUINOGFX_PORT_t *PORTreg_t;

#if defined(ADAFRUIT_PYPORTAL) || defined(ADAFRUIT_PYBADGE_M4_EXPRESS) || defined(ADAFRUIT_PYGAMER_M4_EXPRESS) || defined(ADAFRUIT_HALLOWING_M4_EXPRESS)
#define USE_SPI_DMA ///< Auto DMA if using PyPortal
#else
//#define USE_SPI_DMA ///< If set, use DMA if available
//#define USE_SPI_DMA ///< If set, use DMA if available
#endif
// Another "oops" name -- this now also handles parallel DMA.
// If DMA is enabled, Arduino sketch MUST #include <Adafruit_ZeroDMA.h>
Expand Down
Loading

0 comments on commit 53ba4bb

Please sign in to comment.