|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
Concrete LoRa radio driver for the Semtech SX126x family. More...
Classes | |
| struct | cad_params |
| SX126x-specific channel-activity-detection parameters. More... | |
| struct | config |
| Configuration for an SX126x driver instance. More... | |
| struct | tcxo_config |
| TCXO configuration applied through DIO3. More... | |
Public Types | |
| enum class | chip_variant : uint8_t { sx1261 , sx1262 , sx1268 } |
| SX126x family chip variant. More... | |
| enum class | regulator : uint8_t { ldo = 0x00 , dc_dc = 0x01 } |
| Voltage regulator selection. More... | |
| enum class | standby_clock : uint8_t { rc , xosc } |
| Clock source kept running in standby mode. More... | |
| enum class | sleep_mode : uint8_t { warm , cold } |
| Sleep-mode configuration retention. More... | |
| enum class | cad_symbols : uint8_t { sym_1 = 0x00 , sym_2 = 0x01 , sym_4 = 0x02 , sym_8 = 0x03 , sym_16 = 0x04 } |
| Number of symbols a CAD (channel activity detection) operates on. More... | |
| using | irq_flag = sx126x_irq_flag |
| IRQ-register bitfield enumeration. See sx126x_irq_flag. | |
Public Member Functions | |
| sx126x (spi::master_bus &bus, config config) | |
| Constructs a new SX126x driver on the given SPI bus. | |
| ~sx126x () override | |
| sx126x (const sx126x &)=delete | |
| sx126x & | operator= (const sx126x &)=delete |
| sx126x (sx126x &&other) noexcept | |
| sx126x & | operator= (sx126x &&other) noexcept |
| chip_variant | variant () const noexcept |
| Returns the configured chip variant. | |
| spi::master_device & | spi () noexcept |
| Returns the underlying SPI device for advanced/diagnostic use. | |
| void | standby (standby_clock clock) |
| Puts the radio in standby mode with the selected clock source. | |
| void | sleep (sleep_mode mode) |
| Puts the radio in sleep mode with the selected retention. | |
| result< void > | try_standby (standby_clock clock) |
| Puts the radio in standby mode with the selected clock source. | |
| result< void > | try_sleep (sleep_mode mode) |
| Puts the radio in sleep mode with the selected retention. | |
| void | set_sync_word (uint16_t sync_word) |
| Sets a raw 16-bit LoRa sync word. | |
| void | set_cad_params (cad_params params) |
| Sets CAD detection parameters. | |
| std::optional< rx_info > | adopt_pending () |
| Drains an IRQ the chip latched while no driver was running. | |
| flags< irq_flag > | irq_status () |
| Returns the current IRQ-register status. | |
| void | clear_irq_status (flags< irq_flag > mask) |
| Clears the specified IRQ bits. | |
| result< std::optional< rx_info > > | try_adopt_pending () |
| Drains an IRQ the chip latched while no driver was running. | |
| result< void > | try_set_sync_word (uint16_t sync_word) |
| Sets a raw 16-bit LoRa sync word. | |
| result< void > | try_set_cad_params (cad_params params) |
| Sets CAD detection parameters. | |
| result< flags< irq_flag > > | try_irq_status () |
| Returns the current IRQ-register status. | |
| result< void > | try_clear_irq_status (flags< irq_flag > mask) |
| Clears the specified IRQ bits. | |
| void | write_command (uint8_t opcode, std::span< const uint8_t > params) |
| Sends a command opcode with parameter bytes. | |
| void | read_command (uint8_t opcode, std::span< uint8_t > response) |
| Sends a command opcode and reads the response bytes. | |
| void | write_register (uint16_t addr, std::span< const uint8_t > data) |
| Writes one or more chip registers. | |
| void | read_register (uint16_t addr, std::span< uint8_t > data) |
| Reads one or more chip registers. | |
| void | write_buffer (uint8_t offset, std::span< const uint8_t > data) |
| Writes the chip's data buffer at the specified offset. | |
| void | read_buffer (uint8_t offset, std::span< uint8_t > data) |
| Reads the chip's data buffer at the specified offset. | |
| result< void > | try_write_command (uint8_t opcode, std::span< const uint8_t > params) |
| Result variant of write_command. | |
| result< void > | try_read_command (uint8_t opcode, std::span< uint8_t > response) |
| Result variant of read_command. | |
| result< void > | try_write_register (uint16_t addr, std::span< const uint8_t > data) |
| Result variant of write_register. | |
| result< void > | try_read_register (uint16_t addr, std::span< uint8_t > data) |
| Result variant of read_register. | |
| result< void > | try_write_buffer (uint8_t offset, std::span< const uint8_t > data) |
| Result variant of write_buffer. | |
| result< void > | try_read_buffer (uint8_t offset, std::span< uint8_t > data) |
| Result variant of read_buffer. | |
| void | sleep () |
| Puts the radio in its lowest-power sleep mode. | |
| void | standby () |
| Puts the radio in standby mode. | |
| result< void > | try_sleep () |
| Puts the radio in its lowest-power sleep mode. | |
| result< void > | try_standby () |
| Puts the radio in standby mode. | |
| void | set_sync_word (lora_network network) |
| Selects the LoRa network by setting the sync word. | |
| result< void > | try_set_sync_word (lora_network network) |
| Selects the LoRa network by setting the sync word. | |
Public Member Functions inherited from idfxx::radio::lora_transceiver | |
| virtual | ~lora_transceiver ()=default |
| lora_transceiver (const lora_transceiver &)=delete | |
| lora_transceiver & | operator= (const lora_transceiver &)=delete |
| chip_mode | current_mode () const noexcept |
| Returns the radio's current high-level mode. | |
| lora_modulation | modulation () const noexcept |
| Returns the configured LoRa modulation parameters. | |
| lora_packet_params | packet_params () const noexcept |
| Returns the configured LoRa packet framing parameters. | |
| std::chrono::microseconds | time_on_air (size_t payload_length) const noexcept |
| Computes the time-on-air of a packet under the configured link parameters. | |
| std::optional< rx_duty_cycle > | rx_duty_cycle_for (uint16_t min_symbols=8) const noexcept |
| Computes duty-cycle receive windows for the configured link parameters. | |
| void | standby () |
| Puts the radio in standby mode. | |
| void | sleep () |
| Puts the radio in its lowest-power sleep mode. | |
| void | start_listening () |
| Starts continuous-receive mode. | |
| void | start_listening (std::chrono::microseconds rx_period, std::chrono::microseconds sleep_period) |
| Starts duty-cycled (periodic) receive for low-power listening. | |
| void | start_listening (rx_duty_cycle cycle) |
| Starts duty-cycled (periodic) receive from precomputed windows. | |
| void | start_listening (const std::optional< rx_duty_cycle > &cycle) |
| Starts duty-cycled receive, falling back to continuous receive. | |
| idfxx::future< cad_info > | start_channel_scan () |
| Starts a one-shot channel-activity scan and returns a future. | |
| cad_info | scan_channel () |
| Scans the channel for LoRa activity, blocking until the result is known. | |
| bool | channel_busy () |
| Returns whether LoRa activity is currently detected on the channel. | |
| result< void > | try_standby () |
| Puts the radio in standby mode. | |
| result< void > | try_sleep () |
| Puts the radio in its lowest-power sleep mode. | |
| result< void > | try_start_listening () |
| Starts continuous-receive mode. | |
| result< void > | try_start_listening (std::chrono::microseconds rx_period, std::chrono::microseconds sleep_period) |
| Starts duty-cycled (periodic) receive for low-power listening. | |
| result< void > | try_start_listening (rx_duty_cycle cycle) |
| Starts duty-cycled (periodic) receive from precomputed windows. | |
| result< void > | try_start_listening (const std::optional< rx_duty_cycle > &cycle) |
| Starts duty-cycled receive, falling back to continuous receive. | |
| result< idfxx::future< cad_info > > | try_start_channel_scan () |
| Starts a one-shot channel-activity scan and returns a future. | |
| result< cad_info > | try_scan_channel () |
| Scans the channel for LoRa activity, blocking until the result is known. | |
| result< bool > | try_channel_busy () |
| Returns whether LoRa activity is currently detected on the channel. | |
| void | configure (const lora_link &link) |
| Applies a complete link configuration. | |
| void | set_frequency (freq::hertz hz) |
| Sets the RF carrier frequency. | |
| void | set_output_power (electro::dbm power, ramp_time ramp=ramp_time::us_200) |
| Sets the transmit output power. | |
| void | set_modulation (lora_modulation mod) |
| Configures the LoRa modulation parameters. | |
| void | set_packet_params (lora_packet_params params) |
| Configures the LoRa packet framing. | |
| void | set_sync_word (lora_network network) |
| Selects the LoRa network by setting the sync word. | |
| result< void > | try_configure (const lora_link &link) |
| Applies a complete link configuration. | |
| result< void > | try_set_frequency (freq::hertz hz) |
| Sets the RF carrier frequency. | |
| result< void > | try_set_output_power (electro::dbm power, ramp_time ramp=ramp_time::us_200) |
| Sets the transmit output power. | |
| result< void > | try_set_modulation (lora_modulation mod) |
| Configures the LoRa modulation parameters. | |
| result< void > | try_set_packet_params (lora_packet_params params) |
| Configures the LoRa packet framing. | |
| result< void > | try_set_sync_word (lora_network network) |
| Selects the LoRa network by setting the sync word. | |
| void | transmit (std::span< const uint8_t > data) |
| Transmits a packet and blocks until completion, sizing the timeout automatically. | |
| template<typename Rep , typename Period > | |
| void | transmit (std::span< const uint8_t > data, const std::chrono::duration< Rep, Period > &timeout) |
| Transmits a packet and blocks until completion. | |
| template<typename Rep , typename Period > | |
| rx_info | receive (std::span< uint8_t > buffer, const std::chrono::duration< Rep, Period > &timeout) |
| Receives a single packet, blocking until one arrives or the timeout expires. | |
| result< void > | try_transmit (std::span< const uint8_t > data) |
| Transmits a packet and blocks until completion, sizing the timeout automatically. | |
| template<typename Rep , typename Period > | |
| result< void > | try_transmit (std::span< const uint8_t > data, const std::chrono::duration< Rep, Period > &timeout) |
| Transmits a packet and blocks until completion. | |
| template<typename Rep , typename Period > | |
| result< rx_info > | try_receive (std::span< uint8_t > buffer, const std::chrono::duration< Rep, Period > &timeout) |
| Receives a single packet, blocking until one arrives or the timeout expires. | |
| idfxx::future< void > | start_transmit (std::span< const uint8_t > data) |
| Starts a transmit and returns a future tracking its completion. | |
| idfxx::future< rx_info > | start_receive (std::span< uint8_t > buffer) |
| Starts a single-shot receive into the caller's buffer. | |
| rx_info | read_received (std::span< uint8_t > buffer) |
| Reads the most recently received packet into the caller's buffer. | |
| result< idfxx::future< void > > | try_start_transmit (std::span< const uint8_t > data) |
| Starts a transmit and returns a future tracking its completion. | |
| result< idfxx::future< rx_info > > | try_start_receive (std::span< uint8_t > buffer) |
| Starts a single-shot receive into the caller's buffer. | |
| result< rx_info > | try_read_received (std::span< uint8_t > buffer) |
| Reads the most recently received packet into the caller's buffer. | |
| packet_status | last_packet_status () |
| Returns detailed status for the most recent packet. | |
| electro::centi_dbm | current_rssi () |
| Returns the instantaneous RSSI on the configured channel. | |
| result< packet_status > | try_last_packet_status () |
| Returns detailed status for the most recent packet. | |
| result< electro::centi_dbm > | try_current_rssi () |
| Returns the instantaneous RSSI on the configured channel. | |
Static Public Member Functions | |
| static result< sx126x > | make (spi::master_bus &bus, config config) |
| Creates a new SX126x driver on the given SPI bus. | |
Additional Inherited Members | |
Static Public Attributes inherited from idfxx::radio::lora_transceiver | |
| static constexpr size_t | max_payload_length = 255 |
| Maximum LoRa payload length in bytes. | |
| static constexpr std::chrono::milliseconds | transmit_timeout_margin {250} |
| Margin added to the packet's time-on-air when the blocking transmit overload without a timeout sizes its own wait: covers command staging, PA ramp-up, and scheduling latency on top of the pure air-time. | |
| static constexpr std::chrono::milliseconds | scan_guard_window {1000} |
| Guard window for the blocking scan_channel. | |
Protected Member Functions inherited from idfxx::radio::lora_transceiver | |
| lora_transceiver ()=default | |
| lora_transceiver (lora_transceiver &&) noexcept=default | |
| lora_transceiver & | operator= (lora_transceiver &&) noexcept=default |
Concrete LoRa radio driver for the Semtech SX126x family.
Covers the SX1261 (sub-GHz, max +15 dBm), SX1262 (sub-GHz, max +22 dBm), and SX1268 (sub-GHz, max +22 dBm, PA tuned for 410–810 MHz). The variant is selected at construction via config::variant; the driver then picks the correct PA-config table and validates output-power range.
Move-only and non-copyable, like the rest of idfxx. The destructor tears down the worker task, removes the DIO1 ISR, and puts the chip in sleep mode.
Definition at line 79 of file sx126x.hpp.
IRQ-register bitfield enumeration. See sx126x_irq_flag.
Definition at line 82 of file sx126x.hpp.
|
strong |
Number of symbols a CAD (channel activity detection) operates on.
The chip supports only these five values (DS_SX1261-2 §13.4.7, table 13-72). The enumerator value is the cadSymbolNum register byte.
Definition at line 158 of file sx126x.hpp.
|
strong |
SX126x family chip variant.
Determines the PA configuration the driver applies and the output-power range it accepts from set_output_power.
| Enumerator | |
|---|---|
| sx1261 | Sub-GHz, low-power PA, max +15 dBm. |
| sx1262 | Sub-GHz, high-power PA, max +22 dBm. |
| sx1268 | Sub-GHz, high-power PA tuned for 410–810 MHz, max +22 dBm. |
Definition at line 91 of file sx126x.hpp.
|
strong |
Voltage regulator selection.
| Enumerator | |
|---|---|
| ldo | LDO regulator (universally safe). |
| dc_dc | DC-DC + LDO (requires board support). |
Definition at line 101 of file sx126x.hpp.
|
strong |
Sleep-mode configuration retention.
The chip-agnostic lora_transceiver::sleep performs a warm sleep; the SX126x-specific sleep(sleep_mode) overload can request a cold sleep, which loses all configuration and requires the driver's defaults and the caller's settings to be reapplied on wake.
| Enumerator | |
|---|---|
| warm | Retain register configuration for fast wake-up. |
| cold | Lowest-power sleep; all configuration is lost. |
Definition at line 128 of file sx126x.hpp.
|
strong |
Clock source kept running in standby mode.
The chip-agnostic lora_transceiver::standby uses the low-power RC oscillator; the SX126x-specific standby(standby_clock) overload selects the crystal oscillator for a faster transition into transmit or receive.
| Enumerator | |
|---|---|
| rc | 13 MHz RC oscillator (lowest standby current). |
| xosc | Crystal oscillator (faster TX/RX transitions, higher current). |
Definition at line 114 of file sx126x.hpp.
|
explicit |
Constructs a new SX126x driver on the given SPI bus.
Does not take ownership of bus. The caller must ensure the bus outlives this driver.
| bus | Parent SPI master bus. |
| config | Driver configuration. |
| std::system_error | on failure. |
|
override |
|
delete |
|
noexcept |
|
inline |
Drains an IRQ the chip latched while no driver was running.
Intended for use immediately after a warm start (see config::warm_start): a packet the chip received while the host slept leaves rx_done latched and DIO1 high, but the driver's interrupt handler never saw the edge. This reads and clears the pending IRQ status and, for a latched rx_done, reads the packet out of the chip into the receive cache, where lora_transceiver::read_received picks it up.
std::nullopt if no packet was pending. | std::system_error | on failure (including a corrupt pending packet, reported as idfxx::errc::invalid_crc). |
Definition at line 398 of file sx126x.hpp.
References try_adopt_pending(), and idfxx::unwrap().
Clears the specified IRQ bits.
| mask | Bits to clear. |
| std::system_error | on failure. |
Definition at line 414 of file sx126x.hpp.
References try_clear_irq_status(), and idfxx::unwrap().
Returns the current IRQ-register status.
| std::system_error | on failure. |
Definition at line 406 of file sx126x.hpp.
References try_irq_status(), and idfxx::unwrap().
|
static |
Creates a new SX126x driver on the given SPI bus.
Does not take ownership of bus. The caller must ensure the bus outlives this driver.
| bus | Parent SPI master bus. |
| config | Driver configuration. |
|
inline |
Reads the chip's data buffer at the specified offset.
| offset | Byte offset within the 256-byte chip buffer. |
| data | Buffer to receive into. |
| std::system_error | on failure. |
Definition at line 519 of file sx126x.hpp.
References try_read_buffer(), and idfxx::unwrap().
|
inline |
Sends a command opcode and reads the response bytes.
| opcode | Command opcode. |
| response | Buffer to receive response bytes into. |
| std::system_error | on failure. |
Definition at line 483 of file sx126x.hpp.
References try_read_command(), and idfxx::unwrap().
|
inline |
Reads one or more chip registers.
| addr | 16-bit register address. |
| data | Buffer to receive into. |
| std::system_error | on failure. |
Definition at line 501 of file sx126x.hpp.
References try_read_register(), and idfxx::unwrap().
|
inline |
Sets CAD detection parameters.
Tunes the chip's CAD detection thresholds. The chip-agnostic lora_transceiver::try_start_channel_scan uses driver defaults.
| params | CAD detection parameters. |
| std::system_error | on failure. |
Definition at line 370 of file sx126x.hpp.
References try_set_cad_params(), and idfxx::unwrap().
|
inline |
Selects the LoRa network by setting the sync word.
Senders and receivers must select the same network to hear each other. Each driver maps the selection to its chip's native sync-word encoding; chip-specific raw values remain available through driver-specific overloads (e.g. sx126x::set_sync_word(uint16_t)).
| network | Network whose sync word to use. |
| std::system_error | on failure. |
Definition at line 503 of file lora_transceiver.hpp.
|
inline |
Sets a raw 16-bit LoRa sync word.
For interoperating with networks that use a non-standard sync word. The inherited lora_transceiver::set_sync_word overload selects the standard public/private network values.
| sync_word | Raw sync-word register value (MSB first). |
| std::system_error | on failure. |
Definition at line 358 of file sx126x.hpp.
References try_set_sync_word(), and idfxx::unwrap().
|
inline |
Puts the radio in its lowest-power sleep mode.
Configuration is retained where the chip supports it, so the next operation wakes the radio without a full reconfiguration.
| std::system_error | on failure. |
Definition at line 177 of file lora_transceiver.hpp.
|
inline |
Puts the radio in sleep mode with the selected retention.
The inherited lora_transceiver::sleep performs a warm sleep (configuration retained). Select sleep_mode::cold for the lowest-power sleep, in which all configuration is lost and must be reapplied on wake.
| mode | Configuration-retention mode. |
| std::system_error | on failure. |
Definition at line 320 of file sx126x.hpp.
References try_sleep(), and idfxx::unwrap().
|
noexcept |
Returns the underlying SPI device for advanced/diagnostic use.
|
inline |
Puts the radio in standby mode.
Standby stops any in-progress receive or channel scan and parks the radio with its configuration retained, ready for the next operation.
| std::system_error | on failure. |
Definition at line 166 of file lora_transceiver.hpp.
|
inline |
Puts the radio in standby mode with the selected clock source.
The inherited lora_transceiver::standby uses the low-power RC oscillator; select standby_clock::xosc to keep the crystal oscillator running for faster transitions into transmit or receive.
| clock | Clock source to keep running in standby. |
| std::system_error | on failure. |
Definition at line 307 of file sx126x.hpp.
References try_standby(), and idfxx::unwrap().
Drains an IRQ the chip latched while no driver was running.
Result variant of adopt_pending; see there for the warm-start recovery flow this supports.
std::nullopt if no packet was pending, or an error. | idfxx::errc::invalid_crc | A packet was pending but failed the chip's CRC check; the IRQ has been cleared. |
Referenced by adopt_pending().
Clears the specified IRQ bits.
| mask | Bits to clear. |
Referenced by clear_irq_status().
Returns the current IRQ-register status.
Referenced by irq_status().
| result< void > idfxx::radio::sx126x::try_read_buffer | ( | uint8_t | offset, |
| std::span< uint8_t > | data | ||
| ) |
Result variant of read_buffer.
Referenced by read_buffer().
| result< void > idfxx::radio::sx126x::try_read_command | ( | uint8_t | opcode, |
| std::span< uint8_t > | response | ||
| ) |
Result variant of read_command.
Referenced by read_command().
| result< void > idfxx::radio::sx126x::try_read_register | ( | uint16_t | addr, |
| std::span< uint8_t > | data | ||
| ) |
Result variant of read_register.
Referenced by read_register().
| result< void > idfxx::radio::sx126x::try_set_cad_params | ( | cad_params | params | ) |
Sets CAD detection parameters.
| params | CAD detection parameters. |
Referenced by set_cad_params().
|
inline |
Selects the LoRa network by setting the sync word.
Senders and receivers must select the same network to hear each other. Each driver maps the selection to its chip's native sync-word encoding.
| network | Network whose sync word to use. |
Definition at line 591 of file lora_transceiver.hpp.
| result< void > idfxx::radio::sx126x::try_set_sync_word | ( | uint16_t | sync_word | ) |
Sets a raw 16-bit LoRa sync word.
For interoperating with networks that use a non-standard sync word. The inherited lora_transceiver::try_set_sync_word overload selects the standard public/private network values.
| sync_word | Raw sync-word register value (MSB first). |
Referenced by set_sync_word().
|
inline |
Puts the radio in its lowest-power sleep mode.
Configuration is retained where the chip supports it, so the next operation wakes the radio without a full reconfiguration.
Definition at line 315 of file lora_transceiver.hpp.
Referenced by sleep().
| result< void > idfxx::radio::sx126x::try_sleep | ( | sleep_mode | mode | ) |
Puts the radio in sleep mode with the selected retention.
| mode | Configuration-retention mode. |
|
inline |
Puts the radio in standby mode.
Standby stops any in-progress receive or channel scan and parks the radio with its configuration retained, ready for the next operation.
Definition at line 305 of file lora_transceiver.hpp.
Referenced by standby().
| result< void > idfxx::radio::sx126x::try_standby | ( | standby_clock | clock | ) |
Puts the radio in standby mode with the selected clock source.
| clock | Clock source to keep running in standby. |
| result< void > idfxx::radio::sx126x::try_write_buffer | ( | uint8_t | offset, |
| std::span< const uint8_t > | data | ||
| ) |
Result variant of write_buffer.
Referenced by write_buffer().
| result< void > idfxx::radio::sx126x::try_write_command | ( | uint8_t | opcode, |
| std::span< const uint8_t > | params | ||
| ) |
Result variant of write_command.
Referenced by write_command().
| result< void > idfxx::radio::sx126x::try_write_register | ( | uint16_t | addr, |
| std::span< const uint8_t > | data | ||
| ) |
Result variant of write_register.
Referenced by write_register().
|
noexcept |
Returns the configured chip variant.
|
inline |
Writes the chip's data buffer at the specified offset.
| offset | Byte offset within the 256-byte chip buffer. |
| data | Bytes to write. |
| std::system_error | on failure. |
Definition at line 510 of file sx126x.hpp.
References try_write_buffer(), and idfxx::unwrap().
|
inline |
Sends a command opcode with parameter bytes.
| opcode | Command opcode. |
| params | Parameter bytes to send after the opcode. |
| std::system_error | on failure. |
Definition at line 474 of file sx126x.hpp.
References try_write_command(), and idfxx::unwrap().
|
inline |
Writes one or more chip registers.
| addr | 16-bit register address. |
| data | Bytes to write. |
| std::system_error | on failure. |
Definition at line 492 of file sx126x.hpp.
References try_write_register(), and idfxx::unwrap().