So...this one inline-C - does not work, #ifdef does not work:
Spoiler: Bad code
[CODE lang="b4x" title="bad code"]#if C
#include <esp_sleep.h>
#include <driver/rtc_io.h>
#define BUTTON_PIN GPIO_NUM_0
void deepSleep(B4R::Object* o) {
// wake up by timer (msec)
uint64_t sleep_time_us = o->toULong() * 1000;
if(sleep_time_us > 0) {
esp_sleep_enable_timer_wakeup(sleep_time_us);
}
#ifdef CONFIG_IDF_TARGET_ESP32
// ESP32: use EXT0 (just single pin)
Serial.println("CONFIG_IDF_TARGET_ESP32");
delay(100);
esp_sleep_enable_ext0_wakeup(BUTTON_PIN, LOW);
#elifdef defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3)
Serial.println("CONFIG_IDF_TARGET_ESP32++++");
delay(100);
// ESP32-S2 / C3 / S3: use EXT1 (pins mask)
uint64_t ext1_mask = 1ULL << BUTTON_PIN;
//esp_sleep_enable_ext1_wakeup(ext1_mask, ESP_GPIO_WAKEUP_GPIO_LOW); //these two: ESP_SLEEP_EXT1_WAKEUP_ANY_LOW, ESP_EXT1_WAKEUP_ALL_LOW = do not work
esp_deep_sleep_enable_gpio_wakeup(ext1_mask, ESP_GPIO_WAKEUP_GPIO_LOW);
#endif
// going To Deep Sleep
esp_deep_sleep_start();
}
#end if[/CODE]
But without #ifdef - it works ! even "Serial.println" also works:
[CODE lang="b4x" title="Works without #ifdef"]#if C
#include <esp_sleep.h>
#include <driver/rtc_io.h>
#define BUTTON_PIN GPIO_NUM_0
void deepSleep(B4R::Object* o) {
// wake up by timer (msec)
uint64_t sleep_time_us = o->toULong() * 1000;
if(sleep_time_us > 0) {
esp_sleep_enable_timer_wakeup(sleep_time_us);
}
// #ifdef CONFIG_IDF_TARGET_ESP32
// // ESP32: use EXT0 (just single pin)
// Serial.println("CONFIG_IDF_TARGET_ESP32");
// delay(100);
// esp_sleep_enable_ext0_wakeup(BUTTON_PIN, LOW);
// #elifdef defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3)
Serial.println("CONFIG_IDF_TARGET_ESP32++++");
delay(100);
// ESP32-S2 / C3 / S3: use EXT1 (pins mask)
uint64_t ext1_mask = 1ULL << BUTTON_PIN;
esp_deep_sleep_enable_gpio_wakeup(ext1_mask, ESP_GPIO_WAKEUP_GPIO_LOW);
// #endif
// going To Deep Sleep
esp_deep_sleep_start();
}
#end if[/CODE]
New upload port: COM14 (serial)
---------------------
AppStart
ESP.ResetReasonMessage = Restarted 11: Unknown reset reason (11)
Device_ID = F0F5BDFDD470_v0.21
MAGIC_EEPROM = 213
This device name = aiFonar_F0F5BDFDD470_v0.21
RTC read BatCapacity = 0
From RTC BatCapacity = 0, try from NVS
From NVS BatCapacity = 59.8000
RTC saved BatCapacity = 59.8000
Configuring WDT...
Last Reset : ESP_OK
WDT is configured
going to sleep
Go deep sleep for 0 msecs
CONFIG_IDF_TARGET_ESP32++++
And waking up from deepsleep by GPIO0 button - is ok !
But it's interesting to have the universal code for various MCU models, with #ifdef.
@Erel , could you comment it ? What's wrong with #ifdef inside the Inline-C? Always compiled OK, but does not work.