irda_protocol_defs_i.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #pragma once
  2. #include <stddef.h>
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #include "irda.h"
  6. #include "irda_common_i.h"
  7. /***************************************************************************************************
  8. * NEC protocol description
  9. * https://radioparty.ru/manuals/encyclopedia/213-ircontrol?start=1
  10. ****************************************************************************************************
  11. * Preamble Preamble Pulse Distance/Width Pause Preamble Preamble Stop
  12. * mark space Modulation repeat repeat bit
  13. * mark space
  14. *
  15. * 9000 4500 32 bit + stop bit 40000/100000 9000 2250
  16. * __________ _ _ _ _ _ _ _ _ _ _ _ _ _ ___________ _
  17. * ____ __________ _ _ _ __ __ __ _ _ __ __ _ _ ________________ ____________ ___
  18. *
  19. ***************************************************************************************************/
  20. #define IRDA_NEC_PREAMBULE_MARK 9000
  21. #define IRDA_NEC_PREAMBULE_SPACE 4500
  22. #define IRDA_NEC_BIT1_MARK 560
  23. #define IRDA_NEC_BIT1_SPACE 1600
  24. #define IRDA_NEC_BIT0_MARK 560
  25. #define IRDA_NEC_BIT0_SPACE 560
  26. #define IRDA_NEC_REPEAT_PAUSE_MIN 30000
  27. #define IRDA_NEC_REPEAT_PAUSE1 46000
  28. #define IRDA_NEC_REPEAT_PAUSE2 97000
  29. #define IRDA_NEC_SILENCE IRDA_NEC_REPEAT_PAUSE2
  30. #define IRDA_NEC_REPEAT_PAUSE_MAX 150000
  31. #define IRDA_NEC_REPEAT_MARK 9000
  32. #define IRDA_NEC_REPEAT_SPACE 2250
  33. #define IRDA_NEC_PREAMBLE_TOLERANCE 0.07 // percents
  34. #define IRDA_NEC_BIT_TOLERANCE 120 // us
  35. void* irda_decoder_nec_alloc(void);
  36. void irda_decoder_nec_reset(void* decoder);
  37. void irda_decoder_nec_free(void* decoder);
  38. IrdaMessage* irda_decoder_nec_decode(void* decoder, bool level, uint32_t duration);
  39. void* irda_encoder_nec_alloc(void);
  40. IrdaStatus irda_encoder_nec_encode(void* encoder_ptr, uint32_t* duration, bool* level);
  41. void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message);
  42. void irda_encoder_nec_free(void* encoder_ptr);
  43. void* irda_decoder_necext_alloc(void);
  44. void* irda_encoder_necext_alloc(void);
  45. void irda_encoder_necext_reset(void* encoder_ptr, const IrdaMessage* message);
  46. bool irda_decoder_nec_interpret(IrdaCommonDecoder* decoder);
  47. bool irda_decoder_necext_interpret(IrdaCommonDecoder* decoder);
  48. IrdaStatus irda_decoder_nec_decode_repeat(IrdaCommonDecoder* decoder);
  49. IrdaStatus irda_encoder_nec_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level);
  50. extern const IrdaCommonProtocolSpec protocol_necext;
  51. extern const IrdaCommonProtocolSpec protocol_nec;
  52. /***************************************************************************************************
  53. * SAMSUNG32 protocol description
  54. * https://www.mikrocontroller.net/articles/IRMP_-_english#SAMSUNG
  55. ****************************************************************************************************
  56. * Preamble Preamble Pulse Distance/Width Pause Preamble Preamble Bit1 Stop
  57. * mark space Modulation repeat repeat bit
  58. * mark space
  59. *
  60. * 4500 4500 32 bit + stop bit 40000/100000 4500 4500
  61. * __________ _ _ _ _ _ _ _ _ _ _ _ ___________ _ _
  62. * _ __________ __ _ __ __ __ _ _ __ __ _ ________________ ____________ ____ ___
  63. *
  64. ***************************************************************************************************/
  65. #define IRDA_SAMSUNG_PREAMBULE_MARK 4500
  66. #define IRDA_SAMSUNG_PREAMBULE_SPACE 4500
  67. #define IRDA_SAMSUNG_BIT1_MARK 550
  68. #define IRDA_SAMSUNG_BIT1_SPACE 1650
  69. #define IRDA_SAMSUNG_BIT0_MARK 550
  70. #define IRDA_SAMSUNG_BIT0_SPACE 550
  71. #define IRDA_SAMSUNG_REPEAT_PAUSE_MIN 30000
  72. #define IRDA_SAMSUNG_REPEAT_PAUSE1 46000
  73. #define IRDA_SAMSUNG_REPEAT_PAUSE2 97000
  74. /* Samsung silence have to be greater than REPEAT MAX
  75. * otherwise there can be problems during unit tests parsing
  76. * of some data. Real tolerances we don't know, but in real life
  77. * silence time should be greater than max repeat time. This is
  78. * because of similar preambule timings for repeat and first messages. */
  79. #define IRDA_SAMSUNG_SILENCE 145000
  80. #define IRDA_SAMSUNG_REPEAT_PAUSE_MAX 140000
  81. #define IRDA_SAMSUNG_REPEAT_MARK 4500
  82. #define IRDA_SAMSUNG_REPEAT_SPACE 4500
  83. #define IRDA_SAMSUNG_PREAMBLE_TOLERANCE 0.07 // percents
  84. #define IRDA_SAMSUNG_BIT_TOLERANCE 120 // us
  85. void* irda_decoder_samsung32_alloc(void);
  86. void irda_decoder_samsung32_reset(void* decoder);
  87. void irda_decoder_samsung32_free(void* decoder);
  88. IrdaMessage* irda_decoder_samsung32_decode(void* decoder, bool level, uint32_t duration);
  89. IrdaStatus irda_encoder_samsung32_encode(void* encoder_ptr, uint32_t* duration, bool* level);
  90. void irda_encoder_samsung32_reset(void* encoder_ptr, const IrdaMessage* message);
  91. void* irda_encoder_samsung32_alloc(void);
  92. void irda_encoder_samsung32_free(void* encoder_ptr);
  93. bool irda_decoder_samsung32_interpret(IrdaCommonDecoder* decoder);
  94. IrdaStatus irda_decoder_samsung32_decode_repeat(IrdaCommonDecoder* decoder);
  95. IrdaStatus irda_encoder_samsung32_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level);
  96. extern const IrdaCommonProtocolSpec protocol_samsung32;
  97. /***************************************************************************************************
  98. * RC6 protocol description
  99. * https://www.mikrocontroller.net/articles/IRMP_-_english#RC6_.2B_RC6A
  100. ****************************************************************************************************
  101. * Preamble Manchester/biphase Silence
  102. * mark/space Modulation
  103. *
  104. * 2666 889 444/888 - bit (x2 for toggle bit) 2666
  105. *
  106. * ________ __ __ __ __ ____ __ __ __ __ __ __ __ __
  107. * _ _________ ____ __ __ ____ __ __ __ __ __ __ __ __ _______________
  108. * | 1 | 0 | 0 | 0 | 0 | ... | ... | |
  109. * s m2 m1 m0 T address (MSB) command (MSB)
  110. *
  111. * s - start bit (always 1)
  112. * m0-2 - mode (000 for RC6)
  113. * T - toggle bit, twice longer
  114. * address - 8 bit
  115. * command - 8 bit
  116. ***************************************************************************************************/
  117. #define IRDA_RC6_PREAMBULE_MARK 2666
  118. #define IRDA_RC6_PREAMBULE_SPACE 889
  119. #define IRDA_RC6_BIT 444 // half of time-quant for 1 bit
  120. #define IRDA_RC6_PREAMBLE_TOLERANCE 0.07 // percents
  121. #define IRDA_RC6_BIT_TOLERANCE 120 // us
  122. /* protocol allows 2700 silence, but it is hard to send 1 message without repeat */
  123. #define IRDA_RC6_SILENCE (2700 * 10)
  124. void* irda_decoder_rc6_alloc(void);
  125. void irda_decoder_rc6_reset(void* decoder);
  126. void irda_decoder_rc6_free(void* decoder);
  127. IrdaMessage* irda_decoder_rc6_decode(void* decoder, bool level, uint32_t duration);
  128. void* irda_encoder_rc6_alloc(void);
  129. void irda_encoder_rc6_reset(void* encoder_ptr, const IrdaMessage* message);
  130. void irda_encoder_rc6_free(void* decoder);
  131. IrdaStatus irda_encoder_rc6_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
  132. bool irda_decoder_rc6_interpret(IrdaCommonDecoder* decoder);
  133. IrdaStatus irda_decoder_rc6_decode_manchester(IrdaCommonDecoder* decoder);
  134. IrdaStatus irda_encoder_rc6_encode_manchester(IrdaCommonEncoder* encoder_ptr, uint32_t* duration, bool* polarity);
  135. extern const IrdaCommonProtocolSpec protocol_rc6;