mirror of
https://github.com/esphome/esphome.git
synced 2026-11-09 14:45:57 +00:00
Merge remote-tracking branch 'origin/dev' into sx1509-max6956-apply-outputs
# Conflicts: # esphome/components/sx1509/sx1509.h
This commit is contained in:
191 files changed
+1389
-1164
No files matched your search
@@ -13,33 +13,25 @@ void AdE7953I2c::dump_config() {
|
||||
}
|
||||
bool AdE7953I2c::ade_write_8(uint16_t reg, uint8_t value) {
|
||||
uint8_t data[3];
|
||||
data[0] = reg >> 8;
|
||||
data[1] = reg >> 0;
|
||||
put_be16(data, reg);
|
||||
data[2] = value;
|
||||
return this->write(data, 3) != i2c::ERROR_OK;
|
||||
}
|
||||
bool AdE7953I2c::ade_write_16(uint16_t reg, uint16_t value) {
|
||||
uint8_t data[4];
|
||||
data[0] = reg >> 8;
|
||||
data[1] = reg >> 0;
|
||||
data[2] = value >> 8;
|
||||
data[3] = value >> 0;
|
||||
put_be16(data, reg);
|
||||
put_be16(data + 2, value);
|
||||
return this->write(data, 4) != i2c::ERROR_OK;
|
||||
}
|
||||
bool AdE7953I2c::ade_write_32(uint16_t reg, uint32_t value) {
|
||||
uint8_t data[6];
|
||||
data[0] = reg >> 8;
|
||||
data[1] = reg >> 0;
|
||||
data[2] = value >> 24;
|
||||
data[3] = value >> 16;
|
||||
data[4] = value >> 8;
|
||||
data[5] = value >> 0;
|
||||
put_be16(data, reg);
|
||||
put_be32(data + 2, value);
|
||||
return this->write(data, 6) != i2c::ERROR_OK;
|
||||
}
|
||||
bool AdE7953I2c::ade_read_8(uint16_t reg, uint8_t *value) {
|
||||
uint8_t reg_data[2];
|
||||
reg_data[0] = reg >> 8;
|
||||
reg_data[1] = reg >> 0;
|
||||
put_be16(reg_data, reg);
|
||||
i2c::ErrorCode err = this->write(reg_data, 2);
|
||||
if (err != i2c::ERROR_OK)
|
||||
return true;
|
||||
@@ -48,8 +40,7 @@ bool AdE7953I2c::ade_read_8(uint16_t reg, uint8_t *value) {
|
||||
}
|
||||
bool AdE7953I2c::ade_read_16(uint16_t reg, uint16_t *value) {
|
||||
uint8_t reg_data[2];
|
||||
reg_data[0] = reg >> 8;
|
||||
reg_data[1] = reg >> 0;
|
||||
put_be16(reg_data, reg);
|
||||
i2c::ErrorCode err = this->write(reg_data, 2);
|
||||
if (err != i2c::ERROR_OK)
|
||||
return true;
|
||||
@@ -62,8 +53,7 @@ bool AdE7953I2c::ade_read_16(uint16_t reg, uint16_t *value) {
|
||||
}
|
||||
bool AdE7953I2c::ade_read_32(uint16_t reg, uint32_t *value) {
|
||||
uint8_t reg_data[2];
|
||||
reg_data[0] = reg >> 8;
|
||||
reg_data[1] = reg >> 0;
|
||||
put_be16(reg_data, reg);
|
||||
i2c::ErrorCode err = this->write(reg_data, 2);
|
||||
if (err != i2c::ERROR_OK)
|
||||
return true;
|
||||
|
||||
@@ -10,10 +10,8 @@ static const uint8_t ADS1115_REGISTER_CONFIG = 0x01;
|
||||
|
||||
void ADS1115Component::setup() {
|
||||
uint16_t value;
|
||||
if (!this->read_byte_16(ADS1115_REGISTER_CONVERSION, &value)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_byte_16(ADS1115_REGISTER_CONVERSION, &value)))
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t config = 0;
|
||||
// Clear single-shot bit
|
||||
@@ -57,10 +55,8 @@ void ADS1115Component::setup() {
|
||||
// 0bxxxxxxxxxxxxxx11
|
||||
config |= 0b0000000000000011;
|
||||
|
||||
if (!this->write_byte_16(ADS1115_REGISTER_CONFIG, config)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte_16(ADS1115_REGISTER_CONFIG, config)))
|
||||
return;
|
||||
}
|
||||
this->prev_config_ = config;
|
||||
}
|
||||
void ADS1115Component::dump_config() {
|
||||
|
||||
@@ -51,28 +51,23 @@ void AHT10Component::setup() {
|
||||
error_code = this->write(AHT10_INITIALIZE_CMD, sizeof(AHT10_INITIALIZE_CMD));
|
||||
break;
|
||||
}
|
||||
if (error_code != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(error_code == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
uint8_t cal_attempts = 0;
|
||||
uint8_t data = AHT10_STATUS_BUSY;
|
||||
while (data & AHT10_STATUS_BUSY) {
|
||||
delay(AHT10_DEFAULT_DELAY);
|
||||
if (this->read(&data, 1) != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read(&data, 1) == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
++cal_attempts;
|
||||
if (cal_attempts > AHT10_INIT_ATTEMPTS) {
|
||||
this->mark_failed(LOG_STR("Initialization timed out"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ((data & 0x68) != 0x08) { // Bit[6:5] = 0b00, NORMAL mode and Bit[3] = 0b1, CALIBRATED
|
||||
this->mark_failed(LOG_STR("Initialization failed"));
|
||||
// Bit[6:5] = 0b00, NORMAL mode and Bit[3] = 0b1, CALIBRATED
|
||||
if (!this->setup_check((data & 0x68) == 0x08, LOG_STR("Initialization failed")))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void AHT10Component::restart_read_() {
|
||||
|
||||
@@ -373,9 +373,7 @@ void AirtonSerialClimate::send_ab_() {
|
||||
}
|
||||
|
||||
void AirtonSerialClimate::write_frame_(uint8_t *frame, size_t len) {
|
||||
const uint16_t crc = crc16(frame, len - 2);
|
||||
frame[len - 2] = static_cast<uint8_t>(crc >> 8);
|
||||
frame[len - 1] = static_cast<uint8_t>(crc);
|
||||
put_be16(frame + len - 2, crc16(frame, len - 2));
|
||||
this->write_array(frame, len);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,10 +72,8 @@ bool AM2315C::convert_(uint8_t *data, float &humidity, float &temperature) {
|
||||
void AM2315C::setup() {
|
||||
// get status
|
||||
uint8_t status = 0;
|
||||
if (this->read(&status, 1) != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read(&status, 1) == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
|
||||
// reset registers if required, according to the datasheet
|
||||
// this can be required after power on, although this was
|
||||
|
||||
@@ -34,10 +34,8 @@ void AM2320Component::setup() {
|
||||
uint8_t data[8];
|
||||
data[0] = 0;
|
||||
data[1] = 4;
|
||||
if (!this->read_data_(data)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_data_(data)))
|
||||
return;
|
||||
}
|
||||
}
|
||||
void AM2320Component::dump_config() {
|
||||
ESP_LOGD(TAG, "AM2320:");
|
||||
|
||||
@@ -26,8 +26,7 @@ Am43Packet Am43Encoder::get_position_request() {
|
||||
|
||||
Am43Packet Am43Encoder::get_send_pin_request(uint16_t pin) {
|
||||
uint8_t data[2];
|
||||
data[0] = (pin & 0xFF00) >> 8;
|
||||
data[1] = pin & 0xFF;
|
||||
put_be16(data, pin);
|
||||
return encode(CMD_SEND_PIN, data, 2);
|
||||
}
|
||||
|
||||
|
||||
@@ -304,9 +304,7 @@ void APC1Component::send_command_(APC1Command cmd, uint16_t data) {
|
||||
0,
|
||||
0,
|
||||
};
|
||||
uint16_t checksum = sum16_bytes(buf.data(), 5);
|
||||
buf[5] = static_cast<uint8_t>((checksum >> 8) & 0xFF);
|
||||
buf[6] = static_cast<uint8_t>(checksum & 0xFF);
|
||||
put_be16(buf.data() + 5, sum16_bytes(buf.data(), 5));
|
||||
this->write_array(buf);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,10 +60,8 @@ static constexpr i2c::I2CRegValue APDS9960_GESTURE_OFFSETS[] PROGMEM = {
|
||||
|
||||
void APDS9960::setup() {
|
||||
uint8_t id;
|
||||
if (!this->read_byte(0x92, &id)) { // ID register
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_byte(0x92, &id))) // ID register
|
||||
return;
|
||||
}
|
||||
|
||||
if (id != 0xAB && id != 0x9C && id != 0xA8 && id != 0x9E) { // APDS9960 all should have one of these IDs
|
||||
this->mark_failed(LOG_STR("APDS9960 has invalid id"));
|
||||
|
||||
@@ -22,10 +22,8 @@ static const uint8_t REGISTER_AGC = 0x1A; // 8 bytes / R
|
||||
static const uint8_t REGISTER_MAGNITUDE = 0x1B; // 16 bytes / R
|
||||
|
||||
void AS5600Component::setup() {
|
||||
if (!this->read_byte(REGISTER_STATUS).has_value()) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_byte(REGISTER_STATUS).has_value()))
|
||||
return;
|
||||
}
|
||||
|
||||
// configuration direction pin, if given
|
||||
// the dir pin on the chip should be low for clockwise
|
||||
@@ -53,10 +51,8 @@ void AS5600Component::setup() {
|
||||
// clang-format on
|
||||
|
||||
// write config to config register
|
||||
if (!this->write_byte_16(REGISTER_CONF, config)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte_16(REGISTER_CONF, config)))
|
||||
return;
|
||||
}
|
||||
|
||||
// configure the start position
|
||||
this->write_byte_16(REGISTER_ZPOS, this->start_position_);
|
||||
|
||||
@@ -315,10 +315,8 @@ void AS734XComponent::setup() {
|
||||
this->write_byte(AS7343_CHAIN_CMD, 0x46 + (i / len) * 0x10);
|
||||
}
|
||||
}
|
||||
if (!ok) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(ok))
|
||||
return;
|
||||
}
|
||||
this->disable_loop();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,10 +71,8 @@ void BH1745Component::setup() {
|
||||
this->mark_failed(LOG_STR("Wrong part ID"));
|
||||
return;
|
||||
}
|
||||
if (!this->write_byte(REG_SYSTEM_CONTROL, SYSTEM_CONTROL_SW_RESET)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(REG_SYSTEM_CONTROL, SYSTEM_CONTROL_SW_RESET)))
|
||||
return;
|
||||
}
|
||||
|
||||
// Light lost behind glass is scaled back up, as the other light sensors do
|
||||
this->lux_scale_ = 160.0f * this->glass_attenuation_factor_ /
|
||||
@@ -85,10 +83,8 @@ void BH1745Component::setup() {
|
||||
// High threshold 0 and low threshold 0xFFFF (low byte first) make the interrupt condition always
|
||||
// true, so the INT pin simply follows the enable bit, which drives the breakout's LEDs.
|
||||
static constexpr uint8_t THRESHOLDS[4] = {0x00, 0x00, 0xFF, 0xFF};
|
||||
if (!this->write_bytes(REG_TH_LSB, THRESHOLDS, sizeof(THRESHOLDS))) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_bytes(REG_TH_LSB, THRESHOLDS, sizeof(THRESHOLDS))))
|
||||
return;
|
||||
}
|
||||
}
|
||||
// RGBC_EN makes the chip measure continuously; update() reads the latest result.
|
||||
if (!this->write_byte(REG_MODE_CONTROL1, static_cast<uint8_t>(this->measurement_time_)) ||
|
||||
|
||||
@@ -64,10 +64,8 @@ MTreg:
|
||||
|
||||
void BH1750Sensor::setup() {
|
||||
uint8_t turn_on = BH1750_COMMAND_POWER_ON;
|
||||
if (this->write(&turn_on, 1) != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write(&turn_on, 1) == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
this->state_ = IDLE;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,8 @@ void BH1900NUXSensor::setup() {
|
||||
// Initialize I2C device
|
||||
i2c::ErrorCode result_code =
|
||||
this->write_register(SOFT_RESET_REG, &SOFT_RESET_PAYLOAD, 1); // Software Reset to check communication
|
||||
if (result_code != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(result_code == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void BH1900NUXSensor::update() {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "bl0942.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include <cinttypes>
|
||||
|
||||
@@ -89,26 +90,19 @@ void BL0942::write_reg_(uint8_t reg, uint32_t val) {
|
||||
pkt[2] = (val & 0xff);
|
||||
pkt[3] = (val >> 8) & 0xff;
|
||||
pkt[4] = (val >> 16) & 0xff;
|
||||
pkt[5] = (pkt[0] + pkt[1] + pkt[2] + pkt[3] + pkt[4]) ^ 0xff;
|
||||
pkt[5] = sum_bytes(pkt, 5) ^ 0xFF;
|
||||
this->write_array(pkt, 6);
|
||||
delay(1);
|
||||
}
|
||||
|
||||
int BL0942::read_reg_(uint8_t reg) {
|
||||
union {
|
||||
uint8_t b[4];
|
||||
uint32_le_t le32;
|
||||
} resp;
|
||||
uint8_t resp[4];
|
||||
|
||||
this->write_byte(BL0942_READ_COMMAND | this->address_);
|
||||
this->write_byte(reg);
|
||||
this->flush();
|
||||
if (this->read_array(resp.b, 4) &&
|
||||
resp.b[3] ==
|
||||
(uint8_t) ((BL0942_READ_COMMAND + this->address_ + reg + resp.b[0] + resp.b[1] + resp.b[2]) ^ 0xff)) {
|
||||
resp.b[3] = 0;
|
||||
return resp.le32;
|
||||
}
|
||||
if (this->read_array(resp, 4) && resp[3] == (sum_bytes(resp, 3, BL0942_READ_COMMAND + this->address_ + reg) ^ 0xFF))
|
||||
return encode_uint24(resp[2], resp[1], resp[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,8 @@ static constexpr uint8_t CLOCK_1_60_HZ = 0x83;
|
||||
static constexpr uint32_t MAX_TIMER_DURATION_S = 255 * 60;
|
||||
|
||||
void BM8563::setup() {
|
||||
if (!this->write_byte_16(CONTROL_STATUS_1_REG, 0)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte_16(CONTROL_STATUS_1_REG, 0)))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void BM8563::update() { this->read_time(); }
|
||||
|
||||
@@ -75,29 +75,21 @@ void BME280Component::setup() {
|
||||
this->reset_to_construction_state();
|
||||
}
|
||||
|
||||
if (!this->read_byte(BME280_REGISTER_CHIPID, &chip_id)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_byte(BME280_REGISTER_CHIPID, &chip_id)))
|
||||
return;
|
||||
}
|
||||
if (chip_id != 0x60) {
|
||||
this->mark_failed(LOG_STR("Wrong chip ID or no response"));
|
||||
if (!this->setup_check(chip_id == 0x60, LOG_STR("Wrong chip ID or no response")))
|
||||
return;
|
||||
}
|
||||
|
||||
// Send a soft reset.
|
||||
if (!this->write_byte(BME280_REGISTER_RESET, BME280_SOFT_RESET)) {
|
||||
this->mark_failed(LOG_STR("Reset failed"));
|
||||
if (!this->setup_check(this->write_byte(BME280_REGISTER_RESET, BME280_SOFT_RESET), LOG_STR("Reset failed")))
|
||||
return;
|
||||
}
|
||||
// Wait until the NVM data has finished loading.
|
||||
uint8_t status;
|
||||
uint8_t retry = 5;
|
||||
do { // NOLINT
|
||||
delay(2);
|
||||
if (!this->read_byte(BME280_REGISTER_STATUS, &status)) {
|
||||
this->mark_failed(LOG_STR("Error reading status register"));
|
||||
if (!this->setup_check(this->read_byte(BME280_REGISTER_STATUS, &status), LOG_STR("Error reading status register")))
|
||||
return;
|
||||
}
|
||||
} while ((status & BME280_STATUS_IM_UPDATE) && (--retry));
|
||||
if (status & BME280_STATUS_IM_UPDATE) {
|
||||
this->mark_failed(LOG_STR("Timeout loading NVM"));
|
||||
@@ -129,29 +121,23 @@ void BME280Component::setup() {
|
||||
this->calibration_.h6 = read_u8_(BME280_REGISTER_DIG_H6);
|
||||
|
||||
uint8_t humid_control_val = 0;
|
||||
if (!this->read_byte(BME280_REGISTER_CONTROLHUMID, &humid_control_val)) {
|
||||
this->mark_failed(LOG_STR("Read humidity control"));
|
||||
if (!this->setup_check(this->read_byte(BME280_REGISTER_CONTROLHUMID, &humid_control_val),
|
||||
LOG_STR("Read humidity control")))
|
||||
return;
|
||||
}
|
||||
humid_control_val &= ~0b00000111;
|
||||
humid_control_val |= this->humidity_oversampling_ & 0b111;
|
||||
if (!this->write_byte(BME280_REGISTER_CONTROLHUMID, humid_control_val)) {
|
||||
this->mark_failed(LOG_STR("Write humidity control"));
|
||||
if (!this->setup_check(this->write_byte(BME280_REGISTER_CONTROLHUMID, humid_control_val),
|
||||
LOG_STR("Write humidity control")))
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t config_register = 0;
|
||||
if (!this->read_byte(BME280_REGISTER_CONFIG, &config_register)) {
|
||||
this->mark_failed(LOG_STR("Read config"));
|
||||
if (!this->setup_check(this->read_byte(BME280_REGISTER_CONFIG, &config_register), LOG_STR("Read config")))
|
||||
return;
|
||||
}
|
||||
config_register &= ~0b11111100;
|
||||
config_register |= 0b101 << 5; // 1000 ms standby time
|
||||
config_register |= (this->iir_filter_ & 0b111) << 2;
|
||||
if (!this->write_byte(BME280_REGISTER_CONFIG, config_register)) {
|
||||
this->mark_failed(LOG_STR("Write config"));
|
||||
if (!this->setup_check(this->write_byte(BME280_REGISTER_CONFIG, config_register), LOG_STR("Write config")))
|
||||
return;
|
||||
}
|
||||
}
|
||||
void BME280Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "BME280:");
|
||||
|
||||
@@ -82,59 +82,44 @@ void BMI270Component::setup() {
|
||||
return;
|
||||
|
||||
// 2. Soft-reset via CMD register (0x7E = 0xB6)
|
||||
if (!this->write_byte(BMI270_REG_CMD, BMI270_CMD_SOFT_RESET)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(BMI270_REG_CMD, BMI270_CMD_SOFT_RESET)))
|
||||
return;
|
||||
}
|
||||
delay(20);
|
||||
|
||||
// 4. Upload the configuration blob
|
||||
if (!load_config_file_()) {
|
||||
this->mark_failed(LOG_STR("Config file upload failed"));
|
||||
if (!this->setup_check(load_config_file_(), LOG_STR("Config file upload failed")))
|
||||
return;
|
||||
}
|
||||
ESP_LOGD(TAG, "Config blob uploaded ✓");
|
||||
|
||||
// 5. Configure accelerometer
|
||||
// ACC_CONF: ODR | BWP(0x2 = normal avg4) | perf_mode(1)
|
||||
uint8_t acc_conf =
|
||||
(uint8_t) (accel_odr_) | (BMI270_CONF_BWP_NORMAL << BMI270_CONF_BWP_SHIFT) | BMI270_ACC_CONF_PERF_MODE;
|
||||
if (!this->write_byte(BMI270_REG_ACC_CONF, acc_conf)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(BMI270_REG_ACC_CONF, acc_conf)))
|
||||
return;
|
||||
}
|
||||
if (!this->write_byte(BMI270_REG_ACC_RANGE, (uint8_t) accel_range_)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(BMI270_REG_ACC_RANGE, (uint8_t) accel_range_)))
|
||||
return;
|
||||
}
|
||||
|
||||
// 6. Configure gyroscope
|
||||
// GYR_CONF: ODR | BWP(0x2 = normal) | noise_perf(1) | filter_perf(1)
|
||||
uint8_t gyr_conf = (uint8_t) (gyro_odr_) | (BMI270_CONF_BWP_NORMAL << BMI270_CONF_BWP_SHIFT) |
|
||||
BMI270_GYR_CONF_NOISE_PERF | BMI270_GYR_CONF_FILTER_PERF;
|
||||
if (!this->write_byte(BMI270_REG_GYR_CONF, gyr_conf)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(BMI270_REG_GYR_CONF, gyr_conf)))
|
||||
return;
|
||||
}
|
||||
if (!this->write_byte(BMI270_REG_GYR_RANGE, (uint8_t) gyro_range_)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(BMI270_REG_GYR_RANGE, (uint8_t) gyro_range_)))
|
||||
return;
|
||||
}
|
||||
|
||||
// 7. Enable accelerometer, gyroscope, and temperature sensor
|
||||
// PWR_CTRL bits: temp_en[3] | gyr_en[2] | acc_en[1]
|
||||
if (!this->write_byte(BMI270_REG_PWR_CTRL, BMI270_PWR_CTRL_IMU)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(BMI270_REG_PWR_CTRL, BMI270_PWR_CTRL_IMU)))
|
||||
return;
|
||||
}
|
||||
delay(5);
|
||||
|
||||
// 8. Re-enable advanced power save (optional; keeps current low between reads)
|
||||
// Disabled here for simplicity – leave in performance mode
|
||||
if (!this->write_byte(BMI270_REG_PWR_CONF, BMI270_PWR_CONF_FIFO_SELF_WAKEUP)) { // bit1 = fifo_self_wakeup
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
// bit1 = fifo_self_wakeup
|
||||
if (!this->setup_check(this->write_byte(BMI270_REG_PWR_CONF, BMI270_PWR_CONF_FIFO_SELF_WAKEUP)))
|
||||
return;
|
||||
}
|
||||
|
||||
// 9. Optionally bring up whatever is wired to the aux interface.
|
||||
// This is entirely additive: it is off by default, and failure only disables
|
||||
|
||||
@@ -24,10 +24,8 @@ void BMP085Component::update() {
|
||||
}
|
||||
void BMP085Component::setup() {
|
||||
uint8_t data[22];
|
||||
if (!this->read_bytes(BMP085_REGISTER_AC1_H, data, 22)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_bytes(BMP085_REGISTER_AC1_H, data, 22)))
|
||||
return;
|
||||
}
|
||||
|
||||
// Load calibration
|
||||
this->calibration_.ac1 = encode_uint16(data[0], data[1]);
|
||||
|
||||
@@ -40,33 +40,24 @@ void BMP280Component::setup() {
|
||||
|
||||
// Read the chip id twice, to work around a bug where the first read is 0.
|
||||
// https://community.st.com/t5/stm32-mcus-products/issue-with-reading-bmp280-chip-id-using-spi/td-p/691855
|
||||
if (!this->bmp_read_byte(0xD0, &chip_id)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->bmp_read_byte(0xD0, &chip_id)))
|
||||
return;
|
||||
}
|
||||
if (!this->bmp_read_byte(0xD0, &chip_id)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->bmp_read_byte(0xD0, &chip_id)))
|
||||
return;
|
||||
}
|
||||
if (chip_id != 0x58) {
|
||||
this->mark_failed(LOG_STR("Wrong chip ID or no response"));
|
||||
if (!this->setup_check(chip_id == 0x58, LOG_STR("Wrong chip ID or no response")))
|
||||
return;
|
||||
}
|
||||
|
||||
// Send a soft reset.
|
||||
if (!this->bmp_write_byte(BMP280_REGISTER_RESET, BMP280_SOFT_RESET)) {
|
||||
this->mark_failed(LOG_STR("Reset failed"));
|
||||
if (!this->setup_check(this->bmp_write_byte(BMP280_REGISTER_RESET, BMP280_SOFT_RESET), LOG_STR("Reset failed")))
|
||||
return;
|
||||
}
|
||||
// Wait until the NVM data has finished loading.
|
||||
uint8_t status;
|
||||
uint8_t retry = 5;
|
||||
do {
|
||||
delay(2);
|
||||
if (!this->bmp_read_byte(BMP280_REGISTER_STATUS, &status)) {
|
||||
this->mark_failed(LOG_STR("Error reading status register"));
|
||||
if (!this->setup_check(this->bmp_read_byte(BMP280_REGISTER_STATUS, &status),
|
||||
LOG_STR("Error reading status register")))
|
||||
return;
|
||||
}
|
||||
} while ((status & BMP280_STATUS_IM_UPDATE) && (--retry));
|
||||
if (status & BMP280_STATUS_IM_UPDATE) {
|
||||
this->mark_failed(LOG_STR("Timeout loading NVM"));
|
||||
@@ -89,17 +80,13 @@ void BMP280Component::setup() {
|
||||
this->calibration_.p9 = this->read_s16_le_(0x9E);
|
||||
|
||||
uint8_t config_register = 0;
|
||||
if (!this->bmp_read_byte(BMP280_REGISTER_CONFIG, &config_register)) {
|
||||
this->mark_failed(LOG_STR("Read config"));
|
||||
if (!this->setup_check(this->bmp_read_byte(BMP280_REGISTER_CONFIG, &config_register), LOG_STR("Read config")))
|
||||
return;
|
||||
}
|
||||
config_register &= ~0b11111100;
|
||||
config_register |= 0b000 << 5; // 0.5 ms standby time
|
||||
config_register |= (this->iir_filter_ & 0b111) << 2;
|
||||
if (!this->bmp_write_byte(BMP280_REGISTER_CONFIG, config_register)) {
|
||||
this->mark_failed(LOG_STR("Write config"));
|
||||
if (!this->setup_check(this->bmp_write_byte(BMP280_REGISTER_CONFIG, config_register), LOG_STR("Write config")))
|
||||
return;
|
||||
}
|
||||
}
|
||||
void BMP280Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "BMP280:");
|
||||
|
||||
@@ -50,10 +50,8 @@ void BMP3XXComponent::setup() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!read_byte(BMP388_CHIP_ID, &this->chip_id_.reg)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(read_byte(BMP388_CHIP_ID, &this->chip_id_.reg)))
|
||||
return;
|
||||
}
|
||||
ESP_LOGCONFIG(TAG, "Chip %s Id 0x%X", LOG_STR_ARG(chip_type_to_str(this->chip_id_.reg)), this->chip_id_.reg);
|
||||
|
||||
if (chip_id_.reg != BMP388_ID && chip_id_.reg != BMP390_ID) {
|
||||
@@ -63,10 +61,10 @@ void BMP3XXComponent::setup() {
|
||||
// set sensor in sleep mode
|
||||
stop_conversion();
|
||||
// Read the calibration parameters into the params structure
|
||||
if (!read_bytes(BMP388_TRIM_PARAMS, (uint8_t *) &compensation_params_, sizeof(compensation_params_))) {
|
||||
this->mark_failed(LOG_STR("Can't read calibration data"));
|
||||
if (!this->setup_check(
|
||||
read_bytes(BMP388_TRIM_PARAMS, (uint8_t *) &compensation_params_, sizeof(compensation_params_)),
|
||||
LOG_STR("Can't read calibration data")))
|
||||
return;
|
||||
}
|
||||
compensation_float_params_.param_T1 =
|
||||
(float) compensation_params_.param_T1 / powf(2.0f, -8.0f); // Calculate the floating point trim parameters
|
||||
compensation_float_params_.param_T2 = (float) compensation_params_.param_T2 / powf(2.0f, 30.0f);
|
||||
|
||||
@@ -27,16 +27,14 @@ static constexpr uint16_t TIME_TO_EMPTY_NOT_APPLICABLE = 0xFFFF;
|
||||
|
||||
void BQ27220Component::setup() {
|
||||
const uint8_t device_number_cmd[2] = {0x01, 0x00}; // DEVICE_NUMBER subcommand, little-endian
|
||||
if (this->write_register(REG_CONTROL, device_number_cmd, 2) != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR("Failed to communicate with BQ27220"));
|
||||
if (!this->setup_check(this->write_register(REG_CONTROL, device_number_cmd, 2) == i2c::ERROR_OK,
|
||||
LOG_STR("Failed to communicate with BQ27220")))
|
||||
return;
|
||||
}
|
||||
delay(2); // SLUUBD4A §5.3: the subcommand result needs a moment before it can be read
|
||||
uint16_t device_number = 0;
|
||||
if (!this->read_byte_16_le(REG_MAC_DATA, &device_number)) {
|
||||
this->mark_failed(LOG_STR("Failed to read device number from BQ27220"));
|
||||
if (!this->setup_check(this->read_byte_16_le(REG_MAC_DATA, &device_number),
|
||||
LOG_STR("Failed to read device number from BQ27220")))
|
||||
return;
|
||||
}
|
||||
if (device_number != DEVICE_NUMBER) {
|
||||
ESP_LOGE(TAG, "Unexpected device number 0x%04X (expected 0x%04X)", device_number, DEVICE_NUMBER);
|
||||
this->mark_failed(LOG_STR("Unexpected device number"));
|
||||
|
||||
@@ -24,10 +24,8 @@ void CH423Component::setup() {
|
||||
if (success && !(this->sys_params_ & CH423_SYS_IO_OE)) {
|
||||
success = this->read_inputs_();
|
||||
}
|
||||
if (!success) {
|
||||
this->mark_failed(LOG_STR("CH423 not detected"));
|
||||
if (!this->setup_check(success, LOG_STR("CH423 not detected")))
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGCONFIG(TAG, "Initialization complete. Warning: %d, Error: %d", this->status_has_warning(),
|
||||
this->status_has_error());
|
||||
|
||||
@@ -23,10 +23,9 @@ uint8_t cm1106_checksum(const uint8_t *response, size_t len) {
|
||||
|
||||
void CM1106Component::setup() {
|
||||
uint8_t response[8] = {0};
|
||||
if (!this->cm1106_write_command_(C_M1106_CMD_GET_CO2, sizeof(C_M1106_CMD_GET_CO2), response, sizeof(response))) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(
|
||||
this->cm1106_write_command_(C_M1106_CMD_GET_CO2, sizeof(C_M1106_CMD_GET_CO2), response, sizeof(response))))
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->abc_boot_logic_ != CM1106_ABC_NONE) {
|
||||
this->abc_set_(this->abc_boot_logic_ == CM1106_ABC_ENABLED);
|
||||
@@ -76,8 +75,7 @@ void CM1106Component::update() {
|
||||
void CM1106Component::calibrate_zero(uint16_t ppm) {
|
||||
uint8_t cmd[6];
|
||||
memcpy(cmd, C_M1106_CMD_SET_CO2_CALIB, sizeof(cmd));
|
||||
cmd[3] = ppm >> 8;
|
||||
cmd[4] = ppm & 0xFF;
|
||||
put_be16(cmd + 3, ppm);
|
||||
if (this->send_command_expect_ack_(cmd, sizeof(cmd), C_M1106_CMD_SET_CO2_CALIB_RESPONSE)) {
|
||||
ESP_LOGD(TAG, "Successfully calibrated sensor to %uppm", ppm);
|
||||
}
|
||||
@@ -89,8 +87,7 @@ void CM1106Component::abc_set_(bool enabled) {
|
||||
memcpy(cmd, C_M1106_CMD_SET_ABC_STATUS, sizeof(cmd));
|
||||
cmd[4] = enabled ? CM1106_ABC_FLAG_ENABLE : CM1106_ABC_FLAG_DISABLE;
|
||||
cmd[5] = this->abc_cycle_;
|
||||
cmd[6] = this->abc_baseline_ >> 8;
|
||||
cmd[7] = this->abc_baseline_ & 0xFF;
|
||||
put_be16(cmd + 6, this->abc_baseline_);
|
||||
if (this->send_command_expect_ack_(cmd, sizeof(cmd), C_M1106_CMD_SET_ABC_STATUS_RESPONSE)) {
|
||||
ESP_LOGD(TAG, "Successfully set ABC status");
|
||||
}
|
||||
|
||||
@@ -108,7 +108,9 @@ CONF_VOC_INDEX = "voc_index"
|
||||
CONF_VOLUME_INCREMENT = "volume_increment"
|
||||
CONF_VOLUME_INITIAL = "volume_initial"
|
||||
CONF_VOLUME_MAX = "volume_max"
|
||||
CONF_VOLUME_MAX_DB = "volume_max_db"
|
||||
CONF_VOLUME_MIN = "volume_min"
|
||||
CONF_VOLUME_MIN_DB = "volume_min_db"
|
||||
CONF_WINDOW = "window"
|
||||
|
||||
ICON_CURRENT_DC = "mdi:current-dc"
|
||||
|
||||
@@ -63,11 +63,9 @@ void CST226Touchscreen::continue_setup_() {
|
||||
this->attach_interrupt_(this->interrupt_pin_, gpio::INTERRUPT_FALLING_EDGE);
|
||||
}
|
||||
buffer[0] = 0xD1;
|
||||
if (this->write_register16(0xD1, buffer, 1) != i2c::ERROR_OK) {
|
||||
ESP_LOGE(TAG, "Write byte to 0xD1 failed");
|
||||
this->mark_failed();
|
||||
if (!this->setup_check(this->write_register16(0xD1, buffer, 1) == i2c::ERROR_OK,
|
||||
LOG_STR("Write byte to 0xD1 failed")))
|
||||
return;
|
||||
}
|
||||
delay(10);
|
||||
if (this->read16_(0xD204, buffer, 4)) {
|
||||
uint16_t chip_id = buffer[2] + (buffer[3] << 8);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "d01.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
// uart specification for d01 sensor from https://manuals.plus/ae/1005006417362019:
|
||||
@@ -31,7 +32,7 @@ void D01SensorComponent::loop() {
|
||||
continue;
|
||||
}
|
||||
this->read_array(buf, 4);
|
||||
uint8_t sum = (buf[0] + buf[1] + buf[2]) & 0x7F;
|
||||
uint8_t sum = sum_bytes(buf, 3) & 0x7F;
|
||||
if (sum != buf[3]) {
|
||||
ESP_LOGW(TAG, "checksum mismatch");
|
||||
continue;
|
||||
|
||||
@@ -37,9 +37,7 @@ void DaikinClimate::transmit_state() {
|
||||
this->set_presets_(remote_state);
|
||||
remote_state[21] = this->operation_mode_();
|
||||
remote_state[22] = this->temperature_();
|
||||
uint16_t fan_speed = this->fan_speed_();
|
||||
remote_state[24] = fan_speed >> 8;
|
||||
remote_state[25] = fan_speed & 0xff;
|
||||
put_be16(remote_state + 24, this->fan_speed_());
|
||||
|
||||
remote_state[7] = sum_bytes(remote_state, 7);
|
||||
remote_state[34] = sum_bytes(remote_state + 16, 18);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "esphome/components/remote_base/remote_base.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
namespace esphome::daikin_arc {
|
||||
|
||||
@@ -89,9 +90,7 @@ void DaikinArcClimate::transmit_state() {
|
||||
remote_header[9] |= 0x10;
|
||||
this->last_humidity_ = remote_state[7];
|
||||
}
|
||||
uint16_t fan_speed = this->fan_speed_();
|
||||
remote_state[8] = fan_speed >> 8;
|
||||
remote_state[9] = fan_speed & 0xff;
|
||||
put_be16(remote_state + 8, this->fan_speed_());
|
||||
|
||||
// Calculate checksum
|
||||
for (size_t i = 0; i < sizeof(remote_header) - 1; i++) {
|
||||
|
||||
@@ -117,8 +117,7 @@ void DalyBmsComponent::request_data_(uint8_t data_id) {
|
||||
request_message[10] = 0x00; // |
|
||||
request_message[11] = 0x00; // Empty Data
|
||||
|
||||
request_message[12] = (uint8_t) (request_message[0] + request_message[1] + request_message[2] +
|
||||
request_message[3]); // Checksum (Lower byte of the other bytes sum)
|
||||
request_message[12] = sum_bytes(request_message, 4); // Checksum
|
||||
|
||||
ESP_LOGV(TAG, "Request datapacket Nr %x", data_id);
|
||||
this->write_array(request_message, sizeof(request_message));
|
||||
|
||||
@@ -9,9 +9,12 @@ from esphome.components.esp32 import (
|
||||
VARIANT_ESP32C6,
|
||||
VARIANT_ESP32C61,
|
||||
VARIANT_ESP32H2,
|
||||
VARIANT_ESP32H4,
|
||||
VARIANT_ESP32H21,
|
||||
VARIANT_ESP32P4,
|
||||
VARIANT_ESP32S2,
|
||||
VARIANT_ESP32S3,
|
||||
VARIANT_ESP32S31,
|
||||
get_esp32_variant,
|
||||
)
|
||||
from esphome.components.zephyr import zephyr_add_prj_conf
|
||||
@@ -121,6 +124,35 @@ WAKEUP_PINS = {
|
||||
}
|
||||
|
||||
|
||||
# Variants where the C++ code enables ext0 or GPIO wakeup for 'wakeup_pin'
|
||||
WAKEUP_PIN_VARIANTS = [
|
||||
VARIANT_ESP32,
|
||||
VARIANT_ESP32C2,
|
||||
VARIANT_ESP32C3,
|
||||
VARIANT_ESP32C5,
|
||||
VARIANT_ESP32C6,
|
||||
VARIANT_ESP32C61,
|
||||
VARIANT_ESP32P4,
|
||||
VARIANT_ESP32S2,
|
||||
VARIANT_ESP32S3,
|
||||
]
|
||||
|
||||
# Variants whose soc_caps.h defines SOC_PM_SUPPORT_EXT1_WAKEUP
|
||||
EXT1_WAKEUP_VARIANTS = [
|
||||
VARIANT_ESP32,
|
||||
VARIANT_ESP32C5,
|
||||
VARIANT_ESP32C6,
|
||||
VARIANT_ESP32C61,
|
||||
VARIANT_ESP32H2,
|
||||
VARIANT_ESP32H4,
|
||||
VARIANT_ESP32H21,
|
||||
VARIANT_ESP32P4,
|
||||
VARIANT_ESP32S2,
|
||||
VARIANT_ESP32S3,
|
||||
VARIANT_ESP32S31,
|
||||
]
|
||||
|
||||
|
||||
def validate_pin_number_esp32(value: ConfigType) -> ConfigType:
|
||||
valid_pins = WAKEUP_PINS.get(get_esp32_variant(), WAKEUP_PINS[VARIANT_ESP32])
|
||||
if value[CONF_NUMBER] not in valid_pins:
|
||||
@@ -146,6 +178,11 @@ def validate_wakeup_pin(
|
||||
if not processed_pins:
|
||||
raise cv.Invalid("'wakeup_pin' needs at least one entry")
|
||||
|
||||
if CORE.is_esp32:
|
||||
esp32.only_on_variant(
|
||||
supported=WAKEUP_PIN_VARIANTS, msg_prefix="Wakeup from 'wakeup_pin'"
|
||||
)(value)
|
||||
|
||||
for i, pin_config in enumerate(processed_pins):
|
||||
# now validate each item
|
||||
validated_pin = WAKEUP_PIN_SCHEMA(pin_config)
|
||||
@@ -313,7 +350,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
cv.Optional(CONF_ESP32_EXT1_WAKEUP): cv.All(
|
||||
cv.only_on_esp32,
|
||||
esp32.only_on_variant(
|
||||
unsupported=[VARIANT_ESP32C2, VARIANT_ESP32C3],
|
||||
supported=EXT1_WAKEUP_VARIANTS,
|
||||
msg_prefix="Wakeup from ext1",
|
||||
),
|
||||
cv.Schema(
|
||||
@@ -337,13 +374,11 @@ CONFIG_SCHEMA = cv.All(
|
||||
cv.Optional(CONF_TOUCH_WAKEUP): cv.All(
|
||||
cv.only_on_esp32,
|
||||
esp32.only_on_variant(
|
||||
unsupported=[
|
||||
VARIANT_ESP32C2,
|
||||
VARIANT_ESP32C3,
|
||||
VARIANT_ESP32C5,
|
||||
VARIANT_ESP32C6,
|
||||
VARIANT_ESP32C61,
|
||||
VARIANT_ESP32H2,
|
||||
supported=[
|
||||
VARIANT_ESP32,
|
||||
VARIANT_ESP32P4,
|
||||
VARIANT_ESP32S2,
|
||||
VARIANT_ESP32S3,
|
||||
],
|
||||
msg_prefix="Wakeup from touch",
|
||||
),
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "esphome/core/helpers.h"
|
||||
#ifdef USE_ESP32
|
||||
#include <esp_sleep.h>
|
||||
#include "soc/soc_caps.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_TIME
|
||||
@@ -42,7 +43,7 @@ struct WakeUpPinItem {
|
||||
#endif // USE_BK72XX
|
||||
|
||||
#ifdef USE_ESP32
|
||||
#if defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32C2) && !defined(USE_ESP32_VARIANT_ESP32C3)
|
||||
#if SOC_PM_SUPPORT_EXT1_WAKEUP
|
||||
struct Ext1Wakeup {
|
||||
uint64_t mask;
|
||||
esp_sleep_ext1_wakeup_mode_t wakeup_mode;
|
||||
@@ -102,7 +103,7 @@ class WakeTrigger : public Trigger<WakeupCause>, public Component {
|
||||
float get_setup_priority() const override { return ON_WAKE_TRIGGER_SETUP_PRIORITY; }
|
||||
};
|
||||
|
||||
#if defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32C2) && !defined(USE_ESP32_VARIANT_ESP32C3)
|
||||
#if defined(USE_ESP32) && SOC_PM_SUPPORT_EXT1_WAKEUP
|
||||
/// Fires once on boot when the device was woken from deep sleep by the given ext1 pin.
|
||||
class Ext1WakeTrigger : public Trigger<>, public Component {
|
||||
public:
|
||||
@@ -151,13 +152,11 @@ class DeepSleepComponent final : public Component {
|
||||
#endif // USE_BK72XX
|
||||
|
||||
#if defined(USE_ESP32)
|
||||
#if !defined(USE_ESP32_VARIANT_ESP32C2) && !defined(USE_ESP32_VARIANT_ESP32C3)
|
||||
#if SOC_PM_SUPPORT_EXT1_WAKEUP
|
||||
void set_ext1_wakeup(Ext1Wakeup ext1_wakeup);
|
||||
#endif
|
||||
|
||||
#if !defined(USE_ESP32_VARIANT_ESP32C2) && !defined(USE_ESP32_VARIANT_ESP32C3) && \
|
||||
!defined(USE_ESP32_VARIANT_ESP32C5) && !defined(USE_ESP32_VARIANT_ESP32C6) && \
|
||||
!defined(USE_ESP32_VARIANT_ESP32C61) && !defined(USE_ESP32_VARIANT_ESP32H2)
|
||||
#if SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP
|
||||
void set_touch_wakeup(bool touch_wakeup) { this->touch_wakeup_ = touch_wakeup; }
|
||||
#endif
|
||||
|
||||
@@ -211,7 +210,7 @@ class DeepSleepComponent final : public Component {
|
||||
InternalGPIOPin *wakeup_pin_{nullptr};
|
||||
WakeupPinMode wakeup_pin_mode_{WAKEUP_PIN_MODE_IGNORE};
|
||||
|
||||
#if !defined(USE_ESP32_VARIANT_ESP32C2) && !defined(USE_ESP32_VARIANT_ESP32C3)
|
||||
#if SOC_PM_SUPPORT_EXT1_WAKEUP
|
||||
optional<Ext1Wakeup> ext1_wakeup_;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ namespace esphome::deep_sleep {
|
||||
// | ESP32-C6 | | ✓ | | ✓ |
|
||||
// | ESP32-C61 | | ✓ | | ✓ |
|
||||
// | ESP32-H2 | | ✓ | | |
|
||||
// | ESP32-P4 | | ✓ | ✓ | ✓ |
|
||||
//
|
||||
// Each wakeup source below is gated on the SOC capability macro for it, so a
|
||||
// new variant gets the sources its hardware has.
|
||||
//
|
||||
// Notes:
|
||||
// - (✓) = Supported by hardware but not yet implemented in ESPHome
|
||||
@@ -68,7 +72,7 @@ void DeepSleepComponent::set_wakeup_pin_mode(WakeupPinMode wakeup_pin_mode) {
|
||||
this->wakeup_pin_mode_ = wakeup_pin_mode;
|
||||
}
|
||||
|
||||
#if !defined(USE_ESP32_VARIANT_ESP32C2) && !defined(USE_ESP32_VARIANT_ESP32C3)
|
||||
#if SOC_PM_SUPPORT_EXT1_WAKEUP
|
||||
void DeepSleepComponent::set_ext1_wakeup(Ext1Wakeup ext1_wakeup) { this->ext1_wakeup_ = ext1_wakeup; }
|
||||
#endif
|
||||
|
||||
@@ -119,10 +123,8 @@ void DeepSleepComponent::deep_sleep_() {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Single pin wakeup (ext0) - ESP32, S2, S3 only
|
||||
#if !defined(USE_ESP32_VARIANT_ESP32C2) && !defined(USE_ESP32_VARIANT_ESP32C3) && \
|
||||
!defined(USE_ESP32_VARIANT_ESP32C5) && !defined(USE_ESP32_VARIANT_ESP32C6) && \
|
||||
!defined(USE_ESP32_VARIANT_ESP32C61) && !defined(USE_ESP32_VARIANT_ESP32H2)
|
||||
// Single pin wakeup (ext0) - ESP32, S2, S3
|
||||
#if SOC_PM_SUPPORT_EXT0_WAKEUP
|
||||
if (this->wakeup_pin_ != nullptr) {
|
||||
const auto gpio_pin = gpio_num_t(this->wakeup_pin_->get_pin());
|
||||
if (this->wakeup_pin_->get_flags() & gpio::FLAG_PULLUP) {
|
||||
@@ -138,11 +140,9 @@ void DeepSleepComponent::deep_sleep_() {
|
||||
}
|
||||
esp_sleep_enable_ext0_wakeup(gpio_pin, level);
|
||||
}
|
||||
#endif
|
||||
|
||||
// GPIO wakeup - C2, C3, C5, C6, C61 only
|
||||
#if defined(USE_ESP32_VARIANT_ESP32C2) || defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C5) || \
|
||||
defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32C61)
|
||||
// GPIO wakeup - C2, C3, C5, C6, C61, P4 (no variant has both ext0 and this)
|
||||
#elif SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
|
||||
if (this->wakeup_pin_ != nullptr) {
|
||||
const auto gpio_pin = gpio_num_t(this->wakeup_pin_->get_pin());
|
||||
// Make sure GPIO is in input mode, not all RTC GPIO pins are input by default
|
||||
@@ -164,16 +164,14 @@ void DeepSleepComponent::deep_sleep_() {
|
||||
#endif
|
||||
|
||||
// Multiple pin wakeup (ext1) - All except C2, C3
|
||||
#if !defined(USE_ESP32_VARIANT_ESP32C2) && !defined(USE_ESP32_VARIANT_ESP32C3)
|
||||
#if SOC_PM_SUPPORT_EXT1_WAKEUP
|
||||
if (this->ext1_wakeup_.has_value()) {
|
||||
esp_sleep_enable_ext1_wakeup(this->ext1_wakeup_->mask, this->ext1_wakeup_->wakeup_mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Touch wakeup - ESP32, S2, S3 only
|
||||
#if !defined(USE_ESP32_VARIANT_ESP32C2) && !defined(USE_ESP32_VARIANT_ESP32C3) && \
|
||||
!defined(USE_ESP32_VARIANT_ESP32C5) && !defined(USE_ESP32_VARIANT_ESP32C6) && \
|
||||
!defined(USE_ESP32_VARIANT_ESP32C61) && !defined(USE_ESP32_VARIANT_ESP32H2)
|
||||
// Touch wakeup - ESP32, S2, S3, P4
|
||||
#if SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP
|
||||
if (this->touch_wakeup_.has_value() && *(this->touch_wakeup_)) {
|
||||
esp_sleep_enable_touchpad_wakeup();
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "delta_wallbox.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/progmem.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -92,9 +93,7 @@ static const esp32_ble_tracker::ESPBTUUID RX_UUID =
|
||||
|
||||
// Appends the little-endian Modbus CRC-16 to the len bytes in frame and returns the new length.
|
||||
static size_t append_crc(uint8_t *frame, size_t len) {
|
||||
const uint16_t crc = crc16(frame, static_cast<uint16_t>(len));
|
||||
frame[len] = static_cast<uint8_t>(crc & 0xFF);
|
||||
frame[len + 1] = static_cast<uint8_t>(crc >> 8);
|
||||
put_le16(frame + len, crc16(frame, static_cast<uint16_t>(len)));
|
||||
return len + 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -124,9 +124,7 @@ void DFPlayer::play_folder(uint16_t folder, uint16_t file) {
|
||||
|
||||
void DFPlayer::send_cmd_(uint8_t cmd, uint16_t argument) {
|
||||
uint8_t buffer[10]{0x7e, 0xff, 0x06, cmd, 0x01, (uint8_t) (argument >> 8), (uint8_t) argument, 0x00, 0x00, 0xef};
|
||||
const uint16_t checksum = static_cast<uint16_t>(-sum16_bytes(buffer + 1, 6));
|
||||
buffer[7] = checksum >> 8;
|
||||
buffer[8] = (uint8_t) checksum;
|
||||
put_be16(buffer + 7, -sum16_bytes(buffer + 1, 6));
|
||||
|
||||
this->sent_cmd_ = cmd;
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r
|
||||
BYTE_TO_BINARY(data[0]), BYTE_TO_BINARY(data[1]), BYTE_TO_BINARY(data[2]), BYTE_TO_BINARY(data[3]),
|
||||
BYTE_TO_BINARY(data[4]));
|
||||
|
||||
uint8_t checksum_a = data[0] + data[1] + data[2] + data[3];
|
||||
uint8_t checksum_a = sum_bytes(data, 4);
|
||||
// On the DHT11, two algorithms for the checksum seem to be used, either the one from the DHT22,
|
||||
// or just using bytes 0 and 2
|
||||
uint8_t checksum_b = this->model_ == DHT_MODEL_DHT11 ? (data[0] + data[2]) : checksum_a;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// - DHT12_sensor_library: https://github.com/xreef/DHT12_sensor_library/blob/master/DHT12.cpp
|
||||
|
||||
#include "dht12.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome::dht12 {
|
||||
@@ -32,10 +33,8 @@ void DHT12Component::update() {
|
||||
}
|
||||
void DHT12Component::setup() {
|
||||
uint8_t data[5];
|
||||
if (!this->read_data_(data)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_data_(data)))
|
||||
return;
|
||||
}
|
||||
}
|
||||
void DHT12Component::dump_config() {
|
||||
ESP_LOGD(TAG, "DHT12:");
|
||||
@@ -50,7 +49,7 @@ bool DHT12Component::read_data_(uint8_t *data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t checksum = data[0] + data[1] + data[2] + data[3];
|
||||
uint8_t checksum = sum_bytes(data, 4);
|
||||
if (data[4] != checksum) {
|
||||
ESP_LOGW(TAG, "DHT12 Checksum invalid!");
|
||||
return false;
|
||||
|
||||
@@ -31,11 +31,8 @@ void DS248xComponent::setup() {
|
||||
}
|
||||
|
||||
// Configure device
|
||||
if (!this->device_configure_()) {
|
||||
ESP_LOGE(TAG, "DS248x configuration failed!");
|
||||
this->mark_failed();
|
||||
if (!this->setup_check(this->device_configure_(), LOG_STR("DS248x configuration failed!")))
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset to Channel 0
|
||||
this->select_channel(0);
|
||||
|
||||
@@ -45,10 +45,8 @@ static const LogString *square_wave_to_string(SquareWaveFrequency frequency) {
|
||||
void IRAM_ATTR DS3231Component::interrupt_handler(DS3231Component *arg) { arg->enable_loop_soon_any_context(); }
|
||||
|
||||
void DS3231Component::setup() {
|
||||
if (!this->read_control_status_()) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_control_status_()))
|
||||
return;
|
||||
}
|
||||
|
||||
// Keep the oscillator running on battery. INT/SQW is the alarm interrupt line unless a square
|
||||
// wave is configured. The alarm interrupt enables (A1IE/A2IE) are kept as they are: the alarms
|
||||
@@ -63,17 +61,13 @@ void DS3231Component::setup() {
|
||||
mask |= CONTROL_BBSQW;
|
||||
assign_bits(value, CONTROL_BBSQW, this->battery_backed_square_wave_ != 0);
|
||||
}
|
||||
if (!this->update_control_(mask, value)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->update_control_(mask, value)))
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->output_32khz_ >= 0) {
|
||||
assign_bits(this->status_reg_, STATUS_EN32KHZ, this->output_32khz_ != 0);
|
||||
if (!this->write_status_(0)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_status_(0)))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->aging_offset_configured_ && !this->write_aging_offset_(this->aging_offset_)) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "duco.h"
|
||||
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome::duco {
|
||||
@@ -161,9 +162,7 @@ void Duco::send(DucoDevice *device, uint8_t function, std::initializer_list<uint
|
||||
const uint8_t id = this->next_id_();
|
||||
uint8_t frame[5 + MAX_REQUEST_DATA + 2] = {HEADER_START, HEADER_END, static_cast<uint8_t>(size + 2), function, id};
|
||||
std::copy_n(data.begin(), size, frame + 5);
|
||||
const uint16_t crc = crc16(frame + 2, size + 3);
|
||||
frame[size + 5] = crc & 0xFF;
|
||||
frame[size + 6] = crc >> 8;
|
||||
put_le16(frame + size + 5, crc16(frame + 2, size + 3));
|
||||
this->write_array(frame, size + 7);
|
||||
this->flush();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#ifdef USE_ESP32
|
||||
#include "ecocomfort2_hub.h"
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#include <cmath>
|
||||
@@ -535,9 +536,9 @@ void Ecocomfort2Hub::write_config_(uint8_t index, uint8_t value, uint8_t stored)
|
||||
}
|
||||
|
||||
void Ecocomfort2Hub::write_offsets_(int16_t temperature, int16_t humidity) {
|
||||
const auto temperature_bytes = decode_value(static_cast<uint16_t>(temperature));
|
||||
const auto humidity_bytes = decode_value(static_cast<uint16_t>(humidity));
|
||||
uint8_t data[4]{temperature_bytes[0], temperature_bytes[1], humidity_bytes[0], humidity_bytes[1]};
|
||||
uint8_t data[4];
|
||||
put_be16(data, temperature);
|
||||
put_be16(data + 2, humidity);
|
||||
ESP_LOGD(TAG, "[%s] Writing C_ADVANCED_SETTINGS: offsets %d %d", this->parent_->address_str(), temperature, humidity);
|
||||
if (!this->write_settings_(this->advanced_char_, data, sizeof(data)))
|
||||
return;
|
||||
|
||||
@@ -23,10 +23,8 @@ void EE895Component::setup() {
|
||||
this->read(serial_number, 20);
|
||||
|
||||
crc16_check = (serial_number[19] << 8) + serial_number[18];
|
||||
if (crc16_check != calc_crc16_(serial_number, 18)) {
|
||||
this->mark_failed(LOG_STR("CRC check failed"));
|
||||
if (!this->setup_check(crc16_check == calc_crc16_(serial_number, 18), LOG_STR("CRC check failed")))
|
||||
return;
|
||||
}
|
||||
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
|
||||
char serial_hex[format_hex_size(EE895_SERIAL_NUMBER_SIZE)];
|
||||
#endif
|
||||
@@ -62,15 +60,10 @@ void EE895Component::update() {
|
||||
|
||||
void EE895Component::write_command_(uint16_t addr, uint16_t reg_cnt) {
|
||||
uint8_t address[7];
|
||||
uint16_t crc16 = 0;
|
||||
address[0] = FUNCTION_CODE_READ;
|
||||
address[1] = (addr >> 8) & 0xFF;
|
||||
address[2] = addr & 0xFF;
|
||||
address[3] = (reg_cnt >> 8) & 0xFF;
|
||||
address[4] = reg_cnt & 0xFF;
|
||||
crc16 = calc_crc16_(address, 5);
|
||||
address[5] = crc16 & 0xFF;
|
||||
address[6] = (crc16 >> 8) & 0xFF;
|
||||
put_be16(address + 1, addr);
|
||||
put_be16(address + 3, reg_cnt);
|
||||
put_le16(address + 5, calc_crc16_(address, 5));
|
||||
this->write(address, 7);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "ens160_base.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/hal.h"
|
||||
|
||||
namespace esphome::ens160_base {
|
||||
@@ -61,28 +62,22 @@ static const uint8_t ENS160_DATA_AQI = 0x07;
|
||||
void ENS160Component::setup() {
|
||||
// check part_id
|
||||
uint16_t part_id;
|
||||
if (!this->read_bytes(ENS160_REG_PART_ID, reinterpret_cast<uint8_t *>(&part_id), 2)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_bytes(ENS160_REG_PART_ID, reinterpret_cast<uint8_t *>(&part_id), 2)))
|
||||
return;
|
||||
}
|
||||
if (part_id != ENS160_PART_ID) {
|
||||
this->mark_failed(LOG_STR("Sensor reported an invalid ID. Is this a ENS160?"));
|
||||
return;
|
||||
}
|
||||
|
||||
// set mode to reset
|
||||
if (!this->write_byte(ENS160_REG_OPMODE, ENS160_OPMODE_RESET)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(ENS160_REG_OPMODE, ENS160_OPMODE_RESET)))
|
||||
return;
|
||||
}
|
||||
delay(ENS160_BOOTING);
|
||||
|
||||
// check status
|
||||
uint8_t status_value;
|
||||
if (!this->read_byte(ENS160_REG_DATA_STATUS, &status_value)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_byte(ENS160_REG_DATA_STATUS, &status_value)))
|
||||
return;
|
||||
}
|
||||
this->validity_flag_ = static_cast<ValidityFlag>((ENS160_DATA_STATUS_VALIDITY & status_value) >> 2);
|
||||
|
||||
if (this->validity_flag_ == INVALID_OUTPUT) {
|
||||
@@ -91,35 +86,25 @@ void ENS160Component::setup() {
|
||||
}
|
||||
|
||||
// set mode to idle
|
||||
if (!this->write_byte(ENS160_REG_OPMODE, ENS160_OPMODE_IDLE)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(ENS160_REG_OPMODE, ENS160_OPMODE_IDLE)))
|
||||
return;
|
||||
}
|
||||
delay(ENS160_BOOTING);
|
||||
|
||||
// clear command
|
||||
if (!this->write_byte(ENS160_REG_COMMAND, ENS160_COMMAND_NOP)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(ENS160_REG_COMMAND, ENS160_COMMAND_NOP)))
|
||||
return;
|
||||
}
|
||||
if (!this->write_byte(ENS160_REG_COMMAND, ENS160_COMMAND_CLRGPR)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(ENS160_REG_COMMAND, ENS160_COMMAND_CLRGPR)))
|
||||
return;
|
||||
}
|
||||
delay(ENS160_BOOTING);
|
||||
|
||||
// read firmware version
|
||||
if (!this->write_byte(ENS160_REG_COMMAND, ENS160_COMMAND_GET_APPVER)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(ENS160_REG_COMMAND, ENS160_COMMAND_GET_APPVER)))
|
||||
return;
|
||||
}
|
||||
delay(ENS160_BOOTING);
|
||||
|
||||
uint8_t version_data[3];
|
||||
if (!this->read_bytes(ENS160_REG_GPR_READ_4, version_data, 3)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_bytes(ENS160_REG_GPR_READ_4, version_data, 3)))
|
||||
return;
|
||||
}
|
||||
this->firmware_ver_major_ = version_data[0];
|
||||
this->firmware_ver_minor_ = version_data[1];
|
||||
this->firmware_ver_build_ = version_data[2];
|
||||
@@ -137,10 +122,8 @@ void ENS160Component::setup() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (op_mode != ENS160_OPMODE_STD) {
|
||||
this->mark_failed(LOG_STR("Device failed to achieve Standard Operating Mode"));
|
||||
if (!this->setup_check(op_mode == ENS160_OPMODE_STD, LOG_STR("Device failed to achieve Standard Operating Mode")))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ENS160Component::update() {
|
||||
@@ -256,14 +239,9 @@ void ENS160Component::send_env_data_() {
|
||||
ESP_LOGV(TAG, "External humidity compensation: %.1f%%", humidity);
|
||||
}
|
||||
|
||||
uint16_t t = (uint16_t) ((temperature + 273.15f) * 64.0f);
|
||||
uint16_t h = (uint16_t) (humidity * 512.0f);
|
||||
|
||||
uint8_t data[4];
|
||||
data[0] = t & 0xff;
|
||||
data[1] = (t >> 8) & 0xff;
|
||||
data[2] = h & 0xff;
|
||||
data[3] = (h >> 8) & 0xff;
|
||||
put_le16(data, static_cast<uint16_t>((temperature + 273.15f) * 64.0f));
|
||||
put_le16(data + 2, static_cast<uint16_t>(humidity * 512.0f));
|
||||
|
||||
if (!this->write_bytes(ENS160_REG_TEMP_IN, data, 4)) {
|
||||
ESP_LOGE(TAG, "Error writing compensation values");
|
||||
|
||||
@@ -58,10 +58,8 @@ void ES7243::setup() {
|
||||
const bool ok = this->write_byte(REG_MODE_CONFIG, 0x01) && this->write_byte(REG_STATE_CONTROL, 0x00) &&
|
||||
this->write_byte(REG_MUTE_CONTROL, 0x1B) && this->write_byte(REG_SDP_FORMAT, 0x0C) &&
|
||||
this->write_mic_gain_() && this->write_byte(REG_MUTE_CONTROL, 0x13);
|
||||
if (!ok) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(ok))
|
||||
return;
|
||||
}
|
||||
this->setup_complete_ = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,10 +71,8 @@ const LogString *deemphasis_to_str(DeemphasisMode mode) {
|
||||
void ES9038Q2MKatana::setup() {
|
||||
if (!this->check_chip_id(this, KATANA_REG_CHIP_ID, KATANA_CHIP_ID))
|
||||
return;
|
||||
if (!this->write_byte(KATANA_REG_RESET, 0x01)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(KATANA_REG_RESET, 0x01)))
|
||||
return;
|
||||
}
|
||||
delay(RESET_SETTLE_DELAY_MS);
|
||||
|
||||
// MUTE_STREAM is the gate the Linux driver closes between streams; ESPHome has no such
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
|
||||
#include "bluedroid_hex.h"
|
||||
|
||||
// Set with Bluedroid's private include dirs for this file only (native ESP-IDF toolchain)
|
||||
#ifdef USE_ESP32_BLE_BLUEDROID_HEADERS
|
||||
// Set with Bluedroid's private include dirs for this file only (native ESP-IDF toolchain).
|
||||
// The headers only feed the drift checks below. On Windows the include dirs come through with backslashes,
|
||||
// which GCC reads as escapes in the Ninja response file, so the checks are skipped where they are unreachable.
|
||||
#if defined(USE_ESP32_BLE_BLUEDROID_HEADERS) && __has_include("btc/btc_config.h")
|
||||
#define ESPHOME_BLUEDROID_DRIFT_CHECKS
|
||||
#include <type_traits>
|
||||
extern "C" {
|
||||
#include "btc/btc_config.h"
|
||||
@@ -36,7 +39,7 @@ bool __wrap_string_to_bdaddr(const char *string, uint8_t *addr) {
|
||||
} // extern "C"
|
||||
// NOLINTEND(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp,readability-identifier-naming)
|
||||
|
||||
#ifdef USE_ESP32_BLE_BLUEDROID_HEADERS
|
||||
#ifdef ESPHOME_BLUEDROID_DRIFT_CHECKS
|
||||
// ESP-IDF drift checks: if one fails, re-check the wraps against espressif/esp-idf#19235 and Bluedroid's sources.
|
||||
static_assert(std::is_same_v<decltype(&btc_config_get_bin), decltype(&__wrap_btc_config_get_bin)>,
|
||||
"btc_config_get_bin signature changed");
|
||||
|
||||
@@ -7,12 +7,10 @@ namespace esphome::ezsp_proxy_tap {
|
||||
void ash_build_ack_frame(uint8_t *output, uint8_t ack_num) {
|
||||
// ACK control byte: 100nrPPP, where PPP is the next frame number expected
|
||||
const uint8_t control = 0x80 | (ack_num & ASH_MAX_SEQUENCE);
|
||||
const uint16_t crc = crc16be(&control, 1, ASH_CRC_INIT);
|
||||
|
||||
output[0] = ASH_FLAG_BYTE;
|
||||
output[1] = control;
|
||||
output[2] = crc >> 8;
|
||||
output[3] = crc & 0xFF;
|
||||
put_be16(output + 2, crc16be(&control, 1, ASH_CRC_INIT));
|
||||
output[4] = ASH_FLAG_BYTE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
#include "esphome/components/uart/uart.h"
|
||||
@@ -105,12 +106,7 @@ class FingerprintGrowComponent final : public PollingComponent, public uart::UAR
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
|
||||
void set_address(uint32_t address) {
|
||||
this->address_[0] = (uint8_t) (address >> 24);
|
||||
this->address_[1] = (uint8_t) (address >> 16);
|
||||
this->address_[2] = (uint8_t) (address >> 8);
|
||||
this->address_[3] = (uint8_t) (address & 0xFF);
|
||||
}
|
||||
void set_address(uint32_t address) { put_be32(this->address_, address); }
|
||||
void set_sensing_pin(GPIOPin *sensing_pin) { this->sensing_pin_ = sensing_pin; }
|
||||
void set_sensor_power_pin(GPIOPin *sensor_power_pin) { this->sensor_power_pin_ = sensor_power_pin; }
|
||||
void set_password(uint32_t password) { this->password_ = password; }
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <cstdio>
|
||||
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#include "fusb302b_registers.h"
|
||||
@@ -51,10 +52,8 @@ void FUSB302B::task_func(void *arg) { static_cast<FUSB302B *>(arg)->run_task_();
|
||||
|
||||
void FUSB302B::setup() {
|
||||
uint8_t device_id = 0;
|
||||
if (!this->read_byte(FUSB_DEVICE_ID, &device_id)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_byte(FUSB_DEVICE_ID, &device_id)))
|
||||
return;
|
||||
}
|
||||
const uint8_t version = device_id & FUSB_DEVICE_ID_VERSION_MASK;
|
||||
if (version != FUSB_DEVICE_ID_VERSION_A && version != FUSB_DEVICE_ID_VERSION_B) {
|
||||
ESP_LOGE(TAG, "Unknown device ID 0x%02X", device_id);
|
||||
@@ -62,10 +61,8 @@ void FUSB302B::setup() {
|
||||
return;
|
||||
}
|
||||
ESP_LOGD(TAG, "Device ID 0x%02X (product %u, revision %u)", device_id, (device_id >> 2) & 0x3, device_id & 0x3);
|
||||
if (!this->init_chip_()) {
|
||||
this->mark_failed(LOG_STR("Initialization failed"));
|
||||
if (!this->setup_check(this->init_chip_(), LOG_STR("Initialization failed")))
|
||||
return;
|
||||
}
|
||||
|
||||
this->interrupt_pin_->setup();
|
||||
// The task must exist before the interrupt is attached, since the ISR notifies it
|
||||
@@ -351,7 +348,6 @@ bool FUSB302B::send_message(const PdMsg &msg) {
|
||||
// Register address, then the TX tokens; written in one transfer without the copy write_register() makes
|
||||
uint8_t buf[1 + 4 + 1 + 2 + PD_MAX_NUM_DATA_OBJECTS * 4 + 4];
|
||||
size_t len = 0;
|
||||
const uint16_t header = msg.get_coded_header();
|
||||
|
||||
buf[len++] = FUSB_FIFOS;
|
||||
buf[len++] = FUSB_TX_TOKEN_SYNC1;
|
||||
@@ -359,14 +355,11 @@ bool FUSB302B::send_message(const PdMsg &msg) {
|
||||
buf[len++] = FUSB_TX_TOKEN_SYNC1;
|
||||
buf[len++] = FUSB_TX_TOKEN_SYNC2;
|
||||
buf[len++] = FUSB_TX_TOKEN_PACKSYM | (msg.num_of_obj * 4 + 2);
|
||||
buf[len++] = header & 0xFF;
|
||||
buf[len++] = header >> 8;
|
||||
put_le16(buf + len, msg.get_coded_header());
|
||||
len += 2;
|
||||
for (uint8_t i = 0; i < msg.num_of_obj; i++) {
|
||||
const uint32_t obj = msg.data_objects[i];
|
||||
buf[len++] = obj & 0xFF;
|
||||
buf[len++] = (obj >> 8) & 0xFF;
|
||||
buf[len++] = (obj >> 16) & 0xFF;
|
||||
buf[len++] = obj >> 24;
|
||||
put_le32(buf + len, msg.data_objects[i]);
|
||||
len += 4;
|
||||
}
|
||||
buf[len++] = FUSB_TX_TOKEN_JAM_CRC;
|
||||
buf[len++] = FUSB_TX_TOKEN_EOP;
|
||||
|
||||
@@ -17,11 +17,9 @@ static const uint8_t READ_DELAY = 40; // minimum milliseconds from datasheet to
|
||||
|
||||
void GLR01I2CComponent::setup() {
|
||||
// Verify sensor presence
|
||||
if (!this->read_byte_16(REG_VERSION, &this->version_)) {
|
||||
ESP_LOGE(TAG, "Failed to communicate with GL-R01 I2C sensor!");
|
||||
this->mark_failed();
|
||||
if (!this->setup_check(this->read_byte_16(REG_VERSION, &this->version_),
|
||||
LOG_STR("Failed to communicate with GL-R01 I2C sensor!")))
|
||||
return;
|
||||
}
|
||||
ESP_LOGD(TAG, "Found GL-R01 I2C with version 0x%04X", this->version_);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "grove_tb6612fng.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
namespace esphome::grove_tb6612fng {
|
||||
|
||||
@@ -125,10 +126,8 @@ void GroveMotorDriveTB6612FNG::stepper_run(StepperModeTypeT mode, int16_t steps,
|
||||
ms_per_step = (uint16_t) (3000.0f / (float) rpm);
|
||||
buffer_[0] = mode;
|
||||
buffer_[1] = cw; //(cw=1) => cw; (cw=0) => ccw
|
||||
buffer_[2] = steps;
|
||||
buffer_[3] = (steps >> 8);
|
||||
buffer_[4] = ms_per_step;
|
||||
buffer_[5] = (ms_per_step >> 8);
|
||||
put_le16(this->buffer_ + 2, steps);
|
||||
put_le16(this->buffer_ + 4, ms_per_step);
|
||||
|
||||
if (this->write_register(GROVE_MOTOR_DRIVER_I2C_CMD_STEPPER_RUN, buffer_, 6) != i2c::ERROR_OK) {
|
||||
ESP_LOGW(TAG, "Run stepper failed!");
|
||||
@@ -157,8 +156,7 @@ void GroveMotorDriveTB6612FNG::stepper_keep_run(StepperModeTypeT mode, uint16_t
|
||||
|
||||
buffer_[0] = mode;
|
||||
buffer_[1] = cw; //(cw=1) => cw; (cw=0) => ccw
|
||||
buffer_[2] = ms_per_step;
|
||||
buffer_[3] = (ms_per_step >> 8);
|
||||
put_le16(this->buffer_ + 2, ms_per_step);
|
||||
|
||||
if (this->write_register(GROVE_MOTOR_DRIVER_I2C_CMD_STEPPER_KEEP_RUN, buffer_, 4) != i2c::ERROR_OK) {
|
||||
ESP_LOGW(TAG, "Write stepper keep run failed");
|
||||
|
||||
@@ -97,16 +97,12 @@ void GT911Touchscreen::setup_internal_() {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (err != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR("Calibration error"));
|
||||
if (!this->setup_check(err == i2c::ERROR_OK, LOG_STR("Calibration error")))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (err != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(err == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
this->setup_done_ = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,8 +71,7 @@ void HC8Component::calibrate(uint16_t baseline) {
|
||||
|
||||
std::array<uint8_t, 6> command{};
|
||||
std::copy(begin(HC8_COMMAND_CALIBRATE_PREAMBLE), end(HC8_COMMAND_CALIBRATE_PREAMBLE), begin(command));
|
||||
command[3] = baseline >> 8;
|
||||
command[4] = baseline;
|
||||
put_be16(command.data() + 3, baseline);
|
||||
command[5] = 0;
|
||||
|
||||
// the last byte is a checksum over the data
|
||||
|
||||
@@ -22,10 +22,8 @@ static constexpr uint8_t MEAS_CONF_HUM = 0x04; // Bits 2:1 = 10: humidity only
|
||||
|
||||
void HDC2080Component::setup() {
|
||||
const uint8_t data = 0x00; // automatic measurement mode disabled, heater off
|
||||
if (this->write_register(REG_RESET_DRDY_INT_CONF, &data, 1) != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_register(REG_RESET_DRDY_INT_CONF, &data, 1) == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void HDC2080Component::dump_config() {
|
||||
|
||||
@@ -22,18 +22,15 @@ static const uint8_t HDC302X_CMD_HEATER_CONFIGURE[2] = {0x30, 0x6e};
|
||||
|
||||
void HDC302XComponent::setup() {
|
||||
// Soft reset the device
|
||||
if (this->write(HDC302X_CMD_SOFT_RESET, 2) != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR("Soft reset failed"));
|
||||
if (!this->setup_check(this->write(HDC302X_CMD_SOFT_RESET, 2) == i2c::ERROR_OK, LOG_STR("Soft reset failed")))
|
||||
return;
|
||||
}
|
||||
// Delay SensorRR (reset ready), per datasheet, 6.5.
|
||||
delay(3);
|
||||
|
||||
// Clear status register
|
||||
if (this->write(HDC302X_CMD_CLEAR_STATUS_REGISTER, 2) != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR("Clear status failed"));
|
||||
if (!this->setup_check(this->write(HDC302X_CMD_CLEAR_STATUS_REGISTER, 2) == i2c::ERROR_OK,
|
||||
LOG_STR("Clear status failed")))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void HDC302XComponent::dump_config() {
|
||||
|
||||
@@ -44,25 +44,19 @@ void HMC5883LComponent::setup() {
|
||||
config_a |= this->oversampling_ << 5;
|
||||
config_a |= this->datarate_ << 2;
|
||||
config_a |= 0b0 << 0; // Measurement Mode: Normal(high impedance on load)
|
||||
if (!this->write_byte(HMC5883L_REGISTER_CONFIG_A, config_a)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(HMC5883L_REGISTER_CONFIG_A, config_a)))
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t config_b = 0;
|
||||
config_b |= this->range_ << 5;
|
||||
if (!this->write_byte(HMC5883L_REGISTER_CONFIG_B, config_b)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(HMC5883L_REGISTER_CONFIG_B, config_b)))
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t mode = 0;
|
||||
// Continuous Measurement Mode
|
||||
mode |= 0b00;
|
||||
if (!this->write_byte(HMC5883L_REGISTER_MODE, mode)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(HMC5883L_REGISTER_MODE, mode)))
|
||||
return;
|
||||
}
|
||||
}
|
||||
void HMC5883LComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "HMC5883L:");
|
||||
|
||||
@@ -11,14 +11,11 @@ static constexpr size_t HTE501_SERIAL_NUMBER_SIZE = 7;
|
||||
void HTE501Component::setup() {
|
||||
uint8_t address[] = {0x70, 0x29};
|
||||
uint8_t identification[9];
|
||||
if (this->write_read(address, sizeof address, identification, sizeof identification) != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_read(address, sizeof address, identification, sizeof identification) ==
|
||||
i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
if (identification[8] != crc8(identification, 8, 0xFF, 0x31, true)) {
|
||||
this->mark_failed(LOG_STR("CRC check failed"));
|
||||
if (!this->setup_check(identification[8] == crc8(identification, 8, 0xFF, 0x31, true), LOG_STR("CRC check failed")))
|
||||
return;
|
||||
}
|
||||
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
|
||||
char serial_hex[format_hex_size(HTE501_SERIAL_NUMBER_SIZE)];
|
||||
#endif
|
||||
|
||||
@@ -18,10 +18,8 @@ static const uint8_t HTU21D_READHEATER_REG_CMD = 0x11; /**< Read Heater Control
|
||||
static const uint8_t HTU21D_REG_HTRE_BIT = 0x02; /**< Control Register Heater Bit */
|
||||
|
||||
void HTU21DComponent::setup() {
|
||||
if (!this->write_bytes(HTU21D_REGISTER_RESET, nullptr, 0)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_bytes(HTU21D_REGISTER_RESET, nullptr, 0)))
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait for software reset to complete
|
||||
delay(15);
|
||||
|
||||
@@ -48,15 +48,11 @@ static const uint8_t HTU31D_DIAGNOSTICS = 0x08;
|
||||
* I2C.
|
||||
*/
|
||||
void HTU31DComponent::setup() {
|
||||
if (!this->reset_()) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->reset_()))
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->read_serial_num_() == 0) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_serial_num_() != 0))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome::i2c {
|
||||
@@ -64,8 +65,7 @@ ErrorCode I2CDevice::write_register16(uint16_t a_register, const uint8_t *data,
|
||||
SmallBufferWithHeapFallback<18> buffer_alloc(len + 2); // Most I2C writes are <= 16 bytes + 2 for register
|
||||
uint8_t *buffer = buffer_alloc.get();
|
||||
|
||||
buffer[0] = a_register >> 8;
|
||||
buffer[1] = a_register;
|
||||
put_be16(buffer, a_register);
|
||||
std::copy(data, data + len, buffer + 2);
|
||||
return this->bus_->write_readv(this->address_, buffer, len + 2, nullptr, 0);
|
||||
}
|
||||
@@ -108,9 +108,7 @@ bool I2CDevice::write_bytes_16(uint8_t a_register, const uint16_t *data, uint8_t
|
||||
|
||||
buffer[0] = a_register;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
const uint16_t word = data[i];
|
||||
buffer[1 + i * 2] = word >> 8;
|
||||
buffer[2 + i * 2] = word;
|
||||
put_be16(buffer + 1 + i * 2, data[i]);
|
||||
}
|
||||
return this->bus_->write_readv(this->address_, buffer, size, nullptr, 0) == ERROR_OK;
|
||||
}
|
||||
|
||||
@@ -26,10 +26,8 @@ struct SensorData {
|
||||
};
|
||||
|
||||
void IAQCore::setup() {
|
||||
if (this->write(nullptr, 0) != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write(nullptr, 0) == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void IAQCore::update() {
|
||||
|
||||
@@ -37,10 +37,8 @@ void ICM20689Component::setup() {
|
||||
|
||||
this->spi_setup();
|
||||
|
||||
if (!this->spi_is_ready()) {
|
||||
this->mark_failed(LOG_STR("SPI device is not ready"));
|
||||
if (!this->setup_check(this->spi_is_ready(), LOG_STR("SPI device is not ready")))
|
||||
return;
|
||||
}
|
||||
|
||||
// Datasheet 4.20: a soft reset must be the first operation after power-up,
|
||||
// before any register initialization. WHO_AM_I is only valid afterwards.
|
||||
|
||||
@@ -35,10 +35,8 @@ static const uint8_t INA219_REGISTER_CALIBRATION = 0x05;
|
||||
void INA219Component::setup() {
|
||||
// Config Register
|
||||
// 0bx000000000000000 << 15 RESET Bit (1 -> trigger reset)
|
||||
if (!this->write_byte_16(INA219_REGISTER_CONFIG, 0x8000)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte_16(INA219_REGISTER_CONFIG, 0x8000)))
|
||||
return;
|
||||
}
|
||||
|
||||
delay(1);
|
||||
|
||||
@@ -100,10 +98,8 @@ void INA219Component::setup() {
|
||||
|
||||
config |= shunt_gain << 11;
|
||||
ESP_LOGCONFIG(TAG, " Using %dV-Range Shunt Gain=%dmV", bus_32v_range ? 32 : 16, 40 << shunt_gain);
|
||||
if (!this->write_byte_16(INA219_REGISTER_CONFIG, config)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte_16(INA219_REGISTER_CONFIG, config)))
|
||||
return;
|
||||
}
|
||||
|
||||
auto min_lsb = uint32_t(ceilf(this->max_current_a_ * 1000000.0f / 0x8000));
|
||||
auto max_lsb = uint32_t(floorf(this->max_current_a_ * 1000000.0f / 0x1000));
|
||||
@@ -121,10 +117,8 @@ void INA219Component::setup() {
|
||||
this->calibration_lsb_ = lsb;
|
||||
auto calibration = uint32_t(0.04096f / (0.000001f * lsb * this->shunt_resistance_ohm_));
|
||||
ESP_LOGV(TAG, " Using LSB=%" PRIu32 " calibration=%" PRIu32, lsb, calibration);
|
||||
if (!this->write_byte_16(INA219_REGISTER_CALIBRATION, calibration)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte_16(INA219_REGISTER_CALIBRATION, calibration)))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void INA219Component::on_powerdown() {
|
||||
|
||||
@@ -40,10 +40,8 @@ void INA226Component::setup() {
|
||||
ConfigurationRegister config;
|
||||
|
||||
config.reset = 1;
|
||||
if (!this->write_byte_16(INA226_REGISTER_CONFIG, config.raw)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte_16(INA226_REGISTER_CONFIG, config.raw)))
|
||||
return;
|
||||
}
|
||||
delay(1);
|
||||
|
||||
config.raw = 0;
|
||||
@@ -61,10 +59,8 @@ void INA226Component::setup() {
|
||||
// Mode Settings [2:0] Combinations (111 -> Shunt and Bus, Continuous)
|
||||
config.mode = 0b111;
|
||||
|
||||
if (!this->write_byte_16(INA226_REGISTER_CONFIG, config.raw)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte_16(INA226_REGISTER_CONFIG, config.raw)))
|
||||
return;
|
||||
}
|
||||
|
||||
// lsb is multiplied by 1000000 to store it as an integer value
|
||||
uint32_t lsb = static_cast<uint32_t>(ceilf(this->max_current_a_ * 1000000.0f / 32768));
|
||||
@@ -75,10 +71,8 @@ void INA226Component::setup() {
|
||||
|
||||
ESP_LOGV(TAG, " Using LSB=%" PRIu32 " calibration=%" PRIu32, lsb, calibration);
|
||||
|
||||
if (!this->write_byte_16(INA226_REGISTER_CALIBRATION, calibration)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte_16(INA226_REGISTER_CALIBRATION, calibration)))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void INA226Component::dump_config() {
|
||||
|
||||
@@ -35,10 +35,9 @@ static const uint8_t INA260_REGISTER_DEVICE_ID = 0xFF;
|
||||
|
||||
void INA260Component::setup() {
|
||||
// Reset device on setup
|
||||
if (!this->write_byte_16(INA260_REGISTER_CONFIG, 0x8000)) {
|
||||
this->mark_failed(LOG_STR("Device reset failed - Is the device connected?"));
|
||||
if (!this->setup_check(this->write_byte_16(INA260_REGISTER_CONFIG, 0x8000),
|
||||
LOG_STR("Device reset failed - Is the device connected?")))
|
||||
return;
|
||||
}
|
||||
|
||||
delay(2);
|
||||
|
||||
@@ -50,10 +49,9 @@ void INA260Component::setup() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->write_byte_16(INA260_REGISTER_CONFIG, (uint16_t) 0b0000001100000111)) {
|
||||
this->mark_failed(LOG_STR("Failed to update device configuration"));
|
||||
if (!this->setup_check(this->write_byte_16(INA260_REGISTER_CONFIG, (uint16_t) 0b0000001100000111),
|
||||
LOG_STR("Failed to update device configuration")))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void INA260Component::dump_config() {
|
||||
|
||||
@@ -49,16 +49,13 @@ static bool check_model_and_device_match(INAModel model, uint16_t dev_id) {
|
||||
}
|
||||
|
||||
void INA2XX::setup() {
|
||||
if (!this->reset_config_()) {
|
||||
this->mark_failed(LOG_STR("Reset failed, check connection"));
|
||||
if (!this->setup_check(this->reset_config_(), LOG_STR("Reset failed, check connection")))
|
||||
return;
|
||||
}
|
||||
delay(2);
|
||||
|
||||
if (!this->check_device_model_()) {
|
||||
this->mark_failed(LOG_STR("Device not supported or model selected improperly in yaml file"));
|
||||
if (!this->setup_check(this->check_device_model_(),
|
||||
LOG_STR("Device not supported or model selected improperly in yaml file")))
|
||||
return;
|
||||
}
|
||||
delay(1);
|
||||
|
||||
this->configure_adc_range_();
|
||||
|
||||
@@ -7,10 +7,8 @@ ESPHOME_LOG_TAG(TAG, "ina2xx_i2c");
|
||||
|
||||
void INA2XXI2C::setup() {
|
||||
auto err = this->write(nullptr, 0);
|
||||
if (err != i2c::ERROR_OK) {
|
||||
this->mark_failed();
|
||||
if (!this->setup_check(err == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
INA2XX::setup();
|
||||
}
|
||||
|
||||
|
||||
@@ -39,16 +39,12 @@ static constexpr uint32_t READ_TIMEOUT_ID = 0;
|
||||
// A0 = SCL -> 0x43
|
||||
|
||||
void INA3221Component::setup() {
|
||||
if (!this->write_byte_16(INA3221_REGISTER_CONFIG, INA3221_CONFIG_RESET)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte_16(INA3221_REGISTER_CONFIG, INA3221_CONFIG_RESET)))
|
||||
return;
|
||||
}
|
||||
delay(1);
|
||||
|
||||
if (!this->write_byte_16(INA3221_REGISTER_CONFIG, this->config_)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte_16(INA3221_REGISTER_CONFIG, this->config_)))
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef USE_INA3221_ALERT_LIMITS
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
|
||||
@@ -83,8 +83,7 @@ void KamstrupKMPComponent::send_command_(uint16_t command) {
|
||||
msg[0] = 0x3F;
|
||||
msg[1] = 0x10;
|
||||
msg[2] = 0x01;
|
||||
msg[3] = command >> 8;
|
||||
msg[4] = command & 0xFF;
|
||||
put_be16(msg + 3, command);
|
||||
|
||||
this->discard_available();
|
||||
this->send_message_(msg, msg_len);
|
||||
@@ -100,9 +99,7 @@ void KamstrupKMPComponent::send_message_(const uint8_t *msg, int msg_len) {
|
||||
buffer[i] = msg[i];
|
||||
}
|
||||
|
||||
uint16_t crc = crc16be(buffer, buffer_len - 2);
|
||||
buffer[buffer_len - 2] = crc >> 8;
|
||||
buffer[buffer_len - 1] = crc & 0xFF;
|
||||
put_be16(buffer + buffer_len - 2, crc16be(buffer, buffer_len - 2));
|
||||
|
||||
// Prepare actual TX message
|
||||
uint8_t tx_msg[20];
|
||||
|
||||
@@ -217,8 +217,7 @@ uint8_t Lc709203f::set_register_(uint8_t register_to_set, uint16_t value_to_set)
|
||||
// part of the CRC calculation.
|
||||
write_buffer[0] = (this->address_) << 1;
|
||||
write_buffer[1] = register_to_set;
|
||||
write_buffer[2] = value_to_set & 0xFF; // Low byte
|
||||
write_buffer[3] = (value_to_set >> 8) & 0xFF; // High byte
|
||||
put_le16(write_buffer + 2, value_to_set);
|
||||
write_buffer[4] = crc8(write_buffer, 4, 0x00, 0x07, true);
|
||||
|
||||
for (uint8_t i = 0; i <= LC709203F_I2C_RETRY_COUNT; i++) {
|
||||
|
||||
@@ -11,10 +11,8 @@ static const uint8_t LCD_DISPLAY_BACKLIGHT_OFF = 0x00;
|
||||
|
||||
void PCF8574LCDDisplay::setup() {
|
||||
this->backlight_value_ = LCD_DISPLAY_BACKLIGHT_ON;
|
||||
if (!this->write_bytes(this->backlight_value_, nullptr, 0)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_bytes(this->backlight_value_, nullptr, 0)))
|
||||
return;
|
||||
}
|
||||
|
||||
LCDDisplay::setup();
|
||||
}
|
||||
|
||||
@@ -213,29 +213,26 @@ void LD2410SComponent::send_command_(uint16_t command) {
|
||||
uint8_t frame[CMD_FRAME_MAX_SIZE];
|
||||
progmem_memcpy(frame, CMD_FRAME_HEADER, LONG_HEADER_SIZE);
|
||||
uint8_t pos = LONG_PAYLOAD_POS;
|
||||
frame[pos++] = command & 0xFF;
|
||||
frame[pos++] = command >> 8;
|
||||
put_le16(frame + pos, command);
|
||||
pos += 2;
|
||||
switch (command) {
|
||||
case OUTPUT_MODE_SWITCH_CMD:
|
||||
memset(&frame[pos], 0, OUTPUT_MODE_MINIMAL_SIZE);
|
||||
pos += OUTPUT_MODE_MINIMAL_SIZE;
|
||||
break;
|
||||
case CONFIG_MODE_START_CMD:
|
||||
frame[pos++] = CONFIG_MODE_START_VALUE & 0xFF;
|
||||
frame[pos++] = CONFIG_MODE_START_VALUE >> 8;
|
||||
put_le16(frame + pos, CONFIG_MODE_START_VALUE);
|
||||
pos += 2;
|
||||
break;
|
||||
#ifdef USE_LD2410S_PARAMETERS
|
||||
case PARAMETERS_READ_CMD:
|
||||
case PARAMETERS_WRITE_CMD:
|
||||
for (uint8_t i = 0; i < PARAMETER_COUNT; i++) {
|
||||
const uint16_t key = progmem_read_uint16(&PARAMETER_KEYS[i]);
|
||||
frame[pos++] = key & 0xFF;
|
||||
frame[pos++] = key >> 8;
|
||||
put_le16(frame + pos, progmem_read_uint16(&PARAMETER_KEYS[i]));
|
||||
pos += 2;
|
||||
if (command == PARAMETERS_WRITE_CMD) {
|
||||
const uint32_t value = this->parameters_[i]; // a 32-bit field on the wire
|
||||
for (uint8_t shift = 0; shift < 32; shift += 8) {
|
||||
frame[pos++] = (value >> shift) & 0xFF;
|
||||
}
|
||||
put_le32(frame + pos, this->parameters_[i]); // a 32-bit field on the wire
|
||||
pos += 4;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -243,8 +240,7 @@ void LD2410SComponent::send_command_(uint16_t command) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
frame[LONG_HEADER_SIZE] = pos - LONG_PAYLOAD_POS; // payload length, little-endian
|
||||
frame[LONG_HEADER_SIZE + 1] = 0;
|
||||
put_le16(frame + LONG_HEADER_SIZE, pos - LONG_PAYLOAD_POS); // payload length
|
||||
progmem_memcpy(&frame[pos], CMD_FRAME_FOOTER, sizeof(CMD_FRAME_FOOTER));
|
||||
pos += sizeof(CMD_FRAME_FOOTER);
|
||||
this->write_array(frame, pos);
|
||||
|
||||
@@ -84,9 +84,7 @@ static inline uint32_t convert_seconds_to_ms(uint16_t value) { return (uint32_t)
|
||||
|
||||
static inline void convert_int_values_to_hex(const int *values, uint8_t *bytes) {
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
uint16_t val = values[i] & 0xFFFF;
|
||||
bytes[i * 2] = val & 0xFF; // Store low byte first (little-endian)
|
||||
bytes[i * 2 + 1] = (val >> 8) & 0xFF; // Store high byte second
|
||||
put_le16(bytes + i * 2, values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,10 +83,8 @@ static const LogString *filter_bandwidth_to_string(FilterBandwidth bw) {
|
||||
|
||||
void LIS2DW12Component::setup() {
|
||||
uint8_t who_am_i{0};
|
||||
if (!this->read_byte(static_cast<uint8_t>(RegisterMap::WHO_AM_I), &who_am_i)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_byte(static_cast<uint8_t>(RegisterMap::WHO_AM_I), &who_am_i)))
|
||||
return;
|
||||
}
|
||||
if (who_am_i != LIS2DW12_WHO_AM_I_VALUE) {
|
||||
ESP_LOGE(TAG, "WHO_AM_I check failed. Got 0x%02X, expected 0x%02X", who_am_i, LIS2DW12_WHO_AM_I_VALUE);
|
||||
this->mark_failed(LOG_STR("Wrong chip ID"));
|
||||
@@ -94,10 +92,8 @@ void LIS2DW12Component::setup() {
|
||||
}
|
||||
|
||||
// Soft reset
|
||||
if (!this->write_reg_(RegisterMap::CTRL2, 0x40)) {
|
||||
this->mark_failed(LOG_STR("Soft reset failed"));
|
||||
if (!this->setup_check(this->write_reg_(RegisterMap::CTRL2, 0x40), LOG_STR("Soft reset failed")))
|
||||
return;
|
||||
}
|
||||
delay(1); // NOLINT - wait for reset to complete
|
||||
|
||||
uint8_t ctrl2{0};
|
||||
@@ -106,10 +102,8 @@ void LIS2DW12Component::setup() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->configure_registers_()) {
|
||||
this->mark_failed(LOG_STR("Register configuration failed"));
|
||||
if (!this->setup_check(this->configure_registers_(), LOG_STR("Register configuration failed")))
|
||||
return;
|
||||
}
|
||||
|
||||
// 0.244 mg/LSB at ±2g (14-bit), doubling per range step; 12-bit LP1 is 4x coarser
|
||||
const bool lp1 = this->power_mode_ == PowerMode::LOW_POWER_1;
|
||||
|
||||
@@ -42,10 +42,8 @@ void LP5562Output::setup() {
|
||||
// power up the chip and enable the internal 32 kHz oscillator, see
|
||||
// https://github.com/m5stack/M5GFX/blob/b2422cdb4735159209c2097d425c0756505b9a81/src/M5GFX.cpp#L566
|
||||
const uint8_t enable = LP5562_ENABLE_CHIP_EN | (this->logarithmic_dimming_ ? LP5562_ENABLE_LOG_EN : 0);
|
||||
if (!this->write_byte(LP5562_REG_ENABLE, enable)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(LP5562_REG_ENABLE, enable)))
|
||||
return;
|
||||
}
|
||||
delay(1);
|
||||
// use the internal clock, and drive every channel directly from its PWM register instead of the
|
||||
// internal blink/fade engines
|
||||
@@ -55,10 +53,8 @@ void LP5562Output::setup() {
|
||||
return;
|
||||
}
|
||||
for (size_t channel = 0; channel < this->currents_.size(); channel++) {
|
||||
if (!this->write_byte(progmem_read_byte(&LP5562_REG_CURRENT[channel]), this->currents_[channel])) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(progmem_read_byte(&LP5562_REG_CURRENT[channel]), this->currents_[channel])))
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,11 +48,9 @@ uint16_t temperature_sensitivity_from_who_am_i(uint8_t who_am_i) {
|
||||
void LSM6DSComponent::setup() {
|
||||
MotionComponent::setup();
|
||||
uint8_t who_am_i = 0;
|
||||
if (this->read_register(LSM6DS_REG_WHO_AM_I, &who_am_i, 1) != i2c::ERROR_OK) {
|
||||
ESP_LOGE(TAG, "Failed to read WHO_AM_I — check wiring and I2C address");
|
||||
this->mark_failed();
|
||||
if (!this->setup_check(this->read_register(LSM6DS_REG_WHO_AM_I, &who_am_i, 1) == i2c::ERROR_OK,
|
||||
LOG_STR("Failed to read WHO_AM_I — check wiring and I2C address")))
|
||||
return;
|
||||
}
|
||||
const LogString *chip_name = chip_name_from_who_am_i(who_am_i);
|
||||
if (chip_name == nullptr) {
|
||||
ESP_LOGE(TAG, "Unknown WHO_AM_I: 0x%02X", who_am_i);
|
||||
@@ -64,10 +62,9 @@ void LSM6DSComponent::setup() {
|
||||
this->temperature_sensitivity_ = temperature_sensitivity_from_who_am_i(who_am_i);
|
||||
|
||||
// 2. Software reset — clears all registers to defaults
|
||||
if (this->write_register(LSM6DS_REG_CTRL3_C, &CTRL3_C_SW_RESET, 1) != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR("Software reset failed"));
|
||||
if (!this->setup_check(this->write_register(LSM6DS_REG_CTRL3_C, &CTRL3_C_SW_RESET, 1) == i2c::ERROR_OK,
|
||||
LOG_STR("Software reset failed")))
|
||||
return;
|
||||
}
|
||||
// Datasheet: reset bit self-clears after boot (typ. 50 µs);
|
||||
delay(2);
|
||||
|
||||
@@ -75,39 +72,32 @@ void LSM6DSComponent::setup() {
|
||||
// BDU prevents reading a high-byte from one sample and a low-byte from the next.
|
||||
// IF_INC is set by default after reset but we set it explicitly for clarity.
|
||||
uint8_t ctrl3 = CTRL3_C_IF_INC | CTRL3_C_BDU;
|
||||
if (this->write_register(LSM6DS_REG_CTRL3_C, &ctrl3, 1) != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR("Config failed"));
|
||||
if (!this->setup_check(this->write_register(LSM6DS_REG_CTRL3_C, &ctrl3, 1) == i2c::ERROR_OK,
|
||||
LOG_STR("Config failed")))
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. Configure accelerometer: ODR in bits[7:4], FS in bits[3:2]
|
||||
// Anti-aliasing filter bandwidth is left at power-on default (bits[1:0] = 00 = ODR/2).
|
||||
uint8_t ctrl1_xl = (uint8_t) (this->accel_odr_ << 4) | (uint8_t) (this->accel_range_ << 2);
|
||||
if (this->write_register(LSM6DS_REG_CTRL1_XL, &ctrl1_xl, 1) != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR("Failed to configure accelerometer"));
|
||||
if (!this->setup_check(this->write_register(LSM6DS_REG_CTRL1_XL, &ctrl1_xl, 1) == i2c::ERROR_OK,
|
||||
LOG_STR("Failed to configure accelerometer")))
|
||||
return;
|
||||
}
|
||||
|
||||
// 5. Configure gyroscope: ODR in bits[7:4], FS_G + FS_125 in bits[3:0]
|
||||
// For ±125 dps: FS_G[2:1]=00 and FS_125(bit1)=1, so gyro_range_ encodes the full nibble.
|
||||
uint8_t ctrl2_g = (uint8_t) (this->gyro_odr_ << 4) | (uint8_t) (this->gyro_range_);
|
||||
if (this->write_register(LSM6DS_REG_CTRL2_G, &ctrl2_g, 1) != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR("Failed to configure gyroscope"));
|
||||
if (!this->setup_check(this->write_register(LSM6DS_REG_CTRL2_G, &ctrl2_g, 1) == i2c::ERROR_OK,
|
||||
LOG_STR("Failed to configure gyroscope")))
|
||||
return;
|
||||
}
|
||||
|
||||
// 6. Ensure accelerometer is in high-performance mode (CTRL6_C bit 4 = XL_HM_MODE = 0)
|
||||
// and gyroscope is in high-performance mode (CTRL7_G bit 7 = G_HM_MODE = 0).
|
||||
// Both default to 0 (high-performance) after reset, but write explicitly.
|
||||
uint8_t zero = 0x00;
|
||||
if (this->write_register(LSM6DS_REG_CTRL6_C, &zero, 1) != i2c::ERROR_OK) {
|
||||
this->mark_failed();
|
||||
if (!this->setup_check(this->write_register(LSM6DS_REG_CTRL6_C, &zero, 1) == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
if (this->write_register(LSM6DS_REG_CTRL7_G, &zero, 1) != i2c::ERROR_OK) {
|
||||
this->mark_failed();
|
||||
if (!this->setup_check(this->write_register(LSM6DS_REG_CTRL7_G, &zero, 1) == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void LSM6DSComponent::dump_config() {
|
||||
|
||||
@@ -38,17 +38,14 @@ bool M5StackUnitBldc::read_command_raw_(float *value) {
|
||||
}
|
||||
|
||||
void M5StackUnitBldc::setup() {
|
||||
if (!this->write_byte(REG_MODE, static_cast<uint8_t>(this->control_mode_))) {
|
||||
this->mark_failed(LOG_STR("Failed to write control mode"));
|
||||
if (!this->setup_check(this->write_byte(REG_MODE, static_cast<uint8_t>(this->control_mode_)),
|
||||
LOG_STR("Failed to write control mode")))
|
||||
return;
|
||||
}
|
||||
// The unit keeps driving its last command across an ESP reboot, so the cache and the number start from it, and
|
||||
// a running motor only takes the direction through the stop and restore sequence
|
||||
float command;
|
||||
if (!this->read_command_raw_(&command)) {
|
||||
this->mark_failed(LOG_STR("Failed to read the motor command"));
|
||||
if (!this->setup_check(this->read_command_raw_(&command), LOG_STR("Failed to read the motor command")))
|
||||
return;
|
||||
}
|
||||
this->last_command_ = command;
|
||||
// REG_DIRECTION is readable (datasheet register 0x60, W/R), so a boot that already matches the configured
|
||||
// direction skips the stop-and-restore cycle entirely instead of spinning the motor down for no reason. A
|
||||
@@ -71,10 +68,9 @@ void M5StackUnitBldc::setup() {
|
||||
#endif
|
||||
|
||||
const uint8_t motor_config[2] = {static_cast<uint8_t>(this->motor_model_), this->pole_pairs_};
|
||||
if (!this->write_reg_(REG_MOTOR_CONFIG, motor_config)) {
|
||||
this->mark_failed(LOG_STR("Failed to write motor model/pole pairs"));
|
||||
if (!this->setup_check(this->write_reg_(REG_MOTOR_CONFIG, motor_config),
|
||||
LOG_STR("Failed to write motor model/pole pairs")))
|
||||
return;
|
||||
}
|
||||
if (this->has_pid_ && !this->write_reg_(REG_PID, this->pid_)) {
|
||||
this->mark_failed(LOG_STR("Failed to write PID gains"));
|
||||
return;
|
||||
|
||||
@@ -20,10 +20,8 @@ const uint8_t MASK_CURRENT_PIN = 0x0F;
|
||||
**************************************/
|
||||
void MAX6956::setup() {
|
||||
uint8_t configuration;
|
||||
if (!this->read_reg_(MAX6956_CONFIGURATION, &configuration)) {
|
||||
this->mark_failed();
|
||||
if (!this->setup_check(this->read_reg_(MAX6956_CONFIGURATION, &configuration)))
|
||||
return;
|
||||
}
|
||||
|
||||
write_brightness_global();
|
||||
write_brightness_mode();
|
||||
|
||||
@@ -9,10 +9,8 @@ static constexpr uint8_t IOCON_ODR = 0x04; // Open-drain output for INT pin
|
||||
|
||||
void MCP23008::setup() {
|
||||
uint8_t iocon;
|
||||
if (!this->read_reg(mcp23x08_base::MCP23X08_IOCON, &iocon)) {
|
||||
this->mark_failed();
|
||||
if (!this->setup_check(this->read_reg(mcp23x08_base::MCP23X08_IOCON, &iocon)))
|
||||
return;
|
||||
}
|
||||
|
||||
// Read current output register state
|
||||
this->read_reg(mcp23x08_base::MCP23X08_OLAT, &this->olat_);
|
||||
|
||||
@@ -14,10 +14,8 @@ void MCP23016::setup() {
|
||||
// to the even register (IOCON0) in the same pair. Starting from the odd
|
||||
// address gives the correct byte order for 1 << pin mapping:
|
||||
// high byte = port 1 (pins 8-15), low byte = port 0 (pins 0-7).
|
||||
if (!this->read_reg_(MCP23016_IOCON1, &iocon)) {
|
||||
this->mark_failed();
|
||||
if (!this->setup_check(this->read_reg_(MCP23016_IOCON1, &iocon)))
|
||||
return;
|
||||
}
|
||||
|
||||
// Read current output register state
|
||||
this->read_reg_(MCP23016_OLAT1, &this->olat_);
|
||||
|
||||
@@ -10,10 +10,8 @@ static constexpr uint8_t IOCON_ODR = 0x04; // Open-drain output for INT pin
|
||||
|
||||
void MCP23017::setup() {
|
||||
uint8_t iocon;
|
||||
if (!this->read_reg(mcp23x17_base::MCP23X17_IOCONA, &iocon)) {
|
||||
this->mark_failed();
|
||||
if (!this->setup_check(this->read_reg(mcp23x17_base::MCP23X17_IOCONA, &iocon)))
|
||||
return;
|
||||
}
|
||||
|
||||
// Read current output register state
|
||||
this->read_reg(mcp23x17_base::MCP23X17_OLATA, &this->olat_a_);
|
||||
|
||||
@@ -7,10 +7,8 @@ ESPHOME_LOG_TAG(TAG, "mcp4725");
|
||||
|
||||
void MCP4725::setup() {
|
||||
auto err = this->write(nullptr, 0);
|
||||
if (err != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(err == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MCP4725::dump_config() { LOG_I2C_DEVICE(this); }
|
||||
|
||||
@@ -9,10 +9,8 @@ ESPHOME_LOG_TAG(TAG, "mcp4728");
|
||||
|
||||
void MCP4728Component::setup() {
|
||||
auto err = this->write(nullptr, 0);
|
||||
if (err != i2c::ERROR_OK) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(err == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MCP4728Component::dump_config() {
|
||||
|
||||
@@ -53,10 +53,8 @@ void MCP9600Component::setup() {
|
||||
success &= this->write_byte_16(MCP9600_REGISTER_ALERT3_LIMIT, 0x0000);
|
||||
success &= this->write_byte_16(MCP9600_REGISTER_ALERT4_LIMIT, 0x0000);
|
||||
|
||||
if (!success) {
|
||||
this->mark_failed(LOG_STR("Failed to update device configuration"));
|
||||
if (!this->setup_check(success, LOG_STR("Failed to update device configuration")))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MCP9600Component::dump_config() {
|
||||
|
||||
@@ -18,20 +18,16 @@ ESPHOME_LOG_TAG(TAG, "mcp9808");
|
||||
|
||||
void MCP9808Sensor::setup() {
|
||||
uint16_t manu = 0;
|
||||
if (!this->read_byte_16(MCP9808_REG_MANUF_ID, &manu)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_byte_16(MCP9808_REG_MANUF_ID, &manu)))
|
||||
return;
|
||||
}
|
||||
if (manu != MCP9808_MANUF_ID) {
|
||||
ESP_LOGE(TAG, "Incorrect manufacturer ID (%X) for '%s'", manu, LOG_STR_ARG(this->get_log_name()));
|
||||
this->mark_failed(LOG_STR("Wrong chip ID"));
|
||||
return;
|
||||
}
|
||||
uint16_t dev_id = 0;
|
||||
if (!this->read_byte_16(MCP9808_REG_DEVICE_ID, &dev_id)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_byte_16(MCP9808_REG_DEVICE_ID, &dev_id)))
|
||||
return;
|
||||
}
|
||||
if (dev_id != MCP9808_DEV_ID) {
|
||||
ESP_LOGE(TAG, "Incorrect device ID (%X) for '%s'", dev_id, LOG_STR_ARG(this->get_log_name()));
|
||||
this->mark_failed(LOG_STR("Wrong chip ID"));
|
||||
|
||||
@@ -145,7 +145,7 @@ void MicroNova::send_current_command_() {
|
||||
write_len = 4;
|
||||
write_data[2] = this->current_command_.data;
|
||||
// calculate checksum
|
||||
write_data[3] = write_data[0] + write_data[1] + write_data[2];
|
||||
write_data[3] = sum_bytes(write_data, 3);
|
||||
ESP_LOGV_HEX(TAG, write_data, sizeof(write_data), sizeof(write_data), "Sending write request [%s]");
|
||||
} else {
|
||||
write_len = 2;
|
||||
|
||||
@@ -93,8 +93,7 @@ bool MLX90614Component::write_register_(uint8_t reg, uint16_t data) {
|
||||
|
||||
// 3. Write the new value
|
||||
if (data != 0) {
|
||||
buf[2] = data & 0xFF;
|
||||
buf[3] = data >> 8;
|
||||
put_le16(buf + 2, data);
|
||||
buf[4] = crc8_pec(buf, 4);
|
||||
ec = this->write_register(reg, buf + 2, 3);
|
||||
if (ec != i2c::ERROR_OK) {
|
||||
|
||||
@@ -36,28 +36,22 @@ void MMC5603Component::setup() {
|
||||
if (!this->check_chip_id(this, MMC56X3_PRODUCT_ID, 0x00, static_cast<uint8_t>(~MMC56X3_CHIP_ID)))
|
||||
return;
|
||||
|
||||
if (!this->write_byte(MMC56X3_CTRL1_REG, 0x80)) { // turn on set bit
|
||||
this->mark_failed(LOG_STR("Control 1 failed for set bit"));
|
||||
// turn on set bit
|
||||
if (!this->setup_check(this->write_byte(MMC56X3_CTRL1_REG, 0x80), LOG_STR("Control 1 failed for set bit")))
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->write_byte(MMC56X3_CTRL0_REG, 0x08)) { // turn on set bit
|
||||
this->mark_failed(LOG_STR("Control 0 failed for set bit"));
|
||||
// turn on set bit
|
||||
if (!this->setup_check(this->write_byte(MMC56X3_CTRL0_REG, 0x08), LOG_STR("Control 0 failed for set bit")))
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->write_byte(MMC56X3_CTRL0_REG, 0x10)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(MMC56X3_CTRL0_REG, 0x10)))
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t ctrl_2 = 0;
|
||||
|
||||
ctrl_2 &= ~0x10; // turn off cmm_en bit
|
||||
if (!this->write_byte(MMC56X3_CTRL2_REG, ctrl_2)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(MMC56X3_CTRL2_REG, ctrl_2)))
|
||||
return;
|
||||
}
|
||||
}
|
||||
void MMC5603Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "MMC5603:");
|
||||
|
||||
@@ -37,9 +37,7 @@ struct ModbusFrame {
|
||||
uint8_t *buf = this->data.init(pdu_len + 3);
|
||||
buf[0] = address;
|
||||
memcpy(buf + 1, pdu, pdu_len);
|
||||
auto crc = crc16(buf, pdu_len + 1);
|
||||
buf[pdu_len + 1] = crc >> 0;
|
||||
buf[pdu_len + 2] = crc >> 8;
|
||||
put_le16(buf + pdu_len + 1, crc16(buf, pdu_len + 1));
|
||||
}
|
||||
|
||||
uint16_t size() const { return static_cast<uint16_t>(this->data.size()); }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "modbus_controller.h"
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#include <cstring>
|
||||
@@ -586,9 +587,7 @@ ModbusCommandItem ModbusCommandItem::create_write_multiple_command(ModbusControl
|
||||
};
|
||||
uint8_t *p = cmd.payload.init(values.size() * 2);
|
||||
for (auto v : values) {
|
||||
auto decoded_value = decode_value(v);
|
||||
*p++ = decoded_value[0];
|
||||
*p++ = decoded_value[1];
|
||||
p = put_be16(p, v);
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
@@ -635,10 +634,7 @@ ModbusCommandItem ModbusCommandItem::create_write_single_command(ModbusControlle
|
||||
modbusdevice->on_write_register_response(register_type, start_address, data);
|
||||
};
|
||||
|
||||
auto decoded_value = decode_value(value);
|
||||
uint8_t *p = cmd.payload.init(2);
|
||||
p[0] = decoded_value[0];
|
||||
p[1] = decoded_value[1];
|
||||
put_be16(cmd.payload.init(2), value);
|
||||
return cmd;
|
||||
}
|
||||
|
||||
@@ -673,8 +669,7 @@ ModbusCommandItem ModbusCommandItem::create_custom_command(
|
||||
}
|
||||
uint8_t *p = cmd.payload.init(values.size() * 2);
|
||||
for (auto v : values) {
|
||||
*p++ = (v >> 8) & 0xFF;
|
||||
*p++ = v & 0xFF;
|
||||
p = put_be16(p, v);
|
||||
}
|
||||
|
||||
return cmd;
|
||||
|
||||
@@ -15,10 +15,8 @@ void MPR121Component::setup() {
|
||||
// soft reset device
|
||||
this->write_byte(MPR121_SOFTRESET, 0x63);
|
||||
this->set_timeout(100, [this]() {
|
||||
if (!this->write_byte(MPR121_ECR, 0x0)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_byte(MPR121_ECR, 0x0)))
|
||||
return;
|
||||
}
|
||||
// set touch sensitivity for all 12 channels
|
||||
for (auto *channel : this->channels_) {
|
||||
channel->setup();
|
||||
|
||||
@@ -18,16 +18,12 @@ static const uint8_t MS5611_CMD_CONV_D2 = 0x50;
|
||||
static const uint8_t MS5611_CMD_READ_PROM = 0xA2;
|
||||
|
||||
void MS5611Component::setup() {
|
||||
if (!this->write_bytes(MS5611_CMD_RESET, nullptr, 0)) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->write_bytes(MS5611_CMD_RESET, nullptr, 0)))
|
||||
return;
|
||||
}
|
||||
this->set_timeout(100, [this]() {
|
||||
for (uint8_t offset = 0; offset < 6; offset++) {
|
||||
if (!this->read_byte_16(MS5611_CMD_READ_PROM + (offset * 2), &this->prom_[offset])) {
|
||||
this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
if (!this->setup_check(this->read_byte_16(MS5611_CMD_READ_PROM + (offset * 2), &this->prom_[offset])))
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,10 +15,8 @@ static constexpr uint8_t CONFIG_REG_COUNT = sizeof(CONFIG_REGS);
|
||||
|
||||
void MT6701I2CComponent::setup() {
|
||||
uint16_t count;
|
||||
if (!this->read_count(count)) {
|
||||
this->mark_failed(LOG_STR("not responding on I2C"));
|
||||
if (!this->setup_check(this->read_count(count), LOG_STR("not responding on I2C")))
|
||||
return;
|
||||
}
|
||||
this->apply_config_();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,10 +71,8 @@ void NAU7802Sensor::setup() {
|
||||
pu_ctrl |= PU_CTRL_POWERUP_DIGITAL;
|
||||
|
||||
delay(1);
|
||||
if (!(pu_ctrl.get() & PU_CTRL_POWERUP_READY)) {
|
||||
this->mark_failed(LOG_STR("Failed to reset sensor during setup()"));
|
||||
if (!this->setup_check(pu_ctrl.get() & PU_CTRL_POWERUP_READY, LOG_STR("Failed to reset sensor during setup()")))
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t gcal = (uint32_t) (std::round(this->gain_calibration_ * (1 << GCAL1_FRACTIONAL)));
|
||||
this->write_value_(OCAL1_B2_REG, 3, this->offset_calibration_);
|
||||
|
||||
@@ -138,8 +138,7 @@ bool PCA9554Component::read_inputs_() {
|
||||
|
||||
bool PCA9554Component::write_address_(uint8_t address, uint16_t value) {
|
||||
uint8_t outputs[2];
|
||||
outputs[0] = (uint8_t) value;
|
||||
outputs[1] = (uint8_t) (value >> 8);
|
||||
put_le16(outputs, value);
|
||||
const i2c::ErrorCode err = this->write_register(address, outputs, this->reg_width_);
|
||||
if (!this->status_comm_result(err == i2c::ERROR_OK)) {
|
||||
ESP_LOGE(TAG, "write_register(): I2C I/O error: %d", (int) err);
|
||||
|
||||
@@ -124,10 +124,8 @@ void PCA9685Output::loop() {
|
||||
phase_end);
|
||||
|
||||
uint8_t data[4];
|
||||
data[0] = phase_begin & 0xFF;
|
||||
data[1] = (phase_begin >> 8) & 0xFF;
|
||||
data[2] = phase_end & 0xFF;
|
||||
data[3] = (phase_end >> 8) & 0xFF;
|
||||
put_le16(data, phase_begin);
|
||||
put_le16(data + 2, phase_end);
|
||||
|
||||
uint8_t reg = PCA9685_REGISTER_LED0 + 4 * channel;
|
||||
if (!this->write_bytes(reg, data, 4)) {
|
||||
|
||||
@@ -75,8 +75,7 @@ bool PCF8574Component::write_gpio_() {
|
||||
value |= ~this->mode_mask_;
|
||||
|
||||
uint8_t data[2];
|
||||
data[0] = value;
|
||||
data[1] = value >> 8;
|
||||
put_le16(data, value);
|
||||
return this->status_comm_result(this->write(data, this->pcf8575_ ? 2 : 1) == i2c::ERROR_OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ from esphome import pins
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import i2c
|
||||
from esphome.components.audio_dac import AudioDac
|
||||
from esphome.components.const import CONF_VOLUME_MAX_DB, CONF_VOLUME_MIN_DB
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
CONF_BITS_PER_SAMPLE,
|
||||
@@ -19,8 +20,6 @@ DEPENDENCIES = ["i2c"]
|
||||
|
||||
CONF_ANALOG_GAIN = "analog_gain"
|
||||
CONF_CHANNEL_MIX = "channel_mix"
|
||||
CONF_VOLUME_MIN_DB = "volume_min_db"
|
||||
CONF_VOLUME_MAX_DB = "volume_max_db"
|
||||
|
||||
pcm5122_ns = cg.esphome_ns.namespace("pcm5122")
|
||||
PCM5122 = pcm5122_ns.class_("PCM5122", AudioDac, cg.Component, i2c.I2CDevice)
|
||||
|
||||
@@ -31,9 +31,9 @@ void PCM5122::setup() {
|
||||
|
||||
// Ignore clock halt detection; enable clock divider autoset
|
||||
optional<uint8_t> err_detect = this->read_byte(PCM5122_REG_ERROR_DETECT);
|
||||
// Hand-written so clang-tidy sees the has_value() check before value()
|
||||
if (!err_detect.has_value()) {
|
||||
ESP_LOGE(TAG, "Failed to read ERROR_DETECT");
|
||||
this->mark_failed();
|
||||
this->mark_failed(LOG_STR("Failed to read ERROR_DETECT"));
|
||||
return;
|
||||
}
|
||||
uint8_t err_detect_val = err_detect.value();
|
||||
@@ -57,26 +57,19 @@ void PCM5122::setup() {
|
||||
}
|
||||
this->reg(PCM5122_REG_AUDIO_FORMAT) = PCM5122_AUDIO_FORMAT_I2S | alen;
|
||||
|
||||
if (!this->write_channel_mix_()) {
|
||||
this->mark_failed();
|
||||
if (!this->setup_check(this->write_channel_mix_()))
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->write_analog_gain_()) {
|
||||
this->mark_failed();
|
||||
if (!this->setup_check(this->write_analog_gain_()))
|
||||
return;
|
||||
}
|
||||
|
||||
// PLL reference clock: BCK
|
||||
if (!this->select_page_(0)) {
|
||||
ESP_LOGE(TAG, "Write failed");
|
||||
this->mark_failed();
|
||||
if (!this->setup_check(this->select_page_(0), LOG_STR("Write failed")))
|
||||
return;
|
||||
}
|
||||
optional<uint8_t> pll_ref = this->read_byte(PCM5122_REG_PLL_REF);
|
||||
// Hand-written so clang-tidy sees the has_value() check before value()
|
||||
if (!pll_ref.has_value()) {
|
||||
ESP_LOGE(TAG, "Failed to read PLL_REF");
|
||||
this->mark_failed();
|
||||
this->mark_failed(LOG_STR("Failed to read PLL_REF"));
|
||||
return;
|
||||
}
|
||||
uint8_t pll_ref_val = pll_ref.value();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "esphome/components/display/display_color_utils.h"
|
||||
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
@@ -25,8 +26,7 @@ static constexpr uint8_t DEFAULT_IOUT = 75; // per-channel LED current / whi
|
||||
// Pack a `0xAA len cmd data 0xBB` packet into buf; returns the packet length.
|
||||
static inline size_t build_packet(uint8_t *buf, uint8_t cmd, const uint8_t *data, uint16_t len) {
|
||||
buf[0] = PACKET_HEAD;
|
||||
buf[1] = static_cast<uint8_t>(len & 0xFF);
|
||||
buf[2] = static_cast<uint8_t>((len >> 8) & 0xFF);
|
||||
put_le16(buf + 1, len);
|
||||
buf[3] = cmd;
|
||||
if (data != nullptr && len > 0)
|
||||
std::memcpy(buf + PACKET_HEADER_LEN, data, len);
|
||||
@@ -36,10 +36,8 @@ static inline size_t build_packet(uint8_t *buf, uint8_t cmd, const uint8_t *data
|
||||
|
||||
// Fill `total` bytes at buf with a single UNUSED padding packet.
|
||||
static inline void pad_unused(uint8_t *buf, size_t total) {
|
||||
const uint16_t len = static_cast<uint16_t>(total - PACKET_STATIC_LEN);
|
||||
buf[0] = PACKET_HEAD;
|
||||
buf[1] = static_cast<uint8_t>(len & 0xFF);
|
||||
buf[2] = static_cast<uint8_t>((len >> 8) & 0xFF);
|
||||
put_le16(buf + 1, total - PACKET_STATIC_LEN);
|
||||
buf[3] = CMD_UNUSED;
|
||||
buf[total - 1] = PACKET_TAIL;
|
||||
}
|
||||
@@ -69,8 +67,7 @@ void Pixoo::setup() {
|
||||
std::memset(this->frame_buffer_, 0, this->frame_size_);
|
||||
// Pre-build the constant DATA-packet framing; only the RGB888 payload changes per frame.
|
||||
this->frame_buffer_[0] = PACKET_HEAD;
|
||||
this->frame_buffer_[1] = static_cast<uint8_t>(this->data_size_ & 0xFF);
|
||||
this->frame_buffer_[2] = static_cast<uint8_t>((this->data_size_ >> 8) & 0xFF);
|
||||
put_le16(this->frame_buffer_ + 1, this->data_size_);
|
||||
this->frame_buffer_[3] = CMD_DATA;
|
||||
this->frame_buffer_[PACKET_HEADER_LEN + this->data_size_] = PACKET_TAIL;
|
||||
pad_unused(this->frame_buffer_ + this->data_size_ + PACKET_STATIC_LEN, DMA_CHUNK);
|
||||
|
||||
Loaded 100 of 191 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user