Maniacbug's nRF24L01+ arduino library ported to mbed. Functional with minor issues.

Committer:
Christilut
Date:
Thu Apr 25 14:45:45 2013 +0000
Revision:
3:b13cafed7ee5
Parent:
2:a483f426d380
Child:
4:491267614a10
-

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Christilut 0:eb5b89f49c35 1 /*
Christilut 0:eb5b89f49c35 2 Copyright (c) 2007 Stefan Engelke <mbox@stefanengelke.de>
Christilut 0:eb5b89f49c35 3
Christilut 2:a483f426d380 4 Permission is hereby granted, free of charge, to any person
Christilut 2:a483f426d380 5 obtaining a copy of this software and associated documentation
Christilut 2:a483f426d380 6 files (the "Software"), to deal in the Software without
Christilut 2:a483f426d380 7 restriction, including without limitation the rights to use, copy,
Christilut 2:a483f426d380 8 modify, merge, publish, distribute, sublicense, and/or sell copies
Christilut 2:a483f426d380 9 of the Software, and to permit persons to whom the Software is
Christilut 0:eb5b89f49c35 10 furnished to do so, subject to the following conditions:
Christilut 0:eb5b89f49c35 11
Christilut 2:a483f426d380 12 The above copyright notice and this permission notice shall be
Christilut 0:eb5b89f49c35 13 included in all copies or substantial portions of the Software.
Christilut 0:eb5b89f49c35 14
Christilut 2:a483f426d380 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Christilut 2:a483f426d380 16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Christilut 2:a483f426d380 17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Christilut 2:a483f426d380 18 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
Christilut 2:a483f426d380 19 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
Christilut 2:a483f426d380 20 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Christilut 2:a483f426d380 21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
Christilut 0:eb5b89f49c35 22 DEALINGS IN THE SOFTWARE.
Christilut 0:eb5b89f49c35 23 */
Christilut 0:eb5b89f49c35 24
Christilut 0:eb5b89f49c35 25 /* Memory Map */
Christilut 0:eb5b89f49c35 26 #define CONFIG 0x00
Christilut 0:eb5b89f49c35 27 #define EN_AA 0x01
Christilut 0:eb5b89f49c35 28 #define EN_RXADDR 0x02
Christilut 0:eb5b89f49c35 29 #define SETUP_AW 0x03
Christilut 0:eb5b89f49c35 30 #define SETUP_RETR 0x04
Christilut 0:eb5b89f49c35 31 #define RF_CH 0x05
Christilut 0:eb5b89f49c35 32 #define RF_SETUP 0x06
Christilut 0:eb5b89f49c35 33 #define STATUS 0x07
Christilut 0:eb5b89f49c35 34 #define OBSERVE_TX 0x08
Christilut 0:eb5b89f49c35 35 #define CD 0x09
Christilut 0:eb5b89f49c35 36 #define RX_ADDR_P0 0x0A
Christilut 0:eb5b89f49c35 37 #define RX_ADDR_P1 0x0B
Christilut 0:eb5b89f49c35 38 #define RX_ADDR_P2 0x0C
Christilut 0:eb5b89f49c35 39 #define RX_ADDR_P3 0x0D
Christilut 0:eb5b89f49c35 40 #define RX_ADDR_P4 0x0E
Christilut 0:eb5b89f49c35 41 #define RX_ADDR_P5 0x0F
Christilut 0:eb5b89f49c35 42 #define TX_ADDR 0x10
Christilut 0:eb5b89f49c35 43 #define RX_PW_P0 0x11
Christilut 0:eb5b89f49c35 44 #define RX_PW_P1 0x12
Christilut 0:eb5b89f49c35 45 #define RX_PW_P2 0x13
Christilut 0:eb5b89f49c35 46 #define RX_PW_P3 0x14
Christilut 0:eb5b89f49c35 47 #define RX_PW_P4 0x15
Christilut 0:eb5b89f49c35 48 #define RX_PW_P5 0x16
Christilut 0:eb5b89f49c35 49 #define FIFO_STATUS 0x17
Christilut 0:eb5b89f49c35 50 #define DYNPD 0x1C
Christilut 0:eb5b89f49c35 51 #define FEATURE 0x1D
Christilut 0:eb5b89f49c35 52
Christilut 0:eb5b89f49c35 53 /* Bit Mnemonics */
Christilut 0:eb5b89f49c35 54 #define MASK_RX_DR 6
Christilut 0:eb5b89f49c35 55 #define MASK_TX_DS 5
Christilut 0:eb5b89f49c35 56 #define MASK_MAX_RT 4
Christilut 0:eb5b89f49c35 57 #define EN_CRC 3
Christilut 0:eb5b89f49c35 58 #define CRCO 2
Christilut 0:eb5b89f49c35 59 #define PWR_UP 1
Christilut 0:eb5b89f49c35 60 #define PRIM_RX 0
Christilut 0:eb5b89f49c35 61 #define ENAA_P5 5
Christilut 0:eb5b89f49c35 62 #define ENAA_P4 4
Christilut 0:eb5b89f49c35 63 #define ENAA_P3 3
Christilut 0:eb5b89f49c35 64 #define ENAA_P2 2
Christilut 0:eb5b89f49c35 65 #define ENAA_P1 1
Christilut 0:eb5b89f49c35 66 #define ENAA_P0 0
Christilut 0:eb5b89f49c35 67 #define ERX_P5 5
Christilut 0:eb5b89f49c35 68 #define ERX_P4 4
Christilut 0:eb5b89f49c35 69 #define ERX_P3 3
Christilut 0:eb5b89f49c35 70 #define ERX_P2 2
Christilut 0:eb5b89f49c35 71 #define ERX_P1 1
Christilut 0:eb5b89f49c35 72 #define ERX_P0 0
Christilut 0:eb5b89f49c35 73 #define AW 0
Christilut 0:eb5b89f49c35 74 #define ARD 4
Christilut 0:eb5b89f49c35 75 #define ARC 0
Christilut 0:eb5b89f49c35 76 #define PLL_LOCK 4
Christilut 0:eb5b89f49c35 77 #define RF_DR 3
Christilut 0:eb5b89f49c35 78 #define RF_PWR 6
Christilut 0:eb5b89f49c35 79 #define RX_DR 6
Christilut 0:eb5b89f49c35 80 #define TX_DS 5
Christilut 0:eb5b89f49c35 81 #define MAX_RT 4
Christilut 0:eb5b89f49c35 82 #define RX_P_NO 1
Christilut 0:eb5b89f49c35 83 #define TX_FULL 0
Christilut 0:eb5b89f49c35 84 #define PLOS_CNT 4
Christilut 0:eb5b89f49c35 85 #define ARC_CNT 0
Christilut 0:eb5b89f49c35 86 #define TX_REUSE 6
Christilut 0:eb5b89f49c35 87 #define FIFO_FULL 5
Christilut 0:eb5b89f49c35 88 #define TX_EMPTY 4
Christilut 0:eb5b89f49c35 89 #define RX_FULL 1
Christilut 0:eb5b89f49c35 90 #define RX_EMPTY 0
Christilut 0:eb5b89f49c35 91 #define DPL_P5 5
Christilut 0:eb5b89f49c35 92 #define DPL_P4 4
Christilut 0:eb5b89f49c35 93 #define DPL_P3 3
Christilut 0:eb5b89f49c35 94 #define DPL_P2 2
Christilut 0:eb5b89f49c35 95 #define DPL_P1 1
Christilut 0:eb5b89f49c35 96 #define DPL_P0 0
Christilut 0:eb5b89f49c35 97 #define EN_DPL 2
Christilut 0:eb5b89f49c35 98 #define EN_ACK_PAY 1
Christilut 0:eb5b89f49c35 99 #define EN_DYN_ACK 0
Christilut 0:eb5b89f49c35 100
Christilut 0:eb5b89f49c35 101 /* Instruction Mnemonics */
Christilut 0:eb5b89f49c35 102 #define R_REGISTER 0x00
Christilut 0:eb5b89f49c35 103 #define W_REGISTER 0x20
Christilut 0:eb5b89f49c35 104 #define REGISTER_MASK 0x1F
Christilut 0:eb5b89f49c35 105 #define ACTIVATE 0x50
Christilut 0:eb5b89f49c35 106 #define R_RX_PL_WID 0x60
Christilut 0:eb5b89f49c35 107 #define R_RX_PAYLOAD 0x61
Christilut 0:eb5b89f49c35 108 #define W_TX_PAYLOAD 0xA0
Christilut 0:eb5b89f49c35 109 #define W_ACK_PAYLOAD 0xA8
Christilut 0:eb5b89f49c35 110 #define FLUSH_TX 0xE1
Christilut 0:eb5b89f49c35 111 #define FLUSH_RX 0xE2
Christilut 0:eb5b89f49c35 112 #define REUSE_TX_PL 0xE3
Christilut 0:eb5b89f49c35 113 #define NOP 0xFF
Christilut 0:eb5b89f49c35 114
Christilut 0:eb5b89f49c35 115 /* Non-P omissions */
Christilut 0:eb5b89f49c35 116 #define LNA_HCURR 0
Christilut 0:eb5b89f49c35 117
Christilut 0:eb5b89f49c35 118 /* P model memory Map */
Christilut 0:eb5b89f49c35 119 #define RPD 0x09
Christilut 0:eb5b89f49c35 120
Christilut 0:eb5b89f49c35 121 /* P model bit Mnemonics */
Christilut 0:eb5b89f49c35 122 #define RF_DR_LOW 5
Christilut 0:eb5b89f49c35 123 #define RF_DR_HIGH 3
Christilut 0:eb5b89f49c35 124 #define RF_PWR_LOW 1
Christilut 0:eb5b89f49c35 125 #define RF_PWR_HIGH 2
Christilut 0:eb5b89f49c35 126
Christilut 2:a483f426d380 127 #define HIGH 1
Christilut 0:eb5b89f49c35 128 #define LOW 0
Christilut 2:a483f426d380 129 #define _BV(n) (1 << n)
Christilut 0:eb5b89f49c35 130
Christilut 0:eb5b89f49c35 131 /*
Christilut 0:eb5b89f49c35 132 Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
Christilut 0:eb5b89f49c35 133
Christilut 0:eb5b89f49c35 134 This program is free software; you can redistribute it and/or
Christilut 0:eb5b89f49c35 135 modify it under the terms of the GNU General Public License
Christilut 0:eb5b89f49c35 136 version 2 as published by the Free Software Foundation.
Christilut 0:eb5b89f49c35 137 */
Christilut 0:eb5b89f49c35 138
Christilut 0:eb5b89f49c35 139 /**
Christilut 0:eb5b89f49c35 140 * @file RF24.h
Christilut 0:eb5b89f49c35 141 *
Christilut 0:eb5b89f49c35 142 * Class declaration for RF24 and helper enums
Christilut 0:eb5b89f49c35 143 */
Christilut 0:eb5b89f49c35 144
Christilut 0:eb5b89f49c35 145 #ifndef __RF24_H__
Christilut 0:eb5b89f49c35 146 #define __RF24_H__
Christilut 0:eb5b89f49c35 147
Christilut 2:a483f426d380 148 #include <mbed.h>
Christilut 0:eb5b89f49c35 149
Christilut 0:eb5b89f49c35 150 /**
Christilut 0:eb5b89f49c35 151 * Power Amplifier level.
Christilut 0:eb5b89f49c35 152 *
Christilut 0:eb5b89f49c35 153 * For use with setPALevel()
Christilut 0:eb5b89f49c35 154 */
Christilut 0:eb5b89f49c35 155 typedef enum { RF24_PA_MIN = 0,RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR } rf24_pa_dbm_e ;
Christilut 0:eb5b89f49c35 156
Christilut 0:eb5b89f49c35 157 /**
Christilut 0:eb5b89f49c35 158 * Data rate. How fast data moves through the air.
Christilut 0:eb5b89f49c35 159 *
Christilut 0:eb5b89f49c35 160 * For use with setDataRate()
Christilut 0:eb5b89f49c35 161 */
Christilut 0:eb5b89f49c35 162 typedef enum { RF24_1MBPS = 0, RF24_2MBPS, RF24_250KBPS } rf24_datarate_e;
Christilut 0:eb5b89f49c35 163
Christilut 0:eb5b89f49c35 164 /**
Christilut 0:eb5b89f49c35 165 * CRC Length. How big (if any) of a CRC is included.
Christilut 0:eb5b89f49c35 166 *
Christilut 0:eb5b89f49c35 167 * For use with setCRCLength()
Christilut 0:eb5b89f49c35 168 */
Christilut 0:eb5b89f49c35 169 typedef enum { RF24_CRC_DISABLED = 0, RF24_CRC_8, RF24_CRC_16 } rf24_crclength_e;
Christilut 0:eb5b89f49c35 170
Christilut 0:eb5b89f49c35 171 /**
Christilut 0:eb5b89f49c35 172 * Driver for nRF24L01(+) 2.4GHz Wireless Transceiver
Christilut 0:eb5b89f49c35 173 */
Christilut 0:eb5b89f49c35 174
Christilut 0:eb5b89f49c35 175 class RF24
Christilut 0:eb5b89f49c35 176 {
Christilut 0:eb5b89f49c35 177 private:
Christilut 0:eb5b89f49c35 178 DigitalOut ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */
Christilut 0:eb5b89f49c35 179 DigitalOut csn_pin; /**< SPI Chip select */
Christilut 0:eb5b89f49c35 180 bool wide_band; /* 2Mbs data rate in use? */
Christilut 0:eb5b89f49c35 181 bool p_variant; /* False for RF24L01 and true for RF24L01P */
Christilut 0:eb5b89f49c35 182 uint8_t payload_size; /**< Fixed size of payloads */
Christilut 0:eb5b89f49c35 183 bool ack_payload_available; /**< Whether there is an ack payload waiting */
Christilut 0:eb5b89f49c35 184 bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */
Christilut 0:eb5b89f49c35 185 uint8_t ack_payload_length; /**< Dynamic size of pending ack payload. */
Christilut 0:eb5b89f49c35 186 uint64_t pipe0_reading_address; /**< Last address set on pipe 0 for reading. */
Christilut 0:eb5b89f49c35 187 SPI spi;
Christilut 0:eb5b89f49c35 188 Timer mainTimer;
Christilut 0:eb5b89f49c35 189
Christilut 0:eb5b89f49c35 190 protected:
Christilut 0:eb5b89f49c35 191 /**
Christilut 0:eb5b89f49c35 192 * @name Low-level internal interface.
Christilut 0:eb5b89f49c35 193 *
Christilut 0:eb5b89f49c35 194 * Protected methods that address the chip directly. Regular users cannot
Christilut 0:eb5b89f49c35 195 * ever call these. They are documented for completeness and for developers who
Christilut 0:eb5b89f49c35 196 * may want to extend this class.
Christilut 0:eb5b89f49c35 197 */
Christilut 0:eb5b89f49c35 198 /**@{*/
Christilut 0:eb5b89f49c35 199
Christilut 0:eb5b89f49c35 200 /**
Christilut 0:eb5b89f49c35 201 * Set chip select pin
Christilut 0:eb5b89f49c35 202 *
Christilut 0:eb5b89f49c35 203 * Running SPI bus at PI_CLOCK_DIV2 so we don't waste time transferring data
Christilut 0:eb5b89f49c35 204 * and best of all, we make use of the radio's FIFO buffers. A lower speed
Christilut 0:eb5b89f49c35 205 * means we're less likely to effectively leverage our FIFOs and pay a higher
Christilut 0:eb5b89f49c35 206 * AVR runtime cost as toll.
Christilut 0:eb5b89f49c35 207 *
Christilut 0:eb5b89f49c35 208 * @param mode HIGH to take this unit off the SPI bus, LOW to put it on
Christilut 0:eb5b89f49c35 209 */
Christilut 0:eb5b89f49c35 210 void csn(int mode);
Christilut 0:eb5b89f49c35 211
Christilut 0:eb5b89f49c35 212 /**
Christilut 0:eb5b89f49c35 213 * Set chip enable
Christilut 0:eb5b89f49c35 214 *
Christilut 0:eb5b89f49c35 215 * @param level HIGH to actively begin transmission or LOW to put in standby. Please see data sheet
Christilut 0:eb5b89f49c35 216 * for a much more detailed description of this pin.
Christilut 0:eb5b89f49c35 217 */
Christilut 0:eb5b89f49c35 218 void ce(int level);
Christilut 0:eb5b89f49c35 219
Christilut 0:eb5b89f49c35 220 /**
Christilut 0:eb5b89f49c35 221 * Read a chunk of data in from a register
Christilut 0:eb5b89f49c35 222 *
Christilut 0:eb5b89f49c35 223 * @param reg Which register. Use constants from nRF24L01.h
Christilut 0:eb5b89f49c35 224 * @param buf Where to put the data
Christilut 0:eb5b89f49c35 225 * @param len How many bytes of data to transfer
Christilut 0:eb5b89f49c35 226 * @return Current value of status register
Christilut 0:eb5b89f49c35 227 */
Christilut 0:eb5b89f49c35 228 uint8_t read_register(uint8_t reg, uint8_t* buf, uint8_t len);
Christilut 0:eb5b89f49c35 229
Christilut 0:eb5b89f49c35 230 /**
Christilut 0:eb5b89f49c35 231 * Read single byte from a register
Christilut 0:eb5b89f49c35 232 *
Christilut 0:eb5b89f49c35 233 * @param reg Which register. Use constants from nRF24L01.h
Christilut 0:eb5b89f49c35 234 * @return Current value of register @p reg
Christilut 0:eb5b89f49c35 235 */
Christilut 0:eb5b89f49c35 236 uint8_t read_register(uint8_t reg);
Christilut 0:eb5b89f49c35 237
Christilut 0:eb5b89f49c35 238 /**
Christilut 0:eb5b89f49c35 239 * Write a chunk of data to a register
Christilut 0:eb5b89f49c35 240 *
Christilut 0:eb5b89f49c35 241 * @param reg Which register. Use constants from nRF24L01.h
Christilut 0:eb5b89f49c35 242 * @param buf Where to get the data
Christilut 0:eb5b89f49c35 243 * @param len How many bytes of data to transfer
Christilut 0:eb5b89f49c35 244 * @return Current value of status register
Christilut 0:eb5b89f49c35 245 */
Christilut 0:eb5b89f49c35 246 uint8_t write_register(uint8_t reg, const uint8_t* buf, uint8_t len);
Christilut 0:eb5b89f49c35 247
Christilut 0:eb5b89f49c35 248 /**
Christilut 0:eb5b89f49c35 249 * Write a single byte to a register
Christilut 0:eb5b89f49c35 250 *
Christilut 0:eb5b89f49c35 251 * @param reg Which register. Use constants from nRF24L01.h
Christilut 0:eb5b89f49c35 252 * @param value The new value to write
Christilut 0:eb5b89f49c35 253 * @return Current value of status register
Christilut 0:eb5b89f49c35 254 */
Christilut 0:eb5b89f49c35 255 uint8_t write_register(uint8_t reg, uint8_t value);
Christilut 0:eb5b89f49c35 256
Christilut 0:eb5b89f49c35 257 /**
Christilut 0:eb5b89f49c35 258 * Write the transmit payload
Christilut 0:eb5b89f49c35 259 *
Christilut 0:eb5b89f49c35 260 * The size of data written is the fixed payload size, see getPayloadSize()
Christilut 0:eb5b89f49c35 261 *
Christilut 0:eb5b89f49c35 262 * @param buf Where to get the data
Christilut 0:eb5b89f49c35 263 * @param len Number of bytes to be sent
Christilut 0:eb5b89f49c35 264 * @return Current value of status register
Christilut 0:eb5b89f49c35 265 */
Christilut 0:eb5b89f49c35 266 uint8_t write_payload(const void* buf, uint8_t len);
Christilut 0:eb5b89f49c35 267
Christilut 0:eb5b89f49c35 268 /**
Christilut 0:eb5b89f49c35 269 * Read the receive payload
Christilut 0:eb5b89f49c35 270 *
Christilut 0:eb5b89f49c35 271 * The size of data read is the fixed payload size, see getPayloadSize()
Christilut 0:eb5b89f49c35 272 *
Christilut 0:eb5b89f49c35 273 * @param buf Where to put the data
Christilut 0:eb5b89f49c35 274 * @param len Maximum number of bytes to read
Christilut 0:eb5b89f49c35 275 * @return Current value of status register
Christilut 0:eb5b89f49c35 276 */
Christilut 0:eb5b89f49c35 277 uint8_t read_payload(void* buf, uint8_t len);
Christilut 0:eb5b89f49c35 278
Christilut 0:eb5b89f49c35 279
Christilut 0:eb5b89f49c35 280
Christilut 0:eb5b89f49c35 281 /**
Christilut 0:eb5b89f49c35 282 * Retrieve the current status of the chip
Christilut 0:eb5b89f49c35 283 *
Christilut 0:eb5b89f49c35 284 * @return Current value of status register
Christilut 0:eb5b89f49c35 285 */
Christilut 0:eb5b89f49c35 286 uint8_t get_status(void);
Christilut 0:eb5b89f49c35 287
Christilut 0:eb5b89f49c35 288 /**
Christilut 0:eb5b89f49c35 289 * Decode and print the given status to stdout
Christilut 0:eb5b89f49c35 290 *
Christilut 0:eb5b89f49c35 291 * @param status Status value to print
Christilut 0:eb5b89f49c35 292 *
Christilut 0:eb5b89f49c35 293 * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
Christilut 0:eb5b89f49c35 294 */
Christilut 0:eb5b89f49c35 295 void print_status(uint8_t status);
Christilut 0:eb5b89f49c35 296
Christilut 0:eb5b89f49c35 297 /**
Christilut 0:eb5b89f49c35 298 * Decode and print the given 'observe_tx' value to stdout
Christilut 0:eb5b89f49c35 299 *
Christilut 0:eb5b89f49c35 300 * @param value The observe_tx value to print
Christilut 0:eb5b89f49c35 301 *
Christilut 0:eb5b89f49c35 302 * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
Christilut 0:eb5b89f49c35 303 */
Christilut 0:eb5b89f49c35 304 void print_observe_tx(uint8_t value);
Christilut 0:eb5b89f49c35 305
Christilut 0:eb5b89f49c35 306 /**
Christilut 0:eb5b89f49c35 307 * Print the name and value of an 8-bit register to stdout
Christilut 0:eb5b89f49c35 308 *
Christilut 0:eb5b89f49c35 309 * Optionally it can print some quantity of successive
Christilut 0:eb5b89f49c35 310 * registers on the same line. This is useful for printing a group
Christilut 0:eb5b89f49c35 311 * of related registers on one line.
Christilut 0:eb5b89f49c35 312 *
Christilut 0:eb5b89f49c35 313 * @param name Name of the register
Christilut 0:eb5b89f49c35 314 * @param reg Which register. Use constants from nRF24L01.h
Christilut 0:eb5b89f49c35 315 * @param qty How many successive registers to print
Christilut 0:eb5b89f49c35 316 */
Christilut 0:eb5b89f49c35 317 void print_byte_register(const char* name, uint8_t reg, uint8_t qty = 1);
Christilut 0:eb5b89f49c35 318
Christilut 0:eb5b89f49c35 319 /**
Christilut 0:eb5b89f49c35 320 * Print the name and value of a 40-bit address register to stdout
Christilut 0:eb5b89f49c35 321 *
Christilut 0:eb5b89f49c35 322 * Optionally it can print some quantity of successive
Christilut 0:eb5b89f49c35 323 * registers on the same line. This is useful for printing a group
Christilut 0:eb5b89f49c35 324 * of related registers on one line.
Christilut 0:eb5b89f49c35 325 *
Christilut 0:eb5b89f49c35 326 * @param name Name of the register
Christilut 0:eb5b89f49c35 327 * @param reg Which register. Use constants from nRF24L01.h
Christilut 0:eb5b89f49c35 328 * @param qty How many successive registers to print
Christilut 0:eb5b89f49c35 329 */
Christilut 0:eb5b89f49c35 330 void print_address_register(const char* name, uint8_t reg, uint8_t qty = 1);
Christilut 0:eb5b89f49c35 331
Christilut 0:eb5b89f49c35 332 /**
Christilut 0:eb5b89f49c35 333 * Turn on or off the special features of the chip
Christilut 0:eb5b89f49c35 334 *
Christilut 0:eb5b89f49c35 335 * The chip has certain 'features' which are only available when the 'features'
Christilut 0:eb5b89f49c35 336 * are enabled. See the datasheet for details.
Christilut 0:eb5b89f49c35 337 */
Christilut 0:eb5b89f49c35 338 void toggle_features(void);
Christilut 0:eb5b89f49c35 339 /**@}*/
Christilut 0:eb5b89f49c35 340
Christilut 0:eb5b89f49c35 341 public:
Christilut 0:eb5b89f49c35 342 /**
Christilut 0:eb5b89f49c35 343 * @name Primary public interface
Christilut 0:eb5b89f49c35 344 *
Christilut 0:eb5b89f49c35 345 * These are the main methods you need to operate the chip
Christilut 0:eb5b89f49c35 346 */
Christilut 0:eb5b89f49c35 347 /**@{*/
Christilut 0:eb5b89f49c35 348
Christilut 0:eb5b89f49c35 349 /**
Christilut 0:eb5b89f49c35 350 * Constructor
Christilut 0:eb5b89f49c35 351 *
Christilut 0:eb5b89f49c35 352 * Creates a new instance of this driver. Before using, you create an instance
Christilut 0:eb5b89f49c35 353 * and send in the unique pins that this chip is connected to.
Christilut 0:eb5b89f49c35 354 *
Christilut 0:eb5b89f49c35 355 * @param _cepin The pin attached to Chip Enable on the RF module
Christilut 0:eb5b89f49c35 356 * @param _cspin The pin attached to Chip Select
Christilut 0:eb5b89f49c35 357 */
Christilut 2:a483f426d380 358 RF24(PinName mosi, PinName miso, PinName sck, PinName _csnpin, PinName _cepin);
Christilut 0:eb5b89f49c35 359
Christilut 3:b13cafed7ee5 360
Christilut 3:b13cafed7ee5 361 /**
Christilut 3:b13cafed7ee5 362 * Empty the receive buffer
Christilut 3:b13cafed7ee5 363 *
Christilut 3:b13cafed7ee5 364 * @return Current value of status register
Christilut 3:b13cafed7ee5 365 */
Christilut 3:b13cafed7ee5 366 uint8_t flush_rx(void);
Christilut 3:b13cafed7ee5 367
Christilut 3:b13cafed7ee5 368 /**
Christilut 3:b13cafed7ee5 369 * Empty the transmit buffer
Christilut 3:b13cafed7ee5 370 *
Christilut 3:b13cafed7ee5 371 * @return Current value of status register
Christilut 3:b13cafed7ee5 372 */
Christilut 3:b13cafed7ee5 373 uint8_t flush_tx(void);
Christilut 0:eb5b89f49c35 374 /**
Christilut 0:eb5b89f49c35 375 * Begin operation of the chip
Christilut 0:eb5b89f49c35 376 *
Christilut 0:eb5b89f49c35 377 * Call this in setup(), before calling any other methods.
Christilut 0:eb5b89f49c35 378 */
Christilut 0:eb5b89f49c35 379 void begin(void);
Christilut 0:eb5b89f49c35 380
Christilut 0:eb5b89f49c35 381 /**
Christilut 0:eb5b89f49c35 382 * Start listening on the pipes opened for reading.
Christilut 0:eb5b89f49c35 383 *
Christilut 0:eb5b89f49c35 384 * Be sure to call openReadingPipe() first. Do not call write() while
Christilut 0:eb5b89f49c35 385 * in this mode, without first calling stopListening(). Call
Christilut 0:eb5b89f49c35 386 * isAvailable() to check for incoming traffic, and read() to get it.
Christilut 0:eb5b89f49c35 387 */
Christilut 0:eb5b89f49c35 388 void startListening(void);
Christilut 0:eb5b89f49c35 389
Christilut 0:eb5b89f49c35 390 /**
Christilut 0:eb5b89f49c35 391 * Stop listening for incoming messages
Christilut 0:eb5b89f49c35 392 *
Christilut 0:eb5b89f49c35 393 * Do this before calling write().
Christilut 0:eb5b89f49c35 394 */
Christilut 0:eb5b89f49c35 395 void stopListening(void);
Christilut 0:eb5b89f49c35 396
Christilut 0:eb5b89f49c35 397 /**
Christilut 0:eb5b89f49c35 398 * Write to the open writing pipe
Christilut 0:eb5b89f49c35 399 *
Christilut 0:eb5b89f49c35 400 * Be sure to call openWritingPipe() first to set the destination
Christilut 0:eb5b89f49c35 401 * of where to write to.
Christilut 0:eb5b89f49c35 402 *
Christilut 0:eb5b89f49c35 403 * This blocks until the message is successfully acknowledged by
Christilut 0:eb5b89f49c35 404 * the receiver or the timeout/retransmit maxima are reached. In
Christilut 0:eb5b89f49c35 405 * the current configuration, the max delay here is 60ms.
Christilut 0:eb5b89f49c35 406 *
Christilut 0:eb5b89f49c35 407 * The maximum size of data written is the fixed payload size, see
Christilut 0:eb5b89f49c35 408 * getPayloadSize(). However, you can write less, and the remainder
Christilut 0:eb5b89f49c35 409 * will just be filled with zeroes.
Christilut 0:eb5b89f49c35 410 *
Christilut 0:eb5b89f49c35 411 * @param buf Pointer to the data to be sent
Christilut 0:eb5b89f49c35 412 * @param len Number of bytes to be sent
Christilut 0:eb5b89f49c35 413 * @return True if the payload was delivered successfully false if not
Christilut 0:eb5b89f49c35 414 */
Christilut 0:eb5b89f49c35 415 bool write( const void* buf, uint8_t len );
Christilut 0:eb5b89f49c35 416
Christilut 0:eb5b89f49c35 417 /**
Christilut 0:eb5b89f49c35 418 * Test whether there are bytes available to be read
Christilut 0:eb5b89f49c35 419 *
Christilut 0:eb5b89f49c35 420 * @return True if there is a payload available, false if none is
Christilut 0:eb5b89f49c35 421 */
Christilut 0:eb5b89f49c35 422 bool available(void);
Christilut 0:eb5b89f49c35 423
Christilut 0:eb5b89f49c35 424 /**
Christilut 0:eb5b89f49c35 425 * Read the payload
Christilut 0:eb5b89f49c35 426 *
Christilut 0:eb5b89f49c35 427 * Return the last payload received
Christilut 0:eb5b89f49c35 428 *
Christilut 0:eb5b89f49c35 429 * The size of data read is the fixed payload size, see getPayloadSize()
Christilut 0:eb5b89f49c35 430 *
Christilut 0:eb5b89f49c35 431 * @note I specifically chose 'void*' as a data type to make it easier
Christilut 0:eb5b89f49c35 432 * for beginners to use. No casting needed.
Christilut 0:eb5b89f49c35 433 *
Christilut 0:eb5b89f49c35 434 * @param buf Pointer to a buffer where the data should be written
Christilut 0:eb5b89f49c35 435 * @param len Maximum number of bytes to read into the buffer
Christilut 0:eb5b89f49c35 436 * @return True if the payload was delivered successfully false if not
Christilut 0:eb5b89f49c35 437 */
Christilut 0:eb5b89f49c35 438 bool read( void* buf, uint8_t len );
Christilut 0:eb5b89f49c35 439
Christilut 0:eb5b89f49c35 440 /**
Christilut 0:eb5b89f49c35 441 * Open a pipe for writing
Christilut 0:eb5b89f49c35 442 *
Christilut 0:eb5b89f49c35 443 * Only one pipe can be open at once, but you can change the pipe
Christilut 0:eb5b89f49c35 444 * you'll listen to. Do not call this while actively listening.
Christilut 0:eb5b89f49c35 445 * Remember to stopListening() first.
Christilut 0:eb5b89f49c35 446 *
Christilut 0:eb5b89f49c35 447 * Addresses are 40-bit hex values, e.g.:
Christilut 0:eb5b89f49c35 448 *
Christilut 0:eb5b89f49c35 449 * @code
Christilut 0:eb5b89f49c35 450 * openWritingPipe(0xF0F0F0F0F0);
Christilut 0:eb5b89f49c35 451 * @endcode
Christilut 0:eb5b89f49c35 452 *
Christilut 0:eb5b89f49c35 453 * @param address The 40-bit address of the pipe to open. This can be
Christilut 0:eb5b89f49c35 454 * any value whatsoever, as long as you are the only one writing to it
Christilut 0:eb5b89f49c35 455 * and only one other radio is listening to it. Coordinate these pipe
Christilut 0:eb5b89f49c35 456 * addresses amongst nodes on the network.
Christilut 0:eb5b89f49c35 457 */
Christilut 0:eb5b89f49c35 458 void openWritingPipe(uint64_t address);
Christilut 0:eb5b89f49c35 459
Christilut 0:eb5b89f49c35 460 /**
Christilut 0:eb5b89f49c35 461 * Open a pipe for reading
Christilut 0:eb5b89f49c35 462 *
Christilut 0:eb5b89f49c35 463 * Up to 6 pipes can be open for reading at once. Open all the
Christilut 0:eb5b89f49c35 464 * reading pipes, and then call startListening().
Christilut 0:eb5b89f49c35 465 *
Christilut 0:eb5b89f49c35 466 * @see openWritingPipe
Christilut 0:eb5b89f49c35 467 *
Christilut 0:eb5b89f49c35 468 * @warning Pipes 1-5 should share the first 32 bits.
Christilut 0:eb5b89f49c35 469 * Only the least significant byte should be unique, e.g.
Christilut 0:eb5b89f49c35 470 * @code
Christilut 0:eb5b89f49c35 471 * openReadingPipe(1,0xF0F0F0F0AA);
Christilut 0:eb5b89f49c35 472 * openReadingPipe(2,0xF0F0F0F066);
Christilut 0:eb5b89f49c35 473 * @endcode
Christilut 0:eb5b89f49c35 474 *
Christilut 0:eb5b89f49c35 475 * @warning Pipe 0 is also used by the writing pipe. So if you open
Christilut 0:eb5b89f49c35 476 * pipe 0 for reading, and then startListening(), it will overwrite the
Christilut 0:eb5b89f49c35 477 * writing pipe. Ergo, do an openWritingPipe() again before write().
Christilut 0:eb5b89f49c35 478 *
Christilut 0:eb5b89f49c35 479 * @todo Enforce the restriction that pipes 1-5 must share the top 32 bits
Christilut 0:eb5b89f49c35 480 *
Christilut 0:eb5b89f49c35 481 * @param number Which pipe# to open, 0-5.
Christilut 0:eb5b89f49c35 482 * @param address The 40-bit address of the pipe to open.
Christilut 0:eb5b89f49c35 483 */
Christilut 0:eb5b89f49c35 484 void openReadingPipe(uint8_t number, uint64_t address);
Christilut 0:eb5b89f49c35 485
Christilut 0:eb5b89f49c35 486 /**@}*/
Christilut 0:eb5b89f49c35 487 /**
Christilut 0:eb5b89f49c35 488 * @name Optional Configurators
Christilut 0:eb5b89f49c35 489 *
Christilut 0:eb5b89f49c35 490 * Methods you can use to get or set the configuration of the chip.
Christilut 0:eb5b89f49c35 491 * None are required. Calling begin() sets up a reasonable set of
Christilut 0:eb5b89f49c35 492 * defaults.
Christilut 0:eb5b89f49c35 493 */
Christilut 0:eb5b89f49c35 494 /**@{*/
Christilut 0:eb5b89f49c35 495 /**
Christilut 0:eb5b89f49c35 496 * Set the number and delay of retries upon failed submit
Christilut 0:eb5b89f49c35 497 *
Christilut 0:eb5b89f49c35 498 * @param delay How long to wait between each retry, in multiples of 250us,
Christilut 0:eb5b89f49c35 499 * max is 15. 0 means 250us, 15 means 4000us.
Christilut 0:eb5b89f49c35 500 * @param count How many retries before giving up, max 15
Christilut 0:eb5b89f49c35 501 */
Christilut 0:eb5b89f49c35 502 void setRetries(uint8_t delay, uint8_t count);
Christilut 0:eb5b89f49c35 503
Christilut 0:eb5b89f49c35 504 /**
Christilut 0:eb5b89f49c35 505 * Set RF communication channel
Christilut 0:eb5b89f49c35 506 *
Christilut 0:eb5b89f49c35 507 * @param channel Which RF channel to communicate on, 0-127
Christilut 0:eb5b89f49c35 508 */
Christilut 0:eb5b89f49c35 509 void setChannel(uint8_t channel);
Christilut 0:eb5b89f49c35 510
Christilut 0:eb5b89f49c35 511 /**
Christilut 0:eb5b89f49c35 512 * Set Static Payload Size
Christilut 0:eb5b89f49c35 513 *
Christilut 0:eb5b89f49c35 514 * This implementation uses a pre-stablished fixed payload size for all
Christilut 0:eb5b89f49c35 515 * transmissions. If this method is never called, the driver will always
Christilut 0:eb5b89f49c35 516 * transmit the maximum payload size (32 bytes), no matter how much
Christilut 0:eb5b89f49c35 517 * was sent to write().
Christilut 0:eb5b89f49c35 518 *
Christilut 0:eb5b89f49c35 519 * @todo Implement variable-sized payloads feature
Christilut 0:eb5b89f49c35 520 *
Christilut 0:eb5b89f49c35 521 * @param size The number of bytes in the payload
Christilut 0:eb5b89f49c35 522 */
Christilut 0:eb5b89f49c35 523 void setPayloadSize(uint8_t size);
Christilut 0:eb5b89f49c35 524
Christilut 0:eb5b89f49c35 525 /**
Christilut 0:eb5b89f49c35 526 * Get Static Payload Size
Christilut 0:eb5b89f49c35 527 *
Christilut 0:eb5b89f49c35 528 * @see setPayloadSize()
Christilut 0:eb5b89f49c35 529 *
Christilut 0:eb5b89f49c35 530 * @return The number of bytes in the payload
Christilut 0:eb5b89f49c35 531 */
Christilut 0:eb5b89f49c35 532 uint8_t getPayloadSize(void);
Christilut 0:eb5b89f49c35 533
Christilut 0:eb5b89f49c35 534 /**
Christilut 0:eb5b89f49c35 535 * Get Dynamic Payload Size
Christilut 0:eb5b89f49c35 536 *
Christilut 0:eb5b89f49c35 537 * For dynamic payloads, this pulls the size of the payload off
Christilut 0:eb5b89f49c35 538 * the chip
Christilut 0:eb5b89f49c35 539 *
Christilut 0:eb5b89f49c35 540 * @return Payload length of last-received dynamic payload
Christilut 0:eb5b89f49c35 541 */
Christilut 0:eb5b89f49c35 542 uint8_t getDynamicPayloadSize(void);
Christilut 0:eb5b89f49c35 543
Christilut 0:eb5b89f49c35 544 /**
Christilut 0:eb5b89f49c35 545 * Enable custom payloads on the acknowledge packets
Christilut 0:eb5b89f49c35 546 *
Christilut 0:eb5b89f49c35 547 * Ack payloads are a handy way to return data back to senders without
Christilut 0:eb5b89f49c35 548 * manually changing the radio modes on both units.
Christilut 0:eb5b89f49c35 549 *
Christilut 0:eb5b89f49c35 550 * @see examples/pingpair_pl/pingpair_pl.pde
Christilut 0:eb5b89f49c35 551 */
Christilut 0:eb5b89f49c35 552 void enableAckPayload(void);
Christilut 0:eb5b89f49c35 553
Christilut 0:eb5b89f49c35 554 /**
Christilut 0:eb5b89f49c35 555 * Enable dynamically-sized payloads
Christilut 0:eb5b89f49c35 556 *
Christilut 0:eb5b89f49c35 557 * This way you don't always have to send large packets just to send them
Christilut 0:eb5b89f49c35 558 * once in a while. This enables dynamic payloads on ALL pipes.
Christilut 0:eb5b89f49c35 559 *
Christilut 0:eb5b89f49c35 560 * @see examples/pingpair_pl/pingpair_dyn.pde
Christilut 0:eb5b89f49c35 561 */
Christilut 0:eb5b89f49c35 562 void enableDynamicPayloads(void);
Christilut 0:eb5b89f49c35 563
Christilut 0:eb5b89f49c35 564 /**
Christilut 0:eb5b89f49c35 565 * Determine whether the hardware is an nRF24L01+ or not.
Christilut 0:eb5b89f49c35 566 *
Christilut 0:eb5b89f49c35 567 * @return true if the hardware is nRF24L01+ (or compatible) and false
Christilut 0:eb5b89f49c35 568 * if its not.
Christilut 0:eb5b89f49c35 569 */
Christilut 0:eb5b89f49c35 570 bool isPVariant(void) ;
Christilut 0:eb5b89f49c35 571
Christilut 0:eb5b89f49c35 572 /**
Christilut 0:eb5b89f49c35 573 * Enable or disable auto-acknowlede packets
Christilut 0:eb5b89f49c35 574 *
Christilut 0:eb5b89f49c35 575 * This is enabled by default, so it's only needed if you want to turn
Christilut 0:eb5b89f49c35 576 * it off for some reason.
Christilut 0:eb5b89f49c35 577 *
Christilut 0:eb5b89f49c35 578 * @param enable Whether to enable (true) or disable (false) auto-acks
Christilut 0:eb5b89f49c35 579 */
Christilut 0:eb5b89f49c35 580 void setAutoAck(bool enable);
Christilut 0:eb5b89f49c35 581
Christilut 0:eb5b89f49c35 582 /**
Christilut 0:eb5b89f49c35 583 * Enable or disable auto-acknowlede packets on a per pipeline basis.
Christilut 0:eb5b89f49c35 584 *
Christilut 0:eb5b89f49c35 585 * AA is enabled by default, so it's only needed if you want to turn
Christilut 0:eb5b89f49c35 586 * it off/on for some reason on a per pipeline basis.
Christilut 0:eb5b89f49c35 587 *
Christilut 0:eb5b89f49c35 588 * @param pipe Which pipeline to modify
Christilut 0:eb5b89f49c35 589 * @param enable Whether to enable (true) or disable (false) auto-acks
Christilut 0:eb5b89f49c35 590 */
Christilut 0:eb5b89f49c35 591 void setAutoAck( uint8_t pipe, bool enable ) ;
Christilut 0:eb5b89f49c35 592
Christilut 0:eb5b89f49c35 593 /**
Christilut 0:eb5b89f49c35 594 * Set Power Amplifier (PA) level to one of four levels.
Christilut 0:eb5b89f49c35 595 * Relative mnemonics have been used to allow for future PA level
Christilut 0:eb5b89f49c35 596 * changes. According to 6.5 of the nRF24L01+ specification sheet,
Christilut 0:eb5b89f49c35 597 * they translate to: RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm,
Christilut 0:eb5b89f49c35 598 * RF24_PA_MED=-6dBM, and RF24_PA_HIGH=0dBm.
Christilut 0:eb5b89f49c35 599 *
Christilut 0:eb5b89f49c35 600 * @param level Desired PA level.
Christilut 0:eb5b89f49c35 601 */
Christilut 0:eb5b89f49c35 602 void setPALevel( rf24_pa_dbm_e level ) ;
Christilut 0:eb5b89f49c35 603
Christilut 0:eb5b89f49c35 604 /**
Christilut 0:eb5b89f49c35 605 * Fetches the current PA level.
Christilut 0:eb5b89f49c35 606 *
Christilut 0:eb5b89f49c35 607 * @return Returns a value from the rf24_pa_dbm_e enum describing
Christilut 0:eb5b89f49c35 608 * the current PA setting. Please remember, all values represented
Christilut 0:eb5b89f49c35 609 * by the enum mnemonics are negative dBm. See setPALevel for
Christilut 0:eb5b89f49c35 610 * return value descriptions.
Christilut 0:eb5b89f49c35 611 */
Christilut 0:eb5b89f49c35 612 rf24_pa_dbm_e getPALevel( void ) ;
Christilut 0:eb5b89f49c35 613
Christilut 0:eb5b89f49c35 614 /**
Christilut 0:eb5b89f49c35 615 * Set the transmission data rate
Christilut 0:eb5b89f49c35 616 *
Christilut 0:eb5b89f49c35 617 * @warning setting RF24_250KBPS will fail for non-plus units
Christilut 0:eb5b89f49c35 618 *
Christilut 0:eb5b89f49c35 619 * @param speed RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
Christilut 0:eb5b89f49c35 620 * @return true if the change was successful
Christilut 0:eb5b89f49c35 621 */
Christilut 0:eb5b89f49c35 622 bool setDataRate(rf24_datarate_e speed);
Christilut 0:eb5b89f49c35 623
Christilut 0:eb5b89f49c35 624 /**
Christilut 0:eb5b89f49c35 625 * Fetches the transmission data rate
Christilut 0:eb5b89f49c35 626 *
Christilut 0:eb5b89f49c35 627 * @return Returns the hardware's currently configured datarate. The value
Christilut 0:eb5b89f49c35 628 * is one of 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS, as defined in the
Christilut 0:eb5b89f49c35 629 * rf24_datarate_e enum.
Christilut 0:eb5b89f49c35 630 */
Christilut 0:eb5b89f49c35 631 rf24_datarate_e getDataRate( void ) ;
Christilut 0:eb5b89f49c35 632
Christilut 0:eb5b89f49c35 633 /**
Christilut 0:eb5b89f49c35 634 * Set the CRC length
Christilut 0:eb5b89f49c35 635 *
Christilut 0:eb5b89f49c35 636 * @param length RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit
Christilut 0:eb5b89f49c35 637 */
Christilut 0:eb5b89f49c35 638 void setCRCLength(rf24_crclength_e length);
Christilut 0:eb5b89f49c35 639
Christilut 0:eb5b89f49c35 640 /**
Christilut 0:eb5b89f49c35 641 * Get the CRC length
Christilut 0:eb5b89f49c35 642 *
Christilut 0:eb5b89f49c35 643 * @return RF24_DISABLED if disabled or RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit
Christilut 0:eb5b89f49c35 644 */
Christilut 0:eb5b89f49c35 645 rf24_crclength_e getCRCLength(void);
Christilut 0:eb5b89f49c35 646
Christilut 0:eb5b89f49c35 647 /**
Christilut 0:eb5b89f49c35 648 * Disable CRC validation
Christilut 0:eb5b89f49c35 649 *
Christilut 0:eb5b89f49c35 650 */
Christilut 0:eb5b89f49c35 651 void disableCRC( void ) ;
Christilut 0:eb5b89f49c35 652
Christilut 0:eb5b89f49c35 653 /**@}*/
Christilut 0:eb5b89f49c35 654 /**
Christilut 0:eb5b89f49c35 655 * @name Advanced Operation
Christilut 0:eb5b89f49c35 656 *
Christilut 0:eb5b89f49c35 657 * Methods you can use to drive the chip in more advanced ways
Christilut 0:eb5b89f49c35 658 */
Christilut 0:eb5b89f49c35 659 /**@{*/
Christilut 0:eb5b89f49c35 660
Christilut 0:eb5b89f49c35 661 /**
Christilut 0:eb5b89f49c35 662 * Print a giant block of debugging information to stdout
Christilut 0:eb5b89f49c35 663 *
Christilut 0:eb5b89f49c35 664 * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
Christilut 0:eb5b89f49c35 665 */
Christilut 0:eb5b89f49c35 666 void printDetails(void);
Christilut 0:eb5b89f49c35 667
Christilut 0:eb5b89f49c35 668 /**
Christilut 0:eb5b89f49c35 669 * Enter low-power mode
Christilut 0:eb5b89f49c35 670 *
Christilut 0:eb5b89f49c35 671 * To return to normal power mode, either write() some data or
Christilut 0:eb5b89f49c35 672 * startListening, or powerUp().
Christilut 0:eb5b89f49c35 673 */
Christilut 0:eb5b89f49c35 674 void powerDown(void);
Christilut 0:eb5b89f49c35 675
Christilut 0:eb5b89f49c35 676 /**
Christilut 0:eb5b89f49c35 677 * Leave low-power mode - making radio more responsive
Christilut 0:eb5b89f49c35 678 *
Christilut 0:eb5b89f49c35 679 * To return to low power mode, call powerDown().
Christilut 0:eb5b89f49c35 680 */
Christilut 0:eb5b89f49c35 681 void powerUp(void) ;
Christilut 0:eb5b89f49c35 682
Christilut 0:eb5b89f49c35 683 /**
Christilut 0:eb5b89f49c35 684 * Test whether there are bytes available to be read
Christilut 0:eb5b89f49c35 685 *
Christilut 0:eb5b89f49c35 686 * Use this version to discover on which pipe the message
Christilut 0:eb5b89f49c35 687 * arrived.
Christilut 0:eb5b89f49c35 688 *
Christilut 0:eb5b89f49c35 689 * @param[out] pipe_num Which pipe has the payload available
Christilut 0:eb5b89f49c35 690 * @return True if there is a payload available, false if none is
Christilut 0:eb5b89f49c35 691 */
Christilut 0:eb5b89f49c35 692 bool available(uint8_t* pipe_num);
Christilut 0:eb5b89f49c35 693
Christilut 0:eb5b89f49c35 694 /**
Christilut 0:eb5b89f49c35 695 * Non-blocking write to the open writing pipe
Christilut 0:eb5b89f49c35 696 *
Christilut 0:eb5b89f49c35 697 * Just like write(), but it returns immediately. To find out what happened
Christilut 0:eb5b89f49c35 698 * to the send, catch the IRQ and then call whatHappened().
Christilut 0:eb5b89f49c35 699 *
Christilut 0:eb5b89f49c35 700 * @see write()
Christilut 0:eb5b89f49c35 701 * @see whatHappened()
Christilut 0:eb5b89f49c35 702 *
Christilut 0:eb5b89f49c35 703 * @param buf Pointer to the data to be sent
Christilut 0:eb5b89f49c35 704 * @param len Number of bytes to be sent
Christilut 0:eb5b89f49c35 705 * @return True if the payload was delivered successfully false if not
Christilut 0:eb5b89f49c35 706 */
Christilut 0:eb5b89f49c35 707 void startWrite( const void* buf, uint8_t len );
Christilut 0:eb5b89f49c35 708
Christilut 0:eb5b89f49c35 709 /**
Christilut 0:eb5b89f49c35 710 * Write an ack payload for the specified pipe
Christilut 0:eb5b89f49c35 711 *
Christilut 0:eb5b89f49c35 712 * The next time a message is received on @p pipe, the data in @p buf will
Christilut 0:eb5b89f49c35 713 * be sent back in the acknowledgement.
Christilut 0:eb5b89f49c35 714 *
Christilut 0:eb5b89f49c35 715 * @warning According to the data sheet, only three of these can be pending
Christilut 0:eb5b89f49c35 716 * at any time. I have not tested this.
Christilut 0:eb5b89f49c35 717 *
Christilut 0:eb5b89f49c35 718 * @param pipe Which pipe# (typically 1-5) will get this response.
Christilut 0:eb5b89f49c35 719 * @param buf Pointer to data that is sent
Christilut 0:eb5b89f49c35 720 * @param len Length of the data to send, up to 32 bytes max. Not affected
Christilut 0:eb5b89f49c35 721 * by the static payload set by setPayloadSize().
Christilut 0:eb5b89f49c35 722 */
Christilut 0:eb5b89f49c35 723 void writeAckPayload(uint8_t pipe, const void* buf, uint8_t len);
Christilut 0:eb5b89f49c35 724
Christilut 0:eb5b89f49c35 725 /**
Christilut 0:eb5b89f49c35 726 * Determine if an ack payload was received in the most recent call to
Christilut 0:eb5b89f49c35 727 * write().
Christilut 0:eb5b89f49c35 728 *
Christilut 0:eb5b89f49c35 729 * Call read() to retrieve the ack payload.
Christilut 0:eb5b89f49c35 730 *
Christilut 0:eb5b89f49c35 731 * @warning Calling this function clears the internal flag which indicates
Christilut 0:eb5b89f49c35 732 * a payload is available. If it returns true, you must read the packet
Christilut 0:eb5b89f49c35 733 * out as the very next interaction with the radio, or the results are
Christilut 0:eb5b89f49c35 734 * undefined.
Christilut 0:eb5b89f49c35 735 *
Christilut 0:eb5b89f49c35 736 * @return True if an ack payload is available.
Christilut 0:eb5b89f49c35 737 */
Christilut 0:eb5b89f49c35 738 bool isAckPayloadAvailable(void);
Christilut 0:eb5b89f49c35 739
Christilut 0:eb5b89f49c35 740 /**
Christilut 0:eb5b89f49c35 741 * Call this when you get an interrupt to find out why
Christilut 0:eb5b89f49c35 742 *
Christilut 0:eb5b89f49c35 743 * Tells you what caused the interrupt, and clears the state of
Christilut 0:eb5b89f49c35 744 * interrupts.
Christilut 0:eb5b89f49c35 745 *
Christilut 0:eb5b89f49c35 746 * @param[out] tx_ok The send was successful (TX_DS)
Christilut 0:eb5b89f49c35 747 * @param[out] tx_fail The send failed, too many retries (MAX_RT)
Christilut 0:eb5b89f49c35 748 * @param[out] rx_ready There is a message waiting to be read (RX_DS)
Christilut 0:eb5b89f49c35 749 */
Christilut 0:eb5b89f49c35 750 void whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready);
Christilut 0:eb5b89f49c35 751
Christilut 0:eb5b89f49c35 752 /**
Christilut 0:eb5b89f49c35 753 * Test whether there was a carrier on the line for the
Christilut 0:eb5b89f49c35 754 * previous listening period.
Christilut 0:eb5b89f49c35 755 *
Christilut 0:eb5b89f49c35 756 * Useful to check for interference on the current channel.
Christilut 0:eb5b89f49c35 757 *
Christilut 0:eb5b89f49c35 758 * @return true if was carrier, false if not
Christilut 0:eb5b89f49c35 759 */
Christilut 0:eb5b89f49c35 760 bool testCarrier(void);
Christilut 0:eb5b89f49c35 761
Christilut 0:eb5b89f49c35 762 /**
Christilut 0:eb5b89f49c35 763 * Test whether a signal (carrier or otherwise) greater than
Christilut 0:eb5b89f49c35 764 * or equal to -64dBm is present on the channel. Valid only
Christilut 0:eb5b89f49c35 765 * on nRF24L01P (+) hardware. On nRF24L01, use testCarrier().
Christilut 0:eb5b89f49c35 766 *
Christilut 0:eb5b89f49c35 767 * Useful to check for interference on the current channel and
Christilut 0:eb5b89f49c35 768 * channel hopping strategies.
Christilut 0:eb5b89f49c35 769 *
Christilut 0:eb5b89f49c35 770 * @return true if signal => -64dBm, false if not
Christilut 0:eb5b89f49c35 771 */
Christilut 0:eb5b89f49c35 772 bool testRPD(void) ;
Christilut 0:eb5b89f49c35 773
Christilut 2:a483f426d380 774 uint8_t min(uint8_t, uint8_t);
Christilut 0:eb5b89f49c35 775 };
Christilut 0:eb5b89f49c35 776
Christilut 0:eb5b89f49c35 777
Christilut 2:a483f426d380 778 #endif // __RF24_H__
Christilut 2:a483f426d380 779 // vim:ai:cin:sts=2 sw=2 ft=cpp