nrf24.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <furi_hal_spi.h>
  5. #include <xtreme.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #define R_REGISTER 0x00
  10. #define W_REGISTER 0x20
  11. #define REGISTER_MASK 0x1F
  12. #define ACTIVATE 0x50
  13. #define R_RX_PL_WID 0x60
  14. #define R_RX_PAYLOAD 0x61
  15. #define W_TX_PAYLOAD 0xA0
  16. #define W_TX_PAYLOAD_NOACK 0xB0
  17. #define W_ACK_PAYLOAD 0xA8
  18. #define FLUSH_TX 0xE1
  19. #define FLUSH_RX 0xE2
  20. #define REUSE_TX_PL 0xE3
  21. #define RF24_NOP 0xFF
  22. #define REG_CONFIG 0x00
  23. #define REG_EN_AA 0x01
  24. #define REG_EN_RXADDR 0x02
  25. #define REG_SETUP_AW 0x03
  26. #define REG_SETUP_RETR 0x04
  27. #define REG_RDP 0x09
  28. #define REG_DYNPD 0x1C
  29. #define REG_FEATURE 0x1D
  30. #define REG_RF_SETUP 0x06
  31. #define REG_STATUS 0x07
  32. #define REG_RX_ADDR_P0 0x0A
  33. #define REG_RF_CH 0x05
  34. #define REG_TX_ADDR 0x10
  35. #define RX_PW_P0 0x11
  36. #define TX_DS 0x20
  37. #define MAX_RT 0x10
  38. #define nrf24_TIMEOUT 500
  39. #define nrf24_CE_PIN &gpio_ext_pb2
  40. #define nrf24_HANDLE &furi_hal_spi_bus_handle_external
  41. /* Low level API */
  42. /** Write device register
  43. *
  44. * @param handle - pointer to FuriHalSpiHandle
  45. * @param reg - register
  46. * @param data - data to write
  47. *
  48. * @return device status
  49. */
  50. uint8_t nrf24_write_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t data);
  51. /** Read device register
  52. *
  53. * @param handle - pointer to FuriHalSpiHandle
  54. * @param reg - register
  55. * @param[out] data - pointer to data
  56. *
  57. * @return device status
  58. */
  59. uint8_t nrf24_read_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t* data, uint8_t size);
  60. /** Power down the radio
  61. *
  62. * @param handle - pointer to FuriHalSpiHandle
  63. *
  64. * @return device status
  65. */
  66. uint8_t nrf24_set_idle(FuriHalSpiBusHandle* handle);
  67. /** Sets the radio to RX mode
  68. *
  69. * @param handle - pointer to FuriHalSpiHandle
  70. *
  71. * @return device status
  72. */
  73. uint8_t nrf24_set_rx_mode(FuriHalSpiBusHandle* handle, bool nodelay);
  74. /*=============================================================================================================*/
  75. /* High level API */
  76. /** Must call this before using any other nrf24 API
  77. *
  78. */
  79. void nrf24_init();
  80. /** Must call this when we end using nrf24 device
  81. *
  82. */
  83. void nrf24_deinit();
  84. /** Send flush rx command
  85. *
  86. * @param handle - pointer to FuriHalSpiHandle
  87. *
  88. * @return device status
  89. */
  90. uint8_t nrf24_flush_rx(FuriHalSpiBusHandle* handle);
  91. /** Gets RDP from register 0x09
  92. *
  93. * @param handle - pointer to FuriHalSpiHandle
  94. *
  95. * @return RDP from register 0x09
  96. */
  97. uint8_t nrf24_get_rdp(FuriHalSpiBusHandle* handle);
  98. /** Gets the current status flags from the STATUS register
  99. *
  100. * @param handle - pointer to FuriHalSpiHandle
  101. *
  102. * @return status flags
  103. */
  104. uint8_t nrf24_status(FuriHalSpiBusHandle* handle);
  105. bool nrf24_check_connected(FuriHalSpiBusHandle* handle);
  106. #ifdef __cplusplus
  107. }
  108. #endif