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

SX1262 implementation of RadioDriver. More...

#include <radio_sx1262.h>

Inheritance diagram for esphome::home_io_control::RadioSX1262:
Collaboration diagram for esphome::home_io_control::RadioSX1262:

Public Member Functions

 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)
bool init () override
 Initialize the radio hardware. Returns true on success.
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.
void set_mode_rx () override
 Switch to continuous receive mode.
void set_mode_standby () override
 Switch to standby mode.
bool is_failed () const override
 Returns true if the radio failed to initialize or encountered a fatal error.
const char * chip_name () const override
 Get a human‑readable chip name.
void dump_debug () override
 Dump SX1262‑specific debug info.
Public Member Functions inherited from esphome::home_io_control::RadioDriver
 RadioDriver (InternalGPIOPin *rst_pin=nullptr)
virtual ~RadioDriver ()=default
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 wait_busy_ ()
 Wait until BUSY pin is low before any SPI transaction.
void write_opcode_ (uint8_t opcode, const uint8_t *params, uint8_t len)
 Write an opcode with optional parameter bytes.
void read_opcode_ (uint8_t opcode, uint8_t *data, uint8_t len)
 Read response from an opcode.
void write_register_ (uint16_t addr, const uint8_t *data, uint8_t len)
 Write to a register (SX1262 uses opcodes for register access).
void read_register_ (uint16_t addr, uint8_t *data, uint8_t len)
 Read from a register.
void write_buffer_ (uint8_t offset, const uint8_t *data, uint8_t len)
 Write into the SX1262 TX/RX buffer at a given offset.
void read_buffer_ (uint8_t offset, uint8_t *data, uint8_t len)
 Read from the SX1262 RX buffer.
void configure_radio_ ()
 Full radio initialization (called from init()).
void set_frequency_register_ (uint32_t freq_hz)
 Set RF frequency via the frequency register.
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 set_rx_packet_params_ ()
 Apply RX‑specific packet parameters (calls set_packet_params_ for RX).
void clear_irq_status_ (uint16_t irq_mask)
 Clear all IRQ status bits.
uint16_t get_device_errors_ ()
 Read device error flags (and clear them).
void clear_device_errors_ ()
 Clear device error flags.
void reset_rx_state_ (bool force_standby=true)
 Reset RX state machine and buffer.
void fill_capture_info_ (bool blocking_wait, uint16_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)
 Populate the RadioCaptureInfo from SX1262‑specific telemetry.
virtual bool read_rx_packet (RadioRxPacket &packet, bool blocking_wait, uint16_t irq_status)
 Read a received packet from the buffer and return the raw bytes reported by the chip.
virtual uint16_t read_irq_status_raw ()
 Read the raw IRQ status from the radio.
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_ ()
 Hardware reset sequence common to all SX chips.
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.

Static Protected Member Functions

static uint8_t uart_encode_packet (const uint8_t *data, uint8_t len, uint8_t *encoded, uint8_t encoded_max_len)
 Software CRC helper kept for transmit framing parity with the current implementation.
static void gpio_intr (RadioSX1262 *arg)
 DIO1 ISR — sets dio_fired flag. Runs in interrupt context.

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

SX1262 implementation of RadioDriver.

Manages the SX1262 via opcode‑based SPI using the SpiAccess interface. Configures the chip in FSK mode with software CRC‑CCITT to match the IO‑Homecontrol protocol (the SX1262 lacks the SX1276's IoHomeOn mode).

Definition at line 79 of file radio_sx1262.h.

Constructor & Destructor Documentation

◆ RadioSX1262()

esphome::home_io_control::RadioSX1262::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 )
inline

Definition at line 81 of file radio_sx1262.h.

Here is the call graph for this function:

Member Function Documentation

◆ change_frequency()

void esphome::home_io_control::RadioSX1262::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 668 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ check_for_packet()

bool esphome::home_io_control::RadioSX1262::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 853 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ chip_name()

const char * esphome::home_io_control::RadioSX1262::chip_name ( ) const
inlinenodiscardoverridevirtual

Get a human‑readable chip name.

