Skip to content

Commit

Permalink
Merge pull request #197 from mikeshub/32-bit-fix
Browse files Browse the repository at this point in the history
Change pin arguments to 16 bits from at for 32 bit uC compatibility
  • Loading branch information
PaintYourDragon authored Jul 30, 2019
2 parents e12ccce + 0f78242 commit 5239de8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 13 deletions.
56 changes: 52 additions & 4 deletions Adafruit_NeoPixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@

#include "Adafruit_NeoPixel.h"

#ifdef TARGET_LPC1768
#include <time.h>
#endif

#if defined(NRF52) || defined(NRF52_SERIES)
#include "nrf.h"

Expand All @@ -65,7 +69,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, uint16_t p, neoPixelType t) :
begun(false), brightness(0), pixels(NULL), endTime(0) {
updateType(t);
updateLength(n);
Expand Down Expand Up @@ -171,10 +175,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

/*!
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2114,7 +2162,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(uint16_t p) {
if(begun && (pin >= 0)) pinMode(pin, INPUT);
pin = p;
if(begun) {
Expand Down
24 changes: 15 additions & 9 deletions Adafruit_NeoPixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@
#ifndef ADAFRUIT_NEOPIXEL_H
#define ADAFRUIT_NEOPIXEL_H

#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#include <pins_arduino.h>
#ifdef ARDUINO
#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#include <pins_arduino.h>
#endif
#endif

#ifdef TARGET_LPC1768
#include <Arduino.h>
#endif

// The order of primary colors in the NeoPixel data stream can vary among
Expand Down Expand Up @@ -195,14 +201,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, uint16_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(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);
Expand Down Expand Up @@ -246,7 +252,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).
Expand Down Expand Up @@ -334,7 +340,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
Expand Down

0 comments on commit 5239de8

Please sign in to comment.