ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
mcp23008.cpp
Go to the documentation of this file.
1#include "mcp23008.h"
2#include "esphome/core/log.h"
3
4namespace esphome {
5namespace mcp23008 {
6
7static const char *const TAG = "mcp23008";
8
9static constexpr uint8_t IOCON_ODR = 0x04; // Open-drain output for INT pin
10
12 uint8_t iocon;
13 if (!this->read_reg(mcp23x08_base::MCP23X08_IOCON, &iocon)) {
14 this->mark_failed();
15 return;
16 }
17
18 // Read current output register state
20
21 if (this->open_drain_ints_) {
22 // enable open-drain interrupt pins, 3.3V-safe
23 this->write_reg(mcp23x08_base::MCP23X08_IOCON, iocon | IOCON_ODR);
24 }
25
27}
28
30 ESP_LOGCONFIG(TAG, "MCP23008:");
31 LOG_PIN(" Interrupt Pin: ", this->interrupt_pin_);
32}
33
34bool MCP23008::read_reg(uint8_t reg, uint8_t *value) {
35 if (this->is_failed())
36 return false;
37
38 return this->read_byte(reg, value);
39}
40
41bool MCP23008::write_reg(uint8_t reg, uint8_t value) {
42 if (this->is_failed())
43 return false;
44
45 return this->write_byte(reg, value);
46}
47
48} // namespace mcp23008
49} // namespace esphome
void mark_failed()
Mark this component as failed.
bool is_failed() const
Definition component.h:284
bool write_byte(uint8_t a_register, uint8_t data) const
Definition i2c.h:265
bool read_byte(uint8_t a_register, uint8_t *data)
Definition i2c.h:240
bool write_reg(uint8_t reg, uint8_t value) override
Definition mcp23008.cpp:41
void dump_config() override
Definition mcp23008.cpp:29
bool read_reg(uint8_t reg, uint8_t *value) override
Definition mcp23008.cpp:34
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7