ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
i2c_bus_software.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_LIBRETINY
4
6#include "esphome/core/gpio.h"
7#include "i2c_bus.h"
8
9namespace esphome::i2c {
10
14class SoftwareI2CBus final : public I2CBus, public Component {
15 public:
16 void setup() override;
17 void dump_config() override;
18 ErrorCode write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count, uint8_t *read_buffer,
19 size_t read_count) override;
20 float get_setup_priority() const override { return setup_priority::BUS; }
21
22 void set_scan(bool scan) { this->scan_ = scan; }
23 void set_sda_pin(InternalGPIOPin *sda_pin) { this->sda_pin_ = sda_pin; }
24 void set_scl_pin(InternalGPIOPin *scl_pin) { this->scl_pin_ = scl_pin; }
26#ifdef I2C_PORT_FREQUENCY_COUNT
28 uint32_t get_frequency() const override { return this->frequency_; }
29#endif
31 void set_timeout(uint32_t timeout) { this->timeout_ = timeout; }
32
33 protected:
34 bool recover_();
36 void start_();
37 void stop_();
38 bool release_scl_();
39 bool write_byte_(uint8_t data);
40 uint8_t read_byte_(bool ack);
41
47 bool timed_out_{false};
48 bool recovered_{false};
49 bool initialized_{false};
50 bool bus_stuck_{false};
51};
52
53} // namespace esphome::i2c
54
55#endif // USE_LIBRETINY
uint16_le_t frequency
Definition bl0942.h:6
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:73
Bit-banged I2C controller for LibreTiny chips without an Arduino Wire implementation (BK72xx).
uint32_t get_frequency() const override
float get_setup_priority() const override
void set_timeout(uint32_t timeout)
Maximum time in microseconds a device may hold SCL low (clock stretching).
void set_sda_pin(InternalGPIOPin *sda_pin)
ErrorCode write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count, uint8_t *read_buffer, size_t read_count) override
ErrorCode switch_frequency(uint32_t frequency) override
void set_scl_pin(InternalGPIOPin *scl_pin)
bool write_byte_(uint8_t data)
Shift out one byte, returns true if the device acknowledged it.
void set_frequency(uint32_t frequency)
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
uint8_t ack