20#include "esphome/core/hal.h"
179 uint8_t tx_power, uint8_t tcxo_voltage, InternalGPIOPin *fem_en_pin =
nullptr,
180 InternalGPIOPin *vfem_pin =
nullptr, InternalGPIOPin *fem_pa_pin =
nullptr,
183 SX1262_POST_TX_SETTLE_US),
186 fem_en_pin_(fem_en_pin),
188 fem_pa_pin_(fem_pa_pin),
189 fem_profile_(fem_profile),
191 tcxo_voltage_(tcxo_voltage) {}
194 bool init()
override;
221 [[nodiscard]]
const char *
chip_name()
const override {
return "sx1262"; }
239 void write_opcode_(uint8_t opcode,
const uint8_t *params, uint8_t len);
244 void read_opcode_(uint8_t opcode, uint8_t *data, uint8_t len);
259 void write_buffer_(uint8_t offset,
const uint8_t *data, uint8_t len);
264 void read_buffer_(uint8_t offset, uint8_t *data, uint8_t len);
290 void set_packet_params_(uint16_t preamble_len, uint8_t payload_len, uint8_t packet_type, uint8_t crc_type);
330 void fill_capture_info(
bool blocking_wait, uint32_t irq_status, uint8_t rx_offset, uint8_t reported_len,
331 const uint8_t *raw, uint8_t raw_len,
const uint8_t *frame, uint8_t frame_len)
override;
400 InternalGPIOPin *dio1_pin_;
401 InternalGPIOPin *fem_en_pin_;
402 InternalGPIOPin *vfem_pin_;
403 InternalGPIOPin *fem_pa_pin_;
406 uint8_t tcxo_voltage_;
407 uint8_t tcxo_startup_attempts_{0};
408 uint32_t tcxo_startup_delay_us_{0};
SX1262 implementation of RadioDriver.
void set_rx_packet_params() override
Configure RX-specific packet parameters (preamble detector length, fixed probe length).
void before_tx_arm() override
Hook run immediately before every SetTx.
void read_rx_buffer(uint8_t offset, uint8_t *data, uint8_t len) override
Read len bytes from the RX buffer starting at offset.
RadioSX1262(SpiAccess *spi, InternalGPIOPin *rst_pin, InternalGPIOPin *dio1_pin, InternalGPIOPin *busy_pin, uint8_t tx_power, uint8_t tcxo_voltage, InternalGPIOPin *fem_en_pin=nullptr, InternalGPIOPin *vfem_pin=nullptr, InternalGPIOPin *fem_pa_pin=nullptr, FemProfile fem_profile=FemProfile::NONE)
void set_mode_rx() override
Switch to continuous receive mode.
void get_rx_buffer_status(uint8_t &reported_len, uint8_t &rx_offset) override
Read the chip-reported RX length and buffer offset (raw, before any clamping).
void write_opcode_(uint8_t opcode, const uint8_t *params, uint8_t len)
Write an opcode with optional parameter bytes.
void set_mode_standby() override
Switch to standby mode.
void clear_irq_status(uint32_t irq_mask) override
Clear IRQ status bits.
void apply_tuning(const TuningConfig &tuning) override
Apply SX1262 runtime tuning: RX bandwidth, response preamble, post-TX settle delay.
bool has_fast_tx_rx_turnaround() const override
TX→RX turnaround capability (SX1262): slow.
void write_modulation_params_()
Apply the runtime bandwidth setting to the SX1262 modulation parameters.
void write_buffer_(uint8_t offset, const uint8_t *data, uint8_t len)
Write into the SX1262 TX/RX buffer at a given offset.
const char * chip_name() const override
Get a human‑readable chip name.
void fem_set_rx_mode_()
Drive the FEM mode pin to its receive state (LNA), a no-op when no FEM profile is configured.
uint8_t read_rssi_raw_byte() override
Read the single raw RSSI byte (chip-specific opcode); formula is shared, see read_rssi.
void set_tx_packet_params(uint16_t preamble_len, uint8_t payload_len) override
Configure TX packet parameters for one outgoing UART-encoded frame.
uint32_t tx_done_bit() const override
void write_tx_buffer(const uint8_t *data, uint8_t len) override
Write the UART-encoded TX payload into the chip's TX buffer.
uint32_t read_irq_status_raw() override
Read the raw IRQ status word from the radio.
void clear_device_errors_()
Clear device error flags.
void fem_set_tx_mode_()
Drive the FEM mode pin to its transmit state (full PA), a no-op when no FEM profile is configured.
uint32_t rx_done_bit() const override
void set_frequency_register(uint32_t freq_hz) override
Set RF frequency via the chip's own frequency register/opcode encoding, and update current_freq_.
void write_register_(uint16_t addr, const uint8_t *data, uint8_t len)
Write to a register (SX1262 uses opcodes for register access).
void configure_buffer_base() override
Hook run as part of reset_rx_state_, before re-entering RX.
void set_packet_params_(uint16_t preamble_len, uint8_t payload_len, uint8_t packet_type, uint8_t crc_type)
Configure packet parameters (preamble, payload length, CRC).
void dump_debug() override
Dump SX1262‑specific debug info.
void configure_radio_()
Full radio initialization (called from init()).
void start_tx() override
Issue the SetTx opcode with the fixed TX timeout — identical 3-byte payload on both chips,...
void apply_tx_modulation_workaround_()
Apply the Semtech TX modulation-quality erratum workaround (datasheet §15.1).
void configure_tcxo_()
Bring up the DIO3-controlled TCXO and calibrate, with a bounded XOSC-start retry.
uint32_t sync_word_valid_bit() const override
uint16_t hop_dwell_ms(const TuningConfig &tuning) const override
Per-channel dwell for a rotating listen (SX1262).
static void gpio_intr(RadioSX1262 *arg)
DIO1 ISR — sets dio_fired flag. Runs in interrupt context.
void read_opcode_(uint8_t opcode, uint8_t *data, uint8_t len)
Read response from an opcode.
int8_t front_end_rx_gain_db() const override
Gain (dB) of the board's external receive front end that the chip's RSSI includes.
bool init() override
Initialize the radio hardware. Returns true on success.
void set_rx_bandwidth_(SX1262RxBandwidth bandwidth)
Apply the RX bandwidth selector and rewrite the modulation parameters.
void fill_capture_info(bool blocking_wait, uint32_t irq_status, uint8_t rx_offset, uint8_t reported_len, const uint8_t *raw, uint8_t raw_len, const uint8_t *frame, uint8_t frame_len) override
Populate the RadioCaptureInfo from chip-specific telemetry (RSSI opcode, packet-status byte,...
void read_buffer_(uint8_t offset, uint8_t *data, uint8_t len)
Read from the SX1262 RX buffer.
uint32_t activity_irq_mask() const override
IRQ bits that count as "activity" for the internal poll_until_activity_() helper and check_for_packet...
int16_t early_rx_read_offset() const override
Data-buffer offset an in-flight reception is being written to, or a negative value when this chip mus...
void read_register_(uint16_t addr, uint8_t *data, uint8_t len)
Read from a register.
uint32_t preamble_detected_bit() const override
void dump_front_end() override
Dump the FEM profile and its antenna-power estimate (nothing without a FEM).
bool fem_tx_active_level_() const
The level fem_pa_pin_ is driven to for the duration of a transmission, for the current fem_profile_.
uint16_t get_device_errors_()
Read device error flags (and clear them).
SoftPhyDriverBase(InternalGPIOPin *rst_pin, InternalGPIOPin *busy_pin, uint32_t busy_timeout_ms, uint16_t default_response_preamble, uint16_t default_post_tx_settle_us)
void set_post_tx_settle_us_(uint16_t delay_us)
Set the delay between TX completion and re-entering RX.
void set_response_preamble_(uint16_t preamble)
Set the preamble length used for response/continuation frames within an exchange.
Interface for SPI bus access.
static constexpr uint8_t SX1262_SET_DIO3_AS_TCXO_CTRL
static constexpr uint8_t SX1262_CALIBRATE
static constexpr uint16_t SX1262_DEV_ERR_PLL_CALIB
PLL calibration failed.
static constexpr uint16_t SX1262_REG_RX_GAIN
static constexpr uint8_t SX1262_SET_BUFFER_BASE_ADDRESS
static constexpr uint16_t SX1262_DEV_ERR_PLL_LOCK
PLL failed to lock.
static constexpr uint8_t SX1262_CLEAR_DEVICE_ERRORS
static constexpr uint8_t SX1262_GFSK_CRC_OFF
SX1262RxBandwidth
Valid SX1262 RX bandwidth options (kHz register values).
@ BW_58_6_KHZ
58.6 kHz — default; the narrowest value validated on real hardware here.
static constexpr uint8_t SX1262_READ_REGISTER
static constexpr uint8_t SX1262_SET_PACKET_TYPE
static constexpr uint16_t SX1262_DEV_ERR_IMG_CALIB
Image calibration failed.
static constexpr uint16_t SX1262_IRQ_SYNC_WORD_VALID
static constexpr uint8_t SX1262_GET_DEVICE_ERRORS
FemProfile
Which RF front-end module (if any) sits between the SX1262 and the antenna.
@ NONE
No FEM, or a board with the FEM pins wired but no behaviour profile set – see the NONE-specific note ...
static constexpr uint16_t SX1262_DEV_ERR_RC13M_CALIB
13 MHz RC oscillator calibration failed.
static constexpr uint16_t SX1262_IRQ_CRC_ERR
static constexpr uint8_t SX1262_SET_MODULATION_PARAMS
static constexpr uint8_t SX1262_GET_RX_BUFFER_STATUS
void sx1262_format_device_errors(uint16_t errors, char *buf, size_t buf_size)
Expand a GetDeviceErrors word into a human-readable NAME|NAME|... string.
static constexpr uint16_t SX1262_REG_TX_MODULATION
TX modulation-quality erratum register (SX1262 datasheet §15.1, "Modulation Quality with500 kHz LoRa ...
static constexpr uint8_t SX1262_CLEAR_IRQ_STATUS
static constexpr uint8_t SX1262_SET_RX
static constexpr uint8_t SX1262_SET_TX
static constexpr uint8_t SX1262_GFSK_PACKET_TYPE_KNOWN_LENGTH
static constexpr uint32_t SX1262_BUSY_TIMEOUT_MS
How long SoftPhyDriverBase::wait_busy_() waits for BUSY to drop before declaring the chip failed.
static constexpr uint8_t SX1262_CALIBRATE_IMAGE
static constexpr uint8_t SX1262_SET_DIO2_AS_RF_SWITCH_CTRL
static constexpr uint8_t SX1262_WRITE_BUFFER
static constexpr uint16_t SX1262_DEV_ERR_PA_RAMP
PA ramping failed (bit 0x0080 is unused).
static constexpr uint8_t SX1262_READ_BUFFER
static constexpr uint16_t SX1262_IRQ_RX_DONE
static constexpr uint8_t SX1262_SET_PA_CONFIG
static constexpr uint8_t SX1262_SET_TX_PARAMS
static constexpr uint16_t SX1262_IRQ_TX_DONE
static constexpr uint16_t SX1262_DEV_ERR_XOSC_START
Crystal/TCXO failed to start.
static constexpr uint8_t SX1262_SET_DIO_IRQ_PARAMS
static constexpr uint16_t SX1262_DEV_ERR_ADC_CALIB
ADC calibration failed.
static constexpr uint8_t SX1262_SET_PACKET_PARAMS
static constexpr uint8_t SX1262_TX_MODULATION_GFSK_BIT
Bit 2 of SX1262_REG_TX_MODULATION — the (G)FSK-correct value is 1.
static constexpr uint8_t SX1262_GET_STATUS
static constexpr uint16_t SX1262_REG_TX_CLAMP_CONFIG
static constexpr uint16_t SX1262_IRQ_PREAMBLE_DETECTED
static constexpr uint8_t SX1262_SET_RX_TX_FALLBACK_MODE
static constexpr uint8_t SX1262_TX_BUFFER_BASE
Data-buffer split programmed by configure_buffer_base(): TX packets build from 0x00,...
static constexpr uint16_t SX1262_DEV_ERR_RC64K_CALIB
64 kHz RC oscillator calibration failed.
static constexpr uint8_t SX1262_RX_BUFFER_BASE
static constexpr uint16_t SX1262_IRQ_ACTIVITY_MASK
IRQ bits that represent a terminal radio event — a frame finished decoding, an outbound frame complet...
static constexpr uint8_t SX1262_GET_IRQ_STATUS
static constexpr uint8_t SX1262_SET_REGULATOR_MODE
static constexpr uint8_t SX1262_GET_PACKET_STATUS
FemTxEstimate sx1262_fem_tx_estimate(FemProfile profile, uint8_t tx_power)
Estimate what a FEM profile radiates for a configured tx_power.
static constexpr uint16_t SX1262_REG_SYNC_WORD
static constexpr uint8_t SX1262_FALLBACK_STDBY_XOSC
FemRxGain sx1262_fem_rx_gain(FemProfile profile)
The receive gain to remove from RSSI for a FEM profile.
static constexpr uint8_t SX1262_SET_RF_FREQUENCY
static constexpr uint8_t SX1262_SET_STANDBY
static constexpr uint8_t SX1262_WRITE_REGISTER
static constexpr uint8_t SX1262_GET_RSSI_INST
Shared driver flow for radios using the software PHY (SX1262, LR1121).
Receive-side gain of a FEM profile's LNA, in the SX1262's RSSI scale.
int8_t db
Gain (dB) the RSSI includes and the driver removes; 0 when unknown or absent.
const char * basis
Where the figure comes from and how far to trust it, for the config dump.
Antenna-port power estimate for a configured tx_power through a FEM profile's chain.
int antenna_dbm
Estimated antenna-port power in dBm — a rough bound, not a calibrated figure.
uint8_t tx_power
The tx_power actually programmed: the configured value clamped to SetTxParams' range.
All runtime tunable parameters for pairing and radio diagnostics.
SX1262RxBandwidth sx1262_rx_bandwidth
SX1262 RX bandwidth selector.
uint16_t sx1262_post_tx_settle_us
Delay after SX1262 TX before RX (µs).
uint16_t sx1262_response_preamble
SX1262 response preamble in bytes.
uint16_t sx1262_discovery_hop_slice_ms
Per-channel dwell while SX1262 discovery hops.