infrared_protocol_defs_i.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. #pragma once
  2. #include <stddef.h>
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #include "infrared.h"
  6. #include "common/infrared_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 INFRARED_NEC_PREAMBLE_MARK 9000
  21. #define INFRARED_NEC_PREAMBLE_SPACE 4500
  22. #define INFRARED_NEC_BIT1_MARK 560
  23. #define INFRARED_NEC_BIT1_SPACE 1690
  24. #define INFRARED_NEC_BIT0_MARK 560
  25. #define INFRARED_NEC_BIT0_SPACE 560
  26. #define INFRARED_NEC_REPEAT_PERIOD 110000
  27. #define INFRARED_NEC_SILENCE INFRARED_NEC_REPEAT_PERIOD
  28. #define INFRARED_NEC_MIN_SPLIT_TIME INFRARED_NEC_REPEAT_PAUSE_MIN
  29. #define INFRARED_NEC_REPEAT_PAUSE_MIN 4000
  30. #define INFRARED_NEC_REPEAT_PAUSE_MAX 150000
  31. #define INFRARED_NEC_REPEAT_MARK 9000
  32. #define INFRARED_NEC_REPEAT_SPACE 2250
  33. #define INFRARED_NEC_PREAMBLE_TOLERANCE 200 // us
  34. #define INFRARED_NEC_BIT_TOLERANCE 120 // us
  35. void* infrared_decoder_nec_alloc(void);
  36. void infrared_decoder_nec_reset(void* decoder);
  37. void infrared_decoder_nec_free(void* decoder);
  38. InfraredMessage* infrared_decoder_nec_check_ready(void* decoder);
  39. InfraredMessage* infrared_decoder_nec_decode(void* decoder, bool level, uint32_t duration);
  40. void* infrared_encoder_nec_alloc(void);
  41. InfraredStatus infrared_encoder_nec_encode(void* encoder_ptr, uint32_t* duration, bool* level);
  42. void infrared_encoder_nec_reset(void* encoder_ptr, const InfraredMessage* message);
  43. void infrared_encoder_nec_free(void* encoder_ptr);
  44. bool infrared_decoder_nec_interpret(InfraredCommonDecoder* decoder);
  45. InfraredStatus infrared_decoder_nec_decode_repeat(InfraredCommonDecoder* decoder);
  46. InfraredStatus infrared_encoder_nec_encode_repeat(
  47. InfraredCommonEncoder* encoder,
  48. uint32_t* duration,
  49. bool* level);
  50. const InfraredProtocolSpecification* infrared_nec_get_spec(InfraredProtocol protocol);
  51. extern const InfraredCommonProtocolSpec 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 INFRARED_SAMSUNG_PREAMBLE_MARK 4500
  66. #define INFRARED_SAMSUNG_PREAMBLE_SPACE 4500
  67. #define INFRARED_SAMSUNG_BIT1_MARK 550
  68. #define INFRARED_SAMSUNG_BIT1_SPACE 1650
  69. #define INFRARED_SAMSUNG_BIT0_MARK 550
  70. #define INFRARED_SAMSUNG_BIT0_SPACE 550
  71. #define INFRARED_SAMSUNG_REPEAT_PAUSE_MIN 30000
  72. #define INFRARED_SAMSUNG_REPEAT_PAUSE1 46000
  73. #define INFRARED_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 INFRARED_SAMSUNG_MIN_SPLIT_TIME 5000
  80. #define INFRARED_SAMSUNG_SILENCE 145000
  81. #define INFRARED_SAMSUNG_REPEAT_PAUSE_MAX 140000
  82. #define INFRARED_SAMSUNG_REPEAT_MARK 4500
  83. #define INFRARED_SAMSUNG_REPEAT_SPACE 4500
  84. #define INFRARED_SAMSUNG_PREAMBLE_TOLERANCE 200 // us
  85. #define INFRARED_SAMSUNG_BIT_TOLERANCE 120 // us
  86. void* infrared_decoder_samsung32_alloc(void);
  87. void infrared_decoder_samsung32_reset(void* decoder);
  88. void infrared_decoder_samsung32_free(void* decoder);
  89. InfraredMessage* infrared_decoder_samsung32_check_ready(void* ctx);
  90. InfraredMessage* infrared_decoder_samsung32_decode(void* decoder, bool level, uint32_t duration);
  91. InfraredStatus
  92. infrared_encoder_samsung32_encode(void* encoder_ptr, uint32_t* duration, bool* level);
  93. void infrared_encoder_samsung32_reset(void* encoder_ptr, const InfraredMessage* message);
  94. void* infrared_encoder_samsung32_alloc(void);
  95. void infrared_encoder_samsung32_free(void* encoder_ptr);
  96. bool infrared_decoder_samsung32_interpret(InfraredCommonDecoder* decoder);
  97. InfraredStatus infrared_decoder_samsung32_decode_repeat(InfraredCommonDecoder* decoder);
  98. InfraredStatus infrared_encoder_samsung32_encode_repeat(
  99. InfraredCommonEncoder* encoder,
  100. uint32_t* duration,
  101. bool* level);
  102. const InfraredProtocolSpecification* infrared_samsung32_get_spec(InfraredProtocol protocol);
  103. extern const InfraredCommonProtocolSpec protocol_samsung32;
  104. /***************************************************************************************************
  105. * RC6 protocol description
  106. * https://www.mikrocontroller.net/articles/IRMP_-_english#RC6_.2B_RC6A
  107. ****************************************************************************************************
  108. * Preamble Manchester/biphase Silence
  109. * mark/space Modulation
  110. *
  111. * 2666 889 444/888 - bit (x2 for toggle bit) 2666
  112. *
  113. * ________ __ __ __ __ ____ __ __ __ __ __ __ __ __
  114. * _ _________ ____ __ __ ____ __ __ __ __ __ __ __ __ _______________
  115. * | 1 | 0 | 0 | 0 | 0 | ... | ... | |
  116. * s m2 m1 m0 T address (MSB) command (MSB)
  117. *
  118. * s - start bit (always 1)
  119. * m0-2 - mode (000 for RC6)
  120. * T - toggle bit, twice longer
  121. * address - 8 bit
  122. * command - 8 bit
  123. ***************************************************************************************************/
  124. #define INFRARED_RC6_CARRIER_FREQUENCY 36000
  125. #define INFRARED_RC6_DUTY_CYCLE 0.33
  126. #define INFRARED_RC6_PREAMBLE_MARK 2666
  127. #define INFRARED_RC6_PREAMBLE_SPACE 889
  128. #define INFRARED_RC6_BIT 444 // half of time-quant for 1 bit
  129. #define INFRARED_RC6_PREAMBLE_TOLERANCE 200 // us
  130. #define INFRARED_RC6_BIT_TOLERANCE 120 // us
  131. /* protocol allows 2700 silence, but it is hard to send 1 message without repeat */
  132. #define INFRARED_RC6_SILENCE (2700 * 10)
  133. #define INFRARED_RC6_MIN_SPLIT_TIME 2700
  134. void* infrared_decoder_rc6_alloc(void);
  135. void infrared_decoder_rc6_reset(void* decoder);
  136. void infrared_decoder_rc6_free(void* decoder);
  137. InfraredMessage* infrared_decoder_rc6_check_ready(void* ctx);
  138. InfraredMessage* infrared_decoder_rc6_decode(void* decoder, bool level, uint32_t duration);
  139. void* infrared_encoder_rc6_alloc(void);
  140. void infrared_encoder_rc6_reset(void* encoder_ptr, const InfraredMessage* message);
  141. void infrared_encoder_rc6_free(void* decoder);
  142. InfraredStatus infrared_encoder_rc6_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
  143. bool infrared_decoder_rc6_interpret(InfraredCommonDecoder* decoder);
  144. InfraredStatus infrared_decoder_rc6_decode_manchester(
  145. InfraredCommonDecoder* decoder,
  146. bool level,
  147. uint32_t timing);
  148. InfraredStatus infrared_encoder_rc6_encode_manchester(
  149. InfraredCommonEncoder* encoder_ptr,
  150. uint32_t* duration,
  151. bool* polarity);
  152. const InfraredProtocolSpecification* infrared_rc6_get_spec(InfraredProtocol protocol);
  153. extern const InfraredCommonProtocolSpec protocol_rc6;
  154. /***************************************************************************************************
  155. * RC5 protocol description
  156. * https://www.mikrocontroller.net/articles/IRMP_-_english#RC5_.2B_RC5X
  157. ****************************************************************************************************
  158. * Manchester/biphase
  159. * Modulation
  160. *
  161. * 888/1776 - bit (x2 for toggle bit)
  162. *
  163. * __ ____ __ __ __ __ __ __ __ __
  164. * __ __ ____ __ __ __ __ __ __ __ _
  165. * | 1 | 1 | 0 | ... | ... |
  166. * s si T address (MSB) command (MSB)
  167. *
  168. * Note: manchester starts from space timing, so it have to be handled properly
  169. * s - start bit (always 1)
  170. * si - RC5: start bit (always 1), RC5X - 7-th bit of address (in our case always 0)
  171. * T - toggle bit, change it's value every button press
  172. * address - 5 bit
  173. * command - 6/7 bit
  174. ***************************************************************************************************/
  175. #define INFRARED_RC5_CARRIER_FREQUENCY 36000
  176. #define INFRARED_RC5_DUTY_CYCLE 0.33
  177. #define INFRARED_RC5_PREAMBLE_MARK 0
  178. #define INFRARED_RC5_PREAMBLE_SPACE 0
  179. #define INFRARED_RC5_BIT 888 // half of time-quant for 1 bit
  180. #define INFRARED_RC5_PREAMBLE_TOLERANCE 200 // us
  181. #define INFRARED_RC5_BIT_TOLERANCE 120 // us
  182. /* protocol allows 2700 silence, but it is hard to send 1 message without repeat */
  183. #define INFRARED_RC5_SILENCE (2700 * 10)
  184. #define INFRARED_RC5_MIN_SPLIT_TIME 2700
  185. void* infrared_decoder_rc5_alloc(void);
  186. void infrared_decoder_rc5_reset(void* decoder);
  187. void infrared_decoder_rc5_free(void* decoder);
  188. InfraredMessage* infrared_decoder_rc5_check_ready(void* ctx);
  189. InfraredMessage* infrared_decoder_rc5_decode(void* decoder, bool level, uint32_t duration);
  190. void* infrared_encoder_rc5_alloc(void);
  191. void infrared_encoder_rc5_reset(void* encoder_ptr, const InfraredMessage* message);
  192. void infrared_encoder_rc5_free(void* decoder);
  193. InfraredStatus infrared_encoder_rc5_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
  194. bool infrared_decoder_rc5_interpret(InfraredCommonDecoder* decoder);
  195. const InfraredProtocolSpecification* infrared_rc5_get_spec(InfraredProtocol protocol);
  196. extern const InfraredCommonProtocolSpec protocol_rc5;
  197. /***************************************************************************************************
  198. * Sony SIRC protocol description
  199. * https://www.sbprojects.net/knowledge/ir/sirc.php
  200. * http://picprojects.org.uk/
  201. ****************************************************************************************************
  202. * Preamble Preamble Pulse Width Modulation Pause Entirely repeat
  203. * mark space up to period message..
  204. *
  205. * 2400 600 12/15/20 bits (600,1200) ...45000 2400 600
  206. * __________ _ _ _ _ _ _ _ _ _ _ _ _ _ __________ _ _
  207. * ____ __________ _ _ _ __ __ __ _ _ __ __ _ _ ____________________ __________ _
  208. * | command | address |
  209. * SIRC | 7b LSB | 5b LSB |
  210. * SIRC15 | 7b LSB | 8b LSB |
  211. * SIRC20 | 7b LSB | 13b LSB |
  212. *
  213. * No way to determine either next message is repeat or not,
  214. * so recognize only fact message received. Sony remotes always send at least 3 messages.
  215. * Assume 8 last extended bits for SIRC20 are address bits.
  216. ***************************************************************************************************/
  217. #define INFRARED_SIRC_CARRIER_FREQUENCY 40000
  218. #define INFRARED_SIRC_DUTY_CYCLE 0.33
  219. #define INFRARED_SIRC_PREAMBLE_MARK 2400
  220. #define INFRARED_SIRC_PREAMBLE_SPACE 600
  221. #define INFRARED_SIRC_BIT1_MARK 1200
  222. #define INFRARED_SIRC_BIT1_SPACE 600
  223. #define INFRARED_SIRC_BIT0_MARK 600
  224. #define INFRARED_SIRC_BIT0_SPACE 600
  225. #define INFRARED_SIRC_PREAMBLE_TOLERANCE 200 // us
  226. #define INFRARED_SIRC_BIT_TOLERANCE 120 // us
  227. #define INFRARED_SIRC_SILENCE 10000
  228. #define INFRARED_SIRC_MIN_SPLIT_TIME (INFRARED_SIRC_SILENCE - 1000)
  229. #define INFRARED_SIRC_REPEAT_PERIOD 45000
  230. void* infrared_decoder_sirc_alloc(void);
  231. void infrared_decoder_sirc_reset(void* decoder);
  232. InfraredMessage* infrared_decoder_sirc_check_ready(void* decoder);
  233. uint32_t infrared_decoder_sirc_get_timeout(void* decoder);
  234. void infrared_decoder_sirc_free(void* decoder);
  235. InfraredMessage* infrared_decoder_sirc_decode(void* decoder, bool level, uint32_t duration);
  236. void* infrared_encoder_sirc_alloc(void);
  237. void infrared_encoder_sirc_reset(void* encoder_ptr, const InfraredMessage* message);
  238. void infrared_encoder_sirc_free(void* decoder);
  239. InfraredStatus infrared_encoder_sirc_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
  240. bool infrared_decoder_sirc_interpret(InfraredCommonDecoder* decoder);
  241. const InfraredProtocolSpecification* infrared_sirc_get_spec(InfraredProtocol protocol);
  242. InfraredStatus infrared_encoder_sirc_encode_repeat(
  243. InfraredCommonEncoder* encoder,
  244. uint32_t* duration,
  245. bool* level);
  246. extern const InfraredCommonProtocolSpec protocol_sirc;
  247. /***************************************************************************************************
  248. * Kaseikyo protocol description
  249. * https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/ir_Kaseikyo.hpp
  250. ****************************************************************************************************
  251. * Preamble Preamble Pulse Distance/Width Pause Preamble Preamble
  252. * mark space Modulation up to period repeat repeat
  253. * mark space
  254. *
  255. * 3360 1665 48 bit ...130000 3456 1728
  256. * __________ _ _ _ _ _ _ _ _ _ _ _ _ _ ___________
  257. * ____ __________ _ _ _ __ __ __ _ _ __ __ _ _ ________________ ___________
  258. *
  259. ***************************************************************************************************/
  260. #define INFRARED_KASEIKYO_UNIT 432
  261. #define INFRARED_KASEIKYO_PREAMBLE_MARK (8 * INFRARED_KASEIKYO_UNIT)
  262. #define INFRARED_KASEIKYO_PREAMBLE_SPACE (4 * INFRARED_KASEIKYO_UNIT)
  263. #define INFRARED_KASEIKYO_BIT1_MARK INFRARED_KASEIKYO_UNIT
  264. #define INFRARED_KASEIKYO_BIT1_SPACE (3 * INFRARED_KASEIKYO_UNIT)
  265. #define INFRARED_KASEIKYO_BIT0_MARK INFRARED_KASEIKYO_UNIT
  266. #define INFRARED_KASEIKYO_BIT0_SPACE INFRARED_KASEIKYO_UNIT
  267. #define INFRARED_KASEIKYO_REPEAT_PERIOD 130000
  268. #define INFRARED_KASEIKYO_SILENCE INFRARED_KASEIKYO_REPEAT_PERIOD
  269. #define INFRARED_KASEIKYO_MIN_SPLIT_TIME INFRARED_KASEIKYO_REPEAT_PAUSE_MIN
  270. #define INFRARED_KASEIKYO_REPEAT_PAUSE_MIN 4000
  271. #define INFRARED_KASEIKYO_REPEAT_PAUSE_MAX 150000
  272. #define INFRARED_KASEIKYO_REPEAT_MARK INFRARED_KASEIKYO_PREAMBLE_MARK
  273. #define INFRARED_KASEIKYO_REPEAT_SPACE (INFRARED_KASEIKYO_REPEAT_PERIOD - 56000)
  274. #define INFRARED_KASEIKYO_PREAMBLE_TOLERANCE 200 // us
  275. #define INFRARED_KASEIKYO_BIT_TOLERANCE 120 // us
  276. void* infrared_decoder_kaseikyo_alloc(void);
  277. void infrared_decoder_kaseikyo_reset(void* decoder);
  278. void infrared_decoder_kaseikyo_free(void* decoder);
  279. InfraredMessage* infrared_decoder_kaseikyo_check_ready(void* decoder);
  280. InfraredMessage* infrared_decoder_kaseikyo_decode(void* decoder, bool level, uint32_t duration);
  281. void* infrared_encoder_kaseikyo_alloc(void);
  282. InfraredStatus
  283. infrared_encoder_kaseikyo_encode(void* encoder_ptr, uint32_t* duration, bool* level);
  284. void infrared_encoder_kaseikyo_reset(void* encoder_ptr, const InfraredMessage* message);
  285. void infrared_encoder_kaseikyo_free(void* encoder_ptr);
  286. bool infrared_decoder_kaseikyo_interpret(InfraredCommonDecoder* decoder);
  287. InfraredStatus infrared_decoder_kaseikyo_decode_repeat(InfraredCommonDecoder* decoder);
  288. InfraredStatus infrared_encoder_kaseikyo_encode_repeat(
  289. InfraredCommonEncoder* encoder,
  290. uint32_t* duration,
  291. bool* level);
  292. const InfraredProtocolSpecification* infrared_kaseikyo_get_spec(InfraredProtocol protocol);
  293. extern const InfraredCommonProtocolSpec protocol_kaseikyo;