Update on Library support (eg FastLED)

It is likely that the initial port of the library will only be available for people doing the direct build on device. Some of the conventions that SparkCore wants for libraries are differetn enough from the rest of the platforms that I support that I need to think about the best way to manage this so that I don’t have to worry about maintaining two sets of file trees.

I’ll keep this thread updated with the progress as I go through the porting of the library. For reference, there’s a handful of platform specific pieces that need to be ported:

  • FastPin - this is the low level direct pin access that the library uses to do 1-2 cycle pin access
  • FastSPI - this is the direct hardware access to SPI that is used for the various SPI based led chipsets
  • Clockless - this is the low level implementation for the 3-wire led - fairly heavily timer dependent

The rest of FastLED builds on top of this - all the specific led chipset implementations, the math libraries, etc… build on all of that.

Well, I have FastPin ported, and judging by the disassembly, it is working right. However, the loop code in my test app isn’t getting called. Until I get that resolved I’m pretty stopped from being able to move to the next level of porting the library. I opened up a post about that here - https://community.spark.io/t/loop-not-getting-called/9897

I have the pins working now, just need to sanity test/check all of them and i’ll update the code on the branch. This will give a working library for SPI based led chipsets (as the library will be able to use bit-banging to drive the SPI based chipsets) while I work on the hardware SPI support and the clockless support - but roughly, what I am doing is:

cd core-firmware/libraries
git clone https://github.com/FastLED/FastLED.git
cd FastLED
git checkout sparkcore
cd ../../build

in the build directory, edit the makefile and add the following line:

INCLUDE_DIRS += $(LIB_CORE_LIBRARIES_PATH)FastLED

# Include FastLED library code
CPPSRC += $(call target_files,$(LIB_CORE_LIBRARIES_PATH)FastLED,*.cpp)
CSRC += $(call target_files,$(LIB_CORE_LIBRARIES_PATH)FastLED,*.c)

below the similar line for Serial2. et. voila! Now you can use:

#Include <FastLED.h>
FASTLED_USING_NAMESPACE

in code to include and use the library. (Note the addition of the using namespace declaration, FastLED on the sparkcore is namespace’d at the moment).

@dgarcia, I am glad you are progressing on this important port! If I may, I encourage you to use the feature/HAL branch for developing & testing your code as this will become the new master as the Photon goes live. Both the Core and the Photon will use the HAL foundation going forwared. :smile:

1 Like

Ok - i'll try flipping over to that branch after I finish getting the hardware SPI and clockless support. (Note: FastLED is fairly bare metal when it comes to talking to pins and peripherals. I haven't yet looked at the data sheet for the chip behind the Photon, but I wouldn't be surprised if I needed to tweak things a bit - I doubt you folks are using the same pin<-->port mappings between the Photon and SparkCore : ) Unfortunately, given the nature of how the library works with the hardware, until I have a Photon I can't really verify anything other than building for the Photon at the moment.

In the meantime, for everyone else following this issue - I just got first light with a SparkCore and the APA102 led chipset. The library now works with all data/clock based chipsets (albeit via bit-banging at the moment). Note the updates to my comment above on changes to the makefile that are necessary for the time being.

2 Likes

@dgarcia, there is a PIN_MAP[] array which has the port/pin mapping for the Core and eventually, the Photon (in spark_wiring.cpp if I remember). It could be used to build whole-port(s) bitmasks for optimized port writes like what you are doing.

You might get some ideas from here:

https://community.particle.io/t/some-reusable-macros-and-stuff/8846?redirected=true

I am aware of the PIN_MAP array, however that won’t give me the 1-3 cycle (depending on write times to the I/O registers which I haven’t looked up yet) access times that I want/need that I get doing the mapping at compile time with FastPin. Sadly, the link you provided goes to a private topic that I don’t have access to.

With my direct pin access I’m pushing 5-7 Mbps with bit-bang’d SPI, and could probably get more with some more targeted optimizations.

@dgarcia, sorry about the link. Given what you are doing, I don’t think there is anything there of value anyway. Glad to see you are getting good softSPI speeds! Let me know if I can be of any help :smile:

And the library now fully supports the 3-wire chipsets (WS2812, etc…) as well. So, functionally, it is complete now - what’s left is optimization/tuning (including bringing hardware SPI support online). Now I need to figure out the best way to juggle SparkCore’s desire for everything to be in a firmware directory with all the other supported platforms. Are there examples of libraries that do this - or do people just setup a separate, sparkcore specific repository?

