ESPHome  2024.5.4
mcp23s08.cpp
Go to the documentation of this file.
1 #include "mcp23s08.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace mcp23s08 {
6 
7 static const char *const TAG = "mcp23s08";
8 
9 void 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  ESP_LOGCONFIG(TAG, "Setting up MCP23S08...");
17  this->spi_setup();
18 
19  this->enable();
20  uint8_t cmd = 0b01000000;
21  this->transfer_byte(cmd);
23  this->transfer_byte(0b00011000); // Enable HAEN pins for addressing
24  this->disable();
25 
26  // Read current output register state
28 
29  if (this->open_drain_ints_) {
30  // enable open-drain interrupt pins, 3.3V-safe
32  }
33 }
34 
36  ESP_LOGCONFIG(TAG, "MCP23S08:");
37  LOG_PIN(" CS Pin: ", this->cs_);
38 }
39 
40 bool MCP23S08::read_reg(uint8_t reg, uint8_t *value) {
41  this->enable();
42  this->transfer_byte(this->device_opcode_ | 1);
43  this->transfer_byte(reg);
44  *value = this->transfer_byte(0);
45  this->disable();
46  return true;
47 }
48 
49 bool MCP23S08::write_reg(uint8_t reg, uint8_t value) {
50  this->enable();
51  this->transfer_byte(this->device_opcode_);
52  this->transfer_byte(reg);
53  this->transfer_byte(value);
54  this->disable();
55  return true;
56 }
57 
58 } // namespace mcp23s08
59 } // namespace esphome
void dump_config() override
Definition: mcp23s08.cpp:35
GPIOPin * cs_
Definition: spi.h:395
void setup() override
Definition: mcp23s08.cpp:15
void set_device_address(uint8_t device_addr)
Definition: mcp23s08.cpp:9
bool write_reg(uint8_t reg, uint8_t value) override
Definition: mcp23s08.cpp:49
bool read_reg(uint8_t reg, uint8_t *value) override
Definition: mcp23s08.cpp:40
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
stm32_cmd_t * cmd
Definition: stm32flash.h:96