furi-hal-subghz.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. /** Radio Presets */
  14. typedef enum {
  15. FuriHalSubGhzPresetOok270Async, /**< OOK, bandwidth 270kHz, asynchronous */
  16. FuriHalSubGhzPresetOok650Async, /**< OOK, bandwidth 650kHz, asynchronous */
  17. FuriHalSubGhzPreset2FSKAsync, /**< FM, asynchronous */
  18. } FuriHalSubGhzPreset;
  19. /** Switchable Radio Paths */
  20. typedef enum {
  21. FuriHalSubGhzPathIsolate, /**< Isolate Radio from antenna */
  22. FuriHalSubGhzPath433, /**< Center Frquency: 433MHz. Path 1: SW1RF1-SW2RF2, LCLCL */
  23. FuriHalSubGhzPath315, /**< Center Frquency: 315MHz. Path 2: SW1RF2-SW2RF1, LCLCLCL */
  24. FuriHalSubGhzPath868, /**< Center Frquency: 868MHz. Path 3: SW1RF3-SW2RF3, LCLC */
  25. } FuriHalSubGhzPath;
  26. /** SubGhz state */
  27. typedef enum {
  28. SubGhzStateInit, /**< Init pending */
  29. SubGhzStateIdle, /**< Idle, energy save mode */
  30. SubGhzStateAsyncRx, /**< Async RX started */
  31. SubGhzStateAsyncTx, /**< Async TX started, DMA and timer is on */
  32. SubGhzStateAsyncTxLast, /**< Async TX continue, DMA completed and timer got last value to go */
  33. SubGhzStateAsyncTxEnd, /**< Async TX complete, cleanup needed */
  34. } SubGhzState;
  35. /** SubGhz regulation, receive transmission on the current frequency for the
  36. * region */
  37. typedef enum {
  38. SubGhzRegulationOnlyRx, /**only Rx*/
  39. SubGhzRegulationTxRx, /**TxRx*/
  40. } SubGhzRegulation;
  41. /** Initialize and switch to power save mode Used by internal API-HAL
  42. * initalization routine Can be used to reinitialize device to safe state and
  43. * send it to sleep
  44. */
  45. void furi_hal_subghz_init();
  46. /** Send device to sleep mode
  47. */
  48. void furi_hal_subghz_sleep();
  49. /** Dump info to stdout
  50. */
  51. void furi_hal_subghz_dump_state();
  52. /** Load registers from preset by preset name
  53. *
  54. * @param preset to load
  55. */
  56. void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset);
  57. /** Load registers
  58. *
  59. * @param data Registers data
  60. */
  61. void furi_hal_subghz_load_registers(const uint8_t data[][2]);
  62. /** Load PATABLE
  63. *
  64. * @param data 8 uint8_t values
  65. */
  66. void furi_hal_subghz_load_patable(const uint8_t data[8]);
  67. /** Write packet to FIFO
  68. *
  69. * @param data bytes array
  70. * @param size size
  71. */
  72. void furi_hal_subghz_write_packet(const uint8_t* data, uint8_t size);
  73. /** Read packet from FIFO
  74. *
  75. * @param data pointer
  76. * @param size size
  77. */
  78. void furi_hal_subghz_read_packet(uint8_t* data, uint8_t* size);
  79. /** Flush rx FIFO buffer
  80. */
  81. void furi_hal_subghz_flush_rx();
  82. /** Shutdown Issue spwd command
  83. * @warning registers content will be lost
  84. */
  85. void furi_hal_subghz_shutdown();
  86. /** Reset Issue reset command
  87. * @warning registers content will be lost
  88. */
  89. void furi_hal_subghz_reset();
  90. /** Switch to Idle
  91. */
  92. void furi_hal_subghz_idle();
  93. /** Switch to Recieve
  94. */
  95. void furi_hal_subghz_rx();
  96. /** Switch to Transmit
  97. *
  98. * @return true if the transfer is allowed by belonging to the region
  99. */
  100. bool furi_hal_subghz_tx();
  101. /** Get RSSI value in dBm
  102. *
  103. * @return RSSI value
  104. */
  105. float furi_hal_subghz_get_rssi();
  106. /** Check if frequency is in valid range
  107. *
  108. * @param value frequency in Hz
  109. *
  110. * @return true if frequncy is valid, otherwise false
  111. */
  112. bool furi_hal_subghz_is_frequency_valid(uint32_t value);
  113. /** Set frequency and path This function automatically selects antenna matching
  114. * network
  115. *
  116. * @param value frequency in Hz
  117. *
  118. * @return real frequency in herz
  119. */
  120. uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value);
  121. /** Set frequency
  122. *
  123. * @param value frequency in Hz
  124. *
  125. * @return real frequency in herz
  126. */
  127. uint32_t furi_hal_subghz_set_frequency(uint32_t value);
  128. /** Set path
  129. *
  130. * @param path path to use
  131. */
  132. void furi_hal_subghz_set_path(FuriHalSubGhzPath path);
  133. /* High Level API */
  134. /** Signal Timings Capture callback */
  135. typedef void (*FuriHalSubGhzCaptureCallback)(bool level, uint32_t duration, void* context);
  136. /** Enable signal timings capture Initializes GPIO and TIM2 for timings capture
  137. *
  138. * @param callback FuriHalSubGhzCaptureCallback
  139. * @param context callback context
  140. */
  141. void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void* context);
  142. /** Disable signal timings capture Resets GPIO and TIM2
  143. */
  144. void furi_hal_subghz_stop_async_rx();
  145. /** Async TX callback type
  146. * @param context callback context
  147. * @return LevelDuration
  148. */
  149. typedef LevelDuration (*FuriHalSubGhzAsyncTxCallback)(void* context);
  150. /** Start async TX Initializes GPIO, TIM2 and DMA1 for signal output
  151. *
  152. * @param callback FuriHalSubGhzAsyncTxCallback
  153. * @param context callback context
  154. *
  155. * @return true if the transfer is allowed by belonging to the region
  156. */
  157. bool furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void* context);
  158. /** Wait for async transmission to complete
  159. *
  160. * @return true if TX complete
  161. */
  162. bool furi_hal_subghz_is_async_tx_complete();
  163. /** Stop async transmission and cleanup resources Resets GPIO, TIM2, and DMA1
  164. */
  165. void furi_hal_subghz_stop_async_tx();
  166. #ifdef __cplusplus
  167. }
  168. #endif