ESPHome 2026.8.0-dev
Loading...
Searching...
No Matches
cc1101defs.h
Go to the documentation of this file.
1#pragma once
2
3#include <cinttypes>
4
5namespace esphome::cc1101 {
6
7static constexpr float XTAL_FREQUENCY = 26000000;
8
9static constexpr float RSSI_OFFSET = 74.0f;
10static constexpr float RSSI_STEP = 0.5f;
11
12static constexpr uint8_t FSCAL1_PLL_NOT_LOCKED = 0x3F;
13static constexpr uint8_t PLL_LOCK_RETRIES = 3;
14
15static constexpr uint8_t STATUS_CRC_OK_MASK = 0x80;
16static constexpr uint8_t STATUS_LQI_MASK = 0x7F;
17
18static constexpr uint8_t BUS_BURST = 0x40;
19static constexpr uint8_t BUS_READ = 0x80;
20static constexpr uint8_t BUS_WRITE = 0x00;
21static constexpr uint8_t BYTES_IN_RXFIFO = 0x7F; // byte number in RXfifo
22static constexpr size_t PA_TABLE_SIZE = 8;
23
24enum class Register : uint8_t {
25 IOCFG2 = 0x00, // GDO2 output pin configuration
26 IOCFG1 = 0x01, // GDO1 output pin configuration
27 IOCFG0 = 0x02, // GDO0 output pin configuration
28 FIFOTHR = 0x03, // RX FIFO and TX FIFO thresholds
29 SYNC1 = 0x04, // Sync word, high INT8U
30 SYNC0 = 0x05, // Sync word, low INT8U
31 PKTLEN = 0x06, // Packet length
32 PKTCTRL1 = 0x07, // Packet automation control
33 PKTCTRL0 = 0x08, // Packet automation control
34 ADDR = 0x09, // Device address
35 CHANNR = 0x0A, // Channel number
36 FSCTRL1 = 0x0B, // Frequency synthesizer control
37 FSCTRL0 = 0x0C, // Frequency synthesizer control
38 FREQ2 = 0x0D, // Frequency control word, high INT8U
39 FREQ1 = 0x0E, // Frequency control word, middle INT8U
40 FREQ0 = 0x0F, // Frequency control word, low INT8U
41 MDMCFG4 = 0x10, // Modem configuration
42 MDMCFG3 = 0x11, // Modem configuration
43 MDMCFG2 = 0x12, // Modem configuration
44 MDMCFG1 = 0x13, // Modem configuration
45 MDMCFG0 = 0x14, // Modem configuration
46 DEVIATN = 0x15, // Modem deviation setting
47 MCSM2 = 0x16, // Main Radio Control State Machine configuration
48 MCSM1 = 0x17, // Main Radio Control State Machine configuration
49 MCSM0 = 0x18, // Main Radio Control State Machine configuration
50 FOCCFG = 0x19, // Frequency Offset Compensation configuration
51 BSCFG = 0x1A, // Bit Synchronization configuration
52 AGCCTRL2 = 0x1B, // AGC control
53 AGCCTRL1 = 0x1C, // AGC control
54 AGCCTRL0 = 0x1D, // AGC control
55 WOREVT1 = 0x1E, // High INT8U Event 0 timeout
56 WOREVT0 = 0x1F, // Low INT8U Event 0 timeout
57 WORCTRL = 0x20, // Wake On Radio control
58 FREND1 = 0x21, // Front end RX configuration
59 FREND0 = 0x22, // Front end TX configuration
60 FSCAL3 = 0x23, // Frequency synthesizer calibration
61 FSCAL2 = 0x24, // Frequency synthesizer calibration
62 FSCAL1 = 0x25, // Frequency synthesizer calibration
63 FSCAL0 = 0x26, // Frequency synthesizer calibration
64 RCCTRL1 = 0x27, // RC oscillator configuration
65 RCCTRL0 = 0x28, // RC oscillator configuration
66 FSTEST = 0x29, // Frequency synthesizer calibration control
67 PTEST = 0x2A, // Production test
68 AGCTEST = 0x2B, // AGC test
69 TEST2 = 0x2C, // Various test settings
70 TEST1 = 0x2D, // Various test settings
71 TEST0 = 0x2E, // Various test settings
72 UNUSED = 0x2F,
73 PARTNUM = 0x30,
74 VERSION = 0x31,
75 FREQEST = 0x32,
76 LQI = 0x33,
77 RSSI = 0x34,
78 MARCSTATE = 0x35,
79 WORTIME1 = 0x36,
80 WORTIME0 = 0x37,
81 PKTSTATUS = 0x38,
82 VCO_VC_DAC = 0x39,
83 TXBYTES = 0x3A,
84 RXBYTES = 0x3B,
85 RCCTRL1_STATUS = 0x3C,
86 RCCTRL0_STATUS = 0x3D,
87 PATABLE = 0x3E,
88 FIFO = 0x3F,
89};
90
91enum class Command : uint8_t {
92 RES = 0x30, // Reset chip.
93 FSTXON = 0x31, // Enable and calibrate frequency synthesizer
94 XOFF = 0x32, // Turn off crystal oscillator.
95 CAL = 0x33, // Calibrate frequency synthesizer and turn it off
96 RX = 0x34, // Enable RX.
97 TX = 0x35, // Enable TX.
98 IDLE = 0x36, // Exit RX / TX
99 // 0x37 is RESERVED / UNDEFINED in CC1101 Datasheet
100 WOR = 0x38, // Start automatic RX polling sequence (Wake-on-Radio)
101 PWD = 0x39, // Enter power down mode when CSn goes high.
102 FRX = 0x3A, // Flush the RX FIFO buffer.
103 FTX = 0x3B, // Flush the TX FIFO buffer.
104 WORRST = 0x3C, // Reset real time clock.
105 NOP = 0x3D, // No operation.
106};
107
108enum class State : uint8_t {
109 SLEEP,
110 IDLE,
111 XOFF,
112 VCOON_MC,
113 REGON_MC,
114 MANCAL,
115 VCOON,
116 REGON,
117 STARTCAL,
118 BWBOOST,
119 FS_LOCK,
120 IFADCON,
121 ENDCAL,
122 RX,
123 RX_END,
124 RX_RST,
127 FSTXON,
128 TX,
129 TX_END,
132};
133
140
151
162
173
184
191
198
205
212
213enum class Freeze : uint8_t {
218};
219
226
227enum class HystLevel : uint8_t {
232};
233
234enum class FocLimit : uint8_t {
239};
240
241enum class FocPreK : uint8_t {
246};
247
248enum class FocPostK : uint8_t {
251};
252
259
260enum class BsPreKi : uint8_t {
265};
266
267enum class BsPreKp : uint8_t {
272};
273
274enum class BsPostKi : uint8_t {
277};
278
279enum class BsPostKp : uint8_t {
282};
283
290
296
297struct __attribute__((packed)) CC1101State {
298 // Byte array accessors for bulk SPI transfers
299 uint8_t *regs() { return reinterpret_cast<uint8_t *>(this); }
300 const uint8_t *regs() const { return reinterpret_cast<const uint8_t *>(this); }
301
302 // 0x00
303 union {
304 uint8_t IOCFG2;
305 struct {
306 uint8_t GDO2_CFG : 6;
307 uint8_t GDO2_INV : 1;
308 uint8_t : 1;
309 };
310 };
311 // 0x01
312 union {
313 uint8_t IOCFG1;
314 struct {
315 uint8_t GDO1_CFG : 6;
316 uint8_t GDO1_INV : 1;
317 uint8_t GDO_DS : 1; // GDO, not GD0
318 };
319 };
320 // 0x02
321 union {
322 uint8_t IOCFG0;
323 struct {
324 uint8_t GDO0_CFG : 6;
325 uint8_t GDO0_INV : 1;
326 uint8_t TEMP_SENSOR_ENABLE : 1;
327 };
328 };
329 // 0x03
330 union {
331 uint8_t FIFOTHR;
332 struct {
333 uint8_t FIFO_THR : 4;
334 uint8_t CLOSE_IN_RX : 2; // RxAttenuation
335 uint8_t ADC_RETENTION : 1;
336 uint8_t : 1;
337 };
338 };
339 // 0x04
340 uint8_t SYNC1;
341 // 0x05
342 uint8_t SYNC0;
343 // 0x06
344 uint8_t PKTLEN;
345 // 0x07
346 union {
347 uint8_t PKTCTRL1;
348 struct {
349 uint8_t ADR_CHK : 2;
350 uint8_t APPEND_STATUS : 1;
351 uint8_t CRC_AUTOFLUSH : 1;
352 uint8_t : 1;
353 uint8_t PQT : 3;
354 };
355 };
356 // 0x08
357 union {
358 uint8_t PKTCTRL0;
359 struct {
360 uint8_t LENGTH_CONFIG : 2;
361 uint8_t CRC_EN : 1;
362 uint8_t : 1;
363 uint8_t PKT_FORMAT : 2;
364 uint8_t WHITE_DATA : 1;
365 uint8_t : 1;
366 };
367 };
368 // 0x09
369 uint8_t ADDR;
370 // 0x0A
371 uint8_t CHANNR;
372 // 0x0B
373 union {
374 uint8_t FSCTRL1;
375 struct {
376 uint8_t FREQ_IF : 5;
377 uint8_t RESERVED : 1; // hm?
378 uint8_t : 2;
379 };
380 };
381 // 0x0C
382 uint8_t FSCTRL0;
383 // 0x0D
384 uint8_t FREQ2; // [7:6] always zero
385 // 0x0E
386 uint8_t FREQ1;
387 // 0x0F
388 uint8_t FREQ0;
389 // 0x10
390 union {
391 uint8_t MDMCFG4;
392 struct {
393 uint8_t DRATE_E : 4;
394 uint8_t CHANBW_M : 2;
395 uint8_t CHANBW_E : 2;
396 };
397 };
398 // 0x11
399 union {
400 uint8_t MDMCFG3;
401 struct {
402 uint8_t DRATE_M : 8;
403 };
404 };
405 // 0x12
406 union {
407 uint8_t MDMCFG2;
408 struct {
409 uint8_t SYNC_MODE : 2;
410 uint8_t CARRIER_SENSE_ABOVE_THRESHOLD : 1;
411 uint8_t MANCHESTER_EN : 1;
412 uint8_t MOD_FORMAT : 3; // Modulation
413 uint8_t DEM_DCFILT_OFF : 1;
414 };
415 };
416 // 0x13
417 union {
418 uint8_t MDMCFG1;
419 struct {
420 uint8_t CHANSPC_E : 2;
421 uint8_t : 2;
422 uint8_t NUM_PREAMBLE : 3;
423 uint8_t FEC_EN : 1;
424 };
425 };
426 // 0x14
427 union {
428 uint8_t MDMCFG0;
429 struct {
430 uint8_t CHANSPC_M : 8;
431 };
432 };
433 // 0x15
434 union {
435 uint8_t DEVIATN;
436 struct {
437 uint8_t DEVIATION_M : 3;
438 uint8_t : 1;
439 uint8_t DEVIATION_E : 3;
440 uint8_t : 1;
441 };
442 };
443 // 0x16
444 union {
445 uint8_t MCSM2;
446 struct {
447 uint8_t RX_TIME : 3;
448 uint8_t RX_TIME_QUAL : 1;
449 uint8_t RX_TIME_RSSI : 1;
450 uint8_t : 3;
451 };
452 };
453 // 0x17
454 union {
455 uint8_t MCSM1;
456 struct {
457 uint8_t TXOFF_MODE : 2;
458 uint8_t RXOFF_MODE : 2;
459 uint8_t CCA_MODE : 2;
460 uint8_t : 2;
461 };
462 };
463 // 0x18
464 union {
465 uint8_t MCSM0;
466 struct {
467 uint8_t XOSC_FORCE_ON : 1;
468 uint8_t PIN_CTRL_EN : 1;
469 uint8_t PO_TIMEOUT : 2;
470 uint8_t FS_AUTOCAL : 2;
471 uint8_t : 2;
472 };
473 };
474 // 0x19
475 union {
476 uint8_t FOCCFG;
477 struct {
478 uint8_t FOC_LIMIT : 2;
479 uint8_t FOC_POST_K : 1;
480 uint8_t FOC_PRE_K : 2;
481 uint8_t FOC_BS_CS_GATE : 1;
482 uint8_t : 2;
483 };
484 };
485 // 0x1A
486 union {
487 uint8_t BSCFG;
488 struct {
489 uint8_t BS_LIMIT : 2;
490 uint8_t BS_POST_KP : 1;
491 uint8_t BS_POST_KI : 1;
492 uint8_t BS_PRE_KP : 2;
493 uint8_t BS_PRE_KI : 2;
494 };
495 };
496 // 0x1B
497 union {
498 uint8_t AGCCTRL2;
499 struct {
500 uint8_t MAGN_TARGET : 3; // MagnTarget
501 uint8_t MAX_LNA_GAIN : 3; // MaxLnaGain
502 uint8_t MAX_DVGA_GAIN : 2; // MaxDvgaGain
503 };
504 };
505 // 0x1C
506 union {
507 uint8_t AGCCTRL1;
508 struct {
509 uint8_t CARRIER_SENSE_ABS_THR : 4;
510 uint8_t CARRIER_SENSE_REL_THR : 2; // CarrierSenseRelThr
511 uint8_t AGC_LNA_PRIORITY : 1;
512 uint8_t : 1;
513 };
514 };
515 // 0x1D
516 union {
517 uint8_t AGCCTRL0;
518 struct {
519 uint8_t FILTER_LENGTH : 2; // FilterLengthFskMsk or FilterLengthAskOok
520 uint8_t AGC_FREEZE : 2; // Freeze
521 uint8_t WAIT_TIME : 2; // WaitTime
522 uint8_t HYST_LEVEL : 2; // HystLevel
523 };
524 };
525 // 0x1E
526 uint8_t WOREVT1;
527 // 0x1F
528 uint8_t WOREVT0;
529 // 0x20
530 union {
531 uint8_t WORCTRL;
532 struct {
533 uint8_t WOR_RES : 2;
534 uint8_t : 1;
535 uint8_t RC_CAL : 1;
536 uint8_t EVENT1 : 3;
537 uint8_t RC_PD : 1;
538 };
539 };
540 // 0x21
541 union {
542 uint8_t FREND1;
543 struct {
544 uint8_t MIX_CURRENT : 2;
545 uint8_t LODIV_BUF_CURRENT_RX : 2;
546 uint8_t LNA2MIX_CURRENT : 2;
547 uint8_t LNA_CURRENT : 2;
548 };
549 };
550 // 0x22
551 union {
552 uint8_t FREND0;
553 struct {
554 uint8_t PA_POWER : 3;
555 uint8_t : 1;
556 uint8_t LODIV_BUF_CURRENT_TX : 2;
557 uint8_t : 2;
558 };
559 };
560 // 0x23
561 union {
562 uint8_t FSCAL3;
563 struct {
564 uint8_t FSCAL3_LO : 4;
565 uint8_t CHP_CURR_CAL_EN : 2; // Disable charge pump calibration stage when 0.
566 uint8_t FSCAL3_HI : 2;
567 };
568 };
569 // 0x24
570 union {
571 // uint8_t FSCAL2;
572 struct {
573 uint8_t FSCAL2 : 5;
574 uint8_t VCO_CORE_H_EN : 1;
575 uint8_t : 2;
576 };
577 };
578 // 0x25
579 union {
580 // uint8_t FSCAL1;
581 struct {
582 uint8_t FSCAL1 : 6;
583 uint8_t : 2;
584 };
585 };
586 // 0x26
587 union {
588 // uint8_t FSCAL0;
589 struct {
590 uint8_t FSCAL0 : 7;
591 uint8_t : 1;
592 };
593 };
594 // 0x27
595 union {
596 // uint8_t RCCTRL1;
597 struct {
598 uint8_t RCCTRL1 : 7;
599 uint8_t : 1;
600 };
601 };
602 // 0x28
603 union {
604 // uint8_t RCCTRL0;
605 struct {
606 uint8_t RCCTRL0 : 7;
607 uint8_t : 1;
608 };
609 };
610 // 0x29
611 uint8_t FSTEST;
612 // 0x2A
613 uint8_t PTEST;
614 // 0x2B
615 uint8_t AGCTEST;
616 // 0x2C
617 uint8_t TEST2;
618 // 0x2D
619 uint8_t TEST1;
620 // 0x2E
621 union {
622 uint8_t TEST0;
623 struct {
624 uint8_t TEST0_LO : 1;
625 uint8_t VCO_SEL_CAL_EN : 1; // Enable VCO selection calibration stage when 1
626 uint8_t TEST0_HI : 6;
627 };
628 };
629 // 0x2F
630 uint8_t REG_2F;
631 // 0x30
632 uint8_t PARTNUM;
633 // 0x31
634 uint8_t VERSION;
635 // 0x32
636 union {
637 uint8_t FREQEST;
638 struct {
639 int8_t FREQOFF_EST : 8;
640 };
641 };
642 // 0x33
643 union {
644 uint8_t LQI;
645 struct {
646 uint8_t LQI_EST : 7;
647 uint8_t LQI_CRC_OK : 1;
648 };
649 };
650 // 0x34
651 int8_t RSSI;
652 // 0x35
653 union {
654 // uint8_t MARCSTATE;
655 struct {
656 uint8_t MARC_STATE : 5; // State
657 uint8_t : 3;
658 };
659 };
660 // 0x36
661 uint8_t WORTIME1;
662 // 0x37
663 uint8_t WORTIME0;
664 // 0x38
665 union {
666 uint8_t PKTSTATUS;
667 struct {
668 uint8_t GDO0 : 1;
669 uint8_t : 1;
670 uint8_t GDO2 : 1;
671 uint8_t SFD : 1;
672 uint8_t CCA : 1;
673 uint8_t PQT_REACHED : 1;
674 uint8_t CS : 1;
675 uint8_t CRC_OK : 1; // same as LQI_CRC_OK?
676 };
677 };
678 // 0x39
679 uint8_t VCO_VC_DAC;
680 // 0x3A
681 union {
682 uint8_t TXBYTES;
683 struct {
684 uint8_t NUM_TXBYTES : 7;
685 uint8_t TXFIFO_UNDERFLOW : 1;
686 };
687 };
688 // 0x3B
689 union {
690 uint8_t RXBYTES;
691 struct {
692 uint8_t NUM_RXBYTES : 7;
693 uint8_t RXFIFO_OVERFLOW : 1;
694 };
695 };
696 // 0x3C
697 union {
698 // uint8_t RCCTRL1_STATUS;
699 struct {
700 uint8_t RCCTRL1_STATUS : 7;
701 uint8_t : 1;
702 };
703 };
704 // 0x3D
705 union {
706 // uint8_t RCCTRL0_STATUS;
707 struct {
708 uint8_t RCCTRL0_STATUS : 7;
709 uint8_t : 1;
710 };
711 };
712 // 0x3E
713 uint8_t REG_3E;
714 // 0x3F
715 uint8_t REG_3F;
716};
717
718static_assert(sizeof(CC1101State) == 0x40, "CC1101State size mismatch");
719
720} // namespace esphome::cc1101
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:32