mirror of
				https://github.com/esphome/esphome.git
				synced 2025-11-04 09:01:49 +00:00 
			
		
		
		
	Compare commits
	
		
			29 Commits
		
	
	
		
			2023.12.0b
			...
			2023.12.1
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					6d3c7f035d | ||
| 
						 | 
					00ab17cb8e | ||
| 
						 | 
					2ee01e22cd | ||
| 
						 | 
					cfa5e5c5a9 | ||
| 
						 | 
					8675955614 | ||
| 
						 | 
					816dcdf24f | ||
| 
						 | 
					bec1ad9396 | ||
| 
						 | 
					6a9e85438f | ||
| 
						 | 
					ab25e32509 | ||
| 
						 | 
					2ccf985de5 | ||
| 
						 | 
					a64e96e7ad | ||
| 
						 | 
					fbf3d03a33 | ||
| 
						 | 
					7b2b6aaeb1 | ||
| 
						 | 
					e2a00f66b8 | ||
| 
						 | 
					1b3068a409 | ||
| 
						 | 
					e5414d70f5 | ||
| 
						 | 
					977e0184a7 | ||
| 
						 | 
					820f328248 | ||
| 
						 | 
					7807f0d892 | ||
| 
						 | 
					b59666c512 | ||
| 
						 | 
					dbfa77cb4b | ||
| 
						 | 
					ab22a3da34 | ||
| 
						 | 
					eefa1cd3ab | ||
| 
						 | 
					d0df73769d | ||
| 
						 | 
					e8ce780482 | ||
| 
						 | 
					168e704130 | ||
| 
						 | 
					2309f15ce0 | ||
| 
						 | 
					917e0f93ed | ||
| 
						 | 
					70dac54113 | 
@@ -12,7 +12,7 @@ import argcomplete
 | 
			
		||||
 | 
			
		||||
from esphome import const, writer, yaml_util
 | 
			
		||||
import esphome.codegen as cg
 | 
			
		||||
from esphome.config import iter_components, read_config, strip_default_ids
 | 
			
		||||
from esphome.config import iter_component_configs, read_config, strip_default_ids
 | 
			
		||||
