irda_protocol_defs_i.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #pragma once
  2. #include <stddef.h>
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #include "irda.h"
  6. #include "common/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 up to period repeat repeat bit
  13. * mark space
  14. *
  15. * 9000 4500 32 bit + stop bit ...110000 9000 2250
  16. * __________ _ _ _ _ _ _ _ _ _ _ _ _ _ ___________ _
  17. * ____ __________ _ _ _ __ __ __ _ _ __ __ _ _ ________________ ____________ ___
  18. *
  19. ***************************************************************************************************/
  20. #define IRDA_NEC_PREAMBLE_MARK 9000
  21. #define IRDA_NEC_PREAMBLE_SPACE 4500
  22. #define IRDA_NEC_BIT1_MARK 560
  23. #define IRDA_NEC_BIT1_SPACE 1690
  24. #define IRDA_NEC_BIT0_MARK 560
  25. #define IRDA_NEC_BIT0_SPACE 560
  26. #define IRDA_NEC_REPEAT_PERIOD 110000
  27. #define IRDA_NEC_SILENCE IRDA_NEC_REPEAT_PERIOD
  28. #define IRDA_NEC_MIN_SPLIT_TIME IRDA_NEC_REPEAT_PAUSE_MIN
  29. #define IRDA_NEC_REPEAT_PAUSE_MIN 4000
  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 200 // us
  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_check_ready(void* decoder);
  39. IrdaMessage* irda_decoder_nec_decode(void* decoder, bool level, uint32_t duration);
  40. void* irda_encoder_nec_alloc(void);
  41. IrdaStatus irda_encoder_nec_encode(void* encoder_ptr, uint32_t* duration, bool* level);
  42. void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message);
  43. void irda_encoder_nec_free(void* encoder_ptr);
  44. bool irda_decoder_nec_interpret(IrdaCommonDecoder* decoder);
  45. IrdaStatus irda_decoder_nec_decode_repeat(IrdaCommonDecoder* decoder);
  46. IrdaStatus
  47. irda_encoder_nec_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level);
  48. const IrdaProtocolSpecification* irda_nec_get_spec(IrdaProtocol protocol);
  49. extern const IrdaCommonProtocolSpec protocol_nec;
  50. /***************************************************************************************************
  51. * SAMSUNG32 protocol description
  52. * https://www.mikrocontroller.net/articles/IRMP_-_english#SAMSUNG
  53. ****************************************************************************************************
  54. * Preamble Preamble Pulse Distance/Width Pause Preamble Preamble Bit1 Stop
  55. * mark space Modulation repeat repeat bit
  56. * mark space
  57. *
  58. * 4500 4500 32 bit + stop bit 40000/100000 4500 4500
  59. * __________ _ _ _ _ _ _ _ _ _ _ _ ___________ _ _
  60. * _ __________ __ _ __ __ __ _ _ __ __ _ ________________ ____________ ____ ___
  61. *
  62. ***************************************************************************************************/
  63. #define IRDA_SAMSUNG_PREAMBLE_MARK 4500
  64. #define IRDA_SAMSUNG_PREAMBLE_SPACE 4500
  65. #define IRDA_SAMSUNG_BIT1_MARK 550
  66. #define IRDA_SAMSUNG_BIT1_SPACE 1650
  67. #define IRDA_SAMSUNG_BIT0_MARK 550
  68. #define IRDA_SAMSUNG_BIT0_SPACE 550
  69. #define IRDA_SAMSUNG_REPEAT_PAUSE_MIN 30000
  70. #define IRDA_SAMSUNG_REPEAT_PAUSE1 46000
  71. #define IRDA_SAMSUNG_REPEAT_PAUSE2 97000
  72. /* Samsung silence have to be greater than REPEAT MAX
  73. * otherwise there can be problems during unit tests parsing
  74. * of some data. Real tolerances we don't know, but in real life
  75. * silence time should be greater than max repeat time. This is
  76. * because of similar preambule timings for repeat and first messages. */
  77. #define IRDA_SAMSUNG_MIN_SPLIT_TIME 5000
  78. #define IRDA_SAMSUNG_SILENCE 145000
  79. #define IRDA_SAMSUNG_REPEAT_PAUSE_MAX 140000
  80. #define IRDA_SAMSUNG_REPEAT_MARK 4500
  81. #define IRDA_SAMSUNG_REPEAT_SPACE 4500
  82. #define IRDA_SAMSUNG_PREAMBLE_TOLERANCE 200 // us
  83. #define IRDA_SAMSUNG_BIT_TOLERANCE 120 // us
  84. void* irda_decoder_samsung32_alloc(void);
  85. void irda_decoder_samsung32_reset(void* decoder);
  86. void irda_decoder_samsung32_free(void* decoder);
  87. IrdaMessage* irda_decoder_samsung32_check_ready(void* ctx);
  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(
  96. IrdaCommonEncoder* encoder,
  97. uint32_t* duration,
  98. bool* level);
  99. const IrdaProtocolSpecification* irda_samsung32_get_spec(IrdaProtocol protocol);
  100. extern const IrdaCommonProtocolSpec protocol_samsung32;
  101. /***************************************************************************************************
  102. * RC6 protocol description
  103. * https://www.mikrocontroller.net/articles/IRMP_-_english#RC6_.2B_RC6A
  104. ****************************************************************************************************
  105. * Preamble Manchester/biphase Silence
  106. * mark/space Modulation
  107. *
  108. * 2666 889 444/888 - bit (x2 for toggle bit) 2666
  109. *
  110. * ________ __ __ __ __ ____ __ __ __ __ __ __ __ __
  111. * _ _________ ____ __ __ ____ __ __ __ __ __ __ __ __ _______________
  112. * | 1 | 0 | 0 | 0 | 0 | ... | ... | |
  113. * s m2 m1 m0 T address (MSB) command (MSB)
  114. *
  115. * s - start bit (always 1)
  116. * m0-2 - mode (000 for RC6)
  117. * T - toggle bit, twice longer
  118. * address - 8 bit
  119. * command - 8 bit
  120. ***************************************************************************************************/
  121. #define IRDA_RC6_CARRIER_FREQUENCY 36000
  122. #define IRDA_RC6_DUTY_CYCLE 0.33
  123. #define IRDA_RC6_PREAMBLE_MARK 2666
  124. #define IRDA_RC6_PREAMBLE_SPACE 889
  125. #define IRDA_RC6_BIT 444 // half of time-quant for 1 bit
  126. #define IRDA_RC6_PREAMBLE_TOLERANCE 200 // us
  127. #define IRDA_RC6_BIT_TOLERANCE 120 // us
  128. /* protocol allows 2700 silence, but it is hard to send 1 message without repeat */
  129. #define IRDA_RC6_SILENCE (2700 * 10)
  130. #define IRDA_RC6_MIN_SPLIT_TIME 2700
  131. void* irda_decoder_rc6_alloc(void);
  132. void irda_decoder_rc6_reset(void* decoder);
  133. void irda_decoder_rc6_free(void* decoder);
  134. IrdaMessage* irda_decoder_rc6_check_ready(void* ctx);
  135. IrdaMessage* irda_decoder_rc6_decode(void* decoder, bool level, uint32_t duration);
  136. void* irda_encoder_rc6_alloc(void);
  137. void irda_encoder_rc6_reset(void* encoder_ptr, const IrdaMessage* message);
  138. void irda_encoder_rc6_free(void* decoder);
  139. IrdaStatus irda_encoder_rc6_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
  140. bool irda_decoder_rc6_interpret(IrdaCommonDecoder* decoder);
  141. IrdaStatus
  142. irda_decoder_rc6_decode_manchester(IrdaCommonDecoder* decoder, bool level, uint32_t timing);
  143. IrdaStatus irda_encoder_rc6_encode_manchester(
  144. IrdaCommonEncoder* encoder_ptr,
  145. uint32_t* duration,
  146. bool* polarity);
  147. const IrdaProtocolSpecification* irda_rc6_get_spec(IrdaProtocol protocol);
  148. extern const IrdaCommonProtocolSpec protocol_rc6;
  149. /***************************************************************************************************
  150. * RC5 protocol description
  151. * https://www.mikrocontroller.net/articles/IRMP_-_english#RC5_.2B_RC5X
  152. ****************************************************************************************************
  153. * Manchester/biphase
  154. * Modulation
  155. *
  156. * 888/1776 - bit (x2 for toggle bit)
  157. *
  158. * __ ____ __ __ __ __ __ __ __ __
  159. * __ __ ____ __ __ __ __ __ __ __ _
  160. * | 1 | 1 | 0 | ... | ... |
  161. * s si T address (MSB) command (MSB)
  162. *
  163. * Note: manchester starts from space timing, so it have to be handled properly
  164. * s - start bit (always 1)
  165. * si - RC5: start bit (always 1), RC5X - 7-th bit of address (in our case always 0)
  166. * T - toggle bit, change it's value every button press
  167. * address - 5 bit
  168. * command - 6/7 bit
  169. ***************************************************************************************************/
  170. #define IRDA_RC5_CARRIER_FREQUENCY 36000
  171. #define IRDA_RC5_DUTY_CYCLE 0.33
  172. #define IRDA_RC5_PREAMBLE_MARK 0
  173. #define IRDA_RC5_PREAMBLE_SPACE 0
  174. #define IRDA_RC5_BIT 888 // half of time-quant for 1 bit
  175. #define IRDA_RC5_PREAMBLE_TOLERANCE 200 // us
  176. #define IRDA_RC5_BIT_TOLERANCE 120 // us
  177. /* protocol allows 2700 silence, but it is hard to send 1 message without repeat */
  178. #define IRDA_RC5_SILENCE (2700 * 10)
  179. #define IRDA_RC5_MIN_SPLIT_TIME 2700
  180. void* irda_decoder_rc5_alloc(void);
  181. void irda_decoder_rc5_reset(void* decoder);
  182. void irda_decoder_rc5_free(void* decoder);
  183. IrdaMessage* irda_decoder_rc5_check_ready(void* ctx);
  184. IrdaMessage* irda_decoder_rc5_decode(void* decoder, bool level, uint32_t duration);
  185. void* irda_encoder_rc5_alloc(void);
  186. void irda_encoder_rc5_reset(void* encoder_ptr, const IrdaMessage* message);
  187. void irda_encoder_rc5_free(void* decoder);
  188. IrdaStatus irda_encoder_rc5_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
  189. bool irda_decoder_rc5_interpret(IrdaCommonDecoder* decoder);
  190. const IrdaProtocolSpecification* irda_rc5_get_spec(IrdaProtocol protocol);
  191. extern const IrdaCommonProtocolSpec protocol_rc5;
  192. /***************************************************************************************************
  193. * Sony SIRC protocol description
  194. * https://www.sbprojects.net/knowledge/ir/sirc.php
  195. * http://picprojects.org.uk/
  196. ****************************************************************************************************
  197. * Preamble Preamble Pulse Width Modulation Pause Entirely repeat
  198. * mark space up to period message..
  199. *
  200. * 2400 600 12/15/20 bits (600,1200) ...45000 2400 600
  201. * __________ _ _ _ _ _ _ _ _ _ _ _ _ _ __________ _ _
  202. * ____ __________ _ _ _ __ __ __ _ _ __ __ _ _ ____________________ __________ _
  203. * | command | address |
  204. * SIRC | 7b LSB | 5b LSB |
  205. * SIRC15 | 7b LSB | 8b LSB |
  206. * SIRC20 | 7b LSB | 13b LSB |
  207. *
  208. * No way to determine either next message is repeat or not,
  209. * so recognize only fact message received. Sony remotes always send at least 3 messages.
  210. * Assume 8 last extended bits for SIRC20 are address bits.
  211. ***************************************************************************************************/
  212. #define IRDA_SIRC_CARRIER_FREQUENCY 40000
  213. #define IRDA_SIRC_DUTY_CYCLE 0.33
  214. #define IRDA_SIRC_PREAMBLE_MARK 2400
  215. #define IRDA_SIRC_PREAMBLE_SPACE 600
  216. #define IRDA_SIRC_BIT1_MARK 1200
  217. #define IRDA_SIRC_BIT1_SPACE 600
  218. #define IRDA_SIRC_BIT0_MARK 600
  219. #define IRDA_SIRC_BIT0_SPACE 600
  220. #define IRDA_SIRC_PREAMBLE_TOLERANCE 200 // us
  221. #define IRDA_SIRC_BIT_TOLERANCE 120 // us
  222. #define IRDA_SIRC_SILENCE 10000
  223. #define IRDA_SIRC_MIN_SPLIT_TIME (IRDA_SIRC_SILENCE - 1000)
  224. #define IRDA_SIRC_REPEAT_PERIOD 45000
  225. void* irda_decoder_sirc_alloc(void);
  226. void irda_decoder_sirc_reset(void* decoder);
  227. IrdaMessage* irda_decoder_sirc_check_ready(void* decoder);
  228. uint32_t irda_decoder_sirc_get_timeout(void* decoder);
  229. void irda_decoder_sirc_free(void* decoder);
  230. IrdaMessage* irda_decoder_sirc_decode(void* decoder, bool level, uint32_t duration);
  231. void* irda_encoder_sirc_alloc(void);
  232. void irda_encoder_sirc_reset(void* encoder_ptr, const IrdaMessage* message);
  233. void irda_encoder_sirc_free(void* decoder);
  234. IrdaStatus irda_encoder_sirc_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
  235. bool irda_decoder_sirc_interpret(IrdaCommonDecoder* decoder);
  236. const IrdaProtocolSpecification* irda_sirc_get_spec(IrdaProtocol protocol);
  237. IrdaStatus
  238. irda_encoder_sirc_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level);
  239. extern const IrdaCommonProtocolSpec protocol_sirc;