Returns
"sx1276" or "sx1262".

Implements esphome::home_io_control::RadioDriver.

Definition at line 111 of file radio_sx1262.h.

◆ clear_device_errors_()

void esphome::home_io_control::RadioSX1262::clear_device_errors_ ( )
protected

Clear device error flags.

Definition at line 413 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ clear_irq_status_()

void esphome::home_io_control::RadioSX1262::clear_irq_status_ ( uint16_t irq_mask)
protected

Clear all IRQ status bits.

Parameters
irq_maskBitmask of IRQs to clear.

Definition at line 399 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ configure_radio_()

void esphome::home_io_control::RadioSX1262::configure_radio_ ( )
protected

Full radio initialization (called from init()).

Definition at line 529 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ dump_debug()

void esphome::home_io_control::RadioSX1262::dump_debug ( )
overridevirtual

Dump SX1262‑specific debug info.

Reimplemented from esphome::home_io_control::RadioDriver.

Definition at line 483 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ fill_capture_info_()

void esphome::home_io_control::RadioSX1262::fill_capture_info_ ( bool blocking_wait,
uint16_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 )
protected

Populate the RadioCaptureInfo from SX1262‑specific telemetry.

Parameters
blocking_waittrue if this was a blocking wait.
irq_statusRaw IRQ status.
rx_offsetReported RX buffer offset.
reported_lenLength reported by the radio.
rawPointer to raw buffer bytes (may be nullptr).
raw_lenLength of raw buffer.
framePointer to parsed frame bytes (may be nullptr).
frame_lenLength of parsed frame.

Definition at line 428 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ get_device_errors_()

uint16_t esphome::home_io_control::RadioSX1262::get_device_errors_ ( )
protected

Read device error flags (and clear them).

Returns
Error bitmask.

Definition at line 407 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ gpio_intr()

void IRAM_ATTR esphome::home_io_control::RadioSX1262::gpio_intr ( RadioSX1262 * arg)
staticprotected

DIO1 ISR — sets dio_fired flag. Runs in interrupt context.

Definition at line 445 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ init()

bool esphome::home_io_control::RadioSX1262::init ( )
overridevirtual

Initialize the radio hardware. Returns true on success.

Implements esphome::home_io_control::RadioDriver.

Definition at line 449 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ is_failed()

bool esphome::home_io_control::RadioSX1262::is_failed ( ) const
inlinenodiscardoverridevirtual

Returns true if the radio failed to initialize or encountered a fatal error.

Returns
true on failure.

Implements esphome::home_io_control::RadioDriver.

Definition at line 110 of file radio_sx1262.h.

◆ read_buffer_()

void esphome::home_io_control::RadioSX1262::read_buffer_ ( uint8_t offset,
uint8_t * data,
uint8_t len )
protected

Read from the SX1262 RX buffer.

Parameters
offsetBuffer offset.
dataOutput buffer.
lenNumber of bytes to read.

Definition at line 362 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ read_irq_status_raw()

uint16_t esphome::home_io_control::RadioSX1262::read_irq_status_raw ( )
protectedvirtual

Read the raw IRQ status from the radio.

Returns
16‑bit IRQ status word.

Definition at line 256 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ read_opcode_()

void esphome::home_io_control::RadioSX1262::read_opcode_ ( uint8_t opcode,
uint8_t * data,
uint8_t len )
protected

Read response from an opcode.

Parameters
opcodeOpcode that was previously written.
dataOutput buffer.
lenExpected number of bytes to read.

Definition at line 246 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ read_register_()

void esphome::home_io_control::RadioSX1262::read_register_ ( uint16_t addr,
uint8_t * data,
uint8_t len )
protected

Read from a register.

Parameters
addr16‑bit register address.
dataOutput buffer.
lenNumber of bytes to read.

Definition at line 340 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ read_rssi()

int16_t esphome::home_io_control::RadioSX1262::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).

Implements esphome::home_io_control::RadioDriver.

Definition at line 674 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ read_rx_packet()

