Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of TMRh20 by
RF24.h@0:163155b607df, 2016-03-10 (annotated)
- Committer:
- gume
- Date:
- Thu Mar 10 14:40:30 2016 +0000
- Revision:
- 0:163155b607df
- Child:
- 1:8f889354678f
Initial commit. Imported from the Arduino project
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gume | 0:163155b607df | 1 | /* |
gume | 0:163155b607df | 2 | Copyright (C) 2011 J. Coliz <maniacbug@ymail.com> |
gume | 0:163155b607df | 3 | |
gume | 0:163155b607df | 4 | This program is free software; you can redistribute it and/or |
gume | 0:163155b607df | 5 | modify it under the terms of the GNU General Public License |
gume | 0:163155b607df | 6 | version 2 as published by the Free Software Foundation. |
gume | 0:163155b607df | 7 | */ |
gume | 0:163155b607df | 8 | |
gume | 0:163155b607df | 9 | /** |
gume | 0:163155b607df | 10 | * @file RF24.h |
gume | 0:163155b607df | 11 | * |
gume | 0:163155b607df | 12 | * Class declaration for RF24 and helper enums |
gume | 0:163155b607df | 13 | */ |
gume | 0:163155b607df | 14 | |
gume | 0:163155b607df | 15 | #ifndef __RF24_H__ |
gume | 0:163155b607df | 16 | #define __RF24_H__ |
gume | 0:163155b607df | 17 | |
gume | 0:163155b607df | 18 | #include "mbed.h" |
gume | 0:163155b607df | 19 | #include "RF24_config.h" |
gume | 0:163155b607df | 20 | |
gume | 0:163155b607df | 21 | /** |
gume | 0:163155b607df | 22 | * Power Amplifier level. |
gume | 0:163155b607df | 23 | * |
gume | 0:163155b607df | 24 | * For use with setPALevel() |
gume | 0:163155b607df | 25 | */ |
gume | 0:163155b607df | 26 | typedef enum { RF24_PA_MIN = 0,RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR } rf24_pa_dbm_e ; |
gume | 0:163155b607df | 27 | |
gume | 0:163155b607df | 28 | /** |
gume | 0:163155b607df | 29 | * Data rate. How fast data moves through the air. |
gume | 0:163155b607df | 30 | * |
gume | 0:163155b607df | 31 | * For use with setDataRate() |
gume | 0:163155b607df | 32 | */ |
gume | 0:163155b607df | 33 | typedef enum { RF24_1MBPS = 0, RF24_2MBPS, RF24_250KBPS } rf24_datarate_e; |
gume | 0:163155b607df | 34 | |
gume | 0:163155b607df | 35 | /** |
gume | 0:163155b607df | 36 | * CRC Length. How big (if any) of a CRC is included. |
gume | 0:163155b607df | 37 | * |
gume | 0:163155b607df | 38 | * For use with setCRCLength() |
gume | 0:163155b607df | 39 | */ |
gume | 0:163155b607df | 40 | typedef enum { RF24_CRC_DISABLED = 0, RF24_CRC_8, RF24_CRC_16 } rf24_crclength_e; |
gume | 0:163155b607df | 41 | |
gume | 0:163155b607df | 42 | /** |
gume | 0:163155b607df | 43 | * Driver for nRF24L01(+) 2.4GHz Wireless Transceiver |
gume | 0:163155b607df | 44 | */ |
gume | 0:163155b607df | 45 | |
gume | 0:163155b607df | 46 | class RF24 |
gume | 0:163155b607df | 47 | { |
gume | 0:163155b607df | 48 | private: |
gume | 0:163155b607df | 49 | |
gume | 0:163155b607df | 50 | SPI spi; |
gume | 0:163155b607df | 51 | |
gume | 0:163155b607df | 52 | DigitalOut ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */ |
gume | 0:163155b607df | 53 | DigitalOut csn_pin; /**< SPI Chip select */ |
gume | 0:163155b607df | 54 | uint16_t spi_speed; /**< SPI Bus Speed */ |
gume | 0:163155b607df | 55 | |
gume | 0:163155b607df | 56 | uint8_t spi_rxbuff[32+1] ; //SPI receive buffer (payload max 32 bytes) |
gume | 0:163155b607df | 57 | uint8_t spi_txbuff[32+1] ; //SPI transmit buffer (payload max 32 bytes + 1 byte for the command) |
gume | 0:163155b607df | 58 | |
gume | 0:163155b607df | 59 | bool p_variant; /* False for RF24L01 and true for RF24L01P */ |
gume | 0:163155b607df | 60 | uint8_t payload_size; /**< Fixed size of payloads */ |
gume | 0:163155b607df | 61 | bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */ |
gume | 0:163155b607df | 62 | uint8_t pipe0_reading_address[5]; /**< Last address set on pipe 0 for reading. */ |
gume | 0:163155b607df | 63 | uint8_t addr_width; /**< The address width to use - 3,4 or 5 bytes. */ |
gume | 0:163155b607df | 64 | uint32_t txRxDelay; /**< Var for adjusting delays depending on datarate */ |
gume | 0:163155b607df | 65 | |
gume | 0:163155b607df | 66 | Timer mainTimer; |
gume | 0:163155b607df | 67 | |
gume | 0:163155b607df | 68 | |
gume | 0:163155b607df | 69 | protected: |
gume | 0:163155b607df | 70 | /** |
gume | 0:163155b607df | 71 | * SPI transactions |
gume | 0:163155b607df | 72 | * |
gume | 0:163155b607df | 73 | * Common code for SPI transactions including CSN toggle |
gume | 0:163155b607df | 74 | * |
gume | 0:163155b607df | 75 | */ |
gume | 0:163155b607df | 76 | inline void beginTransaction(); |
gume | 0:163155b607df | 77 | |
gume | 0:163155b607df | 78 | inline void endTransaction(); |
gume | 0:163155b607df | 79 | |
gume | 0:163155b607df | 80 | public: |
gume | 0:163155b607df | 81 | |
gume | 0:163155b607df | 82 | /** |
gume | 0:163155b607df | 83 | * @name Primary public interface |
gume | 0:163155b607df | 84 | * |
gume | 0:163155b607df | 85 | * These are the main methods you need to operate the chip |
gume | 0:163155b607df | 86 | */ |
gume | 0:163155b607df | 87 | /**@{*/ |
gume | 0:163155b607df | 88 | |
gume | 0:163155b607df | 89 | /** |
gume | 0:163155b607df | 90 | * Arduino Constructor |
gume | 0:163155b607df | 91 | * |
gume | 0:163155b607df | 92 | * Creates a new instance of this driver. Before using, you create an instance |
gume | 0:163155b607df | 93 | * and send in the unique pins that this chip is connected to. |
gume | 0:163155b607df | 94 | * |
gume | 0:163155b607df | 95 | * @param _cepin The pin attached to Chip Enable on the RF module |
gume | 0:163155b607df | 96 | * @param _cspin The pin attached to Chip Select |
gume | 0:163155b607df | 97 | */ |
gume | 0:163155b607df | 98 | RF24(PinName mosi, PinName miso, PinName sck, PinName _cepin, PinName _cspin); |
gume | 0:163155b607df | 99 | |
gume | 0:163155b607df | 100 | virtual ~RF24() {}; |
gume | 0:163155b607df | 101 | |
gume | 0:163155b607df | 102 | /** |
gume | 0:163155b607df | 103 | * Begin operation of the chip |
gume | 0:163155b607df | 104 | * |
gume | 0:163155b607df | 105 | * Call this in setup(), before calling any other methods. |
gume | 0:163155b607df | 106 | * @code radio.begin() @endcode |
gume | 0:163155b607df | 107 | */ |
gume | 0:163155b607df | 108 | bool begin(void); |
gume | 0:163155b607df | 109 | |
gume | 0:163155b607df | 110 | /** |
gume | 0:163155b607df | 111 | * Start listening on the pipes opened for reading. |
gume | 0:163155b607df | 112 | * |
gume | 0:163155b607df | 113 | * 1. Be sure to call openReadingPipe() first. |
gume | 0:163155b607df | 114 | * 2. Do not call write() while in this mode, without first calling stopListening(). |
gume | 0:163155b607df | 115 | * 3. Call available() to check for incoming traffic, and read() to get it. |
gume | 0:163155b607df | 116 | * |
gume | 0:163155b607df | 117 | * @code |
gume | 0:163155b607df | 118 | * Open reading pipe 1 using address CCCECCCECC |
gume | 0:163155b607df | 119 | * |
gume | 0:163155b607df | 120 | * byte address[] = { 0xCC,0xCE,0xCC,0xCE,0xCC }; |
gume | 0:163155b607df | 121 | * radio.openReadingPipe(1,address); |
gume | 0:163155b607df | 122 | * radio.startListening(); |
gume | 0:163155b607df | 123 | * @endcode |
gume | 0:163155b607df | 124 | */ |
gume | 0:163155b607df | 125 | void startListening(void); |
gume | 0:163155b607df | 126 | |
gume | 0:163155b607df | 127 | /** |
gume | 0:163155b607df | 128 | * Stop listening for incoming messages, and switch to transmit mode. |
gume | 0:163155b607df | 129 | * |
gume | 0:163155b607df | 130 | * Do this before calling write(). |
gume | 0:163155b607df | 131 | * @code |
gume | 0:163155b607df | 132 | * radio.stopListening(); |
gume | 0:163155b607df | 133 | * radio.write(&data,sizeof(data)); |
gume | 0:163155b607df | 134 | * @endcode |
gume | 0:163155b607df | 135 | */ |
gume | 0:163155b607df | 136 | void stopListening(void); |
gume | 0:163155b607df | 137 | |
gume | 0:163155b607df | 138 | /** |
gume | 0:163155b607df | 139 | * Check whether there are bytes available to be read |
gume | 0:163155b607df | 140 | * @code |
gume | 0:163155b607df | 141 | * if(radio.available()){ |
gume | 0:163155b607df | 142 | * radio.read(&data,sizeof(data)); |
gume | 0:163155b607df | 143 | * } |
gume | 0:163155b607df | 144 | * @endcode |
gume | 0:163155b607df | 145 | * @return True if there is a payload available, false if none is |
gume | 0:163155b607df | 146 | */ |
gume | 0:163155b607df | 147 | bool available(void); |
gume | 0:163155b607df | 148 | |
gume | 0:163155b607df | 149 | /** |
gume | 0:163155b607df | 150 | * Read the available payload |
gume | 0:163155b607df | 151 | * |
gume | 0:163155b607df | 152 | * The size of data read is the fixed payload size, see getPayloadSize() |
gume | 0:163155b607df | 153 | * |
gume | 0:163155b607df | 154 | * @note I specifically chose 'void*' as a data type to make it easier |
gume | 0:163155b607df | 155 | * for beginners to use. No casting needed. |
gume | 0:163155b607df | 156 | * |
gume | 0:163155b607df | 157 | * @note No longer boolean. Use available to determine if packets are |
gume | 0:163155b607df | 158 | * available. Interrupt flags are now cleared during reads instead of |
gume | 0:163155b607df | 159 | * when calling available(). |
gume | 0:163155b607df | 160 | * |
gume | 0:163155b607df | 161 | * @param buf Pointer to a buffer where the data should be written |
gume | 0:163155b607df | 162 | * @param len Maximum number of bytes to read into the buffer |
gume | 0:163155b607df | 163 | * |
gume | 0:163155b607df | 164 | * @code |
gume | 0:163155b607df | 165 | * if(radio.available()){ |
gume | 0:163155b607df | 166 | * radio.read(&data,sizeof(data)); |
gume | 0:163155b607df | 167 | * } |
gume | 0:163155b607df | 168 | * @endcode |
gume | 0:163155b607df | 169 | * @return No return value. Use available(). |
gume | 0:163155b607df | 170 | */ |
gume | 0:163155b607df | 171 | void read( void* buf, uint8_t len ); |
gume | 0:163155b607df | 172 | |
gume | 0:163155b607df | 173 | /** |
gume | 0:163155b607df | 174 | * Be sure to call openWritingPipe() first to set the destination |
gume | 0:163155b607df | 175 | * of where to write to. |
gume | 0:163155b607df | 176 | * |
gume | 0:163155b607df | 177 | * This blocks until the message is successfully acknowledged by |
gume | 0:163155b607df | 178 | * the receiver or the timeout/retransmit maxima are reached. In |
gume | 0:163155b607df | 179 | * the current configuration, the max delay here is 60-70ms. |
gume | 0:163155b607df | 180 | * |
gume | 0:163155b607df | 181 | * The maximum size of data written is the fixed payload size, see |
gume | 0:163155b607df | 182 | * getPayloadSize(). However, you can write less, and the remainder |
gume | 0:163155b607df | 183 | * will just be filled with zeroes. |
gume | 0:163155b607df | 184 | * |
gume | 0:163155b607df | 185 | * TX/RX/RT interrupt flags will be cleared every time write is called |
gume | 0:163155b607df | 186 | * |
gume | 0:163155b607df | 187 | * @param buf Pointer to the data to be sent |
gume | 0:163155b607df | 188 | * @param len Number of bytes to be sent |
gume | 0:163155b607df | 189 | * |
gume | 0:163155b607df | 190 | * @code |
gume | 0:163155b607df | 191 | * radio.stopListening(); |
gume | 0:163155b607df | 192 | * radio.write(&data,sizeof(data)); |
gume | 0:163155b607df | 193 | * @endcode |
gume | 0:163155b607df | 194 | * @return True if the payload was delivered successfully false if not |
gume | 0:163155b607df | 195 | */ |
gume | 0:163155b607df | 196 | bool write( const void* buf, uint8_t len ); |
gume | 0:163155b607df | 197 | |
gume | 0:163155b607df | 198 | /** |
gume | 0:163155b607df | 199 | * New: Open a pipe for writing via byte array. Old addressing format retained |
gume | 0:163155b607df | 200 | * for compatibility. |
gume | 0:163155b607df | 201 | * |
gume | 0:163155b607df | 202 | * Only one writing pipe can be open at once, but you can change the address |
gume | 0:163155b607df | 203 | * you'll write to. Call stopListening() first. |
gume | 0:163155b607df | 204 | * |
gume | 0:163155b607df | 205 | * Addresses are assigned via a byte array, default is 5 byte address length |
gume | 0:163155b607df | 206 | s * |
gume | 0:163155b607df | 207 | * @code |
gume | 0:163155b607df | 208 | * uint8_t addresses[][6] = {"1Node","2Node"}; |
gume | 0:163155b607df | 209 | * radio.openWritingPipe(addresses[0]); |
gume | 0:163155b607df | 210 | * @endcode |
gume | 0:163155b607df | 211 | * @code |
gume | 0:163155b607df | 212 | * uint8_t address[] = { 0xCC,0xCE,0xCC,0xCE,0xCC }; |
gume | 0:163155b607df | 213 | * radio.openWritingPipe(address); |
gume | 0:163155b607df | 214 | * address[0] = 0x33; |
gume | 0:163155b607df | 215 | * radio.openReadingPipe(1,address); |
gume | 0:163155b607df | 216 | * @endcode |
gume | 0:163155b607df | 217 | * @see setAddressWidth |
gume | 0:163155b607df | 218 | * |
gume | 0:163155b607df | 219 | * @param address The address of the pipe to open. Coordinate these pipe |
gume | 0:163155b607df | 220 | * addresses amongst nodes on the network. |
gume | 0:163155b607df | 221 | */ |
gume | 0:163155b607df | 222 | |
gume | 0:163155b607df | 223 | void openWritingPipe(const uint8_t *address); |
gume | 0:163155b607df | 224 | |
gume | 0:163155b607df | 225 | /** |
gume | 0:163155b607df | 226 | * Open a pipe for reading |
gume | 0:163155b607df | 227 | * |
gume | 0:163155b607df | 228 | * Up to 6 pipes can be open for reading at once. Open all the required |
gume | 0:163155b607df | 229 | * reading pipes, and then call startListening(). |
gume | 0:163155b607df | 230 | * |
gume | 0:163155b607df | 231 | * @see openWritingPipe |
gume | 0:163155b607df | 232 | * @see setAddressWidth |
gume | 0:163155b607df | 233 | * |
gume | 0:163155b607df | 234 | * @note Pipes 0 and 1 will store a full 5-byte address. Pipes 2-5 will technically |
gume | 0:163155b607df | 235 | * only store a single byte, borrowing up to 4 additional bytes from pipe #1 per the |
gume | 0:163155b607df | 236 | * assigned address width. |
gume | 0:163155b607df | 237 | * @warning Pipes 1-5 should share the same address, except the first byte. |
gume | 0:163155b607df | 238 | * Only the first byte in the array should be unique, e.g. |
gume | 0:163155b607df | 239 | * @code |
gume | 0:163155b607df | 240 | * uint8_t addresses[][6] = {"1Node","2Node"}; |
gume | 0:163155b607df | 241 | * openReadingPipe(1,addresses[0]); |
gume | 0:163155b607df | 242 | * openReadingPipe(2,addresses[1]); |
gume | 0:163155b607df | 243 | * @endcode |
gume | 0:163155b607df | 244 | * |
gume | 0:163155b607df | 245 | * @warning Pipe 0 is also used by the writing pipe. So if you open |
gume | 0:163155b607df | 246 | * pipe 0 for reading, and then startListening(), it will overwrite the |
gume | 0:163155b607df | 247 | * writing pipe. Ergo, do an openWritingPipe() again before write(). |
gume | 0:163155b607df | 248 | * |
gume | 0:163155b607df | 249 | * @param number Which pipe# to open, 0-5. |
gume | 0:163155b607df | 250 | * @param address The 24, 32 or 40 bit address of the pipe to open. |
gume | 0:163155b607df | 251 | */ |
gume | 0:163155b607df | 252 | |
gume | 0:163155b607df | 253 | void openReadingPipe(uint8_t number, const uint8_t *address); |
gume | 0:163155b607df | 254 | |
gume | 0:163155b607df | 255 | /**@}*/ |
gume | 0:163155b607df | 256 | /** |
gume | 0:163155b607df | 257 | * @name Advanced Operation |
gume | 0:163155b607df | 258 | * |
gume | 0:163155b607df | 259 | * Methods you can use to drive the chip in more advanced ways |
gume | 0:163155b607df | 260 | */ |
gume | 0:163155b607df | 261 | /**@{*/ |
gume | 0:163155b607df | 262 | |
gume | 0:163155b607df | 263 | /** |
gume | 0:163155b607df | 264 | * Print a giant block of debugging information to stdout |
gume | 0:163155b607df | 265 | * |
gume | 0:163155b607df | 266 | * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h |
gume | 0:163155b607df | 267 | * The printf.h file is included with the library for Arduino. |
gume | 0:163155b607df | 268 | * @code |
gume | 0:163155b607df | 269 | * #include <printf.h> |
gume | 0:163155b607df | 270 | * setup(){ |
gume | 0:163155b607df | 271 | * Serial.begin(115200); |
gume | 0:163155b607df | 272 | * printf_begin(); |
gume | 0:163155b607df | 273 | * ... |
gume | 0:163155b607df | 274 | * } |
gume | 0:163155b607df | 275 | * @endcode |
gume | 0:163155b607df | 276 | */ |
gume | 0:163155b607df | 277 | void printDetails(void); |
gume | 0:163155b607df | 278 | |
gume | 0:163155b607df | 279 | /** |
gume | 0:163155b607df | 280 | * Test whether there are bytes available to be read in the |
gume | 0:163155b607df | 281 | * FIFO buffers. |
gume | 0:163155b607df | 282 | * |
gume | 0:163155b607df | 283 | * @param[out] pipe_num Which pipe has the payload available |
gume | 0:163155b607df | 284 | * |
gume | 0:163155b607df | 285 | * @code |
gume | 0:163155b607df | 286 | * uint8_t pipeNum; |
gume | 0:163155b607df | 287 | * if(radio.available(&pipeNum)){ |
gume | 0:163155b607df | 288 | * radio.read(&data,sizeof(data)); |
gume | 0:163155b607df | 289 | * Serial.print("Got data on pipe"); |
gume | 0:163155b607df | 290 | * Serial.println(pipeNum); |
gume | 0:163155b607df | 291 | * } |
gume | 0:163155b607df | 292 | * @endcode |
gume | 0:163155b607df | 293 | * @return True if there is a payload available, false if none is |
gume | 0:163155b607df | 294 | */ |
gume | 0:163155b607df | 295 | bool available(uint8_t* pipe_num); |
gume | 0:163155b607df | 296 | |
gume | 0:163155b607df | 297 | /** |
gume | 0:163155b607df | 298 | * Check if the radio needs to be read. Can be used to prevent data loss |
gume | 0:163155b607df | 299 | * @return True if all three 32-byte radio buffers are full |
gume | 0:163155b607df | 300 | */ |
gume | 0:163155b607df | 301 | bool rxFifoFull(); |
gume | 0:163155b607df | 302 | |
gume | 0:163155b607df | 303 | /** |
gume | 0:163155b607df | 304 | * Enter low-power mode |
gume | 0:163155b607df | 305 | * |
gume | 0:163155b607df | 306 | * To return to normal power mode, call powerUp(). |
gume | 0:163155b607df | 307 | * |
gume | 0:163155b607df | 308 | * @note After calling startListening(), a basic radio will consume about 13.5mA |
gume | 0:163155b607df | 309 | * at max PA level. |
gume | 0:163155b607df | 310 | * During active transmission, the radio will consume about 11.5mA, but this will |
gume | 0:163155b607df | 311 | * be reduced to 26uA (.026mA) between sending. |
gume | 0:163155b607df | 312 | * In full powerDown mode, the radio will consume approximately 900nA (.0009mA) |
gume | 0:163155b607df | 313 | * |
gume | 0:163155b607df | 314 | * @code |
gume | 0:163155b607df | 315 | * radio.powerDown(); |
gume | 0:163155b607df | 316 | * avr_enter_sleep_mode(); // Custom function to sleep the device |
gume | 0:163155b607df | 317 | * radio.powerUp(); |
gume | 0:163155b607df | 318 | * @endcode |
gume | 0:163155b607df | 319 | */ |
gume | 0:163155b607df | 320 | void powerDown(void); |
gume | 0:163155b607df | 321 | |
gume | 0:163155b607df | 322 | /** |
gume | 0:163155b607df | 323 | * Leave low-power mode - required for normal radio operation after calling powerDown() |
gume | 0:163155b607df | 324 | * |
gume | 0:163155b607df | 325 | * To return to low power mode, call powerDown(). |
gume | 0:163155b607df | 326 | * @note This will take up to 5ms for maximum compatibility |
gume | 0:163155b607df | 327 | */ |
gume | 0:163155b607df | 328 | void powerUp(void) ; |
gume | 0:163155b607df | 329 | |
gume | 0:163155b607df | 330 | /** |
gume | 0:163155b607df | 331 | * Write for single NOACK writes. Optionally disables acknowledgements/autoretries for a single write. |
gume | 0:163155b607df | 332 | * |
gume | 0:163155b607df | 333 | * @note enableDynamicAck() must be called to enable this feature |
gume | 0:163155b607df | 334 | * |
gume | 0:163155b607df | 335 | * Can be used with enableAckPayload() to request a response |
gume | 0:163155b607df | 336 | * @see enableDynamicAck() |
gume | 0:163155b607df | 337 | * @see setAutoAck() |
gume | 0:163155b607df | 338 | * @see write() |
gume | 0:163155b607df | 339 | * |
gume | 0:163155b607df | 340 | * @param buf Pointer to the data to be sent |
gume | 0:163155b607df | 341 | * @param len Number of bytes to be sent |
gume | 0:163155b607df | 342 | * @param multicast Request ACK (0), NOACK (1) |
gume | 0:163155b607df | 343 | */ |
gume | 0:163155b607df | 344 | bool write( const void* buf, uint8_t len, const bool multicast ); |
gume | 0:163155b607df | 345 | |
gume | 0:163155b607df | 346 | /** |
gume | 0:163155b607df | 347 | * This will not block until the 3 FIFO buffers are filled with data. |
gume | 0:163155b607df | 348 | * Once the FIFOs are full, writeFast will simply wait for success or |
gume | 0:163155b607df | 349 | * timeout, and return 1 or 0 respectively. From a user perspective, just |
gume | 0:163155b607df | 350 | * keep trying to send the same data. The library will keep auto retrying |
gume | 0:163155b607df | 351 | * the current payload using the built in functionality. |
gume | 0:163155b607df | 352 | * @warning It is important to never keep the nRF24L01 in TX mode and FIFO full for more than 4ms at a time. If the auto |
gume | 0:163155b607df | 353 | * retransmit is enabled, the nRF24L01 is never in TX mode long enough to disobey this rule. Allow the FIFO |
gume | 0:163155b607df | 354 | * to clear by issuing txStandBy() or ensure appropriate time between transmissions. |
gume | 0:163155b607df | 355 | * |
gume | 0:163155b607df | 356 | * @code |
gume | 0:163155b607df | 357 | * Example (Partial blocking): |
gume | 0:163155b607df | 358 | * |
gume | 0:163155b607df | 359 | * radio.writeFast(&buf,32); // Writes 1 payload to the buffers |
gume | 0:163155b607df | 360 | * txStandBy(); // Returns 0 if failed. 1 if success. Blocks only until MAX_RT timeout or success. Data flushed on fail. |
gume | 0:163155b607df | 361 | * |
gume | 0:163155b607df | 362 | * radio.writeFast(&buf,32); // Writes 1 payload to the buffers |
gume | 0:163155b607df | 363 | * txStandBy(1000); // Using extended timeouts, returns 1 if success. Retries failed payloads for 1 seconds before returning 0. |
gume | 0:163155b607df | 364 | * @endcode |
gume | 0:163155b607df | 365 | * |
gume | 0:163155b607df | 366 | * @see txStandBy() |
gume | 0:163155b607df | 367 | * @see write() |
gume | 0:163155b607df | 368 | * @see writeBlocking() |
gume | 0:163155b607df | 369 | * |
gume | 0:163155b607df | 370 | * @param buf Pointer to the data to be sent |
gume | 0:163155b607df | 371 | * @param len Number of bytes to be sent |
gume | 0:163155b607df | 372 | * @return True if the payload was delivered successfully false if not |
gume | 0:163155b607df | 373 | */ |
gume | 0:163155b607df | 374 | bool writeFast( const void* buf, uint8_t len ); |
gume | 0:163155b607df | 375 | |
gume | 0:163155b607df | 376 | /** |
gume | 0:163155b607df | 377 | * WriteFast for single NOACK writes. Disables acknowledgements/autoretries for a single write. |
gume | 0:163155b607df | 378 | * |
gume | 0:163155b607df | 379 | * @note enableDynamicAck() must be called to enable this feature |
gume | 0:163155b607df | 380 | * @see enableDynamicAck() |
gume | 0:163155b607df | 381 | * @see setAutoAck() |
gume | 0:163155b607df | 382 | * |
gume | 0:163155b607df | 383 | * @param buf Pointer to the data to be sent |
gume | 0:163155b607df | 384 | * @param len Number of bytes to be sent |
gume | 0:163155b607df | 385 | * @param multicast Request ACK (0) or NOACK (1) |
gume | 0:163155b607df | 386 | */ |
gume | 0:163155b607df | 387 | bool writeFast( const void* buf, uint8_t len, const bool multicast ); |
gume | 0:163155b607df | 388 | |
gume | 0:163155b607df | 389 | /** |
gume | 0:163155b607df | 390 | * This function extends the auto-retry mechanism to any specified duration. |
gume | 0:163155b607df | 391 | * It will not block until the 3 FIFO buffers are filled with data. |
gume | 0:163155b607df | 392 | * If so the library will auto retry until a new payload is written |
gume | 0:163155b607df | 393 | * or the user specified timeout period is reached. |
gume | 0:163155b607df | 394 | * @warning It is important to never keep the nRF24L01 in TX mode and FIFO full for more than 4ms at a time. If the auto |
gume | 0:163155b607df | 395 | * retransmit is enabled, the nRF24L01 is never in TX mode long enough to disobey this rule. Allow the FIFO |
gume | 0:163155b607df | 396 | * to clear by issuing txStandBy() or ensure appropriate time between transmissions. |
gume | 0:163155b607df | 397 | * |
gume | 0:163155b607df | 398 | * @code |
gume | 0:163155b607df | 399 | * Example (Full blocking): |
gume | 0:163155b607df | 400 | * |
gume | 0:163155b607df | 401 | * radio.writeBlocking(&buf,32,1000); //Wait up to 1 second to write 1 payload to the buffers |
gume | 0:163155b607df | 402 | * txStandBy(1000); //Wait up to 1 second for the payload to send. Return 1 if ok, 0 if failed. |
gume | 0:163155b607df | 403 | * //Blocks only until user timeout or success. Data flushed on fail. |
gume | 0:163155b607df | 404 | * @endcode |
gume | 0:163155b607df | 405 | * @note If used from within an interrupt, the interrupt should be disabled until completion, and sei(); called to enable millis(). |
gume | 0:163155b607df | 406 | * @see txStandBy() |
gume | 0:163155b607df | 407 | * @see write() |
gume | 0:163155b607df | 408 | * @see writeFast() |
gume | 0:163155b607df | 409 | * |
gume | 0:163155b607df | 410 | * @param buf Pointer to the data to be sent |
gume | 0:163155b607df | 411 | * @param len Number of bytes to be sent |
gume | 0:163155b607df | 412 | * @param timeout User defined timeout in milliseconds. |
gume | 0:163155b607df | 413 | * @return True if the payload was loaded into the buffer successfully false if not |
gume | 0:163155b607df | 414 | */ |
gume | 0:163155b607df | 415 | bool writeBlocking( const void* buf, uint8_t len, uint32_t timeout ); |
gume | 0:163155b607df | 416 | |
gume | 0:163155b607df | 417 | /** |
gume | 0:163155b607df | 418 | * This function should be called as soon as transmission is finished to |
gume | 0:163155b607df | 419 | * drop the radio back to STANDBY-I mode. If not issued, the radio will |
gume | 0:163155b607df | 420 | * remain in STANDBY-II mode which, per the data sheet, is not a recommended |
gume | 0:163155b607df | 421 | * operating mode. |
gume | 0:163155b607df | 422 | * |
gume | 0:163155b607df | 423 | * @note When transmitting data in rapid succession, it is still recommended by |
gume | 0:163155b607df | 424 | * the manufacturer to drop the radio out of TX or STANDBY-II mode if there is |
gume | 0:163155b607df | 425 | * time enough between sends for the FIFOs to empty. This is not required if auto-ack |
gume | 0:163155b607df | 426 | * is enabled. |
gume | 0:163155b607df | 427 | * |
gume | 0:163155b607df | 428 | * Relies on built-in auto retry functionality. |
gume | 0:163155b607df | 429 | * |
gume | 0:163155b607df | 430 | * @code |
gume | 0:163155b607df | 431 | * Example (Partial blocking): |
gume | 0:163155b607df | 432 | * |
gume | 0:163155b607df | 433 | * radio.writeFast(&buf,32); |
gume | 0:163155b607df | 434 | * radio.writeFast(&buf,32); |
gume | 0:163155b607df | 435 | * radio.writeFast(&buf,32); //Fills the FIFO buffers up |
gume | 0:163155b607df | 436 | * bool ok = txStandBy(); //Returns 0 if failed. 1 if success. |
gume | 0:163155b607df | 437 | * //Blocks only until MAX_RT timeout or success. Data flushed on fail. |
gume | 0:163155b607df | 438 | * @endcode |
gume | 0:163155b607df | 439 | * @see txStandBy(unsigned long timeout) |
gume | 0:163155b607df | 440 | * @return True if transmission is successful |
gume | 0:163155b607df | 441 | * |
gume | 0:163155b607df | 442 | */ |
gume | 0:163155b607df | 443 | bool txStandBy(); |
gume | 0:163155b607df | 444 | |
gume | 0:163155b607df | 445 | /** |
gume | 0:163155b607df | 446 | * This function allows extended blocking and auto-retries per a user defined timeout |
gume | 0:163155b607df | 447 | * @code |
gume | 0:163155b607df | 448 | * Fully Blocking Example: |
gume | 0:163155b607df | 449 | * |
gume | 0:163155b607df | 450 | * radio.writeFast(&buf,32); |
gume | 0:163155b607df | 451 | * radio.writeFast(&buf,32); |
gume | 0:163155b607df | 452 | * radio.writeFast(&buf,32); //Fills the FIFO buffers up |
gume | 0:163155b607df | 453 | * bool ok = txStandBy(1000); //Returns 0 if failed after 1 second of retries. 1 if success. |
gume | 0:163155b607df | 454 | * //Blocks only until user defined timeout or success. Data flushed on fail. |
gume | 0:163155b607df | 455 | * @endcode |
gume | 0:163155b607df | 456 | * @note If used from within an interrupt, the interrupt should be disabled until completion, and sei(); called to enable millis(). |
gume | 0:163155b607df | 457 | * @param timeout Number of milliseconds to retry failed payloads |
gume | 0:163155b607df | 458 | * @return True if transmission is successful |
gume | 0:163155b607df | 459 | * |
gume | 0:163155b607df | 460 | */ |
gume | 0:163155b607df | 461 | bool txStandBy(uint32_t timeout, bool startTx = 0); |
gume | 0:163155b607df | 462 | |
gume | 0:163155b607df | 463 | /** |
gume | 0:163155b607df | 464 | * Write an ack payload for the specified pipe |
gume | 0:163155b607df | 465 | * |
gume | 0:163155b607df | 466 | * The next time a message is received on @p pipe, the data in @p buf will |
gume | 0:163155b607df | 467 | * be sent back in the acknowledgement. |
gume | 0:163155b607df | 468 | * @see enableAckPayload() |
gume | 0:163155b607df | 469 | * @see enableDynamicPayloads() |
gume | 0:163155b607df | 470 | * @warning Only three of these can be pending at any time as there are only 3 FIFO buffers.<br> Dynamic payloads must be enabled. |
gume | 0:163155b607df | 471 | * @note Ack payloads are handled automatically by the radio chip when a payload is received. Users should generally |
gume | 0:163155b607df | 472 | * write an ack payload as soon as startListening() is called, so one is available when a regular payload is received. |
gume | 0:163155b607df | 473 | * @note Ack payloads are dynamic payloads. This only works on pipes 0&1 by default. Call |
gume | 0:163155b607df | 474 | * enableDynamicPayloads() to enable on all pipes. |
gume | 0:163155b607df | 475 | * |
gume | 0:163155b607df | 476 | * @param pipe Which pipe# (typically 1-5) will get this response. |
gume | 0:163155b607df | 477 | * @param buf Pointer to data that is sent |
gume | 0:163155b607df | 478 | * @param len Length of the data to send, up to 32 bytes max. Not affected |
gume | 0:163155b607df | 479 | * by the static payload set by setPayloadSize(). |
gume | 0:163155b607df | 480 | */ |
gume | 0:163155b607df | 481 | void writeAckPayload(uint8_t pipe, const void* buf, uint8_t len); |
gume | 0:163155b607df | 482 | |
gume | 0:163155b607df | 483 | /** |
gume | 0:163155b607df | 484 | * Determine if an ack payload was received in the most recent call to |
gume | 0:163155b607df | 485 | * write(). The regular available() can also be used. |
gume | 0:163155b607df | 486 | * |
gume | 0:163155b607df | 487 | * Call read() to retrieve the ack payload. |
gume | 0:163155b607df | 488 | * |
gume | 0:163155b607df | 489 | * @return True if an ack payload is available. |
gume | 0:163155b607df | 490 | */ |
gume | 0:163155b607df | 491 | bool isAckPayloadAvailable(void); |
gume | 0:163155b607df | 492 | |
gume | 0:163155b607df | 493 | /** |
gume | 0:163155b607df | 494 | * Call this when you get an interrupt to find out why |
gume | 0:163155b607df | 495 | * |
gume | 0:163155b607df | 496 | * Tells you what caused the interrupt, and clears the state of |
gume | 0:163155b607df | 497 | * interrupts. |
gume | 0:163155b607df | 498 | * |
gume | 0:163155b607df | 499 | * @param[out] tx_ok The send was successful (TX_DS) |
gume | 0:163155b607df | 500 | * @param[out] tx_fail The send failed, too many retries (MAX_RT) |
gume | 0:163155b607df | 501 | * @param[out] rx_ready There is a message waiting to be read (RX_DS) |
gume | 0:163155b607df | 502 | */ |
gume | 0:163155b607df | 503 | void whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready); |
gume | 0:163155b607df | 504 | |
gume | 0:163155b607df | 505 | /** |
gume | 0:163155b607df | 506 | * Non-blocking write to the open writing pipe used for buffered writes |
gume | 0:163155b607df | 507 | * |
gume | 0:163155b607df | 508 | * @note Optimization: This function now leaves the CE pin high, so the radio |
gume | 0:163155b607df | 509 | * will remain in TX or STANDBY-II Mode until a txStandBy() command is issued. Can be used as an alternative to startWrite() |
gume | 0:163155b607df | 510 | * if writing multiple payloads at once. |
gume | 0:163155b607df | 511 | * @warning It is important to never keep the nRF24L01 in TX mode with FIFO full for more than 4ms at a time. If the auto |
gume | 0:163155b607df | 512 | * retransmit/autoAck is enabled, the nRF24L01 is never in TX mode long enough to disobey this rule. Allow the FIFO |
gume | 0:163155b607df | 513 | * to clear by issuing txStandBy() or ensure appropriate time between transmissions. |
gume | 0:163155b607df | 514 | * |
gume | 0:163155b607df | 515 | * @see write() |
gume | 0:163155b607df | 516 | * @see writeFast() |
gume | 0:163155b607df | 517 | * @see startWrite() |
gume | 0:163155b607df | 518 | * @see writeBlocking() |
gume | 0:163155b607df | 519 | * |
gume | 0:163155b607df | 520 | * For single noAck writes see: |
gume | 0:163155b607df | 521 | * @see enableDynamicAck() |
gume | 0:163155b607df | 522 | * @see setAutoAck() |
gume | 0:163155b607df | 523 | * |
gume | 0:163155b607df | 524 | * @param buf Pointer to the data to be sent |
gume | 0:163155b607df | 525 | * @param len Number of bytes to be sent |
gume | 0:163155b607df | 526 | * @param multicast Request ACK (0) or NOACK (1) |
gume | 0:163155b607df | 527 | * @return True if the payload was delivered successfully false if not |
gume | 0:163155b607df | 528 | */ |
gume | 0:163155b607df | 529 | void startFastWrite( const void* buf, uint8_t len, const bool multicast, bool startTx = 1 ); |
gume | 0:163155b607df | 530 | |
gume | 0:163155b607df | 531 | /** |
gume | 0:163155b607df | 532 | * Non-blocking write to the open writing pipe |
gume | 0:163155b607df | 533 | * |
gume | 0:163155b607df | 534 | * Just like write(), but it returns immediately. To find out what happened |
gume | 0:163155b607df | 535 | * to the send, catch the IRQ and then call whatHappened(). |
gume | 0:163155b607df | 536 | * |
gume | 0:163155b607df | 537 | * @see write() |
gume | 0:163155b607df | 538 | * @see writeFast() |
gume | 0:163155b607df | 539 | * @see startFastWrite() |
gume | 0:163155b607df | 540 | * @see whatHappened() |
gume | 0:163155b607df | 541 | * |
gume | 0:163155b607df | 542 | * For single noAck writes see: |
gume | 0:163155b607df | 543 | * @see enableDynamicAck() |
gume | 0:163155b607df | 544 | * @see setAutoAck() |
gume | 0:163155b607df | 545 | * |
gume | 0:163155b607df | 546 | * @param buf Pointer to the data to be sent |
gume | 0:163155b607df | 547 | * @param len Number of bytes to be sent |
gume | 0:163155b607df | 548 | * @param multicast Request ACK (0) or NOACK (1) |
gume | 0:163155b607df | 549 | * |
gume | 0:163155b607df | 550 | */ |
gume | 0:163155b607df | 551 | void startWrite( const void* buf, uint8_t len, const bool multicast ); |
gume | 0:163155b607df | 552 | |
gume | 0:163155b607df | 553 | /** |
gume | 0:163155b607df | 554 | * This function is mainly used internally to take advantage of the auto payload |
gume | 0:163155b607df | 555 | * re-use functionality of the chip, but can be beneficial to users as well. |
gume | 0:163155b607df | 556 | * |
gume | 0:163155b607df | 557 | * The function will instruct the radio to re-use the data in the FIFO buffers, |
gume | 0:163155b607df | 558 | * and instructs the radio to re-send once the timeout limit has been reached. |
gume | 0:163155b607df | 559 | * Used by writeFast and writeBlocking to initiate retries when a TX failure |
gume | 0:163155b607df | 560 | * occurs. Retries are automatically initiated except with the standard write(). |
gume | 0:163155b607df | 561 | * This way, data is not flushed from the buffer until switching between modes. |
gume | 0:163155b607df | 562 | * |
gume | 0:163155b607df | 563 | * @note This is to be used AFTER auto-retry fails if wanting to resend |
gume | 0:163155b607df | 564 | * using the built-in payload reuse features. |
gume | 0:163155b607df | 565 | * After issuing reUseTX(), it will keep reending the same payload forever or until |
gume | 0:163155b607df | 566 | * a payload is written to the FIFO, or a flush_tx command is given. |
gume | 0:163155b607df | 567 | */ |
gume | 0:163155b607df | 568 | void reUseTX(); |
gume | 0:163155b607df | 569 | |
gume | 0:163155b607df | 570 | /** |
gume | 0:163155b607df | 571 | * Empty the transmit buffer. This is generally not required in standard operation. |
gume | 0:163155b607df | 572 | * May be required in specific cases after stopListening() , if operating at 250KBPS data rate. |
gume | 0:163155b607df | 573 | * |
gume | 0:163155b607df | 574 | * @return Current value of status register |
gume | 0:163155b607df | 575 | */ |
gume | 0:163155b607df | 576 | uint8_t flush_tx(void); |
gume | 0:163155b607df | 577 | |
gume | 0:163155b607df | 578 | /** |
gume | 0:163155b607df | 579 | * Test whether there was a carrier on the line for the |
gume | 0:163155b607df | 580 | * previous listening period. |
gume | 0:163155b607df | 581 | * |
gume | 0:163155b607df | 582 | * Useful to check for interference on the current channel. |
gume | 0:163155b607df | 583 | * |
gume | 0:163155b607df | 584 | * @return true if was carrier, false if not |
gume | 0:163155b607df | 585 | */ |
gume | 0:163155b607df | 586 | bool testCarrier(void); |
gume | 0:163155b607df | 587 | |
gume | 0:163155b607df | 588 | /** |
gume | 0:163155b607df | 589 | * Test whether a signal (carrier or otherwise) greater than |
gume | 0:163155b607df | 590 | * or equal to -64dBm is present on the channel. Valid only |
gume | 0:163155b607df | 591 | * on nRF24L01P (+) hardware. On nRF24L01, use testCarrier(). |
gume | 0:163155b607df | 592 | * |
gume | 0:163155b607df | 593 | * Useful to check for interference on the current channel and |
gume | 0:163155b607df | 594 | * channel hopping strategies. |
gume | 0:163155b607df | 595 | * |
gume | 0:163155b607df | 596 | * @code |
gume | 0:163155b607df | 597 | * bool goodSignal = radio.testRPD(); |
gume | 0:163155b607df | 598 | * if(radio.available()){ |
gume | 0:163155b607df | 599 | * Serial.println(goodSignal ? "Strong signal > 64dBm" : "Weak signal < 64dBm" ); |
gume | 0:163155b607df | 600 | * radio.read(0,0); |
gume | 0:163155b607df | 601 | * } |
gume | 0:163155b607df | 602 | * @endcode |
gume | 0:163155b607df | 603 | * @return true if signal => -64dBm, false if not |
gume | 0:163155b607df | 604 | */ |
gume | 0:163155b607df | 605 | bool testRPD(void) ; |
gume | 0:163155b607df | 606 | |
gume | 0:163155b607df | 607 | /** |
gume | 0:163155b607df | 608 | * Test whether this is a real radio, or a mock shim for |
gume | 0:163155b607df | 609 | * debugging. Setting either pin to 0xff is the way to |
gume | 0:163155b607df | 610 | * indicate that this is not a real radio. |
gume | 0:163155b607df | 611 | * |
gume | 0:163155b607df | 612 | * @return true if this is a legitimate radio |
gume | 0:163155b607df | 613 | */ |
gume | 0:163155b607df | 614 | bool isValid() { |
gume | 0:163155b607df | 615 | return ce_pin != 0xff && csn_pin != 0xff; |
gume | 0:163155b607df | 616 | } |
gume | 0:163155b607df | 617 | |
gume | 0:163155b607df | 618 | /** |
gume | 0:163155b607df | 619 | * Close a pipe after it has been previously opened. |
gume | 0:163155b607df | 620 | * Can be safely called without having previously opened a pipe. |
gume | 0:163155b607df | 621 | * @param pipe Which pipe # to close, 0-5. |
gume | 0:163155b607df | 622 | */ |
gume | 0:163155b607df | 623 | void closeReadingPipe( uint8_t pipe ) ; |
gume | 0:163155b607df | 624 | |
gume | 0:163155b607df | 625 | /** |
gume | 0:163155b607df | 626 | * Enable error detection by un-commenting #define FAILURE_HANDLING in RF24_config.h |
gume | 0:163155b607df | 627 | * If a failure has been detected, it usually indicates a hardware issue. By default the library |
gume | 0:163155b607df | 628 | * will cease operation when a failure is detected. |
gume | 0:163155b607df | 629 | * This should allow advanced users to detect and resolve intermittent hardware issues. |
gume | 0:163155b607df | 630 | * |
gume | 0:163155b607df | 631 | * In most cases, the radio must be re-enabled via radio.begin(); and the appropriate settings |
gume | 0:163155b607df | 632 | * applied after a failure occurs, if wanting to re-enable the device immediately. |
gume | 0:163155b607df | 633 | * |
gume | 0:163155b607df | 634 | * Usage: (Failure handling must be enabled per above) |
gume | 0:163155b607df | 635 | * @code |
gume | 0:163155b607df | 636 | * if(radio.failureDetected){ |
gume | 0:163155b607df | 637 | * radio.begin(); // Attempt to re-configure the radio with defaults |
gume | 0:163155b607df | 638 | * radio.failureDetected = 0; // Reset the detection value |
gume | 0:163155b607df | 639 | * radio.openWritingPipe(addresses[1]); // Re-configure pipe addresses |
gume | 0:163155b607df | 640 | * radio.openReadingPipe(1,addresses[0]); |
gume | 0:163155b607df | 641 | * report_failure(); // Blink leds, send a message, etc. to indicate failure |
gume | 0:163155b607df | 642 | * } |
gume | 0:163155b607df | 643 | * @endcode |
gume | 0:163155b607df | 644 | */ |
gume | 0:163155b607df | 645 | //#if defined (FAILURE_HANDLING) |
gume | 0:163155b607df | 646 | bool failureDetected; |
gume | 0:163155b607df | 647 | //#endif |
gume | 0:163155b607df | 648 | |
gume | 0:163155b607df | 649 | /**@}*/ |
gume | 0:163155b607df | 650 | |
gume | 0:163155b607df | 651 | /**@}*/ |
gume | 0:163155b607df | 652 | /** |
gume | 0:163155b607df | 653 | * @name Optional Configurators |
gume | 0:163155b607df | 654 | * |
gume | 0:163155b607df | 655 | * Methods you can use to get or set the configuration of the chip. |
gume | 0:163155b607df | 656 | * None are required. Calling begin() sets up a reasonable set of |
gume | 0:163155b607df | 657 | * defaults. |
gume | 0:163155b607df | 658 | */ |
gume | 0:163155b607df | 659 | /**@{*/ |
gume | 0:163155b607df | 660 | |
gume | 0:163155b607df | 661 | /** |
gume | 0:163155b607df | 662 | * Set the address width from 3 to 5 bytes (24, 32 or 40 bit) |
gume | 0:163155b607df | 663 | * |
gume | 0:163155b607df | 664 | * @param a_width The address width to use: 3,4 or 5 |
gume | 0:163155b607df | 665 | */ |
gume | 0:163155b607df | 666 | |
gume | 0:163155b607df | 667 | void setAddressWidth(uint8_t a_width); |
gume | 0:163155b607df | 668 | |
gume | 0:163155b607df | 669 | /** |
gume | 0:163155b607df | 670 | * Set the number and delay of retries upon failed submit |
gume | 0:163155b607df | 671 | * |
gume | 0:163155b607df | 672 | * @param delay How long to wait between each retry, in multiples of 250us, |
gume | 0:163155b607df | 673 | * max is 15. 0 means 250us, 15 means 4000us. |
gume | 0:163155b607df | 674 | * @param count How many retries before giving up, max 15 |
gume | 0:163155b607df | 675 | */ |
gume | 0:163155b607df | 676 | void setRetries(uint8_t delay, uint8_t count); |
gume | 0:163155b607df | 677 | |
gume | 0:163155b607df | 678 | /** |
gume | 0:163155b607df | 679 | * Set RF communication channel |
gume | 0:163155b607df | 680 | * |
gume | 0:163155b607df | 681 | * @param channel Which RF channel to communicate on, 0-125 |
gume | 0:163155b607df | 682 | */ |
gume | 0:163155b607df | 683 | void setChannel(uint8_t channel); |
gume | 0:163155b607df | 684 | |
gume | 0:163155b607df | 685 | /** |
gume | 0:163155b607df | 686 | * Get RF communication channel |
gume | 0:163155b607df | 687 | * |
gume | 0:163155b607df | 688 | * @return The currently configured RF Channel |
gume | 0:163155b607df | 689 | */ |
gume | 0:163155b607df | 690 | uint8_t getChannel(void); |
gume | 0:163155b607df | 691 | |
gume | 0:163155b607df | 692 | /** |
gume | 0:163155b607df | 693 | * Set Static Payload Size |
gume | 0:163155b607df | 694 | * |
gume | 0:163155b607df | 695 | * This implementation uses a pre-stablished fixed payload size for all |
gume | 0:163155b607df | 696 | * transmissions. If this method is never called, the driver will always |
gume | 0:163155b607df | 697 | * transmit the maximum payload size (32 bytes), no matter how much |
gume | 0:163155b607df | 698 | * was sent to write(). |
gume | 0:163155b607df | 699 | * |
gume | 0:163155b607df | 700 | * @todo Implement variable-sized payloads feature |
gume | 0:163155b607df | 701 | * |
gume | 0:163155b607df | 702 | * @param size The number of bytes in the payload |
gume | 0:163155b607df | 703 | */ |
gume | 0:163155b607df | 704 | void setPayloadSize(uint8_t size); |
gume | 0:163155b607df | 705 | |
gume | 0:163155b607df | 706 | /** |
gume | 0:163155b607df | 707 | * Get Static Payload Size |
gume | 0:163155b607df | 708 | * |
gume | 0:163155b607df | 709 | * @see setPayloadSize() |
gume | 0:163155b607df | 710 | * |
gume | 0:163155b607df | 711 | * @return The number of bytes in the payload |
gume | 0:163155b607df | 712 | */ |
gume | 0:163155b607df | 713 | uint8_t getPayloadSize(void); |
gume | 0:163155b607df | 714 | |
gume | 0:163155b607df | 715 | /** |
gume | 0:163155b607df | 716 | * Get Dynamic Payload Size |
gume | 0:163155b607df | 717 | * |
gume | 0:163155b607df | 718 | * For dynamic payloads, this pulls the size of the payload off |
gume | 0:163155b607df | 719 | * the chip |
gume | 0:163155b607df | 720 | * |
gume | 0:163155b607df | 721 | * @note Corrupt packets are now detected and flushed per the |
gume | 0:163155b607df | 722 | * manufacturer. |
gume | 0:163155b607df | 723 | * @code |
gume | 0:163155b607df | 724 | * if(radio.available()){ |
gume | 0:163155b607df | 725 | * if(radio.getDynamicPayloadSize() < 1){ |
gume | 0:163155b607df | 726 | * // Corrupt payload has been flushed |
gume | 0:163155b607df | 727 | * return; |
gume | 0:163155b607df | 728 | * } |
gume | 0:163155b607df | 729 | * radio.read(&data,sizeof(data)); |
gume | 0:163155b607df | 730 | * } |
gume | 0:163155b607df | 731 | * @endcode |
gume | 0:163155b607df | 732 | * |
gume | 0:163155b607df | 733 | * @return Payload length of last-received dynamic payload |
gume | 0:163155b607df | 734 | */ |
gume | 0:163155b607df | 735 | uint8_t getDynamicPayloadSize(void); |
gume | 0:163155b607df | 736 | |
gume | 0:163155b607df | 737 | /** |
gume | 0:163155b607df | 738 | * Enable custom payloads on the acknowledge packets |
gume | 0:163155b607df | 739 | * |
gume | 0:163155b607df | 740 | * Ack payloads are a handy way to return data back to senders without |
gume | 0:163155b607df | 741 | * manually changing the radio modes on both units. |
gume | 0:163155b607df | 742 | * |
gume | 0:163155b607df | 743 | * @note Ack payloads are dynamic payloads. This only works on pipes 0&1 by default. Call |
gume | 0:163155b607df | 744 | * enableDynamicPayloads() to enable on all pipes. |
gume | 0:163155b607df | 745 | */ |
gume | 0:163155b607df | 746 | void enableAckPayload(void); |
gume | 0:163155b607df | 747 | |
gume | 0:163155b607df | 748 | /** |
gume | 0:163155b607df | 749 | * Enable dynamically-sized payloads |
gume | 0:163155b607df | 750 | * |
gume | 0:163155b607df | 751 | * This way you don't always have to send large packets just to send them |
gume | 0:163155b607df | 752 | * once in a while. This enables dynamic payloads on ALL pipes. |
gume | 0:163155b607df | 753 | * |
gume | 0:163155b607df | 754 | */ |
gume | 0:163155b607df | 755 | void enableDynamicPayloads(void); |
gume | 0:163155b607df | 756 | |
gume | 0:163155b607df | 757 | /** |
gume | 0:163155b607df | 758 | * Enable dynamic ACKs (single write multicast or unicast) for chosen messages |
gume | 0:163155b607df | 759 | * |
gume | 0:163155b607df | 760 | * @note To enable full multicast or per-pipe multicast, use setAutoAck() |
gume | 0:163155b607df | 761 | * |
gume | 0:163155b607df | 762 | * @warning This MUST be called prior to attempting single write NOACK calls |
gume | 0:163155b607df | 763 | * @code |
gume | 0:163155b607df | 764 | * radio.enableDynamicAck(); |
gume | 0:163155b607df | 765 | * radio.write(&data,32,1); // Sends a payload with no acknowledgement requested |
gume | 0:163155b607df | 766 | * radio.write(&data,32,0); // Sends a payload using auto-retry/autoACK |
gume | 0:163155b607df | 767 | * @endcode |
gume | 0:163155b607df | 768 | */ |
gume | 0:163155b607df | 769 | void enableDynamicAck(); |
gume | 0:163155b607df | 770 | |
gume | 0:163155b607df | 771 | /** |
gume | 0:163155b607df | 772 | * Determine whether the hardware is an nRF24L01+ or not. |
gume | 0:163155b607df | 773 | * |
gume | 0:163155b607df | 774 | * @return true if the hardware is nRF24L01+ (or compatible) and false |
gume | 0:163155b607df | 775 | * if its not. |
gume | 0:163155b607df | 776 | */ |
gume | 0:163155b607df | 777 | bool isPVariant(void) ; |
gume | 0:163155b607df | 778 | |
gume | 0:163155b607df | 779 | /** |
gume | 0:163155b607df | 780 | * Enable or disable auto-acknowlede packets |
gume | 0:163155b607df | 781 | * |
gume | 0:163155b607df | 782 | * This is enabled by default, so it's only needed if you want to turn |
gume | 0:163155b607df | 783 | * it off for some reason. |
gume | 0:163155b607df | 784 | * |
gume | 0:163155b607df | 785 | * @param enable Whether to enable (true) or disable (false) auto-acks |
gume | 0:163155b607df | 786 | */ |
gume | 0:163155b607df | 787 | void setAutoAck(bool enable); |
gume | 0:163155b607df | 788 | |
gume | 0:163155b607df | 789 | /** |
gume | 0:163155b607df | 790 | * Enable or disable auto-acknowlede packets on a per pipeline basis. |
gume | 0:163155b607df | 791 | * |
gume | 0:163155b607df | 792 | * AA is enabled by default, so it's only needed if you want to turn |
gume | 0:163155b607df | 793 | * it off/on for some reason on a per pipeline basis. |
gume | 0:163155b607df | 794 | * |
gume | 0:163155b607df | 795 | * @param pipe Which pipeline to modify |
gume | 0:163155b607df | 796 | * @param enable Whether to enable (true) or disable (false) auto-acks |
gume | 0:163155b607df | 797 | */ |
gume | 0:163155b607df | 798 | void setAutoAck( uint8_t pipe, bool enable ) ; |
gume | 0:163155b607df | 799 | |
gume | 0:163155b607df | 800 | /** |
gume | 0:163155b607df | 801 | * Set Power Amplifier (PA) level to one of four levels: |
gume | 0:163155b607df | 802 | * RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX |
gume | 0:163155b607df | 803 | * |
gume | 0:163155b607df | 804 | * The power levels correspond to the following output levels respectively: |
gume | 0:163155b607df | 805 | * NRF24L01: -18dBm, -12dBm,-6dBM, and 0dBm |
gume | 0:163155b607df | 806 | * |
gume | 0:163155b607df | 807 | * SI24R1: -6dBm, 0dBm, 3dBM, and 7dBm. |
gume | 0:163155b607df | 808 | * |
gume | 0:163155b607df | 809 | * @param level Desired PA level. |
gume | 0:163155b607df | 810 | */ |
gume | 0:163155b607df | 811 | void setPALevel ( uint8_t level ); |
gume | 0:163155b607df | 812 | |
gume | 0:163155b607df | 813 | /** |
gume | 0:163155b607df | 814 | * Fetches the current PA level. |
gume | 0:163155b607df | 815 | * |
gume | 0:163155b607df | 816 | * NRF24L01: -18dBm, -12dBm, -6dBm and 0dBm |
gume | 0:163155b607df | 817 | * SI24R1: -6dBm, 0dBm, 3dBm, 7dBm |
gume | 0:163155b607df | 818 | * |
gume | 0:163155b607df | 819 | * @return Returns values 0 to 3 representing the PA Level. |
gume | 0:163155b607df | 820 | */ |
gume | 0:163155b607df | 821 | uint8_t getPALevel( void ); |
gume | 0:163155b607df | 822 | |
gume | 0:163155b607df | 823 | /** |
gume | 0:163155b607df | 824 | * Set the transmission data rate |
gume | 0:163155b607df | 825 | * |
gume | 0:163155b607df | 826 | * @warning setting RF24_250KBPS will fail for non-plus units |
gume | 0:163155b607df | 827 | * |
gume | 0:163155b607df | 828 | * @param speed RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps |
gume | 0:163155b607df | 829 | * @return true if the change was successful |
gume | 0:163155b607df | 830 | */ |
gume | 0:163155b607df | 831 | bool setDataRate(rf24_datarate_e speed); |
gume | 0:163155b607df | 832 | |
gume | 0:163155b607df | 833 | /** |
gume | 0:163155b607df | 834 | * Fetches the transmission data rate |
gume | 0:163155b607df | 835 | * |
gume | 0:163155b607df | 836 | * @return Returns the hardware's currently configured datarate. The value |
gume | 0:163155b607df | 837 | * is one of 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS, as defined in the |
gume | 0:163155b607df | 838 | * rf24_datarate_e enum. |
gume | 0:163155b607df | 839 | */ |
gume | 0:163155b607df | 840 | rf24_datarate_e getDataRate( void ) ; |
gume | 0:163155b607df | 841 | |
gume | 0:163155b607df | 842 | /** |
gume | 0:163155b607df | 843 | * Set the CRC length |
gume | 0:163155b607df | 844 | * <br>CRC checking cannot be disabled if auto-ack is enabled |
gume | 0:163155b607df | 845 | * @param length RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit |
gume | 0:163155b607df | 846 | */ |
gume | 0:163155b607df | 847 | void setCRCLength(rf24_crclength_e length); |
gume | 0:163155b607df | 848 | |
gume | 0:163155b607df | 849 | /** |
gume | 0:163155b607df | 850 | * Get the CRC length |
gume | 0:163155b607df | 851 | * <br>CRC checking cannot be disabled if auto-ack is enabled |
gume | 0:163155b607df | 852 | * @return RF24_DISABLED if disabled or RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit |
gume | 0:163155b607df | 853 | */ |
gume | 0:163155b607df | 854 | rf24_crclength_e getCRCLength(void); |
gume | 0:163155b607df | 855 | |
gume | 0:163155b607df | 856 | /** |
gume | 0:163155b607df | 857 | * Disable CRC validation |
gume | 0:163155b607df | 858 | * |
gume | 0:163155b607df | 859 | * @warning CRC cannot be disabled if auto-ack/ESB is enabled. |
gume | 0:163155b607df | 860 | */ |
gume | 0:163155b607df | 861 | void disableCRC( void ) ; |
gume | 0:163155b607df | 862 | |
gume | 0:163155b607df | 863 | /** |
gume | 0:163155b607df | 864 | * The radio will generate interrupt signals when a transmission is complete, |
gume | 0:163155b607df | 865 | * a transmission fails, or a payload is received. This allows users to mask |
gume | 0:163155b607df | 866 | * those interrupts to prevent them from generating a signal on the interrupt |
gume | 0:163155b607df | 867 | * pin. Interrupts are enabled on the radio chip by default. |
gume | 0:163155b607df | 868 | * |
gume | 0:163155b607df | 869 | * @code |
gume | 0:163155b607df | 870 | * Mask all interrupts except the receive interrupt: |
gume | 0:163155b607df | 871 | * |
gume | 0:163155b607df | 872 | * radio.maskIRQ(1,1,0); |
gume | 0:163155b607df | 873 | * @endcode |
gume | 0:163155b607df | 874 | * |
gume | 0:163155b607df | 875 | * @param tx_ok Mask transmission complete interrupts |
gume | 0:163155b607df | 876 | * @param tx_fail Mask transmit failure interrupts |
gume | 0:163155b607df | 877 | * @param rx_ready Mask payload received interrupts |
gume | 0:163155b607df | 878 | */ |
gume | 0:163155b607df | 879 | void maskIRQ(bool tx_ok,bool tx_fail,bool rx_ready); |
gume | 0:163155b607df | 880 | |
gume | 0:163155b607df | 881 | /**@}*/ |
gume | 0:163155b607df | 882 | /** |
gume | 0:163155b607df | 883 | * @name Deprecated |
gume | 0:163155b607df | 884 | * |
gume | 0:163155b607df | 885 | * Methods provided for backwards compabibility. |
gume | 0:163155b607df | 886 | */ |
gume | 0:163155b607df | 887 | /**@{*/ |
gume | 0:163155b607df | 888 | |
gume | 0:163155b607df | 889 | |
gume | 0:163155b607df | 890 | /** |
gume | 0:163155b607df | 891 | * Open a pipe for reading |
gume | 0:163155b607df | 892 | * @note For compatibility with old code only, see new function |
gume | 0:163155b607df | 893 | * |
gume | 0:163155b607df | 894 | * @warning Pipes 1-5 should share the first 32 bits. |
gume | 0:163155b607df | 895 | * Only the least significant byte should be unique, e.g. |
gume | 0:163155b607df | 896 | * @code |
gume | 0:163155b607df | 897 | * openReadingPipe(1,0xF0F0F0F0AA); |
gume | 0:163155b607df | 898 | * openReadingPipe(2,0xF0F0F0F066); |
gume | 0:163155b607df | 899 | * @endcode |
gume | 0:163155b607df | 900 | * |
gume | 0:163155b607df | 901 | * @warning Pipe 0 is also used by the writing pipe. So if you open |
gume | 0:163155b607df | 902 | * pipe 0 for reading, and then startListening(), it will overwrite the |
gume | 0:163155b607df | 903 | * writing pipe. Ergo, do an openWritingPipe() again before write(). |
gume | 0:163155b607df | 904 | * |
gume | 0:163155b607df | 905 | * @param number Which pipe# to open, 0-5. |
gume | 0:163155b607df | 906 | * @param address The 40-bit address of the pipe to open. |
gume | 0:163155b607df | 907 | */ |
gume | 0:163155b607df | 908 | void openReadingPipe(uint8_t number, uint64_t address); |
gume | 0:163155b607df | 909 | |
gume | 0:163155b607df | 910 | /** |
gume | 0:163155b607df | 911 | * Open a pipe for writing |
gume | 0:163155b607df | 912 | * @note For compatibility with old code only, see new function |
gume | 0:163155b607df | 913 | * |
gume | 0:163155b607df | 914 | * Addresses are 40-bit hex values, e.g.: |
gume | 0:163155b607df | 915 | * |
gume | 0:163155b607df | 916 | * @code |
gume | 0:163155b607df | 917 | * openWritingPipe(0xF0F0F0F0F0); |
gume | 0:163155b607df | 918 | * @endcode |
gume | 0:163155b607df | 919 | * |
gume | 0:163155b607df | 920 | * @param address The 40-bit address of the pipe to open. |
gume | 0:163155b607df | 921 | */ |
gume | 0:163155b607df | 922 | void openWritingPipe(uint64_t address); |
gume | 0:163155b607df | 923 | |
gume | 0:163155b607df | 924 | private: |
gume | 0:163155b607df | 925 | |
gume | 0:163155b607df | 926 | /** |
gume | 0:163155b607df | 927 | * @name Low-level internal interface. |
gume | 0:163155b607df | 928 | * |
gume | 0:163155b607df | 929 | * Protected methods that address the chip directly. Regular users cannot |
gume | 0:163155b607df | 930 | * ever call these. They are documented for completeness and for developers who |
gume | 0:163155b607df | 931 | * may want to extend this class. |
gume | 0:163155b607df | 932 | */ |
gume | 0:163155b607df | 933 | /**@{*/ |
gume | 0:163155b607df | 934 | |
gume | 0:163155b607df | 935 | /** |
gume | 0:163155b607df | 936 | * Set chip select pin |
gume | 0:163155b607df | 937 | * |
gume | 0:163155b607df | 938 | * Running SPI bus at PI_CLOCK_DIV2 so we don't waste time transferring data |
gume | 0:163155b607df | 939 | * and best of all, we make use of the radio's FIFO buffers. A lower speed |
gume | 0:163155b607df | 940 | * means we're less likely to effectively leverage our FIFOs and pay a higher |
gume | 0:163155b607df | 941 | * AVR runtime cost as toll. |
gume | 0:163155b607df | 942 | * |
gume | 0:163155b607df | 943 | * @param mode HIGH to take this unit off the SPI bus, LOW to put it on |
gume | 0:163155b607df | 944 | */ |
gume | 0:163155b607df | 945 | void csn(bool mode); |
gume | 0:163155b607df | 946 | |
gume | 0:163155b607df | 947 | /** |
gume | 0:163155b607df | 948 | * Set chip enable |
gume | 0:163155b607df | 949 | * |
gume | 0:163155b607df | 950 | * @param level HIGH to actively begin transmission or LOW to put in standby. Please see data sheet |
gume | 0:163155b607df | 951 | * for a much more detailed description of this pin. |
gume | 0:163155b607df | 952 | */ |
gume | 0:163155b607df | 953 | void ce(bool level); |
gume | 0:163155b607df | 954 | |
gume | 0:163155b607df | 955 | /** |
gume | 0:163155b607df | 956 | * Read a chunk of data in from a register |
gume | 0:163155b607df | 957 | * |
gume | 0:163155b607df | 958 | * @param reg Which register. Use constants from nRF24L01.h |
gume | 0:163155b607df | 959 | * @param buf Where to put the data |
gume | 0:163155b607df | 960 | * @param len How many bytes of data to transfer |
gume | 0:163155b607df | 961 | * @return Current value of status register |
gume | 0:163155b607df | 962 | */ |
gume | 0:163155b607df | 963 | uint8_t read_register(uint8_t reg, uint8_t* buf, uint8_t len); |
gume | 0:163155b607df | 964 | |
gume | 0:163155b607df | 965 | /** |
gume | 0:163155b607df | 966 | * Read single byte from a register |
gume | 0:163155b607df | 967 | * |
gume | 0:163155b607df | 968 | * @param reg Which register. Use constants from nRF24L01.h |
gume | 0:163155b607df | 969 | * @return Current value of register @p reg |
gume | 0:163155b607df | 970 | */ |
gume | 0:163155b607df | 971 | uint8_t read_register(uint8_t reg); |
gume | 0:163155b607df | 972 | |
gume | 0:163155b607df | 973 | /** |
gume | 0:163155b607df | 974 | * Write a chunk of data to a register |
gume | 0:163155b607df | 975 | * |
gume | 0:163155b607df | 976 | * @param reg Which register. Use constants from nRF24L01.h |
gume | 0:163155b607df | 977 | * @param buf Where to get the data |
gume | 0:163155b607df | 978 | * @param len How many bytes of data to transfer |
gume | 0:163155b607df | 979 | * @return Current value of status register |
gume | 0:163155b607df | 980 | */ |
gume | 0:163155b607df | 981 | uint8_t write_register(uint8_t reg, const uint8_t* buf, uint8_t len); |
gume | 0:163155b607df | 982 | |
gume | 0:163155b607df | 983 | /** |
gume | 0:163155b607df | 984 | * Write a single byte to a register |
gume | 0:163155b607df | 985 | * |
gume | 0:163155b607df | 986 | * @param reg Which register. Use constants from nRF24L01.h |
gume | 0:163155b607df | 987 | * @param value The new value to write |
gume | 0:163155b607df | 988 | * @return Current value of status register |
gume | 0:163155b607df | 989 | */ |
gume | 0:163155b607df | 990 | uint8_t write_register(uint8_t reg, uint8_t value); |
gume | 0:163155b607df | 991 | |
gume | 0:163155b607df | 992 | /** |
gume | 0:163155b607df | 993 | * Write the transmit payload |
gume | 0:163155b607df | 994 | * |
gume | 0:163155b607df | 995 | * The size of data written is the fixed payload size, see getPayloadSize() |
gume | 0:163155b607df | 996 | * |
gume | 0:163155b607df | 997 | * @param buf Where to get the data |
gume | 0:163155b607df | 998 | * @param len Number of bytes to be sent |
gume | 0:163155b607df | 999 | * @return Current value of status register |
gume | 0:163155b607df | 1000 | */ |
gume | 0:163155b607df | 1001 | uint8_t write_payload(const void* buf, uint8_t len, const uint8_t writeType); |
gume | 0:163155b607df | 1002 | |
gume | 0:163155b607df | 1003 | /** |
gume | 0:163155b607df | 1004 | * Read the receive payload |
gume | 0:163155b607df | 1005 | * |
gume | 0:163155b607df | 1006 | * The size of data read is the fixed payload size, see getPayloadSize() |
gume | 0:163155b607df | 1007 | * |
gume | 0:163155b607df | 1008 | * @param buf Where to put the data |
gume | 0:163155b607df | 1009 | * @param len Maximum number of bytes to read |
gume | 0:163155b607df | 1010 | * @return Current value of status register |
gume | 0:163155b607df | 1011 | */ |
gume | 0:163155b607df | 1012 | uint8_t read_payload(void* buf, uint8_t len); |
gume | 0:163155b607df | 1013 | |
gume | 0:163155b607df | 1014 | /** |
gume | 0:163155b607df | 1015 | * Empty the receive buffer |
gume | 0:163155b607df | 1016 | * |
gume | 0:163155b607df | 1017 | * @return Current value of status register |
gume | 0:163155b607df | 1018 | */ |
gume | 0:163155b607df | 1019 | uint8_t flush_rx(void); |
gume | 0:163155b607df | 1020 | |
gume | 0:163155b607df | 1021 | /** |
gume | 0:163155b607df | 1022 | * Retrieve the current status of the chip |
gume | 0:163155b607df | 1023 | * |
gume | 0:163155b607df | 1024 | * @return Current value of status register |
gume | 0:163155b607df | 1025 | */ |
gume | 0:163155b607df | 1026 | uint8_t get_status(void); |
gume | 0:163155b607df | 1027 | |
gume | 0:163155b607df | 1028 | #if !defined (MINIMAL) |
gume | 0:163155b607df | 1029 | /** |
gume | 0:163155b607df | 1030 | * Decode and print the given status to stdout |
gume | 0:163155b607df | 1031 | * |
gume | 0:163155b607df | 1032 | * @param status Status value to print |
gume | 0:163155b607df | 1033 | * |
gume | 0:163155b607df | 1034 | * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h |
gume | 0:163155b607df | 1035 | */ |
gume | 0:163155b607df | 1036 | void print_status(uint8_t status); |
gume | 0:163155b607df | 1037 | |
gume | 0:163155b607df | 1038 | /** |
gume | 0:163155b607df | 1039 | * Decode and print the given 'observe_tx' value to stdout |
gume | 0:163155b607df | 1040 | * |
gume | 0:163155b607df | 1041 | * @param value The observe_tx value to print |
gume | 0:163155b607df | 1042 | * |
gume | 0:163155b607df | 1043 | * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h |
gume | 0:163155b607df | 1044 | */ |
gume | 0:163155b607df | 1045 | void print_observe_tx(uint8_t value); |
gume | 0:163155b607df | 1046 | |
gume | 0:163155b607df | 1047 | /** |
gume | 0:163155b607df | 1048 | * Print the name and value of an 8-bit register to stdout |
gume | 0:163155b607df | 1049 | * |
gume | 0:163155b607df | 1050 | * Optionally it can print some quantity of successive |
gume | 0:163155b607df | 1051 | * registers on the same line. This is useful for printing a group |
gume | 0:163155b607df | 1052 | * of related registers on one line. |
gume | 0:163155b607df | 1053 | * |
gume | 0:163155b607df | 1054 | * @param name Name of the register |
gume | 0:163155b607df | 1055 | * @param reg Which register. Use constants from nRF24L01.h |
gume | 0:163155b607df | 1056 | * @param qty How many successive registers to print |
gume | 0:163155b607df | 1057 | */ |
gume | 0:163155b607df | 1058 | void print_byte_register(const char* name, uint8_t reg, uint8_t qty = 1); |
gume | 0:163155b607df | 1059 | |
gume | 0:163155b607df | 1060 | /** |
gume | 0:163155b607df | 1061 | * Print the name and value of a 40-bit address register to stdout |
gume | 0:163155b607df | 1062 | * |
gume | 0:163155b607df | 1063 | * Optionally it can print some quantity of successive |
gume | 0:163155b607df | 1064 | * registers on the same line. This is useful for printing a group |
gume | 0:163155b607df | 1065 | * of related registers on one line. |
gume | 0:163155b607df | 1066 | * |
gume | 0:163155b607df | 1067 | * @param name Name of the register |
gume | 0:163155b607df | 1068 | * @param reg Which register. Use constants from nRF24L01.h |
gume | 0:163155b607df | 1069 | * @param qty How many successive registers to print |
gume | 0:163155b607df | 1070 | */ |
gume | 0:163155b607df | 1071 | void print_address_register(const char* name, uint8_t reg, uint8_t qty = 1); |
gume | 0:163155b607df | 1072 | #endif |
gume | 0:163155b607df | 1073 | /** |
gume | 0:163155b607df | 1074 | * Turn on or off the special features of the chip |
gume | 0:163155b607df | 1075 | * |
gume | 0:163155b607df | 1076 | * The chip has certain 'features' which are only available when the 'features' |
gume | 0:163155b607df | 1077 | * are enabled. See the datasheet for details. |
gume | 0:163155b607df | 1078 | */ |
gume | 0:163155b607df | 1079 | void toggle_features(void); |
gume | 0:163155b607df | 1080 | |
gume | 0:163155b607df | 1081 | /** |
gume | 0:163155b607df | 1082 | * Built in spi transfer function to simplify repeating code repeating code |
gume | 0:163155b607df | 1083 | */ |
gume | 0:163155b607df | 1084 | |
gume | 0:163155b607df | 1085 | uint8_t spiTrans(uint8_t cmd); |
gume | 0:163155b607df | 1086 | |
gume | 0:163155b607df | 1087 | #if defined (FAILURE_HANDLING) |
gume | 0:163155b607df | 1088 | void errNotify(void); |
gume | 0:163155b607df | 1089 | #endif |
gume | 0:163155b607df | 1090 | |
gume | 0:163155b607df | 1091 | /**@}*/ |
gume | 0:163155b607df | 1092 | |
gume | 0:163155b607df | 1093 | }; |
gume | 0:163155b607df | 1094 | |
gume | 0:163155b607df | 1095 | |
gume | 0:163155b607df | 1096 | #endif // __RF24_H__ |
gume | 0:163155b607df | 1097 |