ESPHome  2022.11.3
mcp23xxx_base.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
5 
6 namespace esphome {
7 namespace mcp23xxx_base {
8 
10 
11 class MCP23XXXBase : public Component {
12  public:
13  virtual bool digital_read(uint8_t pin);
14  virtual void digital_write(uint8_t pin, bool value);
15  virtual void pin_mode(uint8_t pin, gpio::Flags flags);
16  virtual void pin_interrupt_mode(uint8_t pin, MCP23XXXInterruptMode interrupt_mode);
17 
18  void set_open_drain_ints(const bool value) { this->open_drain_ints_ = value; }
19  float get_setup_priority() const override;
20 
21  protected:
22  // read a given register
23  virtual bool read_reg(uint8_t reg, uint8_t *value);
24  // write a value to a given register
25  virtual bool write_reg(uint8_t reg, uint8_t value);
26  // update registers with given pin value.
27  virtual void update_reg(uint8_t pin, bool pin_value, uint8_t reg_a);
28 
30 };
31 
32 class MCP23XXXGPIOPin : public GPIOPin {
33  public:
34  void setup() override;
35  void pin_mode(gpio::Flags flags) override;
36  bool digital_read() override;
37  void digital_write(bool value) override;
38  std::string dump_summary() const override;
39 
40  void set_parent(MCP23XXXBase *parent) { parent_ = parent; }
41  void set_pin(uint8_t pin) { pin_ = pin; }
42  void set_inverted(bool inverted) { inverted_ = inverted; }
43  void set_flags(gpio::Flags flags) { flags_ = flags; }
44  void set_interrupt_mode(MCP23XXXInterruptMode interrupt_mode) { interrupt_mode_ = interrupt_mode; }
45 
46  protected:
48  uint8_t pin_;
49  bool inverted_;
52 };
53 
54 } // namespace mcp23xxx_base
55 } // namespace esphome
void set_parent(MCP23XXXBase *parent)
Definition: mcp23xxx_base.h:40
void set_interrupt_mode(MCP23XXXInterruptMode interrupt_mode)
Definition: mcp23xxx_base.h:44
virtual bool write_reg(uint8_t reg, uint8_t value)
void set_open_drain_ints(const bool value)
Definition: mcp23xxx_base.h:18
virtual void setup()
Where the component's initialization should happen.
Definition: component.cpp:47
virtual void pin_interrupt_mode(uint8_t pin, MCP23XXXInterruptMode interrupt_mode)
const uint32_t flags
Definition: stm32flash.h:85
virtual void update_reg(uint8_t pin, bool pin_value, uint8_t reg_a)
virtual void pin_mode(uint8_t pin, gpio::Flags flags)
virtual bool read_reg(uint8_t reg, uint8_t *value)
Definition: a4988.cpp:4
virtual bool digital_read(uint8_t pin)
virtual void digital_write(uint8_t pin, bool value)
float get_setup_priority() const override