NRF library that can auto retransmit
Dependents: DISCO_L475VG_IOT01-Sensors-BSP IeTI_FFT_BT point_bluetooth_prof
nRF24L01P.h@2:959c573e3bf5, 2018-12-17 (annotated)
- Committer:
- krissl
- Date:
- Mon Dec 17 12:18:01 2018 +0000
- Revision:
- 2:959c573e3bf5
- Parent:
- 0:8ae48233b4e4
fixed fuckup
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Owen | 0:8ae48233b4e4 | 1 | /** |
Owen | 0:8ae48233b4e4 | 2 | * @file nRF24L01P.h |
Owen | 0:8ae48233b4e4 | 3 | * |
Owen | 0:8ae48233b4e4 | 4 | * @author Owen Edwards |
Owen | 0:8ae48233b4e4 | 5 | * |
Owen | 0:8ae48233b4e4 | 6 | * @section LICENSE |
Owen | 0:8ae48233b4e4 | 7 | * |
Owen | 0:8ae48233b4e4 | 8 | * Copyright (c) 2010 Owen Edwards |
Owen | 0:8ae48233b4e4 | 9 | * |
Owen | 0:8ae48233b4e4 | 10 | * This program is free software: you can redistribute it and/or modify |
Owen | 0:8ae48233b4e4 | 11 | * it under the terms of the GNU General Public License as published by |
Owen | 0:8ae48233b4e4 | 12 | * the Free Software Foundation, either version 3 of the License, or |
Owen | 0:8ae48233b4e4 | 13 | * (at your option) any later version. |
Owen | 0:8ae48233b4e4 | 14 | * |
Owen | 0:8ae48233b4e4 | 15 | * This program is distributed in the hope that it will be useful, |
Owen | 0:8ae48233b4e4 | 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Owen | 0:8ae48233b4e4 | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Owen | 0:8ae48233b4e4 | 18 | * GNU General Public License for more details. |
Owen | 0:8ae48233b4e4 | 19 | * |
Owen | 0:8ae48233b4e4 | 20 | * You should have received a copy of the GNU General Public License |
Owen | 0:8ae48233b4e4 | 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Owen | 0:8ae48233b4e4 | 22 | * |
Owen | 0:8ae48233b4e4 | 23 | * The above copyright notice and this permission notice shall be included in |
Owen | 0:8ae48233b4e4 | 24 | * all copies or substantial portions of the Software. |
Owen | 0:8ae48233b4e4 | 25 | * |
Owen | 0:8ae48233b4e4 | 26 | * @section DESCRIPTION |
Owen | 0:8ae48233b4e4 | 27 | * |
Owen | 0:8ae48233b4e4 | 28 | * nRF24L01+ Single Chip 2.4GHz Transceiver from Nordic Semiconductor. |
Owen | 0:8ae48233b4e4 | 29 | * |
Owen | 0:8ae48233b4e4 | 30 | * Datasheet: |
Owen | 0:8ae48233b4e4 | 31 | * |
Owen | 0:8ae48233b4e4 | 32 | * http://www.nordicsemi.no/files/Product/data_sheet/nRF24L01P_Product_Specification_1_0.pdf |
Owen | 0:8ae48233b4e4 | 33 | */ |
Owen | 0:8ae48233b4e4 | 34 | |
Owen | 0:8ae48233b4e4 | 35 | #ifndef __NRF24L01P_H__ |
Owen | 0:8ae48233b4e4 | 36 | #define __NRF24L01P_H__ |
Owen | 0:8ae48233b4e4 | 37 | |
Owen | 0:8ae48233b4e4 | 38 | /** |
Owen | 0:8ae48233b4e4 | 39 | * Includes |
Owen | 0:8ae48233b4e4 | 40 | */ |
Owen | 0:8ae48233b4e4 | 41 | #include "mbed.h" |
Owen | 0:8ae48233b4e4 | 42 | |
Owen | 0:8ae48233b4e4 | 43 | /** |
Owen | 0:8ae48233b4e4 | 44 | * Defines |
Owen | 0:8ae48233b4e4 | 45 | */ |
Owen | 0:8ae48233b4e4 | 46 | #define NRF24L01P_TX_PWR_ZERO_DB 0 |
Owen | 0:8ae48233b4e4 | 47 | #define NRF24L01P_TX_PWR_MINUS_6_DB -6 |
Owen | 0:8ae48233b4e4 | 48 | #define NRF24L01P_TX_PWR_MINUS_12_DB -12 |
Owen | 0:8ae48233b4e4 | 49 | #define NRF24L01P_TX_PWR_MINUS_18_DB -18 |
Owen | 0:8ae48233b4e4 | 50 | |
Owen | 0:8ae48233b4e4 | 51 | #define NRF24L01P_DATARATE_250_KBPS 250 |
Owen | 0:8ae48233b4e4 | 52 | #define NRF24L01P_DATARATE_1_MBPS 1000 |
Owen | 0:8ae48233b4e4 | 53 | #define NRF24L01P_DATARATE_2_MBPS 2000 |
Owen | 0:8ae48233b4e4 | 54 | |
Owen | 0:8ae48233b4e4 | 55 | #define NRF24L01P_CRC_NONE 0 |
Owen | 0:8ae48233b4e4 | 56 | #define NRF24L01P_CRC_8_BIT 8 |
Owen | 0:8ae48233b4e4 | 57 | #define NRF24L01P_CRC_16_BIT 16 |
Owen | 0:8ae48233b4e4 | 58 | |
Owen | 0:8ae48233b4e4 | 59 | #define NRF24L01P_MIN_RF_FREQUENCY 2400 |
Owen | 0:8ae48233b4e4 | 60 | #define NRF24L01P_MAX_RF_FREQUENCY 2525 |
Owen | 0:8ae48233b4e4 | 61 | |
Owen | 0:8ae48233b4e4 | 62 | #define NRF24L01P_PIPE_P0 0 |
Owen | 0:8ae48233b4e4 | 63 | #define NRF24L01P_PIPE_P1 1 |
Owen | 0:8ae48233b4e4 | 64 | #define NRF24L01P_PIPE_P2 2 |
Owen | 0:8ae48233b4e4 | 65 | #define NRF24L01P_PIPE_P3 3 |
Owen | 0:8ae48233b4e4 | 66 | #define NRF24L01P_PIPE_P4 4 |
Owen | 0:8ae48233b4e4 | 67 | #define NRF24L01P_PIPE_P5 5 |
Owen | 0:8ae48233b4e4 | 68 | |
Owen | 0:8ae48233b4e4 | 69 | /** |
Owen | 0:8ae48233b4e4 | 70 | * Default setup for the nRF24L01+, based on the Sparkfun "Nordic Serial Interface Board" |
Owen | 0:8ae48233b4e4 | 71 | * for evaluation (http://www.sparkfun.com/products/9019) |
Owen | 0:8ae48233b4e4 | 72 | */ |
Owen | 0:8ae48233b4e4 | 73 | #define DEFAULT_NRF24L01P_ADDRESS ((unsigned long long) 0xE7E7E7E7E7 ) |
Owen | 0:8ae48233b4e4 | 74 | #define DEFAULT_NRF24L01P_ADDRESS_WIDTH 5 |
Owen | 0:8ae48233b4e4 | 75 | #define DEFAULT_NRF24L01P_CRC NRF24L01P_CRC_8_BIT |
Owen | 0:8ae48233b4e4 | 76 | #define DEFAULT_NRF24L01P_RF_FREQUENCY (NRF24L01P_MIN_RF_FREQUENCY + 2) |
Owen | 0:8ae48233b4e4 | 77 | #define DEFAULT_NRF24L01P_DATARATE NRF24L01P_DATARATE_1_MBPS |
Owen | 0:8ae48233b4e4 | 78 | #define DEFAULT_NRF24L01P_TX_PWR NRF24L01P_TX_PWR_ZERO_DB |
Owen | 0:8ae48233b4e4 | 79 | #define DEFAULT_NRF24L01P_TRANSFER_SIZE 4 |
Owen | 0:8ae48233b4e4 | 80 | |
Owen | 0:8ae48233b4e4 | 81 | /** |
Owen | 0:8ae48233b4e4 | 82 | * nRF24L01+ Single Chip 2.4GHz Transceiver from Nordic Semiconductor. |
Owen | 0:8ae48233b4e4 | 83 | */ |
Owen | 0:8ae48233b4e4 | 84 | class nRF24L01P { |
Owen | 0:8ae48233b4e4 | 85 | |
Owen | 0:8ae48233b4e4 | 86 | public: |
Owen | 0:8ae48233b4e4 | 87 | |
Owen | 0:8ae48233b4e4 | 88 | /** |
Owen | 0:8ae48233b4e4 | 89 | * Constructor. |
Owen | 0:8ae48233b4e4 | 90 | * |
Owen | 0:8ae48233b4e4 | 91 | * @param mosi mbed pin to use for MOSI line of SPI interface. |
Owen | 0:8ae48233b4e4 | 92 | * @param miso mbed pin to use for MISO line of SPI interface. |
Owen | 0:8ae48233b4e4 | 93 | * @param sck mbed pin to use for SCK line of SPI interface. |
Owen | 0:8ae48233b4e4 | 94 | * @param csn mbed pin to use for not chip select line of SPI interface. |
Owen | 0:8ae48233b4e4 | 95 | * @param ce mbed pin to use for the chip enable line. |
Owen | 0:8ae48233b4e4 | 96 | * @param irq mbed pin to use for the interrupt request line. |
Owen | 0:8ae48233b4e4 | 97 | */ |
Owen | 0:8ae48233b4e4 | 98 | nRF24L01P(PinName mosi, PinName miso, PinName sck, PinName csn, PinName ce, PinName irq = NC); |
Owen | 0:8ae48233b4e4 | 99 | |
Owen | 0:8ae48233b4e4 | 100 | /** |
Owen | 0:8ae48233b4e4 | 101 | * Set the RF frequency. |
Owen | 0:8ae48233b4e4 | 102 | * |
Owen | 0:8ae48233b4e4 | 103 | * @param frequency the frequency of RF transmission in MHz (2400..2525). |
Owen | 0:8ae48233b4e4 | 104 | */ |
Owen | 0:8ae48233b4e4 | 105 | void setRfFrequency(int frequency = DEFAULT_NRF24L01P_RF_FREQUENCY); |
Owen | 0:8ae48233b4e4 | 106 | |
Owen | 0:8ae48233b4e4 | 107 | /** |
Owen | 0:8ae48233b4e4 | 108 | * Get the RF frequency. |
Owen | 0:8ae48233b4e4 | 109 | * |
Owen | 0:8ae48233b4e4 | 110 | * @return the frequency of RF transmission in MHz (2400..2525). |
Owen | 0:8ae48233b4e4 | 111 | */ |
Owen | 0:8ae48233b4e4 | 112 | int getRfFrequency(void); |
Owen | 0:8ae48233b4e4 | 113 | |
Owen | 0:8ae48233b4e4 | 114 | /** |
Owen | 0:8ae48233b4e4 | 115 | * Set the RF output power. |
Owen | 0:8ae48233b4e4 | 116 | * |
Owen | 0:8ae48233b4e4 | 117 | * @param power the RF output power in dBm (0, -6, -12 or -18). |
Owen | 0:8ae48233b4e4 | 118 | */ |
Owen | 0:8ae48233b4e4 | 119 | void setRfOutputPower(int power = DEFAULT_NRF24L01P_TX_PWR); |
Owen | 0:8ae48233b4e4 | 120 | |
Owen | 0:8ae48233b4e4 | 121 | /** |
Owen | 0:8ae48233b4e4 | 122 | * Get the RF output power. |
Owen | 0:8ae48233b4e4 | 123 | * |
Owen | 0:8ae48233b4e4 | 124 | * @return the RF output power in dBm (0, -6, -12 or -18). |
Owen | 0:8ae48233b4e4 | 125 | */ |
Owen | 0:8ae48233b4e4 | 126 | int getRfOutputPower(void); |
Owen | 0:8ae48233b4e4 | 127 | |
Owen | 0:8ae48233b4e4 | 128 | /** |
Owen | 0:8ae48233b4e4 | 129 | * Set the Air data rate. |
Owen | 0:8ae48233b4e4 | 130 | * |
Owen | 0:8ae48233b4e4 | 131 | * @param rate the air data rate in kbps (250, 1M or 2M). |
Owen | 0:8ae48233b4e4 | 132 | */ |
Owen | 0:8ae48233b4e4 | 133 | void setAirDataRate(int rate = DEFAULT_NRF24L01P_DATARATE); |
Owen | 0:8ae48233b4e4 | 134 | |
Owen | 0:8ae48233b4e4 | 135 | /** |
Owen | 0:8ae48233b4e4 | 136 | * Get the Air data rate. |
Owen | 0:8ae48233b4e4 | 137 | * |
Owen | 0:8ae48233b4e4 | 138 | * @return the air data rate in kbps (250, 1M or 2M). |
Owen | 0:8ae48233b4e4 | 139 | */ |
Owen | 0:8ae48233b4e4 | 140 | int getAirDataRate(void); |
Owen | 0:8ae48233b4e4 | 141 | |
Owen | 0:8ae48233b4e4 | 142 | /** |
Owen | 0:8ae48233b4e4 | 143 | * Set the CRC width. |
Owen | 0:8ae48233b4e4 | 144 | * |
Owen | 0:8ae48233b4e4 | 145 | * @param width the number of bits for the CRC (0, 8 or 16). |
Owen | 0:8ae48233b4e4 | 146 | */ |
Owen | 0:8ae48233b4e4 | 147 | void setCrcWidth(int width = DEFAULT_NRF24L01P_CRC); |
Owen | 0:8ae48233b4e4 | 148 | |
Owen | 0:8ae48233b4e4 | 149 | /** |
Owen | 0:8ae48233b4e4 | 150 | * Get the CRC width. |
Owen | 0:8ae48233b4e4 | 151 | * |
Owen | 0:8ae48233b4e4 | 152 | * @return the number of bits for the CRC (0, 8 or 16). |
Owen | 0:8ae48233b4e4 | 153 | */ |
Owen | 0:8ae48233b4e4 | 154 | int getCrcWidth(void); |
Owen | 0:8ae48233b4e4 | 155 | |
Owen | 0:8ae48233b4e4 | 156 | /** |
Owen | 0:8ae48233b4e4 | 157 | * Set the Receive address. |
Owen | 0:8ae48233b4e4 | 158 | * |
Owen | 0:8ae48233b4e4 | 159 | * @param address address associated with the particular pipe |
Owen | 0:8ae48233b4e4 | 160 | * @param width width of the address in bytes (3..5) |
Owen | 0:8ae48233b4e4 | 161 | * @param pipe pipe to associate the address with (0..5, default 0) |
Owen | 0:8ae48233b4e4 | 162 | * |
Owen | 0:8ae48233b4e4 | 163 | * Note that Pipes 0 & 1 have 3, 4 or 5 byte addresses, |
Owen | 0:8ae48233b4e4 | 164 | * while Pipes 2..5 only use the lowest byte (bits 7..0) of the |
Owen | 0:8ae48233b4e4 | 165 | * address provided here, and use 2, 3 or 4 bytes from Pipe 1's address. |
Owen | 0:8ae48233b4e4 | 166 | * The width parameter is ignored for Pipes 2..5. |
Owen | 0:8ae48233b4e4 | 167 | */ |
Owen | 0:8ae48233b4e4 | 168 | void setRxAddress(unsigned long long address = DEFAULT_NRF24L01P_ADDRESS, int width = DEFAULT_NRF24L01P_ADDRESS_WIDTH, int pipe = NRF24L01P_PIPE_P0); |
Owen | 0:8ae48233b4e4 | 169 | |
Owen | 0:8ae48233b4e4 | 170 | void setRxAddress(unsigned long msb_address, unsigned long lsb_address, int width, int pipe = NRF24L01P_PIPE_P0); |
Owen | 0:8ae48233b4e4 | 171 | |
Owen | 0:8ae48233b4e4 | 172 | /** |
Owen | 0:8ae48233b4e4 | 173 | * Set the Transmit address. |
Owen | 0:8ae48233b4e4 | 174 | * |
Owen | 0:8ae48233b4e4 | 175 | * @param address address for transmission |
Owen | 0:8ae48233b4e4 | 176 | * @param width width of the address in bytes (3..5) |
Owen | 0:8ae48233b4e4 | 177 | * |
Owen | 0:8ae48233b4e4 | 178 | * Note that the address width is shared with the Receive pipes, |
Owen | 0:8ae48233b4e4 | 179 | * so a change to that address width affect transmissions. |
Owen | 0:8ae48233b4e4 | 180 | */ |
Owen | 0:8ae48233b4e4 | 181 | void setTxAddress(unsigned long long address = DEFAULT_NRF24L01P_ADDRESS, int width = DEFAULT_NRF24L01P_ADDRESS_WIDTH); |
Owen | 0:8ae48233b4e4 | 182 | |
Owen | 0:8ae48233b4e4 | 183 | void setTxAddress(unsigned long msb_address, unsigned long lsb_address, int width); |
Owen | 0:8ae48233b4e4 | 184 | |
Owen | 0:8ae48233b4e4 | 185 | /** |
Owen | 0:8ae48233b4e4 | 186 | * Get the Receive address. |
Owen | 0:8ae48233b4e4 | 187 | * |
Owen | 0:8ae48233b4e4 | 188 | * @param pipe pipe to get the address from (0..5, default 0) |
Owen | 0:8ae48233b4e4 | 189 | * @return the address associated with the particular pipe |
Owen | 0:8ae48233b4e4 | 190 | */ |
Owen | 0:8ae48233b4e4 | 191 | unsigned long long getRxAddress(int pipe = NRF24L01P_PIPE_P0); |
Owen | 0:8ae48233b4e4 | 192 | |
Owen | 0:8ae48233b4e4 | 193 | /** |
Owen | 0:8ae48233b4e4 | 194 | * Get the Transmit address. |
Owen | 0:8ae48233b4e4 | 195 | * |
Owen | 0:8ae48233b4e4 | 196 | * @return address address for transmission |
Owen | 0:8ae48233b4e4 | 197 | */ |
Owen | 0:8ae48233b4e4 | 198 | unsigned long long getTxAddress(void); |
Owen | 0:8ae48233b4e4 | 199 | |
Owen | 0:8ae48233b4e4 | 200 | /** |
Owen | 0:8ae48233b4e4 | 201 | * Set the transfer size. |
Owen | 0:8ae48233b4e4 | 202 | * |
Owen | 0:8ae48233b4e4 | 203 | * @param size the size of the transfer, in bytes (1..32) |
Owen | 0:8ae48233b4e4 | 204 | * @param pipe pipe for the transfer (0..5, default 0) |
Owen | 0:8ae48233b4e4 | 205 | */ |
Owen | 0:8ae48233b4e4 | 206 | void setTransferSize(int size = DEFAULT_NRF24L01P_TRANSFER_SIZE, int pipe = NRF24L01P_PIPE_P0); |
Owen | 0:8ae48233b4e4 | 207 | |
Owen | 0:8ae48233b4e4 | 208 | /** |
Owen | 0:8ae48233b4e4 | 209 | * Get the transfer size. |
Owen | 0:8ae48233b4e4 | 210 | * |
Owen | 0:8ae48233b4e4 | 211 | * @return the size of the transfer, in bytes (1..32). |
Owen | 0:8ae48233b4e4 | 212 | */ |
Owen | 0:8ae48233b4e4 | 213 | int getTransferSize(int pipe = NRF24L01P_PIPE_P0); |
Owen | 0:8ae48233b4e4 | 214 | |
Owen | 0:8ae48233b4e4 | 215 | |
Owen | 0:8ae48233b4e4 | 216 | /** |
Owen | 0:8ae48233b4e4 | 217 | * Get the RPD (Received Power Detector) state. |
Owen | 0:8ae48233b4e4 | 218 | * |
Owen | 0:8ae48233b4e4 | 219 | * @return true if the received power exceeded -64dBm |
Owen | 0:8ae48233b4e4 | 220 | */ |
Owen | 0:8ae48233b4e4 | 221 | bool getRPD(void); |
Owen | 0:8ae48233b4e4 | 222 | |
Owen | 0:8ae48233b4e4 | 223 | /** |
Owen | 0:8ae48233b4e4 | 224 | * Put the nRF24L01+ into Receive mode |
Owen | 0:8ae48233b4e4 | 225 | */ |
Owen | 0:8ae48233b4e4 | 226 | void setReceiveMode(void); |
Owen | 0:8ae48233b4e4 | 227 | |
Owen | 0:8ae48233b4e4 | 228 | /** |
Owen | 0:8ae48233b4e4 | 229 | * Put the nRF24L01+ into Transmit mode |
Owen | 0:8ae48233b4e4 | 230 | */ |
Owen | 0:8ae48233b4e4 | 231 | void setTransmitMode(void); |
Owen | 0:8ae48233b4e4 | 232 | |
Owen | 0:8ae48233b4e4 | 233 | /** |
Owen | 0:8ae48233b4e4 | 234 | * Power up the nRF24L01+ into Standby mode |
Owen | 0:8ae48233b4e4 | 235 | */ |
Owen | 0:8ae48233b4e4 | 236 | void powerUp(void); |
Owen | 0:8ae48233b4e4 | 237 | |
Owen | 0:8ae48233b4e4 | 238 | /** |
Owen | 0:8ae48233b4e4 | 239 | * Power down the nRF24L01+ into Power Down mode |
Owen | 0:8ae48233b4e4 | 240 | */ |
Owen | 0:8ae48233b4e4 | 241 | void powerDown(void); |
Owen | 0:8ae48233b4e4 | 242 | |
Owen | 0:8ae48233b4e4 | 243 | /** |
Owen | 0:8ae48233b4e4 | 244 | * Enable the nRF24L01+ to Receive or Transmit (using the CE pin) |
Owen | 0:8ae48233b4e4 | 245 | */ |
Owen | 0:8ae48233b4e4 | 246 | void enable(void); |
Owen | 0:8ae48233b4e4 | 247 | |
Owen | 0:8ae48233b4e4 | 248 | /** |
Owen | 0:8ae48233b4e4 | 249 | * Disable the nRF24L01+ to Receive or Transmit (using the CE pin) |
Owen | 0:8ae48233b4e4 | 250 | */ |
Owen | 0:8ae48233b4e4 | 251 | void disable(void); |
Owen | 0:8ae48233b4e4 | 252 | |
Owen | 0:8ae48233b4e4 | 253 | /** |
Owen | 0:8ae48233b4e4 | 254 | * Transmit data |
Owen | 0:8ae48233b4e4 | 255 | * |
Owen | 0:8ae48233b4e4 | 256 | * @param pipe is ignored (included for consistency with file write routine) |
Owen | 0:8ae48233b4e4 | 257 | * @param data pointer to an array of bytes to write |
Owen | 0:8ae48233b4e4 | 258 | * @param count the number of bytes to send (1..32) |
Owen | 0:8ae48233b4e4 | 259 | * @return the number of bytes actually written, or -1 for an error |
Owen | 0:8ae48233b4e4 | 260 | */ |
Owen | 0:8ae48233b4e4 | 261 | int write(int pipe, char *data, int count); |
Owen | 0:8ae48233b4e4 | 262 | |
Owen | 0:8ae48233b4e4 | 263 | /** |
Owen | 0:8ae48233b4e4 | 264 | * Receive data |
Owen | 0:8ae48233b4e4 | 265 | * |
Owen | 0:8ae48233b4e4 | 266 | * @param pipe the receive pipe to get data from |
Owen | 0:8ae48233b4e4 | 267 | * @param data pointer to an array of bytes to store the received data |
Owen | 0:8ae48233b4e4 | 268 | * @param count the number of bytes to receive (1..32) |
Owen | 0:8ae48233b4e4 | 269 | * @return the number of bytes actually received, 0 if none are received, or -1 for an error |
Owen | 0:8ae48233b4e4 | 270 | */ |
Owen | 0:8ae48233b4e4 | 271 | int read(int pipe, char *data, int count); |
Owen | 0:8ae48233b4e4 | 272 | |
Owen | 0:8ae48233b4e4 | 273 | /** |
Owen | 0:8ae48233b4e4 | 274 | * Determine if there is data available to read |
Owen | 0:8ae48233b4e4 | 275 | * |
Owen | 0:8ae48233b4e4 | 276 | * @param pipe the receive pipe to check for data |
Owen | 0:8ae48233b4e4 | 277 | * @return true if the is data waiting in the given pipe |
Owen | 0:8ae48233b4e4 | 278 | */ |
Owen | 0:8ae48233b4e4 | 279 | bool readable(int pipe = NRF24L01P_PIPE_P0); |
Owen | 0:8ae48233b4e4 | 280 | |
Owen | 0:8ae48233b4e4 | 281 | /** |
Owen | 0:8ae48233b4e4 | 282 | * Disable all receive pipes |
Owen | 0:8ae48233b4e4 | 283 | * |
Owen | 0:8ae48233b4e4 | 284 | * Note: receive pipes are enabled when their address is set. |
Owen | 0:8ae48233b4e4 | 285 | */ |
Owen | 0:8ae48233b4e4 | 286 | void disableAllRxPipes(void); |
Owen | 0:8ae48233b4e4 | 287 | |
Owen | 0:8ae48233b4e4 | 288 | /** |
Owen | 0:8ae48233b4e4 | 289 | * Disable AutoAcknowledge function |
Owen | 0:8ae48233b4e4 | 290 | */ |
Owen | 0:8ae48233b4e4 | 291 | void disableAutoAcknowledge(void); |
Owen | 0:8ae48233b4e4 | 292 | |
Owen | 0:8ae48233b4e4 | 293 | /** |
Owen | 0:8ae48233b4e4 | 294 | * Enable AutoAcknowledge function |
Owen | 0:8ae48233b4e4 | 295 | * |
Owen | 0:8ae48233b4e4 | 296 | * @param pipe the receive pipe |
Owen | 0:8ae48233b4e4 | 297 | */ |
Owen | 0:8ae48233b4e4 | 298 | void enableAutoAcknowledge(int pipe = NRF24L01P_PIPE_P0); |
Owen | 0:8ae48233b4e4 | 299 | |
Owen | 0:8ae48233b4e4 | 300 | /** |
Owen | 0:8ae48233b4e4 | 301 | * Disable AutoRetransmit function |
Owen | 0:8ae48233b4e4 | 302 | */ |
Owen | 0:8ae48233b4e4 | 303 | void disableAutoRetransmit(void); |
Owen | 0:8ae48233b4e4 | 304 | |
Owen | 0:8ae48233b4e4 | 305 | /** |
Owen | 0:8ae48233b4e4 | 306 | * Enable AutoRetransmit function |
Owen | 0:8ae48233b4e4 | 307 | * |
Owen | 0:8ae48233b4e4 | 308 | * @param delay the delay between restransmits, in uS (250uS..4000uS) |
Owen | 0:8ae48233b4e4 | 309 | * @param count number of retransmits before generating an error (1..15) |
Owen | 0:8ae48233b4e4 | 310 | */ |
Owen | 0:8ae48233b4e4 | 311 | void enableAutoRetransmit(int delay, int count); |
Owen | 0:8ae48233b4e4 | 312 | |
Owen | 0:8ae48233b4e4 | 313 | private: |
Owen | 0:8ae48233b4e4 | 314 | |
Owen | 0:8ae48233b4e4 | 315 | /** |
Owen | 0:8ae48233b4e4 | 316 | * Get the contents of an addressable register. |
Owen | 0:8ae48233b4e4 | 317 | * |
Owen | 0:8ae48233b4e4 | 318 | * @param regAddress address of the register |
Owen | 0:8ae48233b4e4 | 319 | * @return the contents of the register |
Owen | 0:8ae48233b4e4 | 320 | */ |
Owen | 0:8ae48233b4e4 | 321 | int getRegister(int regAddress); |
Owen | 0:8ae48233b4e4 | 322 | |
Owen | 0:8ae48233b4e4 | 323 | /** |
Owen | 0:8ae48233b4e4 | 324 | * Set the contents of an addressable register. |
Owen | 0:8ae48233b4e4 | 325 | * |
Owen | 0:8ae48233b4e4 | 326 | * @param regAddress address of the register |
Owen | 0:8ae48233b4e4 | 327 | * @param regData data to write to the register |
Owen | 0:8ae48233b4e4 | 328 | */ |
Owen | 0:8ae48233b4e4 | 329 | void setRegister(int regAddress, int regData); |
Owen | 0:8ae48233b4e4 | 330 | |
Owen | 0:8ae48233b4e4 | 331 | /** |
Owen | 0:8ae48233b4e4 | 332 | * Get the contents of the status register. |
Owen | 0:8ae48233b4e4 | 333 | * |
Owen | 0:8ae48233b4e4 | 334 | * @return the contents of the status register |
Owen | 0:8ae48233b4e4 | 335 | */ |
Owen | 0:8ae48233b4e4 | 336 | int getStatusRegister(void); |
Owen | 0:8ae48233b4e4 | 337 | |
Owen | 0:8ae48233b4e4 | 338 | SPI spi_; |
Owen | 0:8ae48233b4e4 | 339 | DigitalOut nCS_; |
Owen | 0:8ae48233b4e4 | 340 | DigitalOut ce_; |
Owen | 0:8ae48233b4e4 | 341 | InterruptIn nIRQ_; |
Owen | 0:8ae48233b4e4 | 342 | |
Owen | 0:8ae48233b4e4 | 343 | int mode; |
Owen | 0:8ae48233b4e4 | 344 | |
Owen | 0:8ae48233b4e4 | 345 | }; |
Owen | 0:8ae48233b4e4 | 346 | |
Owen | 0:8ae48233b4e4 | 347 | #endif /* __NRF24L01P_H__ */ |