diff --git a/esphome/components/i2c/i2c.cpp b/esphome/components/i2c/i2c.cpp index 562bd26771..8e6d9f32fa 100644 --- a/esphome/components/i2c/i2c.cpp +++ b/esphome/components/i2c/i2c.cpp @@ -56,8 +56,8 @@ void I2CComponent::raw_begin_transmission(uint8_t address) { ESP_LOGVV(TAG, "Beginning Transmission to 0x%02X:", address); this->wire_->beginTransmission(address); } -bool I2CComponent::raw_end_transmission(uint8_t address) { - uint8_t status = this->wire_->endTransmission(); +bool I2CComponent::raw_end_transmission(uint8_t address, bool send_stop) { + uint8_t status = this->wire_->endTransmission(send_stop); ESP_LOGVV(TAG, " Transmission ended. Status code: 0x%02X", status); switch (status) { diff --git a/esphome/components/i2c/i2c.h b/esphome/components/i2c/i2c.h index c4ed40e268..72777f8eb0 100644 --- a/esphome/components/i2c/i2c.h +++ b/esphome/components/i2c/i2c.h @@ -94,7 +94,7 @@ class I2CComponent : public Component { void raw_begin_transmission(uint8_t address); /// End a write transmission to an address, return true if successful. - bool raw_end_transmission(uint8_t address); + bool raw_end_transmission(uint8_t address, bool send_stop = true); /** Request data from an address with a number of (8-bit) bytes. * @@ -173,6 +173,17 @@ class I2CDevice { I2CRegister reg(uint8_t a_register) { return {this, a_register}; } + /// Begin a write transmission. + void raw_begin_transmission() { this->parent_->raw_begin_transmission(this->address_); }; + + /// End a write transmission, return true if successful. + bool raw_end_transmission(bool send_stop = true) { + return this->parent_->raw_end_transmission(this->address_, send_stop); + }; + + /// Write len amount of bytes from data. begin_transmission_ must be called before this. + void raw_write(const uint8_t *data, uint8_t len) { this->parent_->raw_write(this->address_, data, len); }; + /** Read len amount of bytes from a register into data. Optionally with a conversion time after * writing the register value to the bus. *