firmware-base/docs/config.md

4.3 KiB

title description keywords
Configuration System Global configuration and constants for firmware
configuration
pins
platform
ESP32
defines
settings

Configuration System

Path: src/config.h

Revision History: Initial documentation

The configuration system is a centralized header file containing all global settings, pin definitions, platform-specific configurations, and feature flags. It provides a unified interface for configuring hardware dependencies, communication protocols, and enabling/disabling various features of the firmware.

REQUIREMENTS

  • ESP-32 microcontroller (with support for other platforms like Portenta H7, Controllino Mega)
  • Platform.io development environment
  • Configuration is designed to work with Modbus-485 protocol for industrial applications

FEATURES

  • Automatic platform detection (ESP32, Portenta H7, Controllino Mega, Arduino Uno)
  • Component ID enumeration for consistent system-wide component identification
  • Configurable GPIO pin assignments for various peripherals
  • Network configuration for WiFi in both station and access point modes
  • Modbus TCP and RS485 communication settings
  • Temperature profile and signal plotting configuration
  • Customizable debugging and logging options
  • Feature flags for enabling/disabling system components

DEPENDENCIES

graph TD
    config[config.h] --> arduino[Arduino.h]
    config --> configadv[config_adv.h]
    config --> stdint[stdint.h]
    config --> platformlibs[Platform-specific Libraries]

BEHAVIOUR

The configuration system is a static definition file that controls the behavior of the firmware at compile time. It doesn't have runtime behavior itself, but dictates which components are initialized and how they operate.

graph TD
    Config[Configuration System] --> PlatformDetection[Platform Detection]
    Config --> ComponentIDs[Component ID Assignment]
    Config --> FeatureFlags[Feature Flags]
    FeatureFlags --> EnabledComponents[Enabled Components]
    FeatureFlags --> DisabledComponents[Disabled Components]
    Config --> NetworkSettings[Network Settings]
    Config --> PinAssignments[Pin Assignments]

TODOS

PERFORMANCE

  • Consider separating platform-specific configurations into dedicated files
  • Evaluate the impact of enabled debugging flags on performance
  • Review pin assignment efficiency for optimal GPIO usage

SECURITY

  • WiFi credentials are hardcoded - implement secure storage or configuration mechanism
  • Consider encryption for sensitive communications
  • Review and secure default access point settings

COMPLIANCE

  • Review for compliance with industrial standards
  • Consider adding provisions for safety-critical systems where applicable
  • Document electrical specifications for compliance with relevant regulations

RECOMMENDATIONS

  • Use preprocessor guards when modifying to ensure backward compatibility
  • When adding new components, follow the existing ID assignment pattern
  • Consider implementing a runtime configuration system to complement static definitions
  • Separate network credentials into a separate secure file

EXAMPLE

The configuration system is used primarily as an include in other components. For example, when initializing an LED Feedback component:

#ifdef PIN_LED_FEEDBACK_0
  ledFeedback_0 = new LEDFeedback(
      this,                  // owner
      PIN_LED_FEEDBACK_0,    // pin
      LED_PIXEL_COUNT_0,     // pixelCount
      ID_LED_FEEDBACK_0,     // id
      LED_FEEDBACK_0_MB_ADDR // modbusAddress
  );
  if (ledFeedback_0)
  {
    components.push_back(ledFeedback_0);
    Log.infoln(F("LEDFeedback_0 initialized. Pin:%d, Count:%d, ID:%d, MB:%d"),
               PIN_LED_FEEDBACK_0, LED_PIXEL_COUNT_0,
               ID_LED_FEEDBACK_0, LED_FEEDBACK_0_MB_ADDR);
  }
  else
  {
    Log.errorln(F("LEDFeedback_0 initialization failed."));
  }
#endif

References