Browse Source

doxygen: Added documentation to nrf24l01 module

Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
Kiveisha Yevgeniy 10 years ago
parent
commit
451d0390b6
4 changed files with 195 additions and 24 deletions
  1. 5
    2
      examples/nrf_receiver.cxx
  2. 3
    2
      examples/nrf_transmitter.cxx
  3. 13
    13
      src/nrf24l01/nrf24l01.cxx
  4. 174
    7
      src/nrf24l01/nrf24l01.h

+ 5
- 2
examples/nrf_receiver.cxx View File

@@ -41,20 +41,23 @@ sig_handler(int signo)
41 41
     }
42 42
 }
43 43
 
44
+//! [Interesting]
44 45
 void nrf_handler () {
45 46
     std::cout << "devi1 :: " << *((uint32_t *)&(comm->m_rxBuffer[0])) << std::endl;
46 47
 }
48
+//! [Interesting]
47 49
 
48 50
 int
49 51
 main(int argc, char **argv)
50 52
 {
53
+//! [Interesting]
51 54
     comm = new upm::NRF24l01(7);
52 55
     comm->nrfSetRXaddr ((uint8_t *) "devi1");
53 56
     comm->nrfSetTXaddr ((uint8_t *) "devi2");
54 57
     comm->nrfSetPayload (MAX_BUFFER);
55 58
     comm->nrfConfigModule ();
56 59
     comm->dataRecievedHandler = nrf_handler;
57
-    
60
+
58 61
     signal(SIGINT, sig_handler);
59 62
 
60 63
     while (!running) {
@@ -64,6 +67,6 @@ main(int argc, char **argv)
64 67
     std::cout << "exiting application" << std::endl;
65 68
 
66 69
     delete comm;
67
-
70
+//! [Interesting]
68 71
     return 0;
69 72
 }

+ 3
- 2
examples/nrf_transmitter.cxx View File

@@ -47,6 +47,7 @@ void nrf_handler () {
47 47
 int
48 48
 main(int argc, char **argv)
49 49
 {
50
+//! [Interesting]
50 51
     uint32_t dummyData = 0;
51 52
     comm = new upm::NRF24l01(7);
52 53
     comm->nrfSetRXaddr ((uint8_t *) "devi2");
@@ -54,7 +55,7 @@ main(int argc, char **argv)
54 55
     comm->nrfSetPayload (MAX_BUFFER);
55 56
     comm->nrfConfigModule ();
56 57
     comm->dataRecievedHandler = nrf_handler;
57
-    
58
+
58 59
     signal(SIGINT, sig_handler);
59 60
 
60 61
     while (!running) {
@@ -68,6 +69,6 @@ main(int argc, char **argv)
68 69
     std::cout << "exiting application" << std::endl;
69 70
 
70 71
     delete comm;
71
-
72
+//! [Interesting]
72 73
     return 0;
73 74
 }

+ 13
- 13
src/nrf24l01/nrf24l01.cxx View File

@@ -64,13 +64,13 @@ NRF24l01::nrfInitModule (uint8_t chip_select, uint8_t chip_enable) {
64 64
         fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_csn);
65 65
         exit (1);
66 66
     }
67
-    
67
+
68 68
     m_cePinCtx = maa_gpio_init (m_ce);
69 69
     if (m_cePinCtx == NULL) {
70 70
         fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_ce);
71 71
         exit (1);
72 72
     }
73
-    
73
+
74 74
     error = maa_gpio_dir (m_csnPinCtx, MAA_GPIO_OUT);
75 75
     if (error != MAA_SUCCESS) {
76 76
         maa_result_print (error);
@@ -80,7 +80,7 @@ NRF24l01::nrfInitModule (uint8_t chip_select, uint8_t chip_enable) {
80 80
     if (error != MAA_SUCCESS) {
81 81
         maa_result_print (error);
82 82
     }
83
-    
83
+
84 84
     nrfCELow ();
85 85
     m_spi = maa_spi_init (0);
86 86
 }
@@ -95,7 +95,7 @@ NRF24l01::nrfConfigModule() {
95 95
     nrfConfigRegister (RX_PW_P1, m_payload);
96 96
     /* Set length of incoming payload for broadcast */
97 97
     nrfConfigRegister (RX_PW_P2, m_payload);
98
-    
98
+
99 99
     /* Start receiver */
100 100
     nrfPowerUpRX ();
101 101
     nrfFlushRX ();
@@ -114,7 +114,7 @@ void
114 114
 NRF24l01::nrfPowerUpRX() {
115 115
     m_ptx = 0;
116 116
     nrfCELow();
117
-    nrfConfigRegister(CONFIG, mirf_CONFIG | ( (1<<PWR_UP) | (1<<PRIM_RX) ) );
117
+    nrfConfigRegister(CONFIG, NRF_CONFIG | ( (1<<PWR_UP) | (1<<PRIM_RX) ) );
118 118
     nrfCEHigh();
119 119
     nrfConfigRegister(STATUS,(1 << TX_DS) | (1 << MAX_RT));
120 120
 }
@@ -130,7 +130,7 @@ NRF24l01::nrfFlushRX() {
130 130
 void
131 131
 NRF24l01::nrfSetRXaddr(uint8_t * addr) {
132 132
     nrfCELow();
133
-    nrfWriteRegister(RX_ADDR_P1, addr, mirf_ADDR_LEN);
133
+    nrfWriteRegister(RX_ADDR_P1, addr, ADDR_LEN);
134 134
     nrfCEHigh();
135 135
 }
136 136
 
@@ -139,15 +139,15 @@ void
139 139
 NRF24l01::nrfSetTXaddr(uint8_t * addr)
140 140
 {
141 141
     /* RX_ADDR_P0 must be set to the sending addr for auto ack to work. */
142
-    nrfWriteRegister (RX_ADDR_P0, addr, mirf_ADDR_LEN);
143
-    nrfWriteRegister (TX_ADDR, addr, mirf_ADDR_LEN);
142
+    nrfWriteRegister (RX_ADDR_P0, addr, ADDR_LEN);
143
+    nrfWriteRegister (TX_ADDR, addr, ADDR_LEN);
144 144
 }
145 145
 
146 146
 /* The broadcast address should be 0xFFFFF */
147 147
 void
148 148
 NRF24l01::nrfSetBroadcastAddr (uint8_t * addr) {
149 149
     nrfCELow ();
150
-    nrfWriteRegister (RX_ADDR_P2, addr, mirf_ADDR_LEN);
150
+    nrfWriteRegister (RX_ADDR_P2, addr, ADDR_LEN);
151 151
     nrfCEHigh ();
152 152
 }
153 153
 
@@ -180,7 +180,7 @@ NRF24l01::nrfDataReady() {
180 180
     if ( status & (1 << RX_DR) ) {
181 181
         return 1;
182 182
     }
183
-    
183
+
184 184
     return !nrfRXFifoEmpty();
185 185
 }
186 186
 
@@ -250,7 +250,7 @@ NRF24l01::nrfSend(uint8_t * value) {
250 250
     nrfCSOn ();
251 251
     maa_spi_write (m_spi, FLUSH_TX);        // Write cmd to flush tx fifo
252 252
     nrfCSOff ();
253
-    
253
+
254 254
     nrfCSOn ();
255 255
     maa_spi_write (m_spi, W_TX_PAYLOAD);     // Write cmd to write payload
256 256
     nrfTransmitSync(value, m_payload);        // Write payload
@@ -281,13 +281,13 @@ NRF24l01::nrfIsSending () {
281 281
 void
282 282
 NRF24l01::nrfPowerUpTX () {
283 283
     m_ptx = 1;
284
-    nrfConfigRegister (CONFIG, mirf_CONFIG | ( (1<<PWR_UP) | (0<<PRIM_RX) ) );
284
+    nrfConfigRegister (CONFIG, NRF_CONFIG | ( (1<<PWR_UP) | (0<<PRIM_RX) ) );
285 285
 }
286 286
 
287 287
 void
288 288
 NRF24l01::nrfPowerDown () {
289 289
     nrfCELow ();
290
-    nrfConfigRegister (CONFIG, mirf_CONFIG);
290
+    nrfConfigRegister (CONFIG, NRF_CONFIG);
291 291
 }
292 292
 
293 293
 maa_result_t

+ 174
- 7
src/nrf24l01/nrf24l01.h View File

@@ -106,8 +106,8 @@
106 106
 #define NOP                   0xFF
107 107
 
108 108
 /* Nrf24l settings */
109
-#define mirf_ADDR_LEN        5
110
-#define mirf_CONFIG         ((1<<EN_CRC) | (0<<CRCO) )
109
+#define ADDR_LEN        5
110
+#define NRF_CONFIG         ((1<<EN_CRC) | (0<<CRCO) )
111 111
 
112 112
 #define MAX_BUFFER            32
113 113
 
@@ -118,50 +118,217 @@ namespace upm {
118 118
 
119 119
 typedef void (* funcPtrVoidVoid) ();
120 120
 
121
+/**
122
+ * @brief C++ API for NRF24l01 transceiver module
123
+ *
124
+ * This file defines the NRF24l01 C++ interface for libnrf24l01
125
+ *
126
+ * @snippet nrf_receiver.cxx Interesting
127
+ * @snippet nrf_transmitter.cxx Interesting
128
+ */
121 129
 class NRF24l01 {
122 130
     public:
131
+        /**
132
+         * Instanciates a NRF24l01 object
133
+         *
134
+         * @param cs chip select pin
135
+         */
123 136
         NRF24l01 (uint8_t cs);
137
+
138
+        /**
139
+         * NRF24l01 object destructor
140
+         */
124 141
         ~NRF24l01 ();
142
+
143
+        /**
144
+         * Return name of the component
145
+         */
125 146
         std::string name()
126 147
         {
127 148
             return m_name;
128 149
         }
129 150
 
151
+        /**
152
+         * Initialize needed Gpio pins and SPI interface
153
+         *
154
+         * @param chipSelect setting up the chip select pin
155
+         * @param chipEnable setting up the chip enable pin
156
+         */
130 157
         void nrfInitModule (uint8_t chipSelect, uint8_t chipEnable);
158
+
159
+        /**
160
+         * Configure NRF24l01 chip
161
+         */
131 162
         void nrfConfigModule ();
163
+
164
+        /**
165
+         * Send the buffer data
166
+         *
167
+         * @param *value pointer to the buffer
168
+         */
132 169
         void nrfSend (uint8_t *value);
170
+
171
+        /**
172
+         * Send the data located in inner bufer, user must fill the
173
+         * m_txBuffer buffer
174
+         */
133 175
         void nrfSend ();
176
+
177
+        /**
178
+         * Set recieving address of the device
179
+         *
180
+         * @param addr 5 bytes addres
181
+         */
134 182
         void nrfSetRXaddr (uint8_t * addr);
183
+
184
+        /**
185
+         * Set recipient address. nrfSend method will send the data buffer
186
+         * to this address
187
+         *
188
+         * @param addr 5 bytes addres
189
+         */
135 190
         void nrfSetTXaddr (uint8_t * addr);
191
+
192
+        /**
193
+         * Set broadcasting address.
194
+         *
195
+         * @param addr 5 bytes addres
196
+         */
136 197
         void nrfSetBroadcastAddr (uint8_t * addr);
198
+
199
+        /**
200
+         * Set payload size.
201
+         *
202
+         * @param load size of the payload (MAX 32)
203
+         */
137 204
         void nrfSetPayload (uint8_t load);
205
+
206
+        /**
207
+         * Check if data arrived
208
+         */
138 209
         bool nrfDataReady ();
210
+
211
+        /**
212
+         * Check if chip in sending mode
213
+         */
139 214
         bool nrfIsSending ();
215
+
216
+        /**
217
+         * Check if recieving stack is empty
218
+         */
140 219
         bool nrfRXFifoEmpty ();
220
+
221
+        /**
222
+         * Check if transmitting stack is empty
223
+         */
141 224
         bool nrfTXFifoEmpty ();
225
+
226
+        /**
227
+         * Sink all arrived data into the provided buffer
228
+         *
229
+         * @param load size of the payload (MAX 32)
230
+         */
142 231
         void nrfGetData (uint8_t * data);
232
+
233
+        /**
234
+         * Check the chip state
235
+         */
143 236
         uint8_t nrfGetStatus ();
144
-        
237
+
238
+        /**
239
+         * Transmit provided data to the chip
240
+         *
241
+         * @param *dataout pointer to the buffer with data
242
+         * @param len length of the buffer
243
+         */
145 244
         void nrfTransmitSync (uint8_t *dataout, uint8_t len);
245
+
246
+        /**
247
+         * Recieve data from the chip
248
+         *
249
+         * @param *dataout pointer to the buffer with data
250
+         * @param *datain pointer to the buffer where the arrived data
251
+         * will be sinked
252
+         * @param len length of the buffer
253
+         */
146 254
         void nrfTransferSync (uint8_t *dataout ,uint8_t *datain, uint8_t len);
255
+
256
+        /**
257
+         * Write byte value into a register
258
+         *
259
+         * @param reg register address
260
+         * @param value the value to write
261
+         */
147 262
         void nrfConfigRegister (uint8_t reg, uint8_t value);
263
+
264
+        /**
265
+         * Read continues data from register
266
+         *
267
+         * @param reg register address
268
+         * @param *value pointer to the buffer
269
+         * @param len length of the buffer
270
+         */
148 271
         void nrfReadRegister (uint8_t reg, uint8_t * value, uint8_t len);
272
+
273
+        /**
274
+         * Write continues data to register
275
+         *
276
+         * @param reg register address
277
+         * @param *value pointer to the buffer
278
+         * @param len length of the buffer
279
+         */
149 280
         void nrfWriteRegister (uint8_t reg, uint8_t * value, uint8_t len);
281
+
282
+        /**
283
+         * Power up reciever
284
+         */
150 285
         void nrfPowerUpRX ();
286
+
287
+        /**
288
+         * Power up transmitter
289
+         */
151 290
         void nrfPowerUpTX ();
291
+
292
+        /**
293
+         * Power down all
294
+         */
152 295
         void nrfPowerDown ();
153 296
 
297
+        /**
298
+         * Set chip enable pin HIGH
299
+         */
154 300
         maa_result_t nrfCEHigh ();
301
+
302
+        /**
303
+         * Set chip enable LOW
304
+         */
155 305
         maa_result_t nrfCELow ();
306
+
307
+        /**
308
+         * Set chip select pin LOW
309
+         */
156 310
         maa_result_t nrfCSOn ();
311
+
312
+        /**
313
+         * Set chip select pin HIGH
314
+         */
157 315
         maa_result_t nrfCSOff ();
316
+
317
+        /**
318
+         * Flush reciver stack
319
+         */
158 320
         void nrfFlushRX ();
321
+
322
+        /**
323
+         * Pulling method which listenning for arrived data, if data
324
+         * arrived dataRecievedHandler will be triggered
325
+         */
159 326
         void nrfListenForChannel();
160 327
 
161
-        uint8_t                m_rxBuffer[MAX_BUFFER];
162
-        uint8_t                m_txBuffer[MAX_BUFFER];
328
+        uint8_t                m_rxBuffer[MAX_BUFFER]; /**< Reciver buffer */
329
+        uint8_t                m_txBuffer[MAX_BUFFER]; /**< Transmit buffer */
163 330
 
164
-        funcPtrVoidVoid dataRecievedHandler;
331
+        funcPtrVoidVoid dataRecievedHandler; /**< Data arrived handler */
165 332
     private:
166 333
         maa_spi_context        m_spi;
167 334
         uint8_t                m_ce;
@@ -170,7 +337,7 @@ class NRF24l01 {
170 337
         uint8_t             m_ptx;
171 338
         uint8_t                m_payload;
172 339
         uint8_t                m_localAddress[5];
173
-        
340
+
174 341
         maa_gpio_context     m_csnPinCtx;
175 342
         maa_gpio_context     m_cePinCtx;
176 343