build: clean up the mess of ifdefs from platform into a scons-configured hal
This commit is contained in:
120
src/Platform.cpp
120
src/Platform.cpp
@@ -3,40 +3,16 @@
|
||||
#include "Static.h"
|
||||
#include <time.h>
|
||||
|
||||
#ifdef BOARD_ESP32
|
||||
#ifdef CONFIG_WIFI
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
#include <esp_task_wdt.h>
|
||||
#elif defined(BOARD_ESP8266)
|
||||
#ifdef CONFIG_WIFI
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <NTPClient.h>
|
||||
#include <ctime>
|
||||
|
||||
WiFiUDP wifiUdp;
|
||||
NTPClient timeClient(wifiUdp, "pool.ntp.org", 3600 * -7);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_PHOTON
|
||||
STARTUP(BootOptions::initPins());
|
||||
#else
|
||||
#include "inputs/Serial.h"
|
||||
#ifdef CONFIG_MQTT
|
||||
#include "platform/arduino/MQTTTelemetry.h"
|
||||
#endif
|
||||
void printNewline(Print* logOutput, int logLevel)
|
||||
{
|
||||
(void)logLevel; // unused
|
||||
logOutput->print("\n");
|
||||
}
|
||||
int printEspLog(const char* fmt, va_list args)
|
||||
{
|
||||
Log.notice(fmt, args);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int Platform::s_timezone = 0;
|
||||
@@ -46,24 +22,18 @@ Platform::TaskRegistration* Platform::lastTask = NULL;
|
||||
const char*
|
||||
Platform::name()
|
||||
{
|
||||
return PlatformImpl<>::name();
|
||||
#ifdef PLATFORM_PHOTON
|
||||
return "Photon";
|
||||
#elif defined(BOARD_ESP8266)
|
||||
return "ESP8266";
|
||||
#elif defined(BOARD_ESP32)
|
||||
return "ESP32";
|
||||
#else
|
||||
return "Unknown!";
|
||||
#endif
|
||||
}
|
||||
|
||||
const char*
|
||||
Platform::version()
|
||||
{
|
||||
return PlatformImpl<>::version();
|
||||
#ifdef PLATFORM_PHOTON
|
||||
return System.version().c_str();
|
||||
#elif defined(BOARD_ESP32) || defined(BOARD_ESP8266)
|
||||
return ESP.getSdkVersion();
|
||||
#else
|
||||
return "Unknown!";
|
||||
#endif
|
||||
@@ -72,9 +42,7 @@ Platform::version()
|
||||
int
|
||||
Platform::freeRam()
|
||||
{
|
||||
#if defined(BOARD_ESP8266) || defined(BOARD_ESP32)
|
||||
return ESP.getFreeHeap();
|
||||
#endif
|
||||
return PlatformImpl<>::freeRam();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -94,26 +62,17 @@ Platform::preSetup()
|
||||
Log.notice("\xf0\x9f\x94\x8c Serial connected");
|
||||
}
|
||||
#else
|
||||
#ifdef CONFIG_MQTT
|
||||
Log.begin(LOG_LEVEL_TRACE, Static<MQTTTelemetry>::instance()->logPrinter());
|
||||
Static<MQTTTelemetry>::instance()->setSequencer(Static<Sequencer>::instance());
|
||||
#else
|
||||
Log.begin(LOG_LEVEL_TRACE, Static<SerialInput>::instance()->logPrinter());
|
||||
#endif
|
||||
Log.setSuffix(printNewline);
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_ESP32
|
||||
esp_task_wdt_init(10, true);
|
||||
esp_task_wdt_add(NULL);
|
||||
esp_log_set_vprintf(printEspLog);
|
||||
#endif
|
||||
#ifdef BOARD_ESP8266
|
||||
ESP.wdtEnable(0);
|
||||
if (!ESP.checkFlashCRC()) {
|
||||
Log.fatal("Firmware failed CRC check!!!");
|
||||
}
|
||||
#endif
|
||||
PlatformImpl<>::startWatchdog();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -121,19 +80,15 @@ Platform::setup()
|
||||
{
|
||||
#ifdef PLATFORM_PHOTON
|
||||
Time.zone(Static<Platform>::instance()->getTimezone());
|
||||
#elif defined(BOARD_ESP32)
|
||||
constexpr int dst = 1;
|
||||
configTime(s_timezone* 3600, 3600 * dst, "pool.ntp.org");
|
||||
#elif defined(BOARD_ESP8266)
|
||||
#ifdef CONFIG_WIFI
|
||||
timeClient.begin();
|
||||
#endif
|
||||
#endif
|
||||
PlatformImpl<>::startNTP();
|
||||
}
|
||||
|
||||
void
|
||||
Platform::bootSplash()
|
||||
{
|
||||
PlatformImpl<>::bootSplash();
|
||||
|
||||
#ifdef PLATFORM_PHOTON
|
||||
Log.notice(u8" Boot pin configuration:");
|
||||
Log.notice(u8" 2: Setup - %d", bootopts.isSetup);
|
||||
@@ -148,14 +103,7 @@ Platform::bootSplash()
|
||||
lastTaskBuf[15] = 0;
|
||||
Log.error(u8"Crash occurred in task %s", lastTaskBuf);
|
||||
|
||||
#ifdef BOARD_ESP8266
|
||||
auto rInfo = ESP.getResetInfoPtr();
|
||||
if (Platform::bootopts.resetReason == REASON_EXCEPTION_RST) {
|
||||
Log.error("Fatal exception (%d):", rInfo->exccause);
|
||||
}
|
||||
Log.error("epc1=%X, epc2=%X, epc3=%X, excvaddr=%X, depc=%X",
|
||||
rInfo->epc1, rInfo->epc2, rInfo->epc3, rInfo->excvaddr, rInfo->depc);
|
||||
#endif
|
||||
PlatformImpl<>::printCrashInfo();
|
||||
|
||||
strncpy(lastTaskBuf, Renderer::lastFigmentName(), sizeof(lastTaskBuf));
|
||||
lastTaskBuf[15] = 0;
|
||||
@@ -164,7 +112,6 @@ Platform::bootSplash()
|
||||
|
||||
Log.trace("Startup reason: %d", bootopts.resetReason);
|
||||
|
||||
|
||||
Log.trace("Registered tasks:");
|
||||
auto it = beginTasks();
|
||||
while (it != endTasks()) {
|
||||
@@ -180,16 +127,7 @@ Platform::bootSplash()
|
||||
void
|
||||
Platform::loop()
|
||||
{
|
||||
#ifdef BOARD_ESP8266
|
||||
#ifdef CONFIG_WIFI
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
timeClient.update();
|
||||
}
|
||||
#endif
|
||||
ESP.wdtFeed();
|
||||
#elif defined(BOARD_ESP32)
|
||||
esp_task_wdt_reset();
|
||||
#endif
|
||||
PlatformImpl<>::loop();
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -202,40 +140,19 @@ Platform::getLocalTime(struct tm* timedata)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#elif defined(BOARD_ESP32)
|
||||
time_t rawtime;
|
||||
memset(&rawtime, 0, sizeof(rawtime));
|
||||
time(&rawtime);
|
||||
(*timedata) = (*localtime(&rawtime));
|
||||
return (timedata->tm_year > (2016-1990));
|
||||
#else
|
||||
#ifdef CONFIG_WIFI
|
||||
timedata->tm_hour = timeClient.getHours();
|
||||
timedata->tm_min = timeClient.getMinutes();
|
||||
#else
|
||||
memset(timedata, sizeof(struct tm), 0);
|
||||
return false;
|
||||
#endif
|
||||
return true;
|
||||
#endif
|
||||
return PlatformImpl<>::getLocalTime(timedata, s_timezone);
|
||||
}
|
||||
|
||||
const char*
|
||||
Platform::deviceID()
|
||||
{
|
||||
uint64_t chipid;
|
||||
#ifdef BOARD_ESP32
|
||||
chipid = ESP.getEfuseMac();
|
||||
#elif defined(BOARD_ESP8266)
|
||||
chipid = ESP.getChipId();
|
||||
#endif
|
||||
snprintf(s_deviceID, sizeof(s_deviceID), "%08X", (uint32_t)chipid);
|
||||
return s_deviceID;
|
||||
return PlatformImpl<>::deviceID();
|
||||
}
|
||||
|
||||
void
|
||||
Platform::addLEDs(CRGB* leds, uint16_t ledCount) {
|
||||
FastLED.addLeds<WS2812, RENDERBUG_LED_PIN, RENDERBUG_LED_PACKING>(leds, ledCount);
|
||||
FastLED.addLeds<NEOPIXEL, RENDERBUG_LED_PIN>(leds, ledCount);
|
||||
}
|
||||
|
||||
const String
|
||||
@@ -247,12 +164,7 @@ Platform::model()
|
||||
|
||||
void
|
||||
Platform::restart() {
|
||||
#ifdef BOARD_ESP8266
|
||||
ESP.wdtDisable();
|
||||
ESP.restart();
|
||||
#elif defined(BOARD_ESP32)
|
||||
ESP.restart();
|
||||
#endif
|
||||
PlatformImpl<>::restart();
|
||||
}
|
||||
|
||||
|
||||
@@ -260,15 +172,15 @@ void
|
||||
Platform::doReboot(Args& args, Print& out)
|
||||
{
|
||||
out.println("Rebooting");
|
||||
Platform::restart();
|
||||
restart();
|
||||
}
|
||||
|
||||
void
|
||||
Platform::doSafeMode(Args& args, Print& out)
|
||||
{
|
||||
out.println("Rebooting into safe mode");
|
||||
Platform::bootopts.forceSafeMode();
|
||||
Platform::restart();
|
||||
PlatformImpl<>::forceSafeMode();
|
||||
restart();
|
||||
}
|
||||
|
||||
String s;
|
||||
|
Reference in New Issue
Block a user