ESPHome 2025.7.1
Loading...
Searching...
No Matches
helpers.cpp
Go to the documentation of this file.
2
3#ifdef USE_LIBRETINY
4
5#include "esphome/core/hal.h"
6
7#include <WiFi.h> // for macAddress()
8
9namespace esphome {
10
11uint32_t random_uint32() { return rand(); }
12
13bool random_bytes(uint8_t *data, size_t len) {
14 lt_rand_bytes(data, len);
15 return true;
16}
17
18Mutex::Mutex() { handle_ = xSemaphoreCreateMutex(); }
20void Mutex::lock() { xSemaphoreTake(this->handle_, portMAX_DELAY); }
21bool Mutex::try_lock() { return xSemaphoreTake(this->handle_, 0) == pdTRUE; }
22void Mutex::unlock() { xSemaphoreGive(this->handle_); }
23
24// only affects the executing core
25// so should not be used as a mutex lock, only to get accurate timing
26IRAM_ATTR InterruptLock::InterruptLock() { portDISABLE_INTERRUPTS(); }
27IRAM_ATTR InterruptLock::~InterruptLock() { portENABLE_INTERRUPTS(); }
28
29// LibreTiny doesn't support lwIP core locking, so this is a no-op
32
33void get_mac_address_raw(uint8_t *mac) { // NOLINT(readability-non-const-parameter)
34 WiFi.macAddress(mac);
35}
36
37} // namespace esphome
38
39#endif // USE_LIBRETINY
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