From e4ac45d9a23e3bf5d94b15712f5147b720b59708 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 1 May 2021 23:22:00 +0200 Subject: [PATCH] Replace halGetResetInfo with haspDevice.gpio_name --- src/dev/device.h | 6 + src/drv/tft_driver_tftespi.h | 2 +- src/drv/touch/hasp_drv_tft_espi.cpp | 1 - src/hal/hasp_hal.cpp | 182 ++++++++++++++-------------- src/hal/hasp_hal.h | 4 +- src/sys/svc/hasp_http.cpp | 7 +- 6 files changed, 104 insertions(+), 98 deletions(-) diff --git a/src/dev/device.h b/src/dev/device.h index 2bcd0a21..f1f71363 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -94,6 +94,12 @@ class BaseDevice { { return false; } + virtual std::string gpio_name(uint8_t pin) + { + char buffer[8]; + itoa(pin, buffer, DEC); + return buffer; + } }; } // namespace dev diff --git a/src/drv/tft_driver_tftespi.h b/src/drv/tft_driver_tftespi.h index dbda686f..53a21574 100644 --- a/src/drv/tft_driver_tftespi.h +++ b/src/drv/tft_driver_tftespi.h @@ -52,7 +52,7 @@ class TftEspi : BaseTft { if(pin != -1) { char buffer[64]; snprintf_P(buffer, sizeof(buffer), PSTR("%-11s: %s (GPIO %02d)"), String(pinfunction).c_str(), - halGpioName(pin).c_str(), pin); + haspDevice.gpio_name(pin).c_str(), pin); LOG_VERBOSE(TAG_TFT, buffer); } } diff --git a/src/drv/touch/hasp_drv_tft_espi.cpp b/src/drv/touch/hasp_drv_tft_espi.cpp index 552828e4..a15721ee 100644 --- a/src/drv/touch/hasp_drv_tft_espi.cpp +++ b/src/drv/touch/hasp_drv_tft_espi.cpp @@ -8,7 +8,6 @@ #if defined(TOUCH_CS) -#include "hal/hasp_hal.h" // for halGpioName() #include "dev/device.h" #include "drv/tft_driver.h" diff --git a/src/hal/hasp_hal.cpp b/src/hal/hasp_hal.cpp index 0b2bc579..967a1d70 100644 --- a/src/hal/hasp_hal.cpp +++ b/src/hal/hasp_hal.cpp @@ -99,22 +99,22 @@ void halRestartMcu(void) } // halt } -String halGetResetInfo() -{ -#if defined(ARDUINO_ARCH_ESP32) - String resetReason((char*)0); - resetReason.reserve(128); +// String halGetResetInfo() +// { +// #if defined(ARDUINO_ARCH_ESP32) +// String resetReason((char*)0); +// resetReason.reserve(128); - resetReason += String(esp32ResetReason(0)); - resetReason += F(" / "); - resetReason += String(esp32ResetReason(1)); - return resetReason; -#elif defined(ARDUINO_ARCH_ESP8266) - return ESP.getResetInfo(); -#else - return ""; -#endif -} +// resetReason += String(esp32ResetReason(0)); +// resetReason += F(" / "); +// resetReason += String(esp32ResetReason(1)); +// return resetReason; +// #elif defined(ARDUINO_ARCH_ESP8266) +// return ESP.getResetInfo(); +// #else +// return ""; +// #endif +// } // String halGetCoreVersion() // { @@ -127,48 +127,48 @@ String halGetResetInfo() // #endif // } -String halGetChipModel() -{ - String model((char*)0); - model.reserve(128); +// String halGetChipModel() +// { +// String model((char*)0); +// model.reserve(128); -#if defined(STM32F4xx) - model = F("STM32"); -#endif +// #if defined(STM32F4xx) +// model = F("STM32"); +// #endif -#if defined(STM32F4xx) - model = F("STM32F4xx"); +// #if defined(STM32F4xx) +// model = F("STM32F4xx"); -#elif defined(ARDUINO_ARCH_ESP8266) - model = F("ESP8266"); +// #elif defined(ARDUINO_ARCH_ESP8266) +// model = F("ESP8266"); -#elif defined(ARDUINO_ARCH_ESP32) - esp_chip_info_t chip_info; - esp_chip_info(&chip_info); +// #elif defined(ARDUINO_ARCH_ESP32) +// esp_chip_info_t chip_info; +// esp_chip_info(&chip_info); - model = chip_info.cores; - model += F("core "); - switch(chip_info.model) { - case CHIP_ESP32: - model += F("ESP32"); - break; -#ifdef CHIP_ESP32S2 - case CHIP_ESP32S2: - model += F("ESP32-S2"); - break; -#endif - default: - model = F("Unknown ESP32"); - } - model += F(" rev"); - model += chip_info.revision; +// model = chip_info.cores; +// model += F("core "); +// switch(chip_info.model) { +// case CHIP_ESP32: +// model += F("ESP32"); +// break; +// #ifdef CHIP_ESP32S2 +// case CHIP_ESP32S2: +// model += F("ESP32-S2"); +// break; +// #endif +// default: +// model = F("Unknown ESP32"); +// } +// model += F(" rev"); +// model += chip_info.revision; -#else - model = F("Unknown"); -#endif +// #else +// model = F("Unknown"); +// #endif - return model; -} +// return model; +// } /*******************************/ /* Memory Management Functions */ @@ -216,43 +216,43 @@ int getMemFree() { // returns the amount of free memory in bytes return mi.fordblks + freeHighMemory(); } */ -size_t halGetMaxFreeBlock() -{ -#if defined(ARDUINO_ARCH_ESP32) - return ESP.getMaxAllocHeap(); -#elif defined(ARDUINO_ARCH_ESP8266) - return ESP.getMaxFreeBlockSize(); -#else - return freeHighMemory(); -#endif -} +// size_t halGetMaxFreeBlock() +// { +// #if defined(ARDUINO_ARCH_ESP32) +// return ESP.getMaxAllocHeap(); +// #elif defined(ARDUINO_ARCH_ESP8266) +// return ESP.getMaxFreeBlockSize(); +// #else +// return freeHighMemory(); +// #endif +// } -size_t halGetFreeHeap(void) -{ -#if defined(ARDUINO_ARCH_ESP32) - return ESP.getFreeHeap(); -#elif defined(ARDUINO_ARCH_ESP8266) - return ESP.getFreeHeap(); -#else - struct mallinfo chuncks = mallinfo(); +// size_t halGetFreeHeap(void) +// { +// #if defined(ARDUINO_ARCH_ESP32) +// return ESP.getFreeHeap(); +// #elif defined(ARDUINO_ARCH_ESP8266) +// return ESP.getFreeHeap(); +// #else +// struct mallinfo chuncks = mallinfo(); - // fordblks - // This is the total size of memory occupied by free (not in use) chunks. +// // fordblks +// // This is the total size of memory occupied by free (not in use) chunks. - return chuncks.fordblks + freeHighMemory(); -#endif -} +// return chuncks.fordblks + freeHighMemory(); +// #endif +// } -uint8_t halGetHeapFragmentation() -{ -#if defined(ARDUINO_ARCH_ESP32) - return (int8_t)(100.00f - (float)ESP.getMaxAllocHeap() * 100.00f / (float)ESP.getFreeHeap()); -#elif defined(ARDUINO_ARCH_ESP8266) - return ESP.getHeapFragmentation(); -#else - return (int8_t)(100.00f - (float)freeHighMemory() * 100.00f / (float)halGetFreeHeap()); -#endif -} +// uint8_t halGetHeapFragmentation() +// { +// #if defined(ARDUINO_ARCH_ESP32) +// return (int8_t)(100.00f - (float)ESP.getMaxAllocHeap() * 100.00f / (float)ESP.getFreeHeap()); +// #elif defined(ARDUINO_ARCH_ESP8266) +// return ESP.getHeapFragmentation(); +// #else +// return (int8_t)(100.00f - (float)freeHighMemory() * 100.00f / (float)halGetFreeHeap()); +// #endif +// } String halGetMacAddress(int start, const char* seperator) { @@ -284,14 +284,14 @@ String halGetMacAddress(int start, const char* seperator) return cMac; } -uint16_t halGetCpuFreqMHz() -{ -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_32) - return ESP.getCpuFreqMHz(); -#else - return (F_CPU / 1000 / 1000); -#endif -} +// uint16_t halGetCpuFreqMHz() +// { +// #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_32) +// return ESP.getCpuFreqMHz(); +// #else +// return (F_CPU / 1000 / 1000); +// #endif +// } String halDisplayDriverName() { diff --git a/src/hal/hasp_hal.h b/src/hal/hasp_hal.h index 61cfa2a5..4d397f7d 100644 --- a/src/hal/hasp_hal.h +++ b/src/hal/hasp_hal.h @@ -7,7 +7,7 @@ #include // void halRestartMcu(void); -String halGetResetInfo(void); +// String halGetResetInfo(void); // uint8_t halGetHeapFragmentation(void); // size_t halGetMaxFreeBlock(void); // size_t halGetFreeHeap(void); @@ -16,6 +16,6 @@ String halGetResetInfo(void); String halGetMacAddress(int start, const char* seperator); // uint16_t halGetCpuFreqMHz(void); // String halDisplayDriverName(void); -String halGpioName(uint8_t gpio); +// String halGpioName(uint8_t gpio); #endif \ No newline at end of file diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 60803d50..3c9a56b4 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -801,7 +801,7 @@ void webHandleInfo() httpMessage += haspDevice.get_core_version(); //#endif httpMessage += F("
Last Reset: "); - httpMessage += halGetResetInfo(); + // httpMessage += halGetResetInfo(); httpMessage += FPSTR(MAIN_MENU_BUTTON); @@ -1519,7 +1519,8 @@ void webHandleGpioConfig() hasp_gpio_config_t conf = gpioGetPinConfig(id); if((conf.pin == gpio) && gpioConfigInUse(id) && gpioInUse(gpio) && !gpioIsSystemPin(gpio)) { httpMessage += F(""); - httpMessage += halGpioName(gpio); + // httpMessage += halGpioName(gpio); + httpMessage += haspDevice.gpio_name(gpio).c_str(); httpMessage += F(""); switch(conf.type & 0xfe) { @@ -1643,7 +1644,7 @@ void webHandleGpioOptions() for(uint8_t io = 0; io < NUM_DIGITAL_PINS; io++) { if(((conf.pin == io) || !gpioInUse(io)) && !gpioIsSystemPin(io)) { - httpMessage += getOption(io, halGpioName(io), conf.pin == io); + httpMessage += getOption(io, haspDevice.gpio_name(io).c_str(), conf.pin == io); } } httpMessage += F("

");