diff --git a/library.json b/library.json index b96c313..eaac257 100644 --- a/library.json +++ b/library.json @@ -1,4 +1,4 @@ { "name": "WSLed", - "version": "0.0.0+20210128092328" + "version": "0.0.2" } \ No newline at end of file diff --git a/src/NeoPixelesp8266.c b/src/NeoPixelesp8266.c index 6de8525..25c59aa 100644 --- a/src/NeoPixelesp8266.c +++ b/src/NeoPixelesp8266.c @@ -24,16 +24,14 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP8266) #include -#if defined(ARDUINO_ARCH_ESP8266) -# include -# if (ARDUINO_ESP8266_MAJOR < 3) -# define INRAM ICACHE_RAM_ATTR -# else -# define INRAM IRAM_ATTR -# endif +#include +#if (ARDUINO_ESP8266_MAJOR < 3) +# define INRAM ICACHE_RAM_ATTR +#else +# define INRAM IRAM_ATTR #endif // ESP32 doesn't define ICACHE_RAM_ATTR @@ -87,11 +85,7 @@ void INRAM send_pixels_800(uint8_t* pixels, size_t count, uint8_t pin) } while ((cyclesStart - cyclesNext) < CYCLES_800); // set high -#if defined(ARDUINO_ARCH_ESP32) - GPIO.out_w1ts = pinRegister; -#else GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister); -#endif // wait for the LOW do @@ -100,13 +94,9 @@ void INRAM send_pixels_800(uint8_t* pixels, size_t count, uint8_t pin) } while ((cyclesNext - cyclesStart) < cyclesBit); // set low -#if defined(ARDUINO_ARCH_ESP32) - GPIO.out_w1tc = pinRegister; -#else GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister); -#endif } } while (pixels < end); } -#endif +#endif \ No newline at end of file diff --git a/src/wsLED.cpp b/src/wsLED.cpp index 42ff905..d684f06 100644 --- a/src/wsLED.cpp +++ b/src/wsLED.cpp @@ -1,5 +1,5 @@ // Ovladani signalizacni chytre LED diody -#include "wsLED.h" +#include "wsLED.hpp" #if defined(ARDUINO_ARCH_ESP32) //# include "esp_task.h" // https://github.com/JSchaenzle/ESP32-NeoPixel-WS2812-RMT/blob/master/ws2812_control.c @@ -8,9 +8,10 @@ # define LED_RMT_TX_CHANNEL RMT_CHANNEL_0 # endif // 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 -# define TL 52 // low time for either bit +# define T0H 16 // 0 bit high time +# define T1H 32 // 1 bit high time +# define T0L 34 // 0 bit low time +# define T1L 18 // 1 bit low time # define INRAM IRAM_ATTR #endif #if defined(ARDUINO_ARCH_ESP8266) @@ -65,29 +66,30 @@ void wsLED::show(void) 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, T1L, 0}}} : (rmt_item32_t) {{{T0H, 1, T0L, 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)); + _endtime = micros() + 100; // TODO: unfortunately this time is not valid for ESP32 using RMT peripheral #else noInterrupts(); send_pixels_800(color, 1, _pin); interrupts(); -#endif _endtime = micros(); +#endif } - wsLED::wsLED(int pin, int order) : _pin(pin) , _order(order) + , _scale(0xff) , _ledState(LED_STOP) {} wsLED::wsLED(void) : _pin(NOT_A_PIN) , _order(RGB) + , _scale(0xff) , _ledState(LED_STOP) {} @@ -121,8 +123,6 @@ void wsLED::begin(void) ESP_ERROR_CHECK(rmt_config(&config)); ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0)); - - _mutex = xSemaphoreCreateMutex(); #endif _color[0] = _color[1] = _color[2] = 0; show(); @@ -141,9 +141,6 @@ void INRAM wsLED::rtLed(void) { uint32_t timing; -#if defined(ESP32) - xSemaphoreTake(_mutex, portMAX_DELAY); -#endif _handler.detach(); switch (_ledState) { case LED_BLINK: @@ -156,7 +153,6 @@ void INRAM wsLED::rtLed(void) timing = _blinkSpeed; break; - case LED_BREATH: { ++_subState; _subState %= countof(LB); @@ -191,9 +187,6 @@ void INRAM wsLED::rtLed(void) } show(); _handler.attach_ms(timing, ledTrampoline, this); -#if defined(ESP32) - xSemaphoreGive(_mutex); -#endif } void wsLED::setColors(LEDRGB color1, LEDRGB color2) @@ -211,18 +204,12 @@ void wsLED::blink(uint32_t speed) if (NOT_A_PIN != _pin) { if (LED_BLINK != _ledState) { -#if defined(ESP32) - xSemaphoreTake(_mutex, portMAX_DELAY); -#endif _handler.detach(); _ledState = LED_BLINK; _scale = 0xff; _subState = 1; _blinkSpeed = speed; _handler.attach_ms(5, ledTrampoline, this); -#if defined(ESP32) - xSemaphoreGive(_mutex); -#endif } } } @@ -232,17 +219,11 @@ void wsLED::breath(void) if (NOT_A_PIN != _pin) { if (LED_BREATH != _ledState) { -#if defined(ESP32) - xSemaphoreTake(_mutex, portMAX_DELAY); -#endif _handler.detach(); _ledState = LED_BREATH; _subState = 0; setColor(_color1); _handler.attach_ms(5, ledTrampoline, this); -#if defined(ESP32) - xSemaphoreGive(_mutex); -#endif } } } @@ -257,9 +238,6 @@ void wsLED::pulse(LEDRGB color, uint32_t duration) { if (NOT_A_PIN != _pin) { -#if defined(ESP32) - xSemaphoreTake(_mutex, portMAX_DELAY); -#endif _handler.detach(); _scale = 0xff; _pulseColor = color; @@ -269,9 +247,6 @@ void wsLED::pulse(LEDRGB color, uint32_t duration) _pulseDuration = duration; _ledState = LED_PULSE_START; _handler.attach_ms(5, ledTrampoline, this); -#if defined(ESP32) - xSemaphoreGive(_mutex); -#endif } } @@ -281,14 +256,14 @@ ledstate_t wsLED::getState(void) return _ledState; } -void wsLED::stop(void) +void wsLED::stop(LEDRGB color) { if (NOT_A_PIN != _pin) { _handler.detach(); _ledState = LED_STOP; _scale = 0xff; - setColor(LEDRGB(0, 0, 0)); + setColor(color); show(); } } diff --git a/src/wsLED.h b/src/wsLED.hpp similarity index 96% rename from src/wsLED.h rename to src/wsLED.hpp index 67c38a9..2838bdc 100644 --- a/src/wsLED.h +++ b/src/wsLED.hpp @@ -19,8 +19,7 @@ SOFTWARE. See more at http://www.xpablo.cz */ -#ifndef __WSLED_H__ -#define __WSLED_H__ +#pragma once #include #include #if defined(ARDUINO_ARCH_ESP32) @@ -146,16 +145,12 @@ protected: #if defined(ARDUINO_ARCH_ESP32) int _rmtChannel; rmt_item32_t led_data_buffer[LED_BUFFER_ITEMS]; - SemaphoreHandle_t _mutex; #endif uint32_t _endtime; void show(void); void setColor(LEDRGB color); bool canShow(void); -#if defined(ARDUINO_ARCH_ESP32) - portMUX_TYPE _mux = portMUX_INITIALIZER_UNLOCKED; -#endif public: wsLED(int pin, int order = RGB); @@ -169,8 +164,5 @@ public: void setOrder(int neworder); ledstate_t getState(void); void pulse(LEDRGB color, uint32_t duration); - void stop(void); + void stop(LEDRGB color = LEDRGB(0, 0, 0)); }; - -#endif -