Skip to content

Commit

Permalink
Add working Neopixel library code from @ellensp
Browse files Browse the repository at this point in the history
  • Loading branch information
Floppy committed Jun 26, 2021
1 parent c3a55ee commit 3907a4e
Show file tree
Hide file tree
Showing 8 changed files with 3,036 additions and 4 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ tags
.piolibdeps
.clang_complete
.gcc-flags.json
/lib/

# Secure Credentials
Configuration_Secure.h
Expand Down
2 changes: 1 addition & 1 deletion ini/features.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ HAS_TMC26X = TMC26XStepper=https://github.com/trinam
src_filter=+<src/module/TMC26X.cpp>
HAS_L64XX = Arduino-L6470@0.8.0
src_filter=+<src/libs/L64XX> +<src/module/stepper/L64xx.cpp> +<src/gcode/feature/L6470> +<src/HAL/shared/HAL_spi_L6470.cpp>
NEOPIXEL_LED = adafruit/Adafruit NeoPixel@~1.8.0
NEOPIXEL_LED = Adafruit NeoPixel
src_filter=+<src/feature/leds/neopixel.cpp>
TEMP_.+_IS_MAX31865 = Adafruit MAX31865 library@~1.1.0
I2C_AMMETER = peterus/INA226Lib@1.1.2
Expand Down
1 change: 0 additions & 1 deletion ini/stm32f1.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ build_unflags = -std=gnu++11
src_filter = ${common.default_src_filter} +<src/HAL/STM32> +<src/HAL/shared/backtrace>
extra_scripts = ${common.extra_scripts}
pre:buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py
custom_marlin.NEOPIXEL_LED = Adafruit NeoPixel=https://github.com/ellensp/Adafruit_NeoPixel

[common_STM32F103RC]
platform = ${common_stm32.platform}
Expand Down
2,585 changes: 2,585 additions & 0 deletions lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp

Large diffs are not rendered by default.

357 changes: 357 additions & 0 deletions lib/Adafruit_NeoPixel/Adafruit_NeoPixel.h

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions lib/Adafruit_NeoPixel/esp8266.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// This is a mash-up of the Due show() code + insights from Michael Miller's
// ESP8266 work for the NeoPixelBus library: github.com/Makuna/NeoPixelBus
// Needs to be a separate .c file to enforce ICACHE_RAM_ATTR execution.

#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) {
uint32_t ccount;
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
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
#define CYCLES_800 (F_CPU / 800000) // 1.25us per bit
#define CYCLES_400_T0H (F_CPU / 2000000) // 0.5uS
#define CYCLES_400_T1H (F_CPU / 833333) // 1.2us
#define CYCLES_400 (F_CPU / 400000) // 2.5us per bit

uint8_t *p, *end, pix, mask;
uint32_t t, time0, time1, period, c, startTime, pinMask;

pinMask = _BV(pin);
p = pixels;
end = p + numBytes;
pix = *p++;
mask = 0x80;
startTime = 0;

#ifdef NEO_KHZ400
if(is800KHz) {
#endif
time0 = CYCLES_800_T0H;
time1 = CYCLES_800_T1H;
period = CYCLES_800;
#ifdef NEO_KHZ400
} else { // 400 KHz bitstream
time0 = CYCLES_400_T0H;
time1 = CYCLES_400_T1H;
period = CYCLES_400;
}
#endif

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++;
mask = 0x80;
}
}
while((_getCycleCount() - startTime) < period); // Wait for last bit
}

#endif // ESP8266
9 changes: 9 additions & 0 deletions lib/Adafruit_NeoPixel/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=Adafruit NeoPixel
version=1.2.4
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for controlling single-wire-based LED pixels and strip.
paragraph=Arduino library for controlling single-wire-based LED pixels and strip.
category=Display
url=https://github.com/adafruit/Adafruit_NeoPixel
architectures=*
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

[platformio]
src_dir = Marlin
lib_dir = lib
boards_dir = buildroot/share/PlatformIO/boards
default_envs = STM32F103RC_btt_USB
include_dir = Marlin
Expand Down Expand Up @@ -44,7 +45,7 @@ extra_scripts =
pre:buildroot/share/PlatformIO/scripts/common-cxxflags.py
pre:buildroot/share/PlatformIO/scripts/preflight-checks.py
post:buildroot/share/PlatformIO/scripts/common-dependencies-post.py
lib_deps =
lib_deps = Adafruit NeoPixel
default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
-<src/lcd/HD44780> -<src/lcd/TFTGLCD> -<src/lcd/dwin> -<src/lcd/dogm> -<src/lcd/tft> -<src/lcd/tft_io>
-<src/HAL/STM32/tft> -<src/HAL/STM32F1/tft>
Expand Down

0 comments on commit 3907a4e

Please sign in to comment.