From a0fab862fba72b93dbadd03ce3b7e80b66851f2c Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 7 Dec 2019 13:56:34 -0800 Subject: [PATCH] NEOPIXEBUS_NO_STL (#314) --- .../animations/NeoPixelAnimation/NeoPixelAnimation.ino | 4 ++-- src/NeoPixelAnimator.h | 2 +- src/NeoPixelBus.h | 10 +++++++++- src/internal/NeoAvrMethod.h | 2 +- src/internal/NeoBufferMethods.h | 2 +- src/internal/NeoEase.h | 2 +- src/internal/NeoGamma.cpp | 5 +---- src/internal/NeoPixelAnimator.cpp | 1 + src/internal/NeoPixelAvr.c | 2 +- 9 files changed, 18 insertions(+), 12 deletions(-) diff --git a/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino b/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino index 4f0386a..fc3a372 100644 --- a/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino +++ b/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino @@ -53,7 +53,7 @@ NeoPixelAnimator animations(PixelCount, NEO_CENTISECONDS); // NEO_DECASECONDS 10000 // ~7.5 days, 10 second updates // -#ifdef ARDUINO_ARCH_AVR +#if defined(NEOPIXEBUS_NO_STL) // for AVR, you need to manage the state due to lack of STL/compiler support // for Esp8266 you can define the function using a lambda and state is created for you // see below for an example @@ -158,7 +158,7 @@ void SetupAnimationSet() break; } -#ifdef ARDUINO_ARCH_AVR +#if defined(NEOPIXEBUS_NO_STL) // each animation starts with the color that was present animationState[pixel].StartingColor = originalColor; // and ends with a random color diff --git a/src/NeoPixelAnimator.h b/src/NeoPixelAnimator.h index 46fcad1..d990599 100644 --- a/src/NeoPixelAnimator.h +++ b/src/NeoPixelAnimator.h @@ -43,7 +43,7 @@ struct AnimationParam AnimationState state; }; -#ifdef ARDUINO_ARCH_AVR +#if defined(NEOPIXEBUS_NO_STL) typedef void(*AnimUpdateCallback)(const AnimationParam& param); diff --git a/src/NeoPixelBus.h b/src/NeoPixelBus.h index 5d65025..fff2cd1 100644 --- a/src/NeoPixelBus.h +++ b/src/NeoPixelBus.h @@ -27,6 +27,14 @@ License along with NeoPixel. If not, see #include +// some platforms do not come with STL or properly defined one, specifically functional +// if you see... +// undefined reference to `std::__throw_bad_function_call()' +// ...then that platform should be added here so NEOPIXEBUS_NO_STL gets defined +#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) || defined(STM32L432xx) || defined(STM32L476xx) || defined(ARDUINO_ARCH_SAM) +#define NEOPIXEBUS_NO_STL 1 +#endif + // some platforms do not define this standard progmem type for some reason // #ifndef PGM_VOID_P @@ -89,7 +97,7 @@ License along with NeoPixel. If not, see #include "internal/NeoArmMethod.h" -#elif defined(ARDUINO_ARCH_AVR) +#elif defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) #include "internal/NeoAvrMethod.h" diff --git a/src/internal/NeoAvrMethod.h b/src/internal/NeoAvrMethod.h index a304920..96aa47c 100644 --- a/src/internal/NeoAvrMethod.h +++ b/src/internal/NeoAvrMethod.h @@ -27,7 +27,7 @@ License along with NeoPixel. If not, see #pragma once -#ifdef ARDUINO_ARCH_AVR +#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) extern "C" { diff --git a/src/internal/NeoBufferMethods.h b/src/internal/NeoBufferMethods.h index 4bd531f..79d354f 100644 --- a/src/internal/NeoBufferMethods.h +++ b/src/internal/NeoBufferMethods.h @@ -27,7 +27,7 @@ License along with NeoPixel. If not, see #pragma once -#ifdef ARDUINO_ARCH_AVR +#if defined(NEOPIXEBUS_NO_STL) typedef uint16_t(*LayoutMapCallback)(int16_t x, int16_t y); diff --git a/src/internal/NeoEase.h b/src/internal/NeoEase.h index b7b5df9..113344b 100644 --- a/src/internal/NeoEase.h +++ b/src/internal/NeoEase.h @@ -26,7 +26,7 @@ License along with NeoPixel. If not, see #pragma once -#ifdef ARDUINO_ARCH_AVR +#if defined(NEOPIXEBUS_NO_STL) typedef float(*AnimEaseFunction)(float unitValue); diff --git a/src/internal/NeoGamma.cpp b/src/internal/NeoGamma.cpp index f33cbfb..fdff9e7 100644 --- a/src/internal/NeoGamma.cpp +++ b/src/internal/NeoGamma.cpp @@ -25,10 +25,7 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include -#include "RgbColor.h" -#include "RgbwColor.h" -#include "NeoEase.h" -#include "NeoGamma.h" +#include "NeoPixelBus.h" const uint8_t NeoGammaTableMethod::_table[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, diff --git a/src/internal/NeoPixelAnimator.cpp b/src/internal/NeoPixelAnimator.cpp index d535316..55e74ae 100644 --- a/src/internal/NeoPixelAnimator.cpp +++ b/src/internal/NeoPixelAnimator.cpp @@ -24,6 +24,7 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ +#include "NeoPixelBus.h" #include "NeoPixelAnimator.h" NeoPixelAnimator::NeoPixelAnimator(uint16_t countAnimations, uint16_t timeScale) : diff --git a/src/internal/NeoPixelAvr.c b/src/internal/NeoPixelAvr.c index 761fa7e..09ad113 100644 --- a/src/internal/NeoPixelAvr.c +++ b/src/internal/NeoPixelAvr.c @@ -34,7 +34,7 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ // must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set -#if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) +#if (defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)) && !defined(__arm__) #include