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

Committer:
Christilut
Date:
Thu Apr 04 11:49:28 2013 +0000
Revision:
1:d061e50ccc5d
Parent:
nRF24L01P_MANIC.h@0:eb5b89f49c35
Child:
2:a483f426d380
Fixed name

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