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

+ 3
- 2
examples/nrf_transmitter.cxx View File

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

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

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

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

106
 #define NOP                   0xFF
106
 #define NOP                   0xFF
107
 
107
 
108
 /* Nrf24l settings */
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
 #define MAX_BUFFER            32
112
 #define MAX_BUFFER            32
113
 
113
 
118
 
118
 
119
 typedef void (* funcPtrVoidVoid) ();
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
 class NRF24l01 {
129
 class NRF24l01 {
122
     public:
130
     public:
131
+        /**
132
+         * Instanciates a NRF24l01 object
133
+         *
134
+         * @param cs chip select pin
135
+         */
123
         NRF24l01 (uint8_t cs);
136
         NRF24l01 (uint8_t cs);
137
+
138
+        /**
139
+         * NRF24l01 object destructor
140
+         */
124
         ~NRF24l01 ();
141
         ~NRF24l01 ();
142
+
143
+        /**
144
+         * Return name of the component
145
+         */
125
         std::string name()
146
         std::string name()
126
         {
147
         {
127
             return m_name;
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
         void nrfInitModule (uint8_t chipSelect, uint8_t chipEnable);
157
         void nrfInitModule (uint8_t chipSelect, uint8_t chipEnable);
158
+
159
+        /**
160
+         * Configure NRF24l01 chip
161
+         */
131
         void nrfConfigModule ();
162
         void nrfConfigModule ();
163
+
164
+        /**
165
+         * Send the buffer data
166
+         *
167
+         * @param *value pointer to the buffer
168
+         */
132
         void nrfSend (uint8_t *value);
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
         void nrfSend ();
175
         void nrfSend ();
176
+
177
+        /**
178
+         * Set recieving address of the device
179
+         *
180
+         * @param addr 5 bytes addres
181
+         */
134
         void nrfSetRXaddr (uint8_t * addr);
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
         void nrfSetTXaddr (uint8_t * addr);
190
         void nrfSetTXaddr (uint8_t * addr);
191
+
192
+        /**
193
+         * Set broadcasting address.
194
+         *
195
+         * @param addr 5 bytes addres
196
+         */
136
         void nrfSetBroadcastAddr (uint8_t * addr);
197
         void nrfSetBroadcastAddr (uint8_t * addr);
198
+
199
+        /**
200
+         * Set payload size.
201
+         *
202
+         * @param load size of the payload (MAX 32)
203
+         */
137
         void nrfSetPayload (uint8_t load);
204
         void nrfSetPayload (uint8_t load);
205
+
206
+        /**
207
+         * Check if data arrived
208
+         */
138
         bool nrfDataReady ();
209
         bool nrfDataReady ();
210
+
211
+        /**
212
+         * Check if chip in sending mode
213
+         */
139
         bool nrfIsSending ();
214
         bool nrfIsSending ();
215
+
216
+        /**
217
+         * Check if recieving stack is empty
218
+         */
140
         bool nrfRXFifoEmpty ();
219
         bool nrfRXFifoEmpty ();
220
+
221
+        /**
222
+         * Check if transmitting stack is empty
223
+         */
141
         bool nrfTXFifoEmpty ();
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
         void nrfGetData (uint8_t * data);
231
         void nrfGetData (uint8_t * data);
232
+
233
+        /**
234
+         * Check the chip state
235
+         */
143
         uint8_t nrfGetStatus ();
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
         void nrfTransmitSync (uint8_t *dataout, uint8_t len);
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
         void nrfTransferSync (uint8_t *dataout ,uint8_t *datain, uint8_t len);
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
         void nrfConfigRegister (uint8_t reg, uint8_t value);
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
         void nrfReadRegister (uint8_t reg, uint8_t * value, uint8_t len);
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
         void nrfWriteRegister (uint8_t reg, uint8_t * value, uint8_t len);
280
         void nrfWriteRegister (uint8_t reg, uint8_t * value, uint8_t len);
281
+
282
+        /**
283
+         * Power up reciever
284
+         */
150
         void nrfPowerUpRX ();
285
         void nrfPowerUpRX ();
286
+
287
+        /**
288
+         * Power up transmitter
289
+         */
151
         void nrfPowerUpTX ();
290
         void nrfPowerUpTX ();
291
+
292
+        /**
293
+         * Power down all
294
+         */
152
         void nrfPowerDown ();
295
         void nrfPowerDown ();
153
 
296
 
297
+        /**
298
+         * Set chip enable pin HIGH
299
+         */
154
         maa_result_t nrfCEHigh ();
300
         maa_result_t nrfCEHigh ();
301
+
302
+        /**
303
+         * Set chip enable LOW
304
+         */
155
         maa_result_t nrfCELow ();
305
         maa_result_t nrfCELow ();
306
+
307
+        /**
308
+         * Set chip select pin LOW
309
+         */
156
         maa_result_t nrfCSOn ();
310
         maa_result_t nrfCSOn ();
311
+
312
+        /**
313
+         * Set chip select pin HIGH
314
+         */
157
         maa_result_t nrfCSOff ();
315
         maa_result_t nrfCSOff ();
316
+
317
+        /**
318
+         * Flush reciver stack
319
+         */
158
         void nrfFlushRX ();
320
         void nrfFlushRX ();
321
+
322
+        /**
323
+         * Pulling method which listenning for arrived data, if data
324
+         * arrived dataRecievedHandler will be triggered
325
+         */
159
         void nrfListenForChannel();
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
     private:
332
     private:
166
         maa_spi_context        m_spi;
333
         maa_spi_context        m_spi;
167
         uint8_t                m_ce;
334
         uint8_t                m_ce;
170
         uint8_t             m_ptx;
337
         uint8_t             m_ptx;
171
         uint8_t                m_payload;
338
         uint8_t                m_payload;
172
         uint8_t                m_localAddress[5];
339
         uint8_t                m_localAddress[5];
173
-        
340
+
174
         maa_gpio_context     m_csnPinCtx;
341
         maa_gpio_context     m_csnPinCtx;
175
         maa_gpio_context     m_cePinCtx;
342
         maa_gpio_context     m_cePinCtx;
176
 
343