ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
sx126x_commands.h
Go to the documentation of this file.
1#pragma once
2#include "radio_profile.h"
3#include "sx126x_spi_device.h"
4#include <span>
5
6namespace esphome::sx126x {
7static constexpr size_t SX126X_MAX_PACKET_SIZE = 255;
13
14// Encodes chip commands. No ESPHome lifecycle, callbacks, or raw SPI access.
15// Commands record failure in the SPI device: callers start a sequence with begin()
16// and check ok() at its end, or before acting on a value that was read.
18 public:
19 SX126xCommands() = default;
20 SX126xCommands(const SX126xCommands &) = delete;
22 SX126xSpiDevice &bus() { return this->spi_device_; }
23 // Fills applied as it goes; only use it if the result is OK.
24 [[nodiscard]] ConfigurationResult configure(const RadioProfile &profile, std::span<char, 16> version,
25 AppliedProfile &applied);
26 // Sets the payload length in the applied packet parameters and writes them.
27 void set_packet_length(AppliedProfile &applied, uint8_t length);
31 void receive();
32 void transmit(uint32_t timeout_ms = 0);
33 void sleep(bool cold = false);
34 void clear_irqs(uint16_t mask = 0xFFFF);
35 // Returns 0 if the read was skipped or failed.
36 uint16_t read_irq();
37 void write_fifo(const uint8_t *data, size_t size);
38 // Leaves the packet unchanged if a read fails.
39 void read_packet(uint8_t modulation, std::span<uint8_t, SX126X_MAX_PACKET_SIZE> packet, uint8_t &length, float &rssi,
40 float &snr);
42 static uint16_t ramp_us(uint8_t ramp);
43
44 private:
45 void read_opcode_(uint8_t opcode, uint8_t *data, uint8_t size);
46 void write_opcode_(uint8_t opcode, const uint8_t *data, uint8_t size);
47 void set_dio_irq_params_(uint16_t flags, uint16_t dio1);
48 void read_register_(uint16_t reg, uint8_t *data, uint8_t size);
49 void write_register_(uint16_t reg, const uint8_t *data, uint8_t size);
50 static void encode_packet_params(const RadioProfile &profile, AppliedProfile &applied);
51 SX126xSpiDevice spi_device_;
52};
53} // namespace esphome::sx126x
BedjetMode mode
BedJet operating mode.
uint16_le_t frequency
Definition bl0942.h:6
void transmit(uint32_t timeout_ms=0)
ConfigurationResult configure(const RadioProfile &profile, std::span< char, 16 > version, AppliedProfile &applied)
void standby(SX126xStandbyMode mode)
void set_frequency(uint32_t frequency)
void calibrate_image(uint32_t frequency)
static uint16_t ramp_us(uint8_t ramp)
SX126xCommands & operator=(const SX126xCommands &)=delete
void write_fifo(const uint8_t *data, size_t size)
SX126xCommands(const SX126xCommands &)=delete
static uint32_t bandwidth_hz(SX126xBw bw)
void set_packet_length(AppliedProfile &applied, uint8_t length)
void read_packet(uint8_t modulation, std::span< uint8_t, SX126X_MAX_PACKET_SIZE > packet, uint8_t &length, float &rssi, float &snr)
void clear_irqs(uint16_t mask=0xFFFF)
uint16_t flags
uint16_t size
Definition helpers.cpp:44
static void uint32_t
uint16_t length
Definition tt21100.cpp:0