PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

971 rinda
53KB

  1. // RadioHead.h
  2. // Author: Mike McCauley (mikem@airspayce.com) DO NOT CONTACT THE AUTHOR DIRECTLY
  3. // Copyright (C) 2014 Mike McCauley
  4. // $Id: RadioHead.h,v 1.56 2016/07/07 00:02:53 mikem Exp mikem $
  5. /// \mainpage RadioHead Packet Radio library for embedded microprocessors
  6. ///
  7. /// This is the RadioHead Packet Radio library for embedded microprocessors.
  8. /// It provides a complete object-oriented library for sending and receiving packetized messages
  9. /// via a variety of common data radios and other transports on a range of embedded microprocessors.
  10. ///
  11. /// The version of the package that this documentation refers to can be downloaded
  12. /// from http://www.airspayce.com/mikem/arduino/RadioHead/RadioHead-1.61.zip
  13. /// You can find the latest version at http://www.airspayce.com/mikem/arduino/RadioHead
  14. ///
  15. /// You can also find online help and discussion at
  16. /// http://groups.google.com/group/radiohead-arduino
  17. /// Please use that group for all questions and discussions on this topic.
  18. /// Do not contact the author directly, unless it is to discuss commercial licensing.
  19. /// Before asking a question or reporting a bug, please read
  20. /// - http://en.wikipedia.org/wiki/Wikipedia:Reference_desk/How_to_ask_a_software_question
  21. /// - http://www.catb.org/esr/faqs/smart-questions.html
  22. /// - http://www.chiark.greenend.org.uk/~shgtatham/bugs.html
  23. ///
  24. /// \par Overview
  25. ///
  26. /// RadioHead consists of 2 main sets of classes: Drivers and Managers.
  27. ///
  28. /// - Drivers provide low level access to a range of different packet radios and other packetized message transports.
  29. /// - Managers provide high level message sending and receiving facilities for a range of different requirements.
  30. ///
  31. /// Every RadioHead program will have an instance of a Driver to provide access to the data radio or transport,
  32. /// and a Manager that uses that driver to send and receive messages for the application. The programmer is required
  33. /// to instantiate a Driver and a Manager, and to initialise the Manager. Thereafter the facilities of the Manager
  34. /// can be used to send and receive messages.
  35. ///
  36. /// It is also possible to use a Driver on its own, without a Manager, although this only allows unaddressed,
  37. /// unreliable transport via the Driver's facilities.
  38. ///
  39. /// In some specialised use cases, it is possible to instantiate more than one Driver and more than one Manager.
  40. ///
  41. /// A range of different common embedded microprocessor platforms are supported, allowing your project to run
  42. /// on your choice of processor.
  43. ///
  44. /// Example programs are included to show the main modes of use.
  45. ///
  46. /// \par Drivers
  47. ///
  48. /// The following Drivers are provided:
  49. ///
  50. /// - RH_RF22
  51. /// Works with Hope-RF
  52. /// RF22B and RF23B based transceivers, and compatible chips and modules,
  53. /// including the RFM22B transceiver module such as
  54. /// this bare module: http://www.sparkfun.com/products/10153
  55. /// and this shield: http://www.sparkfun.com/products/11018
  56. /// and this board: http://www.anarduino.com/miniwireless
  57. /// and RF23BP modules such as: http://www.anarduino.com/details.jsp?pid=130
  58. /// Supports GFSK, FSK and OOK. Access to other chip
  59. /// features such as on-chip temperature measurement, analog-digital
  60. /// converter, transmitter power control etc is also provided.
  61. ///
  62. /// - RH_RF24
  63. /// Works with Silicon Labs Si4460/4461/4463/4464 family of transceivers chip, and the equivalent
  64. /// HopeRF RF24/26/27 family of chips and the HopeRF RFM24W/26W/27W modules.
  65. /// Supports GFSK, FSK and OOK. Access to other chip
  66. /// features such as on-chip temperature measurement, analog-digital
  67. /// converter, transmitter power control etc is also provided.
  68. ///
  69. /// - RH_RF69
  70. /// Works with Hope-RF
  71. /// RF69B based radio modules, such as the RFM69 module, (as used on the excellent Moteino and Moteino-USB
  72. /// boards from LowPowerLab http://lowpowerlab.com/moteino/ )
  73. /// and compatible chips and modules such as RFM69W, RFM69HW, RFM69CW, RFM69HCW (Semtech SX1231, SX1231H).
  74. /// Also works with Anarduino MiniWireless -CW and -HW boards http://www.anarduino.com/miniwireless/ including
  75. /// the marvellous high powered MinWireless-HW (with 20dBm output for excellent range).
  76. /// Supports GFSK, FSK.
  77. ///
  78. /// - RH_NRF24
  79. /// Works with Nordic nRF24 based 2.4GHz radio modules, such as nRF24L01 and others.
  80. /// Also works with Hope-RF RFM73
  81. /// and compatible devices (such as BK2423). nRF24L01 and RFM73 can interoperate
  82. /// with each other.
  83. ///
  84. /// - RH_NRF905
  85. /// Works with Nordic nRF905 based 433/868/915 MHz radio modules.
  86. ///
  87. /// - RH_NRF51
  88. /// Works with Nordic nRF51 compatible 2.4 GHz SoC/devices such as the nRF51822.
  89. ///
  90. /// - RH_RF95
  91. /// Works with Semtech SX1276/77/78/79, Modtronix inAir4 and inAir9,
  92. /// and HopeRF RFM95/96/97/98 and other similar LoRa capable radios.
  93. /// Supports Long Range (LoRa) with spread spectrum frequency hopping, large payloads etc.
  94. /// FSK/GFSK/OOK modes are not (yet) supported.
  95. ///
  96. /// - RH_MRF89
  97. /// Works with Microchip MRF89XA and compatible transceivers.
  98. /// and modules such as MRF89XAM9A.
  99. ///
  100. /// - RH_CC110
  101. /// Works with Texas Instruments CC110L transceivers and compatible modules such as Anaren AIR BoosterPack 430BOOST-CC110L
  102. ///
  103. /// - RH_ASK
  104. /// Works with a range of inexpensive ASK (amplitude shift keying) RF transceivers such as RX-B1
  105. /// (also known as ST-RX04-ASK) receiver; TX-C1 transmitter and DR3100 transceiver; FS1000A/XY-MK-5V transceiver;
  106. /// HopeRF RFM83C / RFM85. Supports ASK (OOK).
  107. ///
  108. /// - RH_Serial
  109. /// Works with RS232, RS422, RS485, RS488 and other point-to-point and multidropped serial connections,
  110. /// or with TTL serial UARTs such as those on Arduino and many other processors,
  111. /// or with data radios with a
  112. /// serial port interface. RH_Serial provides packetization and error detection over any hardware or
  113. /// virtual serial connection. Also builds and runs on Linux and OSX.
  114. ///
  115. /// - RH_TCP
  116. /// For use with simulated sketches compiled and running on Linux.
  117. /// Works with tools/etherSimulator.pl to pass messages between simulated sketches, allowing
  118. /// testing of Manager classes on Linux and without need for real radios or other transport hardware.
  119. ///
  120. /// Drivers can be used on their own to provide unaddressed, unreliable datagrams.
  121. /// All drivers have the same identical API.
  122. /// Or you can use any Driver with any of the Managers described below.
  123. ///
  124. /// We welcome contributions of well tested and well documented code to support other transports.
  125. ///
  126. /// \par Managers
  127. ///
  128. /// The following Mangers are provided:
  129. ///
  130. /// - RHDatagram
  131. /// Addressed, unreliable variable length messages, with optional broadcast facilities.
  132. ///
  133. /// - RHReliableDatagram
  134. /// Addressed, reliable, retransmitted, acknowledged variable length messages.
  135. ///
  136. /// - RHRouter
  137. /// Multi-hop delivery from source node to destination node via 0 or more intermediate nodes, with manual routing.
  138. ///
  139. /// - RHMesh
  140. /// Multi-hop delivery with automatic route discovery and rediscovery.
  141. ///
  142. /// Any Manager may be used with any Driver.
  143. ///
  144. /// \par Platforms
  145. ///
  146. /// A range of platforms is supported:
  147. ///
  148. /// - Arduino and the Arduino IDE (version 1.0 to 1.6.5 and later)
  149. /// Including Diecimila, Uno, Mega, Leonardo, Yun, Due, Zero etc. http://arduino.cc/, Also similar boards such as
  150. /// - Moteino http://lowpowerlab.com/moteino/
  151. /// - Anarduino Mini http://www.anarduino.com/mini/
  152. /// - RedBearLab Blend V1.0 http://redbearlab.com/blend/ (with Arduino 1.0.5 and RedBearLab Blend Add-On version 20140701)
  153. /// - MoteinoMEGA https://lowpowerlab.com/shop/moteinomega
  154. /// (with Arduino 1.0.5 and the MoteinoMEGA Arduino Core
  155. /// https://github.com/LowPowerLab/Moteino/tree/master/MEGA/Core)
  156. /// - ESP8266 on Arduino IDE and Boards Manager per https://github.com/esp8266/Arduino
  157. /// Tested using Arduino 1.6.8 with esp8266 by ESP8266 Community version 2.1.0
  158. /// Examples serial_reliable_datagram_* and ask_* are shown to work.
  159. /// CAUTION: The GHz radio included in the ESP8266 is
  160. /// not yet supported.
  161. /// - etc.
  162. ///
  163. /// - ChipKIT Core with Arduino IDE on any ChipKIT Core supported Digilent processor (tested on Uno32)
  164. /// http://chipkit.net/wiki/index.php?title=ChipKIT_core
  165. ///
  166. /// - Maple and Flymaple boards with libmaple and the Maple-IDE development environment
  167. /// http://leaflabs.com/devices/maple/ and http://www.open-drone.org/flymaple
  168. ///
  169. /// - Teensy including Teensy 3.1 and earlier built using Arduino IDE 1.0.5 to 1.6.4 and later with
  170. /// teensyduino addon 1.18 to 1.23 and later.
  171. /// http://www.pjrc.com/teensy
  172. ///
  173. /// - Particle Photon https://store.particle.io/collections/photon and ARM3 based CPU with built-in
  174. /// Wi-Fi transceiver and extensive IoT software suport. RadioHead does not support the built-in transceiver
  175. /// bt can be used to control other SPI based radios, Serial ports etc.
  176. /// See below for details on how to build RadioHead for Photon
  177. ///
  178. /// - ATtiny built using Arduino IDE 1.0.5 with the arduino-tiny support from https://code.google.com/p/arduino-tiny/
  179. /// and Digispark built with Arduino 1.6.5.
  180. /// (Caution: these are very small processors and not all RadioHead features may be available, depending on memory requirements)
  181. ///
  182. /// - nRF51 compatible Arm chips such as nRF51822 with Arduino 1.6.4 and later using the procedures
  183. /// in http://redbearlab.com/getting-started-nrf51822/
  184. ///
  185. /// - Raspberry Pi
  186. /// Uses BCM2835 library for GPIO http://www.airspayce.com/mikem/bcm2835/
  187. /// Currently works only with RH_NRF24 driver or other drivers that do not require interrupt support.
  188. /// Contributed by Mike Poublon.
  189. ///
  190. /// - Linux and OSX
  191. /// Using the RHutil/HardwareSerial class, the RH_Serial driver and any manager will
  192. /// build and run on Linux and OSX. These can be used to build programs that talk securely and reliably to
  193. /// Arduino and other processors or to other Linux or OSX hosts on a reliable, error detected datagram
  194. /// protocol over a serial line.
  195. ///
  196. /// Other platforms are partially supported, such as Generic AVR 8 bit processors, MSP430.
  197. /// We welcome contributions that will expand the range of supported platforms.
  198. ///
  199. /// RadioHead is available (through the efforts of others)
  200. /// for PlatformIO. PlatformIO is a cross-platform code builder and the missing library manager.
  201. /// http://platformio.org/#!/lib/show/124/RadioHead
  202. ///
  203. /// \par History
  204. ///
  205. /// RadioHead was created in April 2014, substantially based on code from some of our other earlier Radio libraries:
  206. ///
  207. /// - RHMesh, RHRouter, RHReliableDatagram and RHDatagram are derived from the RF22 library version 1.39.
  208. /// - RH_RF22 is derived from the RF22 library version 1.39.
  209. /// - RH_RF69 is derived from the RF69 library version 1.2.
  210. /// - RH_ASK is based on the VirtualWire library version 1.26, after significant conversion to C++.
  211. /// - RH_Serial was new.
  212. /// - RH_NRF24 is based on the NRF24 library version 1.12, with some significant changes.
  213. ///
  214. /// During this combination and redevelopment, we have tried to retain all the processor dependencies and support from
  215. /// the libraries that were contributed by other people. However not all platforms can be tested by us, so if you
  216. /// find that support from some platform has not been successfully migrated, please feel free to fix it and send us a
  217. /// patch.
  218. ///
  219. /// Users of RHMesh, RHRouter, RHReliableDatagram and RHDatagram in the previous RF22 library will find that their
  220. /// existing code will run mostly without modification. See the RH_RF22 documentation for more details.
  221. ///
  222. /// \par Installation
  223. ///
  224. /// Install in the usual way: unzip the distribution zip file to the libraries
  225. /// sub-folder of your sketchbook.
  226. /// The example sketches will be visible in in your Arduino, mpide, maple-ide or whatever.
  227. /// http://arduino.cc/en/Guide/Libraries
  228. ///
  229. /// \par Building for Particle Photon
  230. ///
  231. /// The Photon is not supported by the Arduino IDE, so it takes a little effort to set up a build environment.
  232. /// Heres what we did to enable building of RadioHead example sketches on Linux,
  233. /// but there are other ways to skin this cat.
  234. /// Basic reference for getting stated is: http://particle-firmware.readthedocs.org/en/develop/build/
  235. /// - Download the ARM gcc cross compiler binaries and unpack it in a suitable place:
  236. /// \code
  237. /// cd /tmp
  238. /// wget https://launchpad.net/gcc-arm-embedded/5.0/5-2015-q4-major/+download/gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2
  239. /// tar xvf gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2
  240. /// \endcode
  241. /// - If dfu-util and friends not installed on your platform, download dfu-util and friends to somewhere in your path
  242. /// \code
  243. /// cd ~/bin
  244. /// wget http://dfu-util.sourceforge.net/releases/dfu-util-0.8-binaries/linux-i386/dfu-util
  245. /// wget http://dfu-util.sourceforge.net/releases/dfu-util-0.8-binaries/linux-i386/dfu-suffix
  246. /// wget http://dfu-util.sourceforge.net/releases/dfu-util-0.8-binaries/linux-i386/dfu-prefix
  247. /// \endcode
  248. /// - Download the Particle firmware (contains headers and libraries require to compile Photon sketches)
  249. /// to a suitable place:
  250. /// \code
  251. /// cd /tmp
  252. /// wget https://github.com/spark/firmware/archive/develop.zip
  253. /// unzip develop.zip
  254. /// \endcode
  255. /// - Make a working area containing the RadioHead library source code and your RadioHead sketch. You must
  256. /// rename the sketch from .pde or .ino to application.cpp
  257. /// \code
  258. /// cd /tmp
  259. /// mkdir RadioHead
  260. /// cd RadioHead
  261. /// cp /usr/local/projects/arduino/libraries/RadioHead/*.h .
  262. /// cp /usr/local/projects/arduino/libraries/RadioHead/*.cpp .
  263. /// cp /usr/local/projects/arduino/libraries/RadioHead/examples/cc110/cc110_client/cc110_client.pde application.cpp
  264. /// \endcode
  265. /// - Edit application.cpp and comment out any #include <SPI.h> so it looks like:
  266. /// \code
  267. /// // #include <SPI.h>
  268. /// \endcode
  269. /// - Connect your Photon by USB. Put it in DFU mode as descibed in Photon documentation. Light should be flashing yellow
  270. /// - Compile the RadioHead sketch and install it as the user program (this does not update the rest of the
  271. /// Photon firmware, just the user part:
  272. /// \code
  273. /// cd /tmp/firmware-develop/main
  274. /// PATH=$PATH:/tmp/gcc-arm-none-eabi-5_2-2015q4/bin make APPDIR=/tmp/RadioHead all PLATFORM=photon program-dfu
  275. /// \endcode
  276. /// - You should see RadioHead compile without errors and download the finished sketch into the Photon.
  277. ///
  278. /// \par Compatible Hardware Suppliers
  279. ///
  280. /// We have had good experiences with the following suppliers of RadioHead compatible hardware:
  281. ///
  282. /// - LittleBird http://littlebirdelectronics.com.au in Australia for all manner of Arduinos and radios.
  283. /// - LowPowerLab http://lowpowerlab.com/moteino in USA for the excellent Moteino and Moteino-USB
  284. /// boards which include Hope-RF RF69B radios on-board.
  285. /// - Anarduino and HopeRF USA (http://www.hoperfusa.com and http://www.anarduino.com) who have a wide range
  286. /// of HopeRF radios and Arduino integrated modules.
  287. /// - SparkFun https://www.sparkfun.com/ in USA who design and sell a wide range of Arduinos and radio modules.
  288. ///
  289. /// \par Donations
  290. ///
  291. /// This library is offered under a free GPL license for those who want to use it that way.
  292. /// We try hard to keep it up to date, fix bugs
  293. /// and to provide free support. If this library has helped you save time or money, please consider donating at
  294. /// http://www.airspayce.com or here:
  295. ///
  296. /// \htmlonly <form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_donations" /> <input type="hidden" name="business" value="mikem@airspayce.com" /> <input type="hidden" name="lc" value="AU" /> <input type="hidden" name="item_name" value="Airspayce" /> <input type="hidden" name="item_number" value="RadioHead" /> <input type="hidden" name="currency_code" value="USD" /> <input type="hidden" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHosted" /> <input type="image" alt="PayPal — The safer, easier way to pay online." name="submit" src="https://www.paypalobjects.com/en_AU/i/btn/btn_donateCC_LG.gif" /> <img alt="" src="https://www.paypalobjects.com/en_AU/i/scr/pixel.gif" width="1" height="1" border="0" /></form> \endhtmlonly
  297. ///
  298. /// \par Trademarks
  299. ///
  300. /// RadioHead is a trademark of AirSpayce Pty Ltd. The RadioHead mark was first used on April 12 2014 for
  301. /// international trade, and is used only in relation to data communications hardware and software and related services.
  302. /// It is not to be confused with any other similar marks covering other goods and services.
  303. ///
  304. /// \par Copyright
  305. ///
  306. /// This software is Copyright (C) 2011-2016 Mike McCauley. Use is subject to license
  307. /// conditions. The main licensing options available are GPL V2 or Commercial:
  308. ///
  309. /// \par Open Source Licensing GPL V2
  310. ///
  311. /// This is the appropriate option if you want to share the source code of your
  312. /// application with everyone you distribute it to, and you also want to give them
  313. /// the right to share who uses it. If you wish to use this software under Open
  314. /// Source Licensing, you must contribute all your source code to the open source
  315. /// community in accordance with the GPL Version 2 when your application is
  316. /// distributed. See http://www.gnu.org/copyleft/gpl.html
  317. ///
  318. /// \par Commercial Licensing
  319. ///
  320. /// This is the appropriate option if you are creating proprietary applications
  321. /// and you are not prepared to distribute and share the source code of your
  322. /// application. Contact info@airspayce.com for details (do not use this address for anything other than
  323. /// commercial license enquiries. For all other queries, using the RadioHead mailing list).
  324. ///
  325. /// \par Revision History
  326. /// \version 1.1 2014-04-14<br>
  327. /// Initial public release
  328. /// \version 1.2 2014-04-23<br>
  329. /// Fixed various typos. <br>
  330. /// Added links to compatible Anarduino products.<br>
  331. /// Added RHNRFSPIDriver, RH_NRF24 classes to support Nordic NRF24 based radios.
  332. /// \version 1.3 2014-04-28<br>
  333. /// Various documentation fixups.<br>
  334. /// RHDatagram::setThisAddress() did not set the local copy of thisAddress. Reported by Steve Childress.<br>
  335. /// Fixed a problem on Teensy with RF22 and RF69, where the interrupt pin needs to be set for input, <br>
  336. /// else pin interrupt doesn't work properly. Reported by Steve Childress and patched by
  337. /// Adrien van den Bossche. Thanks.<br>
  338. /// Fixed a problem that prevented RF22 honouring setPromiscuous(true). Reported by Steve Childress.<br>
  339. /// Updated documentation to clarify some issues to do with maximum message lengths
  340. /// reported by Steve Childress.<br>
  341. /// Added support for yield() on systems that support it (currently Arduino 1.5.5 and later)
  342. /// so that spin-loops can suport multitasking. Suggested by Steve Childress.<br>
  343. /// Added RH_RF22::setGpioReversed() so the reversal it can be configured at run-time after
  344. /// radio initialisation. It must now be called _after_ init(). Suggested by Steve Childress.<br>
  345. /// \version 1.4 2014-04-29<br>
  346. /// Fixed further problems with Teensy compatibility for RH_RF22. Tested on Teensy 3.1.
  347. /// The example/rf22_* examples now run out of the box with the wiring connections as documented for Teensy
  348. /// in RH_RF22.<br>
  349. /// Added YIELDs to spin-loops in RHRouter, RHMesh and RHReliableDatagram, RH_NRF24.<br>
  350. /// Tested RH_Serial examples with Teensy 3.1: they now run out of the box.<br>
  351. /// Tested RH_ASK examples with Teensy 3.1: they now run out of the box.<br>
  352. /// Reduced default SPI speed for NRF24 from 8MHz to 1MHz on Teensy, to improve reliability when
  353. /// poor wiring is in use.<br>
  354. /// on some devices such as Teensy.<br>
  355. /// Tested RH_NRF24 examples with Teensy 3.1: they now run out of the box.<br>
  356. /// \version 1.5 2014-04-29<br>
  357. /// Added support for Nordic Semiconductor nRF905 transceiver with RH_NRF905 driver. Also
  358. /// added examples for nRF905 and tested on Teensy 3.1
  359. /// \version 1.6 2014-04-30<br>
  360. /// NRF905 examples were missing
  361. /// \version 1.7 2014-05-03<br>
  362. /// Added support for Arduino Due. Tested with RH_NRF905, RH_Serial, RH_ASK.
  363. /// IMPORTANT CHANGE to interrupt pins on Arduino with RH_RF22 and RH_RF69 constructors:
  364. /// previously, you had to specify the interrupt _number_ not the interrupt _pin_. Arduinos and Uno32
  365. /// are now consistent with all other platforms: you must specify the interrupt pin number. Default
  366. /// changed to pin 2 (a common choice with RF22 shields).
  367. /// Removed examples/maple/maple_rf22_reliable_datagram_client and
  368. /// examples/maple/maple_rf22_reliable_datagram_client since the rf22 examples now work out
  369. /// of the box with Flymaple.
  370. /// Removed examples/uno32/uno32_rf22_reliable_datagram_client and
  371. /// examples/uno32/uno32_rf22_reliable_datagram_client since the rf22 examples now work out
  372. /// of the box with ChipKit Uno32.
  373. /// \version 1.8 2014-05-08 <br>
  374. /// Added support for YIELD in Teensy 2 and 3, suggested by Steve Childress.<br>
  375. /// Documentation updates. Clarify use of headers and Flags<br>
  376. /// Fixed misalignment in RH_RF69 between ModemConfigChoice definitions and the implemented choices
  377. /// which meant you didnt get the choice you thought and GFSK_Rb55555Fd50 hung the transmitter.<br>
  378. /// Preliminary work on Linux simulator.
  379. /// \version 1.9 2014-05-14 <br>
  380. /// Added support for using Timer 2 instead of Timer 1 on Arduino in RH_ASK when
  381. /// RH_ASK_ARDUINO_USE_TIMER2 is defined. With the kind assistance of
  382. /// Luc Small. Thanks!<br>
  383. /// Updated comments in RHReliableDatagram concerning servers, retries, timeouts and delays.
  384. /// Fixed an error in RHReliableDatagram where recvfrom return value was not checked.
  385. /// Reported by Steve Childress.<br>
  386. /// Added Linux simulator support so simple RadioHead sketches can be compiled and run on Linux.<br>
  387. /// Added RH_TCP driver to permit message passing between simulated sketches on Linux.<br>
  388. /// Added example simulator sketches.<br>
  389. /// Added tools/etherSimulator.pl, a simulator of the 'Luminiferous Ether' that passes
  390. /// messages between simulated sketches and can simulate random message loss etc.<br>
  391. /// Fixed a number of typos and improved some documentation.<br>
  392. /// \version 1.10 2014-05-15 <br>
  393. /// Added support for RFM73 modules to RH_NRF24. These 2 radios are very similar, and can interoperate
  394. /// with each other. Added new RH_NRF24::TransmitPower enums for the RFM73, which has a different
  395. /// range of available powers<br>
  396. /// reduced the default SPI bus speed for RH_NRF24 to 1MHz, since so many modules and CPU have problems
  397. /// with 8MHz.<br>
  398. /// \version 1.11 2014-05-18<br>
  399. /// Testing RH_RF22 with RFM23BP and 3.3V Teensy 3.1 and 5V Arduinos.
  400. /// Updated documentation with respect to GPIO and antenna
  401. /// control pins for RFM23. Updated documentation with respect to transmitter power control for RFM23<br>
  402. /// Fixed a problem with RH_RF22 driver, where GPIO TX and RX pins were not configured during
  403. /// initialisation, causing poor transmit power and sensitivity on those RF22/RF23 devices where GPIO controls
  404. /// the antenna selection pins.
  405. /// \version 1.12 2014-05-20<br>
  406. /// Testing with RF69HW and the RH_RF69 driver. Works well with the Anarduino MiniWireless -CW and -HW
  407. /// boards http://www.anarduino.com/miniwireless/ including
  408. /// the marvellous high powered MinWireless-HW (with 20dBm output for excellent range).<br>
  409. /// Clarified documentation of RH_RF69::setTxPower values for different models of RF69.<br>
  410. /// Added RHReliableDatagram::resetRetransmissions().<br>
  411. /// Retransmission count precision increased to uin32_t.<br>
  412. /// Added data about actual power measurements from RFM22 module.<br>
  413. /// \version 1.13 2014-05-23<br>
  414. /// setHeaderFlags(flags) changed to setHeaderFlags(set, clear), enabling any flags to be
  415. /// individually set and cleared by either RadioHead or application code. Requested by Steve Childress.<br>
  416. /// Fixed power output setting for boost power on RF69HW for 18, 19 and 20dBm.<br>
  417. /// Added data about actual power measurements from RFM69W and RFM69HW modules.<br>
  418. /// \version 1.14 2014-05-26<br>
  419. /// RH_RF69::init() now always sets the PA boost back to the default settings, else can get invalid
  420. /// PA power modes after uploading new sketches without a power cycle. Reported by Bryan.<br>
  421. /// Added new macros RH_VERSION_MAJOR RH_VERSION_MINOR, with automatic maintenance in Makefile.<br>
  422. /// Improvements to RH_TCP: constructor now honours the server argument in the form "servername:port".<br>
  423. /// Added YIELD to RHReliableDatagram::recvfromAckTimeout. Requested by Steve Childress.<br>
  424. /// Fixed a problem with RH_RF22 reliable datagram acknowledgements that was introduced in version 1.13.
  425. /// Reported by Steve Childress.<br>
  426. /// \version 1.15 2014-05-27<br>
  427. /// Fixed a problem with the RadioHead .zip link.
  428. /// \version 1.16 2014-05-30 <br>
  429. /// Fixed RH_RF22 so that lastRssi() returns the signal strength in dBm. Suggested by Steve Childress.<br>
  430. /// Added support for getLastPreambleTime() to RH_RF69. Requested by Steve Childress.<br>
  431. /// RH_NRF24::init() now checks if there is a device connected and responding, else init() will fail.
  432. /// Suggested by Steve Brown.<br>
  433. /// RHSoftwareSPI now initialises default values for SPI pins MOSI = 12, MISO = 11 and SCK = 13.<br>
  434. /// Fixed some problems that prevented RH_NRF24 working with mixed software and hardware SPI
  435. /// on different devices: a race condition
  436. /// due to slow SPI transfers and fast acknowledgement.<br>
  437. /// \version 1.17 2014-06-02 <br>
  438. /// Fixed a debug typo in RHReliableDatagram that was introduced in 1.16.<br>
  439. /// RH_NRF24 now sets default power, data rate and channel in init(), in case another
  440. /// app has previously set different values without powerdown.<br>
  441. /// Caution: there are still problems with RH_NRF24 and Software SPI. Do not use.<br>
  442. /// \version 1.18 2014-06-02<br>
  443. /// Improvements to performance of RH_NRF24 statusRead, allowing RH_NRF24 and Software SPI
  444. /// to operate on slow devices like Arduino Uno.<br>
  445. /// \version 1.19 2014-06-19<br>
  446. /// Added examples ask_transmitter.pde and ask_receiver.pde.<br>
  447. /// Fixed an error in the RH_RF22 doc for connection of Teensy to RF22.<br>
  448. /// Improved documentation of start symbol bit patterns in RH_ASK.cpp
  449. /// \version 1.20 2014-06-24<br>
  450. /// Fixed a problem with compiling on platforms such as ATTiny where SS is not defined.<br>
  451. /// Added YIELD to RHMesh::recvfromAckTimeout().<br>
  452. /// \version 1.21 2014-06-24<br>
  453. /// Fixed an issue in RH_Serial where characters might be lost with back-to-back frames.
  454. /// Suggested by Steve Childress.<br>
  455. /// Brought previous RHutil/crc16.h code into mainline RHCRC.cpp to prevent name collisions
  456. /// with other similarly named code in other libraries. Suggested by Steve Childress.<br>
  457. /// Fix SPI bus speed errors on 8MHz Arduinos.
  458. /// \version 1.22 2014-07-01<br>
  459. /// Update RH_ASK documentation for common wiring connections.<br>
  460. /// Testing RH_ASK with HopeRF RFM83C/RFM85 courtesy Anarduino http://www.anarduino.com/<br>
  461. /// Testing RH_NRF24 with Itead Studio IBoard Pro http://imall.iteadstudio.com/iboard-pro.html
  462. /// using both hardware SPI on the ITDB02 Parallel LCD Module Interface pins and software SPI
  463. /// on the nRF24L01+ Module Interface pins. Documented wiring required.<br>
  464. /// Added support for AVR 1284 and 1284p, contributed by Peter Scargill.
  465. /// Added support for Semtech SX1276/77/78 and HopeRF RFM95/96/97/98 and other similar LoRa capable radios
  466. /// in LoRa mode only. Tested with the excellent MiniWirelessLoRa from
  467. /// Anarduino http://www.anarduino.com/miniwireless<br>
  468. /// \version 1.23 2014-07-03<br>
  469. /// Changed the default modulation for RH_RF69 to GFSK_Rb250Fd250, since the previous default
  470. /// was not very reliable.<br>
  471. /// Documented RH_RF95 range tests.<br>
  472. /// Improvements to RH_RF22 RSSI readings so that lastRssi correctly returns the last message in dBm.<br>
  473. /// \version 1.24 2014-07-18
  474. /// Added support for building RadioHead for STM32F4 Discovery boards, using the native STM Firmware libraries,
  475. /// in order to support Codec2WalkieTalkie (http://www.airspayce.com/mikem/Codec2WalkieTalkie)
  476. /// and other projects. See STM32ArduinoCompat.<br>
  477. /// Default modulation for RH_RF95 was incorrectly set to a very slow Bw125Cr48Sf4096
  478. /// \version 1.25 2014-07-25
  479. /// The available() function will longer terminate any current transmission, and force receive mode.
  480. /// Now, if there is no unprocessed incoming message and an outgoing message is currently being transmitted,
  481. /// available() will return false.<br>
  482. /// RHRouter::sendtoWait(uint8_t*, uint8_t, uint8_t, uint8_t) renamed to sendtoFromSourceWait due to conflicts
  483. /// with new sendtoWait() with optional flags.<br>
  484. /// RHMEsh and RHRouter already supported end-to-end application layer flags, but RHMesh::sendtoWait()
  485. /// and RHRouter::sendToWait have now been extended to expose a way to send optional application layer flags.
  486. /// \version 1.26 2014-08-12
  487. /// Fixed a Teensy 2.0 compile problem due yield() not available on Teensy < 3.0. <br>
  488. /// Adjusted the algorithm of RH_RF69::temperatureRead() to more closely reflect reality.<br>
  489. /// Added functions to RHGenericDriver to get driver packet statistics: rxBad(), rxGood(), txGood().<br>
  490. /// Added RH_RF69::printRegisters().<br>
  491. /// RH_RF95::printRegisters() was incorrectly printing the register index instead of the address.
  492. /// Reported by Phang Moh Lim.<br>
  493. /// RH_RF95, added definitions for some more registers that are usable in LoRa mode.<br>
  494. /// RH_RF95::setTxPower now uses RH_RF95_PA_DAC_ENABLE to achieve 21, 22 and 23dBm.<br>
  495. /// RH_RF95, updated power output measurements.<br>
  496. /// Testing RH_RF69 on Teensy 3.1 with RF69 on PJRC breakout board. OK.<br>
  497. /// Improvements so RadioHead will build under Arduino where SPI is not supported, such as
  498. /// ATTiny.<br>
  499. /// Improvements so RadioHead will build for ATTiny using Arduino IDE and tinycore arduino-tiny-0100-0018.zip.<br>
  500. /// Testing RH_ASK on ATTiny85. Reduced RAM footprint.
  501. /// Added helpful documentation. Caution: RAM memory is *very* tight on this platform.<br>
  502. /// RH_RF22 and RH_RF69, added setIdleMode() function to allow the idle mode radio operating state
  503. /// to be controlled for lower idle power consumption at the expense of slower transitions to TX and RX.<br>
  504. /// \version 1.27 2014-08-13
  505. /// All RH_RF69 modulation schemes now have data whitening enabled by default.<br>
  506. /// Tested and added a number of OOK modulation schemes to RH_RF69 Modem config table.<br>
  507. /// Minor improvements to a number of the faster RH_RF69 modulation schemes, but some slower ones
  508. /// are still not working correctly.<br>
  509. /// \version 1.28 2014-08-20
  510. /// Added new RH_RF24 driver to support Si446x, RF24/26/26, RFM24/26/27 family of transceivers.
  511. /// Tested with the excellent
  512. /// Anarduino Mini and RFM24W and RFM26W with the generous assistance of the good people at
  513. /// Anarduino http://www.anarduino.com.
  514. /// \version 1.29 2014-08-21
  515. /// Fixed a compile error in RH_RF24 introduced at the last minute in hte previous release.<br>
  516. /// Improvements to RH_RF69 modulation schemes: now include the AFCBW in teh ModemConfig.<br>
  517. /// ModemConfig RH_RF69::FSK_Rb2Fd5 and RH_RF69::GFSK_Rb2Fd5 are now working.<br>
  518. /// \version 1.30 2014-08-25
  519. /// Fixed some compile problems with ATtiny84 on Arduino 1.5.5 reported by Glen Cook.<br>
  520. /// \version 1.31 2014-08-27
  521. /// Changed RH_RF69 FSK and GFSK modulations from Rb2_4Fd2_4 to Rb2_4Fd4_8 and FSK_Rb4_8Fd4_8 to FSK_Rb4_8Fd9_6
  522. /// since the previous ones were unreliable (they had modulation indexes of 1).<br>
  523. /// \version 1.32 2014-08-28
  524. /// Testing with RedBearLab Blend board http://redbearlab.com/blend/. OK.<br>
  525. /// Changed more RH_RF69 FSK and GFSK slowish modulations to have modulation index of 2 instead of 1.
  526. /// This required chnaging the symbolic names.<br>
  527. /// \version 1.33 2014-09-01
  528. /// Added support for sleep mode in RHGeneric driver, with new mode
  529. /// RHModeSleep and new virtual function sleep().<br>
  530. /// Added support for sleep to RH_RF69, RH_RF22, RH_NRF24, RH_RF24, RH_RF95 drivers.<br>
  531. /// \version 1.34 2014-09-19
  532. /// Fixed compile errors in example rf22_router_test.<br>
  533. /// Fixed a problem with RH_NRF24::setNetworkAddress, also improvements to RH_NRF24 register printing.
  534. /// Patched by Yveaux.<br>
  535. /// Improvements to RH_NRF24 initialisation for version 2.0 silicon.<br>
  536. /// Fixed problem with ambigiguous print call in RH_RFM69 when compiling for Codec2.<br>
  537. /// Fixed a problem with RH_NRF24 on RFM73 where the LNA gain was not set properly, reducing the sensitivity
  538. /// of the receiver.
  539. /// \version 1.35 2014-09-19
  540. /// Fixed a problem with interrupt setup on RH_RF95 with Teensy3.1. Reported by AD.<br>
  541. /// \version 1.36 2014-09-22
  542. /// Improvements to interrupt pin assignments for __AVR_ATmega1284__ and__AVR_ATmega1284P__, provided by
  543. /// Peter Scargill.<br>
  544. /// Work around a bug in Arduino 1.0.6 where digitalPinToInterrupt is defined but NOT_AN_INTERRUPT is not.<br>
  545. /// \version 1.37 2014-10-19
  546. /// Updated doc for connecting RH_NRF24 to Arduino Mega.<br>
  547. /// Changes to RHGenericDriver::setHeaderFlags(), so that the default for the clear argument
  548. /// is now RH_FLAGS_APPLICATION_SPECIFIC, which is less surprising to users.
  549. /// Testing with the excellent MoteinoMEGA from LowPowerLab
  550. /// https://lowpowerlab.com/shop/moteinomega with on-board RFM69W.
  551. /// \version 1.38 2014-12-29
  552. /// Fixed compile warning on some platforms where RH_RF24::send and RH_RF24::writeTxFifo
  553. /// did not return a value.<br>
  554. /// Fixed some more compiler warnings in RH_RF24 on some platforms.<br>
  555. /// Refactored printRegisters for some radios. Printing to Serial
  556. /// is now controlled by the definition of RH_HAVE_SERIAL.<br>
  557. /// Added partial support for ARM M4 w/CMSIS with STM's Hardware Abstraction lib for
  558. /// Steve Childress.<br>
  559. /// \version 1.39 2014-12-30
  560. /// Fix some compiler warnings under IAR.<br>
  561. /// RH_HAVE_SERIAL and Serial.print calls removed for ATTiny platforms.<br>
  562. /// \version 1.40 2015-03-09
  563. /// Added notice about availability on PlatformIO, thanks to Ivan Kravets.<br>
  564. /// Fixed a problem with RH_NRF24 where short packet lengths would occasionally not be trasmitted
  565. /// due to a race condition with RH_NRF24_TX_DS. Reported by Mark Fox.<br>
  566. /// \version 1.41 2015-03-29
  567. /// RH_RF22, RH_RF24, RH_RF69 and RH_RF95 improved to allow driver.init() to be called multiple
  568. /// times without reallocating a new interrupt, allowing the driver to be reinitialised
  569. /// after sleeping or powering down.
  570. /// \version 1.42 2015-05-17
  571. /// Added support for RH_NRF24 driver on Raspberry Pi, using BCM2835
  572. /// library for GPIO pin IO. Contributed by Mike Poublon.<br>
  573. /// Tested RH_NRF24 module with NRF24L01+PA+LNA SMA Antenna Wireless Transceiver modules
  574. /// similar to: http://www.elecfreaks.com/wiki/index.php?title=2.4G_Wireless_nRF24L01p_with_PA_and_LNA
  575. /// works with no software changes. Measured max power output 18dBm.<br>
  576. /// \version 1.43 2015-08-02
  577. /// Added RH_NRF51 driver to support Nordic nRF51 family processor with 2.4GHz radio such
  578. /// as nRF51822, to be built on Arduino 1.6.4 and later. Tested with RedBearLabs nRF51822 board
  579. /// and BLE Nano kit<br>
  580. /// \version 1.44 2015-08-08
  581. /// Fixed errors with compiling on some platforms without serial, such as ATTiny.
  582. /// Reported by Friedrich Müller.<br>
  583. /// \version 1.45 2015-08-13
  584. /// Added support for using RH_Serial on Linux and OSX (new class RHutil/HardwareSerial
  585. /// encapsulates serial ports on those platforms). Example examples/serial upgraded
  586. /// to build and run on Linux and OSX using the tools/simBuild builder.
  587. /// RHMesh, RHRouter and RHReliableDatagram updated so they can use RH_Serial without
  588. /// polling loops on Linux and OSX for CPU efficiency.<br>
  589. /// \version 1.46 2015-08-14
  590. /// Amplified some doc concerning Linux and OSX RH_Serial. Added support for 230400
  591. /// baud rate in HardwareSerial.<br>
  592. /// Added sample sketches nrf51_audio_tx and nrf51_audio_rx which show how to
  593. /// build an audio TX/RX pair with RedBear nRF51822 boards and a SparkFun MCP4725 DAC board.
  594. /// Uses the built-in ADC of the nRF51822 to sample audio at 5kHz and transmit packets
  595. /// to the receiver which plays them via the DAC.<br>
  596. /// \version 1.47 2015-09-18
  597. /// Removed top level Makefile from distribution: its only used by the developer and
  598. /// its presence confuses some people.<br>
  599. /// Fixed a problem with RHReliableDatagram with some versions of Raspberry Pi random() that causes
  600. /// problems: random(min, max) sometimes exceeds its max limit.
  601. /// \version 1.48 2015-09-30
  602. /// Added support for Arduino Zero. Tested on Arduino Zero Pro.
  603. /// \version 1.49 2015-10-01
  604. /// Fixed problems that prevented interrupts working correctly on Arduino Zero and Due.
  605. /// Builds and runs with 1.6.5 (with 'Arduino SAMD Boards' for Zero version 1.6.1) from arduino.cc.
  606. /// Arduino version 1.7.7 from arduino.org is not currently supported.
  607. /// \version 1.50 2015-10-25
  608. /// Verified correct building and operation with Arduino 1.7.7 from arduino.org.
  609. /// Caution: You must burn the bootloader from 1.7.7 to the Arduino Zero before it will
  610. /// work with Arduino 1.7.7 from arduino.org. Conversely, you must burn the bootloader from 1.6.5
  611. /// to the Arduino Zero before it will
  612. /// work with Arduino 1.6.5 from arduino.cc. Sigh.
  613. /// Fixed a problem with RH_NRF905 that prevented the power and frequency ranges being set
  614. /// properly. Reported by Alan Webber.
  615. /// \version 1.51 2015-12-11
  616. /// Changes to RH_RF6::setTxPower() to be compatible with SX1276/77/78/79 modules that
  617. /// use RFO transmitter pins instead of PA_BOOST, such as the excellent
  618. /// Modtronix inAir4 http://modtronix.com/inair4.html
  619. /// and inAir9 modules http://modtronix.com/inair9.html. With the kind assistance of
  620. /// David from Modtronix.
  621. /// \version 1.52 2015-12-17
  622. /// Added RH_MRF89 module to suport Microchip MRF89XA and compatible transceivers.
  623. /// and modules.<br>
  624. /// \version 1.53 2016-01-02
  625. /// Added RH_CC110 module to support Texas Instruments CC110L and compatible transceivers and modules.<br>
  626. /// \version 1.54 2016-01-29
  627. /// Added support for ESP8266 processor on Arduino IDE. Examples serial_reliable_datagram_* are shown to work.
  628. /// CAUTION: SPI not supported yet. Timers used by RH_ASK are not tested.
  629. /// The GHz radio included in the ESP8266 is not yet supported.
  630. /// \version 1.55 2016-02-12
  631. /// Added macros for htons() and friends to RadioHead.h.
  632. /// Added example sketch serial_gateway.pde. Acts as a transparent gateway between RH_RF22 and RH_Serial,
  633. /// and with minor mods acts as a universal gateway between any 2 RadioHead driver networks.
  634. /// Initial work on supporting STM32 F2 on Particle Photon: new platform type defined.
  635. /// Fixed many warnings exposed by test building for Photon.
  636. /// Particle Photon tested support for RH_Serial, RH_ASK, SPI, RH_CC110 etc.
  637. /// Added notes on how to build RadioHead sketches for Photon.
  638. /// \version 1.56 2016-02-18
  639. /// Implemented timers for RH_ASK on ESP8266, added some doc on IO pin selection.
  640. /// \version 1.57 2016-02-23
  641. /// Fixed an issue reported by S3B, where RH_RF22 would sometimes not clear the rxbufvalid flag.
  642. /// \version 1.58 2-16-04-04
  643. /// Tested RH_RF69 with Arduino Due. OK. Updated doc.<br>
  644. /// Added support for all ChipKIT Core supported boards
  645. /// http://chipkit.net/wiki/index.php?title=ChipKIT_core
  646. /// Tested on ChipKIT Uno32.<br>
  647. /// Digilent Uno32 under the old MPIDE is no longer formally
  648. /// supported but may continue to work for some time.<br>
  649. /// \version 1.59 2016-04-12
  650. /// Testing with the excellent Rocket Scream Mini Ultra Pro with the RFM95W and RFM69HCW modules from
  651. /// http://www.rocketscream.com/blog/product/mini-ultra-pro-with-radio/ (915MHz versions). Updated
  652. /// documentation with hints to suit. Caution: requires Arduino 1.6.8 and Arduino SAMD Boards 1.6.5.
  653. /// See also http://www.rocketscream.com/blog/2016/03/10/radio-range-test-with-rfm69hcw/
  654. /// for the vendors tests and range with the RFM69HCW version.
  655. /// These boards are highly recommended. They also include battery charging support.
  656. /// \version 1.60 2016-06-25
  657. /// Tested with the excellent talk2 Whisper Node boards
  658. /// (https://talk2.wisen.com.au/ and https://bitbucket.org/talk2/),
  659. /// an Arduino Nano compatible board, which include an on-board RF69 radio, external antenna,
  660. /// run on 2xAA batteries and support low power operations. RF69 examples work without modification.
  661. /// Added support for ESP8266 SPI, provided by David Skinner.
  662. /// \version 1.61 2016-07-07
  663. /// Patch to RH_ASK.cpp for ESP8266, to prevent crashes in interrupt handlers. Patch from Alexander Mamchits.
  664. ///
  665. /// \author Mike McCauley. DO NOT CONTACT THE AUTHOR DIRECTLY. USE THE MAILING LIST GIVEN ABOVE
  666. #ifndef RadioHead_h
  667. #define RadioHead_h
  668. // Official version numbers are maintained automatically by Makefile:
  669. #define RH_VERSION_MAJOR 1
  670. #define RH_VERSION_MINOR 61
  671. // Symbolic names for currently supported platform types
  672. #define RH_PLATFORM_ARDUINO 1
  673. #define RH_PLATFORM_MSP430 2
  674. #define RH_PLATFORM_STM32 3
  675. #define RH_PLATFORM_GENERIC_AVR8 4
  676. #define RH_PLATFORM_UNO32 5
  677. #define RH_PLATFORM_UNIX 6
  678. #define RH_PLATFORM_STM32STD 7
  679. #define RH_PLATFORM_STM32F4_HAL 8
  680. #define RH_PLATFORM_RASPI 9
  681. #define RH_PLATFORM_NRF51 10
  682. #define RH_PLATFORM_ESP8266 11
  683. #define RH_PLATFORM_STM32F2 12
  684. #define RH_PLATFORM_CHIPKIT_CORE 13
  685. ////////////////////////////////////////////////////
  686. // Select platform automatically, if possible
  687. #ifndef RH_PLATFORM
  688. #if (MPIDE>=150 && defined(ARDUINO))
  689. // Using ChipKIT Core on Arduino IDE
  690. #define RH_PLATFORM RH_PLATFORM_CHIPKIT_CORE
  691. #elif defined(MPIDE)
  692. // Uno32 under old MPIDE, which has been discontinued:
  693. #define RH_PLATFORM RH_PLATFORM_UNO32
  694. #elif defined(NRF51)
  695. #define RH_PLATFORM RH_PLATFORM_NRF51
  696. #elif defined(ESP8266)
  697. #define RH_PLATFORM RH_PLATFORM_ESP8266
  698. #elif defined(ARDUINO)
  699. #define RH_PLATFORM RH_PLATFORM_ARDUINO
  700. #elif defined(__MSP430G2452__) || defined(__MSP430G2553__)
  701. #define RH_PLATFORM RH_PLATFORM_MSP430
  702. #elif defined(MCU_STM32F103RE)
  703. #define RH_PLATFORM RH_PLATFORM_STM32
  704. #elif defined(STM32F2XX)
  705. #define RH_PLATFORM RH_PLATFORM_STM32F2
  706. #elif defined(USE_STDPERIPH_DRIVER)
  707. #define RH_PLATFORM RH_PLATFORM_STM32STD
  708. #elif defined(RASPBERRY_PI)
  709. #define RH_PLATFORM RH_PLATFORM_RASPI
  710. #elif defined(__unix__) // Linux
  711. #define RH_PLATFORM RH_PLATFORM_UNIX
  712. #elif defined(__APPLE__) // OSX
  713. #define RH_PLATFORM RH_PLATFORM_UNIX
  714. #else
  715. #error Platform not defined!
  716. #endif
  717. #endif
  718. #if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtinyX4__) || defined(__AVR_ATtinyX5__) || defined(__AVR_ATtiny2313__) || defined(__AVR_ATtiny4313__) || defined(__AVR_ATtinyX313__)
  719. #define RH_PLATFORM_ATTINY
  720. #endif
  721. ////////////////////////////////////////////////////
  722. // Platform specific headers:
  723. #if (RH_PLATFORM == RH_PLATFORM_ARDUINO)
  724. #if (ARDUINO >= 100)
  725. #include <Arduino.h>
  726. #else
  727. #include <wiring.h>
  728. #endif
  729. #ifdef RH_PLATFORM_ATTINY
  730. #warning Arduino TinyCore does not support hardware SPI. Use software SPI instead.
  731. #else
  732. #include <SPI.h>
  733. #define RH_HAVE_HARDWARE_SPI
  734. #define RH_HAVE_SERIAL
  735. #endif
  736. #elif (RH_PLATFORM == RH_PLATFORM_ESP8266) // ESP8266 processor on Arduino IDE
  737. #include <Arduino.h>
  738. #include <SPI.h>
  739. #define RH_HAVE_HARDWARE_SPI
  740. #define RH_HAVE_SERIAL
  741. #elif (RH_PLATFORM == RH_PLATFORM_MSP430) // LaunchPad specific
  742. #include "legacymsp430.h"
  743. #include "Energia.h"
  744. #include <SPI.h>
  745. #define RH_HAVE_HARDWARE_SPI
  746. #define RH_HAVE_SERIAL
  747. #elif (RH_PLATFORM == RH_PLATFORM_UNO32 || RH_PLATFORM == RH_PLATFORM_CHIPKIT_CORE)
  748. #include <WProgram.h>
  749. #include <string.h>
  750. #include <SPI.h>
  751. #define RH_HAVE_HARDWARE_SPI
  752. #define memcpy_P memcpy
  753. #define RH_HAVE_SERIAL
  754. #elif (RH_PLATFORM == RH_PLATFORM_STM32) // Maple, Flymaple etc
  755. #include <wirish.h>
  756. #include <stdint.h>
  757. #include <string.h>
  758. #include <HardwareSPI.h>
  759. #define RH_HAVE_HARDWARE_SPI
  760. // Defines which timer to use on Maple
  761. #define MAPLE_TIMER 1
  762. #define PROGMEM
  763. #define memcpy_P memcpy
  764. #define Serial SerialUSB
  765. #define RH_HAVE_SERIAL
  766. #elif (RH_PLATFORM == RH_PLATFORM_STM32F2) // Particle Photon with firmware-develop
  767. #include <stm32f2xx.h>
  768. #include <application.h>
  769. #include <math.h> // floor
  770. #define RH_HAVE_SERIAL
  771. #define RH_HAVE_HARDWARE_SPI
  772. #elif (RH_PLATFORM == RH_PLATFORM_STM32STD) // STM32 with STM32F4xx_StdPeriph_Driver
  773. #include <stm32f4xx.h>
  774. #include <wirish.h>
  775. #include <stdint.h>
  776. #include <string.h>
  777. #include <math.h>
  778. #include <HardwareSPI.h>
  779. #define RH_HAVE_HARDWARE_SPI
  780. #define Serial SerialUSB
  781. #define RH_HAVE_SERIAL
  782. #elif (RH_PLATFORM == RH_PLATFORM_GENERIC_AVR8)
  783. #include <avr/io.h>
  784. #include <avr/interrupt.h>
  785. #include <util/delay.h>
  786. #include <string.h>
  787. #include <stdbool.h>
  788. #define RH_HAVE_HARDWARE_SPI
  789. #include <SPI.h>
  790. // For Steve Childress port to ARM M4 w/CMSIS with STM's Hardware Abstraction lib.
  791. // See ArduinoWorkarounds.h (not supplied)
  792. #elif (RH_PLATFORM == RH_PLATFORM_STM32F4_HAL)
  793. #include <ArduinoWorkarounds.h>
  794. #include <stm32f4xx.h> // Also using ST's CubeMX to generate I/O and CPU setup source code for IAR/EWARM, not GCC ARM.
  795. #include <stdint.h>
  796. #include <string.h>
  797. #include <math.h>
  798. #define RH_HAVE_HARDWARE_SPI // using HAL (Hardware Abstraction Libraries from ST along with CMSIS, not arduino libs or pins concept.
  799. #elif (RH_PLATFORM == RH_PLATFORM_RASPI)
  800. #define RH_HAVE_HARDWARE_SPI
  801. #define RH_HAVE_SERIAL
  802. #define PROGMEM
  803. #include <RHutil/RasPi.h>
  804. #include <string.h>
  805. //Define SS for CS0 or pin 24
  806. #define SS 8
  807. #elif (RH_PLATFORM == RH_PLATFORM_NRF51)
  808. #define RH_HAVE_SERIAL
  809. #define PROGMEM
  810. #include <Arduino.h>
  811. #elif (RH_PLATFORM == RH_PLATFORM_UNIX)
  812. // Simulate the sketch on Linux and OSX
  813. #include <RHutil/simulator.h>
  814. #define RH_HAVE_SERIAL
  815. #include <netinet/in.h> // For htons and friends
  816. #else
  817. #error Platform unknown!
  818. #endif
  819. ////////////////////////////////////////////////////
  820. // This is an attempt to make a portable atomic block
  821. #if (RH_PLATFORM == RH_PLATFORM_ARDUINO)
  822. #if defined(__arm__)
  823. #include <RHutil/atomic.h>
  824. #else
  825. #include <util/atomic.h>
  826. #endif
  827. #define ATOMIC_BLOCK_START ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
  828. #define ATOMIC_BLOCK_END }
  829. #elif (RH_PLATFORM == RH_PLATFORM_CHIPKIT_CORE)
  830. // UsingChipKIT Core on Arduino IDE
  831. #define ATOMIC_BLOCK_START unsigned int __status = disableInterrupts(); {
  832. #define ATOMIC_BLOCK_END } restoreInterrupts(__status);
  833. #elif (RH_PLATFORM == RH_PLATFORM_UNO32)
  834. // Under old MPIDE, which has been discontinued:
  835. #include <peripheral/int.h>
  836. #define ATOMIC_BLOCK_START unsigned int __status = INTDisableInterrupts(); {
  837. #define ATOMIC_BLOCK_END } INTRestoreInterrupts(__status);
  838. #elif (RH_PLATFORM == RH_PLATFORM_STM32F2) // Particle Photon with firmware-develop
  839. #define ATOMIC_BLOCK_START { int __prev = HAL_disable_irq();
  840. #define ATOMIC_BLOCK_END HAL_enable_irq(__prev); }
  841. #elif (RH_PLATFORM == RH_PLATFORM_ESP8266)
  842. // See hardware/esp8266/2.0.0/cores/esp8266/Arduino.h
  843. #define ATOMIC_BLOCK_START { uint32_t __savedPS = xt_rsil(15);
  844. #define ATOMIC_BLOCK_END xt_wsr_ps(__savedPS);}
  845. #else
  846. // TO BE DONE:
  847. #define ATOMIC_BLOCK_START
  848. #define ATOMIC_BLOCK_END
  849. #endif
  850. ////////////////////////////////////////////////////
  851. // Try to be compatible with systems that support yield() and multitasking
  852. // instead of spin-loops
  853. // Recent Arduino IDE or Teensy 3 has yield()
  854. #if (RH_PLATFORM == RH_PLATFORM_ARDUINO && ARDUINO >= 155 && !defined(RH_PLATFORM_ATTINY)) || (TEENSYDUINO && defined(__MK20DX128__))
  855. #define YIELD yield();
  856. #elif (RH_PLATFORM == RH_PLATFORM_ESP8266)
  857. // ESP8266 also hash it
  858. #define YIELD yield();
  859. #else
  860. #define YIELD
  861. #endif
  862. ////////////////////////////////////////////////////
  863. // digitalPinToInterrupt is not available prior to Arduino 1.5.6 and 1.0.6
  864. // See http://arduino.cc/en/Reference/attachInterrupt
  865. #ifndef NOT_AN_INTERRUPT
  866. #define NOT_AN_INTERRUPT -1
  867. #endif
  868. #ifndef digitalPinToInterrupt
  869. #if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && !defined(__arm__)
  870. #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  871. // Arduino Mega, Mega ADK, Mega Pro
  872. // 2->0, 3->1, 21->2, 20->3, 19->4, 18->5
  873. #define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : ((p) >= 18 && (p) <= 21 ? 23 - (p) : NOT_AN_INTERRUPT)))
  874. #elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)
  875. // Arduino 1284 and 1284P - See Manicbug and Optiboot
  876. // 10->0, 11->1, 2->2
  877. #define digitalPinToInterrupt(p) ((p) == 10 ? 0 : ((p) == 11 ? 1 : ((p) == 2 ? 2 : NOT_AN_INTERRUPT)))
  878. #elif defined(__AVR_ATmega32U4__)
  879. // Leonardo, Yun, Micro, Pro Micro, Flora, Esplora
  880. // 3->0, 2->1, 0->2, 1->3, 7->4
  881. #define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT)))))
  882. #else
  883. // All other arduino except Due:
  884. // Serial Arduino, Extreme, NG, BT, Uno, Diecimila, Duemilanove, Nano, Menta, Pro, Mini 04, Fio, LilyPad, Ethernet etc
  885. // 2->0, 3->1
  886. #define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : NOT_AN_INTERRUPT))
  887. #endif
  888. #elif (RH_PLATFORM == RH_PLATFORM_UNO32) || (RH_PLATFORM == RH_PLATFORM_CHIPKIT_CORE)
  889. // Hmmm, this is correct for Uno32, but what about other boards on ChipKIT Core?
  890. #define digitalPinToInterrupt(p) ((p) == 38 ? 0 : ((p) == 2 ? 1 : ((p) == 7 ? 2 : ((p) == 8 ? 3 : ((p) == 735 ? 4 : NOT_AN_INTERRUPT)))))
  891. #else
  892. // Everything else (including Due and Teensy) interrupt number the same as the interrupt pin number
  893. #define digitalPinToInterrupt(p) (p)
  894. #endif
  895. #endif
  896. // On some platforms, attachInterrupt() takes a pin number, not an interrupt number
  897. #if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined (__arm__) && (defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_SAM_DUE))
  898. #define RH_ATTACHINTERRUPT_TAKES_PIN_NUMBER
  899. #endif
  900. // Slave select pin, some platforms such as ATTiny do not define it.
  901. #ifndef SS
  902. #define SS 10
  903. #endif
  904. // These defs cause trouble on some versions of Arduino
  905. #undef abs
  906. #undef round
  907. #undef double
  908. // Sigh: there is no widespread adoption of htons and friends in the base code, only in some WiFi headers etc
  909. // that have a lot of excess baggage
  910. #if RH_PLATFORM != RH_PLATFORM_UNIX && !defined(htons)
  911. // #ifndef htons
  912. // These predefined macros availble on modern GCC compilers
  913. #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  914. // Atmel processors
  915. #define htons(x) ( ((x)<<8) | (((x)>>8)&0xFF) )
  916. #define ntohs(x) htons(x)
  917. #define htonl(x) ( ((x)<<24 & 0xFF000000UL) | \
  918. ((x)<< 8 & 0x00FF0000UL) | \
  919. ((x)>> 8 & 0x0000FF00UL) | \
  920. ((x)>>24 & 0x000000FFUL) )
  921. #define ntohl(x) htonl(x)
  922. #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  923. // Others
  924. #define htons(x) (x)
  925. #define ntohs(x) (x)
  926. #define htonl(x) (x)
  927. #define ntohl(x) (x)
  928. #else
  929. #error "Dont know how to define htons and friends for this processor"
  930. #endif
  931. #endif
  932. // This is the address that indicates a broadcast
  933. #define RH_BROADCAST_ADDRESS 0xff
  934. #endif