|
Home IO Control
ESPHome add-on for IO-Homecontrol devices
|
SX1276 implementation of RadioDriver. More...
#include <radio_sx1276.h>
Public Member Functions | |
| RadioSX1276 (SpiAccess *spi, InternalGPIOPin *rst_pin, InternalGPIOPin *dio0_pin, InternalGPIOPin *dio4_pin, uint8_t tx_power, uint8_t pa_pin) | |
| bool | init () override |
| Initialize the SX1276 radio (reset, calibrate, configure registers). | |
| bool | send_packet (const uint8_t *data, uint8_t len, const RadioTxConfig &tx_config) override |
| Transmit a frame with specified frequency and preamble. | |
| bool | wait_for_packet (RadioRxPacket &packet, uint32_t timeout_ms) override |
| Blocking wait for a packet with timeout. | |
| bool | check_for_packet (RadioRxPacket &packet) override |
| Non‑blocking check for a received packet (called from loop). | |
| void | change_frequency (uint32_t freq_hz) override |
| Change RF frequency using fast hop (no standby needed). | |
| int16_t | read_rssi () override |
| Read instantaneous RSSI (dBm) while in RX mode (used for LBT). | |
| 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 | discovery_hop_slice_ms (const TuningConfig &tuning) const override |
| Per-channel dwell while pairing discovery hops (SX1276). | |
| bool | has_fast_tx_rx_turnaround () const override |
| TX→RX turnaround capability (SX1276): fast. | |
| uint16_t | response_preamble () const override |
| Preamble for response/continuation frames (SX1276). | |
| void | apply_tuning (const TuningConfig &tuning) override |
| Apply SX1276 runtime tuning: RX bandwidth and response preamble. | |
| void | set_mode_rx () override |
| Switch radio into continuous receive mode. | |
| void | set_mode_standby () override |
| Switch radio into 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 radio‑specific debug info to log. | |
| Public Member Functions inherited from esphome::home_io_control::RadioDriver | |
| RadioDriver (InternalGPIOPin *rst_pin=nullptr) | |
| virtual | ~RadioDriver ()=default |
| virtual uint32_t | exchange_wait_slice_ms () const |
| Per-channel dwell while waiting for an authenticated exchange response. | |
| 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 | set_rx_bandwidth_ (SX1276RxBandwidth bandwidth) |
| Apply the RX bandwidth selector to REG_RX_BW and REG_AFC_BW. | |
| void | set_response_preamble_ (uint16_t preamble) |
| Set the preamble length used for response/continuation frames within an exchange. | |
| uint8_t | read_register_ (uint8_t reg) |
| Read an SX1276 register over SPI. | |
| void | write_register_ (uint8_t reg, uint8_t value) |
| Write an SX1276 register over SPI. | |
| void | set_mode_ (uint8_t mode) |
| Set the operating mode (sleep/standby/tx/rx) and wait for mode completion. | |
| void | configure_radio_ () |
| Perform full radio configuration (called during init). | |
| void | run_image_cal_ () |
| Run image calibration routine (required after reset). | |
| bool | poll_until_payload_ready_ (uint32_t timeout_ms, bool &saw_dio0, uint8_t &irq1, uint8_t &irq2) |
| Wait until FIFO payload is ready (polling for TX/RX readiness). | |
| uint8_t | read_fifo_packet_ (uint8_t *buf, uint8_t buf_size) |
| Read a packet from the RX FIFO into a buffer. | |
| void | fill_capture_info_ (bool blocking_wait, uint8_t irq1, uint8_t irq2, uint8_t rssi, const uint8_t *raw, uint8_t raw_len, const uint8_t *frame, uint8_t frame_len) |
| Populate last_capture_ from raw telemetry. | |
| 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. | |
Static Protected Member Functions | |
| static void | gpio_intr (RadioSX1276 *arg) |
| DIO0 ISR — sets dio_fired flag. Runs in interrupt context. | |
Protected Attributes | |
| SpiAccess * | spi_ |
| InternalGPIOPin * | dio0_pin_ |
| InternalGPIOPin * | dio4_pin_ |
| uint8_t | tx_power_ |
| uint8_t | pa_pin_ |
| bool | failed_ {false} |
| SX1276RxBandwidth | rx_bandwidth_ {SX1276RxBandwidth::BW_41_7_KHZ} |
| Runtime-tunable RX bandwidth. | |
| uint16_t | response_preamble_ {SX1276_RESPONSE_PREAMBLE} |
| Runtime-tunable response preamble. | |
| 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} |
SX1276 implementation of RadioDriver.
Manages the SX1276 via SPI using the SpiAccess interface. Configures the chip in FSK mode with IoHomeOn for hardware CRC and IO‑Homecontrol packet framing.
Definition at line 78 of file radio_sx1276.h.
|
inline |
|
inlineoverridevirtual |
Apply SX1276 runtime tuning: RX bandwidth and response preamble.
Reimplemented from esphome::home_io_control::RadioDriver.
Definition at line 137 of file radio_sx1276.h.
|
overridevirtual |
Change RF frequency using fast hop (no standby needed).
| freq_hz | New frequency in Hz. |
Implements esphome::home_io_control::RadioDriver.
Definition at line 90 of file radio_sx1276.cpp.
|
overridevirtual |
Non‑blocking check for a received packet (called from loop).
| packet | Output: received packet if any. |
Implements esphome::home_io_control::RadioDriver.
Definition at line 326 of file radio_sx1276.cpp.
|
inlinenodiscardoverridevirtual |
Get a human‑readable chip name.
Implements esphome::home_io_control::RadioDriver.
Definition at line 148 of file radio_sx1276.h.
|
protected |
Perform full radio configuration (called during init).
Definition at line 136 of file radio_sx1276.cpp.
|
inlinenodiscardoverridevirtual |
Per-channel dwell while pairing discovery hops (SX1276).
The SX1276 supports FastHop (PllHop), so frequency changes need no standby transition and a short slice is enough. The value comes from the user-facing sx1276_discovery_hop_slice_ms tuning field.
Implements esphome::home_io_control::RadioDriver.
Definition at line 122 of file radio_sx1276.h.
|
overridevirtual |
Dump radio‑specific debug info to log.
Reimplemented from esphome::home_io_control::RadioDriver.
Definition at line 351 of file radio_sx1276.cpp.
|
protected |
Populate last_capture_ from raw telemetry.
Note: crc_error is never set on this driver — in IoHomeOn mode the hardware silently drops frames with a bad CRC before they reach the FIFO.
| blocking_wait | if this was a blocking receive. |
| irq1 | IRQ flags 1. |
| irq2 | IRQ flags 2. |
| rssi | RSSI value. |
| raw | Pointer to raw 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 77 of file radio_sx1276.cpp.
|
staticprotected |
DIO0 ISR — sets dio_fired flag. Runs in interrupt context.
Definition at line 75 of file radio_sx1276.cpp.
|
inlinenodiscardoverridevirtual |
TX→RX turnaround capability (SX1276): fast.
The IoHomeOn TX path returns to RX quickly enough that immediate replies (including the pairing key-confirm 0x33) are caught through the standard exchange wait — validated by real-hardware pairing on this driver.
Implements esphome::home_io_control::RadioDriver.
Definition at line 130 of file radio_sx1276.h.
|
overridevirtual |
Initialize the SX1276 radio (reset, calibrate, configure registers).
Implements esphome::home_io_control::RadioDriver.
Definition at line 110 of file radio_sx1276.cpp.
|
inlinenodiscardoverridevirtual |
Returns true if the radio failed to initialize or encountered a fatal error.
Implements esphome::home_io_control::RadioDriver.
Definition at line 146 of file radio_sx1276.h.
|
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 104 of file radio_sx1276.cpp.
|
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 100 of file radio_sx1276.cpp.
|
protected |
Wait until FIFO payload is ready (polling for TX/RX readiness).
| timeout_ms | How long to wait. |
| saw_dio0 | Output: true if DIO0 fired. |
| irq1 | Output: IRQ flags 1. |
| irq2 | Output: IRQ flags 2. |
Definition at line 269 of file radio_sx1276.cpp.
|
protected |
Read a packet from the RX FIFO into a buffer.
| buf | Output buffer. |
| buf_size | Size of buf. |
Definition at line 293 of file radio_sx1276.cpp.
|
protected |
Read an SX1276 register over SPI.
| reg | Register address (7 bits, MSB clear for read). |
Definition at line 24 of file radio_sx1276.cpp.
|
overridevirtual |
Read instantaneous RSSI (dBm) while in RX mode (used for LBT).
Implements esphome::home_io_control::RadioDriver.
Definition at line 98 of file radio_sx1276.cpp.
|
inlinenodiscardoverridevirtual |
Preamble for response/continuation frames (SX1276).
Runtime-tunable; the default and its hardware rationale are documented at SX1276_RESPONSE_PREAMBLE.
Reimplemented from esphome::home_io_control::RadioDriver.
Definition at line 135 of file radio_sx1276.h.
|
protected |
Run image calibration routine (required after reset).
Definition at line 61 of file radio_sx1276.cpp.
|
overridevirtual |
Transmit a frame with specified frequency and preamble.
| data | Pointer to payload bytes. |
| len | Payload length. |
| tx_config | Transmission config (frequency, preamble). |
Implements esphome::home_io_control::RadioDriver.
Definition at line 229 of file radio_sx1276.cpp.
|
protected |
Set the operating mode (sleep/standby/tx/rx) and wait for mode completion.
| mode | One of MODE_SLEEP, MODE_STDBY, MODE_TX, or MODE_RX. |
Definition at line 41 of file radio_sx1276.cpp.
|
overridevirtual |
Switch radio into continuous receive mode.
Implements esphome::home_io_control::RadioDriver.
Definition at line 58 of file radio_sx1276.cpp.
|
overridevirtual |
Switch radio into standby mode.
Implements esphome::home_io_control::RadioDriver.
Definition at line 59 of file radio_sx1276.cpp.
|
inlineprotected |
Set the preamble length used for response/continuation frames within an exchange.
| preamble | Preamble length in bytes. |
Definition at line 159 of file radio_sx1276.h.
|
protected |
Apply the RX bandwidth selector to REG_RX_BW and REG_AFC_BW.
| bandwidth | Bandwidth selector enum (register byte written verbatim). |
Definition at line 220 of file radio_sx1276.cpp.
|
overridevirtual |
Blocking wait for a packet with timeout.
| packet | Output: received packet (freq, len, data). |
| timeout_ms | Maximum time to wait. |
Implements esphome::home_io_control::RadioDriver.
Definition at line 300 of file radio_sx1276.cpp.
|
protected |
Write an SX1276 register over SPI.
| reg | Register address (7 bits, MSB set for write). |
| value | Byte to write. |
Definition at line 32 of file radio_sx1276.cpp.
|
protected |
Definition at line 209 of file radio_sx1276.h.
|
protected |
Definition at line 210 of file radio_sx1276.h.
|
protected |
Definition at line 213 of file radio_sx1276.h.
|
protected |
Definition at line 212 of file radio_sx1276.h.
|
protected |
Runtime-tunable response preamble.
Definition at line 215 of file radio_sx1276.h.
|
protected |
Runtime-tunable RX bandwidth.
Definition at line 214 of file radio_sx1276.h.
|
protected |
Definition at line 208 of file radio_sx1276.h.
|
protected |
Definition at line 211 of file radio_sx1276.h.