upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
rf22.hpp
1 /*
2  * Author: Kiveisha Yevgeniy
3  * Copyright (c) 2015-2016 Intel Corporation
4  *
5  * Author: Mike McCauley
6  * Copyright (c) 2011 Mike McCauley
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 
28 #pragma once
29 
30 #include <stdint.h>
31 #include <mraa.h>
32 
33 // This is the bit in the SPI address that marks it as a write
34 #define RF22_SPI_WRITE_MASK 0x80
35 
36 // This is the maximum message length that can be supported by this library. Limited by
37 // the single message length octet in the header.
38 // Yes, 255 is correct even though the FIFO size in the RF22 is only
39 // 64 octets. We use interrupts to refill the Tx FIFO during transmission and to empty the
40 // Rx FIFO during reception
41 // Can be pre-defined to a smaller size (to save SRAM) prior to including this header
42 #ifndef RF22_MAX_MESSAGE_LEN
43 //#define RF22_MAX_MESSAGE_LEN 255
44 #define RF22_MAX_MESSAGE_LEN 64
45 #endif
46 
47 // Max number of octets the RF22 Rx and Tx FIFOs can hold
48 #define RF22_FIFO_SIZE 64
49 
50 // Keep track of the mode the RF22 is in
51 #define RF22_MODE_IDLE 0
52 #define RF22_MODE_RX 1
53 #define RF22_MODE_TX 2
54 
55 // These values we set for FIFO thresholds are actually the same as the POR values
56 #define RF22_TXFFAEM_THRESHOLD 4
57 #define RF22_RXFFAFULL_THRESHOLD 55
58 
59 // This is the default node address,
60 #define RF22_DEFAULT_NODE_ADDRESS 0
61 
62 // This address in the TO address signifies a broadcast
63 #define RF22_BROADCAST_ADDRESS 0xff
64 
65 // Number of registers to be passed to setModemConfig()
66 #define RF22_NUM_MODEM_CONFIG_REGS 18
67 
68 // Register names
69 #define RF22_REG_00_DEVICE_TYPE 0x00
70 #define RF22_REG_01_VERSION_CODE 0x01
71 #define RF22_REG_02_DEVICE_STATUS 0x02
72 #define RF22_REG_03_INTERRUPT_STATUS1 0x03
73 #define RF22_REG_04_INTERRUPT_STATUS2 0x04
74 #define RF22_REG_05_INTERRUPT_ENABLE1 0x05
75 #define RF22_REG_06_INTERRUPT_ENABLE2 0x06
76 #define RF22_REG_07_OPERATING_MODE1 0x07
77 #define RF22_REG_08_OPERATING_MODE2 0x08
78 #define RF22_REG_09_OSCILLATOR_LOAD_CAPACITANCE 0x09
79 #define RF22_REG_0A_UC_OUTPUT_CLOCK 0x0a
80 #define RF22_REG_0B_GPIO_CONFIGURATION0 0x0b
81 #define RF22_REG_0C_GPIO_CONFIGURATION1 0x0c
82 #define RF22_REG_0D_GPIO_CONFIGURATION2 0x0d
83 #define RF22_REG_0E_IO_PORT_CONFIGURATION 0x0e
84 #define RF22_REG_0F_ADC_CONFIGURATION 0x0f
85 #define RF22_REG_10_ADC_SENSOR_AMP_OFFSET 0x10
86 #define RF22_REG_11_ADC_VALUE 0x11
87 #define RF22_REG_12_TEMPERATURE_SENSOR_CALIBRATION 0x12
88 #define RF22_REG_13_TEMPERATURE_VALUE_OFFSET 0x13
89 #define RF22_REG_14_WAKEUP_TIMER_PERIOD1 0x14
90 #define RF22_REG_15_WAKEUP_TIMER_PERIOD2 0x15
91 #define RF22_REG_16_WAKEUP_TIMER_PERIOD3 0x16
92 #define RF22_REG_17_WAKEUP_TIMER_VALUE1 0x17
93 #define RF22_REG_18_WAKEUP_TIMER_VALUE2 0x18
94 #define RF22_REG_19_LDC_MODE_DURATION 0x19
95 #define RF22_REG_1A_LOW_BATTERY_DETECTOR_THRESHOLD 0x1a
96 #define RF22_REG_1B_BATTERY_VOLTAGE_LEVEL 0x1b
97 #define RF22_REG_1C_IF_FILTER_BANDWIDTH 0x1c
98 #define RF22_REG_1D_AFC_LOOP_GEARSHIFT_OVERRIDE 0x1d
99 #define RF22_REG_1E_AFC_TIMING_CONTROL 0x1e
100 #define RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE 0x1f
101 #define RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE 0x20
102 #define RF22_REG_21_CLOCK_RECOVERY_OFFSET2 0x21
103 #define RF22_REG_22_CLOCK_RECOVERY_OFFSET1 0x22
104 #define RF22_REG_23_CLOCK_RECOVERY_OFFSET0 0x23
105 #define RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1 0x24
106 #define RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0 0x25
107 #define RF22_REG_26_RSSI 0x26
108 #define RF22_REG_27_RSSI_THRESHOLD 0x27
109 #define RF22_REG_28_ANTENNA_DIVERSITY1 0x28
110 #define RF22_REG_29_ANTENNA_DIVERSITY2 0x29
111 #define RF22_REG_2A_AFC_LIMITER 0x2a
112 #define RF22_REG_2B_AFC_CORRECTION_READ 0x2b
113 #define RF22_REG_2C_OOK_COUNTER_VALUE_1 0x2c
114 #define RF22_REG_2D_OOK_COUNTER_VALUE_2 0x2d
115 #define RF22_REG_2E_SLICER_PEAK_HOLD 0x2e
116 #define RF22_REG_30_DATA_ACCESS_CONTROL 0x30
117 #define RF22_REG_31_EZMAC_STATUS 0x31
118 #define RF22_REG_32_HEADER_CONTROL1 0x32
119 #define RF22_REG_33_HEADER_CONTROL2 0x33
120 #define RF22_REG_34_PREAMBLE_LENGTH 0x34
121 #define RF22_REG_35_PREAMBLE_DETECTION_CONTROL1 0x35
122 #define RF22_REG_36_SYNC_WORD3 0x36
123 #define RF22_REG_37_SYNC_WORD2 0x37
124 #define RF22_REG_38_SYNC_WORD1 0x38
125 #define RF22_REG_39_SYNC_WORD0 0x39
126 #define RF22_REG_3A_TRANSMIT_HEADER3 0x3a
127 #define RF22_REG_3B_TRANSMIT_HEADER2 0x3b
128 #define RF22_REG_3C_TRANSMIT_HEADER1 0x3c
129 #define RF22_REG_3D_TRANSMIT_HEADER0 0x3d
130 #define RF22_REG_3E_PACKET_LENGTH 0x3e
131 #define RF22_REG_3F_CHECK_HEADER3 0x3f
132 #define RF22_REG_40_CHECK_HEADER2 0x40
133 #define RF22_REG_41_CHECK_HEADER1 0x41
134 #define RF22_REG_42_CHECK_HEADER0 0x42
135 #define RF22_REG_43_HEADER_ENABLE3 0x43
136 #define RF22_REG_44_HEADER_ENABLE2 0x44
137 #define RF22_REG_45_HEADER_ENABLE1 0x45
138 #define RF22_REG_46_HEADER_ENABLE0 0x46
139 #define RF22_REG_47_RECEIVED_HEADER3 0x47
140 #define RF22_REG_48_RECEIVED_HEADER2 0x48
141 #define RF22_REG_49_RECEIVED_HEADER1 0x49
142 #define RF22_REG_4A_RECEIVED_HEADER0 0x4a
143 #define RF22_REG_4B_RECEIVED_PACKET_LENGTH 0x4b
144 #define RF22_REG_50_ANALOG_TEST_BUS_SELECT 0x50
145 #define RF22_REG_51_DIGITAL_TEST_BUS_SELECT 0x51
146 #define RF22_REG_52_TX_RAMP_CONTROL 0x52
147 #define RF22_REG_53_PLL_TUNE_TIME 0x53
148 #define RF22_REG_55_CALIBRATION_CONTROL 0x55
149 #define RF22_REG_56_MODEM_TEST 0x56
150 #define RF22_REG_57_CHARGE_PUMP_TEST 0x57
151 #define RF22_REG_58_CHARGE_PUMP_CURRENT_TRIMMING 0x58
152 #define RF22_REG_59_DIVIDER_CURRENT_TRIMMING 0x59
153 #define RF22_REG_5A_VCO_CURRENT_TRIMMING 0x5a
154 #define RF22_REG_5B_VCO_CALIBRATION 0x5b
155 #define RF22_REG_5C_SYNTHESIZER_TEST 0x5c
156 #define RF22_REG_5D_BLOCK_ENABLE_OVERRIDE1 0x5d
157 #define RF22_REG_5E_BLOCK_ENABLE_OVERRIDE2 0x5e
158 #define RF22_REG_5F_BLOCK_ENABLE_OVERRIDE3 0x5f
159 #define RF22_REG_60_CHANNEL_FILTER_COEFFICIENT_ADDRESS 0x60
160 #define RF22_REG_61_CHANNEL_FILTER_COEFFICIENT_VALUE 0x61
161 #define RF22_REG_62_CRYSTAL_OSCILLATOR_POR_CONTROL 0x62
162 #define RF22_REG_63_RC_OSCILLATOR_COARSE_CALIBRATION 0x63
163 #define RF22_REG_64_RC_OSCILLATOR_FINE_CALIBRATION 0x64
164 #define RF22_REG_65_LDO_CONTROL_OVERRIDE 0x65
165 #define RF22_REG_66_LDO_LEVEL_SETTINGS 0x66
166 #define RF22_REG_67_DELTA_SIGMA_ADC_TUNING1 0x67
167 #define RF22_REG_68_DELTA_SIGMA_ADC_TUNING2 0x68
168 #define RF22_REG_69_AGC_OVERRIDE1 0x69
169 #define RF22_REG_6A_AGC_OVERRIDE2 0x6a
170 #define RF22_REG_6B_GFSK_FIR_FILTER_COEFFICIENT_ADDRESS 0x6b
171 #define RF22_REG_6C_GFSK_FIR_FILTER_COEFFICIENT_VALUE 0x6c
172 #define RF22_REG_6D_TX_POWER 0x6d
173 #define RF22_REG_6E_TX_DATA_RATE1 0x6e
174 #define RF22_REG_6F_TX_DATA_RATE0 0x6f
175 #define RF22_REG_70_MODULATION_CONTROL1 0x70
176 #define RF22_REG_71_MODULATION_CONTROL2 0x71
177 #define RF22_REG_72_FREQUENCY_DEVIATION 0x72
178 #define RF22_REG_73_FREQUENCY_OFFSET1 0x73
179 #define RF22_REG_74_FREQUENCY_OFFSET2 0x74
180 #define RF22_REG_75_FREQUENCY_BAND_SELECT 0x75
181 #define RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1 0x76
182 #define RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0 0x77
183 #define RF22_REG_79_FREQUENCY_HOPPING_CHANNEL_SELECT 0x79
184 #define RF22_REG_7A_FREQUENCY_HOPPING_STEP_SIZE 0x7a
185 #define RF22_REG_7C_TX_FIFO_CONTROL1 0x7c
186 #define RF22_REG_7D_TX_FIFO_CONTROL2 0x7d
187 #define RF22_REG_7E_RX_FIFO_CONTROL 0x7e
188 #define RF22_REG_7F_FIFO_ACCESS 0x7f
189 
190 // These register masks etc are named wherever possible
191 // corresponding to the bit and field names in the RF-22 Manual
192 // RF22_REG_00_DEVICE_TYPE 0x00
193 #define RF22_DEVICE_TYPE_RX_TRX 0x08
194 #define RF22_DEVICE_TYPE_TX 0x07
195 
196 // RF22_REG_02_DEVICE_STATUS 0x02
197 #define RF22_FFOVL 0x80
198 #define RF22_FFUNFL 0x40
199 #define RF22_RXFFEM 0x20
200 #define RF22_HEADERR 0x10
201 #define RF22_FREQERR 0x08
202 #define RF22_LOCKDET 0x04
203 #define RF22_CPS 0x03
204 #define RF22_CPS_IDLE 0x00
205 #define RF22_CPS_RX 0x01
206 #define RF22_CPS_TX 0x10
207 
208 // RF22_REG_03_INTERRUPT_STATUS1 0x03
209 #define RF22_IFFERROR 0x80
210 #define RF22_ITXFFAFULL 0x40
211 #define RF22_ITXFFAEM 0x20
212 #define RF22_IRXFFAFULL 0x10
213 #define RF22_IEXT 0x08
214 #define RF22_IPKSENT 0x04
215 #define RF22_IPKVALID 0x02
216 #define RF22_ICRCERROR 0x01
217 
218 // RF22_REG_04_INTERRUPT_STATUS2 0x04
219 #define RF22_ISWDET 0x80
220 #define RF22_IPREAVAL 0x40
221 #define RF22_IPREAINVAL 0x20
222 #define RF22_IRSSI 0x10
223 #define RF22_IWUT 0x08
224 #define RF22_ILBD 0x04
225 #define RF22_ICHIPRDY 0x02
226 #define RF22_IPOR 0x01
227 
228 // RF22_REG_05_INTERRUPT_ENABLE1 0x05
229 #define RF22_ENFFERR 0x80
230 #define RF22_ENTXFFAFULL 0x40
231 #define RF22_ENTXFFAEM 0x20
232 #define RF22_ENRXFFAFULL 0x10
233 #define RF22_ENEXT 0x08
234 #define RF22_ENPKSENT 0x04
235 #define RF22_ENPKVALID 0x02
236 #define RF22_ENCRCERROR 0x01
237 
238 // RF22_REG_06_INTERRUPT_ENABLE2 0x06
239 #define RF22_ENSWDET 0x80
240 #define RF22_ENPREAVAL 0x40
241 #define RF22_ENPREAINVAL 0x20
242 #define RF22_ENRSSI 0x10
243 #define RF22_ENWUT 0x08
244 #define RF22_ENLBDI 0x04
245 #define RF22_ENCHIPRDY 0x02
246 #define RF22_ENPOR 0x01
247 
248 // RF22_REG_07_OPERATING_MODE 0x07
249 #define RF22_SWRES 0x80
250 #define RF22_ENLBD 0x40
251 #define RF22_ENWT 0x20
252 #define RF22_X32KSEL 0x10
253 #define RF22_TXON 0x08
254 #define RF22_RXON 0x04
255 #define RF22_PLLON 0x02
256 #define RF22_XTON 0x01
257 
258 // RF22_REG_08_OPERATING_MODE2 0x08
259 #define RF22_ANTDIV 0xc0
260 #define RF22_RXMPK 0x10
261 #define RF22_AUTOTX 0x08
262 #define RF22_ENLDM 0x04
263 #define RF22_FFCLRRX 0x02
264 #define RF22_FFCLRTX 0x01
265 
266 // RF22_REG_0F_ADC_CONFIGURATION 0x0f
267 #define RF22_ADCSTART 0x80
268 #define RF22_ADCDONE 0x80
269 #define RF22_ADCSEL 0x70
270 #define RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR 0x00
271 #define RF22_ADCSEL_GPIO0_SINGLE_ENDED 0x10
272 #define RF22_ADCSEL_GPIO1_SINGLE_ENDED 0x20
273 #define RF22_ADCSEL_GPIO2_SINGLE_ENDED 0x30
274 #define RF22_ADCSEL_GPIO0_GPIO1_DIFFERENTIAL 0x40
275 #define RF22_ADCSEL_GPIO1_GPIO2_DIFFERENTIAL 0x50
276 #define RF22_ADCSEL_GPIO0_GPIO2_DIFFERENTIAL 0x60
277 #define RF22_ADCSEL_GND 0x70
278 #define RF22_ADCREF 0x0c
279 #define RF22_ADCREF_BANDGAP_VOLTAGE 0x00
280 #define RF22_ADCREF_VDD_ON_3 0x08
281 #define RF22_ADCREF_VDD_ON_2 0x0c
282 #define RF22_ADCGAIN 0x03
283 
284 // RF22_REG_10_ADC_SENSOR_AMP_OFFSET 0x10
285 #define RF22_ADCOFFS 0x0f
286 
287 // RF22_REG_12_TEMPERATURE_SENSOR_CALIBRATION 0x12
288 #define RF22_TSRANGE 0xc0
289 #define RF22_TSRANGE_M64_64C 0x00
290 #define RF22_TSRANGE_M64_192C 0x40
291 #define RF22_TSRANGE_0_128C 0x80
292 #define RF22_TSRANGE_M40_216F 0xc0
293 #define RF22_ENTSOFFS 0x20
294 #define RF22_ENTSTRIM 0x10
295 #define RF22_TSTRIM 0x0f
296 
297 // RF22_REG_14_WAKEUP_TIMER_PERIOD1 0x14
298 #define RF22_WTR 0x3c
299 #define RF22_WTD 0x03
300 
301 // RF22_REG_1D_AFC_LOOP_GEARSHIFT_OVERRIDE 0x1d
302 #define RF22_AFBCD 0x80
303 #define RF22_ENAFC 0x40
304 #define RF22_AFCGEARH 0x38
305 #define RF22_AFCGEARL 0x07
306 
307 // RF22_REG_1E_AFC_TIMING_CONTROL 0x1e
308 #define RF22_SWAIT_TIMER 0xc0
309 #define RF22_SHWAIT 0x38
310 #define RF22_ANWAIT 0x07
311 
312 // RF22_REG_30_DATA_ACCESS_CONTROL 0x30
313 #define RF22_ENPACRX 0x80
314 #define RF22_MSBFRST 0x00
315 #define RF22_LSBFRST 0x40
316 #define RF22_CRCHDRS 0x00
317 #define RF22_CRCDONLY 0x20
318 #define RF22_ENPACTX 0x08
319 #define RF22_ENCRC 0x04
320 #define RF22_CRC 0x03
321 #define RF22_CRC_CCITT 0x00
322 #define RF22_CRC_CRC_16_IBM 0x01
323 #define RF22_CRC_IEC_16 0x02
324 #define RF22_CRC_BIACHEVA 0x03
325 
326 // RF22_REG_32_HEADER_CONTROL1 0x32
327 #define RF22_BCEN 0xf0
328 #define RF22_BCEN_NONE 0x00
329 #define RF22_BCEN_HEADER0 0x10
330 #define RF22_BCEN_HEADER1 0x20
331 #define RF22_BCEN_HEADER2 0x40
332 #define RF22_BCEN_HEADER3 0x80
333 #define RF22_HDCH 0x0f
334 #define RF22_HDCH_NONE 0x00
335 #define RF22_HDCH_HEADER0 0x01
336 #define RF22_HDCH_HEADER1 0x02
337 #define RF22_HDCH_HEADER2 0x04
338 #define RF22_HDCH_HEADER3 0x08
339 
340 // RF22_REG_33_HEADER_CONTROL2 0x33
341 #define RF22_HDLEN 0x70
342 #define RF22_HDLEN_0 0x00
343 #define RF22_HDLEN_1 0x10
344 #define RF22_HDLEN_2 0x20
345 #define RF22_HDLEN_3 0x30
346 #define RF22_HDLEN_4 0x40
347 #define RF22_VARPKLEN 0x00
348 #define RF22_FIXPKLEN 0x08
349 #define RF22_SYNCLEN 0x06
350 #define RF22_SYNCLEN_1 0x00
351 #define RF22_SYNCLEN_2 0x02
352 #define RF22_SYNCLEN_3 0x04
353 #define RF22_SYNCLEN_4 0x06
354 #define RF22_PREALEN8 0x01
355 
356 // RF22_REG_6D_TX_POWER 0x6d
357 #define RF22_TXPOW 0x07
358 #define RF22_TXPOW_4X31 0x08 // Not used in RFM22B
359 #define RF22_TXPOW_1DBM 0x00
360 #define RF22_TXPOW_2DBM 0x01
361 #define RF22_TXPOW_5DBM 0x02
362 #define RF22_TXPOW_8DBM 0x03
363 #define RF22_TXPOW_11DBM 0x04
364 #define RF22_TXPOW_14DBM 0x05
365 #define RF22_TXPOW_17DBM 0x06
366 #define RF22_TXPOW_20DBM 0x07
367 // IN RFM23B
368 #define RF22_TXPOW_LNA_SW 0x08
369 
370 // RF22_REG_71_MODULATION_CONTROL2 0x71
371 #define RF22_TRCLK 0xc0
372 #define RF22_TRCLK_NONE 0x00
373 #define RF22_TRCLK_GPIO 0x40
374 #define RF22_TRCLK_SDO 0x80
375 #define RF22_TRCLK_NIRQ 0xc0
376 #define RF22_DTMOD 0x30
377 #define RF22_DTMOD_DIRECT_GPIO 0x00
378 #define RF22_DTMOD_DIRECT_SDI 0x10
379 #define RF22_DTMOD_FIFO 0x20
380 #define RF22_DTMOD_PN9 0x30
381 #define RF22_ENINV 0x08
382 #define RF22_FD8 0x04
383 #define RF22_MODTYP 0x30
384 #define RF22_MODTYP_UNMODULATED 0x00
385 #define RF22_MODTYP_OOK 0x01
386 #define RF22_MODTYP_FSK 0x02
387 #define RF22_MODTYP_GFSK 0x03
388 
389 // RF22_REG_75_FREQUENCY_BAND_SELECT 0x75
390 #define RF22_SBSEL 0x40
391 #define RF22_HBSEL 0x20
392 #define RF22_FB 0x1f
393 
394 // Define this to include Serial printing in diagnostic routines
395 #define RF22_HAVE_SERIAL
396 
397 namespace upm {
398 
439 class RF22
440 {
441 public:
442 
454  typedef struct
455  {
456  uint8_t reg_1c;
457  uint8_t reg_1f;
458  uint8_t reg_20;
459  uint8_t reg_21;
460  uint8_t reg_22;
461  uint8_t reg_23;
462  uint8_t reg_24;
463  uint8_t reg_25;
464  uint8_t reg_2c;
465  uint8_t reg_2d;
466  uint8_t reg_2e;
467  uint8_t reg_58;
468  uint8_t reg_69;
469  uint8_t reg_6e;
470  uint8_t reg_6f;
471  uint8_t reg_70;
472  uint8_t reg_71;
473  uint8_t reg_72;
474  } ModemConfig;
475 
482  typedef enum
483  {
486 
495 
504 
513 
524  RF22(int spiBus = 0, int slaveSelectPin = 10, int interruptPin = 2);
525 
529  virtual ~RF22();
530 
541  uint8_t init();
542 
547  void reset();
548 
554  uint8_t spiRead(uint8_t reg);
555 
561  void spiWrite(uint8_t reg, uint8_t val);
562 
569  void spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len);
570 
577  void spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len);
578 
583  uint8_t statusRead();
584 
595  uint8_t adcRead(uint8_t adcsel = RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR,
596  uint8_t adcref = RF22_ADCREF_BANDGAP_VOLTAGE,
597  uint8_t adcgain = 0,
598  uint8_t adcoffs = 0);
599 
607  uint8_t temperatureRead(uint8_t tsrange = RF22_TSRANGE_M64_64C, uint8_t tvoffs = 0);
608 
614  uint16_t wutRead();
615 
623  void setWutPeriod(uint16_t wtm, uint8_t wtr = 0, uint8_t wtd = 0);
624 
633  uint8_t setFrequency(float center, float afcPullInRange = 0.05);
634 
640  uint8_t setFHStepSize(uint8_t fhs);
641 
647  uint8_t setFHChannel(uint8_t fhch);
648 
654  uint8_t rssiRead();
655 
660  uint8_t ezmacStatusRead();
661 
669  void setMode(uint8_t mode);
670 
675  void setModeIdle();
676 
681  void setModeRx();
682 
687  void setModeTx();
688 
693  uint8_t mode();
694 
703  void setTxPower(uint8_t power);
704 
711  void setModemRegisters(const ModemConfig* config);
712 
719  uint8_t setModemConfig(ModemConfigChoice index);
720 
727  uint8_t available();
728 
733  void waitAvailable();
734 
740  bool waitAvailableTimeout(unsigned long timeout);
741 
753  uint8_t recv(uint8_t* buf, uint8_t* len);
754 
763  uint8_t send(const uint8_t* data, uint8_t len);
764 
769  void waitPacketSent();
770 
776  void setPromiscuous(uint8_t promiscuous);
777 
782  uint8_t headerTo();
783 
788  uint8_t headerFrom();
789 
794  uint8_t headerId();
795 
800  uint8_t headerFlags();
801 
808  uint8_t lastRssi();
809 
817  static void printBuffer(const char* prompt, const uint8_t* buf, uint8_t len);
818 
827  void setPreambleLength(uint8_t nibbles);
828 
837  void setSyncWords(const uint8_t* syncWords, uint8_t len);
838 
839 protected:
844  void handleInterrupt();
845 
850  void clearRxBuf();
851 
856  void clearTxBuf();
857 
864  uint8_t fillTxBuf(const uint8_t* data, uint8_t len);
865 
872  uint8_t appendTxBuf(const uint8_t* data, uint8_t len);
873 
879  void sendNextFragment();
880 
885  void readNextFragment();
886 
891  void resetFifos();
892 
897  void resetRxFifo();
898 
903  void resetTxFifo();
904 
911  virtual void handleExternalInterrupt();
912 
919  virtual void handleWakeupTimerInterrupt();
920 
925  void setHeaderTo(uint8_t to);
926 
931  void setHeaderFrom(uint8_t from);
932 
937  void setHeaderId(uint8_t id);
938 
943  void setHeaderFlags(uint8_t flags);
944 
949  void startTransmit();
950 
955  void restartTransmit();
956  uint64_t getTimestamp ();
957 
958 private:
962  static void isr(void* args);
963 
964  mraa_spi_context _spi;
965  mraa_gpio_context _cs;
966  mraa_gpio_context _irq;
967 
968  volatile uint8_t _mode; // One of RF22_MODE_*
969 
970  uint8_t _idleMode;
971  uint8_t _deviceType;
972 
973  // These volatile members may get changed in the interrupt service routine
974  volatile uint8_t _bufLen;
975  uint8_t _buf[RF22_MAX_MESSAGE_LEN];
976 
977  volatile uint8_t _rxBufValid;
978  volatile uint8_t _txBufSentIndex;
979 
980  volatile uint16_t _rxBad;
981  volatile uint16_t _rxGood;
982  volatile uint16_t _txGood;
983 
984  volatile uint8_t _lastRssi;
985 };
986 
987 }
void restartTransmit()
Definition: rf22.cxx:606
GFSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz.
Definition: rf22.hpp:497
void setHeaderFrom(uint8_t from)
Definition: rf22.cxx:706
uint8_t spiRead(uint8_t reg)
Definition: rf22.cxx:283
FSK, No Manchester, Rb = 57.6kbs, Fd = 28.8kHz.
Definition: rf22.hpp:493
FSK, No Manchester, Rb = 9.6kbs, Fd = 45kHz.
Definition: rf22.hpp:490
Defines register values for a set of modem configuration registers.
Definition: rf22.hpp:454
uint8_t fillTxBuf(const uint8_t *data, uint8_t len)
Definition: rf22.cxx:624
uint8_t headerFrom()
Definition: rf22.cxx:726
uint8_t reg_71
Value for register RF22_REG_71_MODULATION_CONTROL2.
Definition: rf22.hpp:472
uint8_t statusRead()
Definition: rf22.cxx:335
void spiBurstWrite(uint8_t reg, const uint8_t *src, uint8_t len)
Definition: rf22.cxx:316
void spiBurstRead(uint8_t reg, uint8_t *dest, uint8_t len)
Definition: rf22.cxx:295
uint8_t send(const uint8_t *data, uint8_t len)
Definition: rf22.cxx:613
uint8_t recv(uint8_t *buf, uint8_t *len)
Definition: rf22.cxx:580
uint8_t appendTxBuf(const uint8_t *data, uint8_t len)
Definition: rf22.cxx:632
GFSK, No Manchester, Rb = 19.2kbs, Fd = 9.6kHz.
Definition: rf22.hpp:500
uint8_t reg_2d
Value for register RF22_REG_2D_OOK_COUNTER_VALUE_2.
Definition: rf22.hpp:465
static void printBuffer(const char *prompt, const uint8_t *buf, uint8_t len)
Definition: rf22.cxx:576
void reset()
Definition: rf22.cxx:276
void setModeIdle()
Definition: rf22.cxx:452
RF22(int spiBus=0, int slaveSelectPin=10, int interruptPin=2)
Definition: rf22.cxx:78
uint8_t reg_21
Value for register RF22_REG_21_CLOCK_RECOVERY_OFFSET2.
Definition: rf22.hpp:459
uint8_t setModemConfig(ModemConfigChoice index)
Definition: rf22.cxx:508
void handleInterrupt()
Definition: rf22.cxx:188
void readNextFragment()
Definition: rf22.cxx:660
void setHeaderFlags(uint8_t flags)
Definition: rf22.cxx:716
FSK, No Manchester, Rb = 2kbs, Fd = 5kHz.
Definition: rf22.hpp:487
Unmodulated carrier for testing.
Definition: rf22.hpp:484
GFSK, No Manchester, Rb = 57.6kbs, Fd = 28.8kHz.
Definition: rf22.hpp:502
void spiWrite(uint8_t reg, uint8_t val)
Definition: rf22.cxx:290
uint8_t reg_69
Value for register RF22_REG_69_AGC_OVERRIDE1.
Definition: rf22.hpp:468
uint8_t reg_20
Value for register RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE.
Definition: rf22.hpp:458
void setTxPower(uint8_t power)
Definition: rf22.cxx:489
uint8_t setFHStepSize(uint8_t fhs)
Definition: rf22.cxx:423
void startTransmit()
Definition: rf22.cxx:598
void setModeTx()
Definition: rf22.cxx:470
uint8_t reg_2c
Value for register RF22_REG_2C_OOK_COUNTER_VALUE_1.
Definition: rf22.hpp:464
uint16_t wutRead()
Definition: rf22.cxx:364
uint8_t setFHChannel(uint8_t fhch)
Definition: rf22.cxx:431
void setWutPeriod(uint16_t wtm, uint8_t wtr=0, uint8_t wtd=0)
Definition: rf22.cxx:372
uint8_t headerId()
Definition: rf22.cxx:731
FSK, No Manchester, Rb = 38.4kbs, Fd = 19.6kHz.
Definition: rf22.hpp:492
ModemConfigChoice
Definition: rf22.hpp:482
void waitPacketSent()
Definition: rf22.cxx:569
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
uint8_t reg_23
Value for register RF22_REG_23_CLOCK_RECOVERY_OFFSET0.
Definition: rf22.hpp:461
FSK, No Manchester, Rb = 2kbs, Fd = 5kHz, PN9 random modulation for testing.
Definition: rf22.hpp:485
uint8_t temperatureRead(uint8_t tsrange=RF22_TSRANGE_M64_64C, uint8_t tvoffs=0)
Definition: rf22.cxx:357
uint8_t setFrequency(float center, float afcPullInRange=0.05)
Definition: rf22.cxx:385
OOK, No Manchester, Rb = 19.2kbs, Rx Bandwidth = 335kHz.
Definition: rf22.hpp:509
virtual void handleWakeupTimerInterrupt()
Definition: rf22.cxx:697
void resetRxFifo()
Definition: rf22.cxx:678
void setHeaderId(uint8_t id)
Definition: rf22.cxx:711
OOK, No Manchester, Rb = 38.4kbs, Rx Bandwidth = 335kHz.
Definition: rf22.hpp:510
void setPromiscuous(uint8_t promiscuous)
Definition: rf22.cxx:746
uint8_t init()
Definition: rf22.cxx:109
uint8_t reg_70
Value for register RF22_REG_70_MODULATION_CONTROL1.
Definition: rf22.hpp:471
OOK, No Manchester, Rb = 40kbs, Rx Bandwidth = 335kHz.
Definition: rf22.hpp:511
FSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz.
Definition: rf22.hpp:488
void setModemRegisters(const ModemConfig *config)
Definition: rf22.cxx:495
OOK, No Manchester, Rb = 1.2kbs, Rx Bandwidth = 75kHz.
Definition: rf22.hpp:505
GFSK, No Manchester, Rb = 2kbs, Fd = 5kHz.
Definition: rf22.hpp:496
void setSyncWords(const uint8_t *syncWords, uint8_t len)
Definition: rf22.cxx:528
void setPreambleLength(uint8_t nibbles)
Definition: rf22.cxx:522
void sendNextFragment()
Definition: rf22.cxx:644
uint8_t reg_24
Value for register RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1.
Definition: rf22.hpp:462
uint8_t headerFlags()
Definition: rf22.cxx:736
void resetTxFifo()
Definition: rf22.cxx:685
uint8_t reg_58
Value for register RF22_REG_58_CHARGE_PUMP_CURRENT_TRIMMING.
Definition: rf22.hpp:467
FSK, No Manchester, Rb = 4.8kbs, Fd = 45kHz.
Definition: rf22.hpp:489
uint8_t reg_72
Value for register RF22_REG_72_FREQUENCY_DEVIATION.
Definition: rf22.hpp:473
void setModeRx()
Definition: rf22.cxx:461
OOK, No Manchester, Rb = 2.4kbs, Rx Bandwidth = 335kHz.
Definition: rf22.hpp:506
uint8_t reg_22
Value for register RF22_REG_22_CLOCK_RECOVERY_OFFSET1.
Definition: rf22.hpp:460
void setHeaderTo(uint8_t to)
Definition: rf22.cxx:701
uint8_t mode()
Definition: rf22.cxx:484
FSK, No Manchester, Rb = 19.2kbs, Fd = 9.6kHz.
Definition: rf22.hpp:491
void resetFifos()
Definition: rf22.cxx:671
virtual void handleExternalInterrupt()
Definition: rf22.cxx:692
uint8_t ezmacStatusRead()
Definition: rf22.cxx:442
OOK, No Manchester, Rb = 9.6kbs, Rx Bandwidth = 335kHz.
Definition: rf22.hpp:508
uint8_t available()
Definition: rf22.cxx:539
uint8_t headerTo()
Definition: rf22.cxx:721
FSK, No Manchester, Rb = 125kbs, Fd = 125kHz.
Definition: rf22.hpp:494
void setMode(uint8_t mode)
Definition: rf22.cxx:447
void waitAvailable()
Definition: rf22.cxx:547
virtual ~RF22()
Definition: rf22.cxx:102
uint8_t rssiRead()
Definition: rf22.cxx:437
uint8_t reg_6e
Value for register RF22_REG_6E_TX_DATA_RATE1.
Definition: rf22.hpp:469
void clearRxBuf()
Definition: rf22.cxx:533
API for the RF22 Transceiver Module.
Definition: rf22.hpp:439
bool waitAvailableTimeout(unsigned long timeout)
Definition: rf22.cxx:555
uint8_t reg_1f
Value for register RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE.
Definition: rf22.hpp:457
void clearTxBuf()
Definition: rf22.cxx:592
GFSK, No Manchester, Rb = 4.8kbs, Fd = 45kHz.
Definition: rf22.hpp:498
uint8_t adcRead(uint8_t adcsel=RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR, uint8_t adcref=RF22_ADCREF_BANDGAP_VOLTAGE, uint8_t adcgain=0, uint8_t adcoffs=0)
Definition: rf22.cxx:340
uint8_t reg_1c
Value for register RF22_REG_1C_IF_FILTER_BANDWIDTH.
Definition: rf22.hpp:456
uint8_t reg_6f
Value for register RF22_REG_6F_TX_DATA_RATE0.
Definition: rf22.hpp:470
GFSK, No Manchester, Rb = 9.6kbs, Fd = 45kHz.
Definition: rf22.hpp:499
GFSK, No Manchester, Rb = 38.4kbs, Fd = 19.6kHz.
Definition: rf22.hpp:501
uint8_t reg_2e
Value for register RF22_REG_2E_SLICER_PEAK_HOLD.
Definition: rf22.hpp:466
GFSK, No Manchester, Rb = 125kbs, Fd = 125kHz.
Definition: rf22.hpp:503
uint8_t reg_25
Value for register RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0.
Definition: rf22.hpp:463
OOK, No Manchester, Rb = 4.8kbs, Rx Bandwidth = 335kHz.
Definition: rf22.hpp:507
uint8_t lastRssi()
Definition: rf22.cxx:741