From acf1e8036632658881d9a8eeee0f173f26df3851 Mon Sep 17 00:00:00 2001 From: Pavel Brychta Date: Wed, 4 Aug 2021 07:27:19 +0200 Subject: [PATCH] Pouziti semaforu u ESP32 --- src/wsLED.cpp | 14 ++++++++++++++ src/wsLED.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/wsLED.cpp b/src/wsLED.cpp index 3e766dc..8aae605 100644 --- a/src/wsLED.cpp +++ b/src/wsLED.cpp @@ -102,6 +102,8 @@ void wsLED::begin(void) ESP_ERROR_CHECK(rmt_config(&config)); ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0)); + + _semaphore = xSemaphoreCreateBinary(); #endif _color[0] = _color[1] = _color[2] = 0; show(); @@ -120,6 +122,9 @@ void ICACHE_RAM_ATTR wsLED::rtLed(void) { uint32_t timing; +#if defined(ESP32) + xSemaphoreTakeFromISR(_semaphore, pdFALSE); +#endif _handler.detach(); switch (_ledState) { case LED_BLINK: @@ -167,6 +172,9 @@ void ICACHE_RAM_ATTR wsLED::rtLed(void) } show(); _handler.attach_ms(timing, ledTrampoline, this); +#if defined(ESP32) + xSemaphoreGiveFromISR(_semaphore, pdFALSE); +#endif } void wsLED::setColors(LEDRGB color1, LEDRGB color2) @@ -218,6 +226,9 @@ void wsLED::pulse(LEDRGB color, uint32_t duration) { if (NOT_A_PIN != _pin) { +#if defined(ESP32) + xSemaphoreTake(_semaphore, portMAX_DELAY); +#endif _handler.detach(); _scale = 0xff; _pulseColor = color; @@ -227,6 +238,9 @@ void wsLED::pulse(LEDRGB color, uint32_t duration) _pulseDuration = duration; _ledState = LED_PULSE_START; _handler.attach_ms(5, ledTrampoline, this); +#if defined(ESP32) + xSemaphoreGive(_semaphore); +#endif } } diff --git a/src/wsLED.h b/src/wsLED.h index cb50783..258e32e 100644 --- a/src/wsLED.h +++ b/src/wsLED.h @@ -146,6 +146,7 @@ protected: #if defined(ARDUINO_ARCH_ESP32) int _rmtChannel; rmt_item32_t led_data_buffer[LED_BUFFER_ITEMS]; + SemaphoreHandle_t _semaphore; #endif void show(void);