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