From fcb7362d96ba18bdba5ad89116a27d4096132284 Mon Sep 17 00:00:00 2001 From: Pebblebed Date: Sat, 10 Feb 2024 10:43:29 +0000 Subject: [PATCH] Fix clang and update tests --- .../external_eeprom/external_eeprom.cpp | 141 ++++++++---------- .../external_eeprom/external_eeprom.h | 19 +-- tests/test1.yaml | 6 +- tests/test3.1.yaml | 6 +- tests/test5.yaml | 6 +- 5 files changed, 80 insertions(+), 98 deletions(-) diff --git a/esphome/components/external_eeprom/external_eeprom.cpp b/esphome/components/external_eeprom/external_eeprom.cpp index 36a72b87f6..10cae80a55 100644 --- a/esphome/components/external_eeprom/external_eeprom.cpp +++ b/esphome/components/external_eeprom/external_eeprom.cpp @@ -32,7 +32,7 @@ void ExtEepromComponent::dump_config() { /// @return an boolean True for connected bool ExtEepromComponent::is_connected(uint8_t i2c_address) { i2c::ErrorCode err; - if (i2c_address == 255) // We can't set the default so we use 255 instead + if (i2c_address == 255) // We can't set the default so we use 255 instead i2c_address = this->address_; err = this->bus_->write(i2c_address, nullptr, 0, true); if (err != i2c::ERROR_OK) @@ -110,13 +110,10 @@ void ExtEepromComponent::read(uint32_t memaddr, uint8_t *buff, uint16_t buffer_s if (memaddr > 0xFFFF) i2c_address |= 0b100; // Set the block bit to 1 } - if (this->get_address_size_bytes_() == 2) - { + if (this->get_address_size_bytes_() == 2) { uint8_t maddr[] = {(uint8_t) (memaddr >> 8), (uint8_t) (memaddr & 0xFF)}; ret = this->bus_->write(i2c_address, maddr, 2, false); - } - else - { + } else { uint8_t maddr[] = {(uint8_t) (memaddr & 0xFF)}; ret = this->bus_->write(i2c_address, maddr, 1, false); } @@ -318,72 +315,72 @@ void ExtEepromComponent::erase(uint8_t value_to_write) { } void ExtEepromComponent::set_memory_type(EEEDeviceType device_type) { device_type_ = device_type; - // Set settings based on known memory types - switch (device_type_) - { - default: - // Unknown type number - break; - case EEE_24XX00: - this->device_type_text_ = "24XX00"; - this->set_device_config_(16, 1, 1, 5); - break; - case EEE_24XX01: - this->device_type_text_ = "24XX01"; - this->set_device_config_(128, 1, 8, 5); // 128 - break; - case EEE_24XX02: - this->device_type_text_ = "24XX02"; - this->set_device_config_(256, 1, 8, 5); // 256 - break; - case EEE_24XX04: - this->device_type_text_ = "24XX04"; - this->set_device_config_(512, 1, 16, 5); // 512 - break; - case EEE_24XX08: - this->device_type_text_ = "24XX08"; - this->set_device_config_(1024, 1, 16, 5); // 1024 - break; - case EEE_24XX16: - this->device_type_text_ = "24XX16"; - this->set_device_config_(2048, 1, 16, 1); // 2048 - break; - case EEE_24XX32: - this->device_type_text_ = "24XX32"; - this->set_device_config_(4096, 2, 32, 5); // 4096 - break; - case EEE_24XX64: - this->device_type_text_ = "24XX64"; - this->set_device_config_(8192, 2, 32, 5); // 8192 - break; - case EEE_24XX128: - this->device_type_text_ = "24XX128"; - this->set_device_config_(16384, 2, 64, 5); // 16384 - break; - case EEE_24XX256: - this->device_type_text_ = "24XX256"; - this->set_device_config_(32768, 2, 64, 5); // 32768 - break; - case EEE_24XX512: - this->device_type_text_ = "24XX512"; - this->set_device_config_(65536, 2, 64, 5); // 65536 - break; - case EEE_24XX1025: - this->device_type_text_ = "24XX1025"; - this->set_device_config_(128000, 2, 128, 5); // 128000 - break; - case EEE_24XX2048: - this->device_type_text_ = "24XX2048"; - this->set_device_config_(262144, 2, 256, 5); // 262144 - break; + // Set settings based on known memory types + switch (device_type_) { + default: + // Unknown type number + break; + case EEE_24XX00: + this->device_type_text_ = "24XX00"; + this->set_device_config_(16, 1, 1, 5); + break; + case EEE_24XX01: + this->device_type_text_ = "24XX01"; + this->set_device_config_(128, 1, 8, 5); // 128 + break; + case EEE_24XX02: + this->device_type_text_ = "24XX02"; + this->set_device_config_(256, 1, 8, 5); // 256 + break; + case EEE_24XX04: + this->device_type_text_ = "24XX04"; + this->set_device_config_(512, 1, 16, 5); // 512 + break; + case EEE_24XX08: + this->device_type_text_ = "24XX08"; + this->set_device_config_(1024, 1, 16, 5); // 1024 + break; + case EEE_24XX16: + this->device_type_text_ = "24XX16"; + this->set_device_config_(2048, 1, 16, 1); // 2048 + break; + case EEE_24XX32: + this->device_type_text_ = "24XX32"; + this->set_device_config_(4096, 2, 32, 5); // 4096 + break; + case EEE_24XX64: + this->device_type_text_ = "24XX64"; + this->set_device_config_(8192, 2, 32, 5); // 8192 + break; + case EEE_24XX128: + this->device_type_text_ = "24XX128"; + this->set_device_config_(16384, 2, 64, 5); // 16384 + break; + case EEE_24XX256: + this->device_type_text_ = "24XX256"; + this->set_device_config_(32768, 2, 64, 5); // 32768 + break; + case EEE_24XX512: + this->device_type_text_ = "24XX512"; + this->set_device_config_(65536, 2, 64, 5); // 65536 + break; + case EEE_24XX1025: + this->device_type_text_ = "24XX1025"; + this->set_device_config_(128000, 2, 128, 5); // 128000 + break; + case EEE_24XX2048: + this->device_type_text_ = "24XX2048"; + this->set_device_config_(262144, 2, 256, 5); // 262144 + break; } } -void ExtEepromComponent::set_device_config_(uint32_t mem_size, uint8_t address_bytes, uint16_t page_size, uint8_t write_time_ms) +void ExtEepromComponent::set_device_config_(uint32_t mem_size, uint8_t address_bytes, uint16_t page_size, + uint8_t write_time_ms) { this->set_memory_size_(mem_size); this->set_address_size_bytes_(address_bytes); this->set_page_size_(page_size); - this->set_page_write_time_(write_time_ms); + this->set_page_write_time_(write_time_ms); } /// @brief Sets the hw I2C buffer size -2, as 2 bytes are needed for control & addr @@ -398,17 +395,14 @@ void ExtEepromComponent::write_block_(uint8_t deviceaddr, uint32_t memaddr, cons i2c::WriteBuffer buff[2]; i2c::ErrorCode ret; // Check if the device has two address bytes - if (this->get_address_size_bytes_() == 2) - { + if (this->get_address_size_bytes_() == 2) { uint8_t maddr[] = {(uint8_t) (memaddr >> 8), (uint8_t) (memaddr & 0xFF)}; buff[0].data = maddr; buff[0].len = 2; buff[1].data = obj; buff[1].len = size; ret = this->bus_->writev(this->address_, buff, 2, true); - } - else - { + } else { uint8_t maddr[] = {(uint8_t) (memaddr & 0xFF)}; buff[0].data = maddr; buff[0].len = 1; @@ -440,10 +434,7 @@ void ExtEepromComponent::set_page_write_time_(uint8_t write_time_ms) { memory_pa uint8_t ExtEepromComponent::get_page_write_time_() { return memory_page_write_time_ms_; } /// @brief Set address_bytes for the device /// @param address_bytes contains the number of bytes the device uses for address -void ExtEepromComponent::set_address_size_bytes_(uint8_t address_bytes) -{ - this->address_size_bytes_ = address_bytes; -} +void ExtEepromComponent::set_address_size_bytes_(uint8_t address_bytes) { this->address_size_bytes_ = address_bytes; } /// @brief Gets the number of bytes used for the address /// @return size in bytes uint8_t ExtEepromComponent::get_address_size_bytes_() { return this->address_size_bytes_; } diff --git a/esphome/components/external_eeprom/external_eeprom.h b/esphome/components/external_eeprom/external_eeprom.h index d29f9b3c7c..39d2fda962 100644 --- a/esphome/components/external_eeprom/external_eeprom.h +++ b/esphome/components/external_eeprom/external_eeprom.h @@ -9,8 +9,7 @@ namespace external_eeprom { /// @brief This Class provides the methods to read and write data from an 24 LC/AT XX devices such as 24LC32. See /// https://ww1.microchip.com/downloads/en/devicedoc/doc0336.pdf -enum EEEDeviceType -{ +enum EEEDeviceType { EEE_24XX00, EEE_24XX01, EEE_24XX02, @@ -57,8 +56,6 @@ class ExtEepromComponent : public i2c::I2CDevice, public Component { // Getters and Setters for component config void set_memory_type(EEEDeviceType device_type); - - void set_i2c_buffer_size(uint8_t i2c_buffer_size); // Set the size of hw buffer -2 for control & addr uint8_t get_i2c_buffer_size(); // Get the size of hw buffer -2 for control & addr // Functionality to 'get' and 'put' objects to and from EEPROM. @@ -79,14 +76,14 @@ class ExtEepromComponent : public i2c::I2CDevice, public Component { private: void write_block_(uint8_t deviceaddr, uint32_t memaddr, const uint8_t *obj, uint8_t size); void set_device_config_(uint32_t mem_size, uint8_t address_bytes, uint16_t page_size, uint8_t write_time_ms); - void set_memory_size_(uint32_t mem_size); // Set the size of memory in bytes - uint32_t get_memory_size_(); // Return size of memory in bytes - void set_page_size_(uint16_t page_size); // Set the size of the page we can write a page at a time - uint16_t get_page_size_(); // Get the size of the page we can read a page at a time + void set_memory_size_(uint32_t mem_size); // Set the size of memory in bytes + uint32_t get_memory_size_(); // Return size of memory in bytes + void set_page_size_(uint16_t page_size); // Set the size of the page we can write a page at a time + uint16_t get_page_size_(); // Get the size of the page we can read a page at a time void set_address_size_bytes_(uint8_t address_size_bytes); // Set the number of bytes to use for device address - uint8_t get_address_size_bytes_(); // Get the number of bytes to use for device address - void set_page_write_time_(uint8_t write_time_ms); // Set the number of ms required per page write - uint8_t get_page_write_time_(); // Get the number of ms required per page write + uint8_t get_address_size_bytes_(); // Get the number of bytes to use for device address + void set_page_write_time_(uint8_t write_time_ms); // Set the number of ms required per page write + uint8_t get_page_write_time_(); // Get the number of ms required per page write uint32_t memory_size_bytes_{0}; uint16_t memory_page_size_bytes_{0}; uint8_t address_size_bytes_{0}; diff --git a/tests/test1.yaml b/tests/test1.yaml index 5e6cd96105..b1b2b31207 100644 --- a/tests/test1.yaml +++ b/tests/test1.yaml @@ -4334,8 +4334,6 @@ alarm_control_panel: external_eeprom: id: ext_eeprom_component_1 address: 0x57 - ee_page_write_time: 5 - ee_page_size: 32 - ee_memory_size: 4096 - i2c_buffer_size: 126 + ee_memory_type: 24XX32 + i2c_buffer_size: 128 i2c_id: i2c_bus diff --git a/tests/test3.1.yaml b/tests/test3.1.yaml index d4e2cedce1..9399f9ad83 100644 --- a/tests/test3.1.yaml +++ b/tests/test3.1.yaml @@ -736,7 +736,5 @@ adc128s102: external_eeprom: id: ext_eeprom_component_1 address: 0x57 - ee_page_write_time: 5 - ee_page_size: 32 - ee_memory_size: 4096 - i2c_buffer_size: 126 + ee_memory_type: 24XX32 + i2c_buffer_size: 128 diff --git a/tests/test5.yaml b/tests/test5.yaml index 548013430e..314545098a 100644 --- a/tests/test5.yaml +++ b/tests/test5.yaml @@ -734,7 +734,5 @@ light: external_eeprom: id: ext_eeprom_component_1 address: 0x57 - ee_page_write_time: 5 - ee_page_size: 32 - ee_memory_size: 4096 - i2c_buffer_size: 126 + ee_memory_type: 24XX32 + i2c_buffer_size: 128