nrf24.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 \
  41. (XTREME_SETTINGS()->spi_nrf24_handle == SpiDefault ? &furi_hal_spi_bus_handle_external : \
  42. &furi_hal_spi_bus_handle_external_extra)
  43. /* Low level API */
  44. /** Write device register
  45. *
  46. * @param handle - pointer to FuriHalSpiHandle
  47. * @param reg - register
  48. * @param data - data to write
  49. *
  50. * @return device status
  51. */
  52. uint8_t nrf24_write_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t data);
  53. /** Read device register
  54. *
  55. * @param handle - pointer to FuriHalSpiHandle
  56. * @param reg - register
  57. * @param[out] data - pointer to data
  58. *
  59. * @return device status
  60. */
  61. uint8_t nrf24_read_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t* data, uint8_t size);
  62. /** Power down the radio
  63. *
  64. * @param handle - pointer to FuriHalSpiHandle
  65. *
  66. * @return device status
  67. */
  68. uint8_t nrf24_set_idle(FuriHalSpiBusHandle* handle);
  69. /** Sets the radio to RX mode
  70. *
  71. * @param handle - pointer to FuriHalSpiHandle
  72. *
  73. * @return device status
  74. */
  75. uint8_t nrf24_set_rx_mode(FuriHalSpiBusHandle* handle, bool nodelay);
  76. /*=============================================================================================================*/
  77. /* High level API */
  78. /** Must call this before using any other nrf24 API
  79. *
  80. */
  81. void nrf24_init();
  82. /** Must call this when we end using nrf24 device
  83. *
  84. */
  85. void nrf24_deinit();
  86. /** Send flush rx command
  87. *
  88. * @param handle - pointer to FuriHalSpiHandle
  89. *
  90. * @return device status
  91. */
  92. uint8_t nrf24_flush_rx(FuriHalSpiBusHandle* handle);
  93. /** Gets RDP from register 0x09
  94. *
  95. * @param handle - pointer to FuriHalSpiHandle
  96. *
  97. * @return RDP from register 0x09
  98. */
  99. uint8_t nrf24_get_rdp(FuriHalSpiBusHandle* handle);
  100. /** Gets the current status flags from the STATUS register
  101. *
  102. * @param handle - pointer to FuriHalSpiHandle
  103. *
  104. * @return status flags
  105. */
  106. uint8_t nrf24_status(FuriHalSpiBusHandle* handle);
  107. bool nrf24_check_connected(FuriHalSpiBusHandle* handle);
  108. #ifdef __cplusplus
  109. }
  110. #endif