ESPHome  2024.11.3
mcp23016.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
6 
7 namespace esphome {
8 namespace mcp23016 {
9 
11  // 0 side
12  MCP23016_GP0 = 0x00,
18  // 1 side
19  MCP23016_GP1 = 0x01,
25 };
26 
27 class MCP23016 : public Component, public i2c::I2CDevice {
28  public:
29  MCP23016() = default;
30 
31  void setup() override;
32 
33  bool digital_read(uint8_t pin);
34  void digital_write(uint8_t pin, bool value);
35  void pin_mode(uint8_t pin, gpio::Flags flags);
36 
37  float get_setup_priority() const override;
38 
39  protected:
40  // read a given register
41  bool read_reg_(uint8_t reg, uint8_t *value);
42  // write a value to a given register
43  bool write_reg_(uint8_t reg, uint8_t value);
44  // update registers with given pin value.
45  void update_reg_(uint8_t pin, bool pin_value, uint8_t reg_a);
46 
47  uint8_t olat_0_{0x00};
48  uint8_t olat_1_{0x00};
49 };
50 
51 class MCP23016GPIOPin : public GPIOPin {
52  public:
53  void setup() override;
54  void pin_mode(gpio::Flags flags) override;
55  bool digital_read() override;
56  void digital_write(bool value) override;
57  std::string dump_summary() const override;
58 
59  void set_parent(MCP23016 *parent) { parent_ = parent; }
60  void set_pin(uint8_t pin) { pin_ = pin; }
61  void set_inverted(bool inverted) { inverted_ = inverted; }
62  void set_flags(gpio::Flags flags) { flags_ = flags; }
63 
64  protected:
66  uint8_t pin_;
67  bool inverted_;
69 };
70 
71 } // namespace mcp23016
72 } // namespace esphome
void pin_mode(uint8_t pin, gpio::Flags flags)
Definition: mcp23016.cpp:37
void setup() override
Definition: mcp23016.cpp:10
bool write_reg_(uint8_t reg, uint8_t value)
Definition: mcp23016.cpp:52
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition: i2c.h:149
void digital_write(uint8_t pin, bool value)
Definition: mcp23016.cpp:33
bool digital_read(uint8_t pin)
Definition: mcp23016.cpp:26
void set_flags(gpio::Flags flags)
Definition: mcp23016.h:62
const uint32_t flags
Definition: stm32flash.h:85
bool read_reg_(uint8_t reg, uint8_t *value)
Definition: mcp23016.cpp:46
void set_inverted(bool inverted)
Definition: mcp23016.h:61
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
float get_setup_priority() const override
Definition: mcp23016.cpp:45
void update_reg_(uint8_t pin, bool pin_value, uint8_t reg_a)
Definition: mcp23016.cpp:58
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133
void set_parent(MCP23016 *parent)
Definition: mcp23016.h:59