9static const uint16_t RAMP[8] = {10, 20, 40, 80, 200, 800, 1700, 3400};
10static const uint32_t BW_HZ[31] = {4800, 5800, 7300, 9700, 11700, 14600, 19500, 23400, 29300, 39000, 46900,
11 58600, 78200, 93800, 117300, 156200, 187200, 234300, 312000, 373600, 467000, 7810,
12 10420, 15630, 20830, 31250, 41670, 62500, 125000, 250000, 500000};
15static const uint8_t BW_FSK[21] = {
20static constexpr uint32_t RESET_DELAY_HIGH_US = 5000;
21static constexpr uint32_t RESET_DELAY_LOW_US = 2000;
22static constexpr uint32_t SWITCHING_DELAY_US = 1;
23static constexpr uint32_t TRANSMIT_TIMEOUT_MS = 4000;
24static constexpr uint32_t BUSY_TIMEOUT_MS = 20;
27static constexpr uint8_t OCP_80MA = 0x18;
28static constexpr uint8_t OCP_140MA = 0x38;
31static constexpr float LOW_DATA_RATE_OPTIMIZE_THRESHOLD = 16.38f;
39 for (uint8_t &
byte : packet) {
51 for (
size_t i = 0; i <
len; i++) {
63 for (int32_t i = 0; i <
size; i++) {
74 for (int32_t i = 0; i <
size; i++) {
88 for (int32_t i = 0; i <
size; i++) {
100 for (int32_t i = 0; i <
size; i++) {
144 buf[1] = (
delay >> 16) & 0xFF;
145 buf[2] = (
delay >> 8) & 0xFF;
146 buf[3] = (
delay >> 0) & 0xFF;
165 this->version_[
sizeof(this->
version_) - 1] =
'\0';
166 if (strncmp(this->version_,
"SX126", 5) != 0 && strncmp(this->version_,
"LLCC68", 6) != 0) {
167 this->
mark_failed(LOG_STR(
"Unsupported chip version"));
179 uint64_t freq = ((uint64_t) this->
frequency_ << 25) / XTAL_FREQ;
180 buf[0] = (uint8_t) ((freq >> 24) & 0xFF);
181 buf[1] = (uint8_t) ((freq >> 16) & 0xFF);
182 buf[2] = (uint8_t) ((freq >> 8) & 0xFF);
183 buf[3] = (uint8_t) (freq & 0xFF);
191 if (pa_power == 15) {
192 uint8_t cfg[4] = {0x06, 0x00, 0x01, 0x01};
195 uint8_t cfg[4] = {0x04, 0x00, 0x01, 0x01};
198 pa_power = std::max(pa_power, (int8_t) -3);
199 pa_power = std::min(pa_power, (int8_t) 14);
205 uint8_t cfg[4] = {0x04, 0x07, 0x00, 0x01};
207 pa_power = std::max(pa_power, (int8_t) -3);
208 pa_power = std::min(pa_power, (int8_t) 22);
223 buf[3] = (
duration > LOW_DATA_RATE_OPTIMIZE_THRESHOLD) ? 0x01 : 0x00;
235 buf[0] = (bitrate >> 16) & 0xFF;
236 buf[1] = (bitrate >> 8) & 0xFF;
237 buf[2] = (bitrate >> 0) & 0xFF;
240 buf[5] = (fdev >> 16) & 0xFF;
241 buf[6] = (fdev >> 8) & 0xFF;
242 buf[7] = (fdev >> 0) & 0xFF;
284 return SX126X_MAX_PACKET_SIZE;
293 buf[3] = payload_length;
305 buf[6] = payload_length;
319 ESP_LOGW(TAG,
"Radio not ready, packet dropped");
323 ESP_LOGE(TAG,
"Packet size does not match config");
327 ESP_LOGE(TAG,
"Packet size out of range");
343 if (
millis() - start > TRANSMIT_TIMEOUT_MS) {
344 ESP_LOGE(TAG,
"Transmit packet failure");
367 listener->on_packet(packet, rssi, snr);
386 status = (buf[0] << 8) | buf[1];
408 uint8_t buf[2] = {0, 0};
425 if (buf[0] > 0 && buf[1] > 0) {
435 buf[0] = (irq >> 8) & 0xFF;
436 buf[1] = (irq >> 0) & 0xFF;
437 buf[2] = (irq >> 8) & 0xFF;
438 buf[3] = (irq >> 0) & 0xFF;
461 buf[0] = (irq >> 8) & 0xFF;
462 buf[1] = (irq >> 0) & 0xFF;
463 buf[2] = (irq >> 8) & 0xFF;
464 buf[3] = (irq >> 0) & 0xFF;
481 buf[0] = cold ? 0x00 : 0x04;
496 if (
millis() - start > BUSY_TIMEOUT_MS) {
504 ESP_LOGCONFIG(TAG,
"SX126x:");
505 LOG_PIN(
" CS Pin: ", this->
cs_);
507 LOG_PIN(
" RST Pin: ", this->
rst_pin_);
510 " HW Version: %15s\n"
511 " Frequency: %" PRIu32
" Hz\n"
512 " Bandwidth: %" PRIu32
" Hz\n"
513 " PA Power: %" PRId8
" dBm\n"
514 " PA Ramp: %" PRIu16
" us\n"
515 " Payload Length: %" PRIu32
"\n"
521 const char *shaping =
"NONE";
523 shaping =
"GAUSSIAN_BT_0_3";
525 shaping =
"GAUSSIAN_BT_0_5";
527 shaping =
"GAUSSIAN_BT_0_7";
529 shaping =
"GAUSSIAN_BT_1_0";
533 " Deviation: %" PRIu32
" Hz\n"
535 " Preamble Size: %" PRIu16
"\n"
536 " Preamble Detect: %" PRIu16
"\n"
537 " Bitrate: %" PRIu32
"b/s",
540 const char *cr =
"4/8";
549 " Modulation: LORA\n"
550 " Spreading Factor: %" PRIu8
"\n"
552 " Preamble Size: %" PRIu16,
557 ESP_LOGCONFIG(TAG,
" Sync Value: 0x%s",
BedjetMode mode
BedJet operating mode.
void feed_wdt()
Feed the task watchdog.
void mark_failed()
Mark this component as failed.
void enable_loop_soon_any_context()
Thread and ISR-safe version of enable_loop() that can be called from any context.
void disable_loop()
Disable this component's loop.
virtual void digital_write(bool value)=0
virtual bool is_internal()
Only the platform pin class behind the InternalGPIOPin alias may return true: callers static_cast to ...
virtual bool digital_read()=0
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Inform the parent automation that the event has triggered.
void spi_setup() override
void write_byte(uint8_t data)
uint8_t transfer_byte(uint8_t data)
uint8_t read_fifo_(uint8_t offset, std::vector< uint8_t > &packet)
void write_opcode_(uint8_t opcode, uint8_t *data, uint8_t size)
std::vector< uint8_t > sync_value_
std::vector< SX126xListener * > listeners_
size_t get_max_packet_size()
void set_mode_standby(SX126xStandbyMode mode)
SX126xError transmit_packet(const uint8_t *data, size_t len)
static void gpio_intr(SX126x *arg)
Trigger< std::vector< uint8_t >, float, float > packet_trigger_
uint8_t read_opcode_(uint8_t opcode, uint8_t *data, uint8_t size)
void dump_config() override
void write_fifo_(uint8_t offset, const uint8_t *data, size_t len)
void read_register_(uint16_t reg, uint8_t *data, uint8_t size)
void write_register_(uint16_t reg, uint8_t *data, uint8_t size)
void set_packet_params_(uint8_t payload_length)
void call_listeners_(const std::vector< uint8_t > &packet, float rssi, float snr)
std::vector< uint8_t > packet_
uint16_t preamble_detect_
uint16_t whitening_initial_
uint8_t spreading_factor_
void set_mode_sleep(bool cold=false)
ESPHOME_LOG_TAG(TAG, "sx126x_transport")
@ RADIO_SET_MODULATIONPARAMS
@ RADIO_SET_LORASYMBTIMEOUT
@ RADIO_GET_RXBUFFERSTATUS
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
void HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()
char * format_hex_to(char *buffer, size_t buffer_size, const uint8_t *data, size_t length)
Format byte array as lowercase hex to buffer (base implementation).
Application App
Global storage of Application pointer - only one Application can exist.