ESPHome 2025.9.0-dev
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 <Wire.h>
7#include "i2c_bus.h"
8
9namespace esphome {
10namespace i2c {
11
17
18class ArduinoI2CBus : public InternalI2CBus, 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 int get_port() const override { return this->port_; }
33
34 private:
35 void recover_();
36 void set_pins_and_clock_();
37 RecoveryCode recovery_result_;
38
39 protected:
40 int8_t port_{-1};
41 TwoWire *wire_;
42 uint8_t sda_pin_;
43 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_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)
int get_port() const override
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
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:47
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