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 00:16:08 +02:00
committed by GitHub
parent 22c0b0abaa
commit a9630ac847
78 changed files with 6085 additions and 89 deletions
+14
View File
@@ -584,6 +584,8 @@ class EsphomeCore:
@property
def firmware_bin(self):
if self.is_libretiny:
return self.relative_pioenvs_path(self.name, "firmware.uf2")
return self.relative_pioenvs_path(self.name, "firmware.bin")
@property
@@ -602,6 +604,18 @@ class EsphomeCore:
def is_rp2040(self):
return self.target_platform == "rp2040"
@property
def is_bk72xx(self):
return self.target_platform == "bk72xx"
@property
def is_rtl87xx(self):
return self.target_platform == "rtl87xx"
@property
def is_libretiny(self):
return self.is_bk72xx or self.is_rtl87xx
@property
def is_host(self):
return self.target_platform == "host"
+1 -1
View File
@@ -380,7 +380,7 @@ async def to_code(config):
cg.add_build_flag("-Wno-unused-but-set-variable")
cg.add_build_flag("-Wno-sign-compare")
if CORE.using_arduino:
if CORE.using_arduino and not CORE.is_bk72xx:
CORE.add_job(add_arduino_global_workaround)
if config[CONF_INCLUDES]:
+4
View File
@@ -95,6 +95,10 @@
#define USE_HTTP_REQUEST_ESP8266_HTTPS
#define USE_SOCKET_IMPL_LWIP_TCP
#ifdef USE_LIBRETINY
#define USE_SOCKET_IMPL_LWIP_SOCKETS
#endif
// Dummy firmware payload for shelly_dimmer
#define USE_SHD_FIRMWARE_MAJOR_VERSION 56
#define USE_SHD_FIRMWARE_MINOR_VERSION 5
+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() {
+4 -1
View File
@@ -17,6 +17,9 @@
#if defined(USE_ESP32)
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#elif defined(USE_LIBRETINY)
#include <FreeRTOS.h>
#include <semphr.h>
#endif
#define HOT __attribute__((hot))
@@ -543,7 +546,7 @@ class Mutex {
Mutex &operator=(const Mutex &) = delete;
private:
#if defined(USE_ESP32)
#if defined(USE_ESP32) || defined(USE_LIBRETINY)
SemaphoreHandle_t handle_;
#endif
};
+3
View File
@@ -17,6 +17,9 @@
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
#include <esp32-hal-log.h>
#endif
#ifdef USE_LIBRETINY
#include <lt_logger.h>
#endif
namespace esphome {