1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-04 20:32:21 +01:00

[core] Move platform helper implementations into their own file (#9361)

This commit is contained in:
Jesse Hills
2025-07-08 03:55:02 +12:00
committed by GitHub
parent c6f7e84256
commit 8147d117a0
7 changed files with 255 additions and 191 deletions

View File

@@ -0,0 +1,35 @@
#include "esphome/core/helpers.h"
#ifdef USE_LIBRETINY
#include "esphome/core/hal.h"
#include <WiFi.h> // for macAddress()
namespace esphome {
uint32_t random_uint32() { return rand(); }
bool random_bytes(uint8_t *data, size_t len) {
lt_rand_bytes(data, len);
return true;
}
Mutex::Mutex() { handle_ = xSemaphoreCreateMutex(); }
Mutex::~Mutex() {}
void Mutex::lock() { xSemaphoreTake(this->handle_, portMAX_DELAY); }
bool Mutex::try_lock() { return xSemaphoreTake(this->handle_, 0) == pdTRUE; }
void Mutex::unlock() { xSemaphoreGive(this->handle_); }
// only affects the executing core
// so should not be used as a mutex lock, only to get accurate timing
IRAM_ATTR InterruptLock::InterruptLock() { portDISABLE_INTERRUPTS(); }
IRAM_ATTR InterruptLock::~InterruptLock() { portENABLE_INTERRUPTS(); }
void get_mac_address_raw(uint8_t *mac) { // NOLINT(readability-non-const-parameter)
WiFi.macAddress(mac);
}
} // namespace esphome
#endif // USE_LIBRETINY