|
Home IO Control
ESPHome add-on for IO-Homecontrol devices
|
SX1262 implementation of RadioDriver. More...
#include <radio_sx1262.h>
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 RadioCaptureInfo & | get_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} |
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.
|
inline |
|
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.
|
overridevirtual |
Non-blocking check for a received packet.
Called from loop(). Returns true if a packet was read into packet. Contract:
Implements esphome::home_io_control::RadioDriver.
Definition at line 853 of file radio_sx1262.cpp.
|
inlinenodiscardoverridevirtual |
Get a human‑readable chip name.
Implements esphome::home_io_control::RadioDriver.
Definition at line 111 of file radio_sx1262.h.
|
protected |
Clear device error flags.
Definition at line 413 of file radio_sx1262.cpp.
|
protected |
Clear all IRQ status bits.
| irq_mask | Bitmask of IRQs to clear. |
Definition at line 399 of file radio_sx1262.cpp.
|
protected |
Full radio initialization (called from init()).
Definition at line 529 of file radio_sx1262.cpp.
|
overridevirtual |
Dump SX1262‑specific debug info.
Reimplemented from esphome::home_io_control::RadioDriver.
Definition at line 483 of file radio_sx1262.cpp.
|
protected |
Populate the RadioCaptureInfo from SX1262‑specific telemetry.
| blocking_wait | true if this was a blocking wait. |
| irq_status | Raw IRQ status. |
| rx_offset | Reported RX buffer offset. |
| reported_len | Length reported by the radio. |
| raw | Pointer to raw buffer bytes (may be nullptr). |
| raw_len | Length of raw buffer. |
| frame | Pointer to parsed frame bytes (may be nullptr). |
| frame_len | Length of parsed frame. |
Definition at line 428 of file radio_sx1262.cpp.
|
protected |
Read device error flags (and clear them).
Definition at line 407 of file radio_sx1262.cpp.
|
staticprotected |
DIO1 ISR — sets dio_fired flag. Runs in interrupt context.
Definition at line 445 of file radio_sx1262.cpp.
|
overridevirtual |
Initialize the radio hardware. Returns true on success.
Implements esphome::home_io_control::RadioDriver.
Definition at line 449 of file radio_sx1262.cpp.
|
inlinenodiscardoverridevirtual |
Returns true if the radio failed to initialize or encountered a fatal error.
Implements esphome::home_io_control::RadioDriver.
Definition at line 110 of file radio_sx1262.h.
|
protected |
Read from the SX1262 RX buffer.
| offset | Buffer offset. |
| data | Output buffer. |
| len | Number of bytes to read. |
Definition at line 362 of file radio_sx1262.cpp.
|
protectedvirtual |
Read the raw IRQ status from the radio.
Definition at line 256 of file radio_sx1262.cpp.
|
protected |
Read response from an opcode.
| opcode | Opcode that was previously written. |
| data | Output buffer. |
| len | Expected number of bytes to read. |
Definition at line 246 of file radio_sx1262.cpp.
|
protected |
Read from a register.
| addr | 16‑bit register address. |
| data | Output buffer. |
| len | Number of bytes to read. |
Definition at line 340 of file radio_sx1262.cpp.
|
overridevirtual |
Read instantaneous RSSI (in dBm) while in RX mode.
Used for listen-before-talk (LBT) carrier sense before transmitting.
Implements esphome::home_io_control::RadioDriver.
Definition at line 674 of file radio_sx1262.cpp.
|
protectedvirtual |
Read a received packet from the buffer and return the raw bytes reported by the chip.
This is virtual to allow test doubles.
| packet | Output RadioRxPacket. |
| blocking_wait | true if called from a blocking wait path. |
| irq_status | Raw IRQ status word. |
Definition at line 803 of file radio_sx1262.cpp.
|
protected |
Reset RX state machine and buffer.
Optionally force standby first.
| force_standby | If true, switch to standby before reset. |
Definition at line 418 of file radio_sx1262.cpp.
|
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.
|
protected |
Set RF frequency via the frequency register.
| freq_hz | Frequency in Hz. |
Definition at line 656 of file radio_sx1262.cpp.
|
overridevirtual |
Switch to continuous receive mode.
Implements esphome::home_io_control::RadioDriver.
Definition at line 649 of file radio_sx1262.cpp.
|
overridevirtual |
Switch to standby mode.
Implements esphome::home_io_control::RadioDriver.
Definition at line 644 of file radio_sx1262.cpp.
|
protected |
Configure packet parameters (preamble, payload length, CRC).
| preamble_len | Preamble length in symbols. |
| payload_len | Expected payload length. |
| packet_type | Fixed for GFSK. |
| crc_type | CRC configuration (off or on). |
Definition at line 375 of file radio_sx1262.cpp.
|
protected |
Apply RX‑specific packet parameters (calls set_packet_params_ for RX).
Definition at line 391 of file radio_sx1262.cpp.
|
staticprotected |
Software CRC helper kept for transmit framing parity with the current implementation.
Definition at line 196 of file radio_sx1262.cpp.
|
protected |
Wait until BUSY pin is low before any SPI transaction.
Definition at line 225 of file radio_sx1262.cpp.
|
overridevirtual |
Wait (blocking) for a packet with timeout.
Returns true if a packet was received. Contract:
Implements esphome::home_io_control::RadioDriver.
Definition at line 772 of file radio_sx1262.cpp.
|
protected |
Write into the SX1262 TX/RX buffer at a given offset.
| offset | Buffer offset. |
| data | Payload bytes. |
| len | Payload length. |
Definition at line 352 of file radio_sx1262.cpp.
|
protected |
Write an opcode with optional parameter bytes.
| opcode | SX1262 opcode. |
| params | Pointer to parameter buffer (may be nullptr). |
| len | Parameter length. |
Definition at line 237 of file radio_sx1262.cpp.
|
protected |
Write to a register (SX1262 uses opcodes for register access).
| addr | 16‑bit register address. |
| data | Pointer to data bytes. |
| len | Number of bytes. |
Definition at line 329 of file radio_sx1262.cpp.