ESPHome 2026.6.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
5
6static const char *const TAG = "mcp23008";
7
8static constexpr uint8_t IOCON_ODR = 0x04; // Open-drain output for INT pin
9
11 uint8_t iocon;
12 if (!this->read_reg(mcp23x08_base::MCP23X08_IOCON, &iocon)) {
13 this->mark_failed();
14 return;
15 }
16
17 // Read current output register state
19
20 if (this->open_drain_ints_) {
21 // enable open-drain interrupt pins, 3.3V-safe
22 this->write_reg(mcp23x08_base::MCP23X08_IOCON, iocon | IOCON_ODR);
23 }
24
26}
27
29 ESP_LOGCONFIG(TAG, "MCP23008:");
30 LOG_PIN(" Interrupt Pin: ", this->interrupt_pin_);
31}
32
33bool MCP23008::read_reg(uint8_t reg, uint8_t *value) {
34 if (this->is_failed())
35 return false;
36
37 return this->read_byte(reg, value);
38}
39
40bool MCP23008::write_reg(uint8_t reg, uint8_t value) {
41 if (this->is_failed())
42 return false;
43
44 return this->write_byte(reg, value);
45}
46
47} // namespace esphome::mcp23008
void mark_failed()
Mark this component as failed.
bool is_failed() const
Definition component.h:272
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:40
void dump_config() override
Definition mcp23008.cpp:28
bool read_reg(uint8_t reg, uint8_t *value) override
Definition mcp23008.cpp:33