ESPHome  2024.9.2
i2c_bus_esp_idf.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef USE_ESP_IDF
4 
5 #include "i2c_bus.h"
7 #include <driver/i2c.h>
8 
9 namespace esphome {
10 namespace i2c {
11 
16 };
17 
18 class IDFI2CBus : public I2CBus, public Component {
19  public:
20  void setup() override;
21  void dump_config() override;
22  ErrorCode readv(uint8_t address, ReadBuffer *buffers, size_t cnt) override;
23  ErrorCode writev(uint8_t address, WriteBuffer *buffers, size_t cnt, bool stop) override;
24  float get_setup_priority() const override { return setup_priority::BUS; }
25 
26  void set_scan(bool scan) { scan_ = scan; }
27  void set_sda_pin(uint8_t sda_pin) { sda_pin_ = sda_pin; }
28  void set_sda_pullup_enabled(bool sda_pullup_enabled) { sda_pullup_enabled_ = sda_pullup_enabled; }
29  void set_scl_pin(uint8_t scl_pin) { scl_pin_ = scl_pin; }
30  void set_scl_pullup_enabled(bool scl_pullup_enabled) { scl_pullup_enabled_ = scl_pullup_enabled; }
32  void set_timeout(uint32_t timeout) { timeout_ = timeout; }
33 
34  private:
35  void recover_();
36  RecoveryCode recovery_result_;
37 
38  protected:
39  i2c_port_t port_;
40  uint8_t sda_pin_;
42  uint8_t scl_pin_;
44  uint32_t frequency_;
45  uint32_t timeout_ = 0;
46  bool initialized_ = false;
47 };
48 
49 } // namespace i2c
50 } // namespace esphome
51 
52 #endif // USE_ESP_IDF
the WriteBuffer structure stores a pointer to a write buffer and its length
Definition: i2c_bus.h:30
float get_setup_priority() const override
void set_sda_pin(uint8_t sda_pin)
void dump_config() override
void set_sda_pullup_enabled(bool sda_pullup_enabled)
the ReadBuffer structure stores a pointer to a read buffer and its length
Definition: i2c_bus.h:24
ErrorCode writev(uint8_t address, WriteBuffer *buffers, size_t cnt, bool stop) override
void set_frequency(uint32_t frequency)
ErrorCode readv(uint8_t address, ReadBuffer *buffers, size_t cnt) override
const float BUS
For communication buses like i2c/spi.
Definition: component.cpp:16
void set_scl_pullup_enabled(bool scl_pullup_enabled)
This Class provides the methods to read and write bytes from an I2CBus.
Definition: i2c_bus.h:40
void set_scan(bool scan)
uint16_le_t frequency
Definition: bl0942.h:72
bool scan_
Should we scan ? Can be set in the yaml.
Definition: i2c_bus.h:108
void set_timeout(uint32_t timeout)
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_scl_pin(uint8_t scl_pin)
uint8_t address
Definition: bl0906.h:211
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition: i2c_bus.h:11