Skip to content

Commit

Permalink
Fixes compilation errors on example sketches.
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsracz committed Jul 16, 2020
1 parent 8a6772a commit 38b33a9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 9 deletions.
46 changes: 43 additions & 3 deletions examples/ESP32IOBoard/ESP32IOBoard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -269,16 +282,43 @@ 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);

// Create the default internal configuration file
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();
Expand Down
8 changes: 4 additions & 4 deletions src/dcc/DccOutput.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -233,10 +233,10 @@ private:
};

template <int N>
std::atomic_uint8_t DccOutputHw<N>::outputDisableReasons_ {
std::atomic_uint_least8_t DccOutputHw<N>::outputDisableReasons_ {
(uint8_t)DccOutput::DisableReason::INITIALIZATION_PENDING};
template <int N>
std::atomic_uint8_t DccOutputHw<N>::isRailcomCutoutEnabled_ {
std::atomic_uint_least8_t DccOutputHw<N>::isRailcomCutoutEnabled_ {
(uint8_t)DccOutput::RailcomCutout::LONG_CUTOUT};
template <int N> uint8_t DccOutputHw<N>::isRailcomCutoutActive_ {0};

Expand Down
10 changes: 8 additions & 2 deletions src/freertos_drivers/arduino/CpuLoad.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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_

Expand Down Expand Up @@ -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
{
Expand All @@ -252,3 +257,4 @@ private:
};

#endif // _OS_CPULOAD_HXX_
#endif // OPENMRN_FEATURE_THREAD_FREERTOS
9 changes: 9 additions & 0 deletions src/freertos_drivers/arduino/WifiDefs.hxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _FREERTOS_DRIVERS_COMMON_WIFIDEFS_HXX_
#define _FREERTOS_DRIVERS_COMMON_WIFIDEFS_HXX_

#include <stdint.h>

/// 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, ...
Expand All @@ -22,6 +24,7 @@ enum class WlanState : uint8_t
CONNECT_STATIC,
CONNECT_FAILED,
CONNECTION_LOST,
WRONG_PASSWORD,
UPDATE_DISPLAY = 20,
};

Expand All @@ -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[];
Expand Down
11 changes: 11 additions & 0 deletions src/freertos_drivers/stm32/stm32f_hal_conf.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

#include <stm32yyxx_hal_conf.h>

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

0 comments on commit 38b33a9

Please sign in to comment.