Support for LibreTiny platform (RTL8710, BK7231 & other modules) (#3509)

Co-authored-by: Kuba Szczodrzyński <kuba@szczodrzynski.pl>
Co-authored-by: Sam Neirinck <git@samneirinck.com>
Co-authored-by: David Buezas <dbuezas@users.noreply.github.com>
Co-authored-by: Stroe Andrei Catalin <catalin2402@gmail.com>
Co-authored-by: Sam Neirinck <github@samneirinck.be>
Co-authored-by: Péter Sárközi <xmisterhu@gmail.com>
Co-authored-by: Hajo Noerenberg <hn@users.noreply.github.com>
This commit is contained in:
Kuba Szczodrzyński
2023-09-05 10:16:08 +12:00
committed by GitHub
co-authored by Sam Neirinck David Buezas Stroe Andrei Catalin Sam Neirinck Péter Sárközi Hajo Noerenberg
parent 22c0b0abaa
commit a9630ac847
78 changed files with 6085 additions and 89 deletions
+13 -2
View File
@@ -43,6 +43,10 @@
#include "esp_efuse_table.h"
#endif
#ifdef USE_LIBRETINY
#include <WiFi.h> // for macAddress()
#endif
namespace esphome {
static const char *const TAG = "helpers";
@@ -190,6 +194,8 @@ uint32_t random_uint32() {
result |= rosc_hw->randombit;
}
return result;
#elif defined(USE_LIBRETINY)
return rand();
#elif defined(USE_HOST)
std::random_device dev;
std::mt19937 rng(dev());
@@ -216,6 +222,9 @@ bool random_bytes(uint8_t *data, size_t len) {
*data++ = result;
}
return true;
#elif defined(USE_LIBRETINY)
lt_rand_bytes(data, len);
return true;
#elif defined(USE_HOST)
FILE *fp = fopen("/dev/urandom", "r");
if (fp == nullptr) {
@@ -503,7 +512,7 @@ Mutex::Mutex() {}
void Mutex::lock() {}
bool Mutex::try_lock() { return true; }
void Mutex::unlock() {}
#elif defined(USE_ESP32)
#elif defined(USE_ESP32) || defined(USE_LIBRETINY)
Mutex::Mutex() { handle_ = xSemaphoreCreateMutex(); }
void Mutex::lock() { xSemaphoreTake(this->handle_, portMAX_DELAY); }
bool Mutex::try_lock() { return xSemaphoreTake(this->handle_, 0) == pdTRUE; }
@@ -513,7 +522,7 @@ void Mutex::unlock() { xSemaphoreGive(this->handle_); }
#if defined(USE_ESP8266)
IRAM_ATTR InterruptLock::InterruptLock() { state_ = xt_rsil(15); }
IRAM_ATTR InterruptLock::~InterruptLock() { xt_wsr_ps(state_); }
#elif defined(USE_ESP32)
#elif defined(USE_ESP32) || defined(USE_LIBRETINY)
// 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(); }
@@ -555,6 +564,8 @@ void get_mac_address_raw(uint8_t *mac) { // NOLINT(readability-non-const-parame
wifi_get_macaddr(STATION_IF, mac);
#elif defined(USE_RP2040) && defined(USE_WIFI)
WiFi.macAddress(mac);
#elif defined(USE_LIBRETINY)
WiFi.macAddress(mac);
#endif
}
std::string get_mac_address() {