summaryrefslogtreecommitdiffstats
path: root/martin/door/src/cc1101.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-03-17 12:18:56 +0100
committermanuel <manuel@mausz.at>2020-03-17 12:18:56 +0100
commit0553b9907f912e56a2cd2a08b03a83ce6f2a75c6 (patch)
tree45ed1908a50168f8420f13866cfd68386d0f2c78 /martin/door/src/cc1101.h
parentf0ecb4d38fff522c72905a8551355ca925381fa3 (diff)
downloadarduino-0553b9907f912e56a2cd2a08b03a83ce6f2a75c6.tar.gz
arduino-0553b9907f912e56a2cd2a08b03a83ce6f2a75c6.tar.bz2
arduino-0553b9907f912e56a2cd2a08b03a83ce6f2a75c6.zip
Add martin/door
Diffstat (limited to 'martin/door/src/cc1101.h')
-rw-r--r--martin/door/src/cc1101.h158
1 files changed, 158 insertions, 0 deletions
diff --git a/martin/door/src/cc1101.h b/martin/door/src/cc1101.h
new file mode 100644
index 0000000..04d828e
--- /dev/null
+++ b/martin/door/src/cc1101.h
@@ -0,0 +1,158 @@
1#pragma once
2
3class CC1101
4{
5 public:
6 enum ISM_FREQ
7 {
8 FREQ_315MHZ,
9 FREQ_434MHZ,
10 FREQ_868MHZ,
11 FREQ_915MHZ,
12 //FREQ_2430MHZ,
13 };
14
15 CC1101(uint8_t gdo0, uint8_t gdo2, uint8_t ss)
16 : _gdo0(gdo0), _gdo2(gdo2), _ss(ss)
17 {}
18 ~CC1101();
19#if !defined(LINUX_ARCH_RASPBERRYPI)
20 void set_spi_pins(uint8_t mosi = MOSI, uint8_t miso = MISO, uint8_t sck = SCK);
21#endif
22 bool setup();
23 bool setISM(ISM_FREQ ism_freq);
24 bool register_check();
25 bool transmit();
26 void setGDO0(int value);
27 bool receive();
28 void wakeup(void);
29 void powerdown(void);
30 void idle();
31 void reset(void);
32
33 private:
34 enum Strobe
35 : uint8_t
36 {
37 SRES = 0x30, // Reset chip
38 SFSTXON = 0x31, // Enable/calibrate freq synthesizer
39 SXOFF = 0x32, // Turn off crystal oscillator
40 SCAL = 0x33, // Calibrate freq synthesizer & disable
41 SRX = 0x34, // Enable RX
42 STX = 0x35, // Enable TX
43 SIDLE = 0x36, // Exit RX / TX
44 SAFC = 0x37, // AFC adjustment of freq synthesizer
45 SWOR = 0x38, // Start automatic RX polling sequence
46 SPWD = 0x39, // Enter pwr down mode when CSn goes hi
47 SFRX = 0x3A, // Flush the RX FIFO buffer
48 SFTX = 0x3A, // Flush the TX FIFO buffer
49 SWORRST = 0x3B, // Reset real time clock
50 SNOP = 0x3C, // No operation
51 };
52
53 enum SPI_RW
54 : uint8_t
55 {
56 WRITE_SINGLE_BYTE = 0x00,
57 WRITE_BURST = 0x40,
58 READ_SINGLE_BYTE = 0x80,
59 READ_BURST = 0xC0,
60 TXFIFO_BURST = 0x7F, // write burst only
61 TXFIFO_SINGLE_BYTE = 0x3F, // write single only
62 RXFIFO_BURST = 0xFF, // read burst only
63 RXFIFO_SINGLE_BYTE = 0xBF, // read single only
64 PATABLE_BURST = 0x7E, // power control read/write
65 PATABLE_SINGLE_BYTE = 0xFE, // power control read/write
66 };
67
68 enum Register
69 : uint8_t
70 {
71 IOCFG2 = 0x00, // GDO2 output pin configuration
72 IOCFG1 = 0x01, // GDO1 output pin configuration
73 IOCFG0 = 0x02, // GDO0 output pin configuration
74 FIFOTHR = 0x03, // RX FIFO and TX FIFO thresholds
75 SYNC1 = 0x04, // Sync word, high byte
76 SYNC0 = 0x05, // Sync word, low byte
77 PKTLEN = 0x06, // Packet length
78 PKTCTRL1 = 0x07, // Packet automation control
79 PKTCTRL0 = 0x08, // Packet automation control
80 ADDR = 0x09, // Device address
81 CHANNR = 0x0A, // Channel number
82 FSCTRL1 = 0x0B, // Frequency synthesizer control
83 FSCTRL0 = 0x0C, // Frequency synthesizer control
84 FREQ2 = 0x0D, // Frequency control word, high byte
85 FREQ1 = 0x0E, // Frequency control word, middle byte
86 FREQ0 = 0x0F, // Frequency control word, low byte
87 MDMCFG4 = 0x10, // Modem configuration
88 MDMCFG3 = 0x11, // Modem configuration
89 MDMCFG2 = 0x12, // Modem configuration
90 MDMCFG1 = 0x13, // Modem configuration
91 MDMCFG0 = 0x14, // Modem configuration
92 DEVIATN = 0x15, // Modem deviation setting
93 MCSM2 = 0x16, // Main Radio Cntrl State Machine config
94 MCSM1 = 0x17, // Main Radio Cntrl State Machine config
95 MCSM0 = 0x18, // Main Radio Cntrl State Machine config
96 FOCCFG = 0x19, // Frequency Offset Compensation config
97 BSCFG = 0x1A, // Bit Synchronization configuration
98 AGCCTRL2 = 0x1B, // AGC control
99 AGCCTRL1 = 0x1C, // AGC control
100 AGCCTRL0 = 0x1D, // AGC control
101 WOREVT1 = 0x1E, // High byte Event 0 timeout
102 WOREVT0 = 0x1F, // Low byte Event 0 timeout
103 WORCTRL = 0x20, // Wake On Radio control
104 FREND1 = 0x21, // Front end RX configuration
105 FREND0 = 0x22, // Front end TX configuration
106 FSCAL3 = 0x23, // Frequency synthesizer calibration
107 FSCAL2 = 0x24, // Frequency synthesizer calibration
108 FSCAL1 = 0x25, // Frequency synthesizer calibration
109 FSCAL0 = 0x26, // Frequency synthesizer calibration
110 RCCTRL1 = 0x27, // RC oscillator configuration
111 RCCTRL0 = 0x28, // RC oscillator configuration
112 FSTEST = 0x29, // Frequency synthesizer cal control
113 PTEST = 0x2A, // Production test
114 AGCTEST = 0x2B, // AGC test
115 TEST2 = 0x2C, // Various test settings
116 TEST1 = 0x2D, // Various test settings
117 TEST0 = 0x2E, // Various test settings
118
119 PARTNUM = 0xF0, // Part number
120 VERSION = 0xF1, // Current version number
121 FREQEST = 0xF2, // Frequency offset estimate
122 LQI = 0xF3, // Demodulator estimate for link quality
123 RSSI = 0xF4, // Received signal strength indication
124 MARCSTATE = 0xF5, // Control state machine state
125 WORTIME1 = 0xF6, // High byte of WOR timer
126 WORTIME0 = 0xF7, // Low byte of WOR timer
127 PKTSTATUS = 0xF8, // Current GDOx status and packet status
128 VCO_VC_DAC = 0xF9, // Current setting from PLL cal module
129 TXBYTES = 0xFA, // Underflow and # of bytes in TXFIFO
130 RXBYTES = 0xFB, // Overflow and # of bytes in RXFIFO
131 RCCTRL1_STATUS = 0xFC, // Last RC Oscillator Calibration Result
132 RCCTRL0_STATUS = 0xFD, // Last RC Oscillator Calibration Result
133 };
134
135 bool spi_begin();
136#if !defined(LINUX_ARCH_RASPBERRYPI)
137 void select();
138 void deselect();
139 bool wait_MISO();
140 uint8_t spi_putc(const uint8_t value);
141#endif
142 void spi_write_register(Register spi_instr, uint8_t value);
143 uint8_t spi_read_register(Register spi_instr);
144 uint8_t spi_write_strobe(Strobe spi_instr);
145 void spi_read_burst(SPI_RW spi_instr, uint8_t *pArr, uint8_t len);
146 void spi_write_burst(SPI_RW spi_instr, const uint8_t *pArr, uint8_t len);
147
148 private:
149 uint8_t _gdo0;
150 uint8_t _gdo2;
151 uint8_t _ss;
152 bool _init_done = false;
153#if !defined(LINUX_ARCH_RASPBERRYPI)
154 uint8_t _mosi = MOSI;
155 uint8_t _miso = MISO;
156 uint8_t _sck = SCK;
157#endif
158};