Skip to content
Browse files

More efficient latching w/multiple instances

  • Loading branch information...
1 parent 4371852 commit 71577e841e4183a46d5dd02701a08d3e170f2710 @PaintYourDragon PaintYourDragon committed Dec 16, 2012
Showing with 7 additions and 3 deletions.
  1. +5 −3 Adafruit_NeoPixel.cpp
  2. +2 −0 Adafruit_NeoPixel.h
View
8 Adafruit_NeoPixel.cpp
@@ -44,6 +44,7 @@ Adafruit_NeoPixel::Adafruit_NeoPixel(uint16_t n, uint8_t p, uint8_t t) {
pin = p;
port = portOutputRegister(digitalPinToPort(p));
pinMask = digitalPinToBitMask(p);
+ endTime = 0L;
} else {
numLEDs = 0;
}
@@ -56,8 +57,6 @@ void Adafruit_NeoPixel::begin(void) {
void Adafruit_NeoPixel::show(void) {
- static uint32_t endTime = 0L;
-
if(!numLEDs) return;
volatile uint16_t
@@ -68,13 +67,16 @@ void Adafruit_NeoPixel::show(void) {
hi, // PORT w/output bit set high
lo; // PORT w/output bit set low
- // A 50+ microsecond pause in the output stream = data latch.
+ // Data latch = 50+ microsecond pause in the output stream.
// Rather than put a delay at the end of the function, the ending
// time is noted and the function will simply hold off (if needed)
// on issuing the subsequent round of data until the latch time has
// elapsed. This allows the mainline code to start generating the
// next frame of data rather than stalling for the latch.
while((micros() - endTime) < 50L);
+ // endTime is a private member (rather than global var) so that
+ // mutliple instances on different pins can be quickly issued in
+ // succession (each instance doesn't delay the next).
// In order to make this code runtime-configurable to work with
// any pin, SBI/CBI instructions are eschewed in favor of full
View
2 Adafruit_NeoPixel.h
@@ -61,5 +61,7 @@ class Adafruit_NeoPixel {
type; // Pixel flags (400 vs 800 KHz, RGB vs GRB color)
volatile uint8_t
*port; // Output PORT register
+ uint32_t
+ endTime; // Latch timing reference
};

0 comments on commit 71577e8

Please sign in to comment.
Something went wrong with that request. Please try again.