|
@@ -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
|
|