7static const char *
const TAG =
"sx126x";
8static const uint16_t RAMP[8] = {10, 20, 40, 80, 200, 800, 1700, 3400};
9static const uint32_t BW_HZ[31] = {4800, 5800, 7300, 9700, 11700, 14600, 19500, 23400, 29300, 39000, 46900,
10 58600, 78200, 93800, 117300, 156200, 187200, 234300, 312000, 373600, 467000, 7810,
11 10420, 15630, 20830, 31250, 41670, 62500, 125000, 250000, 500000};
14static const uint8_t BW_FSK[21] = {
19static constexpr uint32_t RESET_DELAY_HIGH_US = 5000;
20static constexpr uint32_t RESET_DELAY_LOW_US = 2000;
21static constexpr uint32_t SWITCHING_DELAY_US = 1;
22static constexpr uint32_t TRANSMIT_TIMEOUT_MS = 4000;
23static constexpr uint32_t BUSY_TIMEOUT_MS = 20;
26static constexpr uint8_t OCP_80MA = 0x18;
27static constexpr uint8_t OCP_140MA = 0x38;
30static constexpr float LOW_DATA_RATE_OPTIMIZE_THRESHOLD = 16.38f;
38 for (uint8_t &
byte : packet) {
50 for (
const uint8_t &
byte : packet) {
62 for (int32_t i = 0; i <
size; i++) {
73 for (int32_t i = 0; i <
size; i++) {
87 for (int32_t i = 0; i <
size; i++) {
99 for (int32_t i = 0; i <
size; i++) {
143 buf[1] = (
delay >> 16) & 0xFF;
144 buf[2] = (
delay >> 8) & 0xFF;
145 buf[3] = (
delay >> 0) & 0xFF;
164 this->version_[
sizeof(this->
version_) - 1] =
'\0';
165 if (strncmp(this->version_,
"SX126", 5) != 0 && strncmp(this->version_,
"LLCC68", 6) != 0) {
178 uint64_t freq = ((uint64_t) this->
frequency_ << 25) / XTAL_FREQ;
179 buf[0] = (uint8_t) ((freq >> 24) & 0xFF);
180 buf[1] = (uint8_t) ((freq >> 16) & 0xFF);
181 buf[2] = (uint8_t) ((freq >> 8) & 0xFF);
182 buf[3] = (uint8_t) (freq & 0xFF);
190 if (pa_power == 15) {
191 uint8_t cfg[4] = {0x06, 0x00, 0x01, 0x01};
194 uint8_t cfg[4] = {0x04, 0x00, 0x01, 0x01};
197 pa_power = std::max(pa_power, (int8_t) -3);
198 pa_power = std::min(pa_power, (int8_t) 14);
204 uint8_t cfg[4] = {0x04, 0x07, 0x00, 0x01};
206 pa_power = std::max(pa_power, (int8_t) -3);
207 pa_power = std::min(pa_power, (int8_t) 22);
222 buf[3] = (
duration > LOW_DATA_RATE_OPTIMIZE_THRESHOLD) ? 0x01 : 0x00;
234 buf[0] = (bitrate >> 16) & 0xFF;
235 buf[1] = (bitrate >> 8) & 0xFF;
236 buf[2] = (bitrate >> 0) & 0xFF;
239 buf[5] = (fdev >> 16) & 0xFF;
240 buf[6] = (fdev >> 8) & 0xFF;
241 buf[7] = (fdev >> 0) & 0xFF;
282 buf[3] = payload_length;
294 buf[6] = payload_length;
307 ESP_LOGE(TAG,
"Packet size does not match config");
310 if (packet.empty() || packet.size() > this->get_max_packet_size()) {
311 ESP_LOGE(TAG,
"Packet size out of range");
326 if (
millis() - start > TRANSMIT_TIMEOUT_MS) {
327 ESP_LOGE(TAG,
"Transmit packet failure");
350 listener->on_packet(packet, rssi, snr);
369 status = (buf[0] << 8) | buf[1];
391 uint8_t buf[2] = {0, 0};
408 if (buf[0] > 0 && buf[1] > 0) {
418 buf[0] = (irq >> 8) & 0xFF;
419 buf[1] = (irq >> 0) & 0xFF;
420 buf[2] = (irq >> 8) & 0xFF;
421 buf[3] = (irq >> 0) & 0xFF;
444 buf[0] = (irq >> 8) & 0xFF;
445 buf[1] = (irq >> 0) & 0xFF;
446 buf[2] = (irq >> 8) & 0xFF;
447 buf[3] = (irq >> 0) & 0xFF;
464 buf[0] = cold ? 0x00 : 0x04;
479 if (
millis() - start > BUSY_TIMEOUT_MS) {
480 ESP_LOGE(TAG,
"Wait busy timeout");
488 ESP_LOGCONFIG(TAG,
"SX126x:");
489 LOG_PIN(
" CS Pin: ", this->
cs_);
491 LOG_PIN(
" RST Pin: ", this->
rst_pin_);
494 " HW Version: %15s\n"
495 " Frequency: %" PRIu32
" Hz\n"
496 " Bandwidth: %" PRIu32
" Hz\n"
497 " PA Power: %" PRId8
" dBm\n"
498 " PA Ramp: %" PRIu16
" us\n"
499 " Payload Length: %" PRIu32
"\n"
505 const char *shaping =
"NONE";
507 shaping =
"GAUSSIAN_BT_0_3";
509 shaping =
"GAUSSIAN_BT_0_5";
511 shaping =
"GAUSSIAN_BT_0_7";
513 shaping =
"GAUSSIAN_BT_1_0";
517 " Deviation: %" PRIu32
" Hz\n"
519 " Preamble Size: %" PRIu16
"\n"
520 " Preamble Detect: %" PRIu16
"\n"
521 " Bitrate: %" PRIu32
"b/s",
524 const char *cr =
"4/8";
533 " Modulation: LORA\n"
534 " Spreading Factor: %" PRIu8
"\n"
536 " Preamble Size: %" PRIu16,
541 ESP_LOGCONFIG(TAG,
" Sync Value: 0x%s",
545 ESP_LOGE(TAG,
"Configuring SX126x failed");
BedjetMode mode
BedJet operating mode.
void mark_failed()
Mark this component as failed.
void enable_loop_soon_any_context()
Thread and ISR-safe version of enable_loop() that can be called from any context.
void disable_loop()
Disable this component's loop.
virtual void digital_write(bool value)=0
virtual ESPDEPRECATED("Override dump_summary(char*, size_t) instead. Will be removed in 2026.7.0.", "2026.1.0") virtual std boo is_internal)()
Get a summary of this pin as a string.
virtual bool digital_read()=0
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Inform the parent automation that the event has triggered.
void spi_setup() override
void write_byte(uint8_t data)
uint8_t transfer_byte(uint8_t data)
uint8_t read_fifo_(uint8_t offset, std::vector< uint8_t > &packet)
void write_opcode_(uint8_t opcode, uint8_t *data, uint8_t size)
std::vector< uint8_t > sync_value_
std::vector< SX126xListener * > listeners_
size_t get_max_packet_size()
void set_mode_standby(SX126xStandbyMode mode)
static void IRAM_ATTR gpio_intr(SX126x *arg)
Trigger< std::vector< uint8_t >, float, float > packet_trigger_
uint8_t read_opcode_(uint8_t opcode, uint8_t *data, uint8_t size)
void dump_config() override
void read_register_(uint16_t reg, uint8_t *data, uint8_t size)
void write_register_(uint16_t reg, uint8_t *data, uint8_t size)
void set_packet_params_(uint8_t payload_length)
void call_listeners_(const std::vector< uint8_t > &packet, float rssi, float snr)
std::vector< uint8_t > packet_
uint16_t preamble_detect_
SX126xError transmit_packet(const std::vector< uint8_t > &packet)
uint8_t spreading_factor_
void write_fifo_(uint8_t offset, const std::vector< uint8_t > &packet)
void set_mode_sleep(bool cold=false)
@ RADIO_SET_MODULATIONPARAMS
@ RADIO_SET_LORASYMBTIMEOUT
@ RADIO_GET_RXBUFFERSTATUS
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
void HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()
char * format_hex_to(char *buffer, size_t buffer_size, const uint8_t *data, size_t length)
Format byte array as lowercase hex to buffer (base implementation).