1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 14:43:51 +00:00
This commit is contained in:
J. Nick Koston
2025-09-04 12:57:44 -05:00
parent ee090c7c38
commit 5b0d1fb30e
8 changed files with 145 additions and 15 deletions

View File

@@ -27,11 +27,13 @@ void GPIOExpanderTestComponent::setup() {
bool GPIOExpanderTestComponent::digital_read_hw(uint8_t pin) {
ESP_LOGD(TAG, "digital_read_hw pin=%d", pin);
// Return true to indicate successful read operation
return true;
}
bool GPIOExpanderTestComponent::digital_read_cache(uint8_t pin) {
ESP_LOGD(TAG, "digital_read_cache pin=%d", pin);
// Return the pin state (always HIGH for testing)
return true;
}

View File

@@ -0,0 +1,24 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.const import CONF_ID
AUTO_LOAD = ["gpio_expander"]
gpio_expander_test_component_uint16_ns = cg.esphome_ns.namespace(
"gpio_expander_test_component_uint16"
)
GPIOExpanderTestUint16Component = gpio_expander_test_component_uint16_ns.class_(
"GPIOExpanderTestUint16Component", cg.Component
)
CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(): cv.declare_id(GPIOExpanderTestUint16Component),
}
).extend(cv.COMPONENT_SCHEMA)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)

View File

@@ -0,0 +1,43 @@
#include "gpio_expander_test_component_uint16.h"
#include "esphome/core/log.h"
namespace esphome::gpio_expander_test_component_uint16 {
static const char *const TAG = "gpio_expander_test_uint16";
void GPIOExpanderTestUint16Component::setup() {
ESP_LOGD(TAG, "Testing uint16_t bank (single 16-pin bank)");
// Test reading all 16 pins - first should trigger hw read, rest use cache
for (uint8_t pin = 0; pin < 16; pin++) {
this->digital_read(pin);
}
// Reset cache and test specific reads
ESP_LOGD(TAG, "Resetting cache for uint16_t test");
this->reset_pin_cache_();
// First read triggers hw for entire bank
this->digital_read(5);
// These should all use cache since they're in the same bank
this->digital_read(10);
this->digital_read(15);
this->digital_read(0);
ESP_LOGD(TAG, "DONE_UINT16");
}
bool GPIOExpanderTestUint16Component::digital_read_hw(uint8_t pin) {
ESP_LOGD(TAG, "uint16_digital_read_hw pin=%d", pin);
// In a real component, this would read from I2C/SPI into internal state
// For testing, we just return true to indicate successful read
return true; // Return true to indicate successful read
}
bool GPIOExpanderTestUint16Component::digital_read_cache(uint8_t pin) {
ESP_LOGD(TAG, "uint16_digital_read_cache pin=%d", pin);
// Return the actual pin state from our test pattern
return (this->test_state_ >> pin) & 1;
}
} // namespace esphome::gpio_expander_test_component_uint16

View File

@@ -0,0 +1,23 @@
#pragma once
#include "esphome/components/gpio_expander/cached_gpio.h"
#include "esphome/core/component.h"
namespace esphome::gpio_expander_test_component_uint16 {
// Test component using uint16_t bank type (single 16-pin bank)
class GPIOExpanderTestUint16Component : public Component,
public esphome::gpio_expander::CachedGpioExpander<uint16_t, 16> {
public:
void setup() override;
protected:
bool digital_read_hw(uint8_t pin) override;
bool digital_read_cache(uint8_t pin) override;
void digital_write_hw(uint8_t pin, bool value) override{};
private:
uint16_t test_state_{0xAAAA}; // Test pattern: alternating bits
};
} // namespace esphome::gpio_expander_test_component_uint16