ESPHome 2025.7.1
Loading...
Searching...
No Matches
helpers.cpp
Go to the documentation of this file.
2
3#ifdef USE_ESP8266
4
5#include <osapi.h>
6#include <user_interface.h>
7// for xt_rsil()/xt_wsr_ps()
8#include <Arduino.h>
9
10namespace esphome {
11
12uint32_t random_uint32() { return os_random(); }
13bool random_bytes(uint8_t *data, size_t len) { return os_get_random(data, len) == 0; }
14
15// ESP8266 doesn't have mutexes, but that shouldn't be an issue as it's single-core and non-preemptive OS.
16Mutex::Mutex() {}
18void Mutex::lock() {}
19bool Mutex::try_lock() { return true; }
20void Mutex::unlock() {}
21
22IRAM_ATTR InterruptLock::InterruptLock() { state_ = xt_rsil(15); }
23IRAM_ATTR InterruptLock::~InterruptLock() { xt_wsr_ps(state_); }
24
25// ESP8266 doesn't support lwIP core locking, so this is a no-op
28
29void get_mac_address_raw(uint8_t *mac) { // NOLINT(readability-non-const-parameter)
30 wifi_get_macaddr(STATION_IF, mac);
31}
32
33} // namespace esphome
34
35#endif // USE_ESP8266
void unlock()
Definition helpers.cpp:27
bool try_lock()
Definition helpers.cpp:26
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
bool random_bytes(uint8_t *data, size_t len)
Generate len number of random bytes.
Definition helpers.cpp:18
std::string size_t len
Definition helpers.h:229
uint32_t random_uint32()
Return a random 32-bit unsigned integer.
Definition helpers.cpp:17
void get_mac_address_raw(uint8_t *mac)
Get the device MAC address as raw bytes, written into the provided byte array (6 bytes).
Definition helpers.cpp:73