diff --git a/lib/Adafruit_NeoPixel/.github/workflows/githubci.yml b/lib/Adafruit_NeoPixel/.github/workflows/githubci.yml index 2ff3d65477..3cc6520430 100644 --- a/lib/Adafruit_NeoPixel/.github/workflows/githubci.yml +++ b/lib/Adafruit_NeoPixel/.github/workflows/githubci.yml @@ -7,11 +7,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/setup-python@v1 + - uses: actions/setup-python@v4 with: python-version: '3.x' - - uses: actions/checkout@v2 - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - uses: actions/checkout@v3 with: repository: adafruit/ci-arduino path: ci diff --git a/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp b/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp index d1a260a777..12e47612a9 100644 --- a/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp +++ b/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp @@ -229,11 +229,11 @@ void Adafruit_NeoPixel::rp2040Show(uint8_t pin, uint8_t *pixels, uint32_t numBy #if defined(ESP8266) // ESP8266 show() is external to enforce ICACHE_RAM_ATTR execution -extern "C" IRAM_ATTR void espShow(uint8_t pin, uint8_t *pixels, - uint32_t numBytes, boolean is800KHz); +extern "C" IRAM_ATTR void espShow(uint16_t pin, uint8_t *pixels, + uint32_t numBytes, uint8_t type); #elif defined(ESP32) -extern "C" void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, - boolean is800KHz); +extern "C" void espShow(uint16_t pin, uint8_t *pixels, uint32_t numBytes, + uint8_t type); #endif // ESP8266 #if defined(K210) @@ -3439,3 +3439,36 @@ void Adafruit_NeoPixel::rainbow(uint16_t first_hue, int8_t reps, setPixelColor(i, color); } } + +/*! + @brief Convert pixel color order from string (e.g. "BGR") to NeoPixel + color order constant (e.g. NEO_BGR). This may be helpful for code + that initializes from text configuration rather than compile-time + constants. + @param v Input string. Should be reasonably sanitized (a 3- or 4- + character NUL-terminated string) or undefined behavior may + result (output is still a valid NeoPixel order constant, but + might not present as expected). Garbage in, garbage out. + @return One of the NeoPixel color order constants (e.g. NEO_BGR). + NEO_KHZ400 or NEO_KHZ800 bits are not included, nor needed (all + NeoPixels actually support 800 KHz it's been found, and this is + the default state if no KHZ bits set). + @note This function is declared static in the class so it can be called + without a NeoPixel object (since it's not likely been declared + in the code yet). Use Adafruit_NeoPixel::str2order(). +*/ +neoPixelType Adafruit_NeoPixel::str2order(const char *v) { + int8_t r = 0, g = 0, b = 0, w = -1; + if (v) { + char c; + for (uint8_t i=0; ((c = tolower(v[i]))); i++) { + if (c == 'r') r = i; + else if (c == 'g') g = i; + else if (c == 'b') b = i; + else if (c == 'w') w = i; + } + r &= 3; + } + if (w < 0) w = r; // If 'w' not specified, duplicate r bits + return (w << 6) | (r << 4) | ((g & 3) << 2) | (b & 3); +} diff --git a/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.h b/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.h index 53d29f7ccc..ba022f690d 100644 --- a/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.h +++ b/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.h @@ -87,7 +87,7 @@ // 0bRRRRGGBB for RGB // RGB NeoPixel permutations; white and red offsets are always same -// Offset: W R G B +// Offset: W R G B #define NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2)) ///< Transmit as R,G,B #define NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1)) ///< Transmit as R,B,G #define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2)) ///< Transmit as G,R,B @@ -371,6 +371,8 @@ class Adafruit_NeoPixel { uint8_t saturation = 255, uint8_t brightness = 255, bool gammify = true); + static neoPixelType str2order(const char *v); + private: #if defined(ARDUINO_ARCH_RP2040) void rp2040Init(uint8_t pin, bool is800KHz); diff --git a/lib/Adafruit_NeoPixel/README.md b/lib/Adafruit_NeoPixel/README.md index eff1337119..62fef219f4 100644 --- a/lib/Adafruit_NeoPixel/README.md +++ b/lib/Adafruit_NeoPixel/README.md @@ -137,10 +137,11 @@ Please read [CONTRIBUTING.md](https://github.com/adafruit/Adafruit_NeoPixel/blob The PRIME DIRECTIVE is to maintain backward compatibility with existing Arduino sketches -- many are hosted elsewhere and don't track changes here, some are in print and can never be changed! -Please don't reformat code for the sake of reformatting code. The resulting large "visual diff" makes it impossible to untangle actual bug fixes from merely rearranged lines. (Exception for first item in wishlist below.) +Please don't reformat code for the sake of reformatting code. The resulting large "visual diff" makes it impossible to untangle actual bug fixes from merely rearranged lines. Also, don't bother with PRs for timing adjustments "to better match the datasheet," because the datasheet isn't really true to begin with. Things I'd Like To Do But There's No Official Timeline So Please Don't Count On Any Of This Ever Being Canonical: +- 400 KHz support can be removed, turns out it was never actually necessary; even the earliest NeoPixels can ingest 800 KHz data. Of course the #defines should remain so old sketches still compile, but both can be set to 0 and would have no effect on anything. - For the show() function (with all the delicate pixel timing stuff), break out each architecture into separate source files rather than the current unmaintainable tangle of #ifdef statements! - Please don't use updateLength() or updateType() in new code. They should not have been implemented this way (use the C++ 'new' operator with the regular constructor instead) and are only sticking around because of the Prime Directive. setPin() is OK for now though, it's a trick we can use to 'recycle' pixel memory across multiple strips. - In the M0 and M4 code, use the hardware systick counter for bit timing rather than hand-tweaked NOPs (a temporary kludge at the time because I wasn't reading systick correctly). (As of 1.4.2, systick is used on M4 devices and it appears to be overclock-compatible. Not for M0 yet, which is why this item is still here.) diff --git a/lib/Adafruit_NeoPixel/library.properties b/lib/Adafruit_NeoPixel/library.properties index 7bbd4889ca..cec3e149ce 100644 --- a/lib/Adafruit_NeoPixel/library.properties +++ b/lib/Adafruit_NeoPixel/library.properties @@ -1,5 +1,5 @@ name=Adafruit NeoPixel -version=1.10.6 +version=1.11.0 author=Adafruit maintainer=Adafruit sentence=Arduino library for controlling single-wire-based LED pixels and strip.