Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
esphome::home_io_control::SoftPhyDriverBase Class Referenceabstract

Shared RX/TX driver flow for the software-PHY radios (SX1262, LR1121). More...

#include <radio_soft_phy_driver_base.h>

Inheritance diagram for esphome::home_io_control::SoftPhyDriverBase:
Collaboration diagram for esphome::home_io_control::SoftPhyDriverBase:

Public Member Functions

 SoftPhyDriverBase (InternalGPIOPin *rst_pin, uint16_t default_response_preamble, uint16_t default_post_tx_settle_us)
bool send_packet (const uint8_t *data, uint8_t len, const RadioTxConfig &tx_config) override
 Send a packet using the specified carrier frequency and preamble settings.
bool wait_for_packet (RadioRxPacket &packet, uint32_t timeout_ms) override
 Wait (blocking) for a packet with timeout.
bool check_for_packet (RadioRxPacket &packet) override
 Non-blocking check for a received packet.
void change_frequency (uint32_t freq_hz) override
 Change the carrier frequency using fast hop (no standby transition needed).
int16_t read_rssi () override
 Read instantaneous RSSI (in dBm) while in RX mode.
bool is_sync_detected () override
 Check if sync word has been detected (while in RX).
bool is_preamble_detected () override
 Check if preamble has been detected (while in RX).
uint16_t response_preamble () const override
 Preamble for response/continuation frames — shared storage, see the concrete drivers' constructors/tuning defaults for the chip-specific rationale and value.
Public Member Functions inherited from esphome::home_io_control::RadioDriver
 RadioDriver (InternalGPIOPin *rst_pin=nullptr)
virtual ~RadioDriver ()=default
virtual bool init ()=0
 Initialize the radio hardware. Returns true on success.
virtual void apply_tuning (const TuningConfig &tuning)
 Apply runtime tuning parameters to the driver.
virtual uint32_t exchange_wait_slice_ms () const
 Per-channel dwell while waiting for an authenticated exchange response.
virtual uint16_t discovery_hop_slice_ms (const TuningConfig &tuning) const =0
 Per-channel dwell while pairing discovery hops across channels.
virtual bool has_fast_tx_rx_turnaround () const =0
 Whether the chip re-enters RX fast enough after a TX to catch an immediate reply through the standard exchange wait.
virtual void set_mode_rx ()=0
 Switch to continuous receive mode.
virtual void set_mode_standby ()=0
 Switch to standby mode.
virtual bool is_failed () const =0
 Returns true if the radio failed to initialize or encountered a fatal error.
virtual const char * chip_name () const =0
 Get a human‑readable chip name.
virtual void dump_debug ()
 Optional chip-specific diagnostics emitted from dump_config.
uint32_t get_current_freq () const
 Get the current RF frequency.
const RadioCaptureInfoget_last_capture () const
 Get the most recent radio capture info.
bool is_dio_fired () const
 Set by the ISR when DIO fires.
void clear_dio_fired ()
void mark_dio_fired_from_isr ()

Protected Member Functions

void set_response_preamble_ (uint16_t preamble)
 Set the preamble length used for response/continuation frames within an exchange.
void set_post_tx_settle_us_ (uint16_t delay_us)
 Set the delay between TX completion and re-entering RX.
virtual bool read_rx_packet (RadioRxPacket &packet, bool blocking_wait, uint32_t irq_status)
 Read a received packet from the buffer and return the raw bytes reported by the chip.
void reset_rx_state_ (bool force_standby=true)
 Reset RX state machine and buffer. Optionally force standby first.
virtual uint32_t read_irq_status_raw ()=0
 Read the raw IRQ status word from the radio.
virtual void clear_irq_status (uint32_t irq_mask)=0
 Clear IRQ status bits.
virtual uint32_t activity_irq_mask () const
 IRQ bits that count as "activity" for the internal poll_until_activity_() helper and check_for_packet.
virtual int16_t early_rx_read_offset () const
 Data-buffer offset an in-flight reception is being written to, or a negative value when this chip must not be read before RX_DONE.
virtual void set_frequency_register (uint32_t freq_hz)=0
 Set RF frequency via the chip's own frequency register/opcode encoding, and update current_freq_.
virtual void set_rx_packet_params ()=0
 Configure RX-specific packet parameters (preamble detector length, fixed probe length).
