Fix wrong initialization of vectors in ade7953_i2c (#6393)

This commit is contained in:
Stefan Rado 2024-03-18 19:06:17 +01:00 committed by Jesse Hills
parent 9442f7a271
commit db1b187e80
No known key found for this signature in database
GPG key ID: BEAAE804EFD8E83A

View file

@ -13,29 +13,29 @@ void AdE7953I2c::dump_config() {
ade7953_base::ADE7953::dump_config(); ade7953_base::ADE7953::dump_config();
} }
bool AdE7953I2c::ade_write_8(uint16_t reg, uint8_t value) { bool AdE7953I2c::ade_write_8(uint16_t reg, uint8_t value) {
std::vector<uint8_t> data(3); uint8_t data[3];
data.push_back(reg >> 8); data[0] = reg >> 8;
data.push_back(reg >> 0); data[1] = reg >> 0;
data.push_back(value); data[2] = value;
return this->write(data.data(), data.size()) != i2c::ERROR_OK; return this->write(data, 3) != i2c::ERROR_OK;
} }
bool AdE7953I2c::ade_write_16(uint16_t reg, uint16_t value) { bool AdE7953I2c::ade_write_16(uint16_t reg, uint16_t value) {
std::vector<uint8_t> data(4); uint8_t data[4];
data.push_back(reg >> 8); data[0] = reg >> 8;
data.push_back(reg >> 0); data[1] = reg >> 0;
data.push_back(value >> 8); data[2] = value >> 8;
data.push_back(value >> 0); data[3] = value >> 0;
return this->write(data.data(), data.size()) != i2c::ERROR_OK; return this->write(data, 4) != i2c::ERROR_OK;
} }
bool AdE7953I2c::ade_write_32(uint16_t reg, uint32_t value) { bool AdE7953I2c::ade_write_32(uint16_t reg, uint32_t value) {
std::vector<uint8_t> data(6); uint8_t data[6];
data.push_back(reg >> 8); data[0] = reg >> 8;
data.push_back(reg >> 0); data[1] = reg >> 0;
data.push_back(value >> 24); data[2] = value >> 24;
data.push_back(value >> 16); data[3] = value >> 16;
data.push_back(value >> 8); data[4] = value >> 8;
data.push_back(value >> 0); data[5] = value >> 0;
return this->write(data.data(), data.size()) != i2c::ERROR_OK; return this->write(data, 6) != i2c::ERROR_OK;
} }
bool AdE7953I2c::ade_read_8(uint16_t reg, uint8_t *value) { bool AdE7953I2c::ade_read_8(uint16_t reg, uint8_t *value) {
uint8_t reg_data[2]; uint8_t reg_data[2];