Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Garcia <danielgarcia@gmail.com>2016-01-24 07:01:51 +0300
committerDaniel Garcia <danielgarcia@gmail.com>2016-01-24 07:01:51 +0300
commit5dff1f475f4ed7895d6ac7bdd8427c5507543380 (patch)
tree8fdafcb296b70eed48b8ac33283d98d028937ed3
parent55690d683283fac76602fa8e193d886f7c174ebe (diff)
Finishing up ESP8266 support - now fully functional.
-rw-r--r--FastLED.cpp5
-rw-r--r--platforms/esp/8266/clockless_esp8266.h115
-rw-r--r--platforms/esp/8266/fastled_esp8266.h1
-rw-r--r--platforms/esp/8266/fastpin_esp8266.h3
-rw-r--r--platforms/esp/8266/led_sysdefs_esp8266.h6
5 files changed, 128 insertions, 2 deletions
diff --git a/FastLED.cpp b/FastLED.cpp
index f28c662a..f9f7ec4d 100644
--- a/FastLED.cpp
+++ b/FastLED.cpp
@@ -119,7 +119,7 @@ void CFastLED::clearData() {
void CFastLED::delay(unsigned long ms) {
unsigned long start = millis();
- do {
+ do {
#ifndef FASTLED_ACCURATE_CLOCK
// make sure to allow at least one ms to pass to ensure the clock moves
// forward
@@ -234,7 +234,10 @@ extern "C" int atexit(void (* /*func*/ )()) { return 0; }
#ifdef NEED_CXX_BITS
namespace __cxxabiv1
{
+ #ifndef ESP8266
extern "C" void __cxa_pure_virtual (void) {}
+ #endif
+
/* guard variables */
/* The ABI requires a 64-bit type. */
diff --git a/platforms/esp/8266/clockless_esp8266.h b/platforms/esp/8266/clockless_esp8266.h
new file mode 100644
index 00000000..6a7b52e2
--- /dev/null
+++ b/platforms/esp/8266/clockless_esp8266.h
@@ -0,0 +1,115 @@
+#pragma once
+
+FASTLED_NAMESPACE_BEGIN
+
+__attribute__ ((always_inline)) inline static uint32_t __clock_cycles() {
+ uint32_t cyc;
+ __asm__ __volatile__ ("rsr %0,ccount":"=a" (cyc));
+ return cyc;
+}
+
+#define FASTLED_HAS_CLOCKLESS 1
+
+template <int DATA_PIN, int T1, int T2, int T3, EOrder RGB_ORDER = RGB, int XTRA0 = 0, bool FLIP = false, int WAIT_TIME = 5>
+class ClocklessController : public CPixelLEDController<RGB_ORDER> {
+ typedef typename FastPin<DATA_PIN>::port_ptr_t data_ptr_t;
+ typedef typename FastPin<DATA_PIN>::port_t data_t;
+
+ data_t mPinMask;
+ data_ptr_t mPort;
+ CMinWait<WAIT_TIME> mWait;
+public:
+ virtual void init() {
+ FastPin<DATA_PIN>::setOutput();
+ mPinMask = FastPin<DATA_PIN>::mask();
+ mPort = FastPin<DATA_PIN>::port();
+ }
+
+ virtual uint16_t getMaxRefreshRate() const { return 400; }
+
+protected:
+
+ virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
+ //mWait.wait();
+ showRGBInternal(pixels);
+ //mWait.mark();
+ }
+
+ template<int BITS> __attribute__ ((always_inline)) inline static void writeBits(register uint32_t & next_mark, register data_ptr_t port, register data_t hi, register data_t lo, register uint8_t & b) {
+ for(register uint32_t i = BITS; i > 0; i--) {
+ while(__clock_cycles() < next_mark);
+ next_mark = __clock_cycles() + (T1+T2+T3);
+ FastPin<DATA_PIN>::hi();
+ if(b&0x80) {
+ while((next_mark - __clock_cycles()) > (T3 - 3));
+ FastPin<DATA_PIN>::lo();
+ } else {
+ while((next_mark - __clock_cycles()) > (T2+T3 - 3));
+
+ FastPin<DATA_PIN>::lo();
+ }
+ b <<= 1;
+ }
+
+ // while(__clock_cycles() < next_mark);
+ // next_mark = __clock_cycles() + (T1+T2+T3);
+ // FastPin<DATA_PIN>::hi();
+ //
+ // if(b&0x80) {
+ // while((next_mark - __clock_cycles()) > (T3+(2*(F_CPU/24000000))));
+ // FastPin<DATA_PIN>::lo();
+ // } else {
+ // while((next_mark - __clock_cycles()) > (T2+T3+(2*(F_CPU/24000000))));
+ // FastPin<DATA_PIN>::lo();
+ // }
+ }
+
+ // This method is made static to force making register Y available to use for data on AVR - if the method is non-static, then
+ // gcc will use register Y for the this pointer.
+ static uint32_t ICACHE_RAM_ATTR showRGBInternal(PixelController<RGB_ORDER> & pixels) {
+ register data_ptr_t port = FastPin<DATA_PIN>::port();
+ register data_t hi = *port | FastPin<DATA_PIN>::mask();;
+ register data_t lo = *port & ~FastPin<DATA_PIN>::mask();;
+ *port = lo;
+
+ // Setup the pixel controller and load/scale the first byte
+ pixels.preStepFirstByteDithering();
+ register uint8_t b = pixels.loadAndScale0();
+
+ os_intr_lock();
+ uint32_t start = __clock_cycles();
+ uint32_t next_mark = start + (T1+T2+T3);
+ while(pixels.has(1)) {
+ pixels.stepDithering();
+ #if (FASTLED_ALLOW_INTERRUPTS == 1)
+ os_intr_lock();
+ // if interrupts took longer than 45µs, punt on the current frame
+ if(__clock_cycles() > next_mark) {
+ if((__clock_cycles()-next_mark) > ((WAIT_TIME-INTERRUPT_THRESHOLD)*CLKS_PER_US)) { sei(); return __clock_cycles(); }
+ }
+
+ hi = *port | FastPin<DATA_PIN>::mask();
+ lo = *port & ~FastPin<DATA_PIN>::mask();
+ #endif
+ // Write first byte, read next byte
+ writeBits<8+XTRA0>(next_mark, port, hi, lo, b);
+ b = pixels.loadAndScale1();
+
+ // Write second byte, read 3rd byte
+ writeBits<8+XTRA0>(next_mark, port, hi, lo, b);
+ b = pixels.loadAndScale2();
+
+ // Write third byte, read 1st byte of next pixel
+ writeBits<8+XTRA0>(next_mark, port, hi, lo, b);
+ b = pixels.advanceAndLoadAndScale0();
+ #if (FASTLED_ALLOW_INTERRUPTS == 1)
+ os_intr_unlock();
+ #endif
+ };
+
+ os_intr_unlock();
+ return __clock_cycles();
+ }
+};
+
+FASTLED_NAMESPACE_END
diff --git a/platforms/esp/8266/fastled_esp8266.h b/platforms/esp/8266/fastled_esp8266.h
index eda245f5..9a9ee06b 100644
--- a/platforms/esp/8266/fastled_esp8266.h
+++ b/platforms/esp/8266/fastled_esp8266.h
@@ -2,3 +2,4 @@
#include "fastled_delay.h"
#include "fastpin_esp8266.h"
+#include "clockless_esp8266.h"
diff --git a/platforms/esp/8266/fastpin_esp8266.h b/platforms/esp/8266/fastpin_esp8266.h
index 6b9b5e7a..7c1edce2 100644
--- a/platforms/esp/8266/fastpin_esp8266.h
+++ b/platforms/esp/8266/fastpin_esp8266.h
@@ -1,5 +1,6 @@
#pragma once
+FASTLED_NAMESPACE_BEGIN
template<uint8_t PIN, uint32_t MASK> class _ESPPIN {
@@ -40,3 +41,5 @@ _DEFPIN_ESP8266(12); _DEFPIN_ESP8266(13); _DEFPIN_ESP8266(14); _DEFPIN_ESP8266(1
_DEFPIN_ESP8266(16);
#define HAS_HARDWARE_PIN_SUPPORT
+
+#define FASTLED_NAMESPACE_END
diff --git a/platforms/esp/8266/led_sysdefs_esp8266.h b/platforms/esp/8266/led_sysdefs_esp8266.h
index b9b3376c..382717af 100644
--- a/platforms/esp/8266/led_sysdefs_esp8266.h
+++ b/platforms/esp/8266/led_sysdefs_esp8266.h
@@ -20,7 +20,11 @@ typedef uint8_t boolean;
#endif
#ifndef FASTLED_ALLOW_INTERRUPTS
-#define FASTLED_ALLOW_INTERRUPTS 0
+#define FASTLED_ALLOW_INTERRUPTS 1
+#define INTERRUPT_THRESHOLD 1
#endif
#define NEED_CXX_BITS
+
+// #define cli() os_intr_lock();
+// #define sei() os_intr_lock();