9static const uint32_t FXOSC = 32000000u;
10static constexpr uint16_t RAMP[16] PROGMEM = {3400, 2000, 1000, 500, 250, 125, 100, 62, 50, 40, 31, 25, 20, 15, 12, 10};
12static constexpr uint32_t BW_HZ[22] PROGMEM = {2604, 3125, 3906, 5208, 6250, 7812, 10416, 12500,
13 15625, 20833, 25000, 31250, 41666, 50000, 62500, 83333,
14 100000, 125000, 166666, 200000, 250000, 500000};
15static constexpr uint8_t BW_LORA[22] PROGMEM = {
16 BW_7_8,
BW_7_8,
BW_7_8,
BW_7_8,
BW_7_8,
BW_7_8,
BW_10_4,
BW_15_6,
BW_15_6,
BW_20_8,
BW_31_3,
17 BW_31_3,
BW_41_7,
BW_62_5,
BW_62_5,
BW_125_0,
BW_125_0,
BW_125_0,
BW_250_0,
BW_250_0,
BW_250_0,
BW_500_0};
18static constexpr uint8_t BW_FSK_OOK[22]
PROGMEM = {
23static const int32_t RSSI_OFFSET_HF = 157;
24static const int32_t RSSI_OFFSET_LF = 164;
44 for (
auto &
byte : packet) {
53 for (
size_t i = 0; i <
len; i++) {
87 this->
mark_failed(LOG_STR(
"Unsupported chip version"));
95 uint64_t frf = ((uint64_t) this->
frequency_ << 19) / FXOSC;
258 return SX127X_MAX_PACKET_SIZE;
266 ESP_LOGW(TAG,
"Radio not ready, packet dropped");
270 ESP_LOGE(TAG,
"Packet size does not match config");
274 ESP_LOGE(TAG,
"Packet size out of range");
279 ESP_LOGE(TAG,
"DIO0 pin not configured, cannot wait for transmit completion");
306 if (
millis() - start > 4000) {
307 ESP_LOGE(TAG,
"Transmit packet failure");
322 listener->on_packet(packet, rssi, snr);
352 if (payload_length == 0) {
355 this->
packet_.resize(payload_length);
373 if (
millis() - start > 20) {
395 if (
millis() - start > 20) {
423 ESP_LOGCONFIG(TAG,
"SX127x:");
424 LOG_PIN(
" CS Pin: ", this->
cs_);
425 LOG_PIN(
" RST Pin: ", this->
rst_pin_);
427 const char *pa_pin =
"RFO";
433 " Frequency: %" PRIu32
" Hz\n"
434 " Bandwidth: %" PRIu32
" Hz\n"
436 " PA Power: %" PRIu8
" dBm\n"
437 " PA Ramp: %" PRIu16
" us",
441 ESP_LOGCONFIG(TAG,
" Deviation: %" PRIu32
" Hz", this->
deviation_);
444 const char *cr =
"4/8";
453 " Modulation: LORA\n"
454 " Preamble Size: %" PRIu16
"\n"
455 " Spreading Factor: %" PRIu8
"\n"
460 ESP_LOGCONFIG(TAG,
" Payload Length: %" PRIu32, this->
payload_length_);
463 ESP_LOGCONFIG(TAG,
" Sync Value: 0x%02x", this->
sync_value_[0]);
466 const char *shaping =
"NONE";
469 shaping =
"GAUSSIAN_BT_0_3";
471 shaping =
"GAUSSIAN_BT_0_5";
473 shaping =
"GAUSSIAN_BT_1_0";
477 shaping =
"CUTOFF_BR_X_2";
479 shaping =
"CUTOFF_BR_X_1";
485 " Bitrate: %" PRIu32
"b/s\n"
488 " Rx Floor: %.1f dBm\n"
490 shaping, this->
modulation_ ==
MOD_FSK ? LOG_STR_LITERAL(
"FSK") : LOG_STR_LITERAL(
"OOK"),
494 ESP_LOGCONFIG(TAG,
" CRC Enable: %s", TRUEFALSE(this->
crc_enable_));
497 ESP_LOGCONFIG(TAG,
" Payload Length: %" PRIu32, this->
payload_length_);
501 ESP_LOGCONFIG(TAG,
" Sync Value: 0x%s",
506 " Preamble Polarity: 0x%X\n"
507 " Preamble Size: %" PRIu16
"\n"
508 " Preamble Detect: %" PRIu8
"\n"
509 " Preamble Errors: %" PRIu8,
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.
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Inform the parent automation that the event has triggered.
void attach_interrupt(void(*func)(T *), T *arg, gpio::InterruptType type) const
bool digital_read() override
void digital_write(bool value) override
void spi_setup() override
void write_byte(uint8_t data)
uint8_t transfer_byte(uint8_t data)
InternalGPIOPin * rst_pin_
uint8_t preamble_polarity_
InternalGPIOPin * dio0_pin_
Trigger< std::vector< uint8_t >, float, float > packet_trigger_
std::vector< SX127xListener * > listeners_
void write_fifo_(const uint8_t *data, size_t len)
std::vector< uint8_t > sync_value_
void dump_config() override
uint8_t read_register_(uint8_t reg)
static void gpio_intr(SX127x *arg)
void set_mode_(uint8_t modulation, uint8_t mode)
void read_fifo_(std::vector< uint8_t > &packet)
std::vector< uint8_t > packet_
size_t get_max_packet_size()
void write_register_(uint8_t reg, uint8_t value)
void call_listeners_(const std::vector< uint8_t > &packet, float rssi, float snr)
uint8_t spreading_factor_
SX127xError transmit_packet(const uint8_t *data, size_t len)
void configure_fsk_ook_()
constexpr float BME680_GAS_LOOKUP_TABLE_1[16] PROGMEM
@ PREAMBLE_DETECTOR_TOL_SHIFT
@ PREAMBLE_DETECTOR_SIZE_SHIFT
ESPHOME_LOG_TAG(TAG, "sx127x_transport")
@ LOW_DATA_RATE_OPTIMIZE_ON
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
uint16_t progmem_read_uint16(const uint16_t *addr)
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.
uint8_t progmem_read_byte(const uint8_t *addr)