ESPHome 2025.12.5
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
240
246
247struct __attribute__((packed)) CC1101State {
248 // Byte array accessors for bulk SPI transfers
249 uint8_t *regs() { return reinterpret_cast<uint8_t *>(this); }
250 const uint8_t *regs() const { return reinterpret_cast<const uint8_t *>(this); }
251
252 // 0x00
253 union {
254 uint8_t IOCFG2;
255 struct {
256 uint8_t GDO2_CFG : 6;
257 uint8_t GDO2_INV : 1;
258 uint8_t : 1;
259 };
260 };
261 // 0x01
262 union {
263 uint8_t IOCFG1;
264 struct {
265 uint8_t GDO1_CFG : 6;
266 uint8_t GDO1_INV : 1;
267 uint8_t GDO_DS : 1; // GDO, not GD0
268 };
269 };
270 // 0x02
271 union {
272 uint8_t IOCFG0;
273 struct {
274 uint8_t GDO0_CFG : 6;
275 uint8_t GDO0_INV : 1;
276 uint8_t TEMP_SENSOR_ENABLE : 1;
277 };
278 };
279 // 0x03
280 union {
281 uint8_t FIFOTHR;
282 struct {
283 uint8_t FIFO_THR : 4;
284 uint8_t CLOSE_IN_RX : 2; // RxAttenuation
285 uint8_t ADC_RETENTION : 1;
286 uint8_t : 1;
287 };
288 };
289 // 0x04
290 uint8_t SYNC1;
291 // 0x05
292 uint8_t SYNC0;
293 // 0x06
294 uint8_t PKTLEN;
295 // 0x07
296 union {
297 uint8_t PKTCTRL1;
298 struct {
299 uint8_t ADR_CHK : 2;
300 uint8_t APPEND_STATUS : 1;
301 uint8_t CRC_AUTOFLUSH : 1;
302 uint8_t : 1;
303 uint8_t PQT : 3;
304 };
305 };
306 // 0x08
307 union {
308 uint8_t PKTCTRL0;
309 struct {
310 uint8_t LENGTH_CONFIG : 2;
311 uint8_t CRC_EN : 1;
312 uint8_t : 1;
313 uint8_t PKT_FORMAT : 2;
314 uint8_t WHITE_DATA : 1;
315 uint8_t : 1;
316 };
317 };
318 // 0x09
319 uint8_t ADDR;
320 // 0x0A
321 uint8_t CHANNR;
322 // 0x0B
323 union {
324 uint8_t FSCTRL1;
325 struct {
326 uint8_t FREQ_IF : 5;
327 uint8_t RESERVED : 1; // hm?
328 uint8_t : 2;
329 };
330 };
331 // 0x0C
332 uint8_t FSCTRL0;
333 // 0x0D
334 uint8_t FREQ2; // [7:6] always zero
335 // 0x0E
336 uint8_t FREQ1;
337 // 0x0F
338 uint8_t FREQ0;
339 // 0x10
340 union {
341 uint8_t MDMCFG4;
342 struct {
343 uint8_t DRATE_E : 4;
344 uint8_t CHANBW_M : 2;
345 uint8_t CHANBW_E : 2;
346 };
347 };
348 // 0x11
349 union {
350 uint8_t MDMCFG3;
351 struct {
352 uint8_t DRATE_M : 8;
353 };
354 };
355 // 0x12
356 union {
357 uint8_t MDMCFG2;
358 struct {
359 uint8_t SYNC_MODE : 2;
360 uint8_t CARRIER_SENSE_ABOVE_THRESHOLD : 1;
361 uint8_t MANCHESTER_EN : 1;
362 uint8_t MOD_FORMAT : 3; // Modulation
363 uint8_t DEM_DCFILT_OFF : 1;
364 };
365 };
366 // 0x13
367 union {
368 uint8_t MDMCFG1;
369 struct {
370 uint8_t CHANSPC_E : 2;
371 uint8_t : 2;
372 uint8_t NUM_PREAMBLE : 3;
373 uint8_t FEC_EN : 1;
374 };
375 };
376 // 0x14
377 union {
378 uint8_t MDMCFG0;
379 struct {
380 uint8_t CHANSPC_M : 8;
381 };
382 };
383 // 0x15
384 union {
385 uint8_t DEVIATN;
386 struct {
387 uint8_t DEVIATION_M : 3;
388 uint8_t : 1;
389 uint8_t DEVIATION_E : 3;
390 uint8_t : 1;
391 };
392 };
393 // 0x16
394 union {
395 uint8_t MCSM2;
396 struct {
397 uint8_t RX_TIME : 3;
398 uint8_t RX_TIME_QUAL : 1;
399 uint8_t RX_TIME_RSSI : 1;
400 uint8_t : 3;
401 };
402 };
403 // 0x17
404 union {
405 uint8_t MCSM1;
406 struct {
407 uint8_t TXOFF_MODE : 2;
408 uint8_t RXOFF_MODE : 2;
409 uint8_t CCA_MODE : 2;
410 uint8_t : 2;
411 };
412 };
413 // 0x18
414 union {
415 uint8_t MCSM0;
416 struct {
417 uint8_t XOSC_FORCE_ON : 1;
418 uint8_t PIN_CTRL_EN : 1;
419 uint8_t PO_TIMEOUT : 2;
420 uint8_t FS_AUTOCAL : 2;
421 uint8_t : 2;
422 };
423 };
424 // 0x19
425 union {
426 uint8_t FOCCFG;
427 struct {
428 uint8_t FOC_LIMIT : 2;
429 uint8_t FOC_POST_K : 1;
430 uint8_t FOC_PRE_K : 2;
431 uint8_t FOC_BS_CS_GATE : 1;
432 uint8_t : 2;
433 };
434 };
435 // 0x1A
436 union {
437 uint8_t BSCFG;
438 struct {
439 uint8_t BS_LIMIT : 2;
440 uint8_t BS_POST_KP : 1;
441 uint8_t BS_POST_KI : 1;
442 uint8_t BS_PRE_KP : 2;
443 uint8_t BS_PRE_KI : 2;
444 };
445 };
446 // 0x1B
447 union {
448 uint8_t AGCCTRL2;
449 struct {
450 uint8_t MAGN_TARGET : 3; // MagnTarget
451 uint8_t MAX_LNA_GAIN : 3; // MaxLnaGain
452 uint8_t MAX_DVGA_GAIN : 2; // MaxDvgaGain
453 };
454 };
455 // 0x1C
456 union {
457 uint8_t AGCCTRL1;
458 struct {
459 uint8_t CARRIER_SENSE_ABS_THR : 4;
460 uint8_t CARRIER_SENSE_REL_THR : 2; // CarrierSenseRelThr
461 uint8_t AGC_LNA_PRIORITY : 1;
462 uint8_t : 1;
463 };
464 };
465 // 0x1D
466 union {
467 uint8_t AGCCTRL0;
468 struct {
469 uint8_t FILTER_LENGTH : 2; // FilterLengthFskMsk or FilterLengthAskOok
470 uint8_t AGC_FREEZE : 2; // Freeze
471 uint8_t WAIT_TIME : 2; // WaitTime
472 uint8_t HYST_LEVEL : 2; // HystLevel
473 };
474 };
475 // 0x1E
476 uint8_t WOREVT1;
477 // 0x1F
478 uint8_t WOREVT0;
479 // 0x20
480 union {
481 uint8_t WORCTRL;
482 struct {
483 uint8_t WOR_RES : 2;
484 uint8_t : 1;
485 uint8_t RC_CAL : 1;
486 uint8_t EVENT1 : 3;
487 uint8_t RC_PD : 1;
488 };
489 };
490 // 0x21
491 union {
492 uint8_t FREND1;
493 struct {
494 uint8_t MIX_CURRENT : 2;
495 uint8_t LODIV_BUF_CURRENT_RX : 2;
496 uint8_t LNA2MIX_CURRENT : 2;
497 uint8_t LNA_CURRENT : 2;
498 };
499 };
500 // 0x22
501 union {
502 uint8_t FREND0;
503 struct {
504 uint8_t PA_POWER : 3;
505 uint8_t : 1;
506 uint8_t LODIV_BUF_CURRENT_TX : 2;
507 uint8_t : 2;
508 };
509 };
510 // 0x23
511 union {
512 uint8_t FSCAL3;
513 struct {
514 uint8_t FSCAL3_LO : 4;
515 uint8_t CHP_CURR_CAL_EN : 2; // Disable charge pump calibration stage when 0.
516 uint8_t FSCAL3_HI : 2;
517 };
518 };
519 // 0x24
520 union {
521 // uint8_t FSCAL2;
522 struct {
523 uint8_t FSCAL2 : 5;
524 uint8_t VCO_CORE_H_EN : 1;
525 uint8_t : 2;
526 };
527 };
528 // 0x25
529 union {
530 // uint8_t FSCAL1;
531 struct {
532 uint8_t FSCAL1 : 6;
533 uint8_t : 2;
534 };
535 };
536 // 0x26
537 union {
538 // uint8_t FSCAL0;
539 struct {
540 uint8_t FSCAL0 : 7;
541 uint8_t : 1;
542 };
543 };
544 // 0x27
545 union {
546 // uint8_t RCCTRL1;
547 struct {
548 uint8_t RCCTRL1 : 7;
549 uint8_t : 1;
550 };
551 };
552 // 0x28
553 union {
554 // uint8_t RCCTRL0;
555 struct {
556 uint8_t RCCTRL0 : 7;
557 uint8_t : 1;
558 };
559 };
560 // 0x29
561 uint8_t FSTEST;
562 // 0x2A
563 uint8_t PTEST;
564 // 0x2B
565 uint8_t AGCTEST;
566 // 0x2C
567 uint8_t TEST2;
568 // 0x2D
569 uint8_t TEST1;
570 // 0x2E
571 union {
572 uint8_t TEST0;
573 struct {
574 uint8_t TEST0_LO : 1;
575 uint8_t VCO_SEL_CAL_EN : 1; // Enable VCO selection calibration stage when 1
576 uint8_t TEST0_HI : 6;
577 };
578 };
579 // 0x2F
580 uint8_t REG_2F;
581 // 0x30
582 uint8_t PARTNUM;
583 // 0x31
584 uint8_t VERSION;
585 // 0x32
586 union {
587 uint8_t FREQEST;
588 struct {
589 int8_t FREQOFF_EST : 8;
590 };
591 };
592 // 0x33
593 union {
594 uint8_t LQI;
595 struct {
596 uint8_t LQI_EST : 7;
597 uint8_t LQI_CRC_OK : 1;
598 };
599 };
600 // 0x34
601 int8_t RSSI;
602 // 0x35
603 union {
604 // uint8_t MARCSTATE;
605 struct {
606 uint8_t MARC_STATE : 5; // State
607 uint8_t : 3;
608 };
609 };
610 // 0x36
611 uint8_t WORTIME1;
612 // 0x37
613 uint8_t WORTIME0;
614 // 0x38
615 union {
616 uint8_t PKTSTATUS;
617 struct {
618 uint8_t GDO0 : 1;
619 uint8_t : 1;
620 uint8_t GDO2 : 1;
621 uint8_t SFD : 1;
622 uint8_t CCA : 1;
623 uint8_t PQT_REACHED : 1;
624 uint8_t CS : 1;
625 uint8_t CRC_OK : 1; // same as LQI_CRC_OK?
626 };
627 };
628 // 0x39
629 uint8_t VCO_VC_DAC;
630 // 0x3A
631 union {
632 uint8_t TXBYTES;
633 struct {
634 uint8_t NUM_TXBYTES : 7;
635 uint8_t TXFIFO_UNDERFLOW : 1;
636 };
637 };
638 // 0x3B
639 union {
640 uint8_t RXBYTES;
641 struct {
642 uint8_t NUM_RXBYTES : 7;
643 uint8_t RXFIFO_OVERFLOW : 1;
644 };
645 };
646 // 0x3C
647 union {
648 // uint8_t RCCTRL1_STATUS;
649 struct {
650 uint8_t RCCTRL1_STATUS : 7;
651 uint8_t : 1;
652 };
653 };
654 // 0x3D
655 union {
656 // uint8_t RCCTRL0_STATUS;
657 struct {
658 uint8_t RCCTRL0_STATUS : 7;
659 uint8_t : 1;
660 };
661 };
662 // 0x3E
663 uint8_t REG_3E;
664 // 0x3F
665 uint8_t REG_3F;
666};
667
668static_assert(sizeof(CC1101State) == 0x40, "CC1101State size mismatch");
669
670} // namespace esphome::cc1101
struct @65::@66 __attribute__