api-hal-subghz.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <toolbox/level_duration.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /** Radio Presets */
  9. typedef enum {
  10. ApiHalSubGhzPresetOokAsync, /** OOK, asynchronous */
  11. ApiHalSubGhzPreset2FskPacket, /** 2FSK, 115kBaud, variable packet length */
  12. ApiHalSubGhzPresetMP, /** MP OOK, asynchronous */
  13. } ApiHalSubGhzPreset;
  14. /** Switchable Radio Paths */
  15. typedef enum {
  16. ApiHalSubGhzPathIsolate, /** Isolate Radio from antenna */
  17. ApiHalSubGhzPath433, /** Center Frquency: 433MHz. Path 1: SW1RF1-SW2RF2, LCLCL */
  18. ApiHalSubGhzPath315, /** Center Frquency: 315MHz. Path 2: SW1RF2-SW2RF1, LCLCLCL */
  19. ApiHalSubGhzPath868, /** Center Frquency: 868MHz. Path 3: SW1RF3-SW2RF3, LCLC */
  20. } ApiHalSubGhzPath;
  21. /** Initialize and switch to power save mode
  22. * Used by internal API-HAL initalization routine
  23. * Can be used to reinitialize device to safe state and send it to sleep
  24. */
  25. void api_hal_subghz_init();
  26. /** Dump info to stdout */
  27. void api_hal_subghz_dump_state();
  28. /** Load registers from preset by preset name
  29. * @param preset to load
  30. */
  31. void api_hal_subghz_load_preset(ApiHalSubGhzPreset preset);
  32. /** Get status */
  33. uint8_t api_hal_subghz_get_status();
  34. /** Load registers
  35. * @param register-value pairs array, terminated with {0,0}
  36. */
  37. void api_hal_subghz_load_registers(const uint8_t data[][2]);
  38. /** Load PATABLE
  39. * @param data, 8 uint8_t values
  40. */
  41. void api_hal_subghz_load_patable(const uint8_t data[8]);
  42. /** Write packet to FIFO
  43. * @param data, bytes array
  44. * @param size, size
  45. */
  46. void api_hal_subghz_write_packet(const uint8_t* data, uint8_t size);
  47. /** Read packet from FIFO
  48. * @param data, pointer
  49. * @param size, size
  50. */
  51. void api_hal_subghz_read_packet(uint8_t* data, uint8_t* size);
  52. /** Flush rx FIFO buffer */
  53. void api_hal_subghz_flush_rx();
  54. /** Shutdown
  55. * Issue spwd command
  56. * @warning registers content will be lost
  57. */
  58. void api_hal_subghz_shutdown();
  59. /** Reset
  60. * Issue reset command
  61. * @warning registers content will be lost
  62. */
  63. void api_hal_subghz_reset();
  64. /** Switch to Idle */
  65. void api_hal_subghz_idle();
  66. /** Switch to Recieve */
  67. void api_hal_subghz_rx();
  68. /** Switch to Transmit */
  69. void api_hal_subghz_tx();
  70. /** Get RSSI value in dBm */
  71. float api_hal_subghz_get_rssi();
  72. /** Set frequency and path
  73. * This function automatically selects antenna matching network
  74. * @param frequency in herz
  75. * @return real frequency in herz
  76. */
  77. uint32_t api_hal_subghz_set_frequency_and_path(uint32_t value);
  78. /** Set frequency
  79. * @param frequency in herz
  80. * @return real frequency in herz
  81. */
  82. uint32_t api_hal_subghz_set_frequency(uint32_t value);
  83. /** Set path
  84. * @param radio path to use
  85. */
  86. void api_hal_subghz_set_path(ApiHalSubGhzPath path);
  87. /** Signal Timings Capture callback */
  88. typedef void (*ApiHalSubGhzCaptureCallback)(bool level, uint32_t duration, void* context);
  89. /** Set signal timings capture callback
  90. * @param callback - your callback for front capture
  91. */
  92. void api_hal_subghz_set_capture_callback(ApiHalSubGhzCaptureCallback callback, void* context);
  93. /** Enable signal timings capture
  94. * Initializes GPIO and TIM2 for timings capture
  95. */
  96. void api_hal_subghz_enable_capture();
  97. /** Disable signal timings capture
  98. * Resets GPIO and TIM2
  99. */
  100. void api_hal_subghz_disable_capture();
  101. #ifdef __cplusplus
  102. }
  103. #endif