virtual void set_tx_packet_params (uint16_t preamble_len, uint8_t payload_len)=0
 Configure TX packet parameters for one outgoing UART-encoded frame.
virtual uint8_t read_rssi_raw_byte ()=0
 Read the single raw RSSI byte (chip-specific opcode); formula is shared, see read_rssi.
virtual void write_tx_buffer (const uint8_t *data, uint8_t len)=0
 Write the UART-encoded TX payload into the chip's TX buffer.
virtual void get_rx_buffer_status (uint8_t &reported_len, uint8_t &rx_offset)=0
 Read the chip-reported RX length and buffer offset (raw, before any clamping).
virtual void read_rx_buffer (uint8_t offset, uint8_t *data, uint8_t len)=0
 Read len bytes from the RX buffer starting at offset.
virtual void start_tx ()=0
 Issue the SetTx opcode with the fixed TX timeout — identical 3-byte payload on both chips, differing only in opcode/transport, so this stays a thin chip-specific wrapper.
virtual 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)=0
 Populate the RadioCaptureInfo from chip-specific telemetry (RSSI opcode, packet-status byte, and IRQ-word-width narrowing all differ per chip).
virtual void before_tx_arm ()
 Hook run immediately before every SetTx.
virtual void configure_buffer_base ()
 Hook run as part of reset_rx_state_, before re-entering RX.
Chip-specific IRQ bit values

Each driver's own IRQ bit constants, exposed as accessors so the shared RX/TX orchestration never needs to name a chip-specific constant directly.

virtual uint32_t sync_word_valid_bit () const =0
virtual uint32_t rx_done_bit () const =0
virtual uint32_t tx_done_bit () const =0
virtual uint32_t preamble_detected_bit () const =0
Protected Member Functions inherited from esphome::home_io_control::RadioDriver
void clear_last_capture_ ()
 Clear the last capture info (resets diagnostic buffer).
void prepare_blocking_receive_ (RadioRxPacket &packet)
 Common preamble for blocking receive: clear diagnostics and output packet.
void prepare_nonblocking_receive_ (RadioRxPacket &packet)
 Common preamble for non‑blocking receive: clear diagnostics, output packet, and DIO latch.
void reset_hardware_ ()
 Shared hardware reset sequence for chips with an active-low RST pin.
void populate_capture_base_ (bool blocking_wait, uint32_t freq_hz, int16_t rssi_dbm, const uint8_t *raw, uint8_t raw_len, const uint8_t *frame, uint8_t frame_len)
 Populate the common fields of RadioCaptureInfo from raw telemetry.

Additional Inherited Members

Protected Attributes inherited from esphome::home_io_control::RadioDriver
uint32_t current_freq_ {FREQ_CH2}
RadioCaptureInfo last_capture_ {}
InternalGPIOPin * rst_pin_ {nullptr}
volatile bool dio_fired_ {false}

Detailed Description

Shared RX/TX driver flow for the software-PHY radios (SX1262, LR1121).

Definition at line 85 of file radio_soft_phy_driver_base.h.

Constructor & Destructor Documentation

◆ SoftPhyDriverBase()

