ESPHome  2022.5.1
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; }
31  void set_frequency(uint32_t frequency) { frequency_ = frequency; }
32 
33  private:
34  void recover_();
35  RecoveryCode recovery_result_;
36 
37  protected:
38  i2c_port_t port_;
39  uint8_t sda_pin_;
41  uint8_t scl_pin_;
43  uint32_t frequency_;
44  bool initialized_ = false;
45 };
46 
47 } // namespace i2c
48 } // namespace esphome
49 
50 #endif // USE_ESP_IDF
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)
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:15
void set_scl_pullup_enabled(bool scl_pullup_enabled)
void set_scan(bool scan)
Definition: a4988.cpp:4
void set_scl_pin(uint8_t scl_pin)