api-hal-irda.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. ApiHalIrdaTxGetDataStateError, /* An error occured during transmission */
  10. ApiHalIrdaTxGetDataStateOk, /* New data obtained */
  11. ApiHalIrdaTxGetDataStateDone, /* New data obtained, and this is end of package */
  12. ApiHalIrdaTxGetDataStateLastDone, /* New data obtained, and this is end of package and no more data available */
  13. } ApiHalIrdaTxGetDataState;
  14. typedef ApiHalIrdaTxGetDataState (*ApiHalIrdaTxGetDataCallback) (void* context, uint32_t* duration, bool* level);
  15. /**
  16. * Signature of callback function for receiving continuous IRDA rx signal.
  17. *
  18. * @param ctx[in] - context to pass to callback
  19. * @param level[in] - level of input IRDA rx signal
  20. * @param duration[in] - duration of continuous rx signal level in us
  21. */
  22. typedef void (*ApiHalIrdaRxCaptureCallback)(void* ctx, bool level, uint32_t duration);
  23. /**
  24. * Signature of callback function for reaching silence timeout on IRDA port.
  25. *
  26. * @param ctx[in] - context to pass to callback
  27. */
  28. typedef void (*ApiHalIrdaRxTimeoutCallback)(void* ctx);
  29. /**
  30. * Initialize IRDA RX timer to receive interrupts.
  31. * It provides interrupts for every RX-signal edge changing
  32. * with its duration.
  33. */
  34. void api_hal_irda_async_rx_start(void);
  35. /**
  36. * Deinitialize IRDA RX interrupt.
  37. */
  38. void api_hal_irda_async_rx_stop(void);
  39. /** Setup api hal for receiving silence timeout.
  40. * Should be used with 'api_hal_irda_timeout_irq_set_callback()'.
  41. *
  42. * @param[in] timeout_ms - time to wait for silence on IRDA port
  43. * before generating IRQ.
  44. */
  45. void api_hal_irda_async_rx_set_timeout(uint32_t timeout_ms);
  46. /**
  47. * Setup callback for previously initialized IRDA RX interrupt.
  48. *
  49. * @param[in] callback - callback to call when RX signal edge changing occurs
  50. * @param[in] ctx - context for callback
  51. */
  52. void api_hal_irda_async_rx_set_capture_isr_callback(ApiHalIrdaRxCaptureCallback callback, void *ctx);
  53. /**
  54. * Setup callback for reaching silence timeout on IRDA port.
  55. * Should setup api hal with 'api_hal_irda_setup_rx_timeout_irq()' first.
  56. *
  57. * @param[in] callback - callback for silence timeout
  58. * @param[in] ctx - context to pass to callback
  59. */
  60. void api_hal_irda_async_rx_set_timeout_isr_callback(ApiHalIrdaRxTimeoutCallback callback, void *ctx);
  61. /**
  62. * Check if IRDA is in use now.
  63. * @return true - IRDA is busy, false otherwise.
  64. */
  65. bool api_hal_irda_is_busy(void);
  66. /**
  67. * Set callback providing new data. This function has to be called
  68. * before api_hal_irda_async_tx_start().
  69. *
  70. * @param[in] callback - function to provide new data
  71. * @param[in] context - context for callback
  72. */
  73. void api_hal_irda_async_tx_set_data_isr_callback(ApiHalIrdaTxGetDataCallback callback, void* context);
  74. /**
  75. * Start IR asynchronous transmission. It can be stopped by 2 reasons:
  76. * 1) implicit call for api_hal_irda_async_tx_stop()
  77. * 2) callback can provide ApiHalIrdaTxGetDataStateLastDone response
  78. * which means no more data available for transmission.
  79. *
  80. * Any func (api_hal_irda_async_tx_stop() or
  81. * api_hal_irda_async_tx_wait_termination()) has to be called to wait
  82. * end of transmission and free resources.
  83. *
  84. * @param[in] freq - frequency for PWM
  85. * @param[in] duty_cycle - duty cycle for PWM
  86. * @return true if transmission successfully started, false otherwise.
  87. * If start failed no need to free resources.
  88. */
  89. bool api_hal_irda_async_tx_start(uint32_t freq, float duty_cycle);
  90. /**
  91. * Stop IR asynchronous transmission and free resources.
  92. * Transmission will stop as soon as transmission reaches end of
  93. * package (ApiHalIrdaTxGetDataStateDone or ApiHalIrdaTxGetDataStateLastDone).
  94. */
  95. void api_hal_irda_async_tx_stop(void);
  96. /**
  97. * Wait for end of IR asynchronous transmission and free resources.
  98. * Transmission will stop as soon as transmission reaches end of
  99. * transmission (ApiHalIrdaTxGetDataStateLastDone).
  100. */
  101. void api_hal_irda_async_tx_wait_termination(void);
  102. #ifdef __cplusplus
  103. }
  104. #endif