ESPHome 2025.7.1
Loading...
Searching...
No Matches
sx126x.h
Go to the documentation of this file.
1#pragma once
2
6#include "sx126x_reg.h"
7#include <utility>
8#include <vector>
9
10namespace esphome {
11namespace sx126x {
12
48
50
52 public:
53 virtual void on_packet(const std::vector<uint8_t> &packet, float rssi, float snr) = 0;
54};
55
56class SX126x : public Component,
57 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
58 spi::DATA_RATE_8MHZ> {
59 public:
60 size_t get_max_packet_size();
61 float get_setup_priority() const override { return setup_priority::PROCESSOR; }
62 void setup() override;
63 void loop() override;
64 void dump_config() override;
65 void set_bandwidth(SX126xBw bandwidth) { this->bandwidth_ = bandwidth; }
66 void set_bitrate(uint32_t bitrate) { this->bitrate_ = bitrate; }
67 void set_busy_pin(InternalGPIOPin *busy_pin) { this->busy_pin_ = busy_pin; }
68 void set_coding_rate(uint8_t coding_rate) { this->coding_rate_ = coding_rate; }
69 void set_crc_enable(bool crc_enable) { this->crc_enable_ = crc_enable; }
70 void set_deviation(uint32_t deviation) { this->deviation_ = deviation; }
71 void set_dio1_pin(InternalGPIOPin *dio1_pin) { this->dio1_pin_ = dio1_pin; }
72 void set_frequency(uint32_t frequency) { this->frequency_ = frequency; }
73 void set_hw_version(const std::string &hw_version) { this->hw_version_ = hw_version; }
74 void set_mode_rx();
75 void set_mode_tx();
77 void set_mode_sleep();
78 void set_modulation(uint8_t modulation) { this->modulation_ = modulation; }
79 void set_pa_power(int8_t power) { this->pa_power_ = power; }
80 void set_pa_ramp(uint8_t ramp) { this->pa_ramp_ = ramp; }
81 void set_payload_length(uint8_t payload_length) { this->payload_length_ = payload_length; }
82 void set_preamble_detect(uint16_t preamble_detect) { this->preamble_detect_ = preamble_detect; }
84 void set_rst_pin(InternalGPIOPin *rst_pin) { this->rst_pin_ = rst_pin; }
85 void set_rx_start(bool rx_start) { this->rx_start_ = rx_start; }
86 void set_rf_switch(bool rf_switch) { this->rf_switch_ = rf_switch; }
87 void set_shaping(uint8_t shaping) { this->shaping_ = shaping; }
88 void set_spreading_factor(uint8_t spreading_factor) { this->spreading_factor_ = spreading_factor; }
89 void set_sync_value(const std::vector<uint8_t> &sync_value) { this->sync_value_ = sync_value; }
90 void set_tcxo_voltage(uint8_t tcxo_voltage) { this->tcxo_voltage_ = tcxo_voltage; }
91 void set_tcxo_delay(uint32_t tcxo_delay) { this->tcxo_delay_ = tcxo_delay; }
92 void run_image_cal();
93 void configure();
94 SX126xError transmit_packet(const std::vector<uint8_t> &packet);
95 void register_listener(SX126xListener *listener) { this->listeners_.push_back(listener); }
96 Trigger<std::vector<uint8_t>, float, float> *get_packet_trigger() const { return this->packet_trigger_; };
97
98 protected:
101 void set_packet_params_(uint8_t payload_length);
102 uint8_t read_fifo_(uint8_t offset, std::vector<uint8_t> &packet);
103 void write_fifo_(uint8_t offset, const std::vector<uint8_t> &packet);
104 void write_opcode_(uint8_t opcode, uint8_t *data, uint8_t size);
105 uint8_t read_opcode_(uint8_t opcode, uint8_t *data, uint8_t size);
106 void write_register_(uint16_t reg, uint8_t *data, uint8_t size);
107 void read_register_(uint16_t reg, uint8_t *data, uint8_t size);
108 void call_listeners_(const std::vector<uint8_t> &packet, float rssi, float snr);
109 void wait_busy_();
111 std::vector<SX126xListener *> listeners_;
112 std::vector<uint8_t> packet_;
113 std::vector<uint8_t> sync_value_;
117 std::string hw_version_;
118 char version_[16];
120 uint32_t bitrate_{0};
121 uint32_t deviation_{0};
122 uint32_t frequency_{0};
123 uint32_t payload_length_{0};
124 uint32_t tcxo_delay_{0};
125 uint16_t preamble_detect_{0};
126 uint16_t preamble_size_{0};
127 uint8_t tcxo_voltage_{0};
128 uint8_t coding_rate_{0};
130 uint8_t pa_ramp_{0};
131 uint8_t shaping_{0};
133 int8_t pa_power_{0};
134 bool crc_enable_{false};
135 bool rx_start_{false};
136 bool rf_switch_{false};
137};
138
139} // namespace sx126x
140} // namespace esphome
BedjetMode mode
BedJet operating mode.
uint16_le_t frequency
Definition bl0942.h:6
The SPIDevice is what components using the SPI will create.
Definition spi.h:427
void set_rx_start(bool rx_start)
Definition sx126x.h:85
void set_deviation(uint32_t deviation)
Definition sx126x.h:70
float get_setup_priority() const override
Definition sx126x.h:61
void set_spreading_factor(uint8_t spreading_factor)
Definition sx126x.h:88
void set_pa_ramp(uint8_t ramp)
Definition sx126x.h:80
void set_rf_switch(bool rf_switch)
Definition sx126x.h:86
uint8_t read_fifo_(uint8_t offset, std::vector< uint8_t > &packet)
Definition sx126x.cpp:33
void write_opcode_(uint8_t opcode, uint8_t *data, uint8_t size)
Definition sx126x.cpp:70
void set_sync_value(const std::vector< uint8_t > &sync_value)
Definition sx126x.h:89
std::vector< uint8_t > sync_value_
Definition sx126x.h:113
InternalGPIOPin * busy_pin_
Definition sx126x.h:114
std::vector< SX126xListener * > listeners_
Definition sx126x.h:111
size_t get_max_packet_size()
Definition sx126x.cpp:255
Trigger< std::vector< uint8_t >, float, float > * get_packet_trigger() const
Definition sx126x.h:96
InternalGPIOPin * rst_pin_
Definition sx126x.h:116
void set_mode_standby(SX126xStandbyMode mode)
Definition sx126x.cpp:443
void set_payload_length(uint8_t payload_length)
Definition sx126x.h:81
uint8_t read_opcode_(uint8_t opcode, uint8_t *data, uint8_t size)
Definition sx126x.cpp:58
void dump_config() override
Definition sx126x.cpp:462
void set_modulation(uint8_t modulation)
Definition sx126x.h:78
void set_frequency(uint32_t frequency)
Definition sx126x.h:72
void set_tcxo_delay(uint32_t tcxo_delay)
Definition sx126x.h:91
void read_register_(uint16_t reg, uint8_t *data, uint8_t size)
Definition sx126x.cpp:81
void set_bandwidth(SX126xBw bandwidth)
Definition sx126x.h:65
void write_register_(uint16_t reg, uint8_t *data, uint8_t size)
Definition sx126x.cpp:94
uint16_t preamble_size_
Definition sx126x.h:126
void set_preamble_detect(uint16_t preamble_detect)
Definition sx126x.h:82
void set_shaping(uint8_t shaping)
Definition sx126x.h:87
void set_dio1_pin(InternalGPIOPin *dio1_pin)
Definition sx126x.h:71
void loop() override
Definition sx126x.cpp:334
void set_hw_version(const std::string &hw_version)
Definition sx126x.h:73
void set_crc_enable(bool crc_enable)
Definition sx126x.h:69
void set_packet_params_(uint8_t payload_length)
Definition sx126x.cpp:262
void call_listeners_(const std::vector< uint8_t > &packet, float rssi, float snr)
Definition sx126x.cpp:327
std::vector< uint8_t > packet_
Definition sx126x.h:112
void set_coding_rate(uint8_t coding_rate)
Definition sx126x.h:68
uint16_t preamble_detect_
Definition sx126x.h:125
void set_pa_power(int8_t power)
Definition sx126x.h:79
void set_preamble_size(uint16_t preamble_size)
Definition sx126x.h:83
void setup() override
Definition sx126x.cpp:107
void register_listener(SX126xListener *listener)
Definition sx126x.h:95
void set_rst_pin(InternalGPIOPin *rst_pin)
Definition sx126x.h:84
std::string hw_version_
Definition sx126x.h:117
uint32_t payload_length_
Definition sx126x.h:123
Trigger< std::vector< uint8_t >, float, float > * packet_trigger_
Definition sx126x.h:110
void set_bitrate(uint32_t bitrate)
Definition sx126x.h:66
SX126xError transmit_packet(const std::vector< uint8_t > &packet)
Definition sx126x.cpp:287
void set_busy_pin(InternalGPIOPin *busy_pin)
Definition sx126x.h:67
InternalGPIOPin * dio1_pin_
Definition sx126x.h:115
uint8_t spreading_factor_
Definition sx126x.h:132
void set_tcxo_voltage(uint8_t tcxo_voltage)
Definition sx126x.h:90
void write_fifo_(uint8_t offset, const std::vector< uint8_t > &packet)
Definition sx126x.cpp:46
virtual void on_packet(const std::vector< uint8_t > &packet, float rssi, float snr)=0
uint16_t preamble_size
const float PROCESSOR
For components that use data from sensors like displays.
Definition component.cpp:47
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7