nrf24.h 2.8 KB

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