From 329fa2492824a491508bc7ca69bac94b2fa07db5 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sat, 24 Apr 2021 12:11:06 +0200 Subject: [PATCH] Berry conditional compile for modules --- lib/libesp32/Berry/default/be_energylib.c | 4 ++++ lib/libesp32/Berry/default/be_gpio_lib.c | 2 +- lib/libesp32/Berry/default/be_light_lib.c | 4 +++- lib/libesp32/Berry/default/be_modtab.c | 10 +++++++-- lib/libesp32/Berry/default/be_wirelib.c | 4 ++++ lib/libesp32/Berry/default/berry_conf.h | 6 ----- tasmota/xdrv_52_3_berry_energy.ino | 14 ++++++------ tasmota/xdrv_52_3_berry_light.ino | 14 +++++------- tasmota/xdrv_52_3_berry_wire.ino | 27 +++++++---------------- tasmota/xdrv_52_7_berry_embedded.ino | 2 ++ 10 files changed, 43 insertions(+), 44 deletions(-) diff --git a/lib/libesp32/Berry/default/be_energylib.c b/lib/libesp32/Berry/default/be_energylib.c index 020766460..24400e85e 100644 --- a/lib/libesp32/Berry/default/be_energylib.c +++ b/lib/libesp32/Berry/default/be_energylib.c @@ -7,6 +7,8 @@ *******************************************************************/ #include "be_object.h" +#ifdef USE_ENERGY_SENSOR + extern int b_nrg_read(bvm *vm); // #if !BE_USE_PRECOMPILED_OBJECT @@ -24,3 +26,5 @@ module tasmota (scope: global, depend: 1) { @const_object_info_end */ #include "../generate/be_fixed_tasmota.h" #endif + +#endif // USE_ENERGY_SENSOR \ No newline at end of file diff --git a/lib/libesp32/Berry/default/be_gpio_lib.c b/lib/libesp32/Berry/default/be_gpio_lib.c index 1aa4cc771..e52a50cdd 100644 --- a/lib/libesp32/Berry/default/be_gpio_lib.c +++ b/lib/libesp32/Berry/default/be_gpio_lib.c @@ -290,7 +290,7 @@ be_native_module_attr_table(gpio) { be_define_native_module(gpio, NULL); #else /* @const_object_info_begin -module gpio (scope: global, depend: BE_USE_TASMOTA) { +module gpio (scope: global) { LOW, int(0) HIGH, int(1) diff --git a/lib/libesp32/Berry/default/be_light_lib.c b/lib/libesp32/Berry/default/be_light_lib.c index 95f6baf13..28e95e6cc 100644 --- a/lib/libesp32/Berry/default/be_light_lib.c +++ b/lib/libesp32/Berry/default/be_light_lib.c @@ -7,7 +7,7 @@ #include "be_string.h" #include "be_gc.h" - +#ifdef USE_LIGHT extern int l_getlight(bvm *vm); extern int l_setlight(bvm *vm); @@ -39,3 +39,5 @@ module tasmota (scope: global, depend: 1) { @const_object_info_end */ #include "../generate/be_fixed_tasmota.h" #endif + +#endif // USE_LIGHT \ No newline at end of file diff --git a/lib/libesp32/Berry/default/be_modtab.c b/lib/libesp32/Berry/default/be_modtab.c index 0ae689955..3f9af58ad 100644 --- a/lib/libesp32/Berry/default/be_modtab.c +++ b/lib/libesp32/Berry/default/be_modtab.c @@ -63,15 +63,19 @@ BERRY_LOCAL const bntvmodule* const be_module_table[] = { &be_native_module(solidify), #endif /* user-defined modules register start */ -#if BE_USE_TASMOTA + &be_native_module(gpio), +#ifdef USE_LIGHT &be_native_module(light), +#endif #ifdef USE_LVGL &be_native_module(lvgl), #endif // USE_LVGL +#ifdef USE_ENERGY_SENSOR &be_native_module(energy), -#endif +#endif // USE_ENERGY_SENSOR + /* user-defined modules register end */ NULL /* do not remove */ @@ -98,7 +102,9 @@ BERRY_API void be_load_custom_libs(bvm *vm) /* be_load_xxxlib(vm); */ #endif be_load_tasmota_ntvlib(vm); +#ifdef USE_I2C be_load_wirelib(vm); +#endif // USE_I2C be_load_driverlib(vm); #ifdef USE_LVGL // LVGL diff --git a/lib/libesp32/Berry/default/be_wirelib.c b/lib/libesp32/Berry/default/be_wirelib.c index 1ac65dd82..ee75d6a54 100644 --- a/lib/libesp32/Berry/default/be_wirelib.c +++ b/lib/libesp32/Berry/default/be_wirelib.c @@ -9,6 +9,8 @@ #include "be_string.h" #include "be_gc.h" +#ifdef USE_I2C + extern int b_wire_init(bvm *vm); extern int b_wire_begintransmission(bvm *vm); @@ -241,3 +243,5 @@ module tasmota (scope: global, depend: 1) { @const_object_info_end */ #include "../generate/be_fixed_tasmota.h" #endif + +#endif // USE_I2C \ No newline at end of file diff --git a/lib/libesp32/Berry/default/berry_conf.h b/lib/libesp32/Berry/default/berry_conf.h index 9f61edd70..1136d0a5c 100644 --- a/lib/libesp32/Berry/default/berry_conf.h +++ b/lib/libesp32/Berry/default/berry_conf.h @@ -158,12 +158,6 @@ #define BE_USE_GC_MODULE 1 #define BE_USE_SOLIDIFY_MODULE 1 -// #ifdef ESP32 -#define BE_USE_TASMOTA 1 -// #else -// #define BE_USE_TASMOTA 0 -// #endif - /* Macro: BE_EXPLICIT_XXX * If these macros are defined, the corresponding function will * use the version defined by these macros. These macro definitions diff --git a/tasmota/xdrv_52_3_berry_energy.ino b/tasmota/xdrv_52_3_berry_energy.ino index 75ae27245..e39cd8967 100644 --- a/tasmota/xdrv_52_3_berry_energy.ino +++ b/tasmota/xdrv_52_3_berry_energy.ino @@ -20,6 +20,8 @@ #ifdef USE_BERRY +#ifdef USE_ENERGY_SENSOR + #include @@ -32,7 +34,6 @@ * \*********************************************************************************************/ extern "C" { -#ifdef USE_ENERGY_SENSOR // Berry: `begintransmission(address:int) -> nil` int32_t b_nrg_read(struct bvm *vm); int32_t b_nrg_read(struct bvm *vm) { @@ -53,18 +54,17 @@ extern "C" { be_pop(vm, 1); be_return(vm); // Return } -#else // USE_ENERGY_SENSOR +} + +#endif // USE_ENERGY_SENSOR + +extern "C" { // int32_t b_wire_energymissing(struct bvm *vm); int32_t b_wire_energymissing(struct bvm *vm) { be_raise(vm, "feature_error", "Energy sensor is not enabled, use '#define USE_ENERGY_SENSOR'"); } - // define weak aliases - int32_t b_nrg_read(struct bvm *vm) __attribute__ ((weak, alias ("b_wire_energymissing"))); -#endif // USE_ENERGY_SENSOR } - - #endif // USE_BERRY diff --git a/tasmota/xdrv_52_3_berry_light.ino b/tasmota/xdrv_52_3_berry_light.ino index aadeea032..44c383866 100644 --- a/tasmota/xdrv_52_3_berry_light.ino +++ b/tasmota/xdrv_52_3_berry_light.ino @@ -20,6 +20,8 @@ #ifdef USE_BERRY +#ifdef USE_LIGHT + #include #include @@ -29,7 +31,6 @@ \*********************************************************************************************/ extern "C" { -#ifdef USE_LIGHT // push the light status object on the vm stack void push_getlight(bvm *vm, uint32_t light_num) { bool data_present = false; // do we have relevant data @@ -295,18 +296,15 @@ extern "C" { } be_raise(vm, kTypeError, nullptr); } +} -#else // #ifdef USE_LIGHT +#endif // USE_LIGHT +extern "C" { int32_t b_light_missing(struct bvm *vm) { be_raise(vm, "feature_error", "LIGHT is not enabled, use '#define USE_LIGHT'"); } - int32_t l_getlight(struct bvm *vm) __attribute__ ((weak, alias ("b_light_missing"))); - int32_t l_setlight(struct bvm *vm) __attribute__ ((weak, alias ("b_light_missing"))); - int32_t l_gamma8(struct bvm *vm) __attribute__ ((weak, alias ("b_light_missing"))); - int32_t l_gamma10(struct bvm *vm) __attribute__ ((weak, alias ("b_light_missing"))); - int32_t l_rev_gamma10(struct bvm *vm) __attribute__ ((weak, alias ("b_light_missing"))); -#endif // #ifdef USE_LIGHT + } #endif // USE_BERRY diff --git a/tasmota/xdrv_52_3_berry_wire.ino b/tasmota/xdrv_52_3_berry_wire.ino index f288d188a..8aa404222 100644 --- a/tasmota/xdrv_52_3_berry_wire.ino +++ b/tasmota/xdrv_52_3_berry_wire.ino @@ -20,6 +20,8 @@ #ifdef USE_BERRY +#ifdef USE_I2C + #include #include @@ -52,7 +54,6 @@ int32_t getBus(bvm *vm) { * \*********************************************************************************************/ extern "C" { -#ifdef USE_I2C // Berry: `init([bus:int = 0]) -> nil int32_t b_wire_init(struct bvm *vm); int32_t b_wire_init(struct bvm *vm) { @@ -241,28 +242,16 @@ extern "C" { } be_raise(vm, kTypeError, nullptr); } -#else // USE_I2C - // +} + +#endif // USE_I2C + +extern "C" { + // Handle methods that require I2C to be enabled int32_t b_wire_i2cmissing(struct bvm *vm); int32_t b_wire_i2cmissing(struct bvm *vm) { be_raise(vm, "feature_error", "I2C is not enabled, use '#define USE_I2C'"); } - - // define weak aliases - int32_t b_wire_init(struct bvm *vm) __attribute__ ((weak, alias ("b_wire_i2cmissing"))); - int32_t b_wire_begintransmission(struct bvm *vm) __attribute__ ((weak, alias ("b_wire_i2cmissing"))); - int32_t b_wire_endtransmission(struct bvm *vm) __attribute__ ((weak, alias ("b_wire_i2cmissing"))); - int32_t b_wire_requestfrom(struct bvm *vm) __attribute__ ((weak, alias ("b_wire_i2cmissing"))); - int32_t b_wire_available(struct bvm *vm) __attribute__ ((weak, alias ("b_wire_i2cmissing"))); - int32_t b_wire_write(struct bvm *vm) __attribute__ ((weak, alias ("b_wire_i2cmissing"))); - int32_t b_wire_read(struct bvm *vm) __attribute__ ((weak, alias ("b_wire_i2cmissing"))); - int32_t b_wire_scan(struct bvm *vm) __attribute__ ((weak, alias ("b_wire_i2cmissing"))); - int32_t b_wire_validwrite(struct bvm *vm) __attribute__ ((weak, alias ("b_wire_i2cmissing"))); - int32_t b_wire_validread(struct bvm *vm) __attribute__ ((weak, alias ("b_wire_i2cmissing"))); - int32_t b_wire_readbytes(struct bvm *vm) __attribute__ ((weak, alias ("b_wire_i2cmissing"))); - int32_t b_wire_writebytes(struct bvm *vm) __attribute__ ((weak, alias ("b_wire_i2cmissing"))); - int32_t b_wire_detect(struct bvm *vm) __attribute__ ((weak, alias ("b_wire_i2cmissing"))); -#endif // USE_I2C } #endif // USE_BERRY diff --git a/tasmota/xdrv_52_7_berry_embedded.ino b/tasmota/xdrv_52_7_berry_embedded.ino index 8f4375281..cc0a3a320 100644 --- a/tasmota/xdrv_52_7_berry_embedded.ino +++ b/tasmota/xdrv_52_7_berry_embedded.ino @@ -32,7 +32,9 @@ const char berry_prog[] = // auto-import modules // // import alias +#ifdef USE_ENERGY_SENSOR "import energy " +#endif // Phase 1 "class Tasmota: Tasmota_ntv "