furi_hal_subghz.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /**
  2. * @file furi_hal_subghz.h
  3. * SubGhz HAL API
  4. */
  5. #pragma once
  6. #include <stdbool.h>
  7. #include <stdint.h>
  8. #include <stddef.h>
  9. #include <toolbox/level_duration.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /** Low level buffer dimensions and guard times */
  14. #define API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL (256)
  15. #define API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF (API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL / 2)
  16. #define API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME 999
  17. /** Radio Presets */
  18. typedef enum {
  19. FuriHalSubGhzPresetIDLE, /**< default configuration */
  20. FuriHalSubGhzPresetOok270Async, /**< OOK, bandwidth 270kHz, asynchronous */
  21. FuriHalSubGhzPresetOok650Async, /**< OOK, bandwidth 650kHz, asynchronous */
  22. FuriHalSubGhzPreset2FSKDev238Async, /**< FM, deviation 2.380371 kHz, asynchronous */
  23. FuriHalSubGhzPreset2FSKDev476Async, /**< FM, deviation 47.60742 kHz, asynchronous */
  24. FuriHalSubGhzPresetMSK99_97KbAsync, /**< MSK, deviation 47.60742 kHz, 99.97Kb/s, asynchronous */
  25. FuriHalSubGhzPresetGFSK9_99KbAsync, /**< GFSK, deviation 19.042969 kHz, 9.996Kb/s, asynchronous */
  26. FuriHalSubGhzPresetCustom, /**Custom Preset*/
  27. } FuriHalSubGhzPreset;
  28. /** Switchable Radio Paths */
  29. typedef enum {
  30. FuriHalSubGhzPathIsolate, /**< Isolate Radio from antenna */
  31. FuriHalSubGhzPath433, /**< Center Frquency: 433MHz. Path 1: SW1RF1-SW2RF2, LCLCL */
  32. FuriHalSubGhzPath315, /**< Center Frquency: 315MHz. Path 2: SW1RF2-SW2RF1, LCLCLCL */
  33. FuriHalSubGhzPath868, /**< Center Frquency: 868MHz. Path 3: SW1RF3-SW2RF3, LCLC */
  34. } FuriHalSubGhzPath;
  35. /** SubGhz state */
  36. typedef enum {
  37. SubGhzStateInit, /**< Init pending */
  38. SubGhzStateIdle, /**< Idle, energy save mode */
  39. SubGhzStateAsyncRx, /**< Async RX started */
  40. SubGhzStateAsyncTx, /**< Async TX started, DMA and timer is on */
  41. SubGhzStateAsyncTxLast, /**< Async TX continue, DMA completed and timer got last value to go */
  42. SubGhzStateAsyncTxEnd, /**< Async TX complete, cleanup needed */
  43. } SubGhzState;
  44. /** SubGhz regulation, receive transmission on the current frequency for the
  45. * region */
  46. typedef enum {
  47. SubGhzRegulationOnlyRx, /**only Rx*/
  48. SubGhzRegulationTxRx, /**TxRx*/
  49. } SubGhzRegulation;
  50. /** Initialize and switch to power save mode Used by internal API-HAL
  51. * initalization routine Can be used to reinitialize device to safe state and
  52. * send it to sleep
  53. */
  54. void furi_hal_subghz_init();
  55. /** Send device to sleep mode
  56. */
  57. void furi_hal_subghz_sleep();
  58. /** Dump info to stdout
  59. */
  60. void furi_hal_subghz_dump_state();
  61. /** Load registers from preset by preset name
  62. *
  63. * @param preset to load
  64. */
  65. void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset);
  66. /** Load custom registers from preset
  67. *
  68. * @param preset_data registers to load
  69. */
  70. void furi_hal_subghz_load_custom_preset(uint8_t* preset_data);
  71. /** Load registers
  72. *
  73. * @param data Registers data
  74. */
  75. void furi_hal_subghz_load_registers(uint8_t* data);
  76. /** Load PATABLE
  77. *
  78. * @param data 8 uint8_t values
  79. */
  80. void furi_hal_subghz_load_patable(const uint8_t data[8]);
  81. /** Write packet to FIFO
  82. *
  83. * @param data bytes array
  84. * @param size size
  85. */
  86. void furi_hal_subghz_write_packet(const uint8_t* data, uint8_t size);
  87. /** Check if recieve pipe is not empty
  88. *
  89. * @return true if not empty
  90. */
  91. bool furi_hal_subghz_rx_pipe_not_empty();
  92. /** Check if recieved data crc is valid
  93. *
  94. * @return true if valid
  95. */
  96. bool furi_hal_subghz_is_rx_data_crc_valid();
  97. /** Read packet from FIFO
  98. *
  99. * @param data pointer
  100. * @param size size
  101. */
  102. void furi_hal_subghz_read_packet(uint8_t* data, uint8_t* size);
  103. /** Flush rx FIFO buffer
  104. */
  105. void furi_hal_subghz_flush_rx();
  106. /** Flush tx FIFO buffer
  107. */
  108. void furi_hal_subghz_flush_tx();
  109. /** Shutdown Issue spwd command
  110. * @warning registers content will be lost
  111. */
  112. void furi_hal_subghz_shutdown();
  113. /** Reset Issue reset command
  114. * @warning registers content will be lost
  115. */
  116. void furi_hal_subghz_reset();
  117. /** Switch to Idle
  118. */
  119. void furi_hal_subghz_idle();
  120. /** Switch to Recieve
  121. */
  122. void furi_hal_subghz_rx();
  123. /** Switch to Transmit
  124. *
  125. * @return true if the transfer is allowed by belonging to the region
  126. */
  127. bool furi_hal_subghz_tx();
  128. /** Get RSSI value in dBm
  129. *
  130. * @return RSSI value
  131. */
  132. float furi_hal_subghz_get_rssi();
  133. /** Get LQI
  134. *
  135. * @return LQI value
  136. */
  137. uint8_t furi_hal_subghz_get_lqi();
  138. /** Check if frequency is in valid range
  139. *
  140. * @param value frequency in Hz
  141. *
  142. * @return true if frequncy is valid, otherwise false
  143. */
  144. bool furi_hal_subghz_is_frequency_valid(uint32_t value);
  145. /** Set frequency and path This function automatically selects antenna matching
  146. * network
  147. *
  148. * @param value frequency in Hz
  149. *
  150. * @return real frequency in herz
  151. */
  152. uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value);
  153. /** Set frequency
  154. *
  155. * @param value frequency in Hz
  156. *
  157. * @return real frequency in herz
  158. */
  159. uint32_t furi_hal_subghz_set_frequency(uint32_t value);
  160. /** Set path
  161. *
  162. * @param path path to use
  163. */
  164. void furi_hal_subghz_set_path(FuriHalSubGhzPath path);
  165. /* High Level API */
  166. /** Signal Timings Capture callback */
  167. typedef void (*FuriHalSubGhzCaptureCallback)(bool level, uint32_t duration, void* context);
  168. /** Enable signal timings capture Initializes GPIO and TIM2 for timings capture
  169. *
  170. * @param callback FuriHalSubGhzCaptureCallback
  171. * @param context callback context
  172. */
  173. void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void* context);
  174. /** Disable signal timings capture Resets GPIO and TIM2
  175. */
  176. void furi_hal_subghz_stop_async_rx();
  177. /** Async TX callback type
  178. * @param context callback context
  179. * @return LevelDuration
  180. */
  181. typedef LevelDuration (*FuriHalSubGhzAsyncTxCallback)(void* context);
  182. /** Start async TX Initializes GPIO, TIM2 and DMA1 for signal output
  183. *
  184. * @param callback FuriHalSubGhzAsyncTxCallback
  185. * @param context callback context
  186. *
  187. * @return true if the transfer is allowed by belonging to the region
  188. */
  189. bool furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void* context);
  190. /** Wait for async transmission to complete
  191. *
  192. * @return true if TX complete
  193. */
  194. bool furi_hal_subghz_is_async_tx_complete();
  195. /** Stop async transmission and cleanup resources Resets GPIO, TIM2, and DMA1
  196. */
  197. void furi_hal_subghz_stop_async_tx();
  198. #ifdef __cplusplus
  199. }
  200. #endif