Posledni optimalizace
This commit is contained in:
parent
d532130d0a
commit
9c5b298026
@ -3,13 +3,10 @@
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
//# include "esp_task.h"
|
||||
// https://github.com/JSchaenzle/ESP32-NeoPixel-WS2812-RMT/blob/master/ws2812_control.c
|
||||
# include <driver/rmt.h>
|
||||
# include <set>
|
||||
# ifndef LED_RMT_TX_CHANNEL
|
||||
# define LED_RMT_TX_CHANNEL RMT_CHANNEL_0
|
||||
# endif
|
||||
# define BITS_PER_LED_CMD 24
|
||||
# define LED_BUFFER_ITEMS ((1 * BITS_PER_LED_CMD))
|
||||
// These values are determined by measuring pulse timing with logic analyzer and adjusting to match datasheet.
|
||||
# define T0H 14 // 0 bit high time
|
||||
# define T1H 52 // 1 bit high time
|
||||
@ -49,17 +46,16 @@ void wsLED::show(void)
|
||||
color[i] = (uint8_t)(c >> 8);
|
||||
}
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
rmt_item32_t led_data_buffer[LED_BUFFER_ITEMS];
|
||||
|
||||
uint32_t bits_to_send = ((uint32_t)color[0] << 16) | ((uint32_t)color[1] << 8) | (uint32_t)color[2];
|
||||
uint32_t mask = 1 << (BITS_PER_LED_CMD - 1);
|
||||
for (uint32_t bit = 0; bit < BITS_PER_LED_CMD; bit++) {
|
||||
uint32_t bit_is_set = bits_to_send & mask;
|
||||
led_data_buffer[bit] = bit_is_set ? (rmt_item32_t) {{{T1H, 1, TL, 0}}} : (rmt_item32_t) {{{T0H, 1, TL, 0}}};
|
||||
|
||||
led_data_buffer[bit] = bit_is_set ? (rmt_item32_t) {{{T1H, 1, TL, 0}}} : (rmt_item32_t) {{{T0H, 1, TL, 0}}};
|
||||
mask >>= 1;
|
||||
}
|
||||
ESP_ERROR_CHECK(rmt_write_items(LED_RMT_TX_CHANNEL, led_data_buffer, LED_BUFFER_ITEMS, false));
|
||||
ESP_ERROR_CHECK(rmt_wait_tx_done(LED_RMT_TX_CHANNEL, portMAX_DELAY));
|
||||
// ESP_ERROR_CHECK(rmt_wait_tx_done(LED_RMT_TX_CHANNEL, portMAX_DELAY));
|
||||
#else
|
||||
noInterrupts();
|
||||
send_pixels_800(color, 1, _pin);
|
||||
@ -122,6 +118,7 @@ void wsLED::setColor(LEDRGB color)
|
||||
|
||||
void ICACHE_RAM_ATTR wsLED::rtLed(void)
|
||||
{
|
||||
uint32_t timing;
|
||||
|
||||
_handler.detach();
|
||||
switch (_ledState) {
|
||||
@ -132,7 +129,7 @@ void ICACHE_RAM_ATTR wsLED::rtLed(void)
|
||||
setColor(_color1);
|
||||
}
|
||||
_subState = !_subState;
|
||||
_handler.attach_ms(_blinkSpeed, ledTrampoline, this);
|
||||
timing = _blinkSpeed;
|
||||
break;
|
||||
|
||||
|
||||
@ -142,8 +139,11 @@ void ICACHE_RAM_ATTR wsLED::rtLed(void)
|
||||
uint16_t val = pgm_read_word(&LB[_subState]);
|
||||
_scale = (uint8_t)val;
|
||||
val >>= 8;
|
||||
uint32_t timing = 30ul * val;
|
||||
_handler.attach_ms(timing, ledTrampoline, this);
|
||||
timing = 30ul * val;
|
||||
if (timing < 30) {
|
||||
timing = 30;
|
||||
}
|
||||
timing = 30;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -151,20 +151,22 @@ void ICACHE_RAM_ATTR wsLED::rtLed(void)
|
||||
_ledState = _savedState;
|
||||
_subState = 0;
|
||||
setColor(_color1);
|
||||
_handler.attach_ms(5, ledTrampoline, this); // co nejrychleji do predchoziho stavu
|
||||
timing = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
case LED_PULSE_START:
|
||||
setColor(_pulseColor);
|
||||
_ledState = LED_PULSE;
|
||||
_handler.attach_ms(_pulseDuration, ledTrampoline, this);
|
||||
timing = _pulseDuration;
|
||||
break;
|
||||
|
||||
default:
|
||||
timing = 5000;
|
||||
break;
|
||||
}
|
||||
show();
|
||||
_handler.attach_ms(timing, ledTrampoline, this);
|
||||
}
|
||||
|
||||
void wsLED::setColors(LEDRGB color1, LEDRGB color2)
|
||||
@ -219,7 +221,7 @@ void wsLED::pulse(LEDRGB color, uint32_t duration)
|
||||
_handler.detach();
|
||||
_scale = 0xff;
|
||||
_pulseColor = color;
|
||||
if (LED_PULSE != _ledState) {
|
||||
if (LED_BREATH == _ledState || LED_BLINK == _ledState) {
|
||||
_savedState = _ledState;
|
||||
}
|
||||
_pulseDuration = duration;
|
||||
|
@ -23,6 +23,11 @@ See more at http://www.xpablo.cz
|
||||
#define __WSLED_H__
|
||||
#include <Arduino.h>
|
||||
#include <Ticker.h>
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
# include <driver/rmt.h>
|
||||
# define BITS_PER_LED_CMD 24
|
||||
# define LED_BUFFER_ITEMS ((1 * BITS_PER_LED_CMD))
|
||||
#endif
|
||||
|
||||
struct LEDRGB {
|
||||
union {
|
||||
@ -140,6 +145,7 @@ protected:
|
||||
LEDRGB _pulseColor;
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
int _rmtChannel;
|
||||
rmt_item32_t led_data_buffer[LED_BUFFER_ITEMS];
|
||||
#endif
|
||||
|
||||
void show(void);
|
||||
|
Loading…
Reference in New Issue
Block a user