From e620850707cdc4c20f048216a061f2c6a4eb1828 Mon Sep 17 00:00:00 2001 From: Andrew Melvin Date: Wed, 26 Aug 2015 17:36:32 +0100 Subject: [PATCH] Moved to external cpp file --- NeoPixelBus.cpp | 5 ++++ NeoPixelBus.h | 1 + NeoPixelesp8266.c | 12 +++++++++ NeoPixelesp8266uart.cpp | 54 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 NeoPixelesp8266uart.cpp diff --git a/NeoPixelBus.cpp b/NeoPixelBus.cpp index a3971bc..4d08f24 100644 --- a/NeoPixelBus.cpp +++ b/NeoPixelBus.cpp @@ -42,11 +42,14 @@ License along with NeoPixel. If not, see #define UART_INV_MASK (0x3f<<19) #define UART 1 + extern void ICACHE_RAM_ATTR send_pixels_UART(uint8_t* pixels, uint8_t* end); + #else // due to linker overriding the ICACHE_RAM_ATTR for cpp files, these methods are // moved into a C file so the attribute will be applied correctly extern "C" void ICACHE_RAM_ATTR send_pixels_800(uint8_t* pixels, uint8_t* end, uint8_t pin); extern "C" void ICACHE_RAM_ATTR send_pixels_400(uint8_t* pixels, uint8_t* end, uint8_t pin); + #endif #endif @@ -782,6 +785,8 @@ void NeoPixelBus::Show(void) send_pixels_800(p, end, _pin); #else + send_pixels_UART(p, end); + char buff[4]; do diff --git a/NeoPixelBus.h b/NeoPixelBus.h index b29e349..0d9bc93 100644 --- a/NeoPixelBus.h +++ b/NeoPixelBus.h @@ -37,6 +37,7 @@ License along with NeoPixel. If not, see // NeoPixelBus library include to support the slower bus speeds //#define INCLUDE_NEO_KHZ400_SUPPORT + class NeoPixelBus { public: diff --git a/NeoPixelesp8266.c b/NeoPixelesp8266.c index 3766067..91cd2bc 100644 --- a/NeoPixelesp8266.c +++ b/NeoPixelesp8266.c @@ -36,6 +36,18 @@ inline uint32_t _getCycleCount() #define CYCLES_400_T1H (F_CPU / 833333) #define CYCLES_400 (F_CPU / 400000) +#define UART_INV_MASK (0x3f<<19) +#define UART 1 + +#include "eagle_soc.h" +#include "uart_register.h" + + +const char data[4] = { 0b00110111, 0b00000111, 0b00110100, 0b00000100 }; + + + + void ICACHE_RAM_ATTR send_pixels_800(uint8_t* pixels, uint8_t* end, uint8_t pin) { const uint32_t pinRegister = _BV(pin); diff --git a/NeoPixelesp8266uart.cpp b/NeoPixelesp8266uart.cpp new file mode 100644 index 0000000..3be509b --- /dev/null +++ b/NeoPixelesp8266uart.cpp @@ -0,0 +1,54 @@ +/* +NeoPixelEsp8266.h - NeoPixel library helper functions for Esp8266 using cycle count +Copyright (c) 2015 Michael C. Miller. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include +#include +#include "uart_register.h" + + +#if defined(ESP8266) + + +#define UART_INV_MASK (0x3f<<19) +#define UART 1 + + + +const char data[4] = { 0b00110111, 0b00000111, 0b00110100, 0b00000100 }; + + +void ICACHE_RAM_ATTR send_pixels_UART(uint8_t* pixels, uint8_t* end) +{ + char buff[4]; + + do + { + uint8_t subpix = *pixels++; + + buff[0] = data[(subpix >> 6) & 3]; + buff[1] = data[(subpix >> 4) & 3]; + buff[2] = data[(subpix >> 2) & 3]; + buff[3] = data[subpix & 3]; + Serial1.write(buff, sizeof(buff)); + + } while (pixels < end); + +} + +#endif \ No newline at end of file