firmware-base/docs/components/GPIO.md
2025-06-03 16:21:36 +02:00

2.0 KiB

title description keywords
GPIO Component Documentation for the MB_GPIO component, which manages a group of GPIO pins with Modbus interface ESP-32, GPIO, Modbus, industrial, embedded, C++

GPIO

path: src/components/GPIO.h

revision history: initial documentation

The MB_GPIO component provides centralized management of GPIO pins with Modbus interface support. It allows configuration of multiple pins with different modes (input, output, analog, etc.) and maps them to Modbus registers for remote access.

REQUIREMENTS

  • ESP32 microcontroller
  • PlatformIO environment
  • Arduino framework (for GPIO functions)
  • Modbus-485 interface
  • Logging library (ArduinoLog.h)
  • Modbus library (ModbusTCP.h)
  • Component system dependencies

FEATURES

  • Configurable GPIO pins with multiple modes:
    • Input
    • Output
    • Input with pullup/pulldown
    • Output open-drain
    • Analog input
    • Touch input
  • Modbus interface support
    • Read/Write operations
    • Access control per pin
    • Throttling to prevent excessive operations
  • Runtime configuration via JSON
  • Pin state caching to avoid unnecessary operations
  • Built-in logging and debugging

TODOS

  • Add support for input pulldown mode
  • Implement touch input functionality
  • Add more comprehensive error handling
  • Implement capability checks based on ESP32 pin capabilities

EXAMPLE

GPIO configuration example

#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_ADDRS // 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