From 6220427524bbbf85401ba08f5ac612c509a90fa5 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Fri, 5 Dec 2025 22:32:20 -0500 Subject: [PATCH] [cc1101] Use Hz and cv.frequency instead of kHz (#12313) --- esphome/components/cc1101/__init__.py | 10 +++++----- esphome/components/cc1101/cc1101.cpp | 17 ++++++++--------- esphome/components/cc1101/cc1101defs.h | 2 +- tests/components/cc1101/common.yaml | 8 ++++---- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/esphome/components/cc1101/__init__.py b/esphome/components/cc1101/__init__.py index 0f5743d0cd..e6b31b84f8 100644 --- a/esphome/components/cc1101/__init__.py +++ b/esphome/components/cc1101/__init__.py @@ -152,12 +152,12 @@ CONFIG_MAP = { CONF_OUTPUT_POWER: cv.float_range(min=-30.0, max=11.0), CONF_RX_ATTENUATION: cv.enum(RX_ATTENUATION, upper=False), CONF_DC_BLOCKING_FILTER: cv.boolean, - CONF_FREQUENCY: cv.float_range(min=300000.0, max=928000.0), - CONF_IF_FREQUENCY: cv.float_range(min=25, max=788), - CONF_FILTER_BANDWIDTH: cv.float_range(min=58.0, max=812.0), + CONF_FREQUENCY: cv.All(cv.frequency, cv.float_range(min=300000000, max=928000000)), + CONF_IF_FREQUENCY: cv.All(cv.frequency, cv.float_range(min=25000, max=788000)), + CONF_FILTER_BANDWIDTH: cv.All(cv.frequency, cv.float_range(min=58000, max=812000)), CONF_CHANNEL: cv.uint8_t, - CONF_CHANNEL_SPACING: cv.float_range(min=25, max=405), - CONF_FSK_DEVIATION: cv.float_range(min=1.5, max=381), + CONF_CHANNEL_SPACING: cv.All(cv.frequency, cv.float_range(min=25000, max=405000)), + CONF_FSK_DEVIATION: cv.All(cv.frequency, cv.float_range(min=1500, max=381000)), CONF_MSK_DEVIATION: cv.int_range(min=1, max=8), CONF_SYMBOL_RATE: cv.float_range(min=600, max=500000), CONF_SYNC_MODE: cv.enum(SYNC_MODE, upper=False), diff --git a/esphome/components/cc1101/cc1101.cpp b/esphome/components/cc1101/cc1101.cpp index 1a758e415a..3cbf09ded8 100644 --- a/esphome/components/cc1101/cc1101.cpp +++ b/esphome/components/cc1101/cc1101.cpp @@ -160,18 +160,17 @@ void CC1101Component::dump_config() { "4-FSK", "UNUSED", "UNUSED", "MSK"}; int32_t freq = static_cast(this->state_.FREQ2 << 16 | this->state_.FREQ1 << 8 | this->state_.FREQ0) * XTAL_FREQUENCY / (1 << 16); - float symbol_rate = - (((256.0f + this->state_.DRATE_M) * (1 << this->state_.DRATE_E)) / (1 << 28)) * XTAL_FREQUENCY * 1000.0f; + float symbol_rate = (((256.0f + this->state_.DRATE_M) * (1 << this->state_.DRATE_E)) / (1 << 28)) * XTAL_FREQUENCY; float bw = XTAL_FREQUENCY / (8.0f * (4 + this->state_.CHANBW_M) * (1 << this->state_.CHANBW_E)); ESP_LOGCONFIG(TAG, "CC1101:"); LOG_PIN(" CS Pin: ", this->cs_); ESP_LOGCONFIG(TAG, " Chip ID: 0x%04X\n" - " Frequency: %" PRId32 " kHz\n" + " Frequency: %" PRId32 " Hz\n" " Channel: %u\n" " Modulation: %s\n" " Symbol Rate: %.0f baud\n" - " Filter Bandwidth: %.1f kHz\n" + " Filter Bandwidth: %.1f Hz\n" " Output Power: %.1f dBm", this->chip_id_, freq, this->state_.CHANNR, MODULATION_NAMES[this->state_.MOD_FORMAT & 0x07], symbol_rate, bw, this->output_power_effective_); @@ -289,13 +288,13 @@ void CC1101Component::set_output_power(float value) { int32_t freq = static_cast(this->state_.FREQ2 << 16 | this->state_.FREQ1 << 8 | this->state_.FREQ0) * XTAL_FREQUENCY / (1 << 16); uint8_t a = 0xC0; - if (freq >= 300000 && freq <= 348000) { + if (freq >= 300000000 && freq <= 348000000) { a = PowerTableItem::find(PA_TABLE_315, sizeof(PA_TABLE_315) / sizeof(PA_TABLE_315[0]), value); - } else if (freq >= 378000 && freq <= 464000) { + } else if (freq >= 378000000 && freq <= 464000000) { a = PowerTableItem::find(PA_TABLE_433, sizeof(PA_TABLE_433) / sizeof(PA_TABLE_433[0]), value); - } else if (freq >= 779000 && freq < 900000) { + } else if (freq >= 779000000 && freq < 900000000) { a = PowerTableItem::find(PA_TABLE_868, sizeof(PA_TABLE_868) / sizeof(PA_TABLE_868[0]), value); - } else if (freq >= 900000 && freq <= 928000) { + } else if (freq >= 900000000 && freq <= 928000000) { a = PowerTableItem::find(PA_TABLE_915, sizeof(PA_TABLE_915) / sizeof(PA_TABLE_915[0]), value); } @@ -401,7 +400,7 @@ void CC1101Component::set_msk_deviation(uint8_t value) { void CC1101Component::set_symbol_rate(float value) { uint8_t e; uint32_t m; - split_float(value * (1 << 28) / (XTAL_FREQUENCY * 1000), 8, e, m); + split_float(value * (1 << 28) / XTAL_FREQUENCY, 8, e, m); this->state_.DRATE_E = e; this->state_.DRATE_M = static_cast(m); if (this->initialized_) { diff --git a/esphome/components/cc1101/cc1101defs.h b/esphome/components/cc1101/cc1101defs.h index 52f15cb85a..afeb5f1d77 100644 --- a/esphome/components/cc1101/cc1101defs.h +++ b/esphome/components/cc1101/cc1101defs.h @@ -4,7 +4,7 @@ namespace esphome::cc1101 { -static constexpr float XTAL_FREQUENCY = 26000; +static constexpr float XTAL_FREQUENCY = 26000000; static constexpr uint8_t BUS_BURST = 0x40; static constexpr uint8_t BUS_READ = 0x80; diff --git a/tests/components/cc1101/common.yaml b/tests/components/cc1101/common.yaml index 7fd265ca4a..9373ca43e1 100644 --- a/tests/components/cc1101/common.yaml +++ b/tests/components/cc1101/common.yaml @@ -1,11 +1,11 @@ cc1101: id: transceiver cs_pin: ${cs_pin} - frequency: 433920 - if_frequency: 153 - filter_bandwidth: 203 + frequency: 433.92MHz + if_frequency: 153kHz + filter_bandwidth: 203kHz channel: 0 - channel_spacing: 200 + channel_spacing: 200kHz symbol_rate: 5000 modulation_type: ASK/OOK