irda.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef struct IrdaHandler IrdaHandler;
  8. // Do not change protocol order, as it can be saved into memory and fw update can be performed!
  9. typedef enum {
  10. IrdaProtocolSamsung32 = 0,
  11. IrdaProtocolNEC = 1,
  12. IrdaProtocolNECext = 2,
  13. } IrdaProtocol;
  14. typedef struct {
  15. IrdaProtocol protocol;
  16. uint32_t address;
  17. uint32_t command;
  18. bool repeat;
  19. } IrdaMessage;
  20. /**
  21. * Initialize decoder.
  22. *
  23. * \return returns pointer to IRDA decoder handler if success, otherwise - error.
  24. */
  25. IrdaHandler* irda_alloc_decoder(void);
  26. /**
  27. * Provide to decoder next timing. If message is ready, it returns decoded message,
  28. * otherwise NULL.
  29. *
  30. * \param[in] handler - handler to irda decoders. Should be aquired with \c irda_alloc_decoder().
  31. * \param[in] level - high(true) or low(false) level of input signal to analyze.
  32. * it should alternate every call, otherwise it is an error case,
  33. * and decoder resets its state and start decoding from the start.
  34. * \param[in] duration - duration of steady high/low input signal.
  35. * \return if message is ready, returns pointer to decoded message, returns NULL.
  36. */
  37. const IrdaMessage* irda_decode(IrdaHandler* handler, bool level, uint32_t duration);
  38. /**
  39. * Deinitialize decoder and free allocated memory.
  40. *
  41. * \param[in] handler - handler to irda decoders. Should be aquired with \c irda_alloc_decoder().
  42. */
  43. void irda_free_decoder(IrdaHandler* handler);
  44. /**
  45. * Reset IRDA decoder.
  46. *
  47. * \param[in] handler - handler to irda decoders. Should be aquired with \c irda_alloc_decoder().
  48. */
  49. void irda_reset_decoder(IrdaHandler* handler);
  50. /**
  51. * Send message over IRDA.
  52. *
  53. * \param[in] message - message to send.
  54. * \param[in] times - number of times message should be sent.
  55. */
  56. void irda_send(const IrdaMessage* message, int times);
  57. /**
  58. * Get protocol name by protocol enum.
  59. *
  60. * \param[in] protocol - protocol identifier.
  61. * \return string to protocol name.
  62. */
  63. const char* irda_get_protocol_name(IrdaProtocol protocol);
  64. /**
  65. * Get address length by protocol enum.
  66. *
  67. * \param[in] protocol - protocol identifier.
  68. * \return length of address in nibbles.
  69. */
  70. uint8_t irda_get_protocol_address_length(IrdaProtocol protocol);
  71. /**
  72. * Get command length by protocol enum.
  73. *
  74. * \param[in] protocol - protocol identifier.
  75. * \return length of command in nibbles.
  76. */
  77. uint8_t irda_get_protocol_command_length(IrdaProtocol protocol);
  78. #ifdef __cplusplus
  79. }
  80. #endif