mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
Support I2C transactions with combined reads and writes (#996)
* Support I2C transactions with combined reads and writes * Add optional send_stop parameter to I2CComponent::raw_end_transmission * Add convenience methods to I2CDevice * clang-format Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
051a1e4772
commit
7221337442
2 changed files with 14 additions and 3 deletions
|
@ -56,8 +56,8 @@ void I2CComponent::raw_begin_transmission(uint8_t address) {
|
||||||
ESP_LOGVV(TAG, "Beginning Transmission to 0x%02X:", address);
|
ESP_LOGVV(TAG, "Beginning Transmission to 0x%02X:", address);
|
||||||
this->wire_->beginTransmission(address);
|
this->wire_->beginTransmission(address);
|
||||||
}
|
}
|
||||||
bool I2CComponent::raw_end_transmission(uint8_t address) {
|
bool I2CComponent::raw_end_transmission(uint8_t address, bool send_stop) {
|
||||||
uint8_t status = this->wire_->endTransmission();
|
uint8_t status = this->wire_->endTransmission(send_stop);
|
||||||
ESP_LOGVV(TAG, " Transmission ended. Status code: 0x%02X", status);
|
ESP_LOGVV(TAG, " Transmission ended. Status code: 0x%02X", status);
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
|
|
|
@ -94,7 +94,7 @@ class I2CComponent : public Component {
|
||||||
void raw_begin_transmission(uint8_t address);
|
void raw_begin_transmission(uint8_t address);
|
||||||
|
|
||||||
/// End a write transmission to an address, return true if successful.
|
/// 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.
|
/** 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}; }
|
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
|
/** Read len amount of bytes from a register into data. Optionally with a conversion time after
|
||||||
* writing the register value to the bus.
|
* writing the register value to the bus.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue