Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: DISCO-L072CZ-LRWAN1_LoRa_PingPong DISCO-L072CZ-LRWAN1_LoRa_PingPong DISCO-L072CZ-LRWAN1_LoRa_PingPong DISCO-L072CZ-LRWAN1_LoRa_USB_Rx ... more
Fork of SX1276Lib by
Diff: Arduino-mbed-APIs/arduino-esp32.cpp
- Revision:
- 105:6e6d141c3da8
- Parent:
- 104:b5183e348f9d
--- a/Arduino-mbed-APIs/arduino-esp32.cpp Tue Nov 21 16:59:28 2017 +0100
+++ b/Arduino-mbed-APIs/arduino-esp32.cpp Wed Nov 22 12:14:00 2017 +0100
@@ -10,13 +10,11 @@
#include "arduino-mbed.h"
#include "arduino-util.h"
-#include <time.h>
#if defined(ARDUINO_ARCH_ESP32)
#include "soc/efuse_reg.h"
-
/*
* ARDUINO_ARCH_ESP32 ESP32 development board
* Heltec ESP32 boards
@@ -238,7 +236,7 @@
//dprintf("onTimer int called");
uint64_t nsecs = ns_getTicker();
- for (int i = 0; i < MAX_TIMEOUTS-1; i++) {
+ for (int i = 0; i < maxTimeouts-1; i++) {
struct TimeoutVector *tvp = &TimeOuts[i];
if (tvp->timer && nsecs >= tvp->timer->_timeout) {
Timeout *saveTimer = tvp->timer;
@@ -273,6 +271,137 @@
asm("waiti 0");
}
+
+#if 0
+esp_light_sleep_start();
+#endif
+
+#if 0
+// esp_err = gpio_pullup_dis(GPIO_NUM_xx);
+// esp_err = gpio_pulldown_en(GPIO_NUM_xx);
+int err = esp_deep_sleep_enable_ext0_wakeup((gpio_num_t)SW0,0); //1 = High, 0 = Low
+if (err) {
+ dprintf("esp_deep_sleep_enable_ext0_wakeup: error %d", err);
+ return;
+}
+esp_deep_sleep_enable_timer_wakeup(10000000); // or later esp_sleep_enable_timer_wakeup(10000000);
+dprintf("Enter deep sleep");
+esp_deep_sleep_start();
+// esp_light_sleep_start(); // does not exists?
+#endif
+
+
+/*
+ * Convert compile time to system time
+ */
+time_t cvt_date(char const *date, char const *time)
+{
+ char s_month[5];
+ int year;
+ struct tm t;
+ static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+ sscanf(date, "%s %d %d", s_month, &t.tm_mday, &year);
+ sscanf(time, "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec);
+ // Find where is s_month in month_names. Deduce month value.
+ t.tm_mon = (strstr(month_names, s_month) - month_names) / 3;
+ t.tm_year = year - 1900;
+ return (int)mktime(&t);
+}
+
+
+const char *ESP32ResetReason(RESET_REASON r)
+{
+ const char *reason = "";
+
+ switch(r) {
+ case NO_MEAN:
+ reason = "no mean";
+ break;
+ case POWERON_RESET:
+ reason = "Vbat power on reset";
+ break;
+ case SW_RESET:
+ reason = "Software reset digital core";
+ break;
+ case OWDT_RESET:
+ reason = "Legacy watch dog reset digital core";
+ break;
+ case DEEPSLEEP_RESET:
+ reason = "Deep Sleep reset digital core";
+ break;
+ case SDIO_RESET:
+ reason = "Reset by SLC module, reset digital core";
+ break;
+ case TG0WDT_SYS_RESET:
+ reason = "Timer Group0 Watch dog reset digital core";
+ break;
+ case TG1WDT_SYS_RESET:
+ reason = "Timer Group1 Watch dog reset digital core";
+ break;
+ case RTCWDT_SYS_RESET:
+ reason = "RTC Watch dog Reset digital core";
+ break;
+ case INTRUSION_RESET:
+ reason = "Instrusion tested to reset CPU";
+ break;
+ case TGWDT_CPU_RESET:
+ reason = "Time Group reset CPU";
+ break;
+ case SW_CPU_RESET:
+ reason = "Software reset CPU";
+ break;
+ case RTCWDT_CPU_RESET:
+ reason = "RTC Watch dog Reset CPU";
+ break;
+ case EXT_CPU_RESET:
+ reason = "APP CPU reseted by PRO CPU";
+ break;
+ case RTCWDT_BROWN_OUT_RESET:
+ reason = "Reset when the vdd voltage is not stable";
+ break;
+ case RTCWDT_RTC_RESET:
+ reason = "RTC Watch dog reset digital core and rtc module";
+ break;
+ default:
+ reason = "unkown reset";
+ break;
+ }
+ return reason;
+}
+
+
+/*
+ * Method to print the reason by which ESP32
+ * has been awaken from sleep
+ */
+const char *ESP32WakeUpReason(esp_deep_sleep_wakeup_cause_t wakeup_reason)
+{
+ const char *reason = "";
+
+ switch(wakeup_reason)
+ {
+ case ESP_DEEP_SLEEP_WAKEUP_EXT0:
+ reason = "Wakeup caused by external signal using RTC_IO";
+ break;
+ case ESP_DEEP_SLEEP_WAKEUP_EXT1:
+ reason = "Wakeup caused by external signal using RTC_CNTL";
+ break;
+ case ESP_DEEP_SLEEP_WAKEUP_TIMER:
+ reason = "Wakeup caused by timer";
+ break;
+ case ESP_DEEP_SLEEP_WAKEUP_TOUCHPAD:
+ reason = "Wakeup caused by touchpad";
+ break;
+ case ESP_DEEP_SLEEP_WAKEUP_ULP:
+ reason = "Wakeup caused by ULP program";
+ break;
+ default:
+ reason = "Wakeup was not caused by deep sleep";
+ break;
+ }
+ return reason;
+}
+
#endif // ESp32 Timer, sleep, etc.
#endif // ARDUINO

