mirror of
https://github.com/esphome/esphome.git
synced 2026-10-22 05:46:12 +00:00
Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
708a389ee0 | ||
|
|
d24d101484 | ||
|
|
24f5ae6721 | ||
|
|
ab3a46d66b | ||
|
|
cacca57ee3 | ||
|
|
97b5170cfa | ||
|
|
42276e3f67 | ||
|
|
28defaa8c0 | ||
|
|
c608a9a565 | ||
|
|
053fd535ad | ||
|
|
abbc935586 | ||
|
|
5a020fbe54 | ||
|
|
0e36710996 | ||
|
|
8145b7ae93 |
@@ -6,19 +6,11 @@ namespace esphome::as3935_i2c {
|
||||
ESPHOME_LOG_TAG(TAG, "as3935_i2c");
|
||||
|
||||
void I2CAS3935Component::write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_pos) {
|
||||
uint8_t write_reg;
|
||||
if (!this->read_byte(reg, &write_reg)) {
|
||||
this->mark_failed();
|
||||
ESP_LOGW(TAG, "read_byte failed - increase log level for more details!");
|
||||
return;
|
||||
}
|
||||
|
||||
write_reg &= (~mask);
|
||||
write_reg |= (bits << start_pos);
|
||||
|
||||
if (!this->write_byte(reg, write_reg)) {
|
||||
ESP_LOGW(TAG, "write_byte failed - increase log level for more details!");
|
||||
return;
|
||||
const uint8_t value = bits << start_pos;
|
||||
// Bits of value outside mask were ORed in before, so they stay part of the update
|
||||
// Also called at runtime, so a transient bus error only warns, like read_register()
|
||||
if (!this->update_register(reg, mask | value, value)) {
|
||||
ESP_LOGW(TAG, "Failed to update register 0x%02X", reg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -240,17 +240,11 @@ bool AS7341Component::write_register_bit(uint8_t address, bool value, uint8_t bi
|
||||
}
|
||||
|
||||
bool AS7341Component::set_register_bit(uint8_t address, uint8_t bit_position) {
|
||||
uint8_t data;
|
||||
this->read_byte(address, &data);
|
||||
data |= (1 << bit_position);
|
||||
return this->write_byte(address, data);
|
||||
return this->update_register(address, 1 << bit_position, 1 << bit_position);
|
||||
}
|
||||
|
||||
bool AS7341Component::clear_register_bit(uint8_t address, uint8_t bit_position) {
|
||||
uint8_t data;
|
||||
this->read_byte(address, &data);
|
||||
data &= ~(1 << bit_position);
|
||||
return this->write_byte(address, data);
|
||||
return this->update_register(address, 1 << bit_position, 0);
|
||||
}
|
||||
|
||||
uint16_t AS7341Component::swap_bytes(uint16_t data) { return (data >> 8) | (data << 8); }
|
||||
|
||||
@@ -264,12 +264,7 @@ bool AS734XComponent::select_bank_(uint8_t reg) {
|
||||
}
|
||||
|
||||
bool AS734XComponent::update_bits_(uint8_t reg, uint8_t mask, bool value) {
|
||||
uint8_t data = 0;
|
||||
if (!this->select_bank_(reg) || !this->read_byte(reg, &data)) {
|
||||
return false;
|
||||
}
|
||||
data = value ? (data | mask) : (data & ~mask);
|
||||
return this->write_byte(reg, data);
|
||||
return this->select_bank_(reg) && this->update_register(reg, mask, value ? mask : 0);
|
||||
}
|
||||
|
||||
// The exposure is applied before every measurement, so a gain, ATIME or ASTEP changed at runtime
|
||||
|
||||
@@ -138,49 +138,24 @@ bool BME680Component::setup_registers_() {
|
||||
this->calibration_.ambient_temperature = 25; // prime ambient temperature
|
||||
|
||||
// Config register
|
||||
uint8_t config_register;
|
||||
if (!this->read_byte(BME680_REGISTER_CONFIG, &config_register)) {
|
||||
return false;
|
||||
}
|
||||
config_register &= ~0b00011100;
|
||||
config_register |= (this->iir_filter_ & 0b111) << 2;
|
||||
if (!this->write_byte(BME680_REGISTER_CONFIG, config_register)) {
|
||||
if (!this->update_register(BME680_REGISTER_CONFIG, 0b00011100, (this->iir_filter_ & 0b111) << 2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Humidity control register
|
||||
uint8_t hum_control;
|
||||
if (!this->read_byte(BME680_REGISTER_CONTROL_HUMIDITY, &hum_control)) {
|
||||
return false;
|
||||
}
|
||||
hum_control &= ~0b00000111;
|
||||
hum_control |= this->humidity_oversampling_ & 0b111;
|
||||
if (!this->write_byte(BME680_REGISTER_CONTROL_HUMIDITY, hum_control)) {
|
||||
if (!this->update_register(BME680_REGISTER_CONTROL_HUMIDITY, 0b00000111, this->humidity_oversampling_ & 0b111)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Gas 1 control register
|
||||
uint8_t gas1_control;
|
||||
if (!this->read_byte(BME680_REGISTER_CONTROL_GAS1, &gas1_control)) {
|
||||
return false;
|
||||
}
|
||||
gas1_control &= ~0b00011111;
|
||||
gas1_control |= 1 << 4;
|
||||
gas1_control |= 0; // profile 0
|
||||
if (!this->write_byte(BME680_REGISTER_CONTROL_GAS1, gas1_control)) {
|
||||
// Gas 1 control register: run gas, heater profile 0
|
||||
if (!this->update_register(BME680_REGISTER_CONTROL_GAS1, 0b00011111, 1 << 4)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool heat_off = this->heater_temperature_ == 0 || this->heater_duration_ == 0;
|
||||
|
||||
// Gas 0 control register
|
||||
uint8_t gas0_control;
|
||||
if (!this->read_byte(BME680_REGISTER_CONTROL_GAS0, &gas0_control)) {
|
||||
return false;
|
||||
}
|
||||
gas0_control &= ~0b00001000;
|
||||
gas0_control |= heat_off << 3;
|
||||
if (!this->write_byte(BME680_REGISTER_CONTROL_GAS0, gas0_control)) {
|
||||
if (!this->update_register(BME680_REGISTER_CONTROL_GAS0, 0b00001000, heat_off << 3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,13 +28,10 @@ bool BQ25186Component::write_register_(uint8_t reg, uint8_t value) {
|
||||
}
|
||||
|
||||
bool BQ25186Component::update_register_(uint8_t reg, uint8_t mask, uint8_t value) {
|
||||
uint8_t reg_value;
|
||||
if (!this->read_byte(reg, ®_value)) {
|
||||
ESP_LOGW(TAG, "Failed to read register 0x%02X", reg);
|
||||
return false;
|
||||
}
|
||||
reg_value = (reg_value & ~mask) | (value & mask);
|
||||
return this->write_register_(reg, reg_value);
|
||||
if (this->update_register(reg, mask, value))
|
||||
return true;
|
||||
ESP_LOGW(TAG, "Failed to update register 0x%02X", reg);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t BQ25186Component::expected_register_(size_t index) const {
|
||||
|
||||
@@ -71,12 +71,12 @@ class BQ25186Component : public PollingComponent, public i2c::I2CDevice {
|
||||
|
||||
protected:
|
||||
bool write_register_(uint8_t reg, uint8_t value);
|
||||
bool update_register_(uint8_t reg, uint8_t mask, uint8_t value);
|
||||
uint8_t expected_register_(size_t index) const;
|
||||
bool config_matches_(const BQ25186StatusRegisters ®s) const;
|
||||
#ifdef USE_BQ25186_PG_GPO
|
||||
void check_pg_gpo_(const BQ25186StatusRegisters &status, bool &pending);
|
||||
#endif
|
||||
bool update_register_(uint8_t reg, uint8_t mask, uint8_t value);
|
||||
|
||||
#ifdef BQ25186_BINARY_SENSOR_COUNT
|
||||
StaticVector<BQ25186BinarySensor *, BQ25186_BINARY_SENSOR_COUNT> binary_sensors_;
|
||||
|
||||
@@ -42,10 +42,8 @@ void CAP1188Component::finish_setup_() {
|
||||
}
|
||||
|
||||
// Set sensitivity
|
||||
uint8_t sensitivity = 0;
|
||||
this->read_byte(CAP1188_SENSITVITY, &sensitivity);
|
||||
sensitivity = sensitivity & 0x0f;
|
||||
this->write_byte(CAP1188_SENSITVITY, sensitivity | this->touch_threshold_);
|
||||
// The threshold replaces the upper nibble and is ORed into the lower one, as before
|
||||
this->update_register(CAP1188_SENSITVITY, 0xF0 | this->touch_threshold_, this->touch_threshold_);
|
||||
|
||||
// Allow multiple touches
|
||||
this->write_byte(CAP1188_MULTI_TOUCH, this->allow_multiple_touches_);
|
||||
|
||||
@@ -50,7 +50,7 @@ void ES7210::setup() {
|
||||
ES7210_ERROR_FAILED(this->write_byte(ES7210_ADC34_HPF1_REG21, 0x2a));
|
||||
|
||||
// Secondary I2S mode settings
|
||||
ES7210_ERROR_FAILED(this->es7210_update_reg_bit_(ES7210_MODE_CONFIG_REG08, 0x01, 0x00));
|
||||
ES7210_ERROR_FAILED(this->update_register(ES7210_MODE_CONFIG_REG08, 0x01, 0x00));
|
||||
|
||||
// Configure analog power
|
||||
ES7210_ERROR_FAILED(this->write_byte(ES7210_ANALOG_REG40, 0xC3));
|
||||
@@ -141,39 +141,39 @@ bool ES7210::configure_sample_rate_() {
|
||||
|
||||
bool ES7210::configure_mic_gain_() {
|
||||
for (uint8_t i = 0; i < 4; ++i) {
|
||||
ES7210_ERROR_CHECK(this->es7210_update_reg_bit_(ES7210_MIC1_GAIN_REG43 + i, 0x10, 0x00));
|
||||
ES7210_ERROR_CHECK(this->update_register(ES7210_MIC1_GAIN_REG43 + i, 0x10, 0x00));
|
||||
}
|
||||
ES7210_ERROR_CHECK(this->write_byte(ES7210_MIC12_POWER_REG4B, 0xff));
|
||||
ES7210_ERROR_CHECK(this->write_byte(ES7210_MIC34_POWER_REG4C, 0xff));
|
||||
|
||||
// Configure mic 1
|
||||
ES7210_ERROR_CHECK(this->es7210_update_reg_bit_(ES7210_CLOCK_OFF_REG01, 0x0b, 0x00));
|
||||
ES7210_ERROR_CHECK(this->update_register(ES7210_CLOCK_OFF_REG01, 0x0b, 0x00));
|
||||
ES7210_ERROR_CHECK(this->write_byte(ES7210_MIC12_POWER_REG4B, 0x00));
|
||||
ES7210_ERROR_CHECK(this->es7210_update_reg_bit_(ES7210_MIC1_GAIN_REG43, 0x10, 0x10));
|
||||
ES7210_ERROR_CHECK(this->es7210_update_reg_bit_(ES7210_MIC1_GAIN_REG43, 0x0f,
|
||||
this->es7210_gain_reg_value_(this->channel_gains_[0])));
|
||||
ES7210_ERROR_CHECK(this->update_register(ES7210_MIC1_GAIN_REG43, 0x10, 0x10));
|
||||
ES7210_ERROR_CHECK(
|
||||
this->update_register(ES7210_MIC1_GAIN_REG43, 0x0f, this->es7210_gain_reg_value_(this->channel_gains_[0])));
|
||||
|
||||
// Configure mic 2
|
||||
ES7210_ERROR_CHECK(this->es7210_update_reg_bit_(ES7210_CLOCK_OFF_REG01, 0x0b, 0x00));
|
||||
ES7210_ERROR_CHECK(this->update_register(ES7210_CLOCK_OFF_REG01, 0x0b, 0x00));
|
||||
ES7210_ERROR_CHECK(this->write_byte(ES7210_MIC12_POWER_REG4B, 0x00));
|
||||
ES7210_ERROR_CHECK(this->es7210_update_reg_bit_(ES7210_MIC2_GAIN_REG44, 0x10, 0x10));
|
||||
ES7210_ERROR_CHECK(this->es7210_update_reg_bit_(ES7210_MIC2_GAIN_REG44, 0x0f,
|
||||
this->es7210_gain_reg_value_(this->channel_gains_[1])));
|
||||
ES7210_ERROR_CHECK(this->update_register(ES7210_MIC2_GAIN_REG44, 0x10, 0x10));
|
||||
ES7210_ERROR_CHECK(
|
||||
this->update_register(ES7210_MIC2_GAIN_REG44, 0x0f, this->es7210_gain_reg_value_(this->channel_gains_[1])));
|
||||
|
||||
// Configure mic 3
|
||||
// MIC3 uses the ADC3/4 and MIC3/4 clock domains (bits 2 and 4), not the MIC1/2 domains.
|
||||
ES7210_ERROR_CHECK(this->es7210_update_reg_bit_(ES7210_CLOCK_OFF_REG01, 0x15, 0x00));
|
||||
ES7210_ERROR_CHECK(this->update_register(ES7210_CLOCK_OFF_REG01, 0x15, 0x00));
|
||||
ES7210_ERROR_CHECK(this->write_byte(ES7210_MIC34_POWER_REG4C, 0x00));
|
||||
ES7210_ERROR_CHECK(this->es7210_update_reg_bit_(ES7210_MIC3_GAIN_REG45, 0x10, 0x10));
|
||||
ES7210_ERROR_CHECK(this->es7210_update_reg_bit_(ES7210_MIC3_GAIN_REG45, 0x0f,
|
||||
this->es7210_gain_reg_value_(this->channel_gains_[2])));
|
||||
ES7210_ERROR_CHECK(this->update_register(ES7210_MIC3_GAIN_REG45, 0x10, 0x10));
|
||||
ES7210_ERROR_CHECK(
|
||||
this->update_register(ES7210_MIC3_GAIN_REG45, 0x0f, this->es7210_gain_reg_value_(this->channel_gains_[2])));
|
||||
|
||||
// Configure mic 4
|
||||
ES7210_ERROR_CHECK(this->es7210_update_reg_bit_(ES7210_CLOCK_OFF_REG01, 0x15, 0x00));
|
||||
ES7210_ERROR_CHECK(this->update_register(ES7210_CLOCK_OFF_REG01, 0x15, 0x00));
|
||||
ES7210_ERROR_CHECK(this->write_byte(ES7210_MIC34_POWER_REG4C, 0x00));
|
||||
ES7210_ERROR_CHECK(this->es7210_update_reg_bit_(ES7210_MIC4_GAIN_REG46, 0x10, 0x10));
|
||||
ES7210_ERROR_CHECK(this->es7210_update_reg_bit_(ES7210_MIC4_GAIN_REG46, 0x0f,
|
||||
this->es7210_gain_reg_value_(this->channel_gains_[3])));
|
||||
ES7210_ERROR_CHECK(this->update_register(ES7210_MIC4_GAIN_REG46, 0x10, 0x10));
|
||||
ES7210_ERROR_CHECK(
|
||||
this->update_register(ES7210_MIC4_GAIN_REG46, 0x0f, this->es7210_gain_reg_value_(this->channel_gains_[3])));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -227,11 +227,4 @@ bool ES7210::configure_i2s_format_() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ES7210::es7210_update_reg_bit_(uint8_t reg_addr, uint8_t update_bits, uint8_t data) {
|
||||
uint8_t regv;
|
||||
ES7210_ERROR_CHECK(this->read_byte(reg_addr, ®v));
|
||||
regv = (regv & (~update_bits)) | (update_bits & data);
|
||||
return this->write_byte(reg_addr, regv);
|
||||
}
|
||||
|
||||
} // namespace esphome::es7210
|
||||
|
||||
@@ -40,13 +40,6 @@ class ES7210 final : public audio_adc::AudioAdc, public Component, public i2c::I
|
||||
float mic_gain() override { return this->channel_gains_[0]; };
|
||||
|
||||
protected:
|
||||
/// @brief Updates an I2C registry address by modifying the current state
|
||||
/// @param reg_addr I2C register address
|
||||
/// @param update_bits Mask of allowed bits to be modified
|
||||
/// @param data Bit values to be written
|
||||
/// @return True if successful, false otherwise
|
||||
bool es7210_update_reg_bit_(uint8_t reg_addr, uint8_t update_bits, uint8_t data);
|
||||
|
||||
/// @brief Convert floating point mic gain value to register value
|
||||
/// @param mic_gain Gain value to convert
|
||||
/// @return Corresponding register value for specified gain
|
||||
|
||||
@@ -90,24 +90,9 @@ float ES8156::volume() {
|
||||
}
|
||||
|
||||
bool ES8156::set_mute_state_(bool mute_state) {
|
||||
uint8_t reg13;
|
||||
|
||||
this->is_muted_ = mute_state;
|
||||
|
||||
if (!this->read_byte(ES8156_REG13_DAC_MUTE, ®13)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, "Read ES8156_REG13_DAC_MUTE: %u", reg13);
|
||||
|
||||
if (mute_state) {
|
||||
reg13 |= BIT(1) | BIT(2);
|
||||
} else {
|
||||
reg13 &= ~(BIT(1) | BIT(2));
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, "Setting ES8156_REG13_DAC_MUTE to %u (muted: %s)", reg13, YESNO(mute_state));
|
||||
return this->write_byte(ES8156_REG13_DAC_MUTE, reg13);
|
||||
const uint8_t mask = BIT(1) | BIT(2);
|
||||
return this->update_register(ES8156_REG13_DAC_MUTE, mask, mute_state ? mask : 0);
|
||||
}
|
||||
|
||||
} // namespace esphome::es8156
|
||||
|
||||
@@ -133,12 +133,9 @@ bool ES8311::configure_clock_() {
|
||||
}
|
||||
|
||||
// Register 0x02
|
||||
uint8_t reg02;
|
||||
ES8311_ERROR_CHECK(this->read_byte(ES8311_REG02_CLK_MANAGER, ®02));
|
||||
reg02 &= 0x07;
|
||||
reg02 |= (coefficient->pre_div - 1) << 5;
|
||||
reg02 |= encode_pre_mult(coefficient->pre_mult) << 3;
|
||||
ES8311_ERROR_CHECK(this->write_byte(ES8311_REG02_CLK_MANAGER, reg02));
|
||||
ES8311_ERROR_CHECK(
|
||||
this->update_register(ES8311_REG02_CLK_MANAGER, 0xF8,
|
||||
((coefficient->pre_div - 1) << 5) | (encode_pre_mult(coefficient->pre_mult) << 3)));
|
||||
|
||||
// Register 0x03
|
||||
const uint8_t reg03 = (coefficient->fs_mode << 6) | coefficient->adc_osr;
|
||||
@@ -152,27 +149,13 @@ bool ES8311::configure_clock_() {
|
||||
ES8311_ERROR_CHECK(this->write_byte(ES8311_REG05_CLK_MANAGER, reg05));
|
||||
|
||||
// Register 0x06
|
||||
uint8_t reg06;
|
||||
ES8311_ERROR_CHECK(this->read_byte(ES8311_REG06_CLK_MANAGER, ®06));
|
||||
if (this->sclk_inverted_) {
|
||||
uint8_t reg06 = coefficient->bclk_div < 19 ? coefficient->bclk_div - 1 : coefficient->bclk_div;
|
||||
if (this->sclk_inverted_)
|
||||
reg06 |= BIT(5);
|
||||
} else {
|
||||
reg06 &= ~BIT(5);
|
||||
}
|
||||
reg06 &= 0xE0;
|
||||
if (coefficient->bclk_div < 19) {
|
||||
reg06 |= (coefficient->bclk_div - 1) << 0;
|
||||
} else {
|
||||
reg06 |= (coefficient->bclk_div) << 0;
|
||||
}
|
||||
ES8311_ERROR_CHECK(this->write_byte(ES8311_REG06_CLK_MANAGER, reg06));
|
||||
ES8311_ERROR_CHECK(this->update_register(ES8311_REG06_CLK_MANAGER, BIT(5) | 0x1F, reg06));
|
||||
|
||||
// Register 0x07
|
||||
uint8_t reg07;
|
||||
ES8311_ERROR_CHECK(this->read_byte(ES8311_REG07_CLK_MANAGER, ®07));
|
||||
reg07 &= 0xC0;
|
||||
reg07 |= coefficient->lrck_h << 0;
|
||||
ES8311_ERROR_CHECK(this->write_byte(ES8311_REG07_CLK_MANAGER, reg07));
|
||||
ES8311_ERROR_CHECK(this->update_register(ES8311_REG07_CLK_MANAGER, 0x3F, coefficient->lrck_h));
|
||||
|
||||
// Register 0x08
|
||||
ES8311_ERROR_CHECK(this->write_byte(ES8311_REG08_CLK_MANAGER, coefficient->lrck_l));
|
||||
@@ -183,10 +166,7 @@ bool ES8311::configure_clock_() {
|
||||
|
||||
bool ES8311::configure_format_() {
|
||||
// Configure I2S mode and format
|
||||
uint8_t reg00;
|
||||
ES8311_ERROR_CHECK(this->read_byte(ES8311_REG00_RESET, ®00));
|
||||
reg00 &= 0xBF;
|
||||
ES8311_ERROR_CHECK(this->write_byte(ES8311_REG00_RESET, reg00));
|
||||
ES8311_ERROR_CHECK(this->update_register(ES8311_REG00_RESET, BIT(6), 0));
|
||||
|
||||
// Configure SDP in resolution
|
||||
uint8_t reg09 = calculate_resolution_value(this->resolution_in_);
|
||||
@@ -215,21 +195,9 @@ bool ES8311::configure_mic_() {
|
||||
}
|
||||
|
||||
bool ES8311::set_mute_state_(bool mute_state) {
|
||||
uint8_t reg31;
|
||||
|
||||
this->is_muted_ = mute_state;
|
||||
|
||||
if (!this->read_byte(ES8311_REG31_DAC, ®31)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mute_state) {
|
||||
reg31 |= BIT(6) | BIT(5);
|
||||
} else {
|
||||
reg31 &= ~(BIT(6) | BIT(5));
|
||||
}
|
||||
|
||||
return this->write_byte(ES8311_REG31_DAC, reg31);
|
||||
const uint8_t mask = BIT(6) | BIT(5);
|
||||
return this->update_register(ES8311_REG31_DAC, mask, mute_state ? mask : 0);
|
||||
}
|
||||
|
||||
} // namespace esphome::es8311
|
||||
|
||||
@@ -265,12 +265,8 @@ bool FUSB302B::init_chip_() {
|
||||
return false;
|
||||
|
||||
// Let the chip retransmit unacknowledged messages up to 3 times
|
||||
uint8_t control3 = 0;
|
||||
if (!this->read_byte(FUSB_CONTROL3, &control3))
|
||||
return false;
|
||||
control3 =
|
||||
(control3 & ~FUSB_CONTROL3_N_RETRIES_MASK) | (3 << FUSB_CONTROL3_N_RETRIES_SHIFT) | FUSB_CONTROL3_AUTO_RETRY;
|
||||
if (!this->write_byte(FUSB_CONTROL3, control3))
|
||||
if (!this->update_register(FUSB_CONTROL3, FUSB_CONTROL3_N_RETRIES_MASK | FUSB_CONTROL3_AUTO_RETRY,
|
||||
(3 << FUSB_CONTROL3_N_RETRIES_SHIFT) | FUSB_CONTROL3_AUTO_RETRY))
|
||||
return false;
|
||||
|
||||
if (!this->write_byte(FUSB_POWER, FUSB_POWER_ALL))
|
||||
|
||||
@@ -32,49 +32,22 @@ bool MPU6050Component::setup_registers_() {
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, " Setting up Power Management");
|
||||
// Setup power management
|
||||
uint8_t power_management;
|
||||
if (!this->read_byte(MPU6050_REGISTER_POWER_MANAGEMENT_1, &power_management)) {
|
||||
return false;
|
||||
}
|
||||
ESP_LOGV(TAG, " Input power_management: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(power_management));
|
||||
// Set clock source - X-Gyro
|
||||
power_management &= 0b11111000;
|
||||
power_management |= MPU6050_CLOCK_SOURCE_X_GYRO;
|
||||
// Disable sleep
|
||||
power_management &= ~(1 << MPU6050_BIT_SLEEP_ENABLED);
|
||||
// Enable temperature
|
||||
power_management &= ~(1 << MPU6050_BIT_TEMPERATURE_DISABLED);
|
||||
ESP_LOGV(TAG, " Output power_management: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(power_management));
|
||||
if (!this->write_byte(MPU6050_REGISTER_POWER_MANAGEMENT_1, power_management)) {
|
||||
// Clock source X-Gyro, sleep off, temperature on
|
||||
if (!this->update_register(MPU6050_REGISTER_POWER_MANAGEMENT_1,
|
||||
0b111 | (1 << MPU6050_BIT_SLEEP_ENABLED) | (1 << MPU6050_BIT_TEMPERATURE_DISABLED),
|
||||
MPU6050_CLOCK_SOURCE_X_GYRO)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, " Setting up Gyro Config");
|
||||
// Set scale - 2000DPS
|
||||
uint8_t gyro_config;
|
||||
if (!this->read_byte(MPU6050_REGISTER_GYRO_CONFIG, &gyro_config)) {
|
||||
return false;
|
||||
}
|
||||
ESP_LOGV(TAG, " Input gyro_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(gyro_config));
|
||||
gyro_config &= 0b11100111;
|
||||
gyro_config |= MPU6050_SCALE_2000_DPS << 3;
|
||||
ESP_LOGV(TAG, " Output gyro_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(gyro_config));
|
||||
if (!this->write_byte(MPU6050_REGISTER_GYRO_CONFIG, gyro_config)) {
|
||||
if (!this->update_register(MPU6050_REGISTER_GYRO_CONFIG, 0b00011000, MPU6050_SCALE_2000_DPS << 3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, " Setting up Accel Config");
|
||||
// Set range - 2G
|
||||
uint8_t accel_config;
|
||||
if (!this->read_byte(MPU6050_REGISTER_ACCEL_CONFIG, &accel_config)) {
|
||||
return false;
|
||||
}
|
||||
ESP_LOGV(TAG, " Input accel_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(accel_config));
|
||||
accel_config &= 0b11100111;
|
||||
accel_config |= (MPU6050_RANGE_2G << 3);
|
||||
ESP_LOGV(TAG, " Output accel_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(accel_config));
|
||||
return this->write_byte(MPU6050_REGISTER_ACCEL_CONFIG, accel_config);
|
||||
return this->update_register(MPU6050_REGISTER_ACCEL_CONFIG, 0b00011000, MPU6050_RANGE_2G << 3);
|
||||
}
|
||||
void MPU6050Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "MPU6050:");
|
||||
|
||||
@@ -36,49 +36,22 @@ bool MPU6886Component::setup_registers_() {
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, " Setting up Power Management");
|
||||
// Setup power management
|
||||
uint8_t power_management;
|
||||
if (!this->read_byte(MPU6886_REGISTER_POWER_MANAGEMENT_1, &power_management)) {
|
||||
return false;
|
||||
}
|
||||
ESP_LOGV(TAG, " Input power_management: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(power_management));
|
||||
// Set clock source - X-Gyro
|
||||
power_management &= 0b11111000;
|
||||
power_management |= MPU6886_CLOCK_SOURCE_X_GYRO;
|
||||
// Disable sleep
|
||||
power_management &= ~(1 << MPU6886_BIT_SLEEP_ENABLED);
|
||||
// Enable temperature
|
||||
power_management &= ~(1 << MPU6886_BIT_TEMPERATURE_DISABLED);
|
||||
ESP_LOGV(TAG, " Output power_management: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(power_management));
|
||||
if (!this->write_byte(MPU6886_REGISTER_POWER_MANAGEMENT_1, power_management)) {
|
||||
// Clock source X-Gyro, sleep off, temperature on
|
||||
if (!this->update_register(MPU6886_REGISTER_POWER_MANAGEMENT_1,
|
||||
0b111 | (1 << MPU6886_BIT_SLEEP_ENABLED) | (1 << MPU6886_BIT_TEMPERATURE_DISABLED),
|
||||
MPU6886_CLOCK_SOURCE_X_GYRO)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, " Setting up Gyroscope Config");
|
||||
// Set scale - 2000DPS
|
||||
uint8_t gyro_config;
|
||||
if (!this->read_byte(MPU6886_REGISTER_GYRO_CONFIG, &gyro_config)) {
|
||||
return false;
|
||||
}
|
||||
ESP_LOGV(TAG, " Input gyroscope_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(gyro_config));
|
||||
gyro_config &= 0b11100111;
|
||||
gyro_config |= MPU6886_SCALE_2000_DPS << 3;
|
||||
ESP_LOGV(TAG, " Output gyro_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(gyro_config));
|
||||
if (!this->write_byte(MPU6886_REGISTER_GYRO_CONFIG, gyro_config)) {
|
||||
if (!this->update_register(MPU6886_REGISTER_GYRO_CONFIG, 0b00011000, MPU6886_SCALE_2000_DPS << 3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, " Setting up Accelerometer Config");
|
||||
// Set range - 2G
|
||||
uint8_t accel_config;
|
||||
if (!this->read_byte(MPU6886_REGISTER_ACCEL_CONFIG, &accel_config)) {
|
||||
return false;
|
||||
}
|
||||
ESP_LOGV(TAG, " Input accelerometer_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(accel_config));
|
||||
accel_config &= 0b11100111;
|
||||
accel_config |= (MPU6886_RANGE_2G << 3);
|
||||
ESP_LOGV(TAG, " Output accel_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(accel_config));
|
||||
return this->write_byte(MPU6886_REGISTER_ACCEL_CONFIG, accel_config);
|
||||
return this->update_register(MPU6886_REGISTER_ACCEL_CONFIG, 0b00011000, MPU6886_RANGE_2G << 3);
|
||||
}
|
||||
|
||||
void MPU6886Component::dump_config() {
|
||||
|
||||
@@ -129,15 +129,7 @@ void RX8111Component::write_time() {
|
||||
}
|
||||
|
||||
bool RX8111Component::set_stop_bit_(bool stop) {
|
||||
uint8_t control;
|
||||
if (!this->read_byte(RX8111_REG_CONTROL, &control))
|
||||
return false;
|
||||
if (stop) {
|
||||
control |= RX8111_CTRL_STOP;
|
||||
} else {
|
||||
control &= ~RX8111_CTRL_STOP;
|
||||
}
|
||||
return this->write_byte(RX8111_REG_CONTROL, control);
|
||||
return this->update_register(RX8111_REG_CONTROL, RX8111_CTRL_STOP, stop ? RX8111_CTRL_STOP : 0);
|
||||
}
|
||||
|
||||
} // namespace esphome::rx8111
|
||||
|
||||
@@ -172,7 +172,6 @@ void SX1509Component::pin_mode(uint8_t pin, gpio::Flags flags) {
|
||||
|
||||
void SX1509Component::setup_led_driver(uint8_t pin) {
|
||||
uint16_t temp_word = 0;
|
||||
uint8_t temp_byte = 0;
|
||||
|
||||
this->read_byte_16(REG_INPUT_DISABLE_B, &temp_word);
|
||||
temp_word |= (1 << pin);
|
||||
@@ -181,16 +180,11 @@ void SX1509Component::setup_led_driver(uint8_t pin) {
|
||||
this->ddr_mask_ &= ~(1 << pin); // 0=output
|
||||
this->write_byte_16(REG_DIR_B, this->ddr_mask_);
|
||||
|
||||
this->read_byte(REG_CLOCK, &temp_byte);
|
||||
temp_byte |= (1 << 6); // Internal 2MHz oscillator part 1 (set bit 6)
|
||||
temp_byte &= ~(1 << 5); // Internal 2MHz oscillator part 2 (clear bit 5)
|
||||
this->write_byte(REG_CLOCK, temp_byte);
|
||||
// Internal 2MHz oscillator: set bit 6, clear bit 5
|
||||
this->update_register(REG_CLOCK, (1 << 6) | (1 << 5), 1 << 6);
|
||||
|
||||
this->read_byte(REG_MISC, &temp_byte);
|
||||
temp_byte &= ~(1 << 7); // set linear mode bank B
|
||||
temp_byte &= ~(1 << 3); // set linear mode bank A
|
||||
temp_byte |= 0x70; // Frequency of the LED Driver clock ClkX of all IOs:
|
||||
this->write_byte(REG_MISC, temp_byte);
|
||||
// Linear mode for banks A (bit 3) and B (bit 7); LED driver clock ClkX of all IOs (bits 6:4)
|
||||
this->update_register(REG_MISC, (1 << 7) | (1 << 3) | 0x70, 0x70);
|
||||
|
||||
this->read_byte_16(REG_LED_DRIVER_ENABLE_B, &temp_word);
|
||||
temp_word |= (1 << pin);
|
||||
@@ -213,11 +207,7 @@ void SX1509Component::clock_(uint8_t osc_source, uint8_t osc_pin_function, uint8
|
||||
this->clk_x_ = 2000000;
|
||||
osc_divider = (osc_divider & 0b111) << 4; // 3-bit value, bits 6:4
|
||||
|
||||
uint8_t reg_misc = 0;
|
||||
this->read_byte(REG_MISC, ®_misc);
|
||||
reg_misc &= ~(0b111 << 4);
|
||||
reg_misc |= osc_divider;
|
||||
this->write_byte(REG_MISC, reg_misc);
|
||||
this->update_register(REG_MISC, 0b111 << 4, osc_divider);
|
||||
}
|
||||
|
||||
void SX1509Component::setup_keypad_() {
|
||||
@@ -231,15 +221,11 @@ void SX1509Component::setup_keypad_() {
|
||||
this->ddr_mask_ |= (1 << i);
|
||||
this->write_byte_16(REG_DIR_B, this->ddr_mask_);
|
||||
|
||||
this->read_byte(REG_OPEN_DRAIN_A, &temp_byte);
|
||||
for (int i = 0; i < this->rows_; i++)
|
||||
temp_byte |= (1 << i);
|
||||
this->write_byte(REG_OPEN_DRAIN_A, temp_byte);
|
||||
const uint8_t row_bits = (1 << this->rows_) - 1;
|
||||
this->update_register(REG_OPEN_DRAIN_A, row_bits, row_bits);
|
||||
|
||||
this->read_byte(REG_PULL_UP_B, &temp_byte);
|
||||
for (int i = 0; i < this->cols_; i++)
|
||||
temp_byte |= (1 << i);
|
||||
this->write_byte(REG_PULL_UP_B, temp_byte);
|
||||
const uint8_t col_bits = (1 << this->cols_) - 1;
|
||||
this->update_register(REG_PULL_UP_B, col_bits, col_bits);
|
||||
|
||||
if (debounce_time_ >= scan_time_) {
|
||||
debounce_time_ = scan_time_ >> 1; // Force debounce_time to be less than scan_time
|
||||
@@ -268,13 +254,8 @@ uint16_t SX1509Component::read_key_data() {
|
||||
|
||||
void SX1509Component::set_debounce_config_(uint8_t config_value) {
|
||||
// First make sure clock is configured
|
||||
uint8_t temp_byte = 0;
|
||||
this->read_byte(REG_MISC, &temp_byte);
|
||||
temp_byte |= (1 << 4); // Just default to no divider if not set
|
||||
this->write_byte(REG_MISC, temp_byte);
|
||||
this->read_byte(REG_CLOCK, &temp_byte);
|
||||
temp_byte |= (1 << 6); // default to internal osc.
|
||||
this->write_byte(REG_CLOCK, temp_byte);
|
||||
this->update_register(REG_MISC, 1 << 4, 1 << 4); // Just default to no divider if not set
|
||||
this->update_register(REG_CLOCK, 1 << 6, 1 << 6); // default to internal osc.
|
||||
|
||||
config_value &= 0b111; // 3-bit value
|
||||
this->write_byte(REG_DEBOUNCE_CONFIG, config_value);
|
||||
|
||||
@@ -45,13 +45,10 @@ bool SY6970Component::write_register_(uint8_t reg, uint8_t value) {
|
||||
}
|
||||
|
||||
bool SY6970Component::update_register_(uint8_t reg, uint8_t mask, uint8_t value) {
|
||||
uint8_t reg_value;
|
||||
if (!this->read_byte(reg, ®_value)) {
|
||||
ESP_LOGW(TAG, "Failed to read register 0x%02X for update", reg);
|
||||
return false;
|
||||
}
|
||||
reg_value = (reg_value & ~mask) | (value & mask);
|
||||
return this->write_register_(reg, reg_value);
|
||||
if (this->update_register(reg, mask, value))
|
||||
return true;
|
||||
ESP_LOGW(TAG, "Failed to update register 0x%02X", reg);
|
||||
return false;
|
||||
}
|
||||
|
||||
void SY6970Component::setup() {
|
||||
|
||||
@@ -159,12 +159,10 @@ bool TAS2780::select_page_(uint8_t page) {
|
||||
}
|
||||
|
||||
bool TAS2780::update_bits_(uint8_t reg, uint8_t mask, uint8_t value) {
|
||||
uint8_t current;
|
||||
if (!this->select_page_(TAS2780_PAGE_0) || !this->read_byte(reg, ¤t)) {
|
||||
ESP_LOGE(TAG, "Failed to read register 0x%02X", reg);
|
||||
return false;
|
||||
}
|
||||
return this->write_byte(reg, (current & ~mask) | (value & mask));
|
||||
if (this->select_page_(TAS2780_PAGE_0) && this->update_register(reg, mask, value))
|
||||
return true;
|
||||
ESP_LOGW(TAG, "Failed to update register 0x%02X", reg);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TAS2780::init_() {
|
||||
|
||||
@@ -17,14 +17,8 @@ void UFireECComponent::setup() {
|
||||
ESP_LOGI(TAG, "Found ufire_ec board version 0x%02X", version);
|
||||
|
||||
// Write option for temperature adjustments
|
||||
uint8_t config;
|
||||
this->read_byte(REGISTER_CONFIG, &config);
|
||||
if (this->temperature_sensor_ == nullptr && this->temperature_sensor_external_ == nullptr) {
|
||||
config &= ~CONFIG_TEMP_COMPENSATION;
|
||||
} else {
|
||||
config |= CONFIG_TEMP_COMPENSATION;
|
||||
}
|
||||
this->write_byte(REGISTER_CONFIG, config);
|
||||
const bool compensate = this->temperature_sensor_ != nullptr || this->temperature_sensor_external_ != nullptr;
|
||||
this->update_register(REGISTER_CONFIG, CONFIG_TEMP_COMPENSATION, compensate ? CONFIG_TEMP_COMPENSATION : 0);
|
||||
|
||||
// Update temperature compensation
|
||||
this->set_compensation_(this->temperature_compensation_);
|
||||
|
||||
@@ -18,14 +18,8 @@ void UFireISEComponent::setup() {
|
||||
ESP_LOGI(TAG, "Found uFire_ise board version 0x%02X", version);
|
||||
|
||||
// Write option for temperature adjustments
|
||||
uint8_t config;
|
||||
this->read_byte(REGISTER_CONFIG, &config);
|
||||
if (this->temperature_sensor_ == nullptr && this->temperature_sensor_external_ == nullptr) {
|
||||
config &= ~CONFIG_TEMP_COMPENSATION;
|
||||
} else {
|
||||
config |= CONFIG_TEMP_COMPENSATION;
|
||||
}
|
||||
this->write_byte(REGISTER_CONFIG, config);
|
||||
const bool compensate = this->temperature_sensor_ != nullptr || this->temperature_sensor_external_ != nullptr;
|
||||
this->update_register(REGISTER_CONFIG, CONFIG_TEMP_COMPENSATION, compensate ? CONFIG_TEMP_COMPENSATION : 0);
|
||||
}
|
||||
|
||||
void UFireISEComponent::update() {
|
||||
|
||||
Reference in New Issue
Block a user