ESPHome  2024.11.1
i2c_bus_arduino.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef USE_ARDUINO
4 
5 #include "i2c_bus.h"
7 #include <Wire.h>
8 
9 namespace esphome {
10 namespace i2c {
11 
16 };
17 
18 class ArduinoI2CBus : 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_scl_pin(uint8_t scl_pin) { scl_pin_ = scl_pin; }
30  void set_timeout(uint32_t timeout) { timeout_ = timeout; }
31 
32  private:
33  void recover_();
34  void set_pins_and_clock_();
35  RecoveryCode recovery_result_;
36 
37  protected:
38  TwoWire *wire_;
39  uint8_t sda_pin_;
40  uint8_t scl_pin_;
41  uint32_t frequency_;
42  uint32_t timeout_ = 0;
43  bool initialized_ = false;
44 };
45 
46 } // namespace i2c
47 } // namespace esphome
48 
49 #endif // USE_ARDUINO
the WriteBuffer structure stores a pointer to a write buffer and its length
Definition: i2c_bus.h:30
the ReadBuffer structure stores a pointer to a read buffer and its length
Definition: i2c_bus.h:24
void set_scl_pin(uint8_t scl_pin)
const float BUS
For communication buses like i2c/spi.
Definition: component.cpp:16
This Class provides the methods to read and write bytes from an I2CBus.
Definition: i2c_bus.h:40
float get_setup_priority() const override
ErrorCode writev(uint8_t address, WriteBuffer *buffers, size_t cnt, bool stop) override
uint16_le_t frequency
Definition: bl0942.h:72
bool scan_
Should we scan ? Can be set in the yaml.
Definition: i2c_bus.h:108
ErrorCode readv(uint8_t address, ReadBuffer *buffers, size_t cnt) override
void set_timeout(uint32_t timeout)
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
uint8_t address
Definition: bl0906.h:211
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition: i2c_bus.h:11
void set_sda_pin(uint8_t sda_pin)
void set_frequency(uint32_t frequency)