diff --git a/lib/libesp32/berry/default/be_modtab.c b/lib/libesp32/berry/default/be_modtab.c new file mode 100644 index 000000000000..e4f60edcc939 --- /dev/null +++ b/lib/libesp32/berry/default/be_modtab.c @@ -0,0 +1,353 @@ +/******************************************************************** +** Copyright (c) 2018-2020 Guan Wenliang +** This file is part of the Berry default interpreter. +** skiars@qq.com, https://github.com/Skiars/berry +** See Copyright Notice in the LICENSE file or at +** https://github.com/Skiars/berry/blob/master/LICENSE +********************************************************************/ +#include "berry.h" +#include "../../berry_custom/src/modules.h" + +/* this file contains the declaration of the module table. */ + +/* default modules declare */ +be_extern_native_module(string); +be_extern_native_module(json); +be_extern_native_module(math); +be_extern_native_module(time); +be_extern_native_module(os); +be_extern_native_module(global); +be_extern_native_module(sys); +be_extern_native_module(debug); +be_extern_native_module(gc); +be_extern_native_module(solidify); +be_extern_native_module(introspect); +be_extern_native_module(strict); +be_extern_native_module(undefined); + +/* Berry extensions */ +be_extern_native_module(cb); + +/* Tasmota specific */ +be_extern_native_module(python_compat); +be_extern_native_module(re); +be_extern_native_module(mqtt); +be_extern_native_module(persist); +be_extern_native_module(autoconf); +be_extern_native_module(tapp); +be_extern_native_module(light); +be_extern_native_module(gpio); +be_extern_native_module(display); +be_extern_native_module(energy); +be_extern_native_module(webserver); +be_extern_native_module(flash); +be_extern_native_module(path); +be_extern_native_module(unishox); +be_extern_native_module(hue_ntv); +be_extern_native_module(hue_bridge); +be_extern_native_module(uuid); +be_extern_native_module(animate); +be_extern_native_module(partition_core); +be_extern_native_module(crc); +be_extern_native_module(crypto); +be_extern_native_module(ULP); +be_extern_native_module(TFL); +be_extern_native_module(mdns); +#ifdef USE_ZIGBEE +be_extern_native_module(zigbee); +be_extern_native_module(matter_zigbee); +#endif // USE_ZIGBEE +#ifdef USE_BERRY_CAM +be_extern_native_module(cam); +#endif // USE_BERRY_CAM +// BLE +be_extern_native_module(MI32); +be_extern_native_module(BLE); +#ifdef USE_LVGL +be_extern_native_module(lv); +be_extern_native_module(lv_extra); +be_extern_native_module(lv_tasmota); +#ifdef USE_LVGL_HASPMOTA +be_extern_native_module(haspmota); +#endif // USE_LVGL_HASPMOTA +#endif // USE_LVGL +#ifdef USE_MATTER_DEVICE +be_extern_native_module(matter); +#endif // USE_MATTER_DEVICE + +/* user-defined modules declare start */ + +/* user-defined modules declare end */ + +/* module list declaration */ +BERRY_LOCAL const bntvmodule_t* const be_module_table[] = { +/* default modules register */ +#if BE_USE_STRING_MODULE + &be_native_module(string), +#endif +#if BE_USE_JSON_MODULE + &be_native_module(json), +#endif +#if BE_USE_MATH_MODULE + &be_native_module(math), +#endif +#if BE_USE_TIME_MODULE + &be_native_module(time), +#endif +#if BE_USE_OS_MODULE + &be_native_module(os), +#endif +#if BE_USE_GLOBAL_MODULE + &be_native_module(global), +#endif +#if BE_USE_SYS_MODULE + &be_native_module(sys), +#endif +#if BE_USE_DEBUG_MODULE + &be_native_module(debug), +#endif +#if BE_USE_GC_MODULE + &be_native_module(gc), +#endif +#if BE_USE_SOLIDIFY_MODULE + &be_native_module(solidify), +#endif +#if BE_USE_INTROSPECT_MODULE + &be_native_module(introspect), +#endif +#if BE_USE_STRICT_MODULE + &be_native_module(strict), +#endif + &be_native_module(undefined), + + &be_native_module(re), +#ifdef TASMOTA + /* Berry extensions */ + &be_native_module(cb), + + /* user-defined modules register start */ + + &be_native_module(python_compat), + &be_native_module(path), + &be_native_module(mqtt), + &be_native_module(persist), +#ifdef USE_AUTOCONF + &be_native_module(autoconf), +#endif // USE_AUTOCONF + &be_native_module(tapp), + &be_native_module(gpio), +#ifdef USE_DISPLAY + &be_native_module(display), +#endif // USE_DISPLAY +#ifdef USE_LIGHT + &be_native_module(light), +#endif +#if defined(USE_EMULATION) && defined(USE_EMULATION_HUE) + &be_native_module(hue_ntv), + &be_native_module(hue_bridge), +#endif + + &be_native_module(uuid), +#ifdef USE_UNISHOX_COMPRESSION + &be_native_module(unishox), +#endif // USE_UNISHOX_COMPRESSION + +#ifdef USE_WS2812 + &be_native_module(animate), +#endif // USE_WS2812 + +#ifdef USE_LVGL + &be_native_module(lv), + &be_native_module(lv_extra), + &be_native_module(lv_tasmota), +#ifdef USE_LVGL_HASPMOTA + &be_native_module(haspmota), +#endif // USE_LVGL_HASPMOTA +#endif // USE_LVGL +#ifdef USE_ENERGY_SENSOR + &be_native_module(energy), +#endif // USE_ENERGY_SENSOR +#ifdef USE_WEBSERVER + &be_native_module(webserver), +#endif // USE_WEBSERVER +#ifdef USE_ZIGBEE + &be_native_module(zigbee), + &be_native_module(matter_zigbee), +#endif // USE_ZIGBEE + &be_native_module(flash), + &be_native_module(partition_core), + &be_native_module(crc), + &be_native_module(crypto), +#if defined(USE_BERRY_ULP) && ((CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)) + &be_native_module(ULP), +#endif // USE_BERRY_ULP +#if defined(USE_BERRY_TF_LITE) + &be_native_module(TFL), +#endif //USE_BERRY_TF_LITE +#if defined(USE_MI_ESP32) && !defined(USE_BLE_ESP32) + &be_native_module(MI32), + &be_native_module(BLE), +#endif //USE_MI_ESP32 +#ifdef USE_BERRY_CAM + &be_native_module(cam), +#endif +#ifdef USE_DISCOVERY + &be_native_module(mdns), +#endif // USE_DISCOVERY +#ifdef USE_MATTER_DEVICE + &be_native_module(matter), +#endif // USE_MATTER_DEVICE +#endif // TASMOTA + CUSTOM_NATIVE_MODULES + /* user-defined modules register end */ + NULL /* do not remove */ +}; + +be_extern_native_class(dyn); +be_extern_native_class(tasmota); +be_extern_native_class(Trigger); +be_extern_native_class(Driver); +be_extern_native_class(ctypes_bytes); +be_extern_native_class(ctypes_bytes_dyn); +be_extern_native_class(serial); +be_extern_native_class(ccronexpr); +be_extern_native_class(tasmota_log_reader); +be_extern_native_class(light_state); +be_extern_native_class(Wire); +be_extern_native_class(I2C_Driver); +be_extern_native_class(AXP192); +be_extern_native_class(AXP202); +be_extern_native_class(OneWire); +be_extern_native_class(Leds_ntv); +be_extern_native_class(Leds); +be_extern_native_class(AudioGenerator); +be_extern_native_class(AudioFileSource); +be_extern_native_class(AudioOutputI2S); +be_extern_native_class(AudioGeneratorWAV); +be_extern_native_class(AudioGeneratorMP3); +be_extern_native_class(AudioFileSourceFS); +be_extern_native_class(AudioOpusDecoder); +be_extern_native_class(AudioInputI2S); +be_extern_native_class(md5); +be_extern_native_class(udp); +be_extern_native_class(webclient); +be_extern_native_class(tcpclient); +be_extern_native_class(tcpclientasync); +be_extern_native_class(webserver_async); +be_extern_native_class(tcpserver); +be_extern_native_class(energy_struct); +// LVGL core classes +be_extern_native_class(lv_color); +be_extern_native_class(lv_font); +be_extern_native_class(LVGL_glob); +// LVGL custom classes +be_extern_native_class(lv_signal_bars); +be_extern_native_class(lv_wifi_bars); +be_extern_native_class(lv_wifi_bars_icon); +be_extern_native_class(lv_signal_arcs); +be_extern_native_class(lv_wifi_arcs); +be_extern_native_class(lv_wifi_arcs_icon); +be_extern_native_class(lv_clock); +be_extern_native_class(lv_clock_icon); + +be_extern_native_class(int64); + +#ifdef USE_BERRY_IMAGE +be_extern_native_class(img); +#endif // USE_BERRY_IMAGE + +BERRY_LOCAL bclass_array be_class_table = { +#ifdef TASMOTA + /* first list are direct classes */ + &be_native_class(dyn), + &be_native_class(tasmota), + &be_native_class(Trigger), + &be_native_class(Driver), + &be_native_class(serial), + &be_native_class(ccronexpr), + &be_native_class(ctypes_bytes), + &be_native_class(ctypes_bytes_dyn), + &be_native_class(tasmota_log_reader), +#ifdef USE_LIGHT + &be_native_class(light_state), +#endif +#if defined(USE_ONEWIRE) || defined(USE_DS18x20) + &be_native_class(OneWire), +#endif +#ifdef USE_I2C + &be_native_class(Wire), + &be_native_class(I2C_Driver), + &be_native_class(AXP192), + &be_native_class(AXP202), +#endif // USE_I2C + &be_native_class(md5), +#ifdef USE_WEBCLIENT + &be_native_class(udp), + &be_native_class(webclient), + &be_native_class(tcpclient), + &be_native_class(tcpclientasync), +#ifdef USE_BERRY_DEBUG + &be_native_class(webserver_async), // include only when USE_BERRY_DEBUG is enabled +#endif // USE_BERRY_DEBUG +#endif // USE_WEBCLIENT +#ifdef USE_BERRY_TCPSERVER + &be_native_class(tcpserver), +#endif // USE_BERRY_TCPSERVER +#ifdef USE_WS2812 + &be_native_class(Leds_ntv), + &be_native_class(Leds), +#endif // USE_WS2812 +#ifdef USE_ENERGY_SENSOR + &be_native_class(energy_struct), +#endif // USE_ENERGY_SENSOR + +#ifdef USE_LVGL + &be_native_class(LVGL_glob), + + &be_native_class(lv_signal_bars), + &be_native_class(lv_wifi_bars), + &be_native_class(lv_wifi_bars_icon), + &be_native_class(lv_signal_arcs), + &be_native_class(lv_wifi_arcs), + &be_native_class(lv_wifi_arcs_icon), + &be_native_class(lv_clock), + &be_native_class(lv_clock_icon), +#endif // USE_LVGL + +#ifdef USE_BERRY_IMAGE + &be_native_class(img), +#endif // USE_BERRY_IMAGE + +#if defined(USE_I2S_AUDIO_BERRY) && (ESP_IDF_VERSION_MAJOR >= 5) + &be_native_class(AudioGenerator), + &be_native_class(AudioFileSource), + &be_native_class(AudioOutputI2S), + &be_native_class(AudioGeneratorWAV), + &be_native_class(AudioGeneratorMP3), +#ifdef USE_UFILESYS + &be_native_class(AudioFileSourceFS), +#endif // USE_UFILESYS + &be_native_class(AudioOpusDecoder), + &be_native_class(AudioInputI2S), +#endif // defined(USE_I2S_AUDIO_BERRY) && (ESP_IDF_VERSION_MAJOR >= 5) +#endif // TASMOTA + +#if defined(USE_BERRY_INT64) || defined(USE_MATTER_DEVICE) + &be_native_class(int64), +#endif + CUSTOM_NATIVE_CLASSES + NULL, /* do not remove */ +}; + +extern void be_load_ctypes_energy_definitions_lib(bvm *vm); + +/* this code loads the native class definitions */ +BERRY_API void be_load_custom_libs(bvm *vm) +{ + (void)vm; /* prevent a compiler warning */ + + /* add here custom libs */ +#if !BE_USE_PRECOMPILED_OBJECT + /* be_load_xxxlib(vm); */ +#endif +} diff --git a/lib/libesp32/berry/default/berry_conf.h b/lib/libesp32/berry/default/berry_conf.h new file mode 100644 index 000000000000..13200f530993 --- /dev/null +++ b/lib/libesp32/berry/default/berry_conf.h @@ -0,0 +1,323 @@ +/******************************************************************** +** Copyright (c) 2018-2020 Guan Wenliang +** This file is part of the Berry default interpreter. +** skiars@qq.com, https://github.com/Skiars/berry +** See Copyright Notice in the LICENSE file or at +** https://github.com/Skiars/berry/blob/master/LICENSE +********************************************************************/ +#ifndef BERRY_CONF_H +#define BERRY_CONF_H + +#include + +#ifdef COMPILE_BERRY_LIB + #include "my_user_config.h" + #include "include/tasmota_configurations.h" +#endif + +/* Macro: BE_DEBUG + * Berry interpreter debug switch. + * Default: 0 + **/ +#ifndef BE_DEBUG +#define BE_DEBUG 0 +#endif + +/* Macro: BE_LONGLONG_INT + * Select integer length. + * If the value is 0, use an integer of type int, use a long + * integer type when the value is 1, and use a long long integer + * type when the value is 2. + * Default: 2 + */ +#ifdef TASMOTA +#define BE_INTGER_TYPE 1 // use long int = uint32_t +#else +#define BE_INTGER_TYPE 0 +#endif + +/* Macro: BE_USE_SINGLE_FLOAT + * Select floating point precision. + * Use double-precision floating-point numbers when the value + * is 0 (default), otherwise use single-precision floating-point + * numbers. + * Default: 0 + **/ +#define BE_USE_SINGLE_FLOAT 1 // use `float` not `double` + +/* Macro: BE_BYTES_MAX_SIZE + * Maximum size in bytes of a `bytes()` object. + * Putting too much pressure on the memory allocator can do + * harm, so we limit the maximum size. + * Default: 32kb + **/ +#define BE_BYTES_MAX_SIZE (32*1024) /* 32 kb default value */ + +/* Macro: BE_USE_PRECOMPILED_OBJECT + * Use precompiled objects to avoid creating these objects at + * runtime. Enable this macro can greatly optimize RAM usage. + * Default: 1 + **/ +#define BE_USE_PRECOMPILED_OBJECT 1 + +/* Macro: BE_DEBUG_SOURCE_FILE + * Indicate if each function remembers its source file name + * 0: do not keep the file name (saves 4 bytes per function) + * 1: keep the source file name + * Default: 1 + **/ +#define BE_DEBUG_SOURCE_FILE 0 + +/* Macro: BE_DEBUG_RUNTIME_INFO + * Set runtime error debugging information. + * 0: unable to output source file and line number at runtime. + * 1: output source file and line number information at runtime. + * 2: the information use uint16_t type (save space). + * Default: 1 + **/ +#define BE_DEBUG_RUNTIME_INFO 0 + +/* Macro: BE_DEBUG_VAR_INFO + * Set variable debugging tracking information. + * 0: disable variable debugging tracking information at runtime. + * 1: enable variable debugging tracking information at runtime. + * Default: 1 + **/ +#define BE_DEBUG_VAR_INFO 0 + +/* Macro: BE_USE_PERF_COUNTERS + * Use the obshook function to report low-level actions. + * Default: 0 + **/ +#define BE_USE_PERF_COUNTERS 1 + +/* Macro: BE_VM_OBSERVABILITY_SAMPLING + * If BE_USE_PERF_COUNTERS == 1 + * then the observability hook is called regularly in the VM loop + * allowing to stop infinite loops or too-long running code. + * The value is a power of 2. + * Default: 20 - which translates to 2^20 or ~1 million instructions + **/ +#define BE_VM_OBSERVABILITY_SAMPLING 20 + +/* Macro: BE_STACK_TOTAL_MAX + * Set the maximum total stack size. + * Default: 20000 + **/ +#define BE_STACK_TOTAL_MAX 8000 + +/* Macro: BE_STACK_FREE_MIN + * Set the minimum free count of the stack. The stack idles will + * be checked when a function is called, and the stack will be + * expanded if the number of free is less than BE_STACK_FREE_MIN. + * Default: 10 + **/ +#define BE_STACK_FREE_MIN 20 + +/* Macro: BE_STACK_START + * Set the starting size of the stack at VM creation. + * Default: 50 + **/ +#define BE_STACK_START 100 + +/* Macro: BE_CONST_SEARCH_SIZE + * Constants in function are limited to 255. However the compiler + * will look for a maximum of pre-existing constants to avoid + * performance degradation. This may cause the number of constants + * to be higher than required. + * Increase is you need to solidify functions. + * Default: 50 + **/ +#define BE_CONST_SEARCH_SIZE 150 + +/* Macro: BE_STACK_FREE_MIN + * The short string will hold the hash value when the value is + * true. It may be faster but requires more RAM. + * Default: 0 + **/ +#define BE_USE_STR_HASH_CACHE 0 + +/* Macro: BE_USE_FILE_SYSTEM + * The file system interface will be used when this macro is true + * or when using the OS module. Otherwise the file system interface + * will not be used. + * Default: 0 + **/ +#ifdef TASMOTA +#define BE_USE_FILE_SYSTEM 0 +#else +#define BE_USE_FILE_SYSTEM 1 +#endif + +/* Macro: BE_USE_SCRIPT_COMPILER + * Enable compiler when BE_USE_SCRIPT_COMPILER is not 0, otherwise + * disable the compiler. + * Default: 1 + **/ +#define BE_USE_SCRIPT_COMPILER 1 + +/* Macro: BE_USE_BYTECODE_SAVER + * Enable save bytecode to file when BE_USE_BYTECODE_SAVER is not 0, + * otherwise disable the feature. + * Default: 1 + **/ +#define BE_USE_BYTECODE_SAVER 1 + +/* Macro: BE_USE_BYTECODE_LOADER + * Enable load bytecode from file when BE_USE_BYTECODE_LOADER is not 0, + * otherwise disable the feature. + * Default: 1 + **/ +#define BE_USE_BYTECODE_LOADER 1 + +/* Macro: BE_USE_SHARED_LIB + * Enable shared library when BE_USE_SHARED_LIB is not 0, + * otherwise disable the feature. + * Default: 1 + **/ +#define BE_USE_SHARED_LIB 0 + +/* Macro: BE_USE_OVERLOAD_HASH + * Allows instances to overload hash methods for use in the + * built-in Map class. Disable this feature to crop the code + * size. + * Default: 1 + **/ +#define BE_USE_OVERLOAD_HASH 1 + +/* Macro: BE_USE_DEBUG_HOOK + * Berry debug hook switch. + * Default: 0 + **/ +#define BE_USE_DEBUG_HOOK 0 + +/* Macro: BE_USE_DEBUG_GC + * Enable GC debug mode. This causes an actual gc after each + * allocation. It's much slower and should not be used + * in production code. + * Default: 0 + **/ +#define BE_USE_DEBUG_GC 0 + +/* Macro: BE_USE_DEBUG_STACK + * Enable Stack Resize debug mode. At each function call + * the stack is reallocated at a different memory location + * and the previous location is cleared with toxic data. + * Default: 0 + **/ +#define BE_USE_DEBUG_STACK 0 + +/* Macro: BE_USE_MEM_ALIGNED + * Some embedded processors have special memory areas + * with read/write constraints of being aligned to 32 bits boundaries. + * This options tries to move such memory areas to this region. + * Default: 0 + **/ +#ifdef TASMOTA +#define BE_USE_MEM_ALIGNED 1 +#else +#define BE_USE_MEM_ALIGNED 0 +#endif + +/* Macro: BE_USE_XXX_MODULE + * These macros control whether the related module is compiled. + * When they are true, they will enable related modules. At this + * point you can use the import statement to import the module. + * They will not compile related modules when they are false. + **/ + +#ifdef TASMOTA + #define BE_USE_STRING_MODULE 1 + #define BE_USE_JSON_MODULE 1 + #define BE_USE_MATH_MODULE 1 + #define BE_USE_TIME_MODULE 0 + #define BE_USE_OS_MODULE 0 + #define BE_USE_GLOBAL_MODULE 1 + #define BE_USE_SYS_MODULE 1 + #define BE_USE_DEBUG_MODULE 0 + #define BE_USE_GC_MODULE 1 + #define BE_USE_SOLIDIFY_MODULE 0 + #define BE_USE_INTROSPECT_MODULE 1 + #define BE_USE_STRICT_MODULE 1 +#else + #define BE_USE_STRING_MODULE 1 + #define BE_USE_JSON_MODULE 1 + #define BE_USE_MATH_MODULE 1 + #define BE_USE_TIME_MODULE 1 + #define BE_USE_OS_MODULE 1 + #define BE_USE_GLOBAL_MODULE 1 + #define BE_USE_SYS_MODULE 1 + #define BE_USE_DEBUG_MODULE 1 + #define BE_USE_GC_MODULE 1 + #define BE_USE_SOLIDIFY_MODULE 1 + #define BE_USE_INTROSPECT_MODULE 1 + #define BE_USE_STRICT_MODULE 1 +#endif + +#if defined(USE_BERRY_DEBUG) || !defined(TASMOTA) + #undef BE_USE_DEBUG_MODULE + #undef BE_USE_SOLIDIFY_MODULE + #define BE_USE_DEBUG_MODULE 1 + #define BE_USE_SOLIDIFY_MODULE 1 +#endif // USE_BERRY_DEBUG + +/* Macro: BE_EXPLICIT_XXX + * If these macros are defined, the corresponding function will + * use the version defined by these macros. These macro definitions + * are not required. + * The default is to use the functions in the standard library. + **/ +#ifdef __cplusplus +extern "C" { +#endif + extern void *berry_malloc(size_t size); + extern void berry_free(void *ptr); + extern void *berry_realloc(void *ptr, size_t size); + extern void *berry_malloc32(size_t size); +#ifdef __cplusplus +} +#endif +#ifdef USE_BERRY_PSRAM + #define BE_EXPLICIT_MALLOC berry_malloc + #define BE_EXPLICIT_FREE berry_free + #define BE_EXPLICIT_REALLOC berry_realloc +#else + #define BE_EXPLICIT_MALLOC malloc + #define BE_EXPLICIT_FREE free + #define BE_EXPLICIT_REALLOC realloc +#endif // USE_BERRY_PSRAM + +#define BE_EXPLICIT_ABORT abort +#define BE_EXPLICIT_EXIT exit +// #define BE_EXPLICIT_MALLOC malloc +// #define BE_EXPLICIT_FREE free +// #define BE_EXPLICIT_REALLOC realloc + +/* Macro: be_assert + * Berry debug assertion. Only enabled when BE_DEBUG is active. + * Default: use the assert() function of the standard library. + **/ +#define be_assert(expr) assert(expr) + +/* Tasmota debug specific */ +#ifdef USE_BERRY_DEBUG + #undef BE_DEBUG_RUNTIME_INFO + #define BE_DEBUG_RUNTIME_INFO 1 /* record line information in 32 bits to be places in IRAM */ + #undef BE_DEBUG + #define BE_DEBUG 1 + #undef be_assert + #define be_assert(expr) \ + ((expr) \ + ? (0) \ + : serial_debug("BRY: ASSERT '%s', %s - %i\n", #expr, __FILE__, __LINE__)) + #ifdef USE_LVGL + #undef BE_STACK_START + #define BE_STACK_START 200 + #endif // USE_LVGL + #ifdef USE_MATTER_DEVICE + #undef BE_STACK_START + #define BE_STACK_START 256 + #endif // USE_MATTER_DEVICE +#endif // USE_BERRY_DEBUG + +#endif