Merge pull request #3552 from TripleWhy/seedRandom16

Seed FastLED's RNG
This commit is contained in:
Blaž Kristan
2023-11-29 13:30:06 +01:00
committed by Frank
parent 68dc4d11a9
commit 451243c78d
2 changed files with 25 additions and 12 deletions

View File

@@ -735,7 +735,20 @@ void WLED::setup()
DEBUG_PRINT(pcTaskGetTaskName(NULL)); DEBUG_PRINT(F(" free stack ")); DEBUG_PRINTLN(uxTaskGetStackHighWaterMark(NULL));
#endif
// Seed FastLED random functions with an esp random value, which already works properly at this point.
#if defined(ARDUINO_ARCH_ESP32)
uint32_t seed32 = esp_random();
seed32 ^= random(); // WLEDMM some extra entropy (for older frameworks where esp_ramdom alone might be too predictable after startup)
#elif defined(ARDUINO_ARCH_ESP8266)
const uint32_t seed32 = RANDOM_REG32;
#else
const uint32_t seed32 = random(std::numeric_limits<long>::max());
#endif
random16_set_seed((uint16_t)((seed32 & 0xFFFF) ^ (seed32 >> 16)));
#if WLED_WATCHDOG_TIMEOUT > 0
enableWatchdog();
#endif
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_DISABLE_BROWNOUT_DET)
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 1); //enable brownout detector