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