ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
mcp23s08.cpp
Go to the documentation of this file.
1#include "mcp23s08.h"
2#include "esphome/core/log.h"
3
4namespace esphome {
5namespace mcp23s08 {
6
7static const char *const TAG = "mcp23s08";
8
9void MCP23S08::set_device_address(uint8_t device_addr) {
10 if (device_addr != 0) {
11 this->device_opcode_ |= ((device_addr & 0x03) << 1);
12 }
13}
14
16 this->spi_setup();
17
18 this->enable();
19 uint8_t cmd = 0b01000000;
20 this->transfer_byte(cmd);
22 this->transfer_byte(0b00011000); // Enable HAEN pins for addressing
23 this->disable();
24
25 // Read current output register state
27
28 if (this->open_drain_ints_) {
29 // enable open-drain interrupt pins, 3.3V-safe
31 }
32}
33
35 ESP_LOGCONFIG(TAG, "MCP23S08:");
36 LOG_PIN(" CS Pin: ", this->cs_);
37}
38
39bool MCP23S08::read_reg(uint8_t reg, uint8_t *value) {
40 this->enable();
41 this->transfer_byte(this->device_opcode_ | 1);
42 this->transfer_byte(reg);
43 *value = this->transfer_byte(0);
44 this->disable();
45 return true;
46}
47
48bool MCP23S08::write_reg(uint8_t reg, uint8_t value) {
49 this->enable();
50 this->transfer_byte(this->device_opcode_);
51 this->transfer_byte(reg);
52 this->transfer_byte(value);
53 this->disable();
54 return true;
55}
56
57} // namespace mcp23s08
58} // namespace esphome
bool write_reg(uint8_t reg, uint8_t value) override
Definition mcp23s08.cpp:48
void dump_config() override
Definition mcp23s08.cpp:34
void set_device_address(uint8_t device_addr)
Definition mcp23s08.cpp:9
bool read_reg(uint8_t reg, uint8_t *value) override
Definition mcp23s08.cpp:39
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7