furi-hal-irda.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <stddef.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. typedef enum {
  9. FuriHalIrdaTxGetDataStateError, /* An error occured during transmission */
  10. FuriHalIrdaTxGetDataStateOk, /* New data obtained */
  11. FuriHalIrdaTxGetDataStateDone, /* New data obtained, and this is end of package */
  12. FuriHalIrdaTxGetDataStateLastDone, /* New data obtained, and this is end of package and no more data available */
  13. } FuriHalIrdaTxGetDataState;
  14. /* Callback type for providing data to IRDA DMA TX system. It is called every tim */
  15. typedef FuriHalIrdaTxGetDataState (*FuriHalIrdaTxGetDataISRCallback) (void* context, uint32_t* duration, bool* level);
  16. /* Callback type called every time signal is sent by DMA to Timer.
  17. * Actually, it means there are 2 timings left to send for this signal, which is almost end.
  18. * Don't use this callback to stop transmission, as far as there are next signal is
  19. * charged for transmission by DMA.
  20. */
  21. typedef void (*FuriHalIrdaTxSignalSentISRCallback) (void* context);
  22. /**
  23. * Signature of callback function for receiving continuous IRDA rx signal.
  24. *
  25. * @param ctx[in] - context to pass to callback
  26. * @param level[in] - level of input IRDA rx signal
  27. * @param duration[in] - duration of continuous rx signal level in us
  28. */
  29. typedef void (*FuriHalIrdaRxCaptureCallback)(void* ctx, bool level, uint32_t duration);
  30. /**
  31. * Signature of callback function for reaching silence timeout on IRDA port.
  32. *
  33. * @param ctx[in] - context to pass to callback
  34. */
  35. typedef void (*FuriHalIrdaRxTimeoutCallback)(void* ctx);
  36. /**
  37. * Initialize IRDA RX timer to receive interrupts.
  38. * It provides interrupts for every RX-signal edge changing
  39. * with its duration.
  40. */
  41. void furi_hal_irda_async_rx_start(void);
  42. /**
  43. * Deinitialize IRDA RX interrupt.
  44. */
  45. void furi_hal_irda_async_rx_stop(void);
  46. /** Setup hal for receiving silence timeout.
  47. * Should be used with 'furi_hal_irda_timeout_irq_set_callback()'.
  48. *
  49. * @param[in] timeout_us - time to wait for silence on IRDA port
  50. * before generating IRQ.
  51. */
  52. void furi_hal_irda_async_rx_set_timeout(uint32_t timeout_us);
  53. /** Setup callback for previously initialized IRDA RX interrupt.
  54. *
  55. * @param[in] callback - callback to call when RX signal edge changing occurs
  56. * @param[in] ctx - context for callback
  57. */
  58. void furi_hal_irda_async_rx_set_capture_isr_callback(FuriHalIrdaRxCaptureCallback callback, void *ctx);
  59. /**
  60. * Setup callback for reaching silence timeout on IRDA port.
  61. * Should setup hal with 'furi_hal_irda_setup_rx_timeout_irq()' first.
  62. *
  63. * @param[in] callback - callback for silence timeout
  64. * @param[in] ctx - context to pass to callback
  65. */
  66. void furi_hal_irda_async_rx_set_timeout_isr_callback(FuriHalIrdaRxTimeoutCallback callback, void *ctx);
  67. /**
  68. * Check if IRDA is in use now.
  69. * @return true - IRDA is busy, false otherwise.
  70. */
  71. bool furi_hal_irda_is_busy(void);
  72. /**
  73. * Set callback providing new data. This function has to be called
  74. * before furi_hal_irda_async_tx_start().
  75. *
  76. * @param[in] callback - function to provide new data
  77. * @param[in] context - context for callback
  78. */
  79. void furi_hal_irda_async_tx_set_data_isr_callback(FuriHalIrdaTxGetDataISRCallback callback, void* context);
  80. /**
  81. * Start IR asynchronous transmission. It can be stopped by 2 reasons:
  82. * 1) implicit call for furi_hal_irda_async_tx_stop()
  83. * 2) callback can provide FuriHalIrdaTxGetDataStateLastDone response
  84. * which means no more data available for transmission.
  85. *
  86. * Any func (furi_hal_irda_async_tx_stop() or
  87. * furi_hal_irda_async_tx_wait_termination()) has to be called to wait
  88. * end of transmission and free resources.
  89. *
  90. * @param[in] freq - frequency for PWM
  91. * @param[in] duty_cycle - duty cycle for PWM
  92. * @return true if transmission successfully started, false otherwise.
  93. * If start failed no need to free resources.
  94. */
  95. bool furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle);
  96. /**
  97. * Stop IR asynchronous transmission and free resources.
  98. * Transmission will stop as soon as transmission reaches end of
  99. * package (FuriHalIrdaTxGetDataStateDone or FuriHalIrdaTxGetDataStateLastDone).
  100. */
  101. void furi_hal_irda_async_tx_stop(void);
  102. /**
  103. * Wait for end of IR asynchronous transmission and free resources.
  104. * Transmission will stop as soon as transmission reaches end of
  105. * transmission (FuriHalIrdaTxGetDataStateLastDone).
  106. */
  107. void furi_hal_irda_async_tx_wait_termination(void);
  108. /**
  109. * Set callback for end of signal transmission
  110. *
  111. * @param[in] callback - function to call when signal is sent
  112. * @param[in] context - context for callback
  113. */
  114. void furi_hal_irda_async_tx_set_signal_sent_isr_callback(FuriHalIrdaTxSignalSentISRCallback callback, void* context);
  115. #ifdef __cplusplus
  116. }
  117. #endif