mirror of
https://github.com/esphome/esphome.git
synced 2026-08-18 03:59:08 +08:00
[sx126x] Add data whitening options (#17102)
CI / Create common environment (push) Has been cancelled
CI / Check pylint (push) Has been cancelled
CI / Run script/ci-custom (push) Has been cancelled
CI / Check import esphome.__main__ time (push) Has been cancelled
CI / Test downstream esphome/device-builder (push) Has been cancelled
CI / Run pytest (macOS-latest, 3.11) (push) Has been cancelled
CI / Run pytest (macOS-latest, 3.14) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.11) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.13) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.14) (push) Has been cancelled
CI / Run pytest (windows-latest, 3.11) (push) Has been cancelled
CI / Run pytest (windows-latest, 3.14) (push) Has been cancelled
CI / Determine which jobs to run (push) Has been cancelled
CI / Run integration tests (${{ matrix.bucket.name }}) (push) Has been cancelled
CI / Run C++ unit tests (push) Has been cancelled
CI / Run CodSpeed benchmarks (push) Has been cancelled
CI / Run script/clang-tidy for ESP8266 (push) Has been cancelled
CI / Run script/clang-tidy for ZEPHYR (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF 1/3 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF 2/3 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF 3/3 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 C6 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 P4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 S3 (push) Has been cancelled
CI / Test components batch (${{ matrix.components }}) (push) Has been cancelled
CI / Test esp32 components with PlatformIO (push) Has been cancelled
CI / pre-commit.ci lite (push) Has been cancelled
CI / Build target branch for memory impact (push) Has been cancelled
CI / Build PR branch for memory impact (push) Has been cancelled
CI / Comment memory impact (push) Has been cancelled
CI / CI Status (push) Has been cancelled
CI / Create common environment (push) Has been cancelled
CI / Check pylint (push) Has been cancelled
CI / Run script/ci-custom (push) Has been cancelled
CI / Check import esphome.__main__ time (push) Has been cancelled
CI / Test downstream esphome/device-builder (push) Has been cancelled
CI / Run pytest (macOS-latest, 3.11) (push) Has been cancelled
CI / Run pytest (macOS-latest, 3.14) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.11) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.13) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.14) (push) Has been cancelled
CI / Run pytest (windows-latest, 3.11) (push) Has been cancelled
CI / Run pytest (windows-latest, 3.14) (push) Has been cancelled
CI / Determine which jobs to run (push) Has been cancelled
CI / Run integration tests (${{ matrix.bucket.name }}) (push) Has been cancelled
CI / Run C++ unit tests (push) Has been cancelled
CI / Run CodSpeed benchmarks (push) Has been cancelled
CI / Run script/clang-tidy for ESP8266 (push) Has been cancelled
CI / Run script/clang-tidy for ZEPHYR (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF 1/3 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF 2/3 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF 3/3 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 C6 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 P4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 S3 (push) Has been cancelled
CI / Test components batch (${{ matrix.components }}) (push) Has been cancelled
CI / Test esp32 components with PlatformIO (push) Has been cancelled
CI / pre-commit.ci lite (push) Has been cancelled
CI / Build target branch for memory impact (push) Has been cancelled
CI / Build PR branch for memory impact (push) Has been cancelled
CI / Comment memory impact (push) Has been cancelled
CI / CI Status (push) Has been cancelled
Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
This commit is contained in:
co-authored by
Jonathan Swoboda
parent
0df1db6205
commit
2483576909
@@ -41,6 +41,8 @@ CONF_SPREADING_FACTOR = "spreading_factor"
|
||||
CONF_SYNC_VALUE = "sync_value"
|
||||
CONF_TCXO_VOLTAGE = "tcxo_voltage"
|
||||
CONF_TCXO_DELAY = "tcxo_delay"
|
||||
CONF_WHITENING_ENABLE = "whitening_enable"
|
||||
CONF_WHITENING_INITIAL = "whitening_initial"
|
||||
|
||||
sx126x_ns = cg.esphome_ns.namespace("sx126x")
|
||||
SX126x = sx126x_ns.class_("SX126x", cg.Component, spi.SPIDevice)
|
||||
@@ -232,6 +234,10 @@ CONFIG_SCHEMA = (
|
||||
cv.positive_time_period_microseconds,
|
||||
cv.Range(max=TimePeriod(microseconds=262144000)),
|
||||
),
|
||||
cv.Optional(CONF_WHITENING_ENABLE, default=False): cv.boolean,
|
||||
cv.Optional(CONF_WHITENING_INITIAL, default=0x0100): cv.All(
|
||||
cv.hex_int, cv.Range(min=0, max=0x1FF)
|
||||
),
|
||||
},
|
||||
)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
@@ -285,6 +291,8 @@ async def to_code(config: ConfigType) -> None:
|
||||
cg.add(var.set_rf_switch(config[CONF_RF_SWITCH]))
|
||||
cg.add(var.set_tcxo_voltage(config[CONF_TCXO_VOLTAGE]))
|
||||
cg.add(var.set_tcxo_delay(config[CONF_TCXO_DELAY]))
|
||||
cg.add(var.set_whitening_enable(config[CONF_WHITENING_ENABLE]))
|
||||
cg.add(var.set_whitening_initial(config[CONF_WHITENING_INITIAL]))
|
||||
|
||||
|
||||
NO_ARGS_ACTION_SCHEMA = automation.maybe_simple_id(
|
||||
|
||||
@@ -251,6 +251,16 @@ void SX126x::configure() {
|
||||
this->write_register_(REG_CRC_POLYNOMIAL, buf, 2);
|
||||
}
|
||||
|
||||
// set whitening params
|
||||
if (this->whitening_enable_) {
|
||||
// according to the datasheet, section 12 table 12-1 "The user should not
|
||||
// change the value of the 7 MSB of this register"
|
||||
this->read_register_(REG_WHITENING_INITIAL, buf, 1);
|
||||
buf[0] = (buf[0] & 0xFE) | ((this->whitening_initial_ >> 8) & 0x01);
|
||||
buf[1] = this->whitening_initial_ & 0xFF;
|
||||
this->write_register_(REG_WHITENING_INITIAL, buf, 2);
|
||||
}
|
||||
|
||||
// set packet params and sync word
|
||||
this->set_packet_params_(this->get_max_packet_size());
|
||||
if (!this->sync_value_.empty()) {
|
||||
@@ -297,7 +307,7 @@ void SX126x::set_packet_params_(uint8_t payload_length) {
|
||||
} else {
|
||||
buf[7] = 0x01;
|
||||
}
|
||||
buf[8] = 0x00;
|
||||
buf[8] = (this->whitening_enable_) ? 0x01 : 0x00;
|
||||
this->write_opcode_(RADIO_SET_PACKETPARAMS, buf, 9);
|
||||
}
|
||||
}
|
||||
@@ -541,6 +551,10 @@ void SX126x::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, " Sync Value: 0x%s",
|
||||
format_hex_to(hex_buf, this->sync_value_.data(), this->sync_value_.size()));
|
||||
}
|
||||
ESP_LOGCONFIG(TAG, " Whitening Enable: %s", TRUEFALSE(this->whitening_enable_));
|
||||
if (this->whitening_enable_) {
|
||||
ESP_LOGCONFIG(TAG, " Whitening Initial: 0x%03x", this->whitening_initial_);
|
||||
}
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Configuring SX126x failed");
|
||||
}
|
||||
|
||||
@@ -71,6 +71,8 @@ class SX126x : public Component,
|
||||
void set_crc_size(uint8_t crc_size) { this->crc_size_ = crc_size; }
|
||||
void set_crc_polynomial(uint16_t crc_polynomial) { this->crc_polynomial_ = crc_polynomial; }
|
||||
void set_crc_initial(uint16_t crc_initial) { this->crc_initial_ = crc_initial; }
|
||||
void set_whitening_enable(bool whitening_enable) { this->whitening_enable_ = whitening_enable; }
|
||||
void set_whitening_initial(uint16_t whitening_initial) { this->whitening_initial_ = whitening_initial; }
|
||||
void set_deviation(uint32_t deviation) { this->deviation_ = deviation; }
|
||||
void set_dio1_pin(GPIOPin *dio1_pin) { this->dio1_pin_ = dio1_pin; }
|
||||
void set_frequency(uint32_t frequency) { this->frequency_ = frequency; }
|
||||
@@ -128,6 +130,8 @@ class SX126x : public Component,
|
||||
uint8_t crc_size_{0};
|
||||
uint16_t crc_polynomial_{0};
|
||||
uint16_t crc_initial_{0};
|
||||
bool whitening_enable_{false};
|
||||
uint16_t whitening_initial_{0};
|
||||
uint32_t deviation_{0};
|
||||
uint32_t frequency_{0};
|
||||
uint32_t payload_length_{0};
|
||||
|
||||
@@ -52,6 +52,7 @@ enum SX126xOpCode : uint8_t {
|
||||
|
||||
enum SX126xRegister : uint16_t {
|
||||
REG_VERSION_STRING = 0x0320,
|
||||
REG_WHITENING_INITIAL = 0x06B8,
|
||||
REG_CRC_INITIAL = 0x06BC,
|
||||
REG_CRC_POLYNOMIAL = 0x06BE,
|
||||
REG_GFSK_SYNCWORD = 0x06C0,
|
||||
|
||||
@@ -21,6 +21,8 @@ sx126x:
|
||||
coding_rate: CR_4_6
|
||||
tcxo_voltage: 1_8V
|
||||
tcxo_delay: 5ms
|
||||
whitening_enable: false
|
||||
whitening_initial: 0x1FF
|
||||
on_packet:
|
||||
then:
|
||||
- lambda: |-
|
||||
|
||||
Reference in New Issue
Block a user