nrf24l01 :: Added NRF module with examples.
authorYevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
Mon, 2 Jun 2014 09:33:21 +0000 (02:33 -0700)
committerYevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
Mon, 2 Jun 2014 09:33:21 +0000 (02:33 -0700)
Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
examples/CMakeLists.txt
examples/nrf_receiver.cxx [new file with mode: 0644]
examples/nrf_transmitter.cxx [new file with mode: 0644]
src/CMakeLists.txt
src/nrf24l01/CMakeLists.txt [new file with mode: 0644]
src/nrf24l01/jsupm_nrf24l01.i [new file with mode: 0644]
src/nrf24l01/nrf24l01.cxx [new file with mode: 0644]
src/nrf24l01/nrf24l01.h [new file with mode: 0644]
src/nrf24l01/pyupm_nrf24l01.i [new file with mode: 0644]

index 4f98602..44ffc36 100644 (file)
@@ -6,6 +6,8 @@ add_executable (rgb-lcd rgb-lcd.cxx)
 add_executable (buzzer-sound buzzer-sound.cxx)
 add_executable (led-bar led-bar.cxx)
 add_executable (seg-lcd 4digitdisplay.cxx)
+add_executable (nrf_transmitter nrf_transmitter.cxx)
+add_executable (nrf_receiver nrf_receiver.cxx)
 
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
 include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@@ -13,6 +15,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/lcd)
 include_directories (${PROJECT_SOURCE_DIR}/src/buzzer)
 include_directories (${PROJECT_SOURCE_DIR}/src/ledbar)
 include_directories (${PROJECT_SOURCE_DIR}/src/4digitdisplay)
+include_directories (${PROJECT_SOURCE_DIR}/src/nrf24l01)
 
 target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
 target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
