From 38b33a9ad33d8d730f71ae88508fddcc584e95a2 Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Thu, 16 Jul 2020 23:34:07 +0200 Subject: [PATCH] Fixes compilation errors on example sketches. --- examples/ESP32IOBoard/ESP32IOBoard.ino | 46 +++++++++++++++++-- src/dcc/DccOutput.hxx | 8 ++-- src/freertos_drivers/arduino/CpuLoad.hxx | 10 +++- src/freertos_drivers/arduino/WifiDefs.hxx | 9 ++++ .../stm32/stm32f_hal_conf.hxx | 11 +++++ 5 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 src/freertos_drivers/stm32/stm32f_hal_conf.hxx diff --git a/examples/ESP32IOBoard/ESP32IOBoard.ino b/examples/ESP32IOBoard/ESP32IOBoard.ino index f76c665..de76b7e 100644 --- a/examples/ESP32IOBoard/ESP32IOBoard.ino +++ b/examples/ESP32IOBoard/ESP32IOBoard.ino @@ -54,6 +54,12 @@ // output. This is not recommended for production deployment. //#define PRINT_PACKETS +// uncomment the line below to specify a GPIO pin that should be used to force +// a factory reset when the node starts and the GPIO pin reads LOW. An external +// weak pull-up resistor to 3v3 would be recommended to prevent unintended +// factory resets. +//#define FACTORY_RESET_GPIO_PIN 22 + #include "config.h" /// This is the node id to assign to this device, this must be unique @@ -165,6 +171,10 @@ GPIO_PIN(IO13, GpioInputPU, 39); GPIO_PIN(IO14, GpioInputPU, 25); GPIO_PIN(IO15, GpioInputPU, 26); +#if defined(FACTORY_RESET_GPIO_PIN) +GPIO_PIN(FACTORY_RESET, GpioInputPU, FACTORY_RESET_GPIO_PIN); +#endif // FACTORY_RESET_GPIO_PIN + openlcb::ConfiguredProducer IO8_producer( openmrn.stack()->node(), cfg.seg().producers().entry<0>(), IO8_Pin()); openlcb::ConfiguredProducer IO9_producer( @@ -184,6 +194,9 @@ openlcb::ConfiguredProducer IO15_producer( // Create an initializer that can initialize all the GPIO pins in one shot typedef GpioInitializer< +#if defined(FACTORY_RESET_GPIO_PIN) + FACTORY_RESET_Pin, // factory reset +#endif // FACTORY_RESET_GPIO_PIN IO0_Pin, IO1_Pin, IO2_Pin, IO3_Pin, // outputs 0-3 IO4_Pin, IO5_Pin, IO6_Pin, IO7_Pin, // outputs 4-7 IO8_Pin, IO9_Pin, IO10_Pin, IO11_Pin, // inputs 0-3 @@ -269,6 +282,36 @@ void setup() } } + // initialize all declared GPIO pins + GpioInit::hw_init(); + +#if defined(FACTORY_RESET_GPIO_PIN) + // Check the factory reset pin which should normally read HIGH (set), if it + // reads LOW (clr) delete the cdi.xml and openlcb_config + if (!FACTORY_RESET_Pin::get()) + { + printf("!!!! WARNING WARNING WARNING WARNING WARNING !!!!\n"); + printf("The factory reset GPIO pin %d has been triggered.\n", + FACTORY_RESET_GPIO_PIN); + for (uint8_t sec = 10; sec > 0 && !FACTORY_RESET_Pin::get(); sec--) + { + printf("Factory reset will be initiated in %d seconds.\n", sec); + usleep(SEC_TO_USEC(1)); + } + if (!FACTORY_RESET_Pin::get()) + { + unlink(openlcb::CDI_FILENAME); + unlink(openlcb::CONFIG_FILENAME); + printf("Factory reset complete\n"); + } + else + { + printf("Factory reset aborted as pin %d was not held LOW\n", + FACTORY_RESET_GPIO_PIN); + } + } +#endif // FACTORY_RESET_GPIO_PIN + // Create the CDI.xml dynamically openmrn.create_config_descriptor_xml(cfg, openlcb::CDI_FILENAME); @@ -276,9 +319,6 @@ void setup() openmrn.stack()->create_config_file_if_needed(cfg.seg().internal_config(), openlcb::CANONICAL_VERSION, openlcb::CONFIG_FILE_SIZE); - // initialize all declared GPIO pins - GpioInit::hw_init(); - // Start the OpenMRN stack openmrn.begin(); openmrn.start_executor_thread(); diff --git a/src/dcc/DccOutput.hxx b/src/dcc/DccOutput.hxx index 8ec19d0..6548b89 100644 --- a/src/dcc/DccOutput.hxx +++ b/src/dcc/DccOutput.hxx @@ -186,11 +186,11 @@ public: /// \link DccOutput::DisableReason } These bits are all set by the /// application. The DCC Driver will only read this variable, and enable /// the output if all bits are zero. - static std::atomic_uint8_t outputDisableReasons_; + static std::atomic_uint_least8_t outputDisableReasons_; /// 0 if we should not produce a railcom cutout; 1 for short cutout; 2 for /// regular cutout. Set by the application and read by the DCC driver. - static std::atomic_uint8_t isRailcomCutoutEnabled_; + static std::atomic_uint_least8_t isRailcomCutoutEnabled_; /// 1 if we are in a railcom cutout currently. Set and cleared by the /// driver before calling the start/stop railcom cutout functions. @@ -233,10 +233,10 @@ private: }; template -std::atomic_uint8_t DccOutputHw::outputDisableReasons_ { +std::atomic_uint_least8_t DccOutputHw::outputDisableReasons_ { (uint8_t)DccOutput::DisableReason::INITIALIZATION_PENDING}; template -std::atomic_uint8_t DccOutputHw::isRailcomCutoutEnabled_ { +std::atomic_uint_least8_t DccOutputHw::isRailcomCutoutEnabled_ { (uint8_t)DccOutput::RailcomCutout::LONG_CUTOUT}; template uint8_t DccOutputHw::isRailcomCutoutActive_ {0}; diff --git a/src/freertos_drivers/arduino/CpuLoad.hxx b/src/freertos_drivers/arduino/CpuLoad.hxx index 0498f03..c87e1b2 100644 --- a/src/freertos_drivers/arduino/CpuLoad.hxx +++ b/src/freertos_drivers/arduino/CpuLoad.hxx @@ -31,6 +31,10 @@ * @date 30 August 2015 */ +#include "openmrn_features.h" + +#ifdef OPENMRN_FEATURE_THREAD_FREERTOS + #ifndef _OS_CPULOAD_HXX_ #define _OS_CPULOAD_HXX_ @@ -229,11 +233,12 @@ private: auto k = l->new_key(); if (k < 300) { - l->set_key_description(k, StringPrintf("irq-%u", k)); + l->set_key_description(k, StringPrintf("irq-%u", (unsigned)k)); } else if (k & 1) { - l->set_key_description(k, StringPrintf("ex 0x%x", k & ~1)); + l->set_key_description( + k, StringPrintf("ex 0x%x", (unsigned)(k & ~1))); } else { @@ -252,3 +257,4 @@ private: }; #endif // _OS_CPULOAD_HXX_ +#endif // OPENMRN_FEATURE_THREAD_FREERTOS diff --git a/src/freertos_drivers/arduino/WifiDefs.hxx b/src/freertos_drivers/arduino/WifiDefs.hxx index 75ab855..751bc50 100644 --- a/src/freertos_drivers/arduino/WifiDefs.hxx +++ b/src/freertos_drivers/arduino/WifiDefs.hxx @@ -1,6 +1,8 @@ #ifndef _FREERTOS_DRIVERS_COMMON_WIFIDEFS_HXX_ #define _FREERTOS_DRIVERS_COMMON_WIFIDEFS_HXX_ +#include + /// Wifi not associated to access point: continuous short blinks. #define WIFI_BLINK_NOTASSOCIATED 0b1010 /// Waiting for IP address: double short blink, pause, double short blink, ... @@ -22,6 +24,7 @@ enum class WlanState : uint8_t CONNECT_STATIC, CONNECT_FAILED, CONNECTION_LOST, + WRONG_PASSWORD, UPDATE_DISPLAY = 20, }; @@ -42,6 +45,12 @@ enum class CountryCode : uint8_t UNKNOWN, ///< unknown country code }; +enum class WlanConnectResult +{ + CONNECT_OK = 0, ///< success + PASSWORD_INVALID, /// password privided is invalid +}; + extern "C" { /// Name of wifi accesspoint to connect to. extern char WIFI_SSID[]; diff --git a/src/freertos_drivers/stm32/stm32f_hal_conf.hxx b/src/freertos_drivers/stm32/stm32f_hal_conf.hxx new file mode 100644 index 0000000..1c351c6 --- /dev/null +++ b/src/freertos_drivers/stm32/stm32f_hal_conf.hxx @@ -0,0 +1,11 @@ + +#include + +static inline void SetInterruptPriority(uint32_t irq, uint8_t priority) +{ + NVIC_SetPriority((IRQn_Type)irq, priority >> (8U - __NVIC_PRIO_BITS)); +} + +#ifndef configKERNEL_INTERRUPT_PRIORITY +#define configKERNEL_INTERRUPT_PRIORITY 0xA0 +#endif