ESPHome 2025.5.0
Loading...
Searching...
No Matches
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
9namespace esphome {
10namespace i2c {
11
17
18class 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
uint8_t address
Definition bl0906.h:4
uint16_le_t frequency
Definition bl0942.h:6
void set_scl_pin(uint8_t scl_pin)
float get_setup_priority() const override
void set_timeout(uint32_t timeout)
void set_frequency(uint32_t frequency)
ErrorCode writev(uint8_t address, WriteBuffer *buffers, size_t cnt, bool stop) override
void set_sda_pin(uint8_t sda_pin)
ErrorCode readv(uint8_t address, ReadBuffer *buffers, size_t cnt) override
This Class provides the methods to read and write bytes from an I2CBus.
Definition i2c_bus.h:40
bool scan_
Should we scan ? Can be set in the yaml.
Definition i2c_bus.h:108
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition i2c_bus.h:11
const float BUS
For communication buses like i2c/spi.
Definition component.cpp:16
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
the ReadBuffer structure stores a pointer to a read buffer and its length
Definition i2c_bus.h:24
the WriteBuffer structure stores a pointer to a write buffer and its length
Definition i2c_bus.h:30