17#include <idfxx/future>
22#include <idfxx/spi/master>
26#include <electro/decibel>
27#include <electro/electro>
28#include <frequency/frequency>
62inline constexpr bool idfxx::enable_flags_operators<idfxx::radio::sx126x_irq_flag> =
true;
205 std::optional<tcxo_config>
tcxo = std::nullopt;
214 std::optional<flags<sx126x_irq_flag>>
dio1_mask = std::nullopt;
233#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
278 [[nodiscard]]
spi::master_device&
spi() noexcept;
288#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
295#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
341#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
346#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
466#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
540 explicit sx126x(std::unique_ptr<state> s)
noexcept;
543 [[nodiscard]]
chip_mode do_current_mode() const noexcept override;
544 [[nodiscard]]
result<
void> do_standby() override;
545 [[nodiscard]]
result<
void> do_sleep() override;
546 [[nodiscard]]
result<
void> do_start_listening() override;
547 [[nodiscard]]
result<
void>
548 do_start_listening(std::chrono::microseconds rx_period, std::chrono::microseconds sleep_period) override;
551 [[nodiscard]]
result<
void> do_set_frequency(freq::hertz hz) override;
552 [[nodiscard]]
result<
void> do_set_output_power(electro::dbm power,
ramp_time ramp) override;
556 [[nodiscard]]
result<
idfxx::
future<
void>> do_start_transmit(std::span<const uint8_t> data) override;
557 [[nodiscard]]
result<
rx_info> do_read_received(std::span<uint8_t> buffer) override;
559 [[nodiscard]]
result<electro::centi_dbm> do_current_rssi() override;
560 [[nodiscard]] std::chrono::microseconds do_rx_duty_cycle_min_sleep() const noexcept override;
562 std::unique_ptr<state> _state;
Base class for event loops.
Type-safe set of flags from a scoped enum.
static constexpr gpio nc()
Returns a GPIO representing "not connected".
Abstract base class for LoRa radio transceivers.
result< void > try_sleep()
Puts the radio in its lowest-power sleep mode.
void sleep()
Puts the radio in its lowest-power sleep mode.
void standby()
Puts the radio in standby 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.
Concrete LoRa radio driver for the Semtech SX126x family.
result< void > try_write_buffer(uint8_t offset, std::span< const uint8_t > data)
Result variant of write_buffer.
result< void > try_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.
flags< irq_flag > irq_status()
Returns the current IRQ-register status.
sx126x & operator=(const sx126x &)=delete
spi::master_device & spi() noexcept
Returns the underlying SPI device for advanced/diagnostic use.
sx126x(sx126x &&other) noexcept
result< void > try_set_sync_word(uint16_t sync_word)
Sets a raw 16-bit LoRa sync word.
result< void > try_sleep()
Puts the radio in its lowest-power sleep mode.
sx126x & operator=(sx126x &&other) noexcept
void standby(standby_clock clock)
Puts the radio in standby mode with the selected clock source.
sleep_mode
Sleep-mode configuration retention.
@ cold
Lowest-power sleep; all configuration is lost.
@ warm
Retain register configuration for fast wake-up.
void read_command(uint8_t opcode, std::span< uint8_t > response)
Sends a command opcode and reads the response bytes.
std::optional< rx_info > adopt_pending()
Drains an IRQ the chip latched while no driver was running.
result< void > try_set_cad_params(cad_params params)
Sets CAD detection parameters.
chip_variant
SX126x family chip variant.
@ sx1262
Sub-GHz, high-power PA, max +22 dBm.
@ sx1261
Sub-GHz, low-power PA, max +15 dBm.
@ sx1268
Sub-GHz, high-power PA tuned for 410–810 MHz, max +22 dBm.
void write_buffer(uint8_t offset, std::span< const uint8_t > data)
Writes the chip's data buffer at the specified offset.
void set_sync_word(uint16_t sync_word)
Sets a raw 16-bit LoRa sync word.
void sleep(sleep_mode mode)
Puts the radio in sleep mode with the selected retention.
result< void > try_standby()
Puts the radio in standby mode.
cad_symbols
Number of symbols a CAD (channel activity detection) operates on.
@ sym_1
CAD over 1 symbol (CAD_ON_1_SYMB).
@ sym_8
CAD over 8 symbols (CAD_ON_8_SYMB).
@ sym_4
CAD over 4 symbols (CAD_ON_4_SYMB).
@ sym_2
CAD over 2 symbols (CAD_ON_2_SYMB).
@ sym_16
CAD over 16 symbols (CAD_ON_16_SYMB).
sx126x(spi::master_bus &bus, config config)
Constructs a new SX126x driver on the given SPI bus.
void clear_irq_status(flags< irq_flag > mask)
Clears the specified IRQ bits.
result< void > try_write_command(uint8_t opcode, std::span< const uint8_t > params)
Result variant of write_command.
static result< sx126x > make(spi::master_bus &bus, config config)
Creates a new SX126x driver on the given SPI bus.
void set_cad_params(cad_params params)
Sets CAD detection parameters.
void read_register(uint16_t addr, std::span< uint8_t > data)
Reads one or more chip registers.
result< void > try_read_buffer(uint8_t offset, std::span< uint8_t > data)
Result variant of read_buffer.
regulator
Voltage regulator selection.
@ dc_dc
DC-DC + LDO (requires board support).
@ ldo
LDO regulator (universally safe).
sx126x(const sx126x &)=delete
result< flags< irq_flag > > try_irq_status()
Returns the current IRQ-register status.
result< void > try_standby(standby_clock clock)
Puts the radio in standby mode with the selected clock source.
void write_register(uint16_t addr, std::span< const uint8_t > data)
Writes one or more chip registers.
result< void > try_read_command(uint8_t opcode, std::span< uint8_t > response)
Result variant of read_command.
result< void > try_read_register(uint16_t addr, std::span< uint8_t > data)
Result variant of read_register.
result< void > try_sleep(sleep_mode mode)
Puts the radio in sleep mode with the selected retention.
standby_clock
Clock source kept running in standby mode.
@ xosc
Crystal oscillator (faster TX/RX transitions, higher current).
@ rc
13 MHz RC oscillator (lowest standby current).
chip_variant variant() const noexcept
Returns the configured chip variant.
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_register(uint16_t addr, std::span< const uint8_t > data)
Result variant of write_register.
void write_command(uint8_t opcode, std::span< const uint8_t > params)
Sends a command opcode with parameter bytes.
Type-safe wrapper for FreeRTOS task priority values.
Chip-agnostic radio event base and typed events.
Chip-agnostic LoRa modulation and packet types.
Abstract LoRa transceiver interface.
LoRa radio types and driver classes.
constexpr event< event_id > tx_done
Transmit-complete event.
constexpr event< event_id, cad_info > cad_done
Channel-scan-complete event, carrying cad_info.
lora_network
LoRa network selection.
constexpr event< event_id, rx_info > rx_done
Receive-complete event, carrying the packet's rx_info.
ramp_time
Power-amplifier ramp-time bucket.
sx126x_irq_flag
SX126x IRQ-register bitfield.
constexpr event< event_id > preamble_detected
Preamble-detected event.
chip_mode
Top-level radio operating mode.
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Result of a channel-activity-detection operation.
LoRa modulation parameters.
LoRa packet framing parameters.
Detailed status for the most recent packet.
Information about a received packet.
SX126x-specific channel-activity-detection parameters.
uint8_t det_peak
Detector peak threshold.
cad_symbols symbols
Number of symbols CAD listens on.
constexpr bool operator==(const cad_params &) const noexcept=default
Compares two CAD parameter sets for equality.
uint8_t det_min
Detector minimum threshold.
Configuration for an SX126x driver instance.
idfxx::gpio rxen
Optional external RF-switch RX-enable pin; nc() if unused.
freq::hertz clock_speed
SPI clock; chip max is 18 MHz.
idfxx::gpio dio1
DIO1 IRQ input from chip (required).
idfxx::gpio txen
Optional external RF-switch TX-enable pin; nc() if unused.
bool rx_boost
Use boosted-RX gain (more sensitive, higher current).
size_t worker_stack_size
Worker task stack size in bytes.
bool warm_start
Attach to an already configured chip instead of resetting and reconfiguring it.
chip_variant variant
Chip family member.
std::optional< core_id > worker_core
Worker task core affinity.
idfxx::gpio cs
SPI chip-select pin (required).
std::optional< tcxo_config > tcxo
Optional TCXO; leave unset for crystal.
event_loop * loop
Event loop to post radio events on; nullptr disables posting.
idfxx::gpio nreset
Active-low reset to chip; nc() skips the hardware reset.
task_priority worker_priority
Worker task priority.
std::optional< flags< sx126x_irq_flag > > dio1_mask
IRQ flags latched by the chip and routed to DIO1.
idfxx::gpio busy
BUSY input from chip (required).
std::chrono::milliseconds busy_timeout
Max wait for BUSY to go low.
bool dio2_as_rf_switch
Use DIO2 as the antenna T/R switch.
TCXO configuration applied through DIO3.
constexpr bool operator==(const tcxo_config &) const noexcept=default
Compares two TCXO configurations for equality.
electro::millivolts voltage
TCXO supply voltage (1600–3300 mV).
std::chrono::microseconds startup
TCXO startup time before the chip uses it.