ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
cc1101.cpp
Go to the documentation of this file.
1#include "cc1101.h"
2#include "cc1101pa.h"
4#include "esphome/core/log.h"
6#include <cmath>
7#include <cstring>
8
9#ifdef USE_ESP32
10#include <esp_memory_utils.h>
11#endif
12
13namespace esphome::cc1101 {
14
15ESPHOME_LOG_TAG(TAG, "cc1101");
16static constexpr size_t TX_FIFO_SIZE = 64;
17
18// MDMCFG2 MOD_FORMAT values
19PROGMEM_STRING_TABLE(ModulationStrings, "2-FSK", "GFSK", "UNUSED", "ASK/OOK", "4-FSK", "UNUSED", "UNUSED", "MSK");
20
21static void split_float(float value, int mbits, uint8_t &e, uint32_t &m) {
22 int e_tmp;
23 float m_tmp = std::frexp(value, &e_tmp);
24 if (e_tmp <= mbits) {
25 e = 0;
26 m = 0;
27 return;
28 }
29 e = static_cast<uint8_t>(e_tmp - mbits - 1);
30 m = static_cast<uint32_t>(((m_tmp * 2 - 1) * (1 << (mbits + 1))) + 1) >> 1;
31 if (m == (1UL << mbits)) {
32 e = e + 1;
33 m = 0;
34 }
35}
36
38 // Datasheet defaults
39 memset(&this->state_, 0, sizeof(this->state_));
40 this->state_.GDO2_CFG = 0x0D; // Serial Data (for RX on GDO2)
41 this->state_.GDO1_CFG = 0x2E;
42 this->state_.GDO0_CFG = 0x0D; // Serial Data (for RX on GDO0 / TX Input)
43 this->state_.FIFO_THR = 7;
44 this->state_.SYNC1 = 0xD3;
45 this->state_.SYNC0 = 0x91;
46 this->state_.PKTLEN = 0xFF;
47 this->state_.APPEND_STATUS = 1;
48 this->state_.LENGTH_CONFIG = 1;
49 this->state_.CRC_EN = 1;
50 this->state_.WHITE_DATA = 1;
51 this->state_.FREQ_IF = 0x0F;
52 this->state_.FREQ2 = 0x1E;
53 this->state_.FREQ1 = 0xC4;
54 this->state_.FREQ0 = 0xEC;
55 this->state_.DRATE_E = 0x0C;
56 this->state_.CHANBW_E = 0x02;
57 this->state_.DRATE_M = 0x22;
58 this->state_.SYNC_MODE = 2;
59 this->state_.CHANSPC_E = 2;
60 this->state_.NUM_PREAMBLE = 2;
61 this->state_.CHANSPC_M = 0xF8;
62 this->state_.DEVIATION_M = 7;
63 this->state_.DEVIATION_E = 4;
64 this->state_.RX_TIME = 7;
65 this->state_.CCA_MODE = 3;
66 this->state_.PO_TIMEOUT = 1;
67 this->state_.FOC_LIMIT = 2;
68 this->state_.FOC_POST_K = 1;
69 this->state_.FOC_PRE_K = 2;
70 this->state_.FOC_BS_CS_GATE = 1;
71 this->state_.BS_POST_KP = 1;
72 this->state_.BS_POST_KI = 1;
73 this->state_.BS_PRE_KP = 2;
74 this->state_.BS_PRE_KI = 1;
75 this->state_.MAGN_TARGET = 3;
76 this->state_.AGC_LNA_PRIORITY = 1;
77 this->state_.FILTER_LENGTH = 1;
78 this->state_.WAIT_TIME = 1;
79 this->state_.HYST_LEVEL = 2;
80 this->state_.WOREVT1 = 0x87;
81 this->state_.WOREVT0 = 0x6B;
82 this->state_.RC_CAL = 1;
83 this->state_.EVENT1 = 7;
84 this->state_.RC_PD = 1;
85 this->state_.MIX_CURRENT = 2;
86 this->state_.LODIV_BUF_CURRENT_RX = 1;
87 this->state_.LNA2MIX_CURRENT = 1;
88 this->state_.LNA_CURRENT = 1;
89 this->state_.LODIV_BUF_CURRENT_TX = 1;
90 this->state_.FSCAL3_LO = 9;
91 this->state_.CHP_CURR_CAL_EN = 2;
92 this->state_.FSCAL3_HI = 2;
93 this->state_.FSCAL2 = 0x0A;
94 this->state_.FSCAL1 = 0x20;
95 this->state_.FSCAL0 = 0x0D;
96 this->state_.RCCTRL1 = 0x41;
97 this->state_.FSTEST = 0x59;
98 this->state_.PTEST = 0x7F;
99 this->state_.AGCTEST = 0x3F;
100 this->state_.TEST2 = 0x88;
101 this->state_.TEST1 = 0x31;
102 this->state_.TEST0_LO = 1;
103 this->state_.VCO_SEL_CAL_EN = 1;
104 this->state_.TEST0_HI = 2;
105
106 // PKTCTRL0
107 this->state_.PKT_FORMAT = 3;
108 this->state_.LENGTH_CONFIG = 2;
109 this->state_.FS_AUTOCAL = 1;
110
111 // CRITICAL: Initialize PA Table to avoid transmitting 0 power (Silence)
112 memset(this->pa_table_, 0, sizeof(this->pa_table_));
113}
114
116
118 this->spi_setup();
119
120 if (this->gdo0_pin_ != nullptr) {
121 this->gdo0_pin_->setup();
122 }
123
124 this->configure();
125 if (this->is_failed()) {
126 return;
127 }
128
129 // Defer pin mode setup until after all components have completed setup()
130 // This handles the case where remote_transmitter runs after CC1101 and changes pin mode
131 if (this->gdo0_pin_ != nullptr) {
132 this->defer([this]() {
134 if (this->state_.PKT_FORMAT == static_cast<uint8_t>(PacketFormat::PACKET_FORMAT_FIFO)) {
136 }
137 });
138 }
139}
140
142 // Manual reset sequence per CC1101 datasheet section 19.1.2
143 this->cs_->digital_write(true);
145 this->cs_->digital_write(false);
147 this->cs_->digital_write(true);
149 this->cs_->digital_write(false);
150 delay(5);
151
152 this->strobe_(Command::RES);
153 delay(5);
154
157 this->chip_id_ = encode_uint16(this->state_.PARTNUM, this->state_.VERSION);
158 ESP_LOGD(TAG, "CC1101 found! Chip ID: 0x%04X", this->chip_id_);
159 if (this->state_.VERSION == 0 || this->state_.PARTNUM == 0xFF) {
160 ESP_LOGE(TAG, "Failed to verify CC1101.");
161 this->mark_failed();
162 return;
163 }
164
165 this->initialized_ = true;
166
167 for (uint8_t i = 0; i <= static_cast<uint8_t>(Register::TEST0); i++) {
168 if (i == static_cast<uint8_t>(Register::FSTEST) || i == static_cast<uint8_t>(Register::AGCTEST)) {
169 continue;
170 }
171 this->write_(static_cast<Register>(i));
172 }
174
175 if (!this->enter_rx_()) {
176 this->mark_failed();
177 return;
178 }
179}
180
181void CC1101Component::call_listeners_(const std::vector<uint8_t> &packet, float freq_offset, float rssi, uint8_t lqi) {
182 for (auto &listener : this->listeners_) {
183 listener->on_packet(packet, freq_offset, rssi, lqi);
184 }
185 this->packet_trigger_.trigger(packet, freq_offset, rssi, lqi);
186}
187
189 this->disable_loop();
190 if (this->state_.PKT_FORMAT != static_cast<uint8_t>(PacketFormat::PACKET_FORMAT_FIFO) || this->gdo0_pin_ == nullptr ||
191 !this->gdo0_pin_->digital_read()) {
192 return;
193 }
194
195 // Read state
197 uint8_t rx_bytes = this->state_.NUM_RXBYTES;
198 bool overflow = this->state_.RXFIFO_OVERFLOW;
199 if (overflow || rx_bytes == 0) {
200 ESP_LOGW(TAG, "RX FIFO overflow, flushing");
201 this->enter_idle_();
202 this->strobe_(Command::FRX);
203 this->enter_rx_();
204 return;
205 }
206
207 // Read packet
208 uint8_t payload_length, expected_rx;
209 if (this->state_.LENGTH_CONFIG == static_cast<uint8_t>(LengthConfig::LENGTH_CONFIG_VARIABLE)) {
210 this->read_(Register::FIFO, &payload_length, 1);
211 expected_rx = payload_length + 1;
212 } else {
213 payload_length = this->state_.PKTLEN;
214 expected_rx = payload_length;
215 }
216 if (payload_length == 0 || payload_length > 64 || rx_bytes != expected_rx) {
217 ESP_LOGW(TAG, "Invalid packet: rx_bytes %u, payload_length %u", rx_bytes, payload_length);
218 this->enter_idle_();
219 this->strobe_(Command::FRX);
220 this->enter_rx_();
221 return;
222 }
223 this->packet_.resize(payload_length);
224 this->read_(Register::FIFO, this->packet_.data(), payload_length);
225
226 // Read status from registers (more reliable than FIFO status bytes due to timing issues)
228 this->read_(Register::RSSI);
229 this->read_(Register::LQI);
230 float freq_offset = static_cast<int8_t>(this->state_.FREQEST) * (XTAL_FREQUENCY / (1 << 14));
231 float rssi = (this->state_.RSSI * RSSI_STEP) - RSSI_OFFSET;
232 bool crc_ok = (this->state_.LQI & STATUS_CRC_OK_MASK) != 0;
233 uint8_t lqi = this->state_.LQI & STATUS_LQI_MASK;
234 if (this->state_.CRC_EN == 0 || crc_ok) {
235 this->call_listeners_(this->packet_, freq_offset, rssi, lqi);
236 }
237
238 // Return to rx
239 this->enter_idle_();
240 this->strobe_(Command::FRX);
241 this->enter_rx_();
242}
243
245 int32_t freq = static_cast<int32_t>(this->state_.FREQ2 << 16 | this->state_.FREQ1 << 8 | this->state_.FREQ0) *
246 XTAL_FREQUENCY / (1 << 16);
247 float symbol_rate = (((256.0f + this->state_.DRATE_M) * (1 << this->state_.DRATE_E)) / (1 << 28)) * XTAL_FREQUENCY;
248 float bw = XTAL_FREQUENCY / (8.0f * (4 + this->state_.CHANBW_M) * (1 << this->state_.CHANBW_E));
249 ESP_LOGCONFIG(TAG,
250 "CC1101:\n"
251 " Chip ID: 0x%04X\n"
252 " Frequency: %" PRId32 " Hz\n"
253 " Channel: %u\n"
254 " Modulation: %s\n"
255 " Symbol Rate: %.0f baud\n"
256 " Filter Bandwidth: %.1f Hz\n"
257 " Output Power: %.1f dBm",
258 this->chip_id_, freq, this->state_.CHANNR,
259 LOG_STR_ARG(ModulationStrings::get_log_str(this->state_.MOD_FORMAT & 0x07, 0)), symbol_rate, bw,
260 this->output_power_effective_);
261 LOG_PIN(" CS Pin: ", this->cs_);
262}
263
265 // Read the mode before the PKTCTRL0 write below overwrites it in state_
266 const bool packet_mode = this->state_.PKT_FORMAT == static_cast<uint8_t>(PacketFormat::PACKET_FORMAT_FIFO);
267 // Ensure Packet Format is 3 (Async Serial)
268 this->write_(Register::PKTCTRL0, 0x32);
269 ESP_LOGV(TAG, "Beginning TX sequence");
270 if (this->gdo0_pin_ != nullptr) {
271 // setup() only attaches the interrupt in packet mode. In async serial mode the pin may be
272 // shared with remote_receiver, and detaching here would remove the receiver's interrupt.
273 if (packet_mode) {
275 }
277 }
278 // Transition through IDLE to bypass CCA (Clear Channel Assessment) which can
279 // block TX entry when strobing from RX, and to ensure FS_AUTOCAL calibration
280 this->enter_idle_();
281 if (!this->enter_tx_()) {
282 ESP_LOGW(TAG, "Failed to enter TX state!");
283 }
284}
285
287 ESP_LOGV(TAG, "Beginning RX sequence");
288 if (this->gdo0_pin_ != nullptr) {
290 }
291 // Transition through IDLE to ensure FS_AUTOCAL calibration occurs
292 this->enter_idle_();
293 if (!this->enter_rx_()) {
294 ESP_LOGW(TAG, "Failed to enter RX state!");
295 }
296}
297
299 this->strobe_(Command::RES);
300 this->configure();
301}
302
304 ESP_LOGV(TAG, "Setting IDLE state");
305 this->enter_idle_();
306}
307
308bool CC1101Component::wait_for_state_(State target_state, uint32_t timeout_ms) {
309 uint32_t start = millis();
310 while (millis() - start < timeout_ms) {
312 State s = static_cast<State>(this->state_.MARC_STATE);
313 if (s == target_state) {
314 return true;
315 }
317 }
318 return false;
319}
320
322 // The PLL must be recalibrated until PLL lock is achieved
323 for (uint8_t retries = PLL_LOCK_RETRIES; retries > 0; retries--) {
324 this->strobe_(cmd);
325 if (!this->wait_for_state_(target_state)) {
326 return false;
327 }
328 this->read_(Register::FSCAL1);
329 if (this->state_.FSCAL1 != FSCAL1_PLL_NOT_LOCKED) {
330 return true;
331 }
332 ESP_LOGW(TAG, "PLL lock failed, retrying calibration");
333 this->enter_idle_();
334 }
335 ESP_LOGE(TAG, "PLL lock failed after retries");
336 return false;
337}
338
343
345
347
349 uint8_t index = static_cast<uint8_t>(cmd);
350 if (cmd < Command::RES || cmd > Command::NOP) {
351 return 0xFF;
352 }
353 this->enable();
354 uint8_t status_byte = this->transfer_byte(index);
355 this->disable();
356 return status_byte;
357}
358
360 uint8_t index = static_cast<uint8_t>(reg);
361 this->enable();
362 this->write_byte(index);
363 this->write_array(&this->state_.regs()[index], 1);
364 this->disable();
365}
366
368 uint8_t index = static_cast<uint8_t>(reg);
369 this->state_.regs()[index] = value;
370 this->write_(reg);
371}
372
373void CC1101Component::write_(Register reg, const uint8_t *buffer, size_t length) {
374 uint8_t index = static_cast<uint8_t>(reg);
375 this->enable();
376 this->write_byte(index | BUS_WRITE | BUS_BURST);
377 this->write_array(buffer, length);
378 this->disable();
379}
380
382 uint8_t index = static_cast<uint8_t>(reg);
383 this->enable();
384 this->write_byte(index | BUS_READ | BUS_BURST);
385 this->state_.regs()[index] = this->transfer_byte(0);
386 this->disable();
387}
388
389void CC1101Component::read_(Register reg, uint8_t *buffer, size_t length) {
390 uint8_t index = static_cast<uint8_t>(reg);
391 this->enable();
392 this->write_byte(index | BUS_READ | BUS_BURST);
393 this->read_array(buffer, length);
394 this->disable();
395}
396
398 if (this->state_.PKT_FORMAT != static_cast<uint8_t>(PacketFormat::PACKET_FORMAT_FIFO)) {
399 return CC1101Error::PARAMS;
400 }
401 const bool variable = this->state_.LENGTH_CONFIG == static_cast<uint8_t>(LengthConfig::LENGTH_CONFIG_VARIABLE);
402 // In variable length mode the FIFO also holds the length byte
403 if (len + (variable ? 1 : 0) > TX_FIFO_SIZE) {
404 ESP_LOGE(TAG, "Packet of %u bytes does not fit the TX FIFO", static_cast<unsigned>(len));
405 return CC1101Error::PARAMS;
406 }
407
408 // Write packet
409 this->enter_idle_();
410 this->strobe_(Command::FTX);
411 if (variable) {
412 this->write_(Register::FIFO, static_cast<uint8_t>(len));
413 }
414#ifdef USE_ESP32
415 // SPI DMA cannot read flash or unaligned buffers; stage them here so the driver does not allocate a copy
416 alignas(4) uint8_t staged[TX_FIFO_SIZE];
417 if (len != 0 && (!esp_ptr_dma_capable(data) || (reinterpret_cast<uintptr_t>(data) & 3) != 0)) {
418 std::memcpy(staged, data, len);
419 data = staged;
420 }
421#endif
422 this->write_(Register::FIFO, data, len);
423
424 // Calibrate PLL
426 ESP_LOGW(TAG, "PLL lock failed during TX");
427 this->enter_idle_();
428 this->enter_rx_();
430 }
431
432 // Transmit packet
433 this->strobe_(Command::TX);
434 if (!this->wait_for_state_(State::IDLE, 1000)) {
435 ESP_LOGW(TAG, "TX timeout");
436 this->enter_idle_();
437 this->enter_rx_();
439 }
440
441 // Return to rx
442 this->enter_rx_();
443 return CC1101Error::NONE;
444}
445
446// Setters
449 int32_t freq = static_cast<int32_t>(this->state_.FREQ2 << 16 | this->state_.FREQ1 << 8 | this->state_.FREQ0) *
450 XTAL_FREQUENCY / (1 << 16);
451 uint8_t a = 0xC0;
452 if (freq >= 300000000 && freq <= 348000000) {
453 a = PowerTableItem::find(PA_TABLE_315, sizeof(PA_TABLE_315) / sizeof(PA_TABLE_315[0]), value);
454 } else if (freq >= 378000000 && freq <= 464000000) {
455 a = PowerTableItem::find(PA_TABLE_433, sizeof(PA_TABLE_433) / sizeof(PA_TABLE_433[0]), value);
456 } else if (freq >= 779000000 && freq < 900000000) {
457 a = PowerTableItem::find(PA_TABLE_868, sizeof(PA_TABLE_868) / sizeof(PA_TABLE_868[0]), value);
458 } else if (freq >= 900000000 && freq <= 928000000) {
459 a = PowerTableItem::find(PA_TABLE_915, sizeof(PA_TABLE_915) / sizeof(PA_TABLE_915[0]), value);
460 }
461
462 if (static_cast<Modulation>(this->state_.MOD_FORMAT) == Modulation::MODULATION_ASK_OOK) {
463 this->pa_table_[0] = 0;
464 this->pa_table_[1] = a;
465 } else {
466 this->pa_table_[0] = a;
467 this->pa_table_[1] = 0;
468 }
470 if (this->initialized_) {
471 this->write_(Register::PATABLE, this->pa_table_, sizeof(this->pa_table_));
472 }
473}
474
476 this->state_.CLOSE_IN_RX = static_cast<uint8_t>(value);
477 if (this->initialized_) {
479 }
480}
481
483 this->state_.DEM_DCFILT_OFF = value ? 0 : 1;
484 if (this->initialized_) {
486 }
487}
488
490 int32_t freq = static_cast<int32_t>(value * (1 << 16) / XTAL_FREQUENCY);
491 this->state_.FREQ2 = static_cast<uint8_t>(freq >> 16);
492 this->state_.FREQ1 = static_cast<uint8_t>(freq >> 8);
493 this->state_.FREQ0 = static_cast<uint8_t>(freq);
494 if (this->initialized_) {
495 this->enter_idle_();
496 this->write_(Register::FREQ2);
497 this->write_(Register::FREQ1);
498 this->write_(Register::FREQ0);
499 this->enter_rx_();
500 }
501}
502
504 this->state_.FREQ_IF = value * (1 << 10) / XTAL_FREQUENCY;
505 if (this->initialized_) {
507 }
508}
509
511 uint8_t e;
512 uint32_t m;
513 split_float(XTAL_FREQUENCY / (value * 8), 2, e, m);
514 this->state_.CHANBW_E = e;
515 this->state_.CHANBW_M = static_cast<uint8_t>(m);
516 if (this->initialized_) {
518 }
519}
520
522 this->state_.CHANNR = value;
523 if (this->initialized_) {
524 this->enter_idle_();
526 this->enter_rx_();
527 }
528}
529
531 uint8_t e;
532 uint32_t m;
533 split_float(value * (1 << 18) / XTAL_FREQUENCY, 8, e, m);
534 this->state_.CHANSPC_E = e;
535 this->state_.CHANSPC_M = static_cast<uint8_t>(m);
536 if (this->initialized_) {
539 }
540}
541
543 uint8_t e;
544 uint32_t m;
545 split_float(value * (1 << 17) / XTAL_FREQUENCY, 3, e, m);
546 this->state_.DEVIATION_E = e;
547 this->state_.DEVIATION_M = static_cast<uint8_t>(m);
548 if (this->initialized_) {
550 }
551}
552
554 this->state_.DEVIATION_E = 0;
555 this->state_.DEVIATION_M = value - 1;
556 if (this->initialized_) {
558 }
559}
560
562 uint8_t e;
563 uint32_t m;
564 split_float(value * (1 << 28) / XTAL_FREQUENCY, 8, e, m);
565 this->state_.DRATE_E = e;
566 this->state_.DRATE_M = static_cast<uint8_t>(m);
567 if (this->initialized_) {
570 }
571}
572
574 this->state_.SYNC_MODE = static_cast<uint8_t>(value);
575 if (this->initialized_) {
577 }
578}
579
581 this->state_.CARRIER_SENSE_ABOVE_THRESHOLD = value ? 1 : 0;
582 if (this->initialized_) {
584 }
585}
586
588 this->state_.MOD_FORMAT = static_cast<uint8_t>(value);
589 this->state_.PA_POWER = value == Modulation::MODULATION_ASK_OOK ? 1 : 0;
590 if (this->initialized_) {
591 this->enter_idle_();
595 this->enter_rx_();
596 }
597}
598
600 this->state_.MANCHESTER_EN = value ? 1 : 0;
601 if (this->initialized_) {
603 }
604}
605
607 this->state_.NUM_PREAMBLE = value;
608 if (this->initialized_) {
610 }
611}
612
614 this->state_.SYNC1 = value;
615 if (this->initialized_) {
616 this->write_(Register::SYNC1);
617 }
618}
619
621 this->state_.SYNC0 = value;
622 if (this->initialized_) {
623 this->write_(Register::SYNC0);
624 }
625}
626
628 this->state_.MAGN_TARGET = static_cast<uint8_t>(value);
629 if (this->initialized_) {
631 }
632}
633
635 this->state_.MAX_LNA_GAIN = static_cast<uint8_t>(value);
636 if (this->initialized_) {
638 }
639}
640
642 this->state_.MAX_DVGA_GAIN = static_cast<uint8_t>(value);
643 if (this->initialized_) {
645 }
646}
647
649 this->state_.CARRIER_SENSE_ABS_THR = static_cast<uint8_t>(value & 0b1111);
650 if (this->initialized_) {
652 }
653}
654
656 this->state_.CARRIER_SENSE_REL_THR = static_cast<uint8_t>(value);
657 if (this->initialized_) {
659 }
660}
661
663 this->state_.AGC_LNA_PRIORITY = value ? 1 : 0;
664 if (this->initialized_) {
666 }
667}
668
670 this->state_.FILTER_LENGTH = static_cast<uint8_t>(value);
671 if (this->initialized_) {
673 }
674}
675
677 this->state_.FILTER_LENGTH = static_cast<uint8_t>(value);
678 if (this->initialized_) {
680 }
681}
682
684 this->state_.AGC_FREEZE = static_cast<uint8_t>(value);
685 if (this->initialized_) {
687 }
688}
689
691 this->state_.WAIT_TIME = static_cast<uint8_t>(value);
692 if (this->initialized_) {
694 }
695}
696
698 this->state_.HYST_LEVEL = static_cast<uint8_t>(value);
699 if (this->initialized_) {
701 }
702}
703
705 this->state_.FOC_BS_CS_GATE = value ? 1 : 0;
706 if (this->initialized_) {
708 }
709}
710
712 this->state_.FOC_LIMIT = static_cast<uint8_t>(value);
713 if (this->initialized_) {
715 }
716}
717
719 this->state_.FOC_PRE_K = static_cast<uint8_t>(value);
720 if (this->initialized_) {
722 }
723}
724
726 this->state_.FOC_POST_K = static_cast<uint8_t>(value);
727 if (this->initialized_) {
729 }
730}
731
733 this->state_.BS_LIMIT = static_cast<uint8_t>(value);
734 if (this->initialized_) {
735 this->write_(Register::BSCFG);
736 }
737}
738
740 this->state_.BS_PRE_KI = static_cast<uint8_t>(value);
741 if (this->initialized_) {
742 this->write_(Register::BSCFG);
743 }
744}
745
747 this->state_.BS_PRE_KP = static_cast<uint8_t>(value);
748 if (this->initialized_) {
749 this->write_(Register::BSCFG);
750 }
751}
752
754 this->state_.BS_POST_KI = static_cast<uint8_t>(value);
755 if (this->initialized_) {
756 this->write_(Register::BSCFG);
757 }
758}
759
761 this->state_.BS_POST_KP = static_cast<uint8_t>(value);
762 if (this->initialized_) {
763 this->write_(Register::BSCFG);
764 }
765}
766
768 this->state_.PKT_FORMAT =
770 if (value) {
771 // Configure GDO0 for FIFO status (asserts on RX FIFO threshold or end of packet)
772 this->state_.GDO0_CFG = 0x01;
773 // Set max RX FIFO threshold to ensure we only trigger on end-of-packet
774 this->state_.FIFO_THR = 15;
775 // Don't append status bytes to FIFO - we read from registers instead
776 this->state_.APPEND_STATUS = 0;
777 } else {
778 // Configure GDO0 for serial data (async serial mode)
779 this->state_.GDO0_CFG = 0x0D;
780 }
781 if (this->initialized_) {
782 if (this->gdo0_pin_ != nullptr) {
783 if (value) {
785 } else {
787 }
788 }
793 }
794}
795
797 if (value == 0) {
798 this->state_.LENGTH_CONFIG = static_cast<uint8_t>(LengthConfig::LENGTH_CONFIG_VARIABLE);
799 } else {
800 this->state_.LENGTH_CONFIG = static_cast<uint8_t>(LengthConfig::LENGTH_CONFIG_FIXED);
801 this->state_.PKTLEN = value;
802 }
803 if (this->initialized_) {
806 }
807}
808
810 this->state_.CRC_EN = value ? 1 : 0;
811 if (this->initialized_) {
813 }
814}
815
817 this->state_.WHITE_DATA = value ? 1 : 0;
818 if (this->initialized_) {
820 }
821}
822
823} // namespace esphome::cc1101
uint8_t m
Definition bl0906.h:1
void mark_failed()
Mark this component as failed.
bool is_failed() const
Definition component.h:287
void enable_loop_soon_any_context()
Thread and ISR-safe version of enable_loop() that can be called from any context.
void defer(const char *name, std::function< void()> &&f)
Defer a callback to the next loop() call with a const char* name.
void disable_loop()
Disable this component's loop.
virtual void digital_write(bool value)=0
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Inform the parent automation that the event has triggered.
Definition automation.h:557
void set_bs_post_kp(BsPostKp value)
Definition cc1101.cpp:760
void set_packet_mode(bool value)
Definition cc1101.cpp:767
void set_max_dvga_gain(MaxDvgaGain value)
Definition cc1101.cpp:641
void set_whitening(bool value)
Definition cc1101.cpp:816
void set_carrier_sense_above_threshold(bool value)
Definition cc1101.cpp:580
void write_(Register reg)
Definition cc1101.cpp:359
void set_sync0(uint8_t value)
Definition cc1101.cpp:620
void set_freeze(Freeze value)
Definition cc1101.cpp:683
void call_listeners_(const std::vector< uint8_t > &packet, float freq_offset, float rssi, uint8_t lqi)
Definition cc1101.cpp:181
void set_rx_attenuation(RxAttenuation value)
Definition cc1101.cpp:475
InternalGPIOPin * gdo0_pin_
Definition cc1101.h:110
void set_symbol_rate(float value)
Definition cc1101.cpp:561
void set_bs_pre_ki(BsPreKi value)
Definition cc1101.cpp:739
uint8_t strobe_(Command cmd)
Definition cc1101.cpp:348
void set_sync_mode(SyncMode value)
Definition cc1101.cpp:573
void set_fsk_deviation(float value)
Definition cc1101.cpp:542
void set_bs_pre_kp(BsPreKp value)
Definition cc1101.cpp:746
void set_msk_deviation(uint8_t value)
Definition cc1101.cpp:553
void set_carrier_sense_rel_thr(CarrierSenseRelThr value)
Definition cc1101.cpp:655
uint8_t pa_table_[PA_TABLE_SIZE]
Definition cc1101.h:105
void set_lna_priority(bool value)
Definition cc1101.cpp:662
void set_foc_bs_cs_gate(bool value)
Definition cc1101.cpp:704
void set_foc_pre_k(FocPreK value)
Definition cc1101.cpp:718
void set_output_power(float value)
Definition cc1101.cpp:447
void set_modulation_type(Modulation value)
Definition cc1101.cpp:587
void set_if_frequency(float value)
Definition cc1101.cpp:503
void set_frequency(float value)
Definition cc1101.cpp:489
void set_num_preamble(uint8_t value)
Definition cc1101.cpp:606
void set_hyst_level(HystLevel value)
Definition cc1101.cpp:697
void set_filter_bandwidth(float value)
Definition cc1101.cpp:510
void set_filter_length_fsk_msk(FilterLengthFskMsk value)
Definition cc1101.cpp:669
void set_crc_enable(bool value)
Definition cc1101.cpp:809
static void gpio_intr(CC1101Component *arg)
Definition cc1101.cpp:115
void set_carrier_sense_abs_thr(int8_t value)
Definition cc1101.cpp:648
void set_bs_post_ki(BsPostKi value)
Definition cc1101.cpp:753
bool enter_calibrated_(State target_state, Command cmd)
Definition cc1101.cpp:321
void set_magn_target(MagnTarget value)
Definition cc1101.cpp:627
void set_channel_spacing(float value)
Definition cc1101.cpp:530
CC1101Error transmit_packet(const std::vector< uint8_t > &packet)
Definition cc1101.h:92
void set_wait_time(WaitTime value)
Definition cc1101.cpp:690
std::vector< CC1101Listener * > listeners_
Definition cc1101.h:117
void set_dc_blocking_filter(bool value)
Definition cc1101.cpp:482
void set_packet_length(uint8_t value)
Definition cc1101.cpp:796
void set_manchester(bool value)
Definition cc1101.cpp:599
std::vector< uint8_t > packet_
Definition cc1101.h:116
void set_channel(uint8_t value)
Definition cc1101.cpp:521
void set_foc_limit(FocLimit value)
Definition cc1101.cpp:711
void set_filter_length_ask_ook(FilterLengthAskOok value)
Definition cc1101.cpp:676
void set_max_lna_gain(MaxLnaGain value)
Definition cc1101.cpp:634
void set_sync1(uint8_t value)
Definition cc1101.cpp:613
bool wait_for_state_(State target_state, uint32_t timeout_ms=100)
Definition cc1101.cpp:308
void set_bs_limit(BsLimit value)
Definition cc1101.cpp:732
void set_foc_post_k(FocPostK value)
Definition cc1101.cpp:725
Trigger< std::vector< uint8_t >, float, float, uint8_t > packet_trigger_
Definition cc1101.h:115
void attach_interrupt(void(*func)(T *), T *arg, gpio::InterruptType type) const
Definition gpio.h:29
void pin_mode(gpio::Flags flags) override
Definition gpio.cpp:195
uint32_t buffer
Definition gif.cpp:50
PROGMEM_STRING_TABLE(ModulationStrings, "2-FSK", "GFSK", "UNUSED", "ASK/OOK", "4-FSK", "UNUSED", "UNUSED", "MSK")
ESPHOME_LOG_TAG(TAG, "cc1101")
@ INTERRUPT_RISING_EDGE
Definition gpio_pin.h:52
uint32_t value
Definition hal.cpp:41
const void size_t len
Definition hal.h:68
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition hal.cpp:48
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
Definition helpers.h:1043
void HOT delay(uint32_t ms)
Definition hal.cpp:85
uint32_t IRAM_ATTR HOT millis()
Definition hal.cpp:25
static void uint32_t
static uint8_t find(const PowerTableItem *items, size_t count, float &dbm_target)
Definition cc1101pa.h:15
uint16_t length
Definition tt21100.cpp:0