From 68f225e3c38866ca74d5cce7deaf0e03f1ebe53f Mon Sep 17 00:00:00 2001 From: mikeshub Date: Sun, 28 Jul 2019 08:00:22 -0500 Subject: [PATCH 1/6] Fix for 32 bit uCs ie LPC1768 --- Adafruit_NeoPixel.cpp | 4 ++-- Adafruit_NeoPixel.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Adafruit_NeoPixel.cpp b/Adafruit_NeoPixel.cpp index 423949c2..79c08ab4 100644 --- a/Adafruit_NeoPixel.cpp +++ b/Adafruit_NeoPixel.cpp @@ -65,7 +65,7 @@ pixel. @return Adafruit_NeoPixel object. Call the begin() function before use. */ -Adafruit_NeoPixel::Adafruit_NeoPixel(uint16_t n, uint8_t p, neoPixelType t) : +Adafruit_NeoPixel::Adafruit_NeoPixel(uint16_t n, unit16_t p, neoPixelType t) : begun(false), brightness(0), pixels(NULL), endTime(0) { updateType(t); updateLength(n); @@ -2114,7 +2114,7 @@ void Adafruit_NeoPixel::show(void) { if any, is set to INPUT and the new pin is set to OUTPUT. @param p Arduino pin number (-1 = no pin). */ -void Adafruit_NeoPixel::setPin(uint8_t p) { +void Adafruit_NeoPixel::setPin(unit16_t p) { if(begun && (pin >= 0)) pinMode(pin, INPUT); pin = p; if(begun) { diff --git a/Adafruit_NeoPixel.h b/Adafruit_NeoPixel.h index eece2364..c8152172 100644 --- a/Adafruit_NeoPixel.h +++ b/Adafruit_NeoPixel.h @@ -195,14 +195,14 @@ class Adafruit_NeoPixel { public: // Constructor: number of LEDs, pin number, LED type - Adafruit_NeoPixel(uint16_t n, uint8_t pin=6, + Adafruit_NeoPixel(uint16_t n, unit16_t pin=6, neoPixelType type=NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel(void); ~Adafruit_NeoPixel(); void begin(void); void show(void); - void setPin(uint8_t p); + void setPin(unit16_t p); void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b); void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w); From 578a1a0244a6e7a35dfd75652d2d707fec2666f0 Mon Sep 17 00:00:00 2001 From: mikeshub Date: Sun, 28 Jul 2019 08:07:57 -0500 Subject: [PATCH 2/6] Change get pin to the right bit width --- Adafruit_NeoPixel.cpp | 4 ++-- Adafruit_NeoPixel.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Adafruit_NeoPixel.cpp b/Adafruit_NeoPixel.cpp index 79c08ab4..c9b6a5f6 100644 --- a/Adafruit_NeoPixel.cpp +++ b/Adafruit_NeoPixel.cpp @@ -171,10 +171,10 @@ void Adafruit_NeoPixel::updateType(neoPixelType t) { #if defined(ESP8266) // ESP8266 show() is external to enforce ICACHE_RAM_ATTR execution extern "C" void ICACHE_RAM_ATTR espShow( - uint8_t pin, uint8_t *pixels, uint32_t numBytes, uint8_t type); + 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, uint8_t type); + uint16_t pin, uint8_t *pixels, uint32_t numBytes, uint8_t type); #endif // ESP8266 /*! diff --git a/Adafruit_NeoPixel.h b/Adafruit_NeoPixel.h index c8152172..e8820075 100644 --- a/Adafruit_NeoPixel.h +++ b/Adafruit_NeoPixel.h @@ -246,7 +246,7 @@ class Adafruit_NeoPixel { @brief Retrieve the pin number used for NeoPixel data output. @return Arduino pin number (-1 if not set). */ - int8_t getPin(void) const { return pin; }; + int16_t getPin(void) const { return pin; }; /*! @brief Return the number of pixels in an Adafruit_NeoPixel strip object. @return Pixel count (0 if not set). @@ -334,7 +334,7 @@ class Adafruit_NeoPixel { boolean begun; ///< true if begin() previously called uint16_t numLEDs; ///< Number of RGB LEDs in strip uint16_t numBytes; ///< Size of 'pixels' buffer below - int8_t pin; ///< Output pin number (-1 if not yet set) + int16_t pin; ///< Output pin number (-1 if not yet set) uint8_t brightness; ///< Strip brightness 0-255 (stored as +1) uint8_t *pixels; ///< Holds LED color values (3 or 4 bytes each) uint8_t rOffset; ///< Red index within each 3- or 4-byte pixel From af3c2950e2a77f18e7a2c1f7393d324bbfd736a1 Mon Sep 17 00:00:00 2001 From: mikeshub Date: Sun, 28 Jul 2019 13:18:33 -0500 Subject: [PATCH 3/6] Revert "Change get pin to the right bit width" This reverts commit 578a1a0244a6e7a35dfd75652d2d707fec2666f0. --- Adafruit_NeoPixel.cpp | 4 ++-- Adafruit_NeoPixel.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Adafruit_NeoPixel.cpp b/Adafruit_NeoPixel.cpp index c9b6a5f6..79c08ab4 100644 --- a/Adafruit_NeoPixel.cpp +++ b/Adafruit_NeoPixel.cpp @@ -171,10 +171,10 @@ void Adafruit_NeoPixel::updateType(neoPixelType t) { #if defined(ESP8266) // ESP8266 show() is external to enforce ICACHE_RAM_ATTR execution extern "C" void ICACHE_RAM_ATTR espShow( - uint16_t pin, uint8_t *pixels, uint32_t numBytes, uint8_t type); + uint8_t pin, uint8_t *pixels, uint32_t numBytes, uint8_t type); #elif defined(ESP32) extern "C" void espShow( - uint16_t pin, uint8_t *pixels, uint32_t numBytes, uint8_t type); + uint8_t pin, uint8_t *pixels, uint32_t numBytes, uint8_t type); #endif // ESP8266 /*! diff --git a/Adafruit_NeoPixel.h b/Adafruit_NeoPixel.h index e8820075..c8152172 100644 --- a/Adafruit_NeoPixel.h +++ b/Adafruit_NeoPixel.h @@ -246,7 +246,7 @@ class Adafruit_NeoPixel { @brief Retrieve the pin number used for NeoPixel data output. @return Arduino pin number (-1 if not set). */ - int16_t getPin(void) const { return pin; }; + int8_t getPin(void) const { return pin; }; /*! @brief Return the number of pixels in an Adafruit_NeoPixel strip object. @return Pixel count (0 if not set). @@ -334,7 +334,7 @@ class Adafruit_NeoPixel { boolean begun; ///< true if begin() previously called uint16_t numLEDs; ///< Number of RGB LEDs in strip uint16_t numBytes; ///< Size of 'pixels' buffer below - int16_t pin; ///< Output pin number (-1 if not yet set) + int8_t pin; ///< Output pin number (-1 if not yet set) uint8_t brightness; ///< Strip brightness 0-255 (stored as +1) uint8_t *pixels; ///< Holds LED color values (3 or 4 bytes each) uint8_t rOffset; ///< Red index within each 3- or 4-byte pixel From 61b03066b032466a3c8430181bdc20c9c100aa29 Mon Sep 17 00:00:00 2001 From: mikeshub Date: Sun, 28 Jul 2019 13:27:22 -0500 Subject: [PATCH 4/6] Fix types for pin --- Adafruit_NeoPixel.cpp | 4 ++-- Adafruit_NeoPixel.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Adafruit_NeoPixel.cpp b/Adafruit_NeoPixel.cpp index 79c08ab4..783b1320 100644 --- a/Adafruit_NeoPixel.cpp +++ b/Adafruit_NeoPixel.cpp @@ -65,7 +65,7 @@ pixel. @return Adafruit_NeoPixel object. Call the begin() function before use. */ -Adafruit_NeoPixel::Adafruit_NeoPixel(uint16_t n, unit16_t p, neoPixelType t) : +Adafruit_NeoPixel::Adafruit_NeoPixel(uint16_t n, uint16_t p, neoPixelType t) : begun(false), brightness(0), pixels(NULL), endTime(0) { updateType(t); updateLength(n); @@ -2114,7 +2114,7 @@ void Adafruit_NeoPixel::show(void) { if any, is set to INPUT and the new pin is set to OUTPUT. @param p Arduino pin number (-1 = no pin). */ -void Adafruit_NeoPixel::setPin(unit16_t p) { +void Adafruit_NeoPixel::setPin(uint16_t p) { if(begun && (pin >= 0)) pinMode(pin, INPUT); pin = p; if(begun) { diff --git a/Adafruit_NeoPixel.h b/Adafruit_NeoPixel.h index c8152172..6e40e07e 100644 --- a/Adafruit_NeoPixel.h +++ b/Adafruit_NeoPixel.h @@ -195,14 +195,14 @@ class Adafruit_NeoPixel { public: // Constructor: number of LEDs, pin number, LED type - Adafruit_NeoPixel(uint16_t n, unit16_t pin=6, + Adafruit_NeoPixel(uint16_t n, uint16_t pin=6, neoPixelType type=NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel(void); ~Adafruit_NeoPixel(); void begin(void); void show(void); - void setPin(unit16_t p); + void setPin(uint16_t p); void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b); void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w); @@ -246,7 +246,7 @@ class Adafruit_NeoPixel { @brief Retrieve the pin number used for NeoPixel data output. @return Arduino pin number (-1 if not set). */ - int8_t getPin(void) const { return pin; }; + int16_t getPin(void) const { return pin; }; /*! @brief Return the number of pixels in an Adafruit_NeoPixel strip object. @return Pixel count (0 if not set). @@ -334,7 +334,7 @@ class Adafruit_NeoPixel { boolean begun; ///< true if begin() previously called uint16_t numLEDs; ///< Number of RGB LEDs in strip uint16_t numBytes; ///< Size of 'pixels' buffer below - int8_t pin; ///< Output pin number (-1 if not yet set) + int16_t pin; ///< Output pin number (-1 if not yet set) uint8_t brightness; ///< Strip brightness 0-255 (stored as +1) uint8_t *pixels; ///< Holds LED color values (3 or 4 bytes each) uint8_t rOffset; ///< Red index within each 3- or 4-byte pixel From 74b2e76e5553a04e8b95d47330b857548919bdbf Mon Sep 17 00:00:00 2001 From: mikeshub Date: Sun, 28 Jul 2019 13:31:19 -0500 Subject: [PATCH 5/6] Update esp pins for consistency in the code --- Adafruit_NeoPixel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_NeoPixel.cpp b/Adafruit_NeoPixel.cpp index 783b1320..a7142d76 100644 --- a/Adafruit_NeoPixel.cpp +++ b/Adafruit_NeoPixel.cpp @@ -171,10 +171,10 @@ void Adafruit_NeoPixel::updateType(neoPixelType t) { #if defined(ESP8266) // ESP8266 show() is external to enforce ICACHE_RAM_ATTR execution extern "C" void ICACHE_RAM_ATTR espShow( - uint8_t pin, uint8_t *pixels, uint32_t numBytes, uint8_t type); + 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, uint8_t type); + uint16_t pin, uint8_t *pixels, uint32_t numBytes, uint8_t type); #endif // ESP8266 /*! From 0f78242a630d6d0ea27be42c9f830b9d17e9bc00 Mon Sep 17 00:00:00 2001 From: mikeshub Date: Mon, 29 Jul 2019 19:22:12 -0500 Subject: [PATCH 6/6] Finish LPC1768 support Due to some confusion on my part I left this code out of the PR. --- Adafruit_NeoPixel.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++ Adafruit_NeoPixel.h | 16 ++++++++++----- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/Adafruit_NeoPixel.cpp b/Adafruit_NeoPixel.cpp index a7142d76..b795a9a8 100644 --- a/Adafruit_NeoPixel.cpp +++ b/Adafruit_NeoPixel.cpp @@ -45,6 +45,10 @@ #include "Adafruit_NeoPixel.h" +#ifdef TARGET_LPC1768 + #include +#endif + #if defined(NRF52) || defined(NRF52_SERIES) #include "nrf.h" @@ -1846,6 +1850,50 @@ void Adafruit_NeoPixel::show(void) { } #endif +#elif defined(TARGET_LPC1768) + uint8_t *ptr, *end, p, bitMask; + ptr = pixels; + end = ptr + numBytes; + p = *ptr++; + bitMask = 0x80; + +#ifdef NEO_KHZ400 // 800 KHz check needed only if 400 KHz support enabled + if(is800KHz) { +#endif + for(;;) { + if(p & bitMask) { + // data ONE high + // min: 550 typ: 700 max: 5,500 + gpio_set(pin); + time::delay_ns(550); + // min: 450 typ: 600 max: 5,000 + gpio_clear(pin); + time::delay_ns(450); + } else { + // data ZERO high + // min: 200 typ: 350 max: 500 + gpio_set(pin); + time::delay_ns(200); + // data low + // min: 450 typ: 600 max: 5,000 + gpio_clear(pin); + time::delay_ns(450); + } + if(bitMask >>= 1) { + // Move on to the next pixel + asm("nop;"); + } else { + if(ptr >= end) break; + p = *ptr++; + bitMask = 0x80; + } + } +#ifdef NEO_KHZ400 + } else { // 400 KHz bitstream + // ToDo! + } +#endif + #elif defined (NRF51) uint8_t *p = pixels, pix, count, mask; diff --git a/Adafruit_NeoPixel.h b/Adafruit_NeoPixel.h index 6e40e07e..afec9f03 100644 --- a/Adafruit_NeoPixel.h +++ b/Adafruit_NeoPixel.h @@ -36,11 +36,17 @@ #ifndef ADAFRUIT_NEOPIXEL_H #define ADAFRUIT_NEOPIXEL_H -#if (ARDUINO >= 100) - #include -#else - #include - #include +#ifdef ARDUINO + #if (ARDUINO >= 100) + #include + #else + #include + #include + #endif +#endif + +#ifdef TARGET_LPC1768 + #include #endif // The order of primary colors in the NeoPixel data stream can vary among