furi_hal_infrared.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * @file furi_hal_infrared.h
  3. * INFRARED HAL API
  4. */
  5. #pragma once
  6. #include <stdint.h>
  7. #include <stdbool.h>
  8. #include <stddef.h>
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #define INFRARED_MAX_FREQUENCY 56000
  13. #define INFRARED_MIN_FREQUENCY 10000
  14. typedef enum {
  15. FuriHalInfraredTxGetDataStateOk, /**< New data obtained */
  16. FuriHalInfraredTxGetDataStateDone, /**< New data obtained, and this is end of package */
  17. FuriHalInfraredTxGetDataStateLastDone, /**< New data obtained, and this is end of package and no more data available */
  18. } FuriHalInfraredTxGetDataState;
  19. /** Callback type for providing data to INFRARED DMA TX system. It is called every tim */
  20. typedef FuriHalInfraredTxGetDataState (
  21. *FuriHalInfraredTxGetDataISRCallback)(void* context, uint32_t* duration, bool* level);
  22. /** Callback type called every time signal is sent by DMA to Timer.
  23. *
  24. * Actually, it means there are 2 timings left to send for this signal, which is
  25. * almost end. Don't use this callback to stop transmission, as far as there are
  26. * next signal is charged for transmission by DMA.
  27. */
  28. typedef void (*FuriHalInfraredTxSignalSentISRCallback)(void* context);
  29. /** Signature of callback function for receiving continuous INFRARED rx signal.
  30. *
  31. * @param ctx[in] context to pass to callback
  32. * @param level[in] level of input INFRARED rx signal
  33. * @param duration[in] duration of continuous rx signal level in us
  34. */
  35. typedef void (*FuriHalInfraredRxCaptureCallback)(void* ctx, bool level, uint32_t duration);
  36. /** Signature of callback function for reaching silence timeout on INFRARED port.
  37. *
  38. * @param ctx[in] context to pass to callback
  39. */
  40. typedef void (*FuriHalInfraredRxTimeoutCallback)(void* ctx);
  41. /** Initialize INFRARED RX timer to receive interrupts.
  42. *
  43. * It provides interrupts for every RX-signal edge changing with its duration.
  44. */
  45. void furi_hal_infrared_async_rx_start(void);
  46. /** Deinitialize INFRARED RX interrupt.
  47. */
  48. void furi_hal_infrared_async_rx_stop(void);
  49. /** Setup hal for receiving silence timeout.
  50. *
  51. * Should be used with 'furi_hal_infrared_timeout_irq_set_callback()'.
  52. *
  53. * @param[in] timeout_us time to wait for silence on INFRARED port before
  54. * generating IRQ.
  55. */
  56. void furi_hal_infrared_async_rx_set_timeout(uint32_t timeout_us);
  57. /** Setup callback for previously initialized INFRARED RX interrupt.
  58. *
  59. * @param[in] callback callback to call when RX signal edge changing occurs
  60. * @param[in] ctx context for callback
  61. */
  62. void furi_hal_infrared_async_rx_set_capture_isr_callback(
  63. FuriHalInfraredRxCaptureCallback callback,
  64. void* ctx);
  65. /** Setup callback for reaching silence timeout on INFRARED port.
  66. *
  67. * Should setup hal with 'furi_hal_infrared_setup_rx_timeout_irq()' first.
  68. *
  69. * @param[in] callback callback for silence timeout
  70. * @param[in] ctx context to pass to callback
  71. */
  72. void furi_hal_infrared_async_rx_set_timeout_isr_callback(
  73. FuriHalInfraredRxTimeoutCallback callback,
  74. void* ctx);
  75. /** Check if INFRARED is in use now.
  76. *
  77. * @return true if INFRARED is busy, false otherwise.
  78. */
  79. bool furi_hal_infrared_is_busy(void);
  80. /** Set callback providing new data.
  81. *
  82. * This function has to be called before furi_hal_infrared_async_tx_start().
  83. *
  84. * @param[in] callback function to provide new data
  85. * @param[in] context context for callback
  86. */
  87. void furi_hal_infrared_async_tx_set_data_isr_callback(
  88. FuriHalInfraredTxGetDataISRCallback callback,
  89. void* context);
  90. /** Start IR asynchronous transmission.
  91. *
  92. * It can be stopped by 2 reasons:
  93. * 1. implicit call for furi_hal_infrared_async_tx_stop()
  94. * 2. callback can provide FuriHalInfraredTxGetDataStateLastDone response which
  95. * means no more data available for transmission.
  96. *
  97. * Any func (furi_hal_infrared_async_tx_stop() or
  98. * furi_hal_infrared_async_tx_wait_termination()) has to be called to wait end of
  99. * transmission and free resources.
  100. *
  101. * @param[in] freq frequency for PWM
  102. * @param[in] duty_cycle duty cycle for PWM
  103. */
  104. void furi_hal_infrared_async_tx_start(uint32_t freq, float duty_cycle);
  105. /** Stop IR asynchronous transmission and free resources.
  106. *
  107. * Transmission will stop as soon as transmission reaches end of package
  108. * (FuriHalInfraredTxGetDataStateDone or FuriHalInfraredTxGetDataStateLastDone).
  109. */
  110. void furi_hal_infrared_async_tx_stop(void);
  111. /** Wait for end of IR asynchronous transmission and free resources.
  112. *
  113. * Transmission will stop as soon as transmission reaches end of transmission
  114. * (FuriHalInfraredTxGetDataStateLastDone).
  115. */
  116. void furi_hal_infrared_async_tx_wait_termination(void);
  117. /** Set callback for end of signal transmission
  118. *
  119. * @param[in] callback function to call when signal is sent
  120. * @param[in] context context for callback
  121. */
  122. void furi_hal_infrared_async_tx_set_signal_sent_isr_callback(
  123. FuriHalInfraredTxSignalSentISRCallback callback,
  124. void* context);
  125. #ifdef __cplusplus
  126. }
  127. #endif