Mutex misto semaforu (nutno overit)

This commit is contained in:
Pavel Brychta 2021-08-04 10:12:37 +02:00
parent acf1e80366
commit cf2b7703a8
2 changed files with 6 additions and 6 deletions

View File

@ -103,7 +103,7 @@ 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(); _mutex = xSemaphoreCreateMutex();
#endif #endif
_color[0] = _color[1] = _color[2] = 0; _color[0] = _color[1] = _color[2] = 0;
show(); show();
@ -123,7 +123,7 @@ void ICACHE_RAM_ATTR wsLED::rtLed(void)
uint32_t timing; uint32_t timing;
#if defined(ESP32) #if defined(ESP32)
xSemaphoreTakeFromISR(_semaphore, pdFALSE); xSemaphoreTake(_mutex, portMAX_DELAY);
#endif #endif
_handler.detach(); _handler.detach();
switch (_ledState) { switch (_ledState) {
@ -173,7 +173,7 @@ void ICACHE_RAM_ATTR wsLED::rtLed(void)
show(); show();
_handler.attach_ms(timing, ledTrampoline, this); _handler.attach_ms(timing, ledTrampoline, this);
#if defined(ESP32) #if defined(ESP32)
xSemaphoreGiveFromISR(_semaphore, pdFALSE); xSemaphoreGive(_mutex);
#endif #endif
} }
@ -227,7 +227,7 @@ void wsLED::pulse(LEDRGB color, uint32_t duration)
if (NOT_A_PIN != _pin) { if (NOT_A_PIN != _pin) {
#if defined(ESP32) #if defined(ESP32)
xSemaphoreTake(_semaphore, portMAX_DELAY); xSemaphoreTake(_mutex, portMAX_DELAY);
#endif #endif
_handler.detach(); _handler.detach();
_scale = 0xff; _scale = 0xff;
@ -239,7 +239,7 @@ void wsLED::pulse(LEDRGB color, uint32_t duration)
_ledState = LED_PULSE_START; _ledState = LED_PULSE_START;
_handler.attach_ms(5, ledTrampoline, this); _handler.attach_ms(5, ledTrampoline, this);
#if defined(ESP32) #if defined(ESP32)
xSemaphoreGive(_semaphore); xSemaphoreGive(_mutex);
#endif #endif
} }
} }

View File

@ -146,7 +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; SemaphoreHandle_t _mutex;
#endif #endif
void show(void); void show(void);