Files
NeoPixelBus/NeoPixelesp8266uart.cpp
T

66 lines
1.7 KiB
C++
Raw Normal View History

2015-08-26 17:36:32 +01:00
/*
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 <Arduino.h>
#include <eagle_soc.h>
#include "uart_register.h"
#if defined(ESP8266)
#define UART_INV_MASK (0x3f<<19)
#define UART 1
const char data[4] = { 0b00110111, 0b00000111, 0b00110100, 0b00000100 };
2015-08-27 07:30:16 +01:00
void ICACHE_RAM_ATTR send_pixels_UART(uint8_t* pixels, uint8_t* end, bool force)
2015-08-26 17:36:32 +01:00
{
char buff[4];
2015-08-27 07:30:16 +01:00
uint8_t count = 0;
static uint8_t* position = NULL;
if (position != NULL && !force ) {
pixels = position;
} else if (position == NULL && !force ) {
return;
}
2015-08-26 17:36:32 +01:00
do
{
uint8_t subpix = *pixels++;
2015-08-27 07:30:16 +01:00
position = pixels;
count++;
2015-08-26 17:36:32 +01:00
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));
2015-08-27 07:30:16 +01:00
} while (pixels < end || count < 156 );
if ( pixels == end) { position = NULL; }
2015-08-26 17:36:32 +01:00
}
#endif