nRF24L01 driver

Dependents:   Nucleo_IOT1 wireless

Revision:
0:7313e63394c3
Child:
5:bb28775120e7
diff -r 000000000000 -r 7313e63394c3 nRF24L01P_PTX.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nRF24L01P_PTX.h	Sun Aug 11 11:58:05 2013 +0000
@@ -0,0 +1,62 @@
+// A simple PTX driver for the nRF24L01+
+// with fixed payload length
+
+#ifndef NRF24L01P_PTX_H
+#define NRF24L01P_PTX_H
+
+#include "nRF24L01P.h"
+
+class nRF24L01P_PTX
+{
+   public:
+      nRF24L01P_PTX(nRF24L01P& Device_, PinName CE_, PinName Int_);
+
+      // Initialize the device for transmitting.  There must be a delay of 
+      // at least 100ms from initial power on before this function is called.
+      void Initialize();
+
+      // Set the channel number, 0 .. 125
+      void SetChannel(int Channel);
+
+      // sets the data rate in Kbps, valid values are 250 (nRF24L01+ only), 1000, 2000
+      void SetDataRate(int Rate);
+      
+      // Set the transmitter power in dB.  Valid values are -18, -12, -6, 0
+      void SetTransmitPower(int Power);
+      
+      // Set the 40-bit destination address
+      void SetDestinationAddress(uint64_t Address);
+
+      // Power up ready to transmit.  There is a delay of Tpd2stby_us
+      // after PowerUp() before a packet can be transmitted.  This
+      // is handled automatically with a timer, so that TransmitPacket()
+      // will block until the device is ready.
+      void PowerUp();
+      
+      // Powers down the device.  PowerUp must be called before a packet can be transmitted.
+      void PowerDown();
+
+      // Returns true if the device is ready to transmit a packet, ie
+      // powered on and not busy
+      bool IsReadyTransmit();
+
+      // Does the actual transmit of a packet, in blocking mode.
+      // Returns 0 on success.
+      // Returns -1 if the packet wasn't successfully acknowledged.
+      int TransmitPacket(char* Buf, int Size);
+
+   private:
+      void IntHandler();
+      void ReadyInitialize();
+      void ReadyStandby();
+   
+      nRF24L01P& Device;
+      DigitalOut CE;
+      InterruptIn Int;
+      Timeout PowerOnTimer;
+      Timeout InitializeTimer;
+      
+      int volatile Status;
+};
+
+#endif