[debug] Add iram sensor for ESP32

This commit is contained in:
J. Nick Koston
2026-04-14 15:47:48 -10:00
parent 193e7d476d
commit 07b129a58a
6 changed files with 26 additions and 0 deletions
@@ -45,6 +45,7 @@ class DebugComponent : public PollingComponent {
void set_loop_time_sensor(sensor::Sensor *loop_time_sensor) { loop_time_sensor_ = loop_time_sensor; } void set_loop_time_sensor(sensor::Sensor *loop_time_sensor) { loop_time_sensor_ = loop_time_sensor; }
#ifdef USE_ESP32 #ifdef USE_ESP32
void set_psram_sensor(sensor::Sensor *psram_sensor) { this->psram_sensor_ = psram_sensor; } void set_psram_sensor(sensor::Sensor *psram_sensor) { this->psram_sensor_ = psram_sensor; }
void set_iram_sensor(sensor::Sensor *iram_sensor) { this->iram_sensor_ = iram_sensor; }
#endif // USE_ESP32 #endif // USE_ESP32
void set_cpu_frequency_sensor(sensor::Sensor *cpu_frequency_sensor) { void set_cpu_frequency_sensor(sensor::Sensor *cpu_frequency_sensor) {
this->cpu_frequency_sensor_ = cpu_frequency_sensor; this->cpu_frequency_sensor_ = cpu_frequency_sensor;
@@ -71,6 +72,7 @@ class DebugComponent : public PollingComponent {
sensor::Sensor *loop_time_sensor_{nullptr}; sensor::Sensor *loop_time_sensor_{nullptr};
#ifdef USE_ESP32 #ifdef USE_ESP32
sensor::Sensor *psram_sensor_{nullptr}; sensor::Sensor *psram_sensor_{nullptr};
sensor::Sensor *iram_sensor_{nullptr};
#endif // USE_ESP32 #endif // USE_ESP32
sensor::Sensor *cpu_frequency_sensor_{nullptr}; sensor::Sensor *cpu_frequency_sensor_{nullptr};
#endif // USE_SENSOR #endif // USE_SENSOR
+3
View File
@@ -301,6 +301,9 @@ void DebugComponent::update_platform_() {
if (this->psram_sensor_ != nullptr) { if (this->psram_sensor_ != nullptr) {
this->psram_sensor_->publish_state(heap_caps_get_free_size(MALLOC_CAP_SPIRAM)); this->psram_sensor_->publish_state(heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
} }
if (this->iram_sensor_ != nullptr) {
this->iram_sensor_->publish_state(heap_caps_get_free_size(MALLOC_CAP_IRAM_8BIT));
}
#endif #endif
} }
+15
View File
@@ -32,6 +32,7 @@ DEPENDENCIES = ["debug"]
CONF_MIN_FREE = "min_free" CONF_MIN_FREE = "min_free"
CONF_PSRAM = "psram" CONF_PSRAM = "psram"
CONF_IRAM = "iram"
CONFIG_SCHEMA = { CONFIG_SCHEMA = {
cv.GenerateID(CONF_DEBUG_ID): cv.use_id(DebugComponent), cv.GenerateID(CONF_DEBUG_ID): cv.use_id(DebugComponent),
@@ -98,6 +99,16 @@ CONFIG_SCHEMA = {
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
), ),
cv.Optional(CONF_IRAM): cv.All(
cv.only_on_esp32,
sensor.sensor_schema(
unit_of_measurement=UNIT_BYTES,
icon=ICON_COUNTER,
accuracy_decimals=0,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
state_class=STATE_CLASS_MEASUREMENT,
),
),
cv.Optional(CONF_CPU_FREQUENCY): cv.All( cv.Optional(CONF_CPU_FREQUENCY): cv.All(
sensor.sensor_schema( sensor.sensor_schema(
unit_of_measurement=UNIT_HERTZ, unit_of_measurement=UNIT_HERTZ,
@@ -138,6 +149,10 @@ async def to_code(config):
sens = await sensor.new_sensor(psram_conf) sens = await sensor.new_sensor(psram_conf)
cg.add(debug_component.set_psram_sensor(sens)) cg.add(debug_component.set_psram_sensor(sens))
if iram_conf := config.get(CONF_IRAM):
sens = await sensor.new_sensor(iram_conf)
cg.add(debug_component.set_iram_sensor(sens))
if cpu_freq_conf := config.get(CONF_CPU_FREQUENCY): if cpu_freq_conf := config.get(CONF_CPU_FREQUENCY):
sens = await sensor.new_sensor(cpu_freq_conf) sens = await sensor.new_sensor(cpu_freq_conf)
cg.add(debug_component.set_cpu_frequency_sensor(sens)) cg.add(debug_component.set_cpu_frequency_sensor(sens))
@@ -9,3 +9,5 @@ sensor:
name: "Heap Fragmentation" name: "Heap Fragmentation"
min_free: min_free:
name: "Heap Min Free" name: "Heap Min Free"
iram:
name: "Free IRAM"
@@ -13,5 +13,7 @@ sensor:
name: "Heap Fragmentation" name: "Heap Fragmentation"
min_free: min_free:
name: "Heap Min Free" name: "Heap Min Free"
iram:
name: "Free IRAM"
psram: psram:
@@ -6,3 +6,5 @@ sensor:
name: "Heap Fragmentation" name: "Heap Fragmentation"
min_free: min_free:
name: "Heap Min Free" name: "Heap Min Free"
iram:
name: "Free IRAM"