@@ -22,3 +25,5 @@ target_link_libraries (rgb-lcd i2clcd ${CMAKE_THREAD_LIBS_INIT})
 target_link_libraries (buzzer-sound buzzer ${CMAKE_THREAD_LIBS_INIT})
 target_link_libraries (led-bar ledbar ${CMAKE_THREAD_LIBS_INIT})
 target_link_libraries (seg-lcd 4digitdisplay ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries (nrf_transmitter nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries (nrf_receiver nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
diff --git a/examples/nrf_receiver.cxx b/examples/nrf_receiver.cxx
new file mode 100644 (file)
index 0000000..77ce571
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
+ * Copyright (c) 2014 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <string.h>
+#include <unistd.h>
+#include <iostream>
+#include "nrf24l01.h"
+#include <signal.h>
+
+int running = 0;
+upm::NRF24l01 *comm = NULL;
+
+void
+sig_handler(int signo)
+{
+       printf("got signal\n");
+    if (signo == SIGINT) {
+        printf("exiting application\n");
+        running = 1;
+    }
+}
+
+void nrf_handler () {
+       std::cout << "devi1 :: " << *((uint32_t *)&(comm->m_rxBuffer[0])) << std::endl;
+}
+
+int
+main(int argc, char **argv)
+{
+    comm = new upm::NRF24l01(7);
+       comm->nrfSetRXaddr ((uint8_t *) "devi1");
+       comm->nrfSetTXaddr ((uint8_t *) "devi2");
+       comm->nrfSetPayload (MAX_BUFFER);
+       comm->nrfConfigModule ();
+       comm->dataRecievedHandler = nrf_handler;
+       
+       signal(SIGINT, sig_handler);
+
+       while (!running) {
+               comm->nrfListenForChannel ();
+       }
+
+       std::cout << "exiting application" << std::endl;
+
+       delete comm;
+
+    return 0;
+}
diff --git a/examples/nrf_transmitter.cxx b/examples/nrf_transmitter.cxx
new file mode 100644 (file)
index 0000000..0679f38
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
+ * Copyright (c) 2014 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <string.h>
+#include <unistd.h>
+#include <iostream>
+#include "nrf24l01.h"
+#include <signal.h>
+
+int running = 0;
+upm::NRF24l01 *comm = NULL;
+
+void
+sig_handler(int signo)
+{
+       printf("got signal\n");
+    if (signo == SIGINT) {
+        printf("exiting application\n");
+        running = 1;
+    }
+}
+
+void nrf_handler () {
+}
+
+int
+main(int argc, char **argv)
+{
+       uint32_t dummyData = 0;
+    comm = new upm::NRF24l01(7);
+       comm->nrfSetRXaddr ((uint8_t *) "devi2");
+       comm->nrfSetTXaddr ((uint8_t *) "devi1");
+       comm->nrfSetPayload (MAX_BUFFER);
+       comm->nrfConfigModule ();
+       comm->dataRecievedHandler = nrf_handler;
+       
+       signal(SIGINT, sig_handler);
+
+       while (!running) {
+               memcpy (comm->m_txBuffer, &dummyData, sizeof (dummyData));
+               comm->nrfSend ();
+               std::cout << "devi2 :: sending data ...." << dummyData << std::endl;
+               usleep (3000000);
+               dummyData += 3000;
+       }
+
+       std::cout << "exiting application" << std::endl;
+
+       delete comm;
+
+    return 0;
+}
index 5db9c01..87264f5 100644 (file)
@@ -4,3 +4,4 @@ add_subdirectory (lcd)
 add_subdirectory (buzzer)
 add_subdirectory (ledbar)
 add_subdirectory (4digitdisplay)
+add_subdirectory (nrf24l01)
diff --git a/src/nrf24l01/CMakeLists.txt b/src/nrf24l01/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9fc5bb9
--- /dev/null
@@ -0,0 +1,4 @@
+set (libname "nrf24l01")
+add_library (nrf24l01 SHARED nrf24l01.cxx)
+include_directories (${MAA_INCLUDE_DIR})
+target_link_libraries (nrf24l01 ${MAA_LIBRARIES})
diff --git a/src/nrf24l01/jsupm_nrf24l01.i b/src/nrf24l01/jsupm_nrf24l01.i
new file mode 100644 (file)
index 0000000..0e66e82
--- /dev/null
@@ -0,0 +1,7 @@
+%module jsupm_nrf24l01
+
+%{
+    #include "nrf24l01.h"
+%}
+
+%include "nrf24l01.h"
diff --git a/src/nrf24l01/nrf24l01.cxx b/src/nrf24l01/nrf24l01.cxx
new file mode 100644 (file)
index 0000000..b1f0f2c
--- /dev/null
@@ -0,0 +1,319 @@
+/*
+ * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
+ * Copyright (c) 2014 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <iostream>
+#include <unistd.h>
+
+#include "nrf24l01.h"
+
+using namespace upm;
+
+NRF24l01::NRF24l01 (uint8_t cs) {
+       maa_init();
+       nrfInitModule (cs, 8);
+}
+
+NRF24l01::~NRF24l01 () {
+       maa_result_t error = MAA_SUCCESS;
+       error = maa_spi_stop(m_spi);
+       if (error != MAA_SUCCESS) {
+        maa_result_print(error);
+    }
+       error = maa_gpio_close (m_cePinCtx);
+    if (error != MAA_SUCCESS) {
+        maa_result_print(error);
+    }
+       error = maa_gpio_close (m_csnPinCtx);
+    if (error != MAA_SUCCESS) {
+        maa_result_print(error);
+    }
+}
+
+void 
+NRF24l01::nrfInitModule (uint8_t chip_select, uint8_t chip_enable) {
+       maa_result_t error = MAA_SUCCESS;
+
+       m_csn           = chip_select;
+       m_ce            = chip_enable;
+       m_channel       = 1;
+
+       m_csnPinCtx = maa_gpio_init (m_csn);
+       if (m_csnPinCtx == NULL) {
+        fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_csn);
+               exit (1);
+       }
+       
+       m_cePinCtx = maa_gpio_init (m_ce);
+       if (m_cePinCtx == NULL) {
+        fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_ce);
+               exit (1);
+       }
+       
+       error = maa_gpio_dir (m_csnPinCtx, MAA_GPIO_OUT);
+    if (error != MAA_SUCCESS) {
+        maa_result_print (error);
+    }
+
+       error = maa_gpio_dir (m_cePinCtx, MAA_GPIO_OUT);
+    if (error != MAA_SUCCESS) {
+        maa_result_print (error);
+    }
+       
+       nrfCELow ();
+       m_spi = maa_spi_init (0);
+}
+
+void 
+NRF24l01::nrfConfigModule() {
+       /* Set RF channel */
+       nrfConfigRegister (RF_CH, m_channel);
+
+       /* Set length of incoming payload */
+       nrfConfigRegister (RX_PW_P0, m_payload);
+       nrfConfigRegister (RX_PW_P1, m_payload);
+       /* Set length of incoming payload for broadcast */
+       nrfConfigRegister (RX_PW_P2, m_payload);
+       
+       /* Start receiver */
+       nrfPowerUpRX ();
+       nrfFlushRX ();
+}
+
+/* Clocks only one byte into the given MiRF register */
+void 
+NRF24l01::nrfConfigRegister(uint8_t reg, uint8_t value) {
+       nrfCSOn ();
+       maa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
+       maa_spi_write (m_spi, value);
+       nrfCSOff ();
+}
+
+void 
+NRF24l01::nrfPowerUpRX() {
+       m_ptx = 0;
+       nrfCELow();
+       nrfConfigRegister(CONFIG, mirf_CONFIG | ( (1<<PWR_UP) | (1<<PRIM_RX) ) );
+       nrfCEHigh();
+       nrfConfigRegister(STATUS,(1 << TX_DS) | (1 << MAX_RT)); 
+}
+
+void 
+NRF24l01::nrfFlushRX() {
+       nrfCSOn ();
+       maa_spi_write (m_spi, FLUSH_RX);
+       nrfCSOff ();
+}
+
+/* Sets the receiving address */
+void 
+NRF24l01::nrfSetRXaddr(uint8_t * addr) {
+       nrfCELow();
+       nrfWriteRegister(RX_ADDR_P1, addr, mirf_ADDR_LEN);
+       nrfCEHigh();
+}
+
+/* Sets the transmitting address */
+void 
+NRF24l01::nrfSetTXaddr(uint8_t * addr)
+{
+       /* RX_ADDR_P0 must be set to the sending addr for auto ack to work. */
+       nrfWriteRegister (RX_ADDR_P0, addr, mirf_ADDR_LEN);
+       nrfWriteRegister (TX_ADDR, addr, mirf_ADDR_LEN);
+}
+
+/* The broadcast address should be 0xFFFFF */
+void 
+NRF24l01::nrfSetBroadcastAddr (uint8_t * addr) {
+       nrfCELow ();
+       nrfWriteRegister (RX_ADDR_P2, addr, mirf_ADDR_LEN);
+       nrfCEHigh ();
+}
+
+void 
+NRF24l01::nrfSetPayload (uint8_t load) {
+       m_payload = load;
+}
+
+void 
+NRF24l01::nrfWriteRegister(uint8_t reg, uint8_t * value, uint8_t len) 
+{
+       nrfCSOn ();
+       maa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
+       nrfTransmitSync(value, len);
+       nrfCSOff ();
+}
+
+void 
+NRF24l01::nrfTransmitSync(uint8_t *dataout, uint8_t len){
+       uint8_t i;
+       for(i = 0; i < len; i++) {
+               maa_spi_write (m_spi, dataout[i]);
+       }
+}
+
+/* Checks if data is available for reading */
+bool 
+NRF24l01::nrfDataReady() {
+       uint8_t status = nrfGetStatus();
+       if ( status & (1 << RX_DR) ) {
+               return 1;
+       }
+       
+       return !nrfRXFifoEmpty();
+}
+
+uint8_t 
+NRF24l01::nrfGetStatus () {
+       uint8_t rv;
+       nrfReadRegister (STATUS, &rv, 1);
+       return rv;
+}
+
+/* Reads an array of bytes from the given start position in the MiRF registers. */
+void 
+NRF24l01::nrfReadRegister (uint8_t reg, uint8_t * value, uint8_t len)
+{
+       nrfCSOn ();
+       maa_spi_write (m_spi, R_REGISTER | (REGISTER_MASK & reg));
+       nrfTransferSync (value, value, len);
+       nrfCSOff ();
+}
+
+void 
+NRF24l01::nrfTransferSync (uint8_t *dataout,uint8_t *datain,uint8_t len) {
+       uint8_t i;
+       for(i = 0;i < len;i++) {
+               datain[i] = maa_spi_write (m_spi, dataout[i]);
+       }
+}
+
+bool 
+NRF24l01::nrfRXFifoEmpty () {
+       uint8_t fifo_status;
+       nrfReadRegister (FIFO_STATUS, &fifo_status, sizeof(fifo_status));
+       return (fifo_status & (1 << RX_EMPTY));
+}
+
+/* Reads payload bytes into data array */
+void 
+NRF24l01::nrfGetData (uint8_t * data) 
+{
+       nrfCSOn ();
+       /* Send cmd to read rx payload */
+       maa_spi_write (m_spi, R_RX_PAYLOAD);
+       /* Read payload */
+       nrfTransferSync(data, data, m_payload);
+       nrfCSOff ();
+       nrfConfigRegister(STATUS, (1<<RX_DR));
+}
+
+/* Sends a data package to the default address. Be sure to send the correct
+ * amount of bytes as configured as payload on the receiver. */
+void 
+NRF24l01::nrfSend(uint8_t * value) {
+       uint8_t status;
+       status = nrfGetStatus();
+
+       while (m_ptx) {
+               status = nrfGetStatus();
+
+               if((status & ((1 << TX_DS)  | (1 << MAX_RT)))){
+                       m_ptx = 0;
+                       break;
+               }
+       } // Wait until last paket is send
+
+       nrfCELow();
+       nrfPowerUpTX();                                                 // Set to transmitter mode , Power up
+       nrfCSOn ();
+       maa_spi_write (m_spi, FLUSH_TX);                // Write cmd to flush tx fifo
+       nrfCSOff ();
+       
+       nrfCSOn ();
+       maa_spi_write (m_spi, W_TX_PAYLOAD);    // Write cmd to write payload
+       nrfTransmitSync(value, m_payload);              // Write payload
+       nrfCSOff ();
+       nrfCEHigh();                                                    // Start transmission
+}
+
+void 
+NRF24l01::nrfSend () {
+       nrfSend (m_txBuffer);
+}
+
+bool 
+NRF24l01::nrfIsSending () {
+       uint8_t status;
+       if (m_ptx)      { // Sending mode.
+               status = nrfGetStatus();
+               /* if sending successful (TX_DS) or max retries exceded (MAX_RT). */
+               if((status & ((1 << TX_DS)  | (1 << MAX_RT)))){
+                       nrfPowerUpRX();
+                       return false; 
+               }
+               return true;
+       }
+       return false;
+}
+
+void 
+NRF24l01::nrfPowerUpTX () {
+       m_ptx = 1;
+       nrfConfigRegister (CONFIG, mirf_CONFIG | ( (1<<PWR_UP) | (0<<PRIM_RX) ) );
+}
+
+void 
+NRF24l01::nrfPowerDown () {
+       nrfCELow ();
+       nrfConfigRegister (CONFIG, mirf_CONFIG);
+}
+
+maa_result_t 
+NRF24l01::nrfCEHigh () {
+       return maa_gpio_write (m_cePinCtx, HIGH);
+}
+
+maa_result_t 
+NRF24l01::nrfCELow () {
+       return maa_gpio_write (m_cePinCtx, LOW);
+}
+
+maa_result_t 
+NRF24l01::nrfCSOn () {
+       return maa_gpio_write (m_csnPinCtx, LOW);
+}
+
+maa_result_t 
+NRF24l01::nrfCSOff () {
+       return maa_gpio_write (m_csnPinCtx, HIGH);
+}
+
+void 
+NRF24l01::nrfListenForChannel() {
+       if(!nrfIsSending() && nrfDataReady()) {
+               nrfGetData(m_rxBuffer);
+               dataRecievedHandler(); /* let know that data arrived */
+       }
+}
+
diff --git a/src/nrf24l01/nrf24l01.h b/src/nrf24l01/nrf24l01.h
new file mode 100644 (file)
index 0000000..223fb31
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
+ * Copyright (c) 2014 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#pragma once
+
+#include <string>
+#include <maa/aio.h>
+#include <maa/gpio.h>
+#include <maa/spi.h>
+
+/* Memory Map */
+#define CONFIG                 0x00
+#define EN_AA                  0x01
+#define EN_RXADDR              0x02
+#define SETUP_AW               0x03
+#define SETUP_RETR             0x04
+#define RF_CH                  0x05
+#define RF_SETUP               0x06
+#define STATUS                 0x07
+#define OBSERVE_TX             0x08
+#define CD                     0x09
+#define RX_ADDR_P0             0x0A
+#define RX_ADDR_P1             0x0B
+#define RX_ADDR_P2             0x0C
+#define RX_ADDR_P3             0x0D
+#define RX_ADDR_P4             0x0E
+#define RX_ADDR_P5             0x0F
+#define TX_ADDR                0x10
+#define RX_PW_P0               0x11
+#define RX_PW_P1               0x12
+#define RX_PW_P2               0x13
+#define RX_PW_P3               0x14
+#define RX_PW_P4               0x15
+#define RX_PW_P5               0x16
+#define FIFO_STATUS            0x17
+
+/* Bit Mnemonics */
+#define MASK_RX_DR             6
+#define MASK_TX_DS             5
+#define MASK_MAX_RT            4
+#define EN_CRC                 3
+#define CRCO                   2
+#define PWR_UP                 1
+#define PRIM_RX                0
+#define ENAA_P5                5
+#define ENAA_P4                4
+#define ENAA_P3                3
+#define ENAA_P2                2
+#define ENAA_P1                1
+#define ENAA_P0                0
+#define ERX_P5                 5
+#define ERX_P4                 4
+#define ERX_P3                 3
+#define ERX_P2                 2
+#define ERX_P1                 1
+#define ERX_P0                 0
+#define AW                     0
+#define ARD                    4
+#define ARC                    0
+#define PLL_LOCK               4
+#define RF_DR                  3
+#define RF_PWR                 1
+#define LNA_HCURR              0        
+#define RX_DR                  6
+#define TX_DS                  5
+#define MAX_RT                 4
+#define RX_P_NO                1
+#define TX_FULL                0
+#define PLOS_CNT               4
+#define ARC_CNT                0
+#define TX_REUSE               6
+#define FIFO_FULL              5
+#define TX_EMPTY               4
+#define RX_FULL                1
+#define RX_EMPTY               0
+
+/* Instruction Mnemonics */
+#define R_REGISTER             0x00
+#define W_REGISTER             0x20
+#define REGISTER_MASK          0x1F
+#define R_RX_PAYLOAD           0x61
+#define W_TX_PAYLOAD           0xA0
+#define FLUSH_TX               0xE1
+#define FLUSH_RX               0xE2
+#define REUSE_TX_PL            0xE3
+#define NOP                    0xFF
+
+/* Nrf24l settings */
+#define mirf_ADDR_LEN          5
+#define mirf_CONFIG            ((1<<EN_CRC) | (0<<CRCO) )
+
+#define MAX_BUFFER                     32
+
+#define HIGH                   1
+#define LOW                            0
+
+namespace upm {
+
+typedef void (* funcPtrVoidVoid) ();
+
+class NRF24l01 {
+    public:
+               NRF24l01 (uint8_t cs);
+               ~NRF24l01 ();
+               std::string name()
+        {
+            return m_name;
+        }
+
+               void nrfInitModule (uint8_t chipSelect, uint8_t chipEnable);
+               void nrfConfigModule ();
+               void nrfSend (uint8_t *value);
+               void nrfSend ();
+               void nrfSetRXaddr (uint8_t * addr);
+               void nrfSetTXaddr (uint8_t * addr);
+               void nrfSetBroadcastAddr (uint8_t * addr);
+               void nrfSetPayload (uint8_t load);
+               bool nrfDataReady ();
+               bool nrfIsSending ();
+               bool nrfRXFifoEmpty ();
+               bool nrfTXFifoEmpty ();
+               void nrfGetData (uint8_t * data);
+               uint8_t nrfGetStatus ();
+               
+               void nrfTransmitSync (uint8_t *dataout, uint8_t len);
+               void nrfTransferSync (uint8_t *dataout ,uint8_t *datain, uint8_t len);
+               void nrfConfigRegister (uint8_t reg, uint8_t value);
+               void nrfReadRegister (uint8_t reg, uint8_t * value, uint8_t len);
+               void nrfWriteRegister (uint8_t reg, uint8_t * value, uint8_t len);
+               void nrfPowerUpRX ();
+               void nrfPowerUpTX ();
+               void nrfPowerDown ();
+
+               maa_result_t nrfCEHigh ();
+               maa_result_t nrfCELow ();
+               maa_result_t nrfCSOn ();
+               maa_result_t nrfCSOff ();
+               void nrfFlushRX ();
+               void nrfListenForChannel();
+
+               uint8_t                         m_rxBuffer[MAX_BUFFER];
+               uint8_t                         m_txBuffer[MAX_BUFFER];
+
+               funcPtrVoidVoid dataRecievedHandler;
+       private:
+               maa_spi_context         m_spi;
+               uint8_t                         m_ce;
+               uint8_t                         m_csn;
+               uint8_t                         m_channel;
+               uint8_t                         m_ptx;
+               uint8_t                         m_payload;
+               uint8_t                         m_localAddress[5];
+               
+               maa_gpio_context        m_csnPinCtx;
+               maa_gpio_context        m_cePinCtx;
+
+               std::string             m_name;
+};
+
+}
diff --git a/src/nrf24l01/pyupm_nrf24l01.i b/src/nrf24l01/pyupm_nrf24l01.i
new file mode 100644 (file)
index 0000000..433c655
--- /dev/null
@@ -0,0 +1,8 @@
+%module pyupm_nrf24l01
+
+%feature("autodoc", "3");
+
+%include "nrf24l01.h"
+%{
+    #include "nrf24l01.h"
+%}