ESPHome  2024.2.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 
31  private:
32  void recover_();
33  RecoveryCode recovery_result_;
34 
35  protected:
36  TwoWire *wire_;
37  uint8_t sda_pin_;
38  uint8_t scl_pin_;
39  uint32_t frequency_;
40  bool initialized_ = false;
41 };
42 
43 } // namespace i2c
44 } // namespace esphome
45 
46 #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:15
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:21
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
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
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)