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
Revision 105:6e6d141c3da8, committed 2017-11-22
- Comitter:
- Helmut Tschemernjak
- Date:
- Wed Nov 22 12:14:00 2017 +0100
- Parent:
- 104:b5183e348f9d
- Child:
- 106:84fff1b57caa
- Commit message:
- Moved ESP32 helper functions into arduino-esp32.cpp
Allow to change MAX_TIMEOUTS without need to change
custom d21 and ESP32 assembler files
Changed in this revision
--- a/Arduino-mbed-APIs/arduino-d21.cpp Tue Nov 21 16:59:28 2017 +0100
+++ b/Arduino-mbed-APIs/arduino-d21.cpp Wed Nov 22 12:14:00 2017 +0100
@@ -14,6 +14,22 @@
#if defined(__SAMD21G18A__) || defined(__SAMD21J18A__)
+
+// 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);
+}
+
/*
* __SAMD21J18A__ is the SamD21 Explained Board
* __SAMD21G18A__ is Genuino Zero-Board (compatible with the LoRa board)
@@ -348,7 +364,7 @@
t->CTRLA.reg &= ~TCC_CTRLA_ENABLE; // Disable TC
while (t->SYNCBUSY.bit.ENABLE == 1); // wait for sync
- 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;
--- 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
--- a/Arduino-mbed-APIs/arduino-mbed.cpp Tue Nov 21 16:59:28 2017 +0100
+++ b/Arduino-mbed-APIs/arduino-mbed.cpp Wed Nov 22 12:14:00 2017 +0100
@@ -240,6 +240,7 @@
}
struct TimeoutVector TimeOuts[MAX_TIMEOUTS];
+int maxTimeouts = MAX_TIMEOUTS;
void
InterruptIn::rise(Callback<void()> func) {
--- a/Arduino-mbed-APIs/arduino-mbed.h Tue Nov 21 16:59:28 2017 +0100
+++ b/Arduino-mbed-APIs/arduino-mbed.h Wed Nov 22 12:14:00 2017 +0100
@@ -12,11 +12,18 @@
#include <arduino.h>
#include "Callback-A.h"
+#include <sys/time.h>
+#include <time.h>
#include <SPI.h>
#undef min
#undef max
#undef map
+#ifdef ARDUINO_ARCH_ESP32
+#include <rom/rtc.h>
+#include <esp_deep_sleep.h>
+#endif
+
typedef int PinName;
#define NC -1
/* we need to redefine out dprintf because stdio.h uses the same name */
@@ -51,14 +58,21 @@
extern int CPUID(uint8_t *buf, int maxSize, uint32_t xorval);
extern void sleep(void);
extern void deepsleep(void);
+extern time_t cvt_date(char const *date, char const *time);
#define MAX_TIMEOUTS 10
+extern int maxTimeouts;
class Timeout;
struct TimeoutVector {
Timeout *timer;
};
extern TimeoutVector TimeOuts[];
+#ifdef ARDUINO_ARCH_ESP32
+extern const char *ESP32WakeUpReason(esp_deep_sleep_wakeup_cause_t wakeup_reason);
+extern const char *ESP32ResetReason(RESET_REASON r);
+#endif
+
/*
* Arduino-mbed.cpp

