mirror of
https://github.com/esphome/esphome.git
synced 2024-11-29 02:04:13 +01:00
Implement different random for rp2040 (#3939)
This commit is contained in:
parent
c3fba97b4c
commit
60717b074e
1 changed files with 16 additions and 2 deletions
|
@ -23,6 +23,7 @@
|
||||||
#include <freertos/portmacro.h>
|
#include <freertos/portmacro.h>
|
||||||
#elif defined(USE_RP2040) && defined(USE_WIFI)
|
#elif defined(USE_RP2040) && defined(USE_WIFI)
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
#include <hardware/structs/rosc.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_ESP32_IGNORE_EFUSE_MAC_CRC
|
#ifdef USE_ESP32_IGNORE_EFUSE_MAC_CRC
|
||||||
|
@ -94,7 +95,12 @@ uint32_t random_uint32() {
|
||||||
#elif defined(USE_ESP8266)
|
#elif defined(USE_ESP8266)
|
||||||
return os_random();
|
return os_random();
|
||||||
#elif defined(USE_RP2040)
|
#elif defined(USE_RP2040)
|
||||||
return ((uint32_t) rand()) << 16 + ((uint32_t) rand());
|
uint32_t result = 0;
|
||||||
|
for (uint8_t i = 0; i < 32; i++) {
|
||||||
|
result <<= 1;
|
||||||
|
result |= rosc_hw->randombit;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
#else
|
#else
|
||||||
#error "No random source available for this configuration."
|
#error "No random source available for this configuration."
|
||||||
#endif
|
#endif
|
||||||
|
@ -107,7 +113,15 @@ bool random_bytes(uint8_t *data, size_t len) {
|
||||||
#elif defined(USE_ESP8266)
|
#elif defined(USE_ESP8266)
|
||||||
return os_get_random(data, len) == 0;
|
return os_get_random(data, len) == 0;
|
||||||
#elif defined(USE_RP2040)
|
#elif defined(USE_RP2040)
|
||||||
return false;
|
while (len-- != 0) {
|
||||||
|
uint8_t result = 0;
|
||||||
|
for (uint8_t i = 0; i < 8; i++) {
|
||||||
|
result <<= 1;
|
||||||
|
result |= rosc_hw->randombit;
|
||||||
|
}
|
||||||
|
*data++ = result;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
#else
|
#else
|
||||||
#error "No random source available for this configuration."
|
#error "No random source available for this configuration."
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue