mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 05:24:53 +01:00
I2c raw cmds with multiplexer (#1817)
Co-authored-by: Maurice Makaay <mmakaay1@xs4all.net>
This commit is contained in:
parent
9a2cd71571
commit
56974153f1
5 changed files with 41 additions and 15 deletions
|
@ -193,12 +193,36 @@ void I2CDevice::check_multiplexer_() {
|
|||
}
|
||||
#endif
|
||||
|
||||
void I2CDevice::raw_begin_transmission() { // NOLINT
|
||||
#ifdef USE_I2C_MULTIPLEXER
|
||||
this->check_multiplexer_();
|
||||
#endif
|
||||
this->parent_->raw_begin_transmission(this->address_);
|
||||
}
|
||||
bool I2CDevice::raw_end_transmission(bool send_stop) { // NOLINT
|
||||
#ifdef USE_I2C_MULTIPLEXER
|
||||
this->check_multiplexer_();
|
||||
#endif
|
||||
return this->parent_->raw_end_transmission(this->address_, send_stop);
|
||||
}
|
||||
void I2CDevice::raw_write(const uint8_t *data, uint8_t len) { // NOLINT
|
||||
#ifdef USE_I2C_MULTIPLEXER
|
||||
this->check_multiplexer_();
|
||||
#endif
|
||||
this->parent_->raw_write(this->address_, data, len);
|
||||
}
|
||||
bool I2CDevice::read_bytes(uint8_t a_register, uint8_t *data, uint8_t len, uint32_t conversion) { // NOLINT
|
||||
#ifdef USE_I2C_MULTIPLEXER
|
||||
this->check_multiplexer_();
|
||||
#endif
|
||||
return this->parent_->read_bytes(this->address_, a_register, data, len, conversion);
|
||||
}
|
||||
bool I2CDevice::read_bytes_raw(uint8_t *data, uint8_t len) { // NOLINT
|
||||
#ifdef USE_I2C_MULTIPLEXER
|
||||
this->check_multiplexer_();
|
||||
#endif
|
||||
return this->parent_->read_bytes_raw(this->address_, data, len);
|
||||
}
|
||||
bool I2CDevice::read_byte(uint8_t a_register, uint8_t *data, uint32_t conversion) { // NOLINT
|
||||
#ifdef USE_I2C_MULTIPLEXER
|
||||
this->check_multiplexer_();
|
||||
|
@ -211,6 +235,12 @@ bool I2CDevice::write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len
|
|||
#endif
|
||||
return this->parent_->write_bytes(this->address_, a_register, data, len);
|
||||
}
|
||||
bool I2CDevice::write_bytes_raw(const uint8_t *data, uint8_t len) { // NOLINT
|
||||
#ifdef USE_I2C_MULTIPLEXER
|
||||
this->check_multiplexer_();
|
||||
#endif
|
||||
return this->parent_->write_bytes_raw(this->address_, data, len);
|
||||
}
|
||||
bool I2CDevice::write_byte(uint8_t a_register, uint8_t data) { // NOLINT
|
||||
#ifdef USE_I2C_MULTIPLEXER
|
||||
this->check_multiplexer_();
|
||||
|
|
|
@ -178,15 +178,13 @@ 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_); };
|
||||
void raw_begin_transmission();
|
||||
|
||||
/// 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);
|
||||
};
|
||||
bool raw_end_transmission(bool send_stop = true);
|
||||
|
||||
/// 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); };
|
||||
void raw_write(const uint8_t *data, uint8_t len);
|
||||
|
||||
/** Read len amount of bytes from a register into data. Optionally with a conversion time after
|
||||
* writing the register value to the bus.
|
||||
|
@ -198,7 +196,7 @@ class I2CDevice {
|
|||
* @return If the operation was successful.
|
||||
*/
|
||||
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len, uint32_t conversion = 0);
|
||||
bool read_bytes_raw(uint8_t *data, uint8_t len) { return this->parent_->read_bytes_raw(this->address_, data, len); }
|
||||
bool read_bytes_raw(uint8_t *data, uint8_t len);
|
||||
|
||||
template<size_t N> optional<std::array<uint8_t, N>> read_bytes(uint8_t a_register) {
|
||||
std::array<uint8_t, N> res;
|
||||
|
@ -246,9 +244,7 @@ class I2CDevice {
|
|||
* @return If the operation was successful.
|
||||
*/
|
||||
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len);
|
||||
bool write_bytes_raw(const uint8_t *data, uint8_t len) {
|
||||
return this->parent_->write_bytes_raw(this->address_, data, len);
|
||||
}
|
||||
bool write_bytes_raw(const uint8_t *data, uint8_t len);
|
||||
|
||||
/** Write a vector of data to a register.
|
||||
*
|
||||
|
|
|
@ -9,9 +9,9 @@ static const char *TAG = "mcp4725";
|
|||
void MCP4725::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up MCP4725 (0x%02X)...", this->address_);
|
||||
|
||||
this->parent_->raw_begin_transmission(this->address_);
|
||||
this->raw_begin_transmission();
|
||||
|
||||
if (!this->parent_->raw_end_transmission(this->address_)) {
|
||||
if (!this->raw_end_transmission()) {
|
||||
this->error_code_ = COMMUNICATION_FAILED;
|
||||
this->mark_failed();
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ void I2CSSD1306::setup() {
|
|||
ESP_LOGCONFIG(TAG, "Setting up I2C SSD1306...");
|
||||
this->init_reset_();
|
||||
|
||||
this->parent_->raw_begin_transmission(this->address_);
|
||||
if (!this->parent_->raw_end_transmission(this->address_)) {
|
||||
this->raw_begin_transmission();
|
||||
if (!this->raw_end_transmission()) {
|
||||
this->error_code_ = COMMUNICATION_FAILED;
|
||||
this->mark_failed();
|
||||
return;
|
||||
|
|
|
@ -10,8 +10,8 @@ void I2CSSD1327::setup() {
|
|||
ESP_LOGCONFIG(TAG, "Setting up I2C SSD1327...");
|
||||
this->init_reset_();
|
||||
|
||||
this->parent_->raw_begin_transmission(this->address_);
|
||||
if (!this->parent_->raw_end_transmission(this->address_)) {
|
||||
this->raw_begin_transmission();
|
||||
if (!this->raw_end_transmission()) {
|
||||
this->error_code_ = COMMUNICATION_FAILED;
|
||||
this->mark_failed();
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue