no modif

Dependents:   ISEN_RF24Network_Node_01 ISEN_RF24Network_Node_02

Committer:
akashvibhute
Date:
Mon Jul 06 05:10:50 2015 +0000
Revision:
0:bb74812ac6bb
Child:
2:3bdf0d9bb71f
working RF24 maniacbug library; tested on nucleo f411

Who changed what in which revision?

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