From e0d73d9a0666bf1c96d4176991854e8bb07e08e7 Mon Sep 17 00:00:00 2001 From: siddacious Date: Wed, 25 Mar 2020 16:43:41 -0700 Subject: [PATCH 1/2] actionified, formatted and doxy'd --- .github/workflows/githubci.yml | 32 ++++++ .travis.yml | 27 ----- LPD8806.cpp | 196 +++++++++++++++++---------------- LPD8806.h | 63 +++++------ README.md | 3 +- library.properties | 3 +- 6 files changed, 162 insertions(+), 162 deletions(-) create mode 100644 .github/workflows/githubci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml new file mode 100644 index 0000000..758f7eb --- /dev/null +++ b/.github/workflows/githubci.yml @@ -0,0 +1,32 @@ +name: Arduino Library CI + +on: [pull_request, push, repository_dispatch] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/setup-python@v1 + with: + python-version: '3.x' + - uses: actions/checkout@v2 + - uses: actions/checkout@v2 + with: + repository: adafruit/ci-arduino + path: ci + + - name: pre-install + run: bash ci/actions_install.sh + + - name: test platforms + run: python3 ci/build_platform.py main_platforms + + - name: clang + run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . + + - name: doxygen + env: + GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} + PRETTYNAME : "Adafruit LPD8806 LED Strip Library" + run: bash ci/doxy_gen_and_deploy.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e5bff4e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: c -sudo: false - -# Blacklist -branches: - except: - - gh-pages - -env: - global: - - PRETTYNAME="Adafruit LPD8806 LED Strip Library" -# Optional, will default to "$TRAVIS_BUILD_DIR/Doxyfile" -# - DOXYFILE: $TRAVIS_BUILD_DIR/Doxyfile - -before_install: - - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh) - -install: - - arduino --install-library "TimerOne" - -script: - - build_main_platforms - -# Generate and deploy documentation -after_success: - - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/library_check.sh) - - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/doxy_gen_and_deploy.sh) \ No newline at end of file diff --git a/LPD8806.cpp b/LPD8806.cpp index d8a03bb..36671f0 100644 --- a/LPD8806.cpp +++ b/LPD8806.cpp @@ -31,9 +31,9 @@ To reset the pass-through behavior and begin sending new data to the start of the strip, a number of zero bytes must be issued (remember, all color data bytes have the high bit set, thus are in the range 128 to 255, so the zero is 'special'). This should be done before each full payload of color -values to the strip. Curiously, zero bytes can only travel 32 LEDs down -the line before needing backup; the next 32 LEDs require an extra zero byte, -and so forth. Longer strips will require progressively more zeros. +values to the strip. Curiously, zero bytes can only travel 32 LEDs down +the line before needing backup; the next 32 LEDs require an extra zero byte, +and so forth. Longer strips will require progressively more zeros. *(see note below) In the interest of efficiency, it's possible to combine the former EOD @@ -70,18 +70,18 @@ a 'latch' anyway. // Teensy/Gemma-specific stuff for hardware-assisted SPI @ 2 MHz -#if(F_CPU > 8000000L) - #define SPI_DELAY asm volatile("rjmp .+0"); // Burn 2 cycles -#elif(F_CPU > 4000000L) - #define SPI_DELAY asm volatile("nop"); // Burn 1 cycle +#if (F_CPU > 8000000L) +#define SPI_DELAY asm volatile("rjmp .+0"); // Burn 2 cycles +#elif (F_CPU > 4000000L) +#define SPI_DELAY asm volatile("nop"); // Burn 1 cycle #else - #define SPI_DELAY // Run max speed +#define SPI_DELAY // Run max speed #endif -#define SPIBIT \ - USICR = ((1<>= 1) { + for (bit = 0x80; bit; bit >>= 1) { #ifdef __AVR__ - if(p & bit) *dataport |= datapinmask; - else *dataport &= ~datapinmask; - *clkport |= clkpinmask; - *clkport &= ~clkpinmask; + if (p & bit) + *dataport |= datapinmask; + else + *dataport &= ~datapinmask; + *clkport |= clkpinmask; + *clkport &= ~clkpinmask; #else - if(p & bit) digitalWrite(datapin, HIGH); - else digitalWrite(datapin, LOW); - digitalWrite(clkpin, HIGH); - digitalWrite(clkpin, LOW); + if (p & bit) + digitalWrite(datapin, HIGH); + else + digitalWrite(datapin, LOW); + digitalWrite(clkpin, HIGH); + digitalWrite(clkpin, LOW); #endif } } @@ -277,7 +284,7 @@ void LPD8806::show(void) { } /**************************************************************************/ -/*! +/*! @brief Convert separate R,G,B into combined 32-bit GRB color @param r Red value, 0-127 @param g Green value, 0-127 @@ -286,13 +293,11 @@ void LPD8806::show(void) { */ /**************************************************************************/ uint32_t LPD8806::Color(byte r, byte g, byte b) { - return ((uint32_t)(g | 0x80) << 16) | - ((uint32_t)(r | 0x80) << 8) | - b | 0x80 ; + return ((uint32_t)(g | 0x80) << 16) | ((uint32_t)(r | 0x80) << 8) | b | 0x80; } /**************************************************************************/ -/*! +/*! @brief Set pixel color from separate 7-bit R, G, B components @param n Pixel # to change (0 is first pixel) @param r Red value, 0-127 @@ -301,7 +306,7 @@ uint32_t LPD8806::Color(byte r, byte g, byte b) { */ /**************************************************************************/ void LPD8806::setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b) { - if(n < numLEDs) { // Arrays are 0-indexed, thus NOT '<=' + if (n < numLEDs) { // Arrays are 0-indexed, thus NOT '<=' uint8_t *p = &pixels[n * 3]; *p++ = g | 0x80; // Strip color order is GRB, *p++ = r | 0x80; // not the more common RGB, @@ -310,50 +315,51 @@ void LPD8806::setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b) { } /**************************************************************************/ -/*! +/*! @brief Set pixel color from 'packed' 32-bit GRB (not RGB) value @param n Pixel # to change (0 is first pixel) @param c Packed color word */ /**************************************************************************/ void LPD8806::setPixelColor(uint16_t n, uint32_t c) { - if(n < numLEDs) { // Arrays are 0-indexed, thus NOT '<=' + if (n < numLEDs) { // Arrays are 0-indexed, thus NOT '<=' uint8_t *p = &pixels[n * 3]; *p++ = (c >> 16) | 0x80; - *p++ = (c >> 8) | 0x80; - *p++ = c | 0x80; + *p++ = (c >> 8) | 0x80; + *p++ = c | 0x80; } } /**************************************************************************/ -/*! +/*! @brief Set pixel color from 'packed' 32-bit RGB value @param n Pixel # to change (0 is first pixel) @param c Packed color word */ /**************************************************************************/ void LPD8806::setPixelColorRGB(uint16_t n, uint32_t c) { - if(n < numLEDs) { // Arrays are 0-indexed, thus NOT '<=' + if (n < numLEDs) { // Arrays are 0-indexed, thus NOT '<=' uint8_t *p = &pixels[n * 3]; - *p++ = (c >> 8) | 0x80; + *p++ = (c >> 8) | 0x80; *p++ = (c >> 16) | 0x80; - *p++ = c | 0x80; + *p++ = c | 0x80; } } /**************************************************************************/ -/*! - @brief Query color from previously-set pixel (returns packed 32-bit GRB value) +/*! + @brief Query color from previously-set pixel (returns packed 32-bit GRB + value) @param n Pixel # to change (0 is first pixel) @returns Packed color word */ /**************************************************************************/ uint32_t LPD8806::getPixelColor(uint16_t n) { - if(n < numLEDs) { + if (n < numLEDs) { uint16_t ofs = n * 3; - return ((uint32_t)(pixels[ofs ] & 0x7f) << 16) | - ((uint32_t)(pixels[ofs + 1] & 0x7f) << 8) | - (uint32_t)(pixels[ofs + 2] & 0x7f); + return ((uint32_t)(pixels[ofs] & 0x7f) << 16) | + ((uint32_t)(pixels[ofs + 1] & 0x7f) << 8) | + (uint32_t)(pixels[ofs + 2] & 0x7f); } return 0; // Pixel # is out of bounds @@ -365,7 +371,7 @@ uint32_t LPD8806::getPixelColor(uint16_t n) { void LPD8806::startSPI(void) { #ifdef __AVR_ATtiny85__ PORTB &= ~(_BV(PORTB1) | _BV(PORTB2)); // Outputs - DDRB |= _BV(PORTB1) | _BV(PORTB2); // DO (NOT MOSI) + SCK + DDRB |= _BV(PORTB1) | _BV(PORTB2); // DO (NOT MOSI) + SCK #else SPI.begin(); SPI.setBitOrder(MSBFIRST); @@ -373,33 +379,33 @@ void LPD8806::startSPI(void) { // SPI bus is run at 2MHz. Although the LPD8806 should, in theory, // work up to 20MHz, the unshielded wiring from the Arduino is more // susceptible to interference. Experiment and see what you get. - #if defined(__AVR__) || defined(CORE_TEENSY) +#if defined(__AVR__) || defined(CORE_TEENSY) SPI.setClockDivider(SPI_CLOCK_DIV8); - #else +#else SPI.setClockDivider((F_CPU + 1000000L) / 2000000L); - #endif +#endif #endif // Issue initial latch/reset to strip: - for(uint16_t i=((numLEDs+31)/32); i>0; i--) spi_out(0); + for (uint16_t i = ((numLEDs + 31) / 32); i > 0; i--) + spi_out(0); } // Enable software SPI pins and issue initial latch: void LPD8806::startBitbang() { pinMode(datapin, OUTPUT); - pinMode(clkpin , OUTPUT); + pinMode(clkpin, OUTPUT); #ifdef __AVR__ *dataport &= ~datapinmask; // Data is held low throughout (latch = 0) - for(uint16_t i=((numLEDs+31)/32)*8; i>0; i--) { - *clkport |= clkpinmask; + for (uint16_t i = ((numLEDs + 31) / 32) * 8; i > 0; i--) { + *clkport |= clkpinmask; *clkport &= ~clkpinmask; } #else digitalWrite(datapin, LOW); - for(uint16_t i=((numLEDs+31)/32)*8; i>0; i--) { + for (uint16_t i = ((numLEDs + 31) / 32) * 8; i > 0; i--) { digitalWrite(clkpin, HIGH); digitalWrite(clkpin, LOW); } #endif } - diff --git a/LPD8806.h b/LPD8806.h index 9321c52..ceabac7 100644 --- a/LPD8806.h +++ b/LPD8806.h @@ -2,56 +2,43 @@ #define LPD8806_H #if (ARDUINO >= 100) - #include +#include #else - #include - #include +#include +#include #endif /**************************************************************************/ -/*! - @brief Class that stores state and functions for interacting with LPD8806 LED strips +/*! + @brief Class that stores state and functions for interacting with LPD8806 + LED strips */ /**************************************************************************/ class LPD8806 { - public: - +public: LPD8806(uint16_t n, uint8_t dpin, uint8_t cpin); // Configurable pins LPD8806(uint16_t n); // Use SPI hardware; specific pins only - LPD8806(void); // Empty constructor; init pins & strip length later - void - begin(void), - setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b), - setPixelColor(uint16_t n, uint32_t c), - setPixelColorRGB(uint16_t n, uint32_t c), - show(void), - updatePins(uint8_t dpin, uint8_t cpin), // Change pins, configurable - updatePins(void), // Change pins, hardware SPI - updateLength(uint16_t n); // Change strip length - uint16_t - numPixels(void); - uint32_t - Color(byte, byte, byte), - getPixelColor(uint16_t n); - - private: + LPD8806(void); // Empty constructor; init pins & strip length later + void begin(void), setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b), + setPixelColor(uint16_t n, uint32_t c), + setPixelColorRGB(uint16_t n, uint32_t c), show(void), + updatePins(uint8_t dpin, uint8_t cpin), // Change pins, configurable + updatePins(void), // Change pins, hardware SPI + updateLength(uint16_t n); // Change strip length + uint16_t numPixels(void); + uint32_t Color(byte, byte, byte), getPixelColor(uint16_t n); - uint16_t - numLEDs, // Number of RGB LEDs in strip - numBytes; // Size of 'pixels' buffer below - uint8_t *pixels; // Holds LED color values (3 bytes each) + latch bytes - int8_t clkpin, datapin; // Clock & data pin numbers +private: + uint16_t numLEDs, // Number of RGB LEDs in strip + numBytes; // Size of 'pixels' buffer below + uint8_t *pixels; // Holds LED color values (3 bytes each) + latch bytes + int8_t clkpin, datapin; // Clock & data pin numbers #ifdef __AVR__ - uint8_t - clkpinmask, datapinmask; // Clock & data PORT bitmasks - volatile uint8_t - *clkport , *dataport; // Clock & data PORT registers + uint8_t clkpinmask, datapinmask; // Clock & data PORT bitmasks + volatile uint8_t *clkport, *dataport; // Clock & data PORT registers #endif - void - startBitbang(void), - startSPI(void); - boolean - begun; // If 'true', begin() method was previously invoked + void startBitbang(void), startSPI(void); + boolean begun; // If 'true', begin() method was previously invoked }; #endif diff --git a/README.md b/README.md index b80e777..2159744 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# Arduino library for LPD8806 # +# Arduino library for LPD8806 [![Build Status](https://github.com/adafruit/LPD8806/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/LPD8806/actions) + This Library was written for the LPD8806 PWM LED driver chips, strips and pixels. But the LPD8803/LPD8809 will probably work too. diff --git a/library.properties b/library.properties index 970ebc3..4e99be4 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=LPD8806 -version=1.0.1 +version=1.0.2 author=Adafruit maintainer=Adafruit sentence=Arduino library for LED strips and pixels using LPD8806 (and probably LPD8803/LPD8809) @@ -7,3 +7,4 @@ paragraph=Arduino library for LED strips and pixels using LPD8806 (and probably category=Display url=https://github.com/adafruit/LPD8806 architectures=* +depends=TimerOne From cabb8d643132efd7206aefcf6ab988995f99995b Mon Sep 17 00:00:00 2001 From: siddacious Date: Mon, 30 Mar 2020 16:38:20 -0700 Subject: [PATCH 2/2] adding .test.only's --- examples/LEDbeltKit_alt/{.test.skip => .leonardo.test.only} | 0 examples/LEDbeltKit_alt/.mega2560.test.only | 0 examples/LEDbeltKit_alt/.uno.test.only | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename examples/LEDbeltKit_alt/{.test.skip => .leonardo.test.only} (100%) create mode 100644 examples/LEDbeltKit_alt/.mega2560.test.only create mode 100644 examples/LEDbeltKit_alt/.uno.test.only diff --git a/examples/LEDbeltKit_alt/.test.skip b/examples/LEDbeltKit_alt/.leonardo.test.only similarity index 100% rename from examples/LEDbeltKit_alt/.test.skip rename to examples/LEDbeltKit_alt/.leonardo.test.only diff --git a/examples/LEDbeltKit_alt/.mega2560.test.only b/examples/LEDbeltKit_alt/.mega2560.test.only new file mode 100644 index 0000000..e69de29 diff --git a/examples/LEDbeltKit_alt/.uno.test.only b/examples/LEDbeltKit_alt/.uno.test.only new file mode 100644 index 0000000..e69de29