Library for the (decidedly not as good as the 24L01+) Nordic 2401A radio.

Fork of Nrf2401 by Heroic Robotics

Revision:
1:049f6cb8b160
Parent:
0:db163b6f1592
--- a/Nrf2401A.cpp	Fri Sep 20 20:55:24 2013 +0000
+++ b/Nrf2401A.cpp	Fri Sep 20 21:47:44 2013 +0000
@@ -16,61 +16,15 @@
  *  Notes:
  *  ------
  *  For documentation on how to use this library, please visit http://www.arduino.cc/playground/Main/InterfacingWithHardware
- *  Pin connections should be as follows for Arduino:
- *
- *  DR1 = 2  (digital pin 2)
- *  CE  = 3
- *  CS  = 4
- *  CLK = 5
- *  DAT = 6
  *
  */
 
-#include "Nrf2401.h"
-
-inline void select_chip(void) {
-    _ce = 1;
-}
-
-inline void deselect_chip(void) {
-    _ce = 0;
-}
-
-inline void enable_chip(void) {
-    _ce = 1;
-}
-
-inline void disable_chip(void) {
-    _ce = 0;
-}
+#include "Nrf2401A.h"
+#include "mbed.h"
 
-inline void cycle_clock(void) {
-    _clk = 1;
-    delay_us(1);
-    _clk = 0;
-}
-
-inline void tx_data_lo(void) {
-    _dat.output();
-    _dat = 1;
-}
-
-inline void tx_data_hi(void) {
-    _dat.output();
-    _dat = 1;
-}
-
-inline int rx_data_hi(void) {
-    _dat.input();
-    return _dat;
-}
-
-inline int data_ready(void) {
-    return _dr1;
-}
 
 Nrf2401::Nrf2401(PinName n_DR1, PinName n_CE, PinName n_CS, PinName n_CLK, PinName n_DAT) :
-    _dr1(n_DR1), _ce(n_CE), _cs(n_CS), _clk(n_CLK), _clk(n_CLK), _dat(n_DAT)
+    _dr1(n_DR1), _ce(n_CE), _cs(n_CS), _clk(n_CLK), _dat(n_DAT)
 {
   _dat.output();
   
@@ -96,7 +50,7 @@
   if(messageSize) payloadSize = messageSize, configure();
   else configuration[14] |= 1, loadConfiguration(true);
   enable_chip();
-  delay_us(250);
+  wait_us(250);
 }
 
 void Nrf2401::txMode(unsigned char messageSize)
@@ -104,14 +58,14 @@
   mode = 0;
   if(messageSize) payloadSize = messageSize, configure();
   else configuration[14] &= ~1, loadConfiguration(true);
-  delay_us(250);
+  wait_us(250);
 }
 
 void Nrf2401::write(unsigned char* dataBuffer)
 {
   if(!dataBuffer) dataBuffer = (unsigned char*) data;
   enable_chip();
-  delay_us(5);
+  wait_us(5);
   loadByte(configuration[7]);
   loadByte(configuration[8]);
   loadByte(configuration[9]);
@@ -119,7 +73,7 @@
   loadByte(remoteAddress);
   for(int i=0; i<payloadSize; i++) loadByte(dataBuffer[i]);
   disable_chip();
-  delay_us(250);
+  wait_us(250);
 }
 
 void Nrf2401::write(unsigned char dataByte)
@@ -132,19 +86,19 @@
 {
   if(!dataBuffer) dataBuffer = (unsigned char*) data;
   disable_chip();
-  _delay_ms(2);
+  wait_ms(2);
   for(int i=0; i<payloadSize; i++)
   {
     dataBuffer[i] = 0;
     for(int n=7; n>-1; n--)
     {
-      if(RX_DATA_HI) dataBuffer[i] |= (1 << n);
-      delay_us(1);
+      if(rx_data_hi()) dataBuffer[i] |= (1 << n);
+      wait_us(1);
       cycle_clock();
     }
   }
   enable_chip();
-  delay_us(1);
+  wait_us(1);
 }
 
 bool Nrf2401::available(void)
@@ -169,7 +123,7 @@
 {
   disable_chip();
   select_chip();
-  delay_us(5);
+  wait_us(5);
   if(modeSwitchOnly) loadByte(configuration[14]);
   else for(int i=0; i<15; i++) loadByte(configuration[i]);
   deselect_chip();
@@ -181,7 +135,7 @@
   {
     if((byte & (1 << i)) == 0) tx_data_lo();
     else                       tx_data_hi();
-    delay_us(1);
+    wait_us(1);
     cycle_clock();
   }
 }