Library for the nRF2401A Transceiver

Dependents:   nRF2401A_Hello_World nRF2401A_Wireless_Accelerometer_joypad nRF2401A_Gameduino_Invaders

Committer:
TheChrisyd
Date:
Sat Oct 05 09:23:20 2013 +0000
Revision:
2:ca8602ee9e1d
Parent:
1:8c57f88ff574
Child:
3:7ae3a5e53a1f
only documentation changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TheChrisyd 2:ca8602ee9e1d 1 /**
TheChrisyd 2:ca8602ee9e1d 2 *@section DESCRIPTION
TheChrisyd 2:ca8602ee9e1d 3 * mbed nRF2401A Library
TheChrisyd 2:ca8602ee9e1d 4 *@section LICENSE
TheChrisyd 0:17cb4be1e37f 5 * Copyright (c) 2011, Per Söderstam
TheChrisyd 0:17cb4be1e37f 6 *
TheChrisyd 0:17cb4be1e37f 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
TheChrisyd 0:17cb4be1e37f 8 * of this software and associated documentation files (the "Software"), to deal
TheChrisyd 0:17cb4be1e37f 9 * in the Software without restriction, including without limitation the rights
TheChrisyd 0:17cb4be1e37f 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
TheChrisyd 0:17cb4be1e37f 11 * copies of the Software, and to permit persons to whom the Software is
TheChrisyd 0:17cb4be1e37f 12 * furnished to do so, subject to the following conditions:
TheChrisyd 0:17cb4be1e37f 13 *
TheChrisyd 0:17cb4be1e37f 14 * The above copyright notice and this permission notice shall be included in
TheChrisyd 0:17cb4be1e37f 15 * all copies or substantial portions of the Software.
TheChrisyd 0:17cb4be1e37f 16 *
TheChrisyd 0:17cb4be1e37f 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
TheChrisyd 0:17cb4be1e37f 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
TheChrisyd 0:17cb4be1e37f 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
TheChrisyd 0:17cb4be1e37f 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
TheChrisyd 0:17cb4be1e37f 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
TheChrisyd 0:17cb4be1e37f 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
TheChrisyd 0:17cb4be1e37f 23 * THE SOFTWARE.
TheChrisyd 2:ca8602ee9e1d 24 * @file "nRF2401A.h"
TheChrisyd 0:17cb4be1e37f 25 */
TheChrisyd 2:ca8602ee9e1d 26 #ifndef _nRF2401A_H
TheChrisyd 2:ca8602ee9e1d 27 #define _nRF2401A_H
TheChrisyd 0:17cb4be1e37f 28
TheChrisyd 0:17cb4be1e37f 29 #include <mbed.h>
TheChrisyd 0:17cb4be1e37f 30 #include <inttypes.h>
TheChrisyd 0:17cb4be1e37f 31 #define Ts 1 /**< Setup time from data to rising clock edge on write (accualy 500 ns). */
TheChrisyd 0:17cb4be1e37f 32 #define Th 1 /**< Hold time from rising clock to data toggle/falling clock (accualy 500 ns). */
TheChrisyd 0:17cb4be1e37f 33 #define Tcs2data 5 /**< Min delay from CS assert to data, in us. */
TheChrisyd 0:17cb4be1e37f 34 #define Tce2data 5 /**< Min delay from CE assert to data, in us. */
TheChrisyd 0:17cb4be1e37f 35 #define Td 1 /**< Minimum delay between edges (actually 50 ns). */
TheChrisyd 0:17cb4be1e37f 36 #define Tpd2cfgm 3 /**< Minimum delay from power up of tranciever to configuration. */
TheChrisyd 0:17cb4be1e37f 37 #define Tsby2txSB 195 /**< Minimum delay from tx initation to air, in us. */
TheChrisyd 0:17cb4be1e37f 38 #define Thmin 5 /**< */
TheChrisyd 0:17cb4be1e37f 39 #define Tclk2data 1 /**< */
TheChrisyd 0:17cb4be1e37f 40
TheChrisyd 1:8c57f88ff574 41 /** nRF2401 Class
TheChrisyd 0:17cb4be1e37f 42 *
TheChrisyd 0:17cb4be1e37f 43 * Example:
TheChrisyd 0:17cb4be1e37f 44 * @code
TheChrisyd 0:17cb4be1e37f 45 * #include "mbed.h"
TheChrisyd 0:17cb4be1e37f 46 * #include "nRF2401A.h"
TheChrisyd 0:17cb4be1e37f 47 *
TheChrisyd 0:17cb4be1e37f 48 * DigitalOut myled(LED1);
TheChrisyd 0:17cb4be1e37f 49 * nRF2401A rf1(p10, p11, p12, p13, p14);
TheChrisyd 0:17cb4be1e37f 50 * nRF2401A rf2(p21, p22, p23, p24, p25);
TheChrisyd 0:17cb4be1e37f 51 *
TheChrisyd 0:17cb4be1e37f 52 * Serial pc(USBTX, USBRX);
TheChrisyd 0:17cb4be1e37f 53 *
TheChrisyd 0:17cb4be1e37f 54 * int main() {
TheChrisyd 0:17cb4be1e37f 55 *
TheChrisyd 0:17cb4be1e37f 56 * wait(0.005);
TheChrisyd 0:17cb4be1e37f 57 *
TheChrisyd 0:17cb4be1e37f 58 * pc.printf("Hello nRF2401A\n\r");
TheChrisyd 0:17cb4be1e37f 59 *
TheChrisyd 0:17cb4be1e37f 60 * rf1.setDataPayloadLength(4 << 3)
TheChrisyd 0:17cb4be1e37f 61 * .setAddress(0x0, 0x0, 0xa6, 0xa6, 0xa6, 3 << 3)
TheChrisyd 0:17cb4be1e37f 62 * .setCRCMode(nRF2401A::NO_CRC)
TheChrisyd 0:17cb4be1e37f 63 * .setDataRate(nRF2401A::BIT_RATE_250KBITS)
TheChrisyd 0:17cb4be1e37f 64 * .setChannel(0x02);
TheChrisyd 0:17cb4be1e37f 65 *
TheChrisyd 0:17cb4be1e37f 66 * rf1.printControlPacket(pc);
TheChrisyd 0:17cb4be1e37f 67 *
TheChrisyd 0:17cb4be1e37f 68 * rf2.setDataPayloadLength(4 << 3)
TheChrisyd 0:17cb4be1e37f 69 * .setAddress(0x0, 0x0, 0x53, 0x53, 0x53, 3 << 3)
TheChrisyd 0:17cb4be1e37f 70 * .setCRCMode(nRF2401A::NO_CRC)
TheChrisyd 0:17cb4be1e37f 71 * .setDataRate(nRF2401A::BIT_RATE_250KBITS)
TheChrisyd 0:17cb4be1e37f 72 * .setChannel(0x02);
TheChrisyd 0:17cb4be1e37f 73 *
TheChrisyd 0:17cb4be1e37f 74 * rf2.printControlPacket(pc);
TheChrisyd 0:17cb4be1e37f 75 *
TheChrisyd 0:17cb4be1e37f 76 * rf1.flushControlPacket();
TheChrisyd 0:17cb4be1e37f 77 * rf2.flushControlPacket();
TheChrisyd 0:17cb4be1e37f 78 *
TheChrisyd 0:17cb4be1e37f 79 * nRF2401A::address_t rf2_addr = {0x0, 0x0, 0x53, 0x53, 0x53};
TheChrisyd 0:17cb4be1e37f 80 * uint8_t msg[] = {0x01, 0x01, 0x01, 0x01};
TheChrisyd 0:17cb4be1e37f 81 * uint32_t *msg32 = (uint32_t *) msg;
TheChrisyd 0:17cb4be1e37f 82 *
TheChrisyd 0:17cb4be1e37f 83 * while(1) {
TheChrisyd 0:17cb4be1e37f 84 *
TheChrisyd 0:17cb4be1e37f 85 * rf1.sendMsg(rf2_addr, 3 << 3, msg, 4 << 3);
TheChrisyd 0:17cb4be1e37f 86 * *msg32 += 1;
TheChrisyd 0:17cb4be1e37f 87 *
TheChrisyd 0:17cb4be1e37f 88 * myled = 1;
TheChrisyd 0:17cb4be1e37f 89 * wait(0.25);
TheChrisyd 0:17cb4be1e37f 90 *
TheChrisyd 0:17cb4be1e37f 91 * rf2.printDataPacket(pc);
TheChrisyd 0:17cb4be1e37f 92 *
TheChrisyd 0:17cb4be1e37f 93 * myled = 0;
TheChrisyd 0:17cb4be1e37f 94 * wait(0.25);
TheChrisyd 0:17cb4be1e37f 95 * }
TheChrisyd 0:17cb4be1e37f 96 * }
TheChrisyd 0:17cb4be1e37f 97 * @endcode
TheChrisyd 0:17cb4be1e37f 98 */
TheChrisyd 0:17cb4be1e37f 99
TheChrisyd 0:17cb4be1e37f 100 /** ISR handler prototype for receiving messages.
TheChrisyd 0:17cb4be1e37f 101 * A function of this type is registered and called when the DR pin on the
TheChrisyd 0:17cb4be1e37f 102 * nRF tranciever signals the reception of a message. The void * argument
TheChrisyd 0:17cb4be1e37f 103 * is likewise supplied when registering and is returned at call time.
TheChrisyd 0:17cb4be1e37f 104 */
TheChrisyd 0:17cb4be1e37f 105 typedef void (*nRF2401A_rx_handler_t)(void *);
TheChrisyd 0:17cb4be1e37f 106
TheChrisyd 0:17cb4be1e37f 107 /**
TheChrisyd 0:17cb4be1e37f 108 *
TheChrisyd 0:17cb4be1e37f 109 *
TheChrisyd 0:17cb4be1e37f 110 */
TheChrisyd 0:17cb4be1e37f 111 class nRF2401A
TheChrisyd 0:17cb4be1e37f 112 {
TheChrisyd 0:17cb4be1e37f 113 public:
TheChrisyd 0:17cb4be1e37f 114 /** Class constructor.
TheChrisyd 0:17cb4be1e37f 115 * The constructor assigns the specified pinout, attatch the
TheChrisyd 0:17cb4be1e37f 116 * DR1 to a pin interrupt and sets up inmutable control packet
TheChrisyd 0:17cb4be1e37f 117 * fields.
TheChrisyd 2:ca8602ee9e1d 118 * @param ce Chip Enable (CE) pin of the nRF2401A.
TheChrisyd 2:ca8602ee9e1d 119 * @param c2 Chip Select (CS) pin of the nRF2401A.
TheChrisyd 2:ca8602ee9e1d 120 * @param dr1 Data Ready 1 (DR1) pin of the nRF2401A.
TheChrisyd 2:ca8602ee9e1d 121 * @param clk1 Clock 1 (CLK1) pin of the nRF2401A.
TheChrisyd 2:ca8602ee9e1d 122 * @param data Data (DATA) pin of the nRF2401A.
TheChrisyd 0:17cb4be1e37f 123 */
TheChrisyd 0:17cb4be1e37f 124 nRF2401A(PinName ce,
TheChrisyd 0:17cb4be1e37f 125 PinName cs,
TheChrisyd 0:17cb4be1e37f 126 PinName dr1,
TheChrisyd 0:17cb4be1e37f 127 PinName clk1,
TheChrisyd 0:17cb4be1e37f 128 PinName data);
TheChrisyd 0:17cb4be1e37f 129
TheChrisyd 0:17cb4be1e37f 130 /** Class destructor.
TheChrisyd 0:17cb4be1e37f 131 * Pretty much useless in the embedded world...
TheChrisyd 0:17cb4be1e37f 132 */
TheChrisyd 0:17cb4be1e37f 133 virtual ~nRF2401A() { return; }
TheChrisyd 0:17cb4be1e37f 134
TheChrisyd 0:17cb4be1e37f 135 /** Set the payload length, in bits.
TheChrisyd 0:17cb4be1e37f 136 * Set the control packet field for length, in number of bits, of the message payload.
TheChrisyd 2:ca8602ee9e1d 137 * @param n Number of bits of the message payload.
TheChrisyd 2:ca8602ee9e1d 138 * @return Reference to the invoked object (for chaining operations).
TheChrisyd 0:17cb4be1e37f 139 */
TheChrisyd 0:17cb4be1e37f 140 nRF2401A& setDataPayloadLength(uint8_t n)
TheChrisyd 0:17cb4be1e37f 141 {
TheChrisyd 0:17cb4be1e37f 142 _ctrl_packet_buf.channel_1_data_payload_len = n;
TheChrisyd 0:17cb4be1e37f 143 return *this;
TheChrisyd 0:17cb4be1e37f 144 }
TheChrisyd 0:17cb4be1e37f 145
TheChrisyd 0:17cb4be1e37f 146 /** Set the address of channel 1.
TheChrisyd 1:8c57f88ff574 147 * The channel address is a up to 40 bit number identifying the tranceiver.
TheChrisyd 2:ca8602ee9e1d 148 * @param addr4 Bits 39-32 of the address.
TheChrisyd 2:ca8602ee9e1d 149 * @param addr4 Bits 31-24 of the address.
TheChrisyd 2:ca8602ee9e1d 150 * @param addr4 Bits 23-16 of the address.
TheChrisyd 2:ca8602ee9e1d 151 * @param addr4 Bits 15-8 of the address.
TheChrisyd 2:ca8602ee9e1d 152 * @param addr4 Bits 7-0 of the address.
TheChrisyd 2:ca8602ee9e1d 153 * @param n_bits Number of bits used in the address.
TheChrisyd 2:ca8602ee9e1d 154 * @return Reference to the invoked object (for chaining operations).
TheChrisyd 0:17cb4be1e37f 155 */
TheChrisyd 0:17cb4be1e37f 156 nRF2401A& setAddress(uint8_t addr4, uint8_t addr3, uint8_t addr2, uint8_t addr1, uint8_t addr0, uint8_t n_bits)
TheChrisyd 0:17cb4be1e37f 157 {
TheChrisyd 0:17cb4be1e37f 158 _ctrl_packet_buf.channel_1_address[0] = addr4;
TheChrisyd 0:17cb4be1e37f 159 _ctrl_packet_buf.channel_1_address[1] = addr3;
TheChrisyd 0:17cb4be1e37f 160 _ctrl_packet_buf.channel_1_address[2] = addr2;
TheChrisyd 0:17cb4be1e37f 161 _ctrl_packet_buf.channel_1_address[3] = addr1;
TheChrisyd 0:17cb4be1e37f 162 _ctrl_packet_buf.channel_1_address[4] = addr0;
TheChrisyd 0:17cb4be1e37f 163 _ctrl_packet_buf.channel_address_len = n_bits;
TheChrisyd 0:17cb4be1e37f 164
TheChrisyd 0:17cb4be1e37f 165 return *this;
TheChrisyd 0:17cb4be1e37f 166 }
TheChrisyd 0:17cb4be1e37f 167
TheChrisyd 0:17cb4be1e37f 168 /** CRC settings.
TheChrisyd 0:17cb4be1e37f 169 * Type covering the allowed settings for use of CRC.
TheChrisyd 0:17cb4be1e37f 170 */
TheChrisyd 0:17cb4be1e37f 171 typedef enum
TheChrisyd 0:17cb4be1e37f 172 {
TheChrisyd 0:17cb4be1e37f 173 NO_CRC = 0x0, /**< Do not use CRC. */
TheChrisyd 0:17cb4be1e37f 174 CRC_8 = 0x1, /**< Use a 8-bit CRC. */
TheChrisyd 0:17cb4be1e37f 175 CRC_16 = 0x3 /**< Use a 16-bit CRC. */
TheChrisyd 0:17cb4be1e37f 176 } CRC_T;
TheChrisyd 0:17cb4be1e37f 177
TheChrisyd 0:17cb4be1e37f 178 /** Set CRC use.
TheChrisyd 0:17cb4be1e37f 179 * Set the CRC mode field of the control packet.
TheChrisyd 2:ca8602ee9e1d 180 * @param mode The CRC mode of choise.
TheChrisyd 2:ca8602ee9e1d 181 * @return Reference to the invoked object (for chaining operations).
TheChrisyd 0:17cb4be1e37f 182 */
TheChrisyd 0:17cb4be1e37f 183 nRF2401A& setCRCMode(CRC_T mode)
TheChrisyd 0:17cb4be1e37f 184 {
TheChrisyd 0:17cb4be1e37f 185 _ctrl_packet_buf.crc_config = mode;
TheChrisyd 0:17cb4be1e37f 186 return *this;
TheChrisyd 0:17cb4be1e37f 187 }
TheChrisyd 0:17cb4be1e37f 188
TheChrisyd 0:17cb4be1e37f 189 /** Data rate settings.
TheChrisyd 1:8c57f88ff574 190 * Type covering the allowed settings for the tranceiver data rate.
TheChrisyd 0:17cb4be1e37f 191 */
TheChrisyd 0:17cb4be1e37f 192 typedef enum
TheChrisyd 0:17cb4be1e37f 193 {
TheChrisyd 0:17cb4be1e37f 194 BIT_RATE_250KBITS = 0x0, /**< */
TheChrisyd 0:17cb4be1e37f 195 BIT_RATE_1MBITS = 0x1 /**< */
TheChrisyd 0:17cb4be1e37f 196 } DATA_RATE_T;
TheChrisyd 0:17cb4be1e37f 197
TheChrisyd 1:8c57f88ff574 198 /** Set tranceiver data rate.
TheChrisyd 0:17cb4be1e37f 199 * Sets the data rate field to either 250 kbit/s or 1 Mbit/s data transfer rate.
TheChrisyd 2:ca8602ee9e1d 200 * @param mode The data rate of choise.
TheChrisyd 2:ca8602ee9e1d 201 * @return Reference to the invoked object (for chaining operations).
TheChrisyd 0:17cb4be1e37f 202 */
TheChrisyd 0:17cb4be1e37f 203 nRF2401A& setDataRate(DATA_RATE_T data_rate)
TheChrisyd 0:17cb4be1e37f 204 {
TheChrisyd 0:17cb4be1e37f 205 _ctrl_packet_buf.rf_data_rate = data_rate;
TheChrisyd 0:17cb4be1e37f 206 return *this;
TheChrisyd 0:17cb4be1e37f 207 }
TheChrisyd 0:17cb4be1e37f 208
TheChrisyd 0:17cb4be1e37f 209 /** Set RF channel.
TheChrisyd 0:17cb4be1e37f 210 * Sets the control packet field for channel number. Channel numbers are from 0 to 127
TheChrisyd 0:17cb4be1e37f 211 * representing channel frequencies equal to (2400 + channel number) MHz.
TheChrisyd 2:ca8602ee9e1d 212 * @param ch Channel number, from the range [0, 127].
TheChrisyd 2:ca8602ee9e1d 213 * @return Reference to the invoked object (for chaining operations).
TheChrisyd 0:17cb4be1e37f 214 */
TheChrisyd 0:17cb4be1e37f 215 nRF2401A& setChannel(uint8_t ch)
TheChrisyd 0:17cb4be1e37f 216 {
TheChrisyd 0:17cb4be1e37f 217 _ctrl_packet_buf.rf_channel = ch;
TheChrisyd 0:17cb4be1e37f 218 return *this;
TheChrisyd 0:17cb4be1e37f 219 }
TheChrisyd 0:17cb4be1e37f 220
TheChrisyd 0:17cb4be1e37f 221 /** Send the control packet to the nRF2401A.
TheChrisyd 0:17cb4be1e37f 222 * This function transfer the control packet image to the nRF2401A.
TheChrisyd 2:ca8602ee9e1d 223 * @return Reference to the invoked object (for chaining operations).
TheChrisyd 0:17cb4be1e37f 224 */
TheChrisyd 0:17cb4be1e37f 225 nRF2401A& flushControlPacket();
TheChrisyd 0:17cb4be1e37f 226
TheChrisyd 0:17cb4be1e37f 227 /**
TheChrisyd 0:17cb4be1e37f 228 *
TheChrisyd 0:17cb4be1e37f 229 */
TheChrisyd 0:17cb4be1e37f 230 void activate(bool active = true);
TheChrisyd 0:17cb4be1e37f 231
TheChrisyd 0:17cb4be1e37f 232 /**
TheChrisyd 0:17cb4be1e37f 233 *
TheChrisyd 0:17cb4be1e37f 234 */
TheChrisyd 0:17cb4be1e37f 235 typedef uint8_t address_t[5];
TheChrisyd 0:17cb4be1e37f 236
TheChrisyd 0:17cb4be1e37f 237 /** Send a message.
TheChrisyd 0:17cb4be1e37f 238 * This routine will transfer the data from the supplied buffer and send
TheChrisyd 0:17cb4be1e37f 239 * it to the specified address using the current control packet settings.
TheChrisyd 2:ca8602ee9e1d 240 * @param addr The address to send to.
TheChrisyd 2:ca8602ee9e1d 241 * @param addr_len Length of address, in bits.
TheChrisyd 2:ca8602ee9e1d 242 * @param msg_buf Message body.
TheChrisyd 2:ca8602ee9e1d 243 * @param msg_len Length of message, in bits.
TheChrisyd 2:ca8602ee9e1d 244 * @return Reference to the invoked object (for chaining operations).
TheChrisyd 0:17cb4be1e37f 245 */
TheChrisyd 0:17cb4be1e37f 246 nRF2401A& sendMsg(address_t addr, uint8_t addr_len, uint8_t *msg_buf, uint8_t msg_len);
TheChrisyd 0:17cb4be1e37f 247
TheChrisyd 0:17cb4be1e37f 248 /** Register a receive action callback.
TheChrisyd 1:8c57f88ff574 249 * Attach a callback that will be called when the tranceiver intercept a
TheChrisyd 0:17cb4be1e37f 250 * message. This callback will be called in the context of an interrupt
TheChrisyd 0:17cb4be1e37f 251 * routine and should act accordingly.
TheChrisyd 2:ca8602ee9e1d 252 * @param handler The callback, of type nRF2401_rx_handler_t.
TheChrisyd 2:ca8602ee9e1d 253 * @param arg Pointer to data supplied to the handler at call time.
TheChrisyd 2:ca8602ee9e1d 254 * @return Reference to the invoked object (for chaining operations).
TheChrisyd 0:17cb4be1e37f 255 */
TheChrisyd 0:17cb4be1e37f 256 nRF2401A& attachRXHandler(nRF2401A_rx_handler_t handler, void *arg);
TheChrisyd 0:17cb4be1e37f 257
TheChrisyd 0:17cb4be1e37f 258 void printControlPacket(Serial& port);
TheChrisyd 0:17cb4be1e37f 259 void printDataPacket(Serial& port);
TheChrisyd 0:17cb4be1e37f 260
TheChrisyd 0:17cb4be1e37f 261 private:
TheChrisyd 0:17cb4be1e37f 262
TheChrisyd 0:17cb4be1e37f 263 DigitalOut _ce; /**< Chip Enable pin. */
TheChrisyd 0:17cb4be1e37f 264 DigitalOut _cs; /**< Chip select pin. */
TheChrisyd 0:17cb4be1e37f 265 DigitalIn _dr1; /**< Data Ready 1 pin. */
TheChrisyd 0:17cb4be1e37f 266 DigitalOut _clk1; /**< Clock 1 pin. */
TheChrisyd 0:17cb4be1e37f 267 DigitalInOut _data; /**< Data pin. */
TheChrisyd 0:17cb4be1e37f 268
TheChrisyd 0:17cb4be1e37f 269 /**
TheChrisyd 0:17cb4be1e37f 270 *
TheChrisyd 0:17cb4be1e37f 271 */
TheChrisyd 0:17cb4be1e37f 272 typedef enum
TheChrisyd 0:17cb4be1e37f 273 {
TheChrisyd 0:17cb4be1e37f 274 UNDEF, /**< The start state. */
TheChrisyd 1:8c57f88ff574 275 RX, /**< The tranceiver is in receive mode. */
TheChrisyd 1:8c57f88ff574 276 TX, /**< The tranceiver is transmitting. */
TheChrisyd 1:8c57f88ff574 277 STANDBY /**< The tranceiver goes into stanby mode. */
TheChrisyd 0:17cb4be1e37f 278 } STATE_T;
TheChrisyd 0:17cb4be1e37f 279
TheChrisyd 0:17cb4be1e37f 280 STATE_T _state;
TheChrisyd 0:17cb4be1e37f 281
TheChrisyd 0:17cb4be1e37f 282 /** Contol packet data.
TheChrisyd 0:17cb4be1e37f 283 *
TheChrisyd 0:17cb4be1e37f 284 */
TheChrisyd 0:17cb4be1e37f 285 struct nRF2401A_ctrl_packet_t
TheChrisyd 0:17cb4be1e37f 286 {
TheChrisyd 0:17cb4be1e37f 287 uint8_t channel_2_data_payload_len; /**< */
TheChrisyd 0:17cb4be1e37f 288 uint8_t channel_1_data_payload_len; /**< */
TheChrisyd 0:17cb4be1e37f 289 uint8_t channel_2_address[5]; /**< */
TheChrisyd 0:17cb4be1e37f 290 uint8_t channel_1_address[5]; /**< */
TheChrisyd 0:17cb4be1e37f 291
TheChrisyd 0:17cb4be1e37f 292 uint8_t crc_config : 2; /**< */
TheChrisyd 0:17cb4be1e37f 293 uint8_t channel_address_len : 6; /**< */
TheChrisyd 0:17cb4be1e37f 294
TheChrisyd 0:17cb4be1e37f 295 uint8_t rf_power : 2; /**< */
TheChrisyd 0:17cb4be1e37f 296 uint8_t xo_frequency : 3; /**< */
TheChrisyd 0:17cb4be1e37f 297 uint8_t rf_data_rate : 1; /**< */
TheChrisyd 0:17cb4be1e37f 298 uint8_t communication_mode : 1; /**< */
TheChrisyd 0:17cb4be1e37f 299 uint8_t enable_dual_channel_mode : 1; /**< */
TheChrisyd 0:17cb4be1e37f 300
TheChrisyd 0:17cb4be1e37f 301 uint8_t txr_switch : 1; /**< */
TheChrisyd 0:17cb4be1e37f 302 uint8_t rf_channel : 7; /**< */
TheChrisyd 0:17cb4be1e37f 303
TheChrisyd 0:17cb4be1e37f 304 } _ctrl_packet_buf; /**< */
TheChrisyd 0:17cb4be1e37f 305
TheChrisyd 0:17cb4be1e37f 306 uint8_t *_ctrl_packet; /**< */
TheChrisyd 0:17cb4be1e37f 307
TheChrisyd 0:17cb4be1e37f 308 uint8_t _data_buf[32]; /**< */
TheChrisyd 0:17cb4be1e37f 309
TheChrisyd 0:17cb4be1e37f 310 nRF2401A_rx_handler_t _rx_handler; /**< */
TheChrisyd 0:17cb4be1e37f 311 void *_rx_handler_arg; /**< */
TheChrisyd 0:17cb4be1e37f 312
TheChrisyd 0:17cb4be1e37f 313 /** Receive ISR.
TheChrisyd 0:17cb4be1e37f 314 * This handler is attached to the rising flank of the DR1 pin. It
TheChrisyd 0:17cb4be1e37f 315 * will thus be called when the nRF2401A receives a packet in ShockBurst
TheChrisyd 0:17cb4be1e37f 316 * mode (the mode used). It will in turn call the attached handler.
TheChrisyd 0:17cb4be1e37f 317 */
TheChrisyd 0:17cb4be1e37f 318 void dataReadyHandler(void);
TheChrisyd 0:17cb4be1e37f 319
TheChrisyd 0:17cb4be1e37f 320 /**
TheChrisyd 0:17cb4be1e37f 321 *
TheChrisyd 0:17cb4be1e37f 322 */
TheChrisyd 0:17cb4be1e37f 323 InterruptIn _dr1_isr;
TheChrisyd 0:17cb4be1e37f 324
TheChrisyd 0:17cb4be1e37f 325 /*
TheChrisyd 0:17cb4be1e37f 326 *
TheChrisyd 0:17cb4be1e37f 327 */
TheChrisyd 0:17cb4be1e37f 328 typedef enum { RX_MODE = 0x1, TX_MODE = 0x0 } TXR_T;
TheChrisyd 0:17cb4be1e37f 329
TheChrisyd 0:17cb4be1e37f 330 /** Write to the data bus.
TheChrisyd 0:17cb4be1e37f 331 * Write n_bits bits on the DATA line.
TheChrisyd 2:ca8602ee9e1d 332 * @param buf Data buffer.
TheChrisyd 2:ca8602ee9e1d 333 * @param n_bits Number of bits to transfer.
TheChrisyd 2:ca8602ee9e1d 334 * @param is_ctrl True if the tranfered data is control word, false if data.
TheChrisyd 0:17cb4be1e37f 335 */
TheChrisyd 0:17cb4be1e37f 336 void pushCtrl(uint8_t *buf, uint8_t n_bits, bool is_ctrl = true);
TheChrisyd 0:17cb4be1e37f 337
TheChrisyd 1:8c57f88ff574 338 /** Read a message from the tranceiver.
TheChrisyd 0:17cb4be1e37f 339 * Read until DR1 goes low.
TheChrisyd 2:ca8602ee9e1d 340 * @param buf Data buffer.
TheChrisyd 2:ca8602ee9e1d 341 * @return Number of bits read.
TheChrisyd 0:17cb4be1e37f 342 */
TheChrisyd 0:17cb4be1e37f 343 int pull(uint8_t *buf);
TheChrisyd 2:ca8602ee9e1d 344 };
TheChrisyd 2:ca8602ee9e1d 345
TheChrisyd 2:ca8602ee9e1d 346 #endif