Kristof T'Jonck / Mbed 2 deprecated CYS_Receiver

Dependencies:   xtoff2 RF24Network mbed

Fork of xtoff3 by pieter Berteloot

Committer:
akashvibhute
Date:
Mon Jul 06 03:17:33 2015 +0000
Revision:
0:3982c0e9eda1
First mbed-arduino working program!; mbed is able to receive data from arduino nodes 0 or 1 depending on address set

Who changed what in which revision?

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