from esphome.const import (
 | 
			
		||||
    ALLOWED_NAME_CHARS,
 | 
			
		||||
    CONF_BAUD_RATE,
 | 
			
		||||
@@ -196,7 +196,7 @@ def write_cpp(config):
 | 
			
		||||
def generate_cpp_contents(config):
 | 
			
		||||
    _LOGGER.info("Generating C++ source...")
 | 
			
		||||
 | 
			
		||||
    for name, component, conf in iter_components(CORE.config):
 | 
			
		||||
    for name, component, conf in iter_component_configs(CORE.config):
 | 
			
		||||
        if component.to_code is not None:
 | 
			
		||||
            coro = wrap_to_code(name, component)
 | 
			
		||||
            CORE.add_job(coro, conf)
 | 
			
		||||
 
 | 
			
		||||
@@ -160,8 +160,7 @@ class ProtoWriteBuffer {
 | 
			
		||||
    this->encode_field_raw(field_id, 2);
 | 
			
		||||
    this->encode_varint_raw(len);
 | 
			
		||||
    auto *data = reinterpret_cast<const uint8_t *>(string);
 | 
			
		||||
    for (size_t i = 0; i < len; i++)
 | 
			
		||||
      this->write(data[i]);
 | 
			
		||||
    this->buffer_->insert(this->buffer_->end(), data, data + len);
 | 
			
		||||
  }
 | 
			
		||||
  void encode_string(uint32_t field_id, const std::string &value, bool force = false) {
 | 
			
		||||
    this->encode_string(field_id, value.data(), value.size());
 | 
			
		||||
 
 | 
			
		||||
@@ -74,7 +74,7 @@ void EKTF2232Touchscreen::update_touches() {
 | 
			
		||||
    uint8_t *d = raw + 1 + (i * 3);
 | 
			
		||||
    x_raw = (d[0] & 0xF0) << 4 | d[1];
 | 
			
		||||
    y_raw = (d[0] & 0x0F) << 8 | d[2];
 | 
			
		||||
    this->set_raw_touch_position_(i, x_raw, y_raw);
 | 
			
		||||
    this->add_raw_touch_position_(i, x_raw, y_raw);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -37,7 +37,7 @@ void ESP32Camera::setup() {
 | 
			
		||||
                          "framebuffer_task",  // name
 | 
			
		||||
                          1024,                // stack size
 | 
			
		||||
                          nullptr,             // task pv params
 | 
			
		||||
                          0,                   // priority
 | 
			
		||||
                          1,                   // priority
 | 
			
		||||
                          nullptr,             // handle
 | 
			
		||||
                          1                    // core
 | 
			
		||||
  );
 | 
			
		||||
 
 | 
			
		||||
@@ -94,7 +94,7 @@ class FT5x06Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice
 | 
			
		||||
 | 
			
		||||
      esph_log_d(TAG, "Read %X status, id: %d, pos %d/%d", status, id, x, y);
 | 
			
		||||
      if (status == 0 || status == 2) {
 | 
			
		||||
        this->set_raw_touch_position_(id, x, y);
 | 
			
		||||
        this->add_raw_touch_position_(id, x, y);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -53,13 +53,13 @@ void FT63X6Touchscreen::update_touches() {
 | 
			
		||||
  uint8_t touch_id = this->read_touch_id_(FT63X6_ADDR_TOUCH1_ID);  // id1 = 0 or 1
 | 
			
		||||
  int16_t x = this->read_touch_coordinate_(FT63X6_ADDR_TOUCH1_X);
 | 
			
		||||
  int16_t y = this->read_touch_coordinate_(FT63X6_ADDR_TOUCH1_Y);
 | 
			
		||||
  this->set_raw_touch_position_(touch_id, x, y);
 | 
			
		||||
  this->add_raw_touch_position_(touch_id, x, y);
 | 
			
		||||
 | 
			
		||||
  if (touch_count >= 2) {
 | 
			
		||||
    touch_id = this->read_touch_id_(FT63X6_ADDR_TOUCH2_ID);  // id2 = 0 or 1(~id1 & 0x01)
 | 
			
		||||
    x = this->read_touch_coordinate_(FT63X6_ADDR_TOUCH2_X);
 | 
			
		||||
    y = this->read_touch_coordinate_(FT63X6_ADDR_TOUCH2_Y);
 | 
			
		||||
    this->set_raw_touch_position_(touch_id, x, y);
 | 
			
		||||
    this->add_raw_touch_position_(touch_id, x, y);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -92,7 +92,7 @@ void GT911Touchscreen::update_touches() {
 | 
			
		||||
    uint16_t id = data[i][0];
 | 
			
		||||
    uint16_t x = encode_uint16(data[i][2], data[i][1]);
 | 
			
		||||
    uint16_t y = encode_uint16(data[i][4], data[i][3]);
 | 
			
		||||
    this->set_raw_touch_position_(id, x, y);
 | 
			
		||||
    this->add_raw_touch_position_(id, x, y);
 | 
			
		||||
  }
 | 
			
		||||
  auto keys = data[num_of_touches][0];
 | 
			
		||||
  for (size_t i = 0; i != 4; i++) {
 | 
			
		||||
 
 | 
			
		||||
@@ -11,43 +11,116 @@ namespace i2c {
 | 
			
		||||
 | 
			
		||||
#define LOG_I2C_DEVICE(this) ESP_LOGCONFIG(TAG, "  Address: 0x%02X", this->address_);
 | 
			
		||||
 | 
			
		||||
class I2CDevice;
 | 
			
		||||
class I2CDevice;  // forward declaration
 | 
			
		||||
 | 
			
		||||
/// @brief This class is used to create I2CRegister objects that act as proxies to read/write internal registers on an
 | 
			
		||||
/// I2C device.
 | 
			
		||||
/// @details
 | 
			
		||||
/// @n typical usage:
 | 
			
		||||
/// @code
 | 
			
		||||
/// constexpr uint8_t ADDR_REGISTER_1 = 0x12;
 | 
			
		||||
/// i2c::I2CRegister reg_1 = this->reg(ADDR_REGISTER_1); // declare
 | 
			
		||||
/// reg_1 |= 0x01; // set bit
 | 
			
		||||
/// reg_1 &= ~0x01; // reset bit
 | 
			
		||||
/// reg_1 = 10; // Set value
 | 
			
		||||
/// uint val = reg_1.get(); // get value
 | 
			
		||||
/// @endcode
 | 
			
		||||
/// @details The I²C protocol specifies how to read/write in sets of 8-bits followed by an Acknowledgement (ACK/NACK)
 | 
			
		||||
/// from the device receiving the data. How the device interprets the bits read/written can vary greatly from
 | 
			
		||||
/// device to device. However most of the devices follow the same protocol for reading/writing 8 bit registers using as
 | 
			
		||||
/// implemented in the I2CRegister: after sending the device address, the controller sends one byte with the internal
 | 
			
		||||
/// register address and then read or write the specified register content.
 | 
			
		||||
class I2CRegister {
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief overloads the = operator. This allows to set the value of an i2c register
 | 
			
		||||
  /// @param value value to be set in the register
 | 
			
		||||
  /// @return pointer to current object
 | 
			
		||||
  I2CRegister &operator=(uint8_t value);
 | 
			
		||||
 | 
			
		||||
  /// @brief overloads the compound &= operator. This allows to reset specific bits of an I²C register
 | 
			
		||||
  /// @param value used for the & operation
 | 
			
		||||
  /// @return pointer to current object
 | 
			
		||||
  I2CRegister &operator&=(uint8_t value);
 | 
			
		||||
 | 
			
		||||
  /// @brief overloads the compound |= operator. This allows to set specific bits of an I²C register
 | 
			
		||||
  /// @param value used for the & operation
 | 
			
		||||
  /// @return pointer to current object
 | 
			
		||||
  I2CRegister &operator|=(uint8_t value);
 | 
			
		||||
 | 
			
		||||
  /// @brief overloads the uint8_t() cast operator to return the I²C register value
 | 
			
		||||
  /// @return pointer to current object
 | 
			
		||||
  explicit operator uint8_t() const { return get(); }
 | 
			
		||||
 | 
			
		||||
  /// @brief returns the register value
 | 
			
		||||
  /// @return the register value
 | 
			
		||||
  uint8_t get() const;
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  friend class I2CDevice;
 | 
			
		||||
 | 
			
		||||
  /// @brief protected constructor that stores the owning object and the register address. Note as only friends can
 | 
			
		||||
  /// create an I2CRegister @see I2CDevice::reg()
 | 
			
		||||
  /// @param parent our parent
 | 
			
		||||
  /// @param a_register address of the i2c register
 | 
			
		||||
  I2CRegister(I2CDevice *parent, uint8_t a_register) : parent_(parent), register_(a_register) {}
 | 
			
		||||
 | 
			
		||||
  I2CDevice *parent_;
 | 
			
		||||
  uint8_t register_;
 | 
			
		||||
  I2CDevice *parent_;  ///< I2CDevice object pointer
 | 
			
		||||
  uint8_t register_;   ///< the internal address of the register
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/// @brief This class is used to create I2CRegister16 objects that act as proxies to read/write internal registers
 | 
			
		||||
/// (specified with a 16 bit address) on an I2C device.
 | 
			
		||||
/// @details
 | 
			
		||||
/// @n typical usage:
 | 
			
		||||
/// @code
 | 
			
		||||
/// constexpr uint16_t X16_BIT_ADDR_REGISTER_1 = 0x1234;
 | 
			
		||||
/// i2c::I2CRegister16 reg_1 = this->reg16(X16_BIT_ADDR_REGISTER_1); // declare
 | 
			
		||||
/// reg_1 |= 0x01; // set bit
 | 
			
		||||
/// reg_1 &= ~0x01; // reset bit
 | 
			
		||||
/// reg_1 = 10; // Set value
 | 
			
		||||
/// uint val = reg_1.get(); // get value
 | 
			
		||||
/// @endcode
 | 
			
		||||
/// @details The I²C protocol specification, reads/writes in sets of 8-bits followed by an Acknowledgement (ACK/NACK)
 | 
			
		||||
/// from the device receiving the data. How the device interprets the bits read/written to it can vary greatly from
 | 
			
		||||
/// device to device. This class can be used to access in the device 8 bits registers that uses a 16 bits internal
 | 
			
		||||
/// address. After sending the device address, the controller sends the internal register address (using two consecutive
 | 
			
		||||
/// bytes following the big indian convention) and then read or write the register content.
 | 
			
		||||
class I2CRegister16 {
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief overloads the = operator. This allows to set the value of an I²C register
 | 
			
		||||
  /// @param value value to be set in the register
 | 
			
		||||
  /// @return pointer to current object
 | 
			
		||||
  I2CRegister16 &operator=(uint8_t value);
 | 
			
		||||
 | 
			
		||||
  /// @brief overloads the compound &= operator. This allows to reset specific bits of an I²C register
 | 
			
		||||
  /// @param value used for the & operation
 | 
			
		||||
  /// @return pointer to current object
 | 
			
		||||
  I2CRegister16 &operator&=(uint8_t value);
 | 
			
		||||
 | 
			
		||||
  /// @brief overloads the compound |= operator. This allows to set bits of an I²C register
 | 
			
		||||
  /// @param value used for the & operation
 | 
			
		||||
  /// @return pointer to current object
 | 
			
		||||
  I2CRegister16 &operator|=(uint8_t value);
 | 
			
		||||
 | 
			
		||||
  /// @brief overloads the uint8_t() cast operator to return the I²C register value
 | 
			
		||||
  /// @return the register value
 | 
			
		||||
  explicit operator uint8_t() const { return get(); }
 | 
			
		||||
 | 
			
		||||
  /// @brief returns the register value
 | 
			
		||||
  /// @return the register value
 | 
			
		||||
  uint8_t get() const;
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  friend class I2CDevice;
 | 
			
		||||
 | 
			
		||||
  /// @brief protected constructor that store the owning object and the register address. Only friends can create an
 | 
			
		||||
  /// I2CRegister16 @see I2CDevice::reg16()
 | 
			
		||||
  /// @param parent our parent
 | 
			
		||||
  /// @param a_register 16 bits address of the i2c register
 | 
			
		||||
  I2CRegister16(I2CDevice *parent, uint16_t a_register) : parent_(parent), register_(a_register) {}
 | 
			
		||||
 | 
			
		||||
  I2CDevice *parent_;
 | 
			
		||||
  uint16_t register_;
 | 
			
		||||
  I2CDevice *parent_;  ///< I2CDevice object pointer
 | 
			
		||||
  uint16_t register_;  ///< the internal 16 bits address of the register
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// like ntohs/htons but without including networking headers.
 | 
			
		||||
@@ -55,29 +128,91 @@ class I2CRegister16 {
 | 
			
		||||
inline uint16_t i2ctohs(uint16_t i2cshort) { return convert_big_endian(i2cshort); }
 | 
			
		||||
inline uint16_t htoi2cs(uint16_t hostshort) { return convert_big_endian(hostshort); }
 | 
			
		||||
 | 
			
		||||
/// @brief This Class provides the methods to read/write bytes from/to an i2c device.
 | 
			
		||||
/// Objects keep a list of devices found on bus as well as a pointer to the I2CBus in use.
 | 
			
		||||
class I2CDevice {
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief we use the C++ default constructor
 | 
			
		||||
  I2CDevice() = default;
 | 
			
		||||
 | 
			
		||||
  /// @brief We store the address of the device on the bus
 | 
			
		||||
  /// @param address of the device
 | 
			
		||||
  void set_i2c_address(uint8_t address) { address_ = address; }
 | 
			
		||||
 | 
			
		||||
  /// @brief we store the pointer to the I2CBus to use
 | 
			
		||||
  /// @param bus pointer to the I2CBus object
 | 
			
		||||
  void set_i2c_bus(I2CBus *bus) { bus_ = bus; }
 | 
			
		||||
 | 
			
		||||
  /// @brief calls the I2CRegister constructor
 | 
			
		||||
  /// @param a_register address of the I²C register
 | 
			
		||||
  /// @return an I2CRegister proxy object
 | 
			
		||||
  I2CRegister reg(uint8_t a_register) { return {this, a_register}; }
 | 
			
		||||
 | 
			
		||||
  /// @brief calls the I2CRegister16 constructor
 | 
			
		||||
  /// @param a_register 16 bits address of the I²C register
 | 
			
		||||
  /// @return an I2CRegister16 proxy object
 | 
			
		||||
  I2CRegister16 reg16(uint16_t a_register) { return {this, a_register}; }
 | 
			
		||||
 | 
			
		||||
  /// @brief reads an array of bytes from the device using an I2CBus
 | 
			
		||||
  /// @param data pointer to an array to store the bytes
 | 
			
		||||
  /// @param len length of the buffer = number of bytes to read
 | 
			
		||||
  /// @return an i2c::ErrorCode
 | 
			
		||||
  ErrorCode read(uint8_t *data, size_t len) { return bus_->read(address_, data, len); }
 | 
			
		||||
 | 
			
		||||
  /// @brief reads an array of bytes from a specific register in the I²C device
 | 
			
		||||
  /// @param a_register an 8 bits internal address of the I²C register to read from
 | 
			
		||||
  /// @param data pointer to an array to store the bytes
 | 
			
		||||
  /// @param len length of the buffer = number of bytes to read
 | 
			
		||||
  /// @param stop (true/false): True will send a stop message, releasing the bus after
 | 
			
		||||
  /// transmission. False will send a restart, keeping the connection active.
 | 
			
		||||
  /// @return an i2c::ErrorCode
 | 
			
		||||
  ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len, bool stop = true);
 | 
			
		||||
 | 
			
		||||
  /// @brief reads an array of bytes from a specific register in the I²C device
 | 
			
		||||
  /// @param a_register the 16 bits internal address of the I²C register to read from
 | 
			
		||||
  /// @param data pointer to an array of bytes to store the information
 | 
			
		||||
  /// @param len length of the buffer = number of bytes to read
 | 
			
		||||
  /// @param stop (true/false): True will send a stop message, releasing the bus after
 | 
			
		||||
  /// transmission. False will send a restart, keeping the connection active.
 | 
			
		||||
  /// @return an i2c::ErrorCode
 | 
			
		||||
  ErrorCode read_register16(uint16_t a_register, uint8_t *data, size_t len, bool stop = true);
 | 
			
		||||
 | 
			
		||||
  ErrorCode write(const uint8_t *data, uint8_t len, bool stop = true) { return bus_->write(address_, data, len, stop); }
 | 
			
		||||
  /// @brief writes an array of bytes to a device using an I2CBus
 | 
			
		||||
  /// @param data pointer to an array that contains the bytes to send
 | 
			
		||||
  /// @param len length of the buffer = number of bytes to write
 | 
			
		||||
  /// @param stop (true/false): True will send a stop message, releasing the bus after
 | 
			
		||||
  /// transmission. False will send a restart, keeping the connection active.
 | 
			
		||||
  /// @return an i2c::ErrorCode
 | 
			
		||||
  ErrorCode write(const uint8_t *data, size_t len, bool stop = true) { return bus_->write(address_, data, len, stop); }
 | 
			
		||||
 | 
			
		||||
  /// @brief writes an array of bytes to a specific register in the I²C device
 | 
			
		||||
  /// @param a_register the internal address of the register to read from
 | 
			
		||||
  /// @param data pointer to an array to store the bytes
 | 
			
		||||
  /// @param len length of the buffer = number of bytes to read
 | 
			
		||||
  /// @param stop (true/false): True will send a stop message, releasing the bus after
 | 
			
		||||
  /// transmission. False will send a restart, keeping the connection active.
 | 
			
		||||
  /// @return an i2c::ErrorCode
 | 
			
		||||
  ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len, bool stop = true);
 | 
			
		||||
 | 
			
		||||
  /// @brief write an array of bytes to a specific register in the I²C device
 | 
			
		||||
  /// @param a_register the 16 bits internal address of the register to read from
 | 
			
		||||
  /// @param data pointer to an array to store the bytes
 | 
			
		||||
  /// @param len length of the buffer = number of bytes to read
 | 
			
		||||
  /// @param stop (true/false): True will send a stop message, releasing the bus after
 | 
			
		||||
  /// transmission. False will send a restart, keeping the connection active.
 | 
			
		||||
  /// @return an i2c::ErrorCode
 | 
			
		||||
  ErrorCode write_register16(uint16_t a_register, const uint8_t *data, size_t len, bool stop = true);
 | 
			
		||||
 | 
			
		||||
  // Compat APIs
 | 
			
		||||
  ///
 | 
			
		||||
  /// Compat APIs
 | 
			
		||||
  /// All methods below have been added for compatibility reasons. They do not bring any functionality and therefore on
 | 
			
		||||
  /// new code it is not recommend to use them.
 | 
			
		||||
  ///
 | 
			
		||||
 | 
			
		||||
  bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len) {
 | 
			
		||||
    return read_register(a_register, data, len) == ERROR_OK;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool read_bytes_raw(uint8_t *data, uint8_t len) { return read(data, len) == ERROR_OK; }
 | 
			
		||||
 | 
			
		||||
  template<size_t N> optional<std::array<uint8_t, N>> read_bytes(uint8_t a_register) {
 | 
			
		||||
@@ -131,8 +266,8 @@ class I2CDevice {
 | 
			
		||||
  bool write_byte_16(uint8_t a_register, uint16_t data) { return write_bytes_16(a_register, &data, 1); }
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  uint8_t address_{0x00};
 | 
			
		||||
  I2CBus *bus_{nullptr};
 | 
			
		||||
  uint8_t address_{0x00};  ///< store the address of the device on the bus
 | 
			
		||||
  I2CBus *bus_{nullptr};   ///< pointer to I2CBus instance
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}  // namespace i2c
 | 
			
		||||
 
 | 
			
		||||
@@ -7,50 +7,93 @@
 | 
			
		||||
namespace esphome {
 | 
			
		||||
namespace i2c {
 | 
			
		||||
 | 
			
		||||
/// @brief Error codes returned by I2CBus and I2CDevice methods
 | 
			
		||||
enum ErrorCode {
 | 
			
		||||
  ERROR_OK = 0,
 | 
			
		||||
  ERROR_INVALID_ARGUMENT = 1,
 | 
			
		||||
  ERROR_NOT_ACKNOWLEDGED = 2,
 | 
			
		||||
  ERROR_TIMEOUT = 3,
 | 
			
		||||
  ERROR_NOT_INITIALIZED = 4,
 | 
			
		||||
  ERROR_TOO_LARGE = 5,
 | 
			
		||||
  ERROR_UNKNOWN = 6,
 | 
			
		||||
  ERROR_CRC = 7,
 | 
			
		||||
  NO_ERROR = 0,                ///< No error found during execution of method
 | 
			
		||||
  ERROR_OK = 0,                ///< No error found during execution of method
 | 
			
		||||
  ERROR_INVALID_ARGUMENT = 1,  ///< method called invalid argument(s)
 | 
			
		||||
  ERROR_NOT_ACKNOWLEDGED = 2,  ///< I2C bus acknowledgment not received
 | 
			
		||||
  ERROR_TIMEOUT = 3,           ///< timeout while waiting to receive bytes
 | 
			
		||||
  ERROR_NOT_INITIALIZED = 4,   ///< call method to a not initialized bus
 | 
			
		||||
  ERROR_TOO_LARGE = 5,         ///< requested a transfer larger than buffers can hold
 | 
			
		||||
  ERROR_UNKNOWN = 6,           ///< miscellaneous I2C error during execution
 | 
			
		||||
  ERROR_CRC = 7,               ///< bytes received with a CRC error
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/// @brief the ReadBuffer structure stores a pointer to a read buffer and its length
 | 
			
		||||
struct ReadBuffer {
 | 
			
		||||
  uint8_t *data;
 | 
			
		||||
  size_t len;
 | 
			
		||||
};
 | 
			
		||||
struct WriteBuffer {
 | 
			
		||||
  const uint8_t *data;
 | 
			
		||||
  size_t len;
 | 
			
		||||
  uint8_t *data;  ///< pointer to the read buffer
 | 
			
		||||
  size_t len;     ///< length of the buffer
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/// @brief the WriteBuffer structure stores a pointer to a write buffer and its length
 | 
			
		||||
struct WriteBuffer {
 | 
			
		||||
  const uint8_t *data;  ///< pointer to the write buffer
 | 
			
		||||
  size_t len;           ///< length of the buffer
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/// @brief This Class provides the methods to read and write bytes from an I2CBus.
 | 
			
		||||
/// @note The I2CBus virtual class follows a *Factory design pattern* that provides all the interfaces methods required
 | 
			
		||||
/// by clients while deferring the actual implementation of these methods to a subclasses. I2C-bus specification and
 | 
			
		||||
/// user manual can be found here https://www.nxp.com/docs/en/user-guide/UM10204.pdf and an interesting I²C Application
 | 
			
		||||
/// note https://www.nxp.com/docs/en/application-note/AN10216.pdf
 | 
			
		||||
class I2CBus {
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief Creates a ReadBuffer and calls the virtual readv() method to read bytes into this buffer
 | 
			
		||||
  /// @param address address of the I²C component on the i2c bus
 | 
			
		||||
  /// @param buffer pointer to an array of bytes that will be used to store the data received
 | 
			
		||||
  /// @param len length of the buffer = number of bytes to read
 | 
			
		||||
  /// @return an i2c::ErrorCode
 | 
			
		||||
  virtual ErrorCode read(uint8_t address, uint8_t *buffer, size_t len) {
 | 
			
		||||
    ReadBuffer buf;
 | 
			
		||||
    buf.data = buffer;
 | 
			
		||||
    buf.len = len;
 | 
			
		||||
    return readv(address, &buf, 1);
 | 
			
		||||
  }
 | 
			
		||||
  virtual ErrorCode readv(uint8_t address, ReadBuffer *buffers, size_t cnt) = 0;
 | 
			
		||||
 | 
			
		||||
  /// @brief This virtual method reads bytes from an I2CBus into an array of ReadBuffer.
 | 
			
		||||
  /// @param address address of the I²C component on the i2c bus
 | 
			
		||||
  /// @param buffers pointer to an array of ReadBuffer
 | 
			
		||||
  /// @param count number of ReadBuffer to read
 | 
			
		||||
  /// @return an i2c::ErrorCode
 | 
			
		||||
  /// @details This is a pure virtual method that must be implemented in a subclass.
 | 
			
		||||
  virtual ErrorCode readv(uint8_t address, ReadBuffer *buffers, size_t count) = 0;
 | 
			
		||||
 | 
			
		||||
  virtual ErrorCode write(uint8_t address, const uint8_t *buffer, size_t len) {
 | 
			
		||||
    return write(address, buffer, len, true);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// @brief Creates a WriteBuffer and calls the writev() method to send the bytes from this buffer
 | 
			
		||||
  /// @param address address of the I²C component on the i2c bus
 | 
			
		||||
  /// @param buffer pointer to an array of bytes that contains the data to be sent
 | 
			
		||||
  /// @param len length of the buffer = number of bytes to write
 | 
			
		||||
  /// @param stop true or false: True will send a stop message, releasing the bus after
 | 
			
		||||
  /// transmission. False will send a restart, keeping the connection active.
 | 
			
		||||
  /// @return an i2c::ErrorCode
 | 
			
		||||
  virtual ErrorCode write(uint8_t address, const uint8_t *buffer, size_t len, bool stop) {
 | 
			
		||||
    WriteBuffer buf;
 | 
			
		||||
    buf.data = buffer;
 | 
			
		||||
    buf.len = len;
 | 
			
		||||
    return writev(address, &buf, 1, stop);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  virtual ErrorCode writev(uint8_t address, WriteBuffer *buffers, size_t cnt) {
 | 
			
		||||
    return writev(address, buffers, cnt, true);
 | 
			
		||||
  }
 | 
			
		||||
  virtual ErrorCode writev(uint8_t address, WriteBuffer *buffers, size_t cnt, bool stop) = 0;
 | 
			
		||||
 | 
			
		||||
  /// @brief This virtual method writes bytes to an I2CBus from an array of WriteBuffer.
 | 
			
		||||
  /// @param address address of the I²C component on the i2c bus
 | 
			
		||||
  /// @param buffers pointer to an array of WriteBuffer
 | 
			
		||||
  /// @param count number of WriteBuffer to write
 | 
			
		||||
  /// @param stop true or false: True will send a stop message, releasing the bus after
 | 
			
		||||
  /// transmission. False will send a restart, keeping the connection active.
 | 
			
		||||
  /// @return an i2c::ErrorCode
 | 
			
		||||
  /// @details This is a pure virtual method that must be implemented in the subclass.
 | 
			
		||||
  virtual ErrorCode writev(uint8_t address, WriteBuffer *buffers, size_t count, bool stop) = 0;
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  /// @brief Scans the I2C bus for devices. Devices presence is kept in an array of std::pair
 | 
			
		||||
  /// that contains the address and the corresponding bool presence flag.
 | 
			
		||||
  void i2c_scan_() {
 | 
			
		||||
    for (uint8_t address = 8; address < 120; address++) {
 | 
			
		||||
      auto err = writev(address, nullptr, 0);
 | 
			
		||||
@@ -61,8 +104,8 @@ class I2CBus {
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  std::vector<std::pair<uint8_t, bool>> scan_results_;
 | 
			
		||||
  bool scan_{false};
 | 
			
		||||
  std::vector<std::pair<uint8_t, bool>> scan_results_;  ///< array containing scan results
 | 
			
		||||
  bool scan_{false};                                    ///< Should we scan ? Can be set in the yaml
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}  // namespace i2c
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,7 @@ void I2SAudioSpeaker::start_() {
 | 
			
		||||
  }
 | 
			
		||||
  this->state_ = speaker::STATE_RUNNING;
 | 
			
		||||
 | 
			
		||||
  xTaskCreate(I2SAudioSpeaker::player_task, "speaker_task", 8192, (void *) this, 0, &this->player_task_handle_);
 | 
			
		||||
  xTaskCreate(I2SAudioSpeaker::player_task, "speaker_task", 8192, (void *) this, 1, &this->player_task_handle_);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void I2SAudioSpeaker::player_task(void *params) {
 | 
			
		||||
 
 | 
			
		||||
@@ -36,6 +36,7 @@ _LOGGER = logging.getLogger(__name__)
 | 
			
		||||
DOMAIN = "image"
 | 
			
		||||
DEPENDENCIES = ["display"]
 | 
			
		||||
MULTI_CONF = True
 | 
			
		||||
MULTI_CONF_NO_DEFAULT = True
 | 
			
		||||
 | 
			
		||||
image_ns = cg.esphome_ns.namespace("image")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -84,7 +84,7 @@ void LilygoT547Touchscreen::update_touches() {
 | 
			
		||||
    id = (buffer[i * 5] >> 4) & 0x0F;
 | 
			
		||||
    y_raw = (uint16_t) ((buffer[i * 5 + 1] << 4) | ((buffer[i * 5 + 3] >> 4) & 0x0F));
 | 
			
		||||
    x_raw = (uint16_t) ((buffer[i * 5 + 2] << 4) | (buffer[i * 5 + 3] & 0x0F));
 | 
			
		||||
    this->set_raw_touch_position_(id, x_raw, y_raw);
 | 
			
		||||
    this->add_raw_touch_position_(id, x_raw, y_raw);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  this->status_clear_warning();
 | 
			
		||||
 
 | 
			
		||||
@@ -237,8 +237,8 @@ void Logger::pre_setup() {
 | 
			
		||||
        Serial1.begin(this->baud_rate_);
 | 
			
		||||
#else
 | 
			
		||||
#if ARDUINO_USB_CDC_ON_BOOT
 | 
			
		||||
        this->hw_serial_ = &Serial;
 | 
			
		||||
        Serial.begin(this->baud_rate_);
 | 
			
		||||
        this->hw_serial_ = &Serial0;
 | 
			
		||||
        Serial0.begin(this->baud_rate_);
 | 
			
		||||
#else
 | 
			
		||||
        this->hw_serial_ = &Serial;
 | 
			
		||||
        Serial.begin(this->baud_rate_);
 | 
			
		||||
 
 | 
			
		||||
@@ -51,7 +51,7 @@ void Touchscreen::loop() {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Touchscreen::set_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_raw, int16_t z_raw) {
 | 
			
		||||
void Touchscreen::add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_raw, int16_t z_raw) {
 | 
			
		||||
  TouchPoint tp;
 | 
			
		||||
  uint16_t x, y;
 | 
			
		||||
  if (this->touches_.count(id) == 0) {
 | 
			
		||||
 
 | 
			
		||||
@@ -87,7 +87,7 @@ class Touchscreen : public PollingComponent {
 | 
			
		||||
 | 
			
		||||
  void attach_interrupt_(InternalGPIOPin *irq_pin, esphome::gpio::InterruptType type);
 | 
			
		||||
 | 
			
		||||
  void set_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_raw, int16_t z_raw = 0);
 | 
			
		||||
  void add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_raw, int16_t z_raw = 0);
 | 
			
		||||
 | 
			
		||||
  void send_touches_();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -109,7 +109,7 @@ void TT21100Touchscreen::update_touches() {
 | 
			
		||||
                 i, touch->touch_type, touch->tip, touch->event_id, touch->touch_id, touch->x, touch->y,
 | 
			
		||||
                 touch->pressure, touch->major_axis_length, touch->orientation);
 | 
			
		||||
 | 
			
		||||
        this->set_raw_touch_position_(touch->tip, touch->x, touch->y, touch->pressure);
 | 
			
		||||
        this->add_raw_touch_position_(touch->tip, touch->x, touch->y, touch->pressure);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -9,13 +9,20 @@ static const char *const TAG = "tuya.fan";
 | 
			
		||||
void TuyaFan::setup() {
 | 
			
		||||
  if (this->speed_id_.has_value()) {
 | 
			
		||||
    this->parent_->register_listener(*this->speed_id_, [this](const TuyaDatapoint &datapoint) {
 | 
			
		||||
      ESP_LOGV(TAG, "MCU reported speed of: %d", datapoint.value_enum);
 | 
			
		||||
      if (datapoint.value_enum >= this->speed_count_) {
 | 
			
		||||
        ESP_LOGE(TAG, "Speed has invalid value %d", datapoint.value_enum);
 | 
			
		||||
      } else {
 | 
			
		||||
        this->speed = datapoint.value_enum + 1;
 | 
			
		||||
      if (datapoint.type == TuyaDatapointType::ENUM) {
 | 
			
		||||
        ESP_LOGV(TAG, "MCU reported speed of: %d", datapoint.value_enum);
 | 
			
		||||
        if (datapoint.value_enum >= this->speed_count_) {
 | 
			
		||||
          ESP_LOGE(TAG, "Speed has invalid value %d", datapoint.value_enum);
 | 
			
		||||
        } else {
 | 
			
		||||
          this->speed = datapoint.value_enum + 1;
 | 
			
		||||
          this->publish_state();
 | 
			
		||||
        }
 | 
			
		||||
      } else if (datapoint.type == TuyaDatapointType::INTEGER) {
 | 
			
		||||
        ESP_LOGV(TAG, "MCU reported speed of: %d", datapoint.value_int);
 | 
			
		||||
        this->speed = datapoint.value_int;
 | 
			
		||||
        this->publish_state();
 | 
			
		||||
      }
 | 
			
		||||
      this->speed_type_ = datapoint.type;
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
  if (this->switch_id_.has_value()) {
 | 
			
		||||
@@ -80,7 +87,11 @@ void TuyaFan::control(const fan::FanCall &call) {
 | 
			
		||||
    this->parent_->set_enum_datapoint_value(*this->direction_id_, enable);
 | 
			
		||||
  }
 | 
			
		||||
  if (this->speed_id_.has_value() && call.get_speed().has_value()) {
 | 
			
		||||
    this->parent_->set_enum_datapoint_value(*this->speed_id_, *call.get_speed() - 1);
 | 
			
		||||
    if (this->speed_type_ == TuyaDatapointType::ENUM) {
 | 
			
		||||
      this->parent_->set_enum_datapoint_value(*this->speed_id_, *call.get_speed() - 1);
 | 
			
		||||
    } else if (this->speed_type_ == TuyaDatapointType::INTEGER) {
 | 
			
		||||
      this->parent_->set_integer_datapoint_value(*this->speed_id_, *call.get_speed());
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -28,6 +28,7 @@ class TuyaFan : public Component, public fan::Fan {
 | 
			
		||||
  optional<uint8_t> oscillation_id_{};
 | 
			
		||||
  optional<uint8_t> direction_id_{};
 | 
			
		||||
  int speed_count_{};
 | 
			
		||||
  TuyaDatapointType speed_type_{};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}  // namespace tuya
 | 
			
		||||
 
 | 
			
		||||
@@ -31,40 +31,122 @@ const LogString *parity_to_str(UARTParityOptions parity);
 | 
			
		||||
 | 
			
		||||
class UARTComponent {
 | 
			
		||||
 public:
 | 
			
		||||
  // Writes an array of bytes to the UART bus.
 | 
			
		||||
  // @param data A vector of bytes to be written.
 | 
			
		||||
  void write_array(const std::vector<uint8_t> &data) { this->write_array(&data[0], data.size()); }
 | 
			
		||||
 | 
			
		||||
  // Writes a single byte to the UART bus.
 | 
			
		||||
  // @param data The byte to be written.
 | 
			
		||||
  void write_byte(uint8_t data) { this->write_array(&data, 1); };
 | 
			
		||||
 | 
			
		||||
  // Writes a null-terminated string to the UART bus.
 | 
			
		||||
  // @param str Pointer to the null-terminated string.
 | 
			
		||||
  void write_str(const char *str) {
 | 
			
		||||
    const auto *data = reinterpret_cast<const uint8_t *>(str);
 | 
			
		||||
    this->write_array(data, strlen(str));
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  // Pure virtual method to write an array of bytes to the UART bus.
 | 
			
		||||
  // @param data Pointer to the array of bytes.
 | 
			
		||||
  // @param len Length of the array.
 | 
			
		||||
  virtual void write_array(const uint8_t *data, size_t len) = 0;
 | 
			
		||||
 | 
			
		||||
  // Reads a single byte from the UART bus.
 | 
			
		||||
  // @param data Pointer to the byte where the read data will be stored.
 | 
			
		||||
  // @return True if a byte was successfully read, false otherwise.
 | 
			
		||||
  bool read_byte(uint8_t *data) { return this->read_array(data, 1); };
 | 
			
		||||
 | 
			
		||||
  // Pure virtual method to peek the next byte in the UART buffer without removing it.
 | 
			
		||||
  // @param data Pointer to the byte where the peeked data will be stored.
 | 
			
		||||
  // @return True if a byte is available to peek, false otherwise.
 | 
			
		||||
  virtual bool peek_byte(uint8_t *data) = 0;
 | 
			
		||||
 | 
			
		||||
  // Pure virtual method to read an array of bytes from the UART bus.
 | 
			
		||||
  // @param data Pointer to the array where the read data will be stored.
 | 
			
		||||
  // @param len Number of bytes to read.
 | 
			
		||||
  // @return True if the specified number of bytes were successfully read, false otherwise.
 | 
			
		||||
  virtual bool read_array(uint8_t *data, size_t len) = 0;
 | 
			
		||||
 | 
			
		||||
  /// Return available number of bytes.
 | 
			
		||||
  // Pure virtual method to return the number of bytes available for reading.
 | 
			
		||||
  // @return Number of available bytes.
 | 
			
		||||
  virtual int available() = 0;
 | 
			
		||||
  /// Block until all bytes have been written to the UART bus.
 | 
			
		||||
 | 
			
		||||
  // Pure virtual method to block until all bytes have been written to the UART bus.
 | 
			
		||||
  virtual void flush() = 0;
 | 
			
		||||
 | 
			
		||||
  // Sets the TX (transmit) pin for the UART bus.
 | 
			
		||||
  // @param tx_pin Pointer to the internal GPIO pin used for transmission.
 | 
			
		||||
  void set_tx_pin(InternalGPIOPin *tx_pin) { this->tx_pin_ = tx_pin; }
 | 
			
		||||
 | 
			
		||||
  // Sets the RX (receive) pin for the UART bus.
 | 
			
		||||
  // @param rx_pin Pointer to the internal GPIO pin used for reception.
 | 
			
		||||
  void set_rx_pin(InternalGPIOPin *rx_pin) { this->rx_pin_ = rx_pin; }
 | 
			
		||||
 | 
			
		||||
  // Sets the size of the RX buffer.
 | 
			
		||||
  // @param rx_buffer_size Size of the RX buffer in bytes.
 | 
			
		||||
  void set_rx_buffer_size(size_t rx_buffer_size) { this->rx_buffer_size_ = rx_buffer_size; }
 | 
			
		||||
 | 
			
		||||
  // Gets the size of the RX buffer.
 | 
			
		||||
  // @return Size of the RX buffer in bytes.
 | 
			
		||||
  size_t get_rx_buffer_size() { return this->rx_buffer_size_; }
 | 
			
		||||
 | 
			
		||||
  // Sets the number of stop bits used in UART communication.
 | 
			
		||||
  // @param stop_bits Number of stop bits.
 | 
			
		||||
  void set_stop_bits(uint8_t stop_bits) { this->stop_bits_ = stop_bits; }
 | 
			
		||||
 | 
			
		||||
  // Gets the number of stop bits used in UART communication.
 | 
			
		||||
  // @return Number of stop bits.
 | 
			
		||||
  uint8_t get_stop_bits() const { return this->stop_bits_; }
 | 
			
		||||
 | 
			
		||||
  // Set the number of data bits used in UART communication.
 | 
			
		||||
  // @param data_bits Number of data bits.
 | 
			
		||||
  void set_data_bits(uint8_t data_bits) { this->data_bits_ = data_bits; }
 | 
			
		||||
 | 
			
		||||
  // Get the number of data bits used in UART communication.
 | 
			
		||||
  // @return Number of data bits.
 | 
			
		||||
  uint8_t get_data_bits() const { return this->data_bits_; }
 | 
			
		||||
 | 
			
		||||
  // Set the parity used in UART communication.
 | 
			
		||||
  // @param parity Parity option.
 | 
			
		||||
  void set_parity(UARTParityOptions parity) { this->parity_ = parity; }
 | 
			
		||||
 | 
			
		||||
  // Get the parity used in UART communication.
 | 
			
		||||
  // @return Parity option.
 | 
			
		||||
  UARTParityOptions get_parity() const { return this->parity_; }
 | 
			
		||||
 | 
			
		||||
  // Set the baud rate for UART communication.
 | 
			
		||||
  // @param baud_rate Baud rate in bits per second.
 | 
			
		||||
  void set_baud_rate(uint32_t baud_rate) { baud_rate_ = baud_rate; }
 | 
			
		||||
 | 
			
		||||
  // Get the baud rate for UART communication.
 | 
			
		||||
  // @return Baud rate in bits per second.
 | 
			
		||||
  uint32_t get_baud_rate() const { return baud_rate_; }
 | 
			
		||||
 | 
			
		||||
#ifdef USE_ESP32
 | 
			
		||||
  virtual void load_settings() = 0;
 | 
			
		||||
  virtual void load_settings(bool dump_config) = 0;
 | 
			
		||||
  /**
 | 
			
		||||
   * Load the UART settings.
 | 
			
		||||
   * @param dump_config If true (default), output the new settings to logs; otherwise, change settings quietly.
 | 
			
		||||
   *
 | 
			
		||||
   * Example:
 | 
			
		||||
   * ```cpp
 | 
			
		||||
   * id(uart1).load_settings(false);
 | 
			
		||||
   * ```
 | 
			
		||||
   *
 | 
			
		||||
   * This will load the current UART interface with the latest settings (baud_rate, parity, etc).
 | 
			
		||||
   */
 | 
			
		||||
  virtual void load_settings(bool dump_config){};
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Load the UART settings.
 | 
			
		||||
   *
 | 
			
		||||
   * Example:
 | 
			
		||||
   * ```cpp
 | 
			
		||||
   * id(uart1).load_settings();
 | 
			
		||||
   * ```
 | 
			
		||||
   *
 | 
			
		||||
   * This will load the current UART interface with the latest settings (baud_rate, parity, etc).
 | 
			
		||||
   */
 | 
			
		||||
  virtual void load_settings(){};
 | 
			
		||||
#endif  // USE_ESP32
 | 
			
		||||
 | 
			
		||||
#ifdef USE_UART_DEBUGGER
 | 
			
		||||
 
 | 
			
		||||
@@ -88,7 +88,11 @@ void ESP32ArduinoUARTComponent::setup() {
 | 
			
		||||
#endif
 | 
			
		||||
  static uint8_t next_uart_num = 0;
 | 
			
		||||
  if (is_default_tx && is_default_rx && next_uart_num == 0) {
 | 
			
		||||
#if ARDUINO_USB_CDC_ON_BOOT
 | 
			
		||||
    this->hw_serial_ = &Serial0;
 | 
			
		||||
#else
 | 
			
		||||
    this->hw_serial_ = &Serial;
 | 
			
		||||
#endif
 | 
			
		||||
    next_uart_num++;
 | 
			
		||||
  } else {
 | 
			
		||||
#ifdef USE_LOGGER
 | 
			
		||||
 
 | 
			
		||||
@@ -167,6 +167,25 @@ void WaveshareEPaper::on_safe_shutdown() { this->deep_sleep(); }
 | 
			
		||||
// ========================================================
 | 
			
		||||
 | 
			
		||||
void WaveshareEPaperTypeA::initialize() {
 | 
			
		||||
  // Achieve display intialization
 | 
			
		||||
  this->init_display_();
 | 
			
		||||
  // If a reset pin is configured, eligible displays can be set to deep sleep
 | 
			
		||||
  // between updates, as recommended by the hardware provider
 | 
			
		||||
  if (this->reset_pin_ != nullptr) {
 | 
			
		||||
    switch (this->model_) {
 | 
			
		||||
      // More models can be added here to enable deep sleep if eligible
 | 
			
		||||
      case WAVESHARE_EPAPER_1_54_IN:
 | 
			
		||||
      case WAVESHARE_EPAPER_1_54_IN_V2:
 | 
			
		||||
        this->deep_sleep_between_updates_ = true;
 | 
			
		||||
        ESP_LOGI(TAG, "Set the display to deep sleep");
 | 
			
		||||
        this->deep_sleep();
 | 
			
		||||
        break;
 | 
			
		||||
      default:
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
void WaveshareEPaperTypeA::init_display_() {
 | 
			
		||||
  if (this->model_ == TTGO_EPAPER_2_13_IN_B74) {
 | 
			
		||||
    this->reset_pin_->digital_write(false);
 | 
			
		||||
    delay(10);
 | 
			
		||||
@@ -261,6 +280,13 @@ void HOT WaveshareEPaperTypeA::display() {
 | 
			
		||||
  bool full_update = this->at_update_ == 0;
 | 
			
		||||
  bool prev_full_update = this->at_update_ == 1;
 | 
			
		||||
 | 
			
		||||
  if (this->deep_sleep_between_updates_) {
 | 
			
		||||
    ESP_LOGI(TAG, "Wake up the display");
 | 
			
		||||
    this->reset_();
 | 
			
		||||
    this->wait_until_idle_();
 | 
			
		||||
    this->init_display_();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (!this->wait_until_idle_()) {
 | 
			
		||||
    this->status_set_warning();
 | 
			
		||||
    return;
 | 
			
		||||
@@ -384,6 +410,11 @@ void HOT WaveshareEPaperTypeA::display() {
 | 
			
		||||
  this->command(0xFF);
 | 
			
		||||
 | 
			
		||||
  this->status_clear_warning();
 | 
			
		||||
 | 
			
		||||
  if (this->deep_sleep_between_updates_) {
 | 
			
		||||
    ESP_LOGI(TAG, "Set the display back to deep sleep");
 | 
			
		||||
    this->deep_sleep();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
int WaveshareEPaperTypeA::get_width_internal() {
 | 
			
		||||
  switch (this->model_) {
 | 
			
		||||
@@ -445,6 +476,8 @@ void WaveshareEPaperTypeA::set_full_update_every(uint32_t full_update_every) {
 | 
			
		||||
 | 
			
		||||
uint32_t WaveshareEPaperTypeA::idle_timeout_() {
 | 
			
		||||
  switch (this->model_) {
 | 
			
		||||
    case WAVESHARE_EPAPER_1_54_IN:
 | 
			
		||||
    case WAVESHARE_EPAPER_1_54_IN_V2:
 | 
			
		||||
    case TTGO_EPAPER_2_13_IN_B1:
 | 
			
		||||
      return 2500;
 | 
			
		||||
    default:
 | 
			
		||||
 
 | 
			
		||||
@@ -92,13 +92,20 @@ class WaveshareEPaperTypeA : public WaveshareEPaper {
 | 
			
		||||
  void display() override;
 | 
			
		||||
 | 
			
		||||
  void deep_sleep() override {
 | 
			
		||||
    if (this->model_ == WAVESHARE_EPAPER_2_9_IN_V2 || this->model_ == WAVESHARE_EPAPER_1_54_IN_V2) {
 | 
			
		||||
      // COMMAND DEEP SLEEP MODE
 | 
			
		||||
      this->command(0x10);
 | 
			
		||||
      this->data(0x01);
 | 
			
		||||
    } else {
 | 
			
		||||
      // COMMAND DEEP SLEEP MODE
 | 
			
		||||
      this->command(0x10);
 | 
			
		||||
    switch (this->model_) {
 | 
			
		||||
      // Models with specific deep sleep command and data
 | 
			
		||||
      case WAVESHARE_EPAPER_1_54_IN:
 | 
			
		||||
      case WAVESHARE_EPAPER_1_54_IN_V2:
 | 
			
		||||
      case WAVESHARE_EPAPER_2_9_IN_V2:
 | 
			
		||||
        // COMMAND DEEP SLEEP MODE
 | 
			
		||||
        this->command(0x10);
 | 
			
		||||
        this->data(0x01);
 | 
			
		||||
        break;
 | 
			
		||||
      // Other models default to simple deep sleep command
 | 
			
		||||
      default:
 | 
			
		||||
        // COMMAND DEEP SLEEP
 | 
			
		||||
        this->command(0x10);
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    this->wait_until_idle_();
 | 
			
		||||
  }
 | 
			
		||||
@@ -108,6 +115,8 @@ class WaveshareEPaperTypeA : public WaveshareEPaper {
 | 
			
		||||
 protected:
 | 
			
		||||
  void write_lut_(const uint8_t *lut, uint8_t size);
 | 
			
		||||
 | 
			
		||||
  void init_display_();
 | 
			
		||||
 | 
			
		||||
  int get_width_internal() override;
 | 
			
		||||
 | 
			
		||||
  int get_height_internal() override;
 | 
			
		||||
@@ -118,6 +127,8 @@ class WaveshareEPaperTypeA : public WaveshareEPaper {
 | 
			
		||||
  uint32_t at_update_{0};
 | 
			
		||||
  WaveshareEPaperTypeAModel model_;
 | 
			
		||||
  uint32_t idle_timeout_() override;
 | 
			
		||||
 | 
			
		||||
  bool deep_sleep_between_updates_{false};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum WaveshareEPaperTypeBModel {
 | 
			
		||||
 
 | 
			
		||||
@@ -117,7 +117,7 @@ class AsyncWebServerRequest {
 | 
			
		||||
  // NOLINTNEXTLINE(readability-identifier-naming)
 | 
			
		||||
  AsyncWebServerResponse *beginResponse(int code, const char *content_type) {
 | 
			
		||||
    auto *res = new AsyncWebServerResponseEmpty(this);  // NOLINT(cppcoreguidelines-owning-memory)
 | 
			
		||||
    this->init_response_(res, 200, content_type);
 | 
			
		||||
    this->init_response_(res, code, content_type);
 | 
			
		||||
    return res;
 | 
			
		||||
  }
 | 
			
		||||
  // NOLINTNEXTLINE(readability-identifier-naming)
 | 
			
		||||
 
 | 
			
		||||
@@ -55,7 +55,7 @@ void XPT2046Component::update_touches() {
 | 
			
		||||
 | 
			
		||||
    ESP_LOGV(TAG, "Touchscreen Update [%d, %d], z = %d", x_raw, y_raw, z_raw);
 | 
			
		||||
 | 
			
		||||
    this->set_raw_touch_position_(0, x_raw, y_raw, z_raw);
 | 
			
		||||
    this->add_raw_touch_position_(0, x_raw, y_raw, z_raw);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -39,6 +39,17 @@ _LOGGER = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def iter_components(config):
 | 
			
		||||
    for domain, conf in config.items():
 | 
			
		||||
        component = get_component(domain)
 | 
			
		||||
        yield domain, component
 | 
			
		||||
        if component.is_platform_component:
 | 
			
		||||
            for p_config in conf:
 | 
			
		||||
                p_name = f"{domain}.{p_config[CONF_PLATFORM]}"
 | 
			
		||||
                platform = get_platform(domain, p_config[CONF_PLATFORM])
 | 
			
		||||
                yield p_name, platform
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def iter_component_configs(config):
 | 
			
		||||
    for domain, conf in config.items():
 | 
			
		||||
        component = get_component(domain)
 | 
			
		||||
        if component.multi_conf:
 | 
			
		||||
@@ -303,8 +314,10 @@ class LoadValidationStep(ConfigValidationStep):
 | 
			
		||||
            # Ignore top-level keys starting with a dot
 | 
			
		||||
            return
 | 
			
		||||
        result.add_output_path([self.domain], self.domain)
 | 
			
		||||
        result[self.domain] = self.conf
 | 
			
		||||
        component = get_component(self.domain)
 | 
			
		||||
        if component.multi_conf_no_default and isinstance(self.conf, core.AutoLoad):
 | 
			
		||||
            self.conf = []
 | 
			
		||||
        result[self.domain] = self.conf
 | 
			
		||||
        path = [self.domain]
 | 
			
		||||
        if component is None:
 | 
			
		||||
            result.add_str_error(f"Component not found: {self.domain}", path)
 | 
			
		||||
@@ -424,7 +437,10 @@ class MetadataValidationStep(ConfigValidationStep):
 | 
			
		||||
 | 
			
		||||
    def run(self, result: Config) -> None:
 | 
			
		||||
        if self.conf is None:
 | 
			
		||||
            result[self.domain] = self.conf = {}
 | 
			
		||||
            if self.comp.multi_conf and self.comp.multi_conf_no_default:
 | 
			
		||||
                result[self.domain] = self.conf = []
 | 
			
		||||
            else:
 | 
			
		||||
                result[self.domain] = self.conf = {}
 | 
			
		||||
 | 
			
		||||
        success = True
 | 
			
		||||
        for dependency in self.comp.dependencies:
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
"""Constants used by esphome."""
 | 
			
		||||
 | 
			
		||||
__version__ = "2023.12.0b2"
 | 
			
		||||
__version__ = "2023.12.1"
 | 
			
		||||
 | 
			
		||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
 | 
			
		||||
VALID_SUBSTITUTIONS_CHARACTERS = (
 | 
			
		||||
 
 | 
			
		||||
@@ -357,7 +357,7 @@ def snake_case(value):
 | 
			
		||||
    return value.replace(" ", "_").lower()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
_DISALLOWED_CHARS = re.compile(r"[^a-zA-Z0-9_]")
 | 
			
		||||
_DISALLOWED_CHARS = re.compile(r"[^a-zA-Z0-9-_]")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def sanitize(value):
 | 
			
		||||
 
 | 
			
		||||
@@ -57,6 +57,10 @@ class ComponentManifest:
 | 
			
		||||
    def multi_conf(self) -> bool:
 | 
			
		||||
        return getattr(self.module, "MULTI_CONF", False)
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def multi_conf_no_default(self) -> bool:
 | 
			
		||||
        return getattr(self.module, "MULTI_CONF_NO_DEFAULT", False)
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def to_code(self) -> Optional[Callable[[Any], None]]:
 | 
			
		||||
        return getattr(self.module, "to_code", None)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
import operator
 | 
			
		||||
from functools import reduce
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.core import CORE, ID
 | 
			
		||||
from esphome.core import CORE
 | 
			
		||||
 | 
			
		||||
from esphome.const import (
 | 
			
		||||
    CONF_INPUT,
 | 
			
		||||
@@ -25,15 +25,16 @@ class PinRegistry(dict):
 | 
			
		||||
    def reset(self):
 | 
			
		||||
        self.pins_used = {}
 | 
			
		||||
 | 
			
		||||
    def get_count(self, key, number):
 | 
			
		||||
    def get_count(self, key, id, number):
 | 
			
		||||
        """
 | 
			
		||||
        Get the number of places a given pin is used.
 | 
			
		||||
        :param key: The ID of the defining component
 | 
			
		||||
        :param key: The key of the registered pin schema.
 | 
			
		||||
        :param id: The ID of the defining component
 | 
			
		||||
        :param number: The pin number
 | 
			
		||||
        :return: The number of places the pin is used.
 | 
			
		||||
        """
 | 
			
		||||
        pin_key = (key, number)
 | 
			
		||||
        return self.pins_used[pin_key] if pin_key in self.pins_used else 0
 | 
			
		||||
        pin_key = (key, id, number)
 | 
			
		||||
        return len(self.pins_used[pin_key]) if pin_key in self.pins_used else 0
 | 
			
		||||
 | 
			
		||||
    def register(self, name, schema, final_validate=None):
 | 
			
		||||
        """
 | 
			
		||||
@@ -65,9 +66,10 @@ class PinRegistry(dict):
 | 
			
		||||
        result = self[key][1](conf)
 | 
			
		||||
        if CONF_NUMBER in result:
 | 
			
		||||
            # key maps to the pin schema
 | 
			
		||||
            if isinstance(key, ID):
 | 
			
		||||
                key = key.id
 | 
			
		||||
            pin_key = (key, result[CONF_NUMBER])
 | 
			
		||||
            if key != CORE.target_platform:
 | 
			
		||||
                pin_key = (key, conf[key], result[CONF_NUMBER])
 | 
			
		||||
            else:
 | 
			
		||||
                pin_key = (key, key, result[CONF_NUMBER])
 | 
			
		||||
            if pin_key not in self.pins_used:
 | 
			
		||||
                self.pins_used[pin_key] = []
 | 
			
		||||
            # client_id identifies the instance of the providing component
 | 
			
		||||
@@ -101,7 +103,7 @@ class PinRegistry(dict):
 | 
			
		||||
        Run the final validation for all pins, and check for reuse
 | 
			
		||||
        :param fconf: The full config
 | 
			
		||||
        """
 | 
			
		||||
        for (key, _), pin_list in self.pins_used.items():
 | 
			
		||||
        for (key, _, _), pin_list in self.pins_used.items():
 | 
			
		||||
            count = len(pin_list)  # number of places same pin used.
 | 
			
		||||
            final_val_fun = self[key][2]  # final validation function
 | 
			
		||||
            for pin_path, client_id, pin_config in pin_list:
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ import re
 | 
			
		||||
from pathlib import Path
 | 
			
		||||
from typing import Union
 | 
			
		||||
 | 
			
		||||
from esphome.config import iter_components
 | 
			
		||||
from esphome.config import iter_components, iter_component_configs
 | 
			
		||||
from esphome.const import (
 | 
			
		||||
    HEADER_FILE_EXTENSIONS,
 | 
			
		||||
    SOURCE_FILE_EXTENSIONS,
 | 
			
		||||
@@ -70,14 +70,14 @@ UPLOAD_SPEED_OVERRIDE = {
 | 
			
		||||
 | 
			
		||||
def get_flags(key):
 | 
			
		||||
    flags = set()
 | 
			
		||||
    for _, component, conf in iter_components(CORE.config):
 | 
			
		||||
    for _, component, conf in iter_component_configs(CORE.config):
 | 
			
		||||
        flags |= getattr(component, key)(conf)
 | 
			
		||||
    return flags
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_include_text():
 | 
			
		||||
    include_text = '#include "esphome.h"\nusing namespace esphome;\n'
 | 
			
		||||
    for _, component, conf in iter_components(CORE.config):
 | 
			
		||||
    for _, component, conf in iter_component_configs(CORE.config):
 | 
			
		||||
        if not hasattr(component, "includes"):
 | 
			
		||||
            continue
 | 
			
		||||
        includes = component.includes
 | 
			
		||||
@@ -232,7 +232,7 @@ the custom_components folder or the external_components feature.
 | 
			
		||||
 | 
			
		||||
def copy_src_tree():
 | 
			
		||||
    source_files: list[loader.FileResource] = []
 | 
			
		||||
    for _, component, _ in iter_components(CORE.config):
 | 
			
		||||
    for _, component in iter_components(CORE.config):
 | 
			
		||||
        source_files += component.resources
 | 
			
		||||
    source_files_map = {
 | 
			
		||||
        Path(x.package.replace(".", "/") + "/" + x.resource): x for x in source_files
 | 
			
		||||
 
 | 
			
		||||
@@ -10,8 +10,8 @@ platformio==6.1.11  # When updating platformio, also update Dockerfile
 | 
			
		||||
esptool==4.6.2
 | 
			
		||||
click==8.1.7
 | 
			
		||||
esphome-dashboard==20231107.0
 | 
			
		||||
aioesphomeapi==21.0.0
 | 
			
		||||
zeroconf==0.128.4
 | 
			
		||||
aioesphomeapi==21.0.1
 | 
			
		||||
zeroconf==0.130.0
 | 
			
		||||
python-magic==0.4.27
 | 
			
		||||
 | 
			
		||||
# esp-idf requires this, but doesn't bundle it by default
 | 
			
		||||
 
 | 
			
		||||
@@ -1667,7 +1667,6 @@ binary_sensor:
 | 
			
		||||
      mcp23xxx: mcp23s08_hub
 | 
			
		||||
      # Use pin number 1
 | 
			
		||||
      number: 1
 | 
			
		||||
      allow_other_uses: true
 | 
			
		||||
      # One of INPUT or INPUT_PULLUP
 | 
			
		||||
      mode: INPUT_PULLUP
 | 
			
		||||
      inverted: false
 | 
			
		||||
@@ -2149,7 +2148,6 @@ output:
 | 
			
		||||
    pin:
 | 
			
		||||
      mcp23xxx: mcp23017_hub
 | 
			
		||||
      number: 0
 | 
			
		||||
      allow_other_uses: true
 | 
			
		||||
      mode: OUTPUT
 | 
			
		||||
      inverted: false
 | 
			
		||||
  - platform: gpio
 | 
			
		||||
@@ -2157,7 +2155,6 @@ output:
 | 
			
		||||
    pin:
 | 
			
		||||
      mcp23xxx: mcp23008_hub
 | 
			
		||||
      number: 0
 | 
			
		||||
      allow_other_uses: true
 | 
			
		||||
      mode: OUTPUT
 | 
			
		||||
      inverted: false
 | 
			
		||||
  - platform: gpio
 | 
			
		||||
@@ -2597,7 +2594,6 @@ switch:
 | 
			
		||||
      mcp23xxx: mcp23s08_hub
 | 
			
		||||
      # Use pin number 0
 | 
			
		||||
      number: 0
 | 
			
		||||
      allow_other_uses: true
 | 
			
		||||
      mode: OUTPUT
 | 
			
		||||
      inverted: false
 | 
			
		||||
  - platform: gpio
 | 
			
		||||
 
 | 
			
		||||
@@ -401,7 +401,6 @@ switch:
 | 
			
		||||
    pin:
 | 
			
		||||
      mcp23xxx: mcp23017_hub
 | 
			
		||||
      number: 0
 | 
			
		||||
      allow_other_uses: true
 | 
			
		||||
      mode: OUTPUT
 | 
			
		||||
    interlock: &interlock [gpio_switch1, gpio_switch2, gpio_switch3]
 | 
			
		||||
  - platform: gpio
 | 
			
		||||
@@ -409,7 +408,6 @@ switch:
 | 
			
		||||
    pin:
 | 
			
		||||
      mcp23xxx: mcp23008_hub
 | 
			
		||||
      number: 0
 | 
			
		||||
      allow_other_uses: true
 | 
			
		||||
      mode: OUTPUT
 | 
			
		||||
    interlock: *interlock
 | 
			
		||||
  - platform: gpio
 | 
			
		||||
 
 | 
			
		||||
@@ -92,3 +92,13 @@ sensor:
 | 
			
		||||
      name: "Loop Time"
 | 
			
		||||
    psram:
 | 
			
		||||
      name: "PSRAM Free"
 | 
			
		||||
 | 
			
		||||
# Purposely test that `animation:` does auto-load `image:`
 | 
			
		||||
# Keep the `image:` undefined.
 | 
			
		||||
# image:
 | 
			
		||||
 | 
			
		||||
animation:
 | 
			
		||||
  - id: rgb565_animation
 | 
			
		||||
    file: pnglogo.png
 | 
			
		||||
    type: RGB565
 | 
			
		||||
    use_transparency: no
 | 
			
		||||
 
 | 
			
		||||
@@ -261,6 +261,7 @@ def test_snake_case(text, expected):
 | 
			
		||||
        ('!"§$%&/()=?foo_bar', "___________foo_bar"),
 | 
			
		||||
        ('foo_!"§$%&/()=?bar', "foo____________bar"),
 | 
			
		||||
        ('foo_bar!"§$%&/()=?', "foo_bar___________"),
 | 
			
		||||
        ('foo-bar!"§$%&/()=?', "foo-bar___________"),
 | 
			
		||||
    ),
 | 
			
		||||
)
 | 
			
		||||
def test_sanitize(text, expected):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user