ESPHome  2024.10.2
tca9555.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include "esphome/core/hal.h"
7 
8 namespace esphome {
9 namespace tca9555 {
10 
11 class TCA9555Component : public Component,
12  public i2c::I2CDevice,
13  public gpio_expander::CachedGpioExpander<uint8_t, 16> {
14  public:
15  TCA9555Component() = default;
16 
18  void setup() override;
19  void pin_mode(uint8_t pin, gpio::Flags flags);
20 
21  float get_setup_priority() const override;
22 
23  void dump_config() override;
24 
25  void loop() override;
26 
27  protected:
28  bool digital_read_hw(uint8_t pin) override;
29  bool digital_read_cache(uint8_t pin) override;
30  void digital_write_hw(uint8_t pin, bool value) override;
31 
33  uint16_t mode_mask_{0x00};
35  uint16_t output_mask_{0x00};
37  uint16_t input_mask_{0x00};
38 
39  bool read_gpio_modes_();
40  bool write_gpio_modes_();
41  bool read_gpio_outputs_();
42 };
43 
45 class TCA9555GPIOPin : public GPIOPin, public Parented<TCA9555Component> {
46  public:
47  void setup() override;
48  void pin_mode(gpio::Flags flags) override;
49  bool digital_read() override;
50  void digital_write(bool value) override;
51  std::string dump_summary() const override;
52 
53  void set_pin(uint8_t pin) { this->pin_ = pin; }
54  void set_inverted(bool inverted) { this->inverted_ = inverted; }
55  void set_flags(gpio::Flags flags) { this->flags_ = flags; }
56 
57  protected:
58  uint8_t pin_;
59  bool inverted_;
61 };
62 
63 } // namespace tca9555
64 } // namespace esphome
uint16_t input_mask_
The state read in digital_read_hw - 1 means HIGH, 0 means LOW.
Definition: tca9555.h:37
bool digital_read_hw(uint8_t pin) override
Definition: tca9555.cpp:76
uint16_t mode_mask_
Mask for the pin mode - 1 means output, 0 means input.
Definition: tca9555.h:33
void set_pin(uint8_t pin)
Definition: tca9555.h:53
float get_setup_priority() const override
Definition: tca9555.cpp:131
void pin_mode(uint8_t pin, gpio::Flags flags)
Definition: tca9555.cpp:36
bool digital_read_cache(uint8_t pin) override
Definition: tca9555.cpp:129
void digital_write_hw(uint8_t pin, bool value) override
Definition: tca9555.cpp:93
Helper class to expose a TCA9555 pin as an internal input GPIO pin.
Definition: tca9555.h:45
void set_flags(gpio::Flags flags)
Definition: tca9555.h:55
uint16_t output_mask_
The mask to write as output state - 1 means HIGH, 0 means LOW.
Definition: tca9555.h:35
const uint32_t flags
Definition: stm32flash.h:85
A class to cache the read state of a GPIO expander.
Definition: cached_gpio.h:11
void set_inverted(bool inverted)
Definition: tca9555.h:54
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void setup() override
Check i2c availability and setup masks.
Definition: tca9555.cpp:18
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133
Helper class to easily give an object a parent of type T.
Definition: helpers.h:521