Merge branch 'dump_summary' into integration

This commit is contained in:
J. Nick Koston
2025-12-30 13:29:31 -10:00
2 changed files with 31 additions and 4 deletions

View File

@@ -2,12 +2,11 @@
#include "esphome/core/log.h"
#include <algorithm>
#include <cstring>
namespace esphome {
void log_pin(const char *tag, const char *prefix, GPIOPin *pin) {
if (pin == nullptr)
return;
static void log_pin_with_prefix(const char *tag, const char *prefix, GPIOPin *pin) {
char buffer[GPIO_SUMMARY_MAX_LEN];
size_t len = pin->dump_summary(buffer, sizeof(buffer));
// Clamp to actual buffer size (snprintf returns would-be length)
@@ -15,4 +14,28 @@ void log_pin(const char *tag, const char *prefix, GPIOPin *pin) {
esp_log_printf_(ESPHOME_LOG_LEVEL_CONFIG, tag, __LINE__, "%s%.*s", prefix, (int) len, buffer);
}
#ifdef USE_ESP8266
static constexpr size_t LOG_PIN_PREFIX_MAX_LEN = 32;
void log_pin(const char *tag, const __FlashStringHelper *prefix, GPIOPin *pin) {
if (pin == nullptr)
return;
// Copy prefix from flash to stack
char prefix_buf[LOG_PIN_PREFIX_MAX_LEN];
strncpy_P(prefix_buf, reinterpret_cast<const char *>(prefix), sizeof(prefix_buf) - 1);
prefix_buf[sizeof(prefix_buf) - 1] = '\0';
log_pin_with_prefix(tag, prefix_buf, pin);
}
#else
void log_pin(const char *tag, const char *prefix, GPIOPin *pin) {
if (pin == nullptr)
return;
log_pin_with_prefix(tag, prefix, pin);
}
#endif
} // namespace esphome

View File

@@ -14,9 +14,13 @@ inline constexpr size_t GPIO_SUMMARY_MAX_LEN = 48;
class GPIOPin; // Forward declaration
/// Log a pin summary to the config log
#ifdef USE_ESP8266
void log_pin(const char *tag, const __FlashStringHelper *prefix, GPIOPin *pin);
#define LOG_PIN(prefix, pin) log_pin(TAG, F(prefix), pin)
#else
void log_pin(const char *tag, const char *prefix, GPIOPin *pin);
#define LOG_PIN(prefix, pin) log_pin(TAG, prefix, pin)
#endif
// put GPIO flags in a namespace to not pollute esphome namespace
namespace gpio {