Pouziti semaforu u ESP32

This commit is contained in:
Pavel Brychta 2021-08-04 07:27:19 +02:00
parent bb9f036dec
commit acf1e80366
2 changed files with 15 additions and 0 deletions

View File

@ -102,6 +102,8 @@ void wsLED::begin(void)
ESP_ERROR_CHECK(rmt_config(&config)); ESP_ERROR_CHECK(rmt_config(&config));
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0)); ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0));
_semaphore = xSemaphoreCreateBinary();
#endif #endif
_color[0] = _color[1] = _color[2] = 0; _color[0] = _color[1] = _color[2] = 0;
show(); show();
@ -120,6 +122,9 @@ void ICACHE_RAM_ATTR wsLED::rtLed(void)
{ {
uint32_t timing; uint32_t timing;
#if defined(ESP32)
xSemaphoreTakeFromISR(_semaphore, pdFALSE);
#endif
_handler.detach(); _handler.detach();
switch (_ledState) { switch (_ledState) {
case LED_BLINK: case LED_BLINK:
@ -167,6 +172,9 @@ void ICACHE_RAM_ATTR wsLED::rtLed(void)
} }
show(); show();
_handler.attach_ms(timing, ledTrampoline, this); _handler.attach_ms(timing, ledTrampoline, this);
#if defined(ESP32)
xSemaphoreGiveFromISR(_semaphore, pdFALSE);
#endif
} }
void wsLED::setColors(LEDRGB color1, LEDRGB color2) 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 (NOT_A_PIN != _pin) {
#if defined(ESP32)
xSemaphoreTake(_semaphore, portMAX_DELAY);
#endif
_handler.detach(); _handler.detach();
_scale = 0xff; _scale = 0xff;
_pulseColor = color; _pulseColor = color;
@ -227,6 +238,9 @@ void wsLED::pulse(LEDRGB color, uint32_t duration)
_pulseDuration = duration; _pulseDuration = duration;
_ledState = LED_PULSE_START; _ledState = LED_PULSE_START;
_handler.attach_ms(5, ledTrampoline, this); _handler.attach_ms(5, ledTrampoline, this);
#if defined(ESP32)
xSemaphoreGive(_semaphore);
#endif
} }
} }

View File

@ -146,6 +146,7 @@ protected:
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
int _rmtChannel; int _rmtChannel;
rmt_item32_t led_data_buffer[LED_BUFFER_ITEMS]; rmt_item32_t led_data_buffer[LED_BUFFER_ITEMS];
SemaphoreHandle_t _semaphore;
#endif #endif
void show(void); void show(void);