ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
i2c_bus_host.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_HOST
4
6#include "esphome/core/log.h"
7#include "i2c_bus.h"
8
9namespace esphome::i2c {
10
11class HostI2CBus final : public I2CBus, public Component {
12 public:
13 ~HostI2CBus() override;
14
15 void setup() override;
16 void dump_config() override;
17 float get_setup_priority() const override { return setup_priority::BUS; }
18
19 ErrorCode write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count, uint8_t *read_buffer,
20 size_t read_count) override;
21
22 void set_device(const std::string &device) { this->device_ = device; }
23 void set_scan(bool scan) { this->scan_ = scan; }
24
26#ifdef I2C_PORT_FREQUENCY_COUNT
27 // The kernel driver owns the clock, so switch_frequency keeps the base default
28 uint32_t get_frequency() const override { return this->frequency_; }
29#endif
30
31 const std::string &get_device() const { return this->device_; }
32
33 protected:
34 void update_error_(const std::string &error);
36
37 std::string device_;
40 bool initialized_{false};
41 std::string first_error_;
42};
43
44} // namespace esphome::i2c
45
46#endif // USE_HOST
uint8_t address
Definition bl0906.h:4
uint16_le_t frequency
Definition bl0942.h:6
ErrorCode map_errno_to_error_code_(int err)
void set_device(const std::string &device)
float get_setup_priority() const override
void update_error_(const std::string &error)
const std::string & get_device() const
void set_frequency(uint32_t frequency)
ErrorCode write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count, uint8_t *read_buffer, size_t read_count) override
void dump_config() override
void set_scan(bool scan)
uint32_t get_frequency() const override
This Class provides the methods to read and write bytes from an I2CBus.
Definition i2c_bus.h:30
bool scan_
Should we scan ? Can be set in the yaml.
Definition i2c_bus.h:71
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition i2c_bus.h:13
constexpr float BUS
For communication buses like i2c/spi.
Definition component.h:39
static void uint32_t