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