Skip to content

Commit

Permalink
Added ESP32 support.
Browse files Browse the repository at this point in the history
Modified library so that it refuses to build on an unknown architecture
instead of building and then doing nothing.

Added ESP32 support, which might not be optimal, but seems to work for
me.
  • Loading branch information
marcmerlin committed Jan 29, 2017
1 parent a378ba7 commit 8efb431
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 7 additions & 2 deletions Adafruit_NeoPixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,13 @@ void Adafruit_NeoPixel::updateType(neoPixelType t) {
}
}

#ifdef ESP8266
#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);
#elif defined(ESP32)
extern "C" void espShow(
uint8_t pin, uint8_t *pixels, uint32_t numBytes, uint8_t type);
#endif // ESP8266

void Adafruit_NeoPixel::show(void) {
Expand Down Expand Up @@ -1411,7 +1414,7 @@ void Adafruit_NeoPixel::show(void) {
// END ARM ----------------------------------------------------------------


#elif defined(ESP8266)
#elif defined(ESP8266) || defined(ESP32)

// ESP8266 ----------------------------------------------------------------

Expand Down Expand Up @@ -1512,6 +1515,8 @@ void Adafruit_NeoPixel::show(void) {
}
}

#else
#error Architecture not supported
#endif


Expand Down
17 changes: 16 additions & 1 deletion esp8266.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// ESP8266 work for the NeoPixelBus library: github.com/Makuna/NeoPixelBus
// Needs to be a separate .c file to enforce ICACHE_RAM_ATTR execution.

#ifdef ESP8266
#if defined(ESP8266) || defined(ESP32)

#include <Arduino.h>
#ifdef ESP8266
#include <eagle_soc.h>
#endif

static uint32_t _getCycleCount(void) __attribute__((always_inline));
static inline uint32_t _getCycleCount(void) {
Expand All @@ -14,8 +16,13 @@ static inline uint32_t _getCycleCount(void) {
return ccount;
}

#ifdef ESP8266
void ICACHE_RAM_ATTR espShow(
uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) {
#else
void espShow(
uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) {
#endif

#define CYCLES_800_T0H (F_CPU / 2500000) // 0.4us
#define CYCLES_800_T1H (F_CPU / 1250000) // 0.8us
Expand Down Expand Up @@ -51,10 +58,18 @@ void ICACHE_RAM_ATTR espShow(
for(t = time0;; t = time0) {
if(pix & mask) t = time1; // Bit high duration
while(((c = _getCycleCount()) - startTime) < period); // Wait for bit start
#ifdef ESP8266
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask); // Set high
#else
gpio_set_level(pin, HIGH);
#endif
startTime = c; // Save start time
while(((c = _getCycleCount()) - startTime) < t); // Wait high duration
#ifdef ESP8266
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low
#else
gpio_set_level(pin, LOW);
#endif
if(!(mask >>= 1)) { // Next bit/byte
if(p >= end) break;
pix = *p++;
Expand Down

0 comments on commit 8efb431

Please sign in to comment.