8static const char *
const TAG =
"sx127x";
9static const uint32_t FXOSC = 32000000u;
10static const uint16_t RAMP[16] = {3400, 2000, 1000, 500, 250, 125, 100, 62, 50, 40, 31, 25, 20, 15, 12, 10};
11static const uint32_t BW_HZ[22] = {2604, 3125, 3906, 5208, 6250, 7812, 10416, 12500, 15625, 20833, 25000,
12 31250, 41666, 50000, 62500, 83333, 100000, 125000, 166666, 200000, 250000, 500000};
20static const int32_t RSSI_OFFSET_HF = 157;
21static const int32_t RSSI_OFFSET_LF = 164;
41 for (
auto &
byte : packet) {
50 for (
const auto &
byte : packet) {
92 uint64_t frf = ((uint64_t) this->
frequency_ << 19) / FXOSC;
262 ESP_LOGE(TAG,
"Packet size does not match config");
265 if (packet.empty() || packet.size() > this->get_max_packet_size()) {
266 ESP_LOGE(TAG,
"Packet size out of range");
271 ESP_LOGE(TAG,
"DIO0 pin not configured, cannot wait for transmit completion");
297 if (
millis() - start > 4000) {
298 ESP_LOGE(TAG,
"Transmit packet failure");
313 listener->on_packet(packet, rssi, snr);
343 if (payload_length == 0) {
346 this->
packet_.resize(payload_length);
364 if (
millis() - start > 20) {
365 ESP_LOGE(TAG,
"Image cal failure");
387 if (
millis() - start > 20) {
388 ESP_LOGE(TAG,
"Set mode failure");
416 ESP_LOGCONFIG(TAG,
"SX127x:");
417 LOG_PIN(
" CS Pin: ", this->
cs_);
418 LOG_PIN(
" RST Pin: ", this->
rst_pin_);
420 const char *pa_pin =
"RFO";
426 " Frequency: %" PRIu32
" Hz\n"
427 " Bandwidth: %" PRIu32
" Hz\n"
429 " PA Power: %" PRIu8
" dBm\n"
430 " PA Ramp: %" PRIu16
" us",
434 ESP_LOGCONFIG(TAG,
" Deviation: %" PRIu32
" Hz", this->
deviation_);
437 const char *cr =
"4/8";
446 " Modulation: LORA\n"
447 " Preamble Size: %" PRIu16
"\n"
448 " Spreading Factor: %" PRIu8
"\n"
453 ESP_LOGCONFIG(TAG,
" Payload Length: %" PRIu32, this->
payload_length_);
456 ESP_LOGCONFIG(TAG,
" Sync Value: 0x%02x", this->
sync_value_[0]);
459 const char *shaping =
"NONE";
462 shaping =
"GAUSSIAN_BT_0_3";
464 shaping =
"GAUSSIAN_BT_0_5";
466 shaping =
"GAUSSIAN_BT_1_0";
470 shaping =
"CUTOFF_BR_X_2";
472 shaping =
"CUTOFF_BR_X_1";
478 " Bitrate: %" PRIu32
"b/s\n"
481 " Rx Floor: %.1f dBm\n"
486 ESP_LOGCONFIG(TAG,
" CRC Enable: %s", TRUEFALSE(this->
crc_enable_));
489 ESP_LOGCONFIG(TAG,
" Payload Length: %" PRIu32, this->
payload_length_);
493 ESP_LOGCONFIG(TAG,
" Sync Value: 0x%s",
498 " Preamble Polarity: 0x%X\n"
499 " Preamble Size: %" PRIu16
"\n"
500 " Preamble Detect: %" PRIu8
"\n"
501 " Preamble Errors: %" PRIu8,
506 ESP_LOGE(TAG,
"Configuring SX127x failed");
BedjetMode mode
BedJet operating mode.
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 digital_read()=0
void attach_interrupt(void(*func)(T *), T *arg, gpio::InterruptType type) const
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)
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 std::vector< uint8_t > &packet)
SX127xError transmit_packet(const std::vector< uint8_t > &packet)
std::vector< uint8_t > sync_value_
void dump_config() override
uint8_t read_register_(uint8_t reg)
static void IRAM_ATTR 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_
void configure_fsk_ook_()
@ PREAMBLE_DETECTOR_TOL_SHIFT
@ PREAMBLE_DETECTOR_SIZE_SHIFT
@ LOW_DATA_RATE_OPTIMIZE_ON
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
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).