diff --git a/esphome/core/gpio.cpp b/esphome/core/gpio.cpp new file mode 100644 index 0000000000..d8353ab64c --- /dev/null +++ b/esphome/core/gpio.cpp @@ -0,0 +1,14 @@ +#include "esphome/core/gpio.h" +#include "esphome/core/log.h" + +namespace esphome { + +void log_pin(const char *tag, const char *prefix, GPIOPin *pin) { + if (pin == nullptr) + return; + char buffer[GPIO_SUMMARY_MAX_LEN]; + pin->dump_summary(buffer, sizeof(buffer)); + esp_log_printf_(ESPHOME_LOG_LEVEL_CONFIG, tag, __LINE__, "%s%s", prefix, buffer); +} + +} // namespace esphome diff --git a/esphome/core/gpio.h b/esphome/core/gpio.h index 5d25fd4ad1..fe53802abf 100644 --- a/esphome/core/gpio.h +++ b/esphome/core/gpio.h @@ -11,12 +11,12 @@ namespace esphome { /// Maximum buffer size for dump_summary output inline constexpr size_t GPIO_SUMMARY_MAX_LEN = 48; -#define LOG_PIN(prefix, pin) \ - if ((pin) != nullptr) { \ - char esphome_pin_buf_[GPIO_SUMMARY_MAX_LEN]; \ - (pin)->dump_summary(esphome_pin_buf_, sizeof(esphome_pin_buf_)); \ - ESP_LOGCONFIG(TAG, prefix "%s", esphome_pin_buf_); \ - } +class GPIOPin; // Forward declaration + +/// Log a pin summary to the config log +void log_pin(const char *tag, const char *prefix, GPIOPin *pin); + +#define LOG_PIN(prefix, pin) log_pin(TAG, prefix, pin) // put GPIO flags in a namespace to not pollute esphome namespace namespace gpio {