esphome::home_io_control::SoftPhyDriverBase::SoftPhyDriverBase ( InternalGPIOPin * rst_pin,
uint16_t default_response_preamble,
uint16_t default_post_tx_settle_us )
inline
Parameters
rst_pinActive-low hardware reset pin, forwarded to RadioDriver.
default_response_preambleChip-specific default for response_preamble (each concrete driver passes its own validated constant — this class has no opinion on the value, only on where it's stored).
default_post_tx_settle_usChip-specific default post-TX settling delay, same rationale.

Definition at line 92 of file radio_soft_phy_driver_base.h.

Here is the call graph for this function:

Member Function Documentation

◆ activity_irq_mask()

virtual uint32_t esphome::home_io_control::SoftPhyDriverBase::activity_irq_mask ( ) const
inlinenodiscardprotectedvirtual

IRQ bits that count as "activity" for the internal poll_until_activity_() helper and check_for_packet.

Default is "any bit" — correct for SX1262, whose SetDioIrqParams mask already excludes PreambleDetected system-wide, so a preamble-only reading can never reach this check in the first place. LR1121 routes PreambleDetected to its IRQ pin for other reasons and overrides this to exclude it: a preamble-only reading means a frame may still be arriving, and treating it as terminal activity would tear down RX mid-reception.

Reimplemented in esphome::home_io_control::RadioLR1121.

Definition at line 157 of file radio_soft_phy_driver_base.h.

◆ before_tx_arm()

virtual void esphome::home_io_control::SoftPhyDriverBase::before_tx_arm ( )
inlineprotectedvirtual

Hook run immediately before every SetTx.

No-op by default; LR1121 overrides this to apply its high-ACP TX-quality workaround, which Semtech's own reference applies unconditionally before every SetRx/SetTx.

Reimplemented in esphome::home_io_control::RadioLR1121, and esphome::home_io_control::RadioSX1262.

Definition at line 202 of file radio_soft_phy_driver_base.h.

◆ change_frequency()

void esphome::home_io_control::SoftPhyDriverBase::change_frequency ( uint32_t freq_hz)
overridevirtual

Change the carrier frequency using fast hop (no standby transition needed).

Implements esphome::home_io_control::RadioDriver.

Definition at line 423 of file radio_soft_phy_driver_base.cpp.

Here is the call graph for this function:

◆ check_for_packet()

bool esphome::home_io_control::SoftPhyDriverBase::check_for_packet ( RadioRxPacket & packet)
overridevirtual

Non-blocking check for a received packet.

Called from loop(). Returns true if a packet was read into packet. Contract:

  • Returns false immediately if no DIO interrupt has fired.
  • On success: populates packet and last_capture_, returns true.
  • On failure: may populate last_capture_ for diagnostics, returns false.

Implements esphome::home_io_control::RadioDriver.

Definition at line 302 of file radio_soft_phy_driver_base.cpp.

Here is the call graph for this function:

◆ clear_irq_status()

virtual void esphome::home_io_control::SoftPhyDriverBase::clear_irq_status ( uint32_t irq_mask)
protectedpure virtual

Clear IRQ status bits.

Parameters
irq_maskBitmask of IRQs to clear (each driver narrows to its own IRQ word width).

Implemented in esphome::home_io_control::RadioLR1121, and esphome::home_io_control::RadioSX1262.

◆ configure_buffer_base()

virtual void esphome::home_io_control::SoftPhyDriverBase::configure_buffer_base ( )
inlineprotectedvirtual

Hook run as part of reset_rx_state_, before re-entering RX.

No-op by default; SX1262 overrides this to (re-)write its buffer base address, which LR1121 doesn't need.

Reimplemented in esphome::home_io_control::RadioSX1262.

Definition at line 205 of file radio_soft_phy_driver_base.h.

◆ early_rx_read_offset()

virtual int16_t esphome::home_io_control::SoftPhyDriverBase::early_rx_read_offset ( ) const
inlinenodiscardprotectedvirtual

Data-buffer offset an in-flight reception is being written to, or a negative value when this chip must not be read before RX_DONE.

Neither chip's RX_DONE marks the end of the frame: with no hardware framing, RX runs in fixed-length mode at SOFT_PHY_RX_PROBE_PACKET_LEN, so RX_DONE arrives a fixed ~10 ms after the sync word no matter how short the frame actually was. That delay lands squarely on the protocol's tightest turnaround — the hub's reply to a device's challenge — so a driver that can read its buffer while reception is still running opts in here and the shared flow finishes on the frame's own air time instead (see try_early_completion_).

Default is -1: wait for RX_DONE exactly as before. SX1262 overrides it with the RX base address it programs in configure_buffer_base(), which is where a single in-flight packet always starts. LR1121 is left on the RX_DONE path pending hardware validation.

Reimplemented in esphome::home_io_control::RadioSX1262.

Definition at line 172 of file radio_soft_phy_driver_base.h.

◆ fill_capture_info()

virtual void esphome::home_io_control::SoftPhyDriverBase::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 )
protectedpure virtual

Populate the RadioCaptureInfo from chip-specific telemetry (RSSI opcode, packet-status byte, and IRQ-word-width narrowing all differ per chip).

Implemented in esphome::home_io_control::RadioLR1121, and esphome::home_io_control::RadioSX1262.

◆ get_rx_buffer_status()