@dgarcia, if you are referring to the IDE library format then it IS unique to the Core. The library format is being reconsidered for Spark CLI and DEV so changes are in the wind. In the meantime, you will have to use the firmware directory approach. I would be glad to assist getting your (fantastic) library onto the IDE if you need help. :slight_smile:

It looks like it isn’t just the firmware directory - the ide doesn’t seem to handle libraries that have a directory structure (FastLED currently supports multiple AVR Platforms and at least five distinct ARM platforms - so I broke out all the platform specific code into directories so that I had a prayer of managing it). Trying to work around it now.

All that said - A beta version of the library is now up in the IDE - it isn’t showing up in the search yet but it looks like this works as a direct link to it - https://www.spark.io/libs/54d93ec543768ef54d000449 - known issues:

  • Different #include syntax than every other platform
  • Need to add a macro to get a reference to the namespace the library uses (this macro is effectively empty for platforms that aren’t using
  • SPI based chipsets aren’t using the hardware SPI channel yet
  • WS2811/WS2812 output and friends are currently disabling interrupts. This should be a temporary thing.
4 Likes

Thanks Daniel!

Do the interrupts get re-enabled once the write to the LEDs is complete? I’m thinking of a case in a program I’m working on where I have timer driven interrupts that are not time critical (so I could handle missing a trigger) but I don’t want to turn off.

Yes, I re-enable the interrupts once the led data is finished being written out. I can possibly do code to allow interrupts to be enabled while writing out the led data (basically, re-enable interrupts between each LED, and if more than 10µs pass because of interrupt handling then punt writing out the frame, however I don’t yet trust the interrupt handlers on the spark core to be that lightweight).

Thanks for the clarification. That helps. No need to change things (based on my use case). I just wanted to know what to expect.

Hello Daniel,

Thanks for your work on this! I only had a few minutes before work this morning, but just got a simple blink example running on my Spark Core using FastLED to drive a LPD8806 strip. Quick question: You say you are not using the hardware SPI channel yet. I’ve used the pins defined on the Spark for SPI (SCK=A3, MOSI=A5) and this is working fine. Is this the right way to do this?

Bongo

Dan’s on a well-deserved vacation, but I think I speak for him when I say “if it’s working, you’re doing it right.”

Also I suspect that by using the HW SPI pins, you’ll get additional speedup “for free” if (when) FastLED adds HW SPI support on SparkCore. We already have hardware SPI support in FastLED on ARM SAM (Due/DigiX), ARM K20 (Teensy 3), the nRF51822 (RFduino) ARM SoC, and of course various AVR MCUs, too. ARM STM32 (SparkCore) will come, too.

Thanks for giving it a spin, and please continue to let us know how it goes!

1 Like

Good morning FastLED wizards!

Yesterday code was compiling fine with FastLED, but today I am getting these compile errors - here testing with your analogoutput.ino example.

Bongo

In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/FastLED.cpp:2:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/colorpalettes.cpp:4:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/colorutils.cpp:6:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/hsv2rgb.cpp:4:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/lib8tion.cpp:3:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/noise.cpp:2:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/power_mgt.cpp:2:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/wiring.cpp:2:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from analogoutput.cpp:1:0:
FastLED/FastLED.h:12:2: warning: #warning FastLED version 3001000 (Not really a warning, just telling you here.) [-Wcpp]
#warning FastLED version 3001000 (Not really a warning, just telling you here.)
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from analogoutput.cpp:1:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
analogoutput.cpp:3:27: error: 'CRGB' does not name a type
void showAnalogRGB( const CRGB& rgb);
^
analogoutput.cpp:3:33: error: ISO C++ forbids declaration of 'rgb' with no type [-fpermissive]
void showAnalogRGB( const CRGB& rgb);
^
make: *** [analogoutput.o] Error 1

Hi- half of the FastLED wizards are out of the country at the moment.

What FastLED examples DO work for you with the SparkCore-- any? Or have they all stopped working now, suddenly?

(My theory: I believe that SparkCore requires special #include setup etc, and the standard FastLED examples are probably not updated yet. )

@kriegsman, Thanks for courtesy of responding. I’ve been away from this board for a few days, so sorry for my slow reply.

I cannot get any FastLED example to work with the SparkCore. And I was having no trouble with a number of simple sketches using FastLED a few days before.

As I understand it, once you include the FastLED library in the SparkCore IDE, which inserts the first of the following lines in your code, you need to add the second of these lines for the library to work.

#include "FastLED/FastLED.h"
FASTLED_USING_NAMESPACE;

Since 6 days ago, I can’t get anything which uses this to compile. Prior to that this same approach worked fine.

Bongo