bool esphome::home_io_control::RadioSX1262::read_rx_packet ( RadioRxPacket & packet,
bool blocking_wait,
uint16_t irq_status )
protectedvirtual

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

This is virtual to allow test doubles.

Parameters
packetOutput RadioRxPacket.
blocking_waittrue if called from a blocking wait path.
irq_statusRaw IRQ status word.
Returns
true if a valid packet was extracted; false otherwise.

Definition at line 803 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ reset_rx_state_()

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

Reset RX state machine and buffer.

Optionally force standby first.

Parameters
force_standbyIf true, switch to standby before reset.

Definition at line 418 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ send_packet()

bool esphome::home_io_control::RadioSX1262::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 radio handles CRC automatically (IoHomeOn mode for SX1276).

Implements esphome::home_io_control::RadioDriver.

Definition at line 682 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ set_frequency_register_()

void esphome::home_io_control::RadioSX1262::set_frequency_register_ ( uint32_t freq_hz)
protected

Set RF frequency via the frequency register.

Parameters
freq_hzFrequency in Hz.

Definition at line 656 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ set_mode_rx()

void esphome::home_io_control::RadioSX1262::set_mode_rx ( )
overridevirtual

Switch to continuous receive mode.

Implements esphome::home_io_control::RadioDriver.

Definition at line 649 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ set_mode_standby()

void esphome::home_io_control::RadioSX1262::set_mode_standby ( )
overridevirtual

Switch to standby mode.

Implements esphome::home_io_control::RadioDriver.

Definition at line 644 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ set_packet_params_()

void esphome::home_io_control::RadioSX1262::set_packet_params_ ( uint16_t preamble_len,
uint8_t payload_len,
uint8_t packet_type,
uint8_t crc_type )
protected

Configure packet parameters (preamble, payload length, CRC).

Parameters
preamble_lenPreamble length in symbols.
payload_lenExpected payload length.
packet_typeFixed for GFSK.
crc_typeCRC configuration (off or on).

Definition at line 375 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ set_rx_packet_params_()

void esphome::home_io_control::RadioSX1262::set_rx_packet_params_ ( )
protected

Apply RX‑specific packet parameters (calls set_packet_params_ for RX).

Definition at line 391 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ uart_encode_packet()

uint8_t esphome::home_io_control::RadioSX1262::uart_encode_packet ( const uint8_t * data,
uint8_t len,
uint8_t * encoded,
uint8_t encoded_max_len )
staticprotected

Software CRC helper kept for transmit framing parity with the current implementation.

Returns
Number of encoded bytes, or 0 if buffer too small.

Definition at line 196 of file radio_sx1262.cpp.

◆ wait_busy_()

void esphome::home_io_control::RadioSX1262::wait_busy_ ( )
protected

Wait until BUSY pin is low before any SPI transaction.

Definition at line 225 of file radio_sx1262.cpp.

◆ wait_for_packet()

bool esphome::home_io_control::RadioSX1262::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 772 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ write_buffer_()

void esphome::home_io_control::RadioSX1262::write_buffer_ ( uint8_t offset,
const uint8_t * data,
uint8_t len )
protected

Write into the SX1262 TX/RX buffer at a given offset.

Parameters
offsetBuffer offset.
dataPayload bytes.
lenPayload length.

Definition at line 352 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ write_opcode_()

void esphome::home_io_control::RadioSX1262::write_opcode_ ( uint8_t opcode,
const uint8_t * params,
uint8_t len )
protected

Write an opcode with optional parameter bytes.

Parameters
opcodeSX1262 opcode.
paramsPointer to parameter buffer (may be nullptr).
lenParameter length.

Definition at line 237 of file radio_sx1262.cpp.

Here is the call graph for this function:

◆ write_register_()

void esphome::home_io_control::RadioSX1262::write_register_ ( uint16_t addr,
const uint8_t * data,
uint8_t len )
protected

Write to a register (SX1262 uses opcodes for register access).

Parameters
addr16‑bit register address.
dataPointer to data bytes.
lenNumber of bytes.

Definition at line 329 of file radio_sx1262.cpp.

Here is the call graph for this function:

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