virtual void esphome::home_io_control::SoftPhyDriverBase::get_rx_buffer_status ( uint8_t & reported_len,
uint8_t & rx_offset )
protectedpure virtual

Read the chip-reported RX length and buffer offset (raw, before any clamping).

Implemented in esphome::home_io_control::RadioLR1121, and esphome::home_io_control::RadioSX1262.

◆ is_preamble_detected()

bool esphome::home_io_control::SoftPhyDriverBase::is_preamble_detected ( )
overridevirtual

Check if preamble has been detected (while in RX).

Used together with sync detection to gate frequency hopping.

Implements esphome::home_io_control::RadioDriver.

Definition at line 437 of file radio_soft_phy_driver_base.cpp.

Here is the call graph for this function:

◆ is_sync_detected()

bool esphome::home_io_control::SoftPhyDriverBase::is_sync_detected ( )
overridevirtual

Check if sync word has been detected (while in RX).

Used to gate frequency hopping — prevents hopping away mid-frame.

Implements esphome::home_io_control::RadioDriver.

Definition at line 435 of file radio_soft_phy_driver_base.cpp.

Here is the call graph for this function:

◆ preamble_detected_bit()

virtual uint32_t esphome::home_io_control::SoftPhyDriverBase::preamble_detected_bit ( ) const
nodiscardprotectedpure virtual

◆ read_irq_status_raw()

virtual uint32_t esphome::home_io_control::SoftPhyDriverBase::read_irq_status_raw ( )
protectedpure virtual

Read the raw IRQ status word from the radio.

Virtual to allow test doubles (both concrete drivers' tests override this).

Implemented in esphome::home_io_control::RadioLR1121, and esphome::home_io_control::RadioSX1262.

◆ read_rssi()

int16_t esphome::home_io_control::SoftPhyDriverBase::read_rssi ( )
overridevirtual

Read instantaneous RSSI (in dBm) while in RX mode.

Used for listen-before-talk (LBT) carrier sense before transmitting.

Returns
RSSI in dBm (negative value).

Same formula on both chips (-(int16_t) raw / 2); only the opcode used to read the single raw byte differs, via read_rssi_raw_byte.

Implements esphome::home_io_control::RadioDriver.

Definition at line 433 of file radio_soft_phy_driver_base.cpp.

Here is the call graph for this function:

◆ read_rssi_raw_byte()

virtual uint8_t esphome::home_io_control::SoftPhyDriverBase::read_rssi_raw_byte ( )
protectedpure virtual

Read the single raw RSSI byte (chip-specific opcode); formula is shared, see read_rssi.

Implemented in esphome::home_io_control::RadioLR1121, and esphome::home_io_control::RadioSX1262.

◆ read_rx_buffer()

virtual void esphome::home_io_control::SoftPhyDriverBase::read_rx_buffer ( uint8_t offset,
uint8_t * data,
uint8_t len )
protectedpure virtual

Read len bytes from the RX buffer starting at offset.

Implemented in esphome::home_io_control::RadioLR1121, and esphome::home_io_control::RadioSX1262.

◆ read_rx_packet()

bool esphome::home_io_control::SoftPhyDriverBase::read_rx_packet ( RadioRxPacket & packet,
bool blocking_wait,
uint32_t irq_status )
protectedvirtual

Read a received packet from the buffer and return the raw bytes reported by the chip.

Virtual to allow test doubles (both concrete drivers' tests override this).

Definition at line 223 of file radio_soft_phy_driver_base.cpp.

Here is the call graph for this function:

◆ reset_rx_state_()

void esphome::home_io_control::SoftPhyDriverBase::reset_rx_state_ ( bool force_standby = true)
protected

Reset RX state machine and buffer. Optionally force standby first.

Definition at line 214 of file radio_soft_phy_driver_base.cpp.

Here is the call graph for this function:

◆ response_preamble()

uint16_t esphome::home_io_control::SoftPhyDriverBase::response_preamble ( ) const
inlinenodiscardoverridevirtual

Preamble for response/continuation frames — shared storage, see the concrete drivers' constructors/tuning defaults for the chip-specific rationale and value.

Reimplemented from esphome::home_io_control::RadioDriver.

Definition at line 116 of file radio_soft_phy_driver_base.h.

◆ rx_done_bit()

virtual uint32_t esphome::home_io_control::SoftPhyDriverBase::rx_done_bit ( ) const
nodiscardprotectedpure virtual

◆ send_packet()

bool esphome::home_io_control::SoftPhyDriverBase::send_packet ( const uint8_t * data,
uint8_t len,
const RadioTxConfig & tx_config )
overridevirtual

Send a packet using the specified carrier frequency and preamble settings.

The driver is responsible for appending the protocol CRC on the air (in hardware or software, depending on the chip).

Implements esphome::home_io_control::RadioDriver.

Definition at line 338 of file radio_soft_phy_driver_base.cpp.

Here is the call graph for this function:

◆ set_frequency_register()

virtual void esphome::home_io_control::SoftPhyDriverBase::set_frequency_register ( uint32_t freq_hz)
protectedpure virtual

Set RF frequency via the chip's own frequency register/opcode encoding, and update current_freq_.

Called from both change_frequency and the shared send_packet().

Implemented in esphome::home_io_control::RadioLR1121, and esphome::home_io_control::RadioSX1262.

◆ set_post_tx_settle_us_()

void esphome::home_io_control::SoftPhyDriverBase::set_post_tx_settle_us_ ( uint16_t delay_us)
inlineprotected

Set the delay between TX completion and re-entering RX.

Definition at line 123 of file radio_soft_phy_driver_base.h.

◆ set_response_preamble_()

void esphome::home_io_control::SoftPhyDriverBase::set_response_preamble_ ( uint16_t preamble)
inlineprotected

Set the preamble length used for response/continuation frames within an exchange.

Definition at line 121 of file radio_soft_phy_driver_base.h.

◆ set_rx_packet_params()

virtual void esphome::home_io_control::SoftPhyDriverBase::set_rx_packet_params ( )
protectedpure virtual

Configure RX-specific packet parameters (preamble detector length, fixed probe length).

Implemented in esphome::home_io_control::RadioLR1121, and esphome::home_io_control::RadioSX1262.

◆ set_tx_packet_params()

virtual void esphome::home_io_control::SoftPhyDriverBase::set_tx_packet_params ( uint16_t preamble_len,
uint8_t payload_len )
protectedpure virtual

Configure TX packet parameters for one outgoing UART-encoded frame.

Parameters
preamble_lenPreamble length in symbols, from the caller's RadioTxConfig.
payload_lenUART-encoded payload length in bytes.

Implemented in esphome::home_io_control::RadioLR1121, and esphome::home_io_control::RadioSX1262.

◆ start_tx()

virtual void esphome::home_io_control::SoftPhyDriverBase::start_tx ( )
protectedpure virtual

Issue the SetTx opcode with the fixed TX timeout — identical 3-byte payload on both chips, differing only in opcode/transport, so this stays a thin chip-specific wrapper.

Implemented in esphome::home_io_control::RadioLR1121, and esphome::home_io_control::RadioSX1262.

◆ sync_word_valid_bit()

virtual uint32_t esphome::home_io_control::SoftPhyDriverBase::sync_word_valid_bit ( ) const
nodiscardprotectedpure virtual

◆ tx_done_bit()

virtual uint32_t esphome::home_io_control::SoftPhyDriverBase::tx_done_bit ( ) const
nodiscardprotectedpure virtual

◆ wait_for_packet()

bool esphome::home_io_control::SoftPhyDriverBase::wait_for_packet ( RadioRxPacket & packet,
uint32_t timeout_ms )
overridevirtual

Wait (blocking) for a packet with timeout.

Returns true if a packet was received. Contract:

  • Clears last_capture_ and output packet before waiting.
  • On success: populates packet and last_capture_, returns true.
  • On timeout/failure: may populate last_capture_ for diagnostics, returns false.
  • Radio remains in RX mode on return (regardless of outcome).

Implements esphome::home_io_control::RadioDriver.

Definition at line 48 of file radio_soft_phy_driver_base.cpp.

Here is the call graph for this function:

◆ write_tx_buffer()

virtual void esphome::home_io_control::SoftPhyDriverBase::write_tx_buffer ( const uint8_t * data,
uint8_t len )
protectedpure virtual

Write the UART-encoded TX payload into the chip's TX buffer.

Implemented in esphome::home_io_control::RadioLR1121, and esphome::home_io_control::RadioSX1262.


The documentation for this class was generated from the following files: