LibDriver NRF24L01
Loading...
Searching...
No Matches
driver_nrf24l01.c
Go to the documentation of this file.
1
36
37#include "driver_nrf24l01.h"
38
42#define CHIP_NAME "Nordic nRF24L01"
43#define MANUFACTURER_NAME "Nordic"
44#define SUPPLY_VOLTAGE_MIN 1.9f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 13.50f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
50
54#define NRF24L01_COMMAND_R_REGISTER 0x00
55#define NRF24L01_COMMAND_W_REGISTER 0x20
56#define NRF24L01_COMMAND_R_RX_PAYLOAD 0x61
57#define NRF24L01_COMMAND_W_TX_PAYLOAD 0xA0
58#define NRF24L01_COMMAND_FLUSH_TX 0xE1
59#define NRF24L01_COMMAND_FLUSH_RX 0xE2
60#define NRF24L01_COMMAND_REUSE_TX_PL 0xE3
61#define NRF24L01_COMMAND_R_RX_PL_WID 0x60
62#define NRF24L01_COMMAND_W_ACK_PAYLOAD 0xA8
63#define NRF24L01_COMMAND_W_TX_PAYLOAD_NO_ACK 0xB0
64#define NRF24L01_COMMAND_NOP 0xFF
65
69#define NRF24L01_REG_CONFIG 0x00
70#define NRF24L01_REG_EN_AA 0x01
71#define NRF24L01_REG_EN_RXADDR 0x02
72#define NRF24L01_REG_SETUP_AW 0x03
73#define NRF24L01_REG_SETUP_RETR 0x04
74#define NRF24L01_REG_RF_CH 0x05
75#define NRF24L01_REG_RF_SETUP 0x06
76#define NRF24L01_REG_STATUS 0x07
77#define NRF24L01_REG_OBSERVE_TX 0x08
78#define NRF24L01_REG_RPD 0x09
79#define NRF24L01_REG_RX_ADDR_P0 0x0A
80#define NRF24L01_REG_RX_ADDR_P1 0x0B
81#define NRF24L01_REG_RX_ADDR_P2 0x0C
82#define NRF24L01_REG_RX_ADDR_P3 0x0D
83#define NRF24L01_REG_RX_ADDR_P4 0x0E
84#define NRF24L01_REG_RX_ADDR_P5 0x0F
85#define NRF24L01_REG_TX_ADDR 0x10
86#define NRF24L01_REG_RX_PW_P0 0x11
87#define NRF24L01_REG_RX_PW_P1 0x12
88#define NRF24L01_REG_RX_PW_P2 0x13
89#define NRF24L01_REG_RX_PW_P3 0x14
90#define NRF24L01_REG_RX_PW_P4 0x15
91#define NRF24L01_REG_RX_PW_P5 0x16
92#define NRF24L01_REG_FIFO_STATUS 0x17
93#define NRF24L01_REG_DYNPD 0x1C
94#define NRF24L01_REG_FEATURE 0x1D
95
107static uint8_t a_nrf24l01_spi_read(nrf24l01_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
108{
109 if (handle->spi_read(NRF24L01_COMMAND_R_REGISTER | reg, buf, len) != 0) /* spi read */
110 {
111 return 1; /* return error */
112 }
113 else
114 {
115 return 0; /* success return 0 */
116 }
117}
118
130static uint8_t a_nrf24l01_spi_write(nrf24l01_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
131{
132 if (handle->spi_write(NRF24L01_COMMAND_W_REGISTER | reg, buf, len) != 0) /* spi write */
133 {
134 return 1; /* return error */
135 }
136 else
137 {
138 return 0; /* success return 0 */
139 }
140}
141
154{
155 if (handle == NULL) /* check handle */
156 {
157 return 2; /* return error */
158 }
159 if (handle->debug_print == NULL) /* check debug_print */
160 {
161 return 3; /* return error */
162 }
163 if (handle->spi_init == NULL) /* check spi_init */
164 {
165 handle->debug_print("nrf24l01: spi_init is null.\n"); /* spi_init is null */
166
167 return 3; /* return error */
168 }
169 if (handle->spi_deinit == NULL) /* check spi_deinit */
170 {
171 handle->debug_print("nrf24l01: spi_deinit is null.\n"); /* spi_deinit is null */
172
173 return 3; /* return error */
174 }
175 if (handle->spi_read == NULL) /* check spi_read */
176 {
177 handle->debug_print("nrf24l01: spi_read is null.\n"); /* spi_read is null */
178
179 return 3; /* return error */
180 }
181 if (handle->spi_write == NULL) /* check spi_write */
182 {
183 handle->debug_print("nrf24l01: spi_write is null.\n"); /* spi_write is null */
184
185 return 3; /* return error */
186 }
187 if (handle->gpio_init == NULL) /* check gpio_init */
188 {
189 handle->debug_print("nrf24l01: gpio_init is null.\n"); /* gpio_init is null */
190
191 return 3; /* return error */
192 }
193 if (handle->gpio_deinit == NULL) /* check gpio_deinit */
194 {
195 handle->debug_print("nrf24l01: gpio_deinit is null.\n"); /* gpio_deinit is null */
196
197 return 3; /* return error */
198 }
199 if (handle->gpio_write == NULL) /* check gpio_write */
200 {
201 handle->debug_print("nrf24l01: gpio_write is null.\n"); /* gpio_write is null */
202
203 return 3; /* return error */
204 }
205 if (handle->delay_ms == NULL) /* check delay_ms */
206 {
207 handle->debug_print("nrf24l01: delay_ms is null.\n"); /* delay_ms is null */
208
209 return 3; /* return error */
210 }
211 if (handle->receive_callback == NULL) /* check receive_callback */
212 {
213 handle->debug_print("nrf24l01: receive_callback is null.\n"); /* receive_callback is null */
214
215 return 3; /* return error */
216 }
217
218 if (handle->gpio_init() != 0) /* gpio init */
219 {
220 handle->debug_print("nrf24l01: gpio init failed.\n"); /* gpio init failed */
221
222 return 4; /* return error */
223 }
224 if (handle->spi_init() != 0) /* spi init */
225 {
226 handle->debug_print("nrf24l01: spi init failed.\n"); /* spi init failed */
227 (void)handle->gpio_deinit(); /* gpio deinit */
228
229 return 1; /* return error */
230 }
231
232 handle->inited = 1; /* flag finish initialization */
233
234 return 0; /* success return 0 */
235}
236
250{
251 uint8_t res;
252 uint8_t prev;
253
254 if (handle == NULL) /* check handle */
255 {
256 return 2; /* return error */
257 }
258 if (handle->inited != 1) /* check handle initialization */
259 {
260 return 3; /* return error */
261 }
262
263 res = handle->spi_write(NRF24L01_COMMAND_NOP, NULL, 0); /* nop */
264 if (res != 0) /* check result */
265 {
266 handle->debug_print("nrf24l01: nop failed.\n"); /* nop failed */
267
268 return 1; /* return error */
269 }
270 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_CONFIG, (uint8_t *)&prev, 1); /* get config */
271 if (res != 0) /* check result */
272 {
273 handle->debug_print("nrf24l01: get config failed.\n"); /* get config failed */
274
275 return 1; /* return error */
276 }
277 prev &= ~(1 << 1); /* clear config */
278 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_CONFIG, (uint8_t *)&prev, 1); /* set config */
279 if (res != 0) /* check result */
280 {
281 handle->debug_print("nrf24l01: set config failed.\n"); /* set config failed */
282
283 return 1; /* return error */
284 }
285 res = handle->gpio_deinit(); /* gpio deinit */
286 if (res != 0) /* check result */
287 {
288 handle->debug_print("nrf24l01: gpio deinit failed.\n"); /* gpio deinit failed */
289
290 return 4; /* return error */
291 }
292 res = handle->spi_deinit(); /* spi deinit */
293 if (res != 0) /* check result */
294 {
295 handle->debug_print("nrf24l01: spi deinit failed.\n"); /* spi deinit failed */
296
297 return 5; /* return error */
298 }
299 handle->inited = 0; /* flag close */
300
301 return 0; /* success return 0 */
302}
303
316{
317 if (handle == NULL) /* check handle */
318 {
319 return 2; /* return error */
320 }
321 if (handle->inited != 1) /* check handle initialization */
322 {
323 return 3; /* return error */
324 }
325
326 if (handle->gpio_write(enable) != 0) /* gpio write */
327 {
328 handle->debug_print("nrf24l01: gpio write failed.\n"); /* gpio write failed */
329
330 return 1; /* return error */
331 }
332
333 return 0; /* success return 0 */
334}
335
350uint8_t nrf24l01_send(nrf24l01_handle_t *handle, uint8_t *buf, uint8_t len)
351{
352 uint8_t res;
353 uint8_t i;
354 uint8_t k;
355 uint8_t tmp;
356 uint8_t buffer[32];
357 uint32_t timeout;
358
359 if (handle == NULL) /* check handle */
360 {
361 return 2; /* return error */
362 }
363 if (handle->inited != 1) /* check handle initialization */
364 {
365 return 3; /* return error */
366 }
367 if (len > 32) /* check the result */
368 {
369 handle->debug_print("nrf24l01: len is over 32.\n"); /* len is over 32 */
370
371 return 4; /* return error */
372 }
373
374 memcpy((uint8_t *)buffer, buf, len); /* copy the data */
375 k = len / 2; /* get the half */
376 for (i = 0; i < k; i++) /* run k times */
377 {
378 tmp = buffer[i]; /* copy to tmp */
379 buffer[i] = buffer[len - 1 - i]; /* buffer[i] = buffer[n - 1 - i] */
380 buffer[len - 1 - i] = tmp; /* set buffer[n - 1 - i]*/
381 }
382 handle->finished = 0; /* clear finished */
383 if (handle->gpio_write(0) != 0) /* gpio write */
384 {
385 handle->debug_print("nrf24l01: gpio write failed.\n"); /* gpio write failed */
386
387 return 1; /* return error */
388 }
389 res = handle->spi_write(NRF24L01_COMMAND_W_TX_PAYLOAD, (uint8_t *)buffer, len); /* set tx payload */
390 if (res != 0) /* check result */
391 {
392 handle->debug_print("nrf24l01: set tx payload failed.\n"); /* set tx payload failed */
393
394 return 1; /* return error */
395 }
396 if (handle->gpio_write(1) != 0) /* gpio write */
397 {
398 handle->debug_print("nrf24l01: gpio write failed.\n"); /* gpio write failed */
399
400 return 1; /* return error */
401 }
402 timeout = 5000; /* set timeout */
403 while ((timeout != 0) && (handle->finished == 0)) /* wait time */
404 {
405 handle->delay_ms(1); /* delay 1 ms */
406 timeout--; /* timeout-- */
407 }
408 if (timeout == 0) /* check timeout */
409 {
410 handle->debug_print("nrf24l01: send timeout.\n"); /* send timeout failed */
411
412 return 5; /* return error */
413 }
414 if (handle->finished == 1) /* check finished */
415 {
416 return 0; /* success return 0 */
417 }
418 else
419 {
420 handle->debug_print("nrf24l01: send failed.\n"); /* send failed */
421
422 return 1; /* return error */
423 }
424}
425
437{
438 uint8_t res;
439 uint8_t prev;
440
441 if (handle == NULL) /* check handle */
442 {
443 return 2; /* return error */
444 }
445 if (handle->inited != 1) /* check handle initialization */
446 {
447 return 3; /* return error */
448 }
449
450 res = handle->gpio_write(0); /* set gpio */
451 if (res != 0) /* check result */
452 {
453 handle->debug_print("nrf24l01: gpio write failed.\n"); /* gpio write failed */
454
455 return 1; /* return error */
456 }
457 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_STATUS, (uint8_t *)&prev, 1); /* get status register */
458 if (res != 0) /* check result */
459 {
460 handle->debug_print("nrf24l01: get status register failed.\n"); /* get status register failed */
461 (void)handle->gpio_write(1); /* set gpio */
462
463 return 1; /* return error */
464 }
465 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_STATUS, (uint8_t *)&prev, 1); /* clear status register */
466 if (res != 0) /* check result */
467 {
468 handle->debug_print("nrf24l01: set status register failed.\n"); /* set status register failed */
469 (void)handle->gpio_write(1); /* set gpio */
470
471 return 1; /* return error */
472 }
473
474 if (((prev >> 0) & 0x01) != 0) /* tx full */
475 {
476 if (handle->receive_callback != NULL) /* if receive callback */
477 {
478 handle->receive_callback(NRF24L01_INTERRUPT_TX_FULL, 0, NULL, 0); /* run receive callback */
479 }
480 }
481 if (((prev >> 4) & 0x01) != 0) /* max rt */
482 {
483 res = handle->spi_write(NRF24L01_COMMAND_FLUSH_TX, NULL, 0); /* flush tx */
484 if (res != 0) /* check result */
485 {
486 handle->debug_print("nrf24l01: flush tx failed.\n"); /* flush tx failed */
487 (void)handle->gpio_write(1); /* set gpio */
488
489 return 1; /* return error */
490 }
491 handle->finished = 2; /* set timeout */
492 if (handle->receive_callback != NULL) /* if receive callback */
493 {
494 handle->receive_callback(NRF24L01_INTERRUPT_MAX_RT, 0, NULL, 0); /* run receive callback */
495 }
496 }
497 if (((prev >> 5) & 0x01) != 0) /* send ok */
498 {
499 handle->finished = 1; /* set finished */
500 if (handle->receive_callback != NULL) /* if receive callback */
501 {
502 handle->receive_callback(NRF24L01_INTERRUPT_TX_DS, 0, NULL, 0); /* run receive callback */
503 }
504 }
505 if (((prev >> 6) & 0x01) != 0) /* receive */
506 {
507 uint8_t num;
508 uint8_t width;
509 uint8_t i;
510 uint8_t k;
511 uint8_t tmp;
512 uint8_t buffer[33];
513
514 res = handle->spi_read(NRF24L01_COMMAND_R_RX_PL_WID, (uint8_t *)&width, 1); /* get payload width */
515 if (res != 0) /* check result */
516 {
517 handle->debug_print("nrf24l01: get payload width failed.\n"); /* get payload width failed */
518 (void)handle->gpio_write(1); /* set gpio */
519
520 return 1; /* return error */
521 }
522 if (width > 32) /* check width */
523 {
524 res = handle->spi_write(NRF24L01_COMMAND_FLUSH_RX, NULL, 0); /* flush rx */
525 if (res != 0) /* check result */
526 {
527 handle->debug_print("nrf24l01: flush rx failed.\n"); /* flush rx failed */
528 (void)handle->gpio_write(1); /* set gpio */
529
530 return 1; /* return error */
531 }
532 }
533 res = handle->spi_read(NRF24L01_COMMAND_R_RX_PAYLOAD, (uint8_t *)buffer, width); /* get rx payload */
534 if (res != 0) /* check result */
535 {
536 handle->debug_print("nrf24l01: get rx payload failed.\n"); /* get rx payload failed */
537 (void)handle->gpio_write(1); /* set gpio */
538
539 return 1; /* return error */
540 }
541 k = width / 2; /* get the half */
542 for (i = 0; i < k; i++) /* run k times */
543 {
544 tmp = buffer[i]; /* copy to tmp */
545 buffer[i] = buffer[width - 1 - i]; /* buffer[i] = buffer[n - 1 - i] */
546 buffer[width - 1 - i] = tmp; /* set buffer[n - 1 - i]*/
547 }
548 num = (prev >> 1) & 0x7; /* get number */
549 if (handle->receive_callback != NULL) /* if receive callback */
550 {
551 handle->receive_callback(NRF24L01_INTERRUPT_RX_DR, num, (uint8_t *)buffer, width); /* run receive callback */
552 }
553 }
554 res = handle->gpio_write(1); /* set gpio write */
555 if (res != 0) /* check result */
556 {
557 handle->debug_print("nrf24l01: gpio write failed.\n"); /* gpio write failed */
558
559 return 1; /* return error */
560 }
561
562 return 0; /* success return 0 */
563}
564
578{
579 uint8_t res;
580 uint8_t prev;
581
582 if (handle == NULL) /* check handle */
583 {
584 return 2; /* return error */
585 }
586 if (handle->inited != 1) /* check handle initialization */
587 {
588 return 3; /* return error */
589 }
590
591 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_CONFIG, (uint8_t *)&prev, 1); /* get config */
592 if (res != 0) /* check result */
593 {
594 handle->debug_print("nrf24l01: get config failed.\n"); /* get config failed */
595
596 return 1; /* return error */
597 }
598 prev &= ~(1 << config); /* clear config */
599 prev |= enable << config; /* set config */
600 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_CONFIG, (uint8_t *)&prev, 1); /* set config */
601 if (res != 0) /* check result */
602 {
603 handle->debug_print("nrf24l01: set config failed.\n"); /* set config failed */
604
605 return 1; /* return error */
606 }
607
608 return 0; /* success return 0 */
609}
610
624{
625 uint8_t res;
626 uint8_t prev;
627
628 if (handle == NULL) /* check handle */
629 {
630 return 2; /* return error */
631 }
632 if (handle->inited != 1) /* check handle initialization */
633 {
634 return 3; /* return error */
635 }
636
637 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_CONFIG, (uint8_t *)&prev, 1); /* get config */
638 if (res != 0) /* check result */
639 {
640 handle->debug_print("nrf24l01: get config failed.\n"); /* get config failed */
641
642 return 1; /* return error */
643 }
644 *enable = (nrf24l01_bool_t)((prev >> config) & 0x01); /* get config */
645
646 return 0; /* success return 0 */
647}
648
661{
662 uint8_t res;
663 uint8_t prev;
664
665 if (handle == NULL) /* check handle */
666 {
667 return 2; /* return error */
668 }
669 if (handle->inited != 1) /* check handle initialization */
670 {
671 return 3; /* return error */
672 }
673
674 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_CONFIG, (uint8_t *)&prev, 1); /* get config */
675 if (res != 0) /* check result */
676 {
677 handle->debug_print("nrf24l01: get config failed.\n"); /* get config failed */
678
679 return 1; /* return error */
680 }
681 prev &= ~(1 << 0); /* clear config */
682 prev |= mode << 0; /* set config */
683 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_CONFIG, (uint8_t *)&prev, 1); /* set config */
684 if (res != 0) /* check result */
685 {
686 handle->debug_print("nrf24l01: set config failed.\n"); /* set config failed */
687
688 return 1; /* return error */
689 }
690
691 return 0; /* success return 0 */
692}
693
706{
707 uint8_t res;
708 uint8_t prev;
709
710 if (handle == NULL) /* check handle */
711 {
712 return 2; /* return error */
713 }
714 if (handle->inited != 1) /* check handle initialization */
715 {
716 return 3; /* return error */
717 }
718
719 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_CONFIG, (uint8_t *)&prev, 1); /* get config */
720 if (res != 0) /* check result */
721 {
722 handle->debug_print("nrf24l01: get config failed.\n"); /* get config failed */
723
724 return 1; /* return error */
725 }
726 *mode = (nrf24l01_mode_t)(prev & 0x01); /* get mode */
727
728 return 0; /* success return 0 */
729}
730
744{
745 uint8_t res;
746 uint8_t prev;
747
748 if (handle == NULL) /* check handle */
749 {
750 return 2; /* return error */
751 }
752 if (handle->inited != 1) /* check handle initialization */
753 {
754 return 3; /* return error */
755 }
756
757 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_EN_AA, (uint8_t *)&prev, 1); /* get auto acknowledgment */
758 if (res != 0) /* check result */
759 {
760 handle->debug_print("nrf24l01: get auto acknowledgment failed.\n"); /* get auto acknowledgment failed */
761
762 return 1; /* return error */
763 }
764 prev &= ~(1 << pipe); /* clear config */
765 prev |= enable << pipe; /* set pipe */
766 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_EN_AA, (uint8_t *)&prev, 1); /* set auto acknowledgment */
767 if (res != 0) /* check result */
768 {
769 handle->debug_print("nrf24l01: set auto acknowledgment failed.\n"); /* set auto acknowledgment failed */
770
771 return 1; /* return error */
772 }
773
774 return 0; /* success return 0 */
775}
776
790{
791 uint8_t res;
792 uint8_t prev;
793
794 if (handle == NULL) /* check handle */
795 {
796 return 2; /* return error */
797 }
798 if (handle->inited != 1) /* check handle initialization */
799 {
800 return 3; /* return error */
801 }
802
803 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_EN_AA, (uint8_t *)&prev, 1); /* get auto acknowledgment */
804 if (res != 0) /* check result */
805 {
806 handle->debug_print("nrf24l01: get auto acknowledgment failed.\n"); /* get auto acknowledgment failed */
807
808 return 1; /* return error */
809 }
810 *enable = (nrf24l01_bool_t)((prev >> pipe) & 0x01); /* get pipe */
811
812 return 0; /* success return 0 */
813}
814
828{
829 uint8_t res;
830 uint8_t prev;
831
832 if (handle == NULL) /* check handle */
833 {
834 return 2; /* return error */
835 }
836 if (handle->inited != 1) /* check handle initialization */
837 {
838 return 3; /* return error */
839 }
840
841 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_EN_RXADDR, (uint8_t *)&prev, 1); /* get rx address */
842 if (res != 0) /* check result */
843 {
844 handle->debug_print("nrf24l01: get rx address failed.\n"); /* get rx address failed */
845
846 return 1; /* return error */
847 }
848 prev &= ~(1 << pipe); /* clear config */
849 prev |= enable << pipe; /* set pipe */
850 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_EN_RXADDR, (uint8_t *)&prev, 1); /* set rx address */
851 if (res != 0) /* check result */
852 {
853 handle->debug_print("nrf24l01: set rx address failed.\n"); /* set rx address failed */
854
855 return 1; /* return error */
856 }
857
858 return 0; /* success return 0 */
859}
860
874{
875 uint8_t res;
876 uint8_t prev;
877
878 if (handle == NULL) /* check handle */
879 {
880 return 2; /* return error */
881 }
882 if (handle->inited != 1) /* check handle initialization */
883 {
884 return 3; /* return error */
885 }
886
887 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_EN_RXADDR, (uint8_t *)&prev, 1); /* get rx address */
888 if (res != 0) /* check result */
889 {
890 handle->debug_print("nrf24l01: get rx address failed.\n"); /* get rx address failed */
891
892 return 1; /* return error */
893 }
894 *enable = (nrf24l01_bool_t)((prev >> pipe) & 0x01); /* get pipe */
895
896 return 0; /* success return 0 */
897}
898
911{
912 uint8_t res;
913 uint8_t prev;
914
915 if (handle == NULL) /* check handle */
916 {
917 return 2; /* return error */
918 }
919 if (handle->inited != 1) /* check handle initialization */
920 {
921 return 3; /* return error */
922 }
923
924 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_SETUP_AW, (uint8_t *)&prev, 1); /* get setup of address widths */
925 if (res != 0) /* check result */
926 {
927 handle->debug_print("nrf24l01: get setup of address widths failed.\n"); /* get setup of address widths failed */
928
929 return 1; /* return error */
930 }
931 prev &= ~(3 << 0); /* clear config */
932 prev |= width << 0; /* set width */
933 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_SETUP_AW, (uint8_t *)&prev, 1); /* set setup of address widths */
934 if (res != 0) /* check result */
935 {
936 handle->debug_print("nrf24l01: set setup of address widths failed.\n"); /* set setup of address widths failed */
937
938 return 1; /* return error */
939 }
940
941 return 0; /* success return 0 */
942}
943
956{
957 uint8_t res;
958 uint8_t prev;
959
960 if (handle == NULL) /* check handle */
961 {
962 return 2; /* return error */
963 }
964 if (handle->inited != 1) /* check handle initialization */
965 {
966 return 3; /* return error */
967 }
968
969 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_SETUP_AW, (uint8_t *)&prev, 1); /* get setup of address widths */
970 if (res != 0) /* check result */
971 {
972 handle->debug_print("nrf24l01: get setup of address widths failed.\n"); /* get setup of address widths failed */
973
974 return 1; /* return error */
975 }
976 *width = (nrf24l01_address_width_t)((prev >> 0) & 0x3); /* get config */
977
978 return 0; /* success return 0 */
979}
980
994{
995 uint8_t res;
996 uint8_t prev;
997
998 if (handle == NULL) /* check handle */
999 {
1000 return 2; /* return error */
1001 }
1002 if (handle->inited != 1) /* check handle initialization */
1003 {
1004 return 3; /* return error */
1005 }
1006 if (delay > 0xF) /* check delay */
1007 {
1008 handle->debug_print("nrf24l01: delay is over 0xF.\n"); /* delay is over 0xF */
1009
1010 return 4; /* return error */
1011 }
1012
1013 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_SETUP_RETR, (uint8_t *)&prev, 1); /* get setup of automatic retransmission */
1014 if (res != 0) /* check result */
1015 {
1016 handle->debug_print("nrf24l01: get setup of automatic retransmission failed.\n"); /* get setup of automatic retransmission failed */
1017
1018 return 1; /* return error */
1019 }
1020 prev &= ~(0xF << 4); /* clear config */
1021 prev |= delay << 4; /* set delay */
1022 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_SETUP_RETR, (uint8_t *)&prev, 1); /* set setup of automatic retransmission */
1023 if (res != 0) /* check result */
1024 {
1025 handle->debug_print("nrf24l01: set setup of automatic retransmission failed.\n"); /* set setup of automatic retransmission failed */
1026
1027 return 1; /* return error */
1028 }
1029
1030 return 0; /* success return 0 */
1031}
1032
1045{
1046 uint8_t res;
1047 uint8_t prev;
1048
1049 if (handle == NULL) /* check handle */
1050 {
1051 return 2; /* return error */
1052 }
1053 if (handle->inited != 1) /* check handle initialization */
1054 {
1055 return 3; /* return error */
1056 }
1057
1058 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_SETUP_RETR, (uint8_t *)&prev, 1); /* get setup of automatic retransmission */
1059 if (res != 0) /* check result */
1060 {
1061 handle->debug_print("nrf24l01: get setup of automatic retransmission failed.\n"); /* get setup of automatic retransmission failed */
1062
1063 return 1; /* return error */
1064 }
1065 *delay = (prev >> 4) & 0xF; /* get delay */
1066
1067 return 0; /* success return 0 */
1068}
1069
1082{
1083 if (handle == NULL) /* check handle */
1084 {
1085 return 2; /* return error */
1086 }
1087 if (handle->inited != 1) /* check handle initialization */
1088 {
1089 return 3; /* return error */
1090 }
1091
1092 *reg = (uint8_t)(us / 250); /* convert real data to register data */
1093
1094 return 0; /* success return 0 */
1095}
1096
1109{
1110 if (handle == NULL) /* check handle */
1111 {
1112 return 2; /* return error */
1113 }
1114 if (handle->inited != 1) /* check handle initialization */
1115 {
1116 return 3; /* return error */
1117 }
1118
1119 *us = (uint32_t)(reg) * 250; /* convert raw data to real data */
1120
1121 return 0; /* success return 0 */
1122}
1123
1137{
1138 uint8_t res;
1139 uint8_t prev;
1140
1141 if (handle == NULL) /* check handle */
1142 {
1143 return 2; /* return error */
1144 }
1145 if (handle->inited != 1) /* check handle initialization */
1146 {
1147 return 3; /* return error */
1148 }
1149 if (count > 0xF) /* check count */
1150 {
1151 handle->debug_print("nrf24l01: count is over 0xF.\n"); /* count is over 0xF */
1152
1153 return 4; /* return error */
1154 }
1155
1156 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_SETUP_RETR, (uint8_t *)&prev, 1); /* get setup of automatic retransmission */
1157 if (res != 0) /* check result */
1158 {
1159 handle->debug_print("nrf24l01: get setup of automatic retransmission failed.\n"); /* get setup of automatic retransmission failed */
1160
1161 return 1; /* return error */
1162 }
1163 prev &= ~(0xF << 0); /* clear config */
1164 prev |= count << 0; /* set count */
1165 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_SETUP_RETR, (uint8_t *)&prev, 1); /* set setup of automatic retransmission */
1166 if (res != 0) /* check result */
1167 {
1168 handle->debug_print("nrf24l01: set setup of automatic retransmission failed.\n"); /* set setup of automatic retransmission failed */
1169
1170 return 1; /* return error */
1171 }
1172
1173 return 0; /* success return 0 */
1174}
1175
1188{
1189 uint8_t res;
1190 uint8_t prev;
1191
1192 if (handle == NULL) /* check handle */
1193 {
1194 return 2; /* return error */
1195 }
1196 if (handle->inited != 1) /* check handle initialization */
1197 {
1198 return 3; /* return error */
1199 }
1200
1201 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_SETUP_RETR, (uint8_t *)&prev, 1); /* get setup of automatic retransmission */
1202 if (res != 0) /* check result */
1203 {
1204 handle->debug_print("nrf24l01: get setup of automatic retransmission failed.\n"); /* get setup of automatic retransmission failed */
1205
1206 return 1; /* return error */
1207 }
1208 *count = (prev >> 0) & 0xF; /* get count */
1209
1210 return 0; /* success return 0 */
1211}
1212
1226{
1227 uint8_t res;
1228 uint8_t prev;
1229
1230 if (handle == NULL) /* check handle */
1231 {
1232 return 2; /* return error */
1233 }
1234 if (handle->inited != 1) /* check handle initialization */
1235 {
1236 return 3; /* return error */
1237 }
1238 if (freq > 0x7F) /* check freq */
1239 {
1240 handle->debug_print("nrf24l01: freq is over 0x7F.\n"); /* freq is over 0x7F */
1241
1242 return 4; /* return error */
1243 }
1244
1245 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RF_CH, (uint8_t *)&prev, 1); /* get rf channel */
1246 if (res != 0) /* check result */
1247 {
1248 handle->debug_print("nrf24l01: get rf channel failed.\n"); /* get rf channel failed */
1249
1250 return 1; /* return error */
1251 }
1252 prev &= ~(0x7F << 0); /* clear config */
1253 prev |= freq << 0; /* set freq */
1254 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RF_CH, (uint8_t *)&prev, 1); /* set rf channel */
1255 if (res != 0) /* check result */
1256 {
1257 handle->debug_print("nrf24l01: set rf channel failed.\n"); /* set rf channel failed */
1258
1259 return 1; /* return error */
1260 }
1261
1262 return 0; /* success return 0 */
1263}
1264
1277{
1278 uint8_t res;
1279 uint8_t prev;
1280
1281 if (handle == NULL) /* check handle */
1282 {
1283 return 2; /* return error */
1284 }
1285 if (handle->inited != 1) /* check handle initialization */
1286 {
1287 return 3; /* return error */
1288 }
1289
1290 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RF_CH, (uint8_t *)&prev, 1); /* get rf channel */
1291 if (res != 0) /* check result */
1292 {
1293 handle->debug_print("nrf24l01: get rf channel failed.\n"); /* get rf channel failed */
1294
1295 return 1; /* return error */
1296 }
1297 *freq = prev & 0x7F; /* get freq */
1298
1299 return 0; /* success return 0 */
1300}
1301
1314{
1315 uint8_t res;
1316 uint8_t prev;
1317
1318 if (handle == NULL) /* check handle */
1319 {
1320 return 2; /* return error */
1321 }
1322 if (handle->inited != 1) /* check handle initialization */
1323 {
1324 return 3; /* return error */
1325 }
1326
1327 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RF_SETUP, (uint8_t *)&prev, 1); /* get rf setup register */
1328 if (res != 0) /* check result */
1329 {
1330 handle->debug_print("nrf24l01: get rf setup register failed.\n"); /* get rf setup register failed */
1331
1332 return 1; /* return error */
1333 }
1334 prev &= ~(1 << 7); /* clear config */
1335 prev |= enable << 7; /* set bool */
1336 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RF_SETUP, (uint8_t *)&prev, 1); /* set rf setup register */
1337 if (res != 0) /* check result */
1338 {
1339 handle->debug_print("nrf24l01: set rf setup register failed.\n"); /* set rf setup register failed */
1340
1341 return 1; /* return error */
1342 }
1343
1344 return 0; /* success return 0 */
1345}
1346
1359{
1360 uint8_t res;
1361 uint8_t prev;
1362
1363 if (handle == NULL) /* check handle */
1364 {
1365 return 2; /* return error */
1366 }
1367 if (handle->inited != 1) /* check handle initialization */
1368 {
1369 return 3; /* return error */
1370 }
1371
1372 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RF_SETUP, (uint8_t *)&prev, 1); /* get rf setup register */
1373 if (res != 0) /* check result */
1374 {
1375 handle->debug_print("nrf24l01: get rf setup register failed.\n"); /* get rf setup register failed */
1376
1377 return 1; /* return error */
1378 }
1379 *enable = (nrf24l01_bool_t)((prev >> 7) & 0x01); /* get bool */
1380
1381 return 0; /* success return 0 */
1382}
1383
1396{
1397 uint8_t res;
1398 uint8_t prev;
1399
1400 if (handle == NULL) /* check handle */
1401 {
1402 return 2; /* return error */
1403 }
1404 if (handle->inited != 1) /* check handle initialization */
1405 {
1406 return 3; /* return error */
1407 }
1408
1409 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RF_SETUP, (uint8_t *)&prev, 1); /* get rf setup register */
1410 if (res != 0) /* check result */
1411 {
1412 handle->debug_print("nrf24l01: get rf setup register failed.\n"); /* get rf setup register failed */
1413
1414 return 1; /* return error */
1415 }
1416 prev &= ~(1 << 4); /* clear config */
1417 prev |= enable << 4; /* set bool */
1418 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RF_SETUP, (uint8_t *)&prev, 1); /* set rf setup register */
1419 if (res != 0) /* check result */
1420 {
1421 handle->debug_print("nrf24l01: set rf setup register failed.\n"); /* set rf setup register failed */
1422
1423 return 1; /* return error */
1424 }
1425
1426 return 0; /* success return 0 */
1427}
1428
1441{
1442 uint8_t res;
1443 uint8_t prev;
1444
1445 if (handle == NULL) /* check handle */
1446 {
1447 return 2; /* return error */
1448 }
1449 if (handle->inited != 1) /* check handle initialization */
1450 {
1451 return 3; /* return error */
1452 }
1453
1454 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RF_SETUP, (uint8_t *)&prev, 1); /* get rf setup register */
1455 if (res != 0) /* check result */
1456 {
1457 handle->debug_print("nrf24l01: get rf setup register failed.\n"); /* get rf setup register failed */
1458
1459 return 1; /* return error */
1460 }
1461 *enable = (nrf24l01_bool_t)((prev >> 4) & 0x01); /* get bool */
1462
1463 return 0; /* success return 0 */
1464}
1465
1478{
1479 uint8_t res;
1480 uint8_t prev;
1481
1482 if (handle == NULL) /* check handle */
1483 {
1484 return 2; /* return error */
1485 }
1486 if (handle->inited != 1) /* check handle initialization */
1487 {
1488 return 3; /* return error */
1489 }
1490
1491 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RF_SETUP, (uint8_t *)&prev, 1); /* get rf setup register */
1492 if (res != 0) /* check result */
1493 {
1494 handle->debug_print("nrf24l01: get rf setup register failed.\n"); /* get rf setup register failed */
1495
1496 return 1; /* return error */
1497 }
1498 prev &= ~(1 << 5); /* clear config */
1499 prev &= ~(1 << 3); /* clear config */
1500 prev |= ((rate >> 0) & 0x1) << 3; /* set rate */
1501 prev |= ((rate >> 1) & 0x1) << 5; /* set rate */
1502 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RF_SETUP, (uint8_t *)&prev, 1); /* set rf setup register */
1503 if (res != 0) /* check result */
1504 {
1505 handle->debug_print("nrf24l01: set rf setup register failed.\n"); /* set rf setup register failed */
1506
1507 return 1; /* return error */
1508 }
1509
1510 return 0; /* success return 0 */
1511}
1512
1525{
1526 uint8_t res;
1527 uint8_t prev;
1528
1529 if (handle == NULL) /* check handle */
1530 {
1531 return 2; /* return error */
1532 }
1533 if (handle->inited != 1) /* check handle initialization */
1534 {
1535 return 3; /* return error */
1536 }
1537
1538 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RF_SETUP, (uint8_t *)&prev, 1); /* get rf setup register */
1539 if (res != 0) /* check result */
1540 {
1541 handle->debug_print("nrf24l01: get rf setup register failed.\n"); /* get rf setup register failed */
1542
1543 return 1; /* return error */
1544 }
1545 *rate = (nrf24l01_data_rate_t)(((prev >> 3) & 0x01) | ((prev >> 5) & 0x01) << 1); /* get rate */
1546
1547 return 0; /* success return 0 */
1548}
1549
1562{
1563 uint8_t res;
1564 uint8_t prev;
1565
1566 if (handle == NULL) /* check handle */
1567 {
1568 return 2; /* return error */
1569 }
1570 if (handle->inited != 1) /* check handle initialization */
1571 {
1572 return 3; /* return error */
1573 }
1574
1575 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RF_SETUP, (uint8_t *)&prev, 1); /* get rf setup register */
1576 if (res != 0) /* check result */
1577 {
1578 handle->debug_print("nrf24l01: get rf setup register failed.\n"); /* get rf setup register failed */
1579
1580 return 1; /* return error */
1581 }
1582 prev &= ~(3 << 1); /* clear config */
1583 prev |= power << 1; /* set power */
1584 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RF_SETUP, (uint8_t *)&prev, 1); /* set rf setup register */
1585 if (res != 0) /* check result */
1586 {
1587 handle->debug_print("nrf24l01: set rf setup register failed.\n"); /* set rf setup register failed */
1588
1589 return 1; /* return error */
1590 }
1591
1592 return 0; /* success return 0 */
1593}
1594
1607{
1608 uint8_t res;
1609 uint8_t prev;
1610
1611 if (handle == NULL) /* check handle */
1612 {
1613 return 2; /* return error */
1614 }
1615 if (handle->inited != 1) /* check handle initialization */
1616 {
1617 return 3; /* return error */
1618 }
1619
1620 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RF_SETUP, (uint8_t *)&prev, 1); /* get rf setup register */
1621 if (res != 0) /* check result */
1622 {
1623 handle->debug_print("nrf24l01: get rf setup register failed.\n"); /* get rf setup register failed */
1624
1625 return 1; /* return error */
1626 }
1627 *power = (nrf24l01_output_power_t)((prev >> 1) & 0x03); /* get output power */
1628
1629 return 0; /* success return 0 */
1630}
1631
1645{
1646 uint8_t res;
1647 uint8_t prev;
1648
1649 if (handle == NULL) /* check handle */
1650 {
1651 return 2; /* return error */
1652 }
1653 if (handle->inited != 1) /* check handle initialization */
1654 {
1655 return 3; /* return error */
1656 }
1657
1658 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_STATUS, (uint8_t *)&prev, 1); /* get status register */
1659 if (res != 0) /* check result */
1660 {
1661 handle->debug_print("nrf24l01: get status register failed.\n"); /* get status register failed */
1662
1663 return 1; /* return error */
1664 }
1665 *enable = (nrf24l01_bool_t)((prev >> type) & 0x01); /* get bool */
1666
1667 return 0; /* success return 0 */
1668}
1669
1682{
1683 uint8_t res;
1684 uint8_t prev;
1685
1686 if (handle == NULL) /* check handle */
1687 {
1688 return 2; /* return error */
1689 }
1690 if (handle->inited != 1) /* check handle initialization */
1691 {
1692 return 3; /* return error */
1693 }
1694
1695 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_STATUS, (uint8_t *)&prev, 1); /* get status register */
1696 if (res != 0) /* check result */
1697 {
1698 handle->debug_print("nrf24l01: get status register failed.\n"); /* get status register failed */
1699
1700 return 1; /* return error */
1701 }
1702 prev &= ~(1 << type); /* clear config */
1703 prev |= 1 << type; /* set interrupt */
1704 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_STATUS, (uint8_t *)&prev, 1); /* set status register */
1705 if (res != 0) /* check result */
1706 {
1707 handle->debug_print("nrf24l01: set status register failed.\n"); /* set status register failed */
1708
1709 return 1; /* return error */
1710 }
1711
1712 return 0; /* success return 0 */
1713}
1714
1726uint8_t nrf24l01_get_data_pipe_number(nrf24l01_handle_t *handle, uint8_t *number)
1727{
1728 uint8_t res;
1729 uint8_t prev;
1730
1731 if (handle == NULL) /* check handle */
1732 {
1733 return 2; /* return error */
1734 }
1735 if (handle->inited != 1) /* check handle initialization */
1736 {
1737 return 3; /* return error */
1738 }
1739
1740 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_STATUS, (uint8_t *)&prev, 1); /* get status register */
1741 if (res != 0) /* check result */
1742 {
1743 handle->debug_print("nrf24l01: get status register failed.\n"); /* get status register failed */
1744
1745 return 1; /* return error */
1746 }
1747 *number = (prev >> 1) & 0x7; /* get number */
1748
1749 return 0; /* success return 0 */
1750}
1751
1764{
1765 uint8_t res;
1766 uint8_t prev;
1767
1768 if (handle == NULL) /* check handle */
1769 {
1770 return 2; /* return error */
1771 }
1772 if (handle->inited != 1) /* check handle initialization */
1773 {
1774 return 3; /* return error */
1775 }
1776
1777 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_OBSERVE_TX, (uint8_t *)&prev, 1); /* get transmit observe register */
1778 if (res != 0) /* check result */
1779 {
1780 handle->debug_print("nrf24l01: get transmit observe register failed.\n"); /* get transmit observe failed */
1781
1782 return 1; /* return error */
1783 }
1784 *count = (prev >> 4) & 0xF; /* get count */
1785
1786 return 0; /* success return 0 */
1787}
1788
1801{
1802 uint8_t res;
1803 uint8_t prev;
1804
1805 if (handle == NULL) /* check handle */
1806 {
1807 return 2; /* return error */
1808 }
1809 if (handle->inited != 1) /* check handle initialization */
1810 {
1811 return 3; /* return error */
1812 }
1813
1814 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_OBSERVE_TX, (uint8_t *)&prev, 1); /* get transmit observe register */
1815 if (res != 0) /* check result */
1816 {
1817 handle->debug_print("nrf24l01: get transmit observe register failed.\n"); /* get transmit observe failed */
1818
1819 return 1; /* return error */
1820 }
1821 *count = (prev >> 0) & 0xF; /* get count */
1822
1823 return 0; /* success return 0 */
1824}
1825
1838{
1839 uint8_t res;
1840 uint8_t prev;
1841
1842 if (handle == NULL) /* check handle */
1843 {
1844 return 2; /* return error */
1845 }
1846 if (handle->inited != 1) /* check handle initialization */
1847 {
1848 return 3; /* return error */
1849 }
1850
1851 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RPD, (uint8_t *)&prev, 1); /* get rpd register */
1852 if (res != 0) /* check result */
1853 {
1854 handle->debug_print("nrf24l01: get rpd failed.\n"); /* get rpd failed */
1855
1856 return 1; /* return error */
1857 }
1858 *enable = (nrf24l01_bool_t)((prev >> 0) & 0x01); /* get bool */
1859
1860 return 0; /* success return 0 */
1861}
1862
1876uint8_t nrf24l01_set_rx_pipe_0_address(nrf24l01_handle_t *handle, uint8_t *addr, uint8_t len)
1877{
1878 uint8_t res;
1879 uint8_t prev;
1880 uint8_t width;
1881 uint8_t i;
1882 uint8_t k;
1883 uint8_t tmp;
1884 uint8_t buffer[8];
1885
1886 if (handle == NULL) /* check handle */
1887 {
1888 return 2; /* return error */
1889 }
1890 if (handle->inited != 1) /* check handle initialization */
1891 {
1892 return 3; /* return error */
1893 }
1894
1895 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_SETUP_AW, (uint8_t *)&prev, 1); /* get setup of address widths */
1896 if (res != 0) /* check result */
1897 {
1898 handle->debug_print("nrf24l01: get setup of address widths failed.\n"); /* get setup of address widths failed */
1899
1900 return 1; /* return error */
1901 }
1902 width = (nrf24l01_address_width_t)((prev >> 0) & 0x3); /* get width */
1903 if (width == 0) /* check width */
1904 {
1905 handle->debug_print("nrf24l01: len is too long with %d.\n", 0); /* len is too long */
1906
1907 return 4; /* return error */
1908 }
1909 else
1910 {
1911 width += 2; /* width + 2 */
1912 }
1913 if (len > width) /* check width */
1914 {
1915 handle->debug_print("nrf24l01: len is too long with %d.\n", width); /* len is too long */
1916
1917 return 4; /* return error */
1918 }
1919
1920 k = len / 2; /* set k */
1921 memcpy((uint8_t *)buffer, addr, len); /* copy data */
1922 for (i = 0; i < k; i++) /* run k times */
1923 {
1924 tmp = buffer[i]; /* copy to tmp */
1925 buffer[i] = buffer[len - 1 - i]; /* buffer[i] = buffer[n - 1 - i] */
1926 buffer[len - 1 - i] = tmp; /* set buffer[n - 1 - i]*/
1927 }
1928 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RX_ADDR_P0, (uint8_t *)buffer, len); /* set receive address data pipe p0 register */
1929 if (res != 0) /* check result */
1930 {
1931 handle->debug_print("nrf24l01: set receive address data pipe p0 register failed.\n"); /* set receive address data pipe p0 register failed */
1932
1933 return 1; /* return error */
1934 }
1935
1936 return 0; /* success return 0 */
1937}
1938
1952uint8_t nrf24l01_get_rx_pipe_0_address(nrf24l01_handle_t *handle, uint8_t *addr, uint8_t *len)
1953{
1954 uint8_t res;
1955 uint8_t i;
1956 uint8_t k;
1957 uint8_t tmp;
1958 uint8_t prev;
1959 uint8_t width;
1960
1961 if (handle == NULL) /* check handle */
1962 {
1963 return 2; /* return error */
1964 }
1965 if (handle->inited != 1) /* check handle initialization */
1966 {
1967 return 3; /* return error */
1968 }
1969
1970 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_SETUP_AW, (uint8_t *)&prev, 1); /* get setup of address widths */
1971 if (res != 0) /* check result */
1972 {
1973 handle->debug_print("nrf24l01: get setup of address widths failed.\n"); /* get setup of address widths failed */
1974
1975 return 1; /* return error */
1976 }
1977 width = (nrf24l01_address_width_t)((prev >> 0) & 0x3); /* get width */
1978 if (width == 0) /* check width */
1979 {
1980 handle->debug_print("nrf24l01: len is too long with %d.\n", 0); /* len is too long */
1981
1982 return 4; /* return error */
1983 }
1984 else
1985 {
1986 width += 2; /* width + 2 */
1987 }
1988 if (*len < width) /* check width */
1989 {
1990 handle->debug_print("nrf24l01: len is too short with %d.\n", width); /* len is too short */
1991
1992 return 4; /* return error */
1993 }
1994 *len = width; /* set width */
1995
1996 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RX_ADDR_P0, (uint8_t *)addr, width); /* get receive address data pipe p0 register */
1997 if (res != 0) /* check result */
1998 {
1999 handle->debug_print("nrf24l01: get receive address data pipe p0 register failed.\n"); /* get receive address data pipe p0 register failed */
2000
2001 return 1; /* return error */
2002 }
2003 k = (*len) / 2; /* set k */
2004 for (i = 0; i < k; i++) /* run k times */
2005 {
2006 tmp = addr[i]; /* copy to tmp */
2007 addr[i] = addr[(*len) - 1 - i]; /* addr[i] = addr[n - 1 - i] */
2008 addr[(*len) - 1 - i] = tmp; /* set addr[n - 1 - i]*/
2009 }
2010
2011 return 0; /* success return 0 */
2012}
2013
2027uint8_t nrf24l01_set_rx_pipe_1_address(nrf24l01_handle_t *handle, uint8_t *addr, uint8_t len)
2028{
2029 uint8_t res;
2030 uint8_t prev;
2031 uint8_t width;
2032 uint8_t i;
2033 uint8_t k;
2034 uint8_t tmp;
2035 uint8_t buffer[8];
2036
2037 if (handle == NULL) /* check handle */
2038 {
2039 return 2; /* return error */
2040 }
2041 if (handle->inited != 1) /* check handle initialization */
2042 {
2043 return 3; /* return error */
2044 }
2045
2046 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_SETUP_AW, (uint8_t *)&prev, 1); /* get setup of address widths */
2047 if (res != 0) /* check result */
2048 {
2049 handle->debug_print("nrf24l01: get setup of address widths failed.\n"); /* get setup of address widths failed */
2050
2051 return 1; /* return error */
2052 }
2053 width = (nrf24l01_address_width_t)((prev >> 0) & 0x3); /* get width */
2054 if (width == 0) /* check width */
2055 {
2056 handle->debug_print("nrf24l01: len is too long with %d.\n", 0); /* len is too long */
2057
2058 return 4; /* return error */
2059 }
2060 else
2061 {
2062 width += 2; /* width + 2 */
2063 }
2064 if (len > width) /* check width */
2065 {
2066 handle->debug_print("nrf24l01: len is too long with %d.\n", width); /* len is too long */
2067
2068 return 4; /* return error */
2069 }
2070
2071 k = len / 2; /* set k */
2072 memcpy((uint8_t *)buffer, addr, len); /* copy data */
2073 for (i = 0; i < k; i++) /* run k times */
2074 {
2075 tmp = buffer[i]; /* copy to tmp */
2076 buffer[i] = buffer[len - 1 - i]; /* buffer[i] = buffer[n - 1 - i] */
2077 buffer[len - 1 - i] = tmp; /* set buffer[n - 1 - i]*/
2078 }
2079 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RX_ADDR_P1, (uint8_t *)buffer, len); /* set receive address data pipe p1 register */
2080 if (res != 0) /* check result */
2081 {
2082 handle->debug_print("nrf24l01: set receive address data pipe p1 register failed.\n"); /* set receive address data pipe p1 register failed */
2083
2084 return 1; /* return error */
2085 }
2086
2087 return 0; /* success return 0 */
2088}
2089
2103uint8_t nrf24l01_get_rx_pipe_1_address(nrf24l01_handle_t *handle, uint8_t *addr, uint8_t *len)
2104{
2105 uint8_t res;
2106 uint8_t i;
2107 uint8_t k;
2108 uint8_t tmp;
2109 uint8_t prev;
2110 uint8_t width;
2111
2112 if (handle == NULL) /* check handle */
2113 {
2114 return 2; /* return error */
2115 }
2116 if (handle->inited != 1) /* check handle initialization */
2117 {
2118 return 3; /* return error */
2119 }
2120
2121 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_SETUP_AW, (uint8_t *)&prev, 1); /* get setup of address widths */
2122 if (res != 0) /* check result */
2123 {
2124 handle->debug_print("nrf24l01: get setup of address widths failed.\n"); /* get setup of address widths failed */
2125
2126 return 1; /* return error */
2127 }
2128 width = (nrf24l01_address_width_t)((prev >> 0) & 0x3); /* get width */
2129 if (width == 0) /* check width */
2130 {
2131 handle->debug_print("nrf24l01: len is too long with %d.\n", 0); /* len is too long */
2132
2133 return 4; /* return error */
2134 }
2135 else
2136 {
2137 width += 2; /* width + 2 */
2138 }
2139 if (*len < width) /* check width */
2140 {
2141 handle->debug_print("nrf24l01: len is too short with %d.\n", width); /* len is too short */
2142
2143 return 4; /* return error */
2144 }
2145 *len = width; /* set width */
2146
2147 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RX_ADDR_P1, (uint8_t *)addr, width); /* get receive address data pipe p1 register */
2148 if (res != 0) /* check result */
2149 {
2150 handle->debug_print("nrf24l01: get receive address data pipe p1 register failed.\n"); /* get receive address data pipe p1 register failed */
2151
2152 return 1; /* return error */
2153 }
2154 k = (*len) / 2; /* set k */
2155 for (i = 0; i < k; i++) /* run k times */
2156 {
2157 tmp = addr[i]; /* copy to tmp */
2158 addr[i] = addr[(*len) - 1 - i]; /* addr[i] = addr[n - 1 - i] */
2159 addr[(*len) - 1 - i] = tmp; /* set addr[n - 1 - i]*/
2160 }
2161
2162 return 0; /* success return 0 */
2163}
2164
2177{
2178 uint8_t res;
2179
2180 if (handle == NULL) /* check handle */
2181 {
2182 return 2; /* return error */
2183 }
2184 if (handle->inited != 1) /* check handle initialization */
2185 {
2186 return 3; /* return error */
2187 }
2188
2189 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RX_ADDR_P2, (uint8_t *)&addr, 1); /* set receive address data pipe p2 register */
2190 if (res != 0) /* check result */
2191 {
2192 handle->debug_print("nrf24l01: set receive address data pipe p2 register failed.\n"); /* set receive address data pipe p2 register failed */
2193
2194 return 1; /* return error */
2195 }
2196
2197 return 0; /* success return 0 */
2198}
2199
2212{
2213 uint8_t res;
2214
2215 if (handle == NULL) /* check handle */
2216 {
2217 return 2; /* return error */
2218 }
2219 if (handle->inited != 1) /* check handle initialization */
2220 {
2221 return 3; /* return error */
2222 }
2223
2224 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RX_ADDR_P2, (uint8_t *)addr, 1); /* get receive address data pipe p2 register */
2225 if (res != 0) /* check result */
2226 {
2227 handle->debug_print("nrf24l01: get receive address data pipe p2 register failed.\n"); /* get receive address data pipe p2 register failed */
2228
2229 return 1; /* return error */
2230 }
2231
2232 return 0; /* success return 0 */
2233}
2234
2247{
2248 uint8_t res;
2249
2250 if (handle == NULL) /* check handle */
2251 {
2252 return 2; /* return error */
2253 }
2254 if (handle->inited != 1) /* check handle initialization */
2255 {
2256 return 3; /* return error */
2257 }
2258
2259 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RX_ADDR_P3, (uint8_t *)&addr, 1); /* set receive address data pipe p3 register */
2260 if (res != 0) /* check result */
2261 {
2262 handle->debug_print("nrf24l01: set receive address data pipe p3 register failed.\n"); /* set receive address data pipe p3 register failed */
2263
2264 return 1; /* return error */
2265 }
2266
2267 return 0; /* success return 0 */
2268}
2269
2282{
2283 uint8_t res;
2284
2285 if (handle == NULL) /* check handle */
2286 {
2287 return 2; /* return error */
2288 }
2289 if (handle->inited != 1) /* check handle initialization */
2290 {
2291 return 3; /* return error */
2292 }
2293
2294 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RX_ADDR_P3, (uint8_t *)addr, 1); /* get receive address data pipe p3 register */
2295 if (res != 0) /* check result */
2296 {
2297 handle->debug_print("nrf24l01: get receive address data pipe p3 register failed.\n"); /* get receive address data pipe p3 register failed */
2298
2299 return 1; /* return error */
2300 }
2301
2302 return 0; /* success return 0 */
2303}
2304
2317{
2318 uint8_t res;
2319
2320 if (handle == NULL) /* check handle */
2321 {
2322 return 2; /* return error */
2323 }
2324 if (handle->inited != 1) /* check handle initialization */
2325 {
2326 return 3; /* return error */
2327 }
2328
2329 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RX_ADDR_P4, (uint8_t *)&addr, 1); /* set receive address data pipe p4 register */
2330 if (res != 0) /* check result */
2331 {
2332 handle->debug_print("nrf24l01: set receive address data pipe p4 register failed.\n"); /* set receive address data pipe p4 register failed */
2333
2334 return 1; /* return error */
2335 }
2336
2337 return 0; /* success return 0 */
2338}
2339
2352{
2353 uint8_t res;
2354
2355 if (handle == NULL) /* check handle */
2356 {
2357 return 2; /* return error */
2358 }
2359 if (handle->inited != 1) /* check handle initialization */
2360 {
2361 return 3; /* return error */
2362 }
2363
2364 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RX_ADDR_P4, (uint8_t *)addr, 1); /* get receive address data pipe p4 register */
2365 if (res != 0) /* check result */
2366 {
2367 handle->debug_print("nrf24l01: get receive address data pipe p4 register failed.\n"); /* get receive address data pipe p4 register failed */
2368
2369 return 1; /* return error */
2370 }
2371
2372 return 0; /* success return 0 */
2373}
2374
2387{
2388 uint8_t res;
2389
2390 if (handle == NULL) /* check handle */
2391 {
2392 return 2; /* return error */
2393 }
2394 if (handle->inited != 1) /* check handle initialization */
2395 {
2396 return 3; /* return error */
2397 }
2398
2399 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RX_ADDR_P5, (uint8_t *)&addr, 1); /* set receive address data pipe p5 register */
2400 if (res != 0) /* check result */
2401 {
2402 handle->debug_print("nrf24l01: set receive address data pipe p5 register failed.\n"); /* set receive address data pipe p5 register failed */
2403
2404 return 1; /* return error */
2405 }
2406
2407 return 0; /* success return 0 */
2408}
2409
2422{
2423 uint8_t res;
2424
2425 if (handle == NULL) /* check handle */
2426 {
2427 return 2; /* return error */
2428 }
2429 if (handle->inited != 1) /* check handle initialization */
2430 {
2431 return 3; /* return error */
2432 }
2433
2434 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RX_ADDR_P5, (uint8_t *)addr, 1); /* get receive address data pipe p5 register */
2435 if (res != 0) /* check result */
2436 {
2437 handle->debug_print("nrf24l01: get receive address data pipe p5 register failed.\n"); /* get receive address data pipe p5 register failed */
2438
2439 return 1; /* return error */
2440 }
2441
2442 return 0; /* success return 0 */
2443}
2444
2458uint8_t nrf24l01_set_tx_address(nrf24l01_handle_t *handle, uint8_t *addr, uint8_t len)
2459{
2460 uint8_t res;
2461 uint8_t prev;
2462 uint8_t width;
2463 uint8_t i;
2464 uint8_t k;
2465 uint8_t tmp;
2466 uint8_t buffer[8];
2467
2468 if (handle == NULL) /* check handle */
2469 {
2470 return 2; /* return error */
2471 }
2472 if (handle->inited != 1) /* check handle initialization */
2473 {
2474 return 3; /* return error */
2475 }
2476
2477 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_SETUP_AW, (uint8_t *)&prev, 1); /* get setup of address widths */
2478 if (res != 0) /* check result */
2479 {
2480 handle->debug_print("nrf24l01: get setup of address widths failed.\n"); /* get setup of address widths failed */
2481
2482 return 1; /* return error */
2483 }
2484 width = (nrf24l01_address_width_t)((prev >> 0) & 0x3); /* get width */
2485 if (width == 0) /* check width */
2486 {
2487 handle->debug_print("nrf24l01: len is too long with %d.\n", 0); /* len is too long */
2488
2489 return 4; /* return error */
2490 }
2491 else
2492 {
2493 width += 2; /* width + 2 */
2494 }
2495 if (len > width) /* check width */
2496 {
2497 handle->debug_print("nrf24l01: len is too long with %d.\n", width); /* len is too long */
2498
2499 return 4; /* return error */
2500 }
2501
2502 k = len / 2; /* set k */
2503 memcpy((uint8_t *)buffer, addr, len); /* copy data */
2504 for (i = 0; i < k; i++) /* run k times */
2505 {
2506 tmp = buffer[i]; /* copy to tmp */
2507 buffer[i] = buffer[len - 1 - i]; /* buffer[i] = buffer[n - 1 - i] */
2508 buffer[len - 1 - i] = tmp; /* set buffer[n - 1 - i]*/
2509 }
2510 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_TX_ADDR, (uint8_t *)buffer, len); /* set tx address */
2511 if (res != 0) /* check result */
2512 {
2513 handle->debug_print("nrf24l01: set tx address failed.\n"); /* set tx address failed */
2514
2515 return 1; /* return error */
2516 }
2517
2518 return 0; /* success return 0 */
2519}
2520
2534uint8_t nrf24l01_get_tx_address(nrf24l01_handle_t *handle, uint8_t *addr, uint8_t *len)
2535{
2536 uint8_t res;
2537 uint8_t prev;
2538 uint8_t width;
2539 uint8_t i;
2540 uint8_t k;
2541 uint8_t tmp;
2542
2543 if (handle == NULL) /* check handle */
2544 {
2545 return 2; /* return error */
2546 }
2547 if (handle->inited != 1) /* check handle initialization */
2548 {
2549 return 3; /* return error */
2550 }
2551
2552 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_SETUP_AW, (uint8_t *)&prev, 1); /* get setup of address widths */
2553 if (res != 0) /* check result */
2554 {
2555 handle->debug_print("nrf24l01: get setup of address widths failed.\n"); /* get setup of address widths failed */
2556
2557 return 1; /* return error */
2558 }
2559 width = (nrf24l01_address_width_t)((prev >> 0) & 0x3); /* get width */
2560 if (width == 0) /* check width */
2561 {
2562 handle->debug_print("nrf24l01: len is too long with %d.\n", 0); /* len is too long */
2563
2564 return 4; /* return error */
2565 }
2566 else
2567 {
2568 width += 2; /* width + 2 */
2569 }
2570 if (*len < width) /* check width */
2571 {
2572 handle->debug_print("nrf24l01: len is too short with %d.\n", width); /* len is too short */
2573
2574 return 4; /* return error */
2575 }
2576 *len = width; /* set width */
2577
2578 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_TX_ADDR, (uint8_t *)addr, width); /* get tx address register */
2579 if (res != 0) /* check result */
2580 {
2581 handle->debug_print("nrf24l01: get tx address failed.\n"); /* get tx address failed */
2582
2583 return 1; /* return error */
2584 }
2585 k = (*len) / 2; /* set k */
2586 for (i = 0; i < k; i++) /* run k times */
2587 {
2588 tmp = addr[i]; /* copy to tmp */
2589 addr[i] = addr[(*len) - 1 - i]; /* addr[i] = addr[n - 1 - i] */
2590 addr[(*len) - 1 - i] = tmp; /* set addr[n - 1 - i]*/
2591 }
2592
2593 return 0; /* success return 0 */
2594}
2595
2609{
2610 uint8_t res;
2611
2612 if (handle == NULL) /* check handle */
2613 {
2614 return 2; /* return error */
2615 }
2616 if (handle->inited != 1) /* check handle initialization */
2617 {
2618 return 3; /* return error */
2619 }
2620 if (num > 0x3F) /* check num */
2621 {
2622 handle->debug_print("nrf24l01: num is over 0x3F.\n"); /* num is over 0x3F */
2623
2624 return 4; /* return error */
2625 }
2626
2627 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RX_PW_P0, (uint8_t *)&num, 1); /* set pipe 0 payload number failed */
2628 if (res != 0) /* check result */
2629 {
2630 handle->debug_print("nrf24l01: set pipe 0 payload number failed.\n"); /* set pipe 0 payload number failed */
2631
2632 return 1; /* return error */
2633 }
2634
2635 return 0; /* success return 0 */
2636}
2637
2650{
2651 uint8_t res;
2652
2653 if (handle == NULL) /* check handle */
2654 {
2655 return 2; /* return error */
2656 }
2657 if (handle->inited != 1) /* check handle initialization */
2658 {
2659 return 3; /* return error */
2660 }
2661
2662 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RX_PW_P0, (uint8_t *)num, 1); /* get pipe 0 payload number failed */
2663 if (res != 0) /* check result */
2664 {
2665 handle->debug_print("nrf24l01: get pipe 0 payload number failed.\n"); /* get pipe 0 payload number failed */
2666
2667 return 1; /* return error */
2668 }
2669 *num = (*num) & 0x3F; /* get number */
2670
2671 return 0; /* success return 0 */
2672}
2673
2687{
2688 uint8_t res;
2689
2690 if (handle == NULL) /* check handle */
2691 {
2692 return 2; /* return error */
2693 }
2694 if (handle->inited != 1) /* check handle initialization */
2695 {
2696 return 3; /* return error */
2697 }
2698 if (num > 0x3F) /* check num */
2699 {
2700 handle->debug_print("nrf24l01: num is over 0x3F.\n"); /* num is over 0x3F */
2701
2702 return 4; /* return error */
2703 }
2704
2705 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RX_PW_P1, (uint8_t *)&num, 1); /* set pipe 1 payload number failed */
2706 if (res != 0) /* check result */
2707 {
2708 handle->debug_print("nrf24l01: set pipe 1 payload number failed.\n"); /* set pipe 1 payload number failed */
2709
2710 return 1; /* return error */
2711 }
2712
2713 return 0; /* success return 0 */
2714}
2715
2728{
2729 uint8_t res;
2730
2731 if (handle == NULL) /* check handle */
2732 {
2733 return 2; /* return error */
2734 }
2735 if (handle->inited != 1) /* check handle initialization */
2736 {
2737 return 3; /* return error */
2738 }
2739
2740 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RX_PW_P1, (uint8_t *)num, 1); /* get pipe 1 payload number failed */
2741 if (res != 0) /* check result */
2742 {
2743 handle->debug_print("nrf24l01: get pipe 1 payload number failed.\n"); /* get pipe 1 payload number failed */
2744
2745 return 1; /* return error */
2746 }
2747 *num = (*num) & 0x3F; /* get number */
2748
2749 return 0; /* success return 0 */
2750}
2751
2765{
2766 uint8_t res;
2767
2768 if (handle == NULL) /* check handle */
2769 {
2770 return 2; /* return error */
2771 }
2772 if (handle->inited != 1) /* check handle initialization */
2773 {
2774 return 3; /* return error */
2775 }
2776 if (num > 0x3F) /* check num */
2777 {
2778 handle->debug_print("nrf24l01: num is over 0x3F.\n"); /* num is over 0x3F */
2779
2780 return 4; /* return error */
2781 }
2782
2783 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RX_PW_P2, (uint8_t *)&num, 1); /* set pipe 2 payload number failed */
2784 if (res != 0) /* check result */
2785 {
2786 handle->debug_print("nrf24l01: set pipe 2 payload number failed.\n"); /* set pipe 2 payload number failed */
2787
2788 return 1; /* return error */
2789 }
2790
2791 return 0; /* success return 0 */
2792}
2793
2806{
2807 uint8_t res;
2808
2809 if (handle == NULL) /* check handle */
2810 {
2811 return 2; /* return error */
2812 }
2813 if (handle->inited != 1) /* check handle initialization */
2814 {
2815 return 3; /* return error */
2816 }
2817
2818 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RX_PW_P2, (uint8_t *)num, 1); /* get pipe 2 payload number failed */
2819 if (res != 0) /* check result */
2820 {
2821 handle->debug_print("nrf24l01: get pipe 2 payload number failed.\n"); /* get pipe 2 payload number failed */
2822
2823 return 1; /* return error */
2824 }
2825 *num = (*num) & 0x3F; /* get number */
2826
2827 return 0; /* success return 0 */
2828}
2829
2843{
2844 uint8_t res;
2845
2846 if (handle == NULL) /* check handle */
2847 {
2848 return 2; /* return error */
2849 }
2850 if (handle->inited != 1) /* check handle initialization */
2851 {
2852 return 3; /* return error */
2853 }
2854 if (num > 0x3F) /* check num */
2855 {
2856 handle->debug_print("nrf24l01: num is over 0x3F.\n"); /* num is over 0x3F */
2857
2858 return 4; /* return error */
2859 }
2860
2861 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RX_PW_P3, (uint8_t *)&num, 1); /* set pipe 3 payload number failed */
2862 if (res != 0) /* check result */
2863 {
2864 handle->debug_print("nrf24l01: set pipe 3 payload number failed.\n"); /* set pipe 3 payload number failed */
2865
2866 return 1; /* return error */
2867 }
2868
2869 return 0; /* success return 0 */
2870}
2871
2884{
2885 uint8_t res;
2886
2887 if (handle == NULL) /* check handle */
2888 {
2889 return 2; /* return error */
2890 }
2891 if (handle->inited != 1) /* check handle initialization */
2892 {
2893 return 3; /* return error */
2894 }
2895
2896 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RX_PW_P3, (uint8_t *)num, 1); /* get pipe 3 payload number failed */
2897 if (res != 0) /* check result */
2898 {
2899 handle->debug_print("nrf24l01: get pipe 3 payload number failed.\n"); /* get pipe 3 payload number failed */
2900
2901 return 1; /* return error */
2902 }
2903 *num = (*num) & 0x3F; /* get number */
2904
2905 return 0; /* success return 0 */
2906}
2907
2921{
2922 uint8_t res;
2923
2924 if (handle == NULL) /* check handle */
2925 {
2926 return 2; /* return error */
2927 }
2928 if (handle->inited != 1) /* check handle initialization */
2929 {
2930 return 3; /* return error */
2931 }
2932 if (num > 0x3F) /* check num */
2933 {
2934 handle->debug_print("nrf24l01: num is over 0x3F.\n"); /* num is over 0x3F */
2935
2936 return 4; /* return error */
2937 }
2938
2939 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RX_PW_P4, (uint8_t *)&num, 1); /* set pipe 4 payload number failed */
2940 if (res != 0) /* check result */
2941 {
2942 handle->debug_print("nrf24l01: set pipe 4 payload number failed.\n"); /* set pipe 4 payload number failed */
2943
2944 return 1; /* return error */
2945 }
2946
2947 return 0; /* success return 0 */
2948}
2949
2962{
2963 uint8_t res;
2964
2965 if (handle == NULL) /* check handle */
2966 {
2967 return 2; /* return error */
2968 }
2969 if (handle->inited != 1) /* check handle initialization */
2970 {
2971 return 3; /* return error */
2972 }
2973
2974 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RX_PW_P4, (uint8_t *)num, 1); /* get pipe 4 payload number failed */
2975 if (res != 0) /* check result */
2976 {
2977 handle->debug_print("nrf24l01: get pipe 4 payload number failed.\n"); /* get pipe 4 payload number failed */
2978
2979 return 1; /* return error */
2980 }
2981 *num = (*num) & 0x3F; /* get number */
2982
2983 return 0; /* success return 0 */
2984}
2985
2999{
3000 uint8_t res;
3001
3002 if (handle == NULL) /* check handle */
3003 {
3004 return 2; /* return error */
3005 }
3006 if (handle->inited != 1) /* check handle initialization */
3007 {
3008 return 3; /* return error */
3009 }
3010 if (num > 0x3F) /* check num */
3011 {
3012 handle->debug_print("nrf24l01: num is over 0x3F.\n"); /* num is over 0x3F */
3013
3014 return 4; /* return error */
3015 }
3016
3017 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_RX_PW_P5, (uint8_t *)&num, 1); /* set pipe 5 payload number failed */
3018 if (res != 0) /* check result */
3019 {
3020 handle->debug_print("nrf24l01: set pipe 5 payload number failed.\n"); /* set pipe 5 payload number failed */
3021
3022 return 1; /* return error */
3023 }
3024
3025 return 0; /* success return 0 */
3026}
3027
3040{
3041 uint8_t res;
3042
3043 if (handle == NULL) /* check handle */
3044 {
3045 return 2; /* return error */
3046 }
3047 if (handle->inited != 1) /* check handle initialization */
3048 {
3049 return 3; /* return error */
3050 }
3051
3052 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_RX_PW_P5, (uint8_t *)num, 1); /* get pipe 5 payload number failed */
3053 if (res != 0) /* check result */
3054 {
3055 handle->debug_print("nrf24l01: get pipe 5 payload number failed.\n"); /* get pipe 5 payload number failed */
3056
3057 return 1; /* return error */
3058 }
3059 *num = (*num) & 0x3F; /* get number */
3060
3061 return 0; /* success return 0 */
3062}
3063
3075uint8_t nrf24l01_get_fifo_status(nrf24l01_handle_t *handle, uint8_t *status)
3076{
3077 uint8_t res;
3078
3079 if (handle == NULL) /* check handle */
3080 {
3081 return 2; /* return error */
3082 }
3083 if (handle->inited != 1) /* check handle initialization */
3084 {
3085 return 3; /* return error */
3086 }
3087
3088 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_FIFO_STATUS, (uint8_t *)status, 1); /* get fifo status failed */
3089 if (res != 0) /* check result */
3090 {
3091 handle->debug_print("nrf24l01: get fifo status failed.\n"); /* get fifo status failed */
3092
3093 return 1; /* return error */
3094 }
3095
3096 return 0; /* success return 0 */
3097}
3098
3112{
3113 uint8_t res;
3114 uint8_t prev;
3115
3116 if (handle == NULL) /* check handle */
3117 {
3118 return 2; /* return error */
3119 }
3120 if (handle->inited != 1) /* check handle initialization */
3121 {
3122 return 3; /* return error */
3123 }
3124
3125 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_DYNPD, (uint8_t *)&prev, 1); /* get dynamic payload length register */
3126 if (res != 0) /* check result */
3127 {
3128 handle->debug_print("nrf24l01: get dynamic payload length register failed.\n"); /* get dynamic payload length register failed */
3129
3130 return 1; /* return error */
3131 }
3132 prev &= ~(1 << pipe); /* clear config */
3133 prev |= enable << pipe; /* set bool */
3134 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_DYNPD, (uint8_t *)&prev, 1); /* set dynamic payload length register */
3135 if (res != 0) /* check result */
3136 {
3137 handle->debug_print("nrf24l01: set dynamic payload length register failed.\n"); /* set dynamic payload length register failed */
3138
3139 return 1; /* return error */
3140 }
3141
3142 return 0; /* success return 0 */
3143}
3144
3158{
3159 uint8_t res;
3160 uint8_t prev;
3161
3162 if (handle == NULL) /* check handle */
3163 {
3164 return 2; /* return error */
3165 }
3166 if (handle->inited != 1) /* check handle initialization */
3167 {
3168 return 3; /* return error */
3169 }
3170
3171 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_DYNPD, (uint8_t *)&prev, 1); /* get dynamic payload length register */
3172 if (res != 0) /* check result */
3173 {
3174 handle->debug_print("nrf24l01: get dynamic payload length register failed.\n"); /* get dynamic payload length register failed */
3175
3176 return 1; /* return error */
3177 }
3178 *enable = (nrf24l01_bool_t)((prev >> pipe) & 0x01); /* get bool */
3179
3180 return 0; /* success return 0 */
3181}
3182
3195{
3196 uint8_t res;
3197 uint8_t prev;
3198
3199 if (handle == NULL) /* check handle */
3200 {
3201 return 2; /* return error */
3202 }
3203 if (handle->inited != 1) /* check handle initialization */
3204 {
3205 return 3; /* return error */
3206 }
3207
3208 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_FEATURE, (uint8_t *)&prev, 1); /* get feature register */
3209 if (res != 0) /* check result */
3210 {
3211 handle->debug_print("nrf24l01: get feature register failed.\n"); /* get feature register failed */
3212
3213 return 1; /* return error */
3214 }
3215 prev &= ~(1 << 2); /* clear config */
3216 prev |= enable << 2; /* set bool */
3217 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_FEATURE, (uint8_t *)&prev, 1); /* set feature register */
3218 if (res != 0) /* check result */
3219 {
3220 handle->debug_print("nrf24l01: set feature register failed.\n"); /* set feature register failed */
3221
3222 return 1; /* return error */
3223 }
3224
3225 return 0; /* success return 0 */
3226}
3227
3240{
3241 uint8_t res;
3242 uint8_t prev;
3243
3244 if (handle == NULL) /* check handle */
3245 {
3246 return 2; /* return error */
3247 }
3248 if (handle->inited != 1) /* check handle initialization */
3249 {
3250 return 3; /* return error */
3251 }
3252
3253 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_FEATURE, (uint8_t *)&prev, 1); /* get feature register */
3254 if (res != 0) /* check result */
3255 {
3256 handle->debug_print("nrf24l01: get feature register failed.\n"); /* get feature register failed */
3257
3258 return 1; /* return error */
3259 }
3260 *enable = (nrf24l01_bool_t)((prev >> 2) & 0x01); /* get bool */
3261
3262 return 0; /* success return 0 */
3263}
3264
3277{
3278 uint8_t res;
3279 uint8_t prev;
3280
3281 if (handle == NULL) /* check handle */
3282 {
3283 return 2; /* return error */
3284 }
3285 if (handle->inited != 1) /* check handle initialization */
3286 {
3287 return 3; /* return error */
3288 }
3289
3290 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_FEATURE, (uint8_t *)&prev, 1); /* get feature register */
3291 if (res != 0) /* check result */
3292 {
3293 handle->debug_print("nrf24l01: get feature register failed.\n"); /* get feature register failed */
3294
3295 return 1; /* return error */
3296 }
3297 prev &= ~(1 << 1); /* clear config */
3298 prev |= enable << 1; /* set bool */
3299 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_FEATURE, (uint8_t *)&prev, 1); /* set feature register */
3300 if (res != 0) /* check result */
3301 {
3302 handle->debug_print("nrf24l01: set feature register failed.\n"); /* set feature register failed */
3303
3304 return 1; /* return error */
3305 }
3306
3307 return 0; /* success return 0 */
3308}
3309
3322{
3323 uint8_t res;
3324 uint8_t prev;
3325
3326 if (handle == NULL) /* check handle */
3327 {
3328 return 2; /* return error */
3329 }
3330 if (handle->inited != 1) /* check handle initialization */
3331 {
3332 return 3; /* return error */
3333 }
3334
3335 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_FEATURE, (uint8_t *)&prev, 1); /* get feature register */
3336 if (res != 0) /* check result */
3337 {
3338 handle->debug_print("nrf24l01: get feature register failed.\n"); /* get feature register failed */
3339
3340 return 1; /* return error */
3341 }
3342 *enable = (nrf24l01_bool_t)((prev >> 1) & 0x01); /* get bool */
3343
3344 return 0; /* success return 0 */
3345}
3346
3359{
3360 uint8_t res;
3361 uint8_t prev;
3362
3363 if (handle == NULL) /* check handle */
3364 {
3365 return 2; /* return error */
3366 }
3367 if (handle->inited != 1) /* check handle initialization */
3368 {
3369 return 3; /* return error */
3370 }
3371
3372 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_FEATURE, (uint8_t *)&prev, 1); /* get feature register */
3373 if (res != 0) /* check result */
3374 {
3375 handle->debug_print("nrf24l01: get feature register failed.\n"); /* get feature register failed */
3376
3377 return 1; /* return error */
3378 }
3379 prev &= ~(1 << 0); /* clear config */
3380 prev |= enable << 0; /* set bool */
3381 res = a_nrf24l01_spi_write(handle, NRF24L01_REG_FEATURE, (uint8_t *)&prev, 1); /* set feature register */
3382 if (res != 0) /* check result */
3383 {
3384 handle->debug_print("nrf24l01: set feature register failed.\n"); /* set feature register failed */
3385
3386 return 1; /* return error */
3387 }
3388
3389 return 0; /* success return 0 */
3390}
3391
3404{
3405 uint8_t res;
3406 uint8_t prev;
3407
3408 if (handle == NULL) /* check handle */
3409 {
3410 return 2; /* return error */
3411 }
3412 if (handle->inited != 1) /* check handle initialization */
3413 {
3414 return 3; /* return error */
3415 }
3416
3417 res = a_nrf24l01_spi_read(handle, NRF24L01_REG_FEATURE, (uint8_t *)&prev, 1); /* get feature register */
3418 if (res != 0) /* check result */
3419 {
3420 handle->debug_print("nrf24l01: get feature register failed.\n"); /* get feature register failed */
3421
3422 return 1; /* return error */
3423 }
3424 *enable = (nrf24l01_bool_t)((prev >> 0) & 0x01); /* get bool */
3425
3426 return 0; /* success return 0 */
3427}
3428
3442uint8_t nrf24l01_read_rx_payload(nrf24l01_handle_t *handle, uint8_t *buf, uint8_t len)
3443{
3444 uint8_t res;
3445 uint8_t i;
3446 uint8_t k;
3447 uint8_t tmp;
3448
3449 if (handle == NULL) /* check handle */
3450 {
3451 return 2; /* return error */
3452 }
3453 if (handle->inited != 1) /* check handle initialization */
3454 {
3455 return 3; /* return error */
3456 }
3457 if (len > 32)
3458 {
3459 handle->debug_print("nrf24l01: len is over 32.\n"); /* len is over 32 */
3460
3461 return 4; /* return error */
3462 }
3463
3464 res = handle->spi_read(NRF24L01_COMMAND_R_RX_PAYLOAD, buf, len); /* get rx payload */
3465 if (res != 0) /* check result */
3466 {
3467 handle->debug_print("nrf24l01: get rx payload failed.\n"); /* get rx payload failed */
3468
3469 return 1; /* return error */
3470 }
3471 k = len / 2; /* get the half */
3472 for (i = 0; i < k; i++) /* run k times */
3473 {
3474 tmp = buf[i]; /* copy to tmp */
3475 buf[i] = buf[len - 1 - i]; /* buf[i] = buf[n - 1 - i] */
3476 buf[len - 1 - i] = tmp; /* set buf[n - 1 - i]*/
3477 }
3478
3479 return 0; /* success return 0 */
3480}
3481
3495uint8_t nrf24l01_write_tx_payload(nrf24l01_handle_t *handle, uint8_t *buf, uint8_t len)
3496{
3497 uint8_t res;
3498 uint8_t i;
3499 uint8_t k;
3500 uint8_t tmp;
3501 uint8_t buffer[32];
3502
3503 if (handle == NULL) /* check handle */
3504 {
3505 return 2; /* return error */
3506 }
3507 if (handle->inited != 1) /* check handle initialization */
3508 {
3509 return 3; /* return error */
3510 }
3511 if (len > 32) /* check len */
3512 {
3513 handle->debug_print("nrf24l01: len is over 32.\n"); /* len is over 32 */
3514
3515 return 4; /* return error */
3516 }
3517
3518 for (i = 0; i < len; i++) /* copy the data */
3519 {
3520 buffer[i] = buf[i]; /* copy */
3521 }
3522 k = len / 2; /* get the half */
3523 for (i = 0; i < k; i++) /* run k times */
3524 {
3525 tmp = buffer[i]; /* copy to tmp */
3526 buffer[i] = buffer[len - 1 - i]; /* buffer[i] = buffer[n - 1 - i] */
3527 buffer[len - 1 - i] = tmp; /* set buffer[n - 1 - i]*/
3528 }
3529 res = handle->spi_write(NRF24L01_COMMAND_W_TX_PAYLOAD, (uint8_t *)buffer, len); /* set tx payload */
3530 if (res != 0) /* check result */
3531 {
3532 handle->debug_print("nrf24l01: set tx payload failed.\n"); /* set tx payload failed */
3533
3534 return 1; /* return error */
3535 }
3536
3537 return 0; /* success return 0 */
3538}
3539
3551{
3552 uint8_t res;
3553
3554 if (handle == NULL) /* check handle */
3555 {
3556 return 2; /* return error */
3557 }
3558 if (handle->inited != 1) /* check handle initialization */
3559 {
3560 return 3; /* return error */
3561 }
3562
3563 res = handle->spi_write(NRF24L01_COMMAND_FLUSH_TX, NULL, 0); /* flush tx */
3564 if (res != 0) /* check result */
3565 {
3566 handle->debug_print("nrf24l01: flush tx failed.\n"); /* flush tx failed */
3567
3568 return 1; /* return error */
3569 }
3570
3571 return 0; /* success return 0 */
3572}
3573
3585{
3586 uint8_t res;
3587
3588 if (handle == NULL) /* check handle */
3589 {
3590 return 2; /* return error */
3591 }
3592 if (handle->inited != 1) /* check handle initialization */
3593 {
3594 return 3; /* return error */
3595 }
3596
3597 res = handle->spi_write(NRF24L01_COMMAND_FLUSH_RX, NULL, 0); /* flush rx */
3598 if (res != 0) /* check result */
3599 {
3600 handle->debug_print("nrf24l01: flush rx failed.\n"); /* flush rx failed */
3601
3602 return 1; /* return error */
3603 }
3604
3605 return 0; /* success return 0 */
3606}
3607
3619{
3620 uint8_t res;
3621
3622 if (handle == NULL) /* check handle */
3623 {
3624 return 2; /* return error */
3625 }
3626 if (handle->inited != 1) /* check handle initialization */
3627 {
3628 return 3; /* return error */
3629 }
3630
3631 res = handle->spi_write(NRF24L01_COMMAND_REUSE_TX_PL, NULL, 0); /* reuse tx payload */
3632 if (res != 0) /* check result */
3633 {
3634 handle->debug_print("nrf24l01: reuse tx payload failed.\n"); /* reuse tx payload failed */
3635
3636 return 1; /* return error */
3637 }
3638
3639 return 0; /* success return 0 */
3640}
3641
3653uint8_t nrf24l01_get_rx_payload_width(nrf24l01_handle_t *handle, uint8_t *width)
3654{
3655 uint8_t res;
3656
3657 if (handle == NULL) /* check handle */
3658 {
3659 return 2; /* return error */
3660 }
3661 if (handle->inited != 1) /* check handle initialization */
3662 {
3663 return 3; /* return error */
3664 }
3665
3666 res = handle->spi_read(NRF24L01_COMMAND_R_RX_PL_WID, width, 1); /* get payload width */
3667 if (res != 0) /* check result */
3668 {
3669 handle->debug_print("nrf24l01: get payload width failed.\n"); /* get payload width failed */
3670
3671 return 1; /* return error */
3672 }
3673
3674 return 0; /* success return 0 */
3675}
3676
3691uint8_t nrf24l01_write_payload_with_ack(nrf24l01_handle_t *handle, nrf24l01_pipe_t pipe, uint8_t *buf, uint8_t len)
3692{
3693 uint8_t res;
3694 uint8_t i;
3695 uint8_t k;
3696 uint8_t tmp;
3697 uint8_t buffer[32];
3698
3699 if (handle == NULL) /* check handle */
3700 {
3701 return 2; /* return error */
3702 }
3703 if (handle->inited != 1) /* check handle initialization */
3704 {
3705 return 3; /* return error */
3706 }
3707 if (len > 32) /* check len */
3708 {
3709 handle->debug_print("nrf24l01: len is over 32.\n"); /* len is over 32 */
3710
3711 return 4; /* return error */
3712 }
3713
3714 for (i = 0; i < len; i++) /* copy the data */
3715 {
3716 buffer[i] = buf[i]; /* copy */
3717 }
3718 k = len / 2; /* get the half */
3719 for (i = 0; i < k; i++) /* run k times */
3720 {
3721 tmp = buffer[i]; /* copy to tmp */
3722 buffer[i] = buffer[len - 1 - i]; /* buffer[i] = buffer[n - 1 - i] */
3723 buffer[len - 1 - i] = tmp; /* set buffer[n - 1 - i]*/
3724 }
3725 res = handle->spi_write((uint8_t)(NRF24L01_COMMAND_W_ACK_PAYLOAD | pipe),
3726 (uint8_t *)buffer, len); /* set payload with ack */
3727 if (res != 0) /* check result */
3728 {
3729 handle->debug_print("nrf24l01: set payload with ack failed.\n"); /* set payload with ack failed */
3730
3731 return 1; /* return error */
3732 }
3733
3734 return 0; /* success return 0 */
3735}
3736
3750uint8_t nrf24l01_write_payload_with_no_ack(nrf24l01_handle_t *handle, uint8_t *buf, uint8_t len)
3751{
3752 uint8_t res;
3753 uint8_t i;
3754 uint8_t k;
3755 uint8_t tmp;
3756 uint8_t buffer[32];
3757
3758 if (handle == NULL) /* check handle */
3759 {
3760 return 2; /* return error */
3761 }
3762 if (handle->inited != 1) /* check handle initialization */
3763 {
3764 return 3; /* return error */
3765 }
3766 if (len > 32) /* check len */
3767 {
3768 handle->debug_print("nrf24l01: len is over 32.\n"); /* len is over 32 */
3769
3770 return 4; /* return error */
3771 }
3772
3773 for (i = 0; i < len; i++) /* copy the data */
3774 {
3775 buffer[i] = buf[i]; /* copy */
3776 }
3777 k = len / 2; /* get the half */
3778 for (i = 0; i < k; i++) /* run k times */
3779 {
3780 tmp = buffer[i]; /* copy to tmp */
3781 buffer[i] = buffer[len - 1 - i]; /* buffer[i] = buffer[n - 1 - i] */
3782 buffer[len - 1 - i] = tmp; /* set buffer[n - 1 - i]*/
3783 }
3784
3785 res = handle->spi_write(NRF24L01_COMMAND_W_TX_PAYLOAD_NO_ACK, (uint8_t *)buffer, len); /* set payload with no ack */
3786 if (res != 0) /* check result */
3787 {
3788 handle->debug_print("nrf24l01: set payload with no ack failed.\n"); /* set payload with no ack failed */
3789
3790 return 1; /* return error */
3791 }
3792
3793 return 0; /* success return 0 */
3794}
3795
3807{
3808 uint8_t res;
3809
3810 if (handle == NULL) /* check handle */
3811 {
3812 return 2; /* return error */
3813 }
3814 if (handle->inited != 1) /* check handle initialization */
3815 {
3816 return 3; /* return error */
3817 }
3818
3819 res = handle->spi_write(NRF24L01_COMMAND_NOP, NULL, 0); /* nop */
3820 if (res != 0) /* check result */
3821 {
3822 handle->debug_print("nrf24l01: nop failed.\n"); /* nop failed */
3823
3824 return 1; /* return error */
3825 }
3826
3827 return 0; /* success return 0 */
3828}
3829
3843uint8_t nrf24l01_set_reg(nrf24l01_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
3844{
3845 if (handle == NULL) /* check handle */
3846 {
3847 return 2; /* return error */
3848 }
3849 if (handle->inited != 1) /* check handle initialization */
3850 {
3851 return 3; /* return error */
3852 }
3853
3854 return a_nrf24l01_spi_write(handle, reg, buf, len); /* write data */
3855}
3856
3870uint8_t nrf24l01_get_reg(nrf24l01_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
3871{
3872 if (handle == NULL) /* check handle */
3873 {
3874 return 2; /* return error */
3875 }
3876 if (handle->inited != 1) /* check handle initialization */
3877 {
3878 return 3; /* return error */
3879 }
3880
3881 return a_nrf24l01_spi_read(handle, reg, buf, len); /* read data */
3882}
3883
3893{
3894 if (info == NULL) /* check handle */
3895 {
3896 return 2; /* return error */
3897 }
3898
3899 memset(info, 0, sizeof(nrf24l01_info_t)); /* initialize nrf24l01 info structure */
3900 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
3901 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
3902 strncpy(info->interface, "SPI", 8); /* copy interface name */
3903 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
3904 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
3905 info->max_current_ma = MAX_CURRENT; /* set maximum current */
3906 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
3907 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
3908 info->driver_version = DRIVER_VERSION; /* set driver version */
3909
3910 return 0; /* success return 0 */
3911}
#define NRF24L01_COMMAND_FLUSH_RX
#define NRF24L01_REG_FEATURE
#define NRF24L01_COMMAND_FLUSH_TX
#define NRF24L01_REG_RX_PW_P4
#define NRF24L01_REG_STATUS
#define NRF24L01_REG_EN_RXADDR
#define MAX_CURRENT
#define NRF24L01_REG_RX_PW_P5
#define NRF24L01_COMMAND_NOP
#define NRF24L01_REG_RX_ADDR_P1
#define NRF24L01_REG_EN_AA
#define NRF24L01_COMMAND_R_REGISTER
chip command definition
#define NRF24L01_REG_OBSERVE_TX
#define NRF24L01_REG_RX_ADDR_P5
#define SUPPLY_VOLTAGE_MAX
#define NRF24L01_REG_RX_PW_P1
#define NRF24L01_COMMAND_W_TX_PAYLOAD_NO_ACK
#define NRF24L01_REG_RX_ADDR_P3
#define NRF24L01_REG_CONFIG
chip register definition
#define NRF24L01_REG_RF_SETUP
#define NRF24L01_REG_RX_PW_P3
#define NRF24L01_REG_DYNPD
#define NRF24L01_COMMAND_R_RX_PAYLOAD
#define TEMPERATURE_MAX
#define NRF24L01_REG_RX_ADDR_P4
#define NRF24L01_REG_RX_PW_P2
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define NRF24L01_REG_SETUP_RETR
#define NRF24L01_REG_RX_ADDR_P2
#define NRF24L01_REG_FIFO_STATUS
#define NRF24L01_REG_SETUP_AW
#define NRF24L01_REG_TX_ADDR
#define NRF24L01_COMMAND_W_ACK_PAYLOAD
#define NRF24L01_REG_RF_CH
#define NRF24L01_COMMAND_W_REGISTER
#define CHIP_NAME
chip information definition
#define NRF24L01_COMMAND_REUSE_TX_PL
#define NRF24L01_COMMAND_R_RX_PL_WID
#define DRIVER_VERSION
#define NRF24L01_REG_RX_PW_P0
#define NRF24L01_COMMAND_W_TX_PAYLOAD
#define NRF24L01_REG_RX_ADDR_P0
#define NRF24L01_REG_RPD
driver nrf24l01 header file
uint8_t nrf24l01_get_rx_pipe_2_address(nrf24l01_handle_t *handle, uint8_t *addr)
get the rx pipe 2 address
nrf24l01_output_power_t
nrf24l01 output power enumeration definition
uint8_t nrf24l01_get_pipe_4_payload_number(nrf24l01_handle_t *handle, uint8_t *num)
get the pipe 4 payload number
uint8_t nrf24l01_flush_tx(nrf24l01_handle_t *handle)
flush tx
uint8_t nrf24l01_get_auto_retransmit_delay(nrf24l01_handle_t *handle, uint8_t *delay)
get the auto retransmit delay
uint8_t nrf24l01_get_rx_pipe_3_address(nrf24l01_handle_t *handle, uint8_t *addr)
get the rx pipe 3 address
uint8_t nrf24l01_get_fifo_status(nrf24l01_handle_t *handle, uint8_t *status)
get the fifo status
uint8_t nrf24l01_get_pipe_1_payload_number(nrf24l01_handle_t *handle, uint8_t *num)
get the pipe 1 payload number
uint8_t nrf24l01_set_dynamic_payload(nrf24l01_handle_t *handle, nrf24l01_bool_t enable)
enable or disable the dynamic payload
struct nrf24l01_handle_s nrf24l01_handle_t
nrf24l01 handle structure definition
uint8_t nrf24l01_set_rx_pipe_3_address(nrf24l01_handle_t *handle, uint8_t addr)
set the rx pipe 3 address
uint8_t nrf24l01_set_tx_address(nrf24l01_handle_t *handle, uint8_t *addr, uint8_t len)
set the tx address
uint8_t nrf24l01_set_pipe_2_payload_number(nrf24l01_handle_t *handle, uint8_t num)
set the pipe 2 payload number
uint8_t nrf24l01_set_pipe_0_payload_number(nrf24l01_handle_t *handle, uint8_t num)
set the pipe 0 payload number
uint8_t nrf24l01_write_tx_payload(nrf24l01_handle_t *handle, uint8_t *buf, uint8_t len)
write the tx payload
uint8_t nrf24l01_set_tx_payload_with_no_ack(nrf24l01_handle_t *handle, nrf24l01_bool_t enable)
enable or disable the tx payload with no ack
uint8_t nrf24l01_get_interrupt(nrf24l01_handle_t *handle, nrf24l01_interrupt_t type, nrf24l01_bool_t *enable)
get the interrupt status
uint8_t nrf24l01_set_pipe_dynamic_payload(nrf24l01_handle_t *handle, nrf24l01_pipe_t pipe, nrf24l01_bool_t enable)
enable or disable the pipe dynamic payload
nrf24l01_config_t
nrf24l01 config enumeration definition
uint8_t nrf24l01_get_retransmitted_packet_count(nrf24l01_handle_t *handle, uint8_t *count)
get the retransmitted packet count
uint8_t nrf24l01_nop(nrf24l01_handle_t *handle)
nop
uint8_t nrf24l01_get_rx_pipe_1_address(nrf24l01_handle_t *handle, uint8_t *addr, uint8_t *len)
get the rx pipe 1 address
uint8_t nrf24l01_set_auto_retransmit_count(nrf24l01_handle_t *handle, uint8_t count)
set the auto retransmit count
uint8_t nrf24l01_get_dynamic_payload(nrf24l01_handle_t *handle, nrf24l01_bool_t *enable)
get the dynamic payload status
uint8_t nrf24l01_set_pipe_4_payload_number(nrf24l01_handle_t *handle, uint8_t num)
set the pipe 4 payload number
uint8_t nrf24l01_send(nrf24l01_handle_t *handle, uint8_t *buf, uint8_t len)
send data
uint8_t nrf24l01_set_payload_with_ack(nrf24l01_handle_t *handle, nrf24l01_bool_t enable)
enable or disable the payload with ack
uint8_t nrf24l01_write_payload_with_no_ack(nrf24l01_handle_t *handle, uint8_t *buf, uint8_t len)
write the payload with no ack
uint8_t nrf24l01_set_config(nrf24l01_handle_t *handle, nrf24l01_config_t config, nrf24l01_bool_t enable)
enable or disable configure
uint8_t nrf24l01_get_received_power_detector(nrf24l01_handle_t *handle, nrf24l01_bool_t *enable)
get the received power detector
uint8_t nrf24l01_get_rx_payload_width(nrf24l01_handle_t *handle, uint8_t *width)
get the rx payload width
uint8_t nrf24l01_set_output_power(nrf24l01_handle_t *handle, nrf24l01_output_power_t power)
set the output power
uint8_t nrf24l01_set_rx_pipe_1_address(nrf24l01_handle_t *handle, uint8_t *addr, uint8_t len)
set the rx pipe 1 address
uint8_t nrf24l01_get_payload_with_ack(nrf24l01_handle_t *handle, nrf24l01_bool_t *enable)
get the payload with ack status
uint8_t nrf24l01_get_mode(nrf24l01_handle_t *handle, nrf24l01_mode_t *mode)
get the chip mode
struct nrf24l01_info_s nrf24l01_info_t
nrf24l01 information structure definition
nrf24l01_mode_t
nrf24l01 mode enumeration definition
uint8_t nrf24l01_auto_retransmit_delay_convert_to_data(nrf24l01_handle_t *handle, uint8_t reg, uint32_t *us)
convert the register raw data to the delay
uint8_t nrf24l01_set_channel_frequency(nrf24l01_handle_t *handle, uint8_t freq)
set the channel frequency
uint8_t nrf24l01_get_address_width(nrf24l01_handle_t *handle, nrf24l01_address_width_t *width)
get the address width
uint8_t nrf24l01_get_pipe_0_payload_number(nrf24l01_handle_t *handle, uint8_t *num)
get the pipe 0 payload number
uint8_t nrf24l01_get_auto_retransmit_count(nrf24l01_handle_t *handle, uint8_t *count)
get the auto retransmit count
uint8_t nrf24l01_irq_handler(nrf24l01_handle_t *handle)
irq handler
uint8_t nrf24l01_set_auto_acknowledgment(nrf24l01_handle_t *handle, nrf24l01_pipe_t pipe, nrf24l01_bool_t enable)
enable or disable auto acknowledgment
uint8_t nrf24l01_get_pipe_2_payload_number(nrf24l01_handle_t *handle, uint8_t *num)
get the pipe 2 payload number
uint8_t nrf24l01_clear_interrupt(nrf24l01_handle_t *handle, nrf24l01_interrupt_t type)
clear the interrupt status
uint8_t nrf24l01_get_output_power(nrf24l01_handle_t *handle, nrf24l01_output_power_t *power)
get the output power
uint8_t nrf24l01_get_auto_acknowledgment(nrf24l01_handle_t *handle, nrf24l01_pipe_t pipe, nrf24l01_bool_t *enable)
get the auto acknowledgment status
uint8_t nrf24l01_get_rx_pipe_0_address(nrf24l01_handle_t *handle, uint8_t *addr, uint8_t *len)
get the rx pipe 0 address
uint8_t nrf24l01_get_tx_address(nrf24l01_handle_t *handle, uint8_t *addr, uint8_t *len)
get the tx address
uint8_t nrf24l01_get_pipe_dynamic_payload(nrf24l01_handle_t *handle, nrf24l01_pipe_t pipe, nrf24l01_bool_t *enable)
get the pipe dynamic payload status
uint8_t nrf24l01_set_pipe_3_payload_number(nrf24l01_handle_t *handle, uint8_t num)
set the pipe 3 payload number
uint8_t nrf24l01_get_config(nrf24l01_handle_t *handle, nrf24l01_config_t config, nrf24l01_bool_t *enable)
get the configure
uint8_t nrf24l01_write_payload_with_ack(nrf24l01_handle_t *handle, nrf24l01_pipe_t pipe, uint8_t *buf, uint8_t len)
write the payload with ack
uint8_t nrf24l01_get_rx_pipe(nrf24l01_handle_t *handle, nrf24l01_pipe_t pipe, nrf24l01_bool_t *enable)
get the rx pipe status
uint8_t nrf24l01_auto_retransmit_delay_convert_to_register(nrf24l01_handle_t *handle, uint32_t us, uint8_t *reg)
convert the delay to the register raw data
uint8_t nrf24l01_get_data_pipe_number(nrf24l01_handle_t *handle, uint8_t *number)
get the data pipe number
uint8_t nrf24l01_get_data_rate(nrf24l01_handle_t *handle, nrf24l01_data_rate_t *rate)
get the data rate
uint8_t nrf24l01_read_rx_payload(nrf24l01_handle_t *handle, uint8_t *buf, uint8_t len)
read the rx payload
uint8_t nrf24l01_get_rx_pipe_5_address(nrf24l01_handle_t *handle, uint8_t *addr)
get the rx pipe 5 address
uint8_t nrf24l01_get_channel_frequency(nrf24l01_handle_t *handle, uint8_t *freq)
get the channel frequency
uint8_t nrf24l01_set_rx_pipe_5_address(nrf24l01_handle_t *handle, uint8_t addr)
set the rx pipe 5 address
nrf24l01_interrupt_t
nrf24l01 interrupt enumeration definition
uint8_t nrf24l01_set_address_width(nrf24l01_handle_t *handle, nrf24l01_address_width_t width)
set the address width
uint8_t nrf24l01_set_active(nrf24l01_handle_t *handle, nrf24l01_bool_t enable)
enable or disable the chip
nrf24l01_address_width_t
nrf24l01 address width enumeration definition
uint8_t nrf24l01_get_lost_packet_count(nrf24l01_handle_t *handle, uint8_t *count)
get the lost packet count
uint8_t nrf24l01_set_rx_pipe(nrf24l01_handle_t *handle, nrf24l01_pipe_t pipe, nrf24l01_bool_t enable)
enable or disable rx pipe
nrf24l01_pipe_t
nrf24l01 pipe enumeration definition
uint8_t nrf24l01_get_continuous_carrier_transmit(nrf24l01_handle_t *handle, nrf24l01_bool_t *enable)
get the continuous carrier transmit status
uint8_t nrf24l01_info(nrf24l01_info_t *info)
get chip's information
uint8_t nrf24l01_set_pipe_5_payload_number(nrf24l01_handle_t *handle, uint8_t num)
set the pipe 5 payload number
uint8_t nrf24l01_set_continuous_carrier_transmit(nrf24l01_handle_t *handle, nrf24l01_bool_t enable)
enable or disable continuous carrier transmit
uint8_t nrf24l01_init(nrf24l01_handle_t *handle)
initialize the chip
uint8_t nrf24l01_set_force_pll_lock_signal(nrf24l01_handle_t *handle, nrf24l01_bool_t enable)
enable or disable force pll lock signal
uint8_t nrf24l01_get_pipe_3_payload_number(nrf24l01_handle_t *handle, uint8_t *num)
get the pipe 3 payload number
uint8_t nrf24l01_set_rx_pipe_2_address(nrf24l01_handle_t *handle, uint8_t addr)
set the rx pipe 2 address
uint8_t nrf24l01_get_rx_pipe_4_address(nrf24l01_handle_t *handle, uint8_t *addr)
get the rx pipe 4 address
uint8_t nrf24l01_get_force_pll_lock_signal(nrf24l01_handle_t *handle, nrf24l01_bool_t *enable)
get the force pll lock signal status
uint8_t nrf24l01_set_mode(nrf24l01_handle_t *handle, nrf24l01_mode_t mode)
set the chip mode
uint8_t nrf24l01_set_auto_retransmit_delay(nrf24l01_handle_t *handle, uint8_t delay)
set the auto retransmit delay
uint8_t nrf24l01_get_pipe_5_payload_number(nrf24l01_handle_t *handle, uint8_t *num)
get the pipe 5 payload number
uint8_t nrf24l01_set_pipe_1_payload_number(nrf24l01_handle_t *handle, uint8_t num)
set the pipe 1 payload number
uint8_t nrf24l01_flush_rx(nrf24l01_handle_t *handle)
flush rx
nrf24l01_data_rate_t
nrf24l01 data rate enumeration definition
uint8_t nrf24l01_deinit(nrf24l01_handle_t *handle)
close the chip
uint8_t nrf24l01_set_data_rate(nrf24l01_handle_t *handle, nrf24l01_data_rate_t rate)
set the data rate
uint8_t nrf24l01_get_tx_payload_with_no_ack(nrf24l01_handle_t *handle, nrf24l01_bool_t *enable)
get the tx payload with no ack status
nrf24l01_bool_t
nrf24l01 bool enumeration definition
uint8_t nrf24l01_set_rx_pipe_0_address(nrf24l01_handle_t *handle, uint8_t *addr, uint8_t len)
set the rx pipe 0 address
uint8_t nrf24l01_reuse_tx_payload(nrf24l01_handle_t *handle)
reuse the tx payload
uint8_t nrf24l01_set_rx_pipe_4_address(nrf24l01_handle_t *handle, uint8_t addr)
set the rx pipe 4 address
@ NRF24L01_INTERRUPT_TX_DS
@ NRF24L01_INTERRUPT_MAX_RT
@ NRF24L01_INTERRUPT_RX_DR
@ NRF24L01_INTERRUPT_TX_FULL
uint8_t nrf24l01_get_reg(nrf24l01_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t nrf24l01_set_reg(nrf24l01_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t(* gpio_write)(uint8_t value)
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
uint8_t(* spi_deinit)(void)
uint8_t(* gpio_init)(void)
uint8_t(* gpio_deinit)(void)
void(* receive_callback)(uint8_t type, uint8_t num, uint8_t *buf, uint8_t len)
char manufacturer_name[32]