ESPHome  2022.8.0
mcp23017.cpp
Go to the documentation of this file.
1 #include "mcp23017.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace mcp23017 {
6 
7 static const char *const TAG = "mcp23017";
8 
10  ESP_LOGCONFIG(TAG, "Setting up MCP23017...");
11  uint8_t iocon;
12  if (!this->read_reg(mcp23x17_base::MCP23X17_IOCONA, &iocon)) {
13  this->mark_failed();
14  return;
15  }
16 
17  if (this->open_drain_ints_) {
18  // enable open-drain interrupt pins, 3.3V-safe
21  }
22 }
23 
24 void MCP23017::dump_config() { ESP_LOGCONFIG(TAG, "MCP23017:"); }
25 
26 bool MCP23017::read_reg(uint8_t reg, uint8_t *value) {
27  if (this->is_failed())
28  return false;
29 
30  return this->read_byte(reg, value);
31 }
32 bool MCP23017::write_reg(uint8_t reg, uint8_t value) {
33  if (this->is_failed())
34  return false;
35 
36  return this->write_byte(reg, value);
37 }
38 
39 } // namespace mcp23017
40 } // namespace esphome
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
Definition: i2c.h:96
bool write_reg(uint8_t reg, uint8_t value) override
Definition: mcp23017.cpp:32
I2CRegister reg(uint8_t a_register)
Definition: i2c.h:46
void setup() override
Definition: mcp23017.cpp:9
bool read_reg(uint8_t reg, uint8_t *value) override
Definition: mcp23017.cpp:26
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
Definition: i2c.h:123
virtual void mark_failed()
Mark this component as failed.
Definition: component.cpp:111
Definition: a4988.cpp:4
void dump_config() override
Definition: mcp23017.cpp:24