Skip to content

Commit

Permalink
Berry ULP - API changes for IDF5.x (arendst#20198)
Browse files Browse the repository at this point in the history
* remove pointless dependencies

* add API changes for IDF5.x
  • Loading branch information
Staars authored Dec 9, 2023
1 parent 15d72e9 commit 864a99d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
9 changes: 2 additions & 7 deletions lib/libesp32/berry_tasmota/src/be_ULP_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@

#if defined(USE_BERRY_ULP) && (defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3))

// #include "esp32/ulp.h"
#include "driver/rtc_io.h"
#include "driver/gpio.h"
#include "driver/adc.h"

extern void be_ULP_run(int32_t entry);
BE_FUNC_CTYPE_DECLARE(be_ULP_run, "", "[i]");

Expand All @@ -25,10 +20,10 @@ BE_FUNC_CTYPE_DECLARE(be_ULP_set_mem, "i", "ii");
extern int32_t be_ULP_get_mem(int32_t pos);
BE_FUNC_CTYPE_DECLARE(be_ULP_get_mem, "i", "i");

extern int32_t be_ULP_gpio_init(gpio_num_t pin, rtc_gpio_mode_t mode);
extern int32_t be_ULP_gpio_init(int32_t pin, int32_t mode);
BE_FUNC_CTYPE_DECLARE(be_ULP_gpio_init, "i", "ii");

extern void be_ULP_adc_config(struct bvm *vm, adc1_channel_t channel, adc_atten_t attenuation, adc_bits_width_t width);
extern void be_ULP_adc_config(struct bvm *vm, int32_t channel, int32_t attenuation, int32_t width);
BE_FUNC_CTYPE_DECLARE(be_ULP_adc_config, "", "@iii");

extern void be_ULP_sleep(int32_t wake_up_s);
Expand Down
61 changes: 48 additions & 13 deletions tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_ulp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,29 @@
#if defined(CONFIG_IDF_TARGET_ESP32)
#include "esp32/ulp.h"
#endif // esp32
#if defined(CONFIG_IDF_TARGET_ESP32S2)
#include "esp32s2/ulp.h"
#include "esp32s2/ulp_riscv.h"
#include "esp32s2/ulp_riscv_adc.h"
#endif // s2
#if defined(CONFIG_IDF_TARGET_ESP32S3)
#include "esp32s3/ulp.h"
#include "esp32s3/ulp_riscv.h"
#include "esp32s3/ulp_riscv_adc.h"
#endif //s3
#if ESP_IDF_VERSION_MAJOR < 5
#if defined(CONFIG_IDF_TARGET_ESP32S2)
#include "esp32s2/ulp.h"
#include "esp32s2/ulp_riscv.h"
#include "esp32s2/ulp_riscv_adc.h"
#endif // s2
#if defined(CONFIG_IDF_TARGET_ESP32S3)
#include "esp32s3/ulp.h"
#include "esp32s3/ulp_riscv.h"
#include "esp32s3/ulp_riscv_adc.h"
#endif //s3
#endif // ESP_IDF_VERSION_MAJOR < 5
#include "driver/rtc_io.h"
#include "driver/gpio.h"
#include "driver/adc.h"
#if ESP_IDF_VERSION_MAJOR >= 5
#include "esp_adc/adc_oneshot.h"
#include "ulp_adc.h"
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
#include "ulp_riscv.h"
#endif // defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
#else
#include "driver/adc.h"
#endif // ESP_IDF_VERSION_MAJOR >= 5

#include "sdkconfig.h"

Expand Down Expand Up @@ -92,20 +102,45 @@ extern "C" {
// enums: channel 0-7, attenuation 0-3, width 0-3
void be_ULP_adc_config(struct bvm *vm, int32_t channel, int32_t attenuation, int32_t width) {
#if defined(CONFIG_IDF_TARGET_ESP32)
#if ESP_IDF_VERSION_MAJOR >= 5
ulp_adc_cfg_t cfg = {
.adc_n = ADC_UNIT_1,
.channel = (adc_channel_t)channel,
.atten = (adc_atten_t)attenuation,
.width = (adc_bitwidth_t)width,
.ulp_mode = ADC_ULP_MODE_FSM,
};
esp_err_t err = ulp_adc_init(&cfg);
#else
esp_err_t err = adc1_config_channel_atten((adc1_channel_t)channel, (adc_atten_t)attenuation);
err += adc1_config_width((adc_bits_width_t)width);
#endif // ESP_IDF_VERSION_MAJOR >= 5
if (err != ESP_OK) {
be_raisef(vm, "ulp_adc_config_error", "ULP: invalid code err=%i", err);
} else {
}
#if ESP_IDF_VERSION_MAJOR < 5
else {
adc1_ulp_enable();
}
#endif // ESP_IDF_VERSION_MAJOR < 5
#else // S2 or S3
#if ESP_IDF_VERSION_MAJOR >= 5
ulp_adc_cfg_t cfg = {
.adc_n = ADC_UNIT_1,
.channel = (adc_channel_t)channel,
.atten = (adc_atten_t)attenuation,
.width = (adc_bitwidth_t)width,
.ulp_mode = ADC_ULP_MODE_RISCV,
};
esp_err_t err = ulp_adc_init(&cfg);
#else
ulp_riscv_adc_cfg_t cfg = {
.channel = (adc_channel_t)channel,
.atten = (adc_atten_t)attenuation,
.width = (adc_bits_width_t)width
};
esp_err_t err = ulp_riscv_adc_init(&cfg);
#endif // ESP_IDF_VERSION_MAJOR >= 5
if (err != ESP_OK) {
be_raisef(vm, "ulp_adc_config_error", "ULP: invalid code err=%i", err);
}
Expand Down Expand Up @@ -149,4 +184,4 @@ extern "C" {
#endif //CONFIG_IDF_TARGET_ESP32 .. S2 .. S3

#endif // USE_BERRY_ULP
#endif // USE_BERRY
#endif // USE_BERRY

0 comments on commit 864a99d

Please sign in to comment.