[core] Add more compat code
This commit is contained in:
6
arduino/libretuya/compat/md5.h
Normal file
6
arduino/libretuya/compat/md5.h
Normal file
@@ -0,0 +1,6 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2022-06-04. */
|
||||
|
||||
#pragma once
|
||||
|
||||
// lowercase "md5.h" to allow including actual MD5.h on case-sensitive OSes
|
||||
#include <MD5.h>
|
||||
@@ -15,6 +15,7 @@
|
||||
#define LT_BOARD_STR STRINGIFY_MACRO(LT_BOARD)
|
||||
|
||||
// Includes
|
||||
#include "LibreTuyaCompat.h"
|
||||
#include "LibreTuyaConfig.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
@@ -39,10 +40,6 @@ extern "C" {
|
||||
"LibreTuya v" LT_VERSION_STR " on " LT_BOARD_STR ", compiled at " __DATE__ " " __TIME__ \
|
||||
)
|
||||
|
||||
// ArduinoCore-API doesn't define these anymore
|
||||
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
|
||||
#define PGM_VOID_P const void *
|
||||
|
||||
void lt_rand_bytes(uint8_t *buf, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
33
arduino/libretuya/core/LibreTuyaCompat.cpp
Normal file
33
arduino/libretuya/core/LibreTuyaCompat.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2022-06-04. */
|
||||
|
||||
#include "LibreTuyaCompat.h"
|
||||
|
||||
#if LT_HAS_FREERTOS
|
||||
BaseType_t xTaskCreateUniversal(
|
||||
TaskFunction_t pxTaskCode,
|
||||
const char *const pcName,
|
||||
const uint32_t usStackDepth,
|
||||
void *const pvParameters,
|
||||
UBaseType_t uxPriority,
|
||||
TaskHandle_t *const pxCreatedTask,
|
||||
const BaseType_t xCoreID
|
||||
) {
|
||||
// #ifndef CONFIG_FREERTOS_UNICORE
|
||||
// if (xCoreID >= 0 && xCoreID < 2) {
|
||||
// return xTaskCreatePinnedToCore(
|
||||
// pxTaskCode,
|
||||
// pcName,
|
||||
// usStackDepth,
|
||||
// pvParameters,
|
||||
// uxPriority,
|
||||
// pxCreatedTask,
|
||||
// xCoreID
|
||||
// );
|
||||
// } else {
|
||||
// #endif
|
||||
return xTaskCreate(pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask);
|
||||
// #ifndef CONFIG_FREERTOS_UNICORE
|
||||
// }
|
||||
// #endif
|
||||
}
|
||||
#endif
|
||||
39
arduino/libretuya/core/LibreTuyaCompat.h
Normal file
39
arduino/libretuya/core/LibreTuyaCompat.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2022-06-04. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#if LT_HAS_FREERTOS
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#endif
|
||||
|
||||
// Definitions for error constants.
|
||||
#define esp_err_t int
|
||||
#define ESP_OK 0 /*!< esp_err_t value indicating success (no error) */
|
||||
#define ESP_FAIL -1 /*!< Generic esp_err_t code indicating failure */
|
||||
|
||||
// ArduinoCore-API doesn't define these anymore
|
||||
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
|
||||
#define PGM_VOID_P const void *
|
||||
#define vsnprintf_P vsnprintf
|
||||
|
||||
// FreeRTOS utilities
|
||||
#if LT_HAS_FREERTOS
|
||||
// if xCoreID < 0 or CPU is unicore, it will use xTaskCreate, else xTaskCreatePinnedToCore
|
||||
// allows to easily handle all possible situations without repetitive code
|
||||
BaseType_t xTaskCreateUniversal(
|
||||
TaskFunction_t pxTaskCode,
|
||||
const char *const pcName,
|
||||
const uint32_t usStackDepth,
|
||||
void *const pvParameters,
|
||||
UBaseType_t uxPriority,
|
||||
TaskHandle_t *const pxCreatedTask,
|
||||
const BaseType_t xCoreID
|
||||
);
|
||||
#define xTaskCreatePinnedToCore xTaskCreateUniversal
|
||||
#endif
|
||||
|
||||
// Default values from sdkconfig.h
|
||||
#define CONFIG_LWIP_MAX_ACTIVE_TCP 16
|
||||
@@ -81,6 +81,8 @@ void lt_log(const uint8_t level, const char *format, ...);
|
||||
#define ESP_EARLY_LOGI(...) LT_I(__VA_ARGS__)
|
||||
#define ESP_EARLY_LOGW(...) LT_W(__VA_ARGS__)
|
||||
#define ESP_EARLY_LOGE(...) LT_E(__VA_ARGS__)
|
||||
#define ets_printf(...) LT_I(__VA_ARGS__)
|
||||
#define ETS_PRINTF(...) LT_I(__VA_ARGS__)
|
||||
|
||||
#define LT_T_MOD(module, ...) \
|
||||
do { \
|
||||
|
||||
@@ -18,6 +18,9 @@ extern "C" {
|
||||
#define LT_MD5_CTX_T void
|
||||
#endif
|
||||
|
||||
// for compatibility with ESP8266
|
||||
typedef LT_MD5_CTX_T md5_context_t;
|
||||
|
||||
void MD5Init(LT_MD5_CTX_T *context);
|
||||
void MD5Update(LT_MD5_CTX_T *context, const unsigned char *buf, unsigned len);
|
||||
void MD5Final(unsigned char digest[16], LT_MD5_CTX_T *context);
|
||||
|
||||
@@ -49,11 +49,6 @@ env.Append(
|
||||
# which conflicts with C++ built-in bool
|
||||
# so it's either -fpermissive or this:
|
||||
("bool", "bool"),
|
||||
# enable LwIPRxBuffer
|
||||
("LT_HAS_LWIP", "1"),
|
||||
# enable LwIPmDNS
|
||||
("LT_HAS_LWIP2", "1"),
|
||||
("LT_PRINTF_BROKEN", "1"), # printf does not handle %.3f properly
|
||||
],
|
||||
LINKFLAGS=[
|
||||
"--specs=nosys.specs",
|
||||
|
||||
@@ -30,6 +30,13 @@ env.Append(
|
||||
"-fsigned-char",
|
||||
],
|
||||
CPPDEFINES=[
|
||||
# LibreTuya configuration
|
||||
("LT_HAS_LWIP", "1"),
|
||||
("LT_HAS_LWIP2", "1"),
|
||||
("LT_HAS_FREERTOS", "1"),
|
||||
("LT_HAS_MBEDTLS", "1"),
|
||||
("LT_PRINTF_BROKEN", "1"), # printf does not handle %.3f properly
|
||||
# other options
|
||||
"M3",
|
||||
"CONFIG_PLATFORM_8711B",
|
||||
# LwIP options
|
||||
|
||||
@@ -51,6 +51,7 @@ def env_add_defaults(env, family_name: str, sdk_name: str):
|
||||
"$LD_DIR",
|
||||
],
|
||||
CPPDEFINES=[
|
||||
("LIBRETUYA", "1"),
|
||||
("LT_VERSION", platform.version),
|
||||
("LT_BOARD", board.get("build.variant")),
|
||||
("F_CPU", board.get("build.f_cpu")),
|
||||
|
||||
@@ -55,3 +55,5 @@ Families should generally call i.e. WiFiClient debugging for client-related code
|
||||
|
||||
- LT_HAS_LWIP - whether family SDK has LwIP. This causes `LwIPRxBuffer.cpp` to be compiled for family libraries to use.
|
||||
- LT_HAS_LWIP2 - whether family has LwIP v2.0.0 or newer. This causes `LwIPmDNS.cpp` to be compiled.
|
||||
- LT_HAS_FREERTOS - whether family supports FreeRTOS
|
||||
- LT_HAS_MBEDTLS - whether family has mbedTLS
|
||||
|
||||
Reference in New Issue
Block a user