--- title: Configuration System description: Global configuration and constants for firmware keywords: [configuration, pins, platform, ESP32, defines, settings] --- ## Configuration System **Path**: [src/config.h](../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 - [Arduino.h](https://www.arduino.cc/reference/en/) - Core Arduino library - [config_adv.h](../src/config_adv.h) - Advanced configuration settings - [stdint.h](https://en.cppreference.com/w/cpp/header/cstdint) - Standard integer types ```mermaid 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. ```mermaid 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: ```cpp #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 - ESP32 GPIO Pin documentation: [ESP32 Technical Reference Manual](https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf)