mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 06:33:51 +00:00 
			
		
		
		
	I2c raw cmds with multiplexer (#1817)
Co-authored-by: Maurice Makaay <mmakaay1@xs4all.net>
This commit is contained in:
		| @@ -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. | ||||
|    * | ||||
|   | ||||
		Reference in New Issue
	
	Block a user