Subversion Repositories HomeAutomation

Rev

Rev 2200 | Rev 2236 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /**
  2.  * @defgroup infrared IR Protocols Driver Library
  3.  * @code #include <drivers/ir/protocols.h> @endcode
  4.  *
  5.  * @brief  
  6.  *
  7.  *
  8.  * @author  Andreas Fritiofson, Anders Runeson
  9.  * @date    2007
  10.  */
  11.  
  12. /**@{*/
  13.  
  14.  
  15. #ifndef IR_PROTOCOLS_H_
  16. #define IR_PROTOCOLS_H_
  17. #include <stdio.h>
  18. #include <config.h>
  19.  
  20. /* Protocol data structure */
  21. typedef struct {
  22.     uint8_t protocol;
  23.     uint64_t data;
  24.     uint16_t timeout;       //Set to 0 to indicate burst protocol (only one pulse train is sent)
  25.     uint8_t repeats;
  26.     uint16_t modfreq;
  27.     uint8_t framecnt;
  28. } Ir_Protocol_Data_t;
  29.  
  30. /* Which protocols to use. These should perhaps be configuration options
  31.  * (config.inc). Only applies to receiver right now */
  32. #ifndef IR_PROTOCOLS_USE_SIRC
  33. # define IR_PROTOCOLS_USE_SIRC      1
  34. #endif
  35. #ifndef IR_PROTOCOLS_USE_RC5
  36. # define IR_PROTOCOLS_USE_RC5       1
  37. #endif
  38. #ifndef IR_PROTOCOLS_USE_SHARP
  39. # define IR_PROTOCOLS_USE_SHARP     1
  40. #endif
  41. #ifndef IR_PROTOCOLS_USE_NEC
  42. # define IR_PROTOCOLS_USE_NEC       1
  43. #endif
  44. #ifndef IR_PROTOCOLS_USE_SAMSUNG
  45. # define IR_PROTOCOLS_USE_SAMSUNG   1
  46. #endif
  47. #ifndef IR_PROTOCOLS_USE_MARANTZ
  48. # define IR_PROTOCOLS_USE_MARANTZ   1
  49. #endif
  50. #ifndef IR_PROTOCOLS_USE_PANASONIC
  51. # define IR_PROTOCOLS_USE_PANASONIC 1
  52. #endif
  53. #ifndef IR_PROTOCOLS_USE_SKY
  54. # define IR_PROTOCOLS_USE_SKY       1
  55. #endif
  56. #ifndef IR_PROTOCOLS_USE_NEXA2
  57. # define IR_PROTOCOLS_USE_NEXA2 1
  58. #endif
  59. #ifndef IR_PROTOCOLS_USE_NEXA1
  60. # define IR_PROTOCOLS_USE_NEXA1 1
  61. #endif
  62. #ifndef IR_PROTOCOLS_USE_VIKING
  63. # define IR_PROTOCOLS_USE_VIKING    1
  64. #endif
  65. #ifndef IR_PROTOCOLS_USE_VIKING_STEAK
  66. # define IR_PROTOCOLS_USE_VIKING_STEAK  1
  67. #endif
  68.  
  69. /* All these functions take a buffer with pulse times and tries to parse it
  70.  * to a Ir_Protocol_Data_t structure. They return IR_OK on success
  71.  * and IR_NOT_CORRECT_DATA if there was no match. */
  72. #if (IR_PROTOCOLS_USE_SIRC)
  73. int8_t parseSIRC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  74. #endif
  75. #if (IR_PROTOCOLS_USE_RC5)
  76. int8_t parseRC5(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  77. #endif
  78. #if (IR_PROTOCOLS_USE_SHARP)
  79. int8_t parseSharp(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  80. #endif
  81. #if (IR_PROTOCOLS_USE_NEC)
  82. int8_t parseNEC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  83. #endif
  84. #if (IR_PROTOCOLS_USE_SAMSUNG)
  85. int8_t parseSamsung(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  86. #endif
  87. #if (IR_PROTOCOLS_USE_MARANTZ)
  88. int8_t parseMarantz(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  89. #endif
  90. #if (IR_PROTOCOLS_USE_PANASONIC)
  91. int8_t parsePanasonic(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  92. #endif
  93. #if (IR_PROTOCOLS_USE_SKY)
  94. int8_t parseSky(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  95. #endif
  96.  
  97. /* RF protocols needs index parameter */
  98. #if (IR_PROTOCOLS_USE_NEXA2)
  99. int8_t parseNexa2(const uint16_t *buf, uint8_t len, uint8_t index, Ir_Protocol_Data_t *proto);
  100. #endif
  101. #if (IR_PROTOCOLS_USE_NEXA1)
  102. int8_t parseNexa1(const uint16_t *buf, uint8_t len, uint8_t index, Ir_Protocol_Data_t *proto);
  103. #endif
  104. #if (IR_PROTOCOLS_USE_VIKING)
  105. int8_t parseViking(const uint16_t *buf, uint8_t len, uint8_t index, Ir_Protocol_Data_t *proto);
  106. #endif
  107. #if (IR_PROTOCOLS_USE_VIKING_STEAK)
  108. int8_t parseVikingSteak(const uint16_t *buf, uint8_t len, uint8_t index, Ir_Protocol_Data_t *proto);
  109. #endif
  110.  
  111. /* Try to parse all above protocols until a match is found. */
  112. int8_t parseProtocol(const uint16_t *buf, uint8_t len, uint8_t index, Ir_Protocol_Data_t *proto);
  113. /* The Hash protocol always succeeds and creates a one-way signature of the
  114.  * pulse times buffer that is supposed to be unique and constant for a specific
  115.  * IR event. It may be used to send a valid event even if the protocol hasn't
  116.  * been implemented or decoded yet. */
  117. int8_t parseHash(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  118.  
  119. /* These functions expand a Ir_Protocol_Data_t structure into a raw buffer with
  120.  * pulse lengths. They return IR_OK on success and IR_NOT_CORRECT_DATA if the
  121.  * Ir_Protocol_Data_t structure is for another protocol or contains invalid
  122.  * data. */
  123. int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  124. int8_t expandRC5(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  125. int8_t expandSharp(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  126. int8_t expandNEC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  127. int8_t expandSamsung(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  128. int8_t expandMarantz(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  129. int8_t expandPanasonic(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  130. int8_t expandSky(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  131. int8_t expandNexa2(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  132. int8_t expandNexa1(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  133. /* Pass the Ir_Protocol_Data_t automatically to the correct function. */
  134. int8_t expandProtocol(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  135.  
  136.  
  137. #define IR_OK               1
  138. #define IR_NO_PROTOCOL      2
  139. #define IR_TIME_OVFL        3
  140. #define IR_NO_DATA          4
  141. #define IR_NOT_CORRECT_DATA 5
  142. #define IR_TO_MUCH_DATA     6
  143. #define IR_NOT_FINISHED     7
  144.  
  145. #define IR_BUTTON_DOWN      0x0
  146. #define IR_BUTTON_UP        0xf
  147.  
  148. // defined for the module, uses same definitions for pressed and released as other buttons
  149. #define IR_BUTTON_RELEASED  0x0
  150. #define IR_BUTTON_PRESSED   0x1
  151.  
  152.  
  153. #define CYCLES_PER_US       (F_CPU/1000000UL)
  154. #define TIMER_PRESC         (8)
  155.  
  156. #ifndef IR_MIN_PULSE_WIDTH
  157. #define IR_MIN_PULSE_WIDTH  (0)                                 //us, used in continuous mode
  158. #endif
  159. #ifndef IR_MIN_STARTPULSE_WIDTH
  160. #define IR_MIN_STARTPULSE_WIDTH (0UL)                           //us, not used when set to 0
  161. #endif
  162. #ifndef IR_MAX_PULSE_WIDTH
  163. #define IR_MAX_PULSE_WIDTH  (12000UL)                           //us
  164. #endif
  165.  
  166. /* RC5 Implementation
  167.  * Receiver: DONE
  168.  * Transmitter: DONE
  169.  */
  170. #define IR_PROTO_RC5        (0)
  171. #define IR_RC5_HALF_BIT     (889*CYCLES_PER_US/TIMER_PRESC)     //us
  172. #define IR_RC5_BIT          (889*2*CYCLES_PER_US/TIMER_PRESC)   //us
  173. #define IR_RC5_TIMEOUT      (117-IR_MAX_PULSE_WIDTH/1000)       //ms    (time between ir frames)
  174. #define IR_RC5_REPS         (1)                                 //      (minimum number of times to repeat code)
  175. #define IR_RC5_F_MOD        (36)                                //kHz   (modulation frequency)
  176. #define IR_RC5_TOL_DIV      (4)
  177.  
  178. /* RC6 Implementation
  179.  * Receiver:
  180.  * Transmitter:
  181.  */
  182. #define IR_PROTO_RC6        (1)
  183. #define IR_RC6_ST_BIT       (1*CYCLES_PER_US/TIMER_PRESC)       //us
  184. #define IR_RC6_TIMEOUT      (50-IR_MAX_PULSE_WIDTH/1000)        //ms    (time between ir frames)
  185. #define IR_RC6_REPS         (1)                                 //      (minimum number of times to repeat code)
  186. #define IR_RC6_F_MOD        (36)                                //kHz   (modulation frequency)
  187. #define IR_RC6_TOL_DIV      (4)
  188.  
  189. /* RCMM Implementation
  190.  * Receiver:
  191.  * Transmitter:
  192.  */
  193. #define IR_PROTO_RCMM       (2)
  194. #define IR_RCMM_ST_BIT      (256*CYCLES_PER_US/TIMER_PRESC)     //us
  195. #define IR_RCMM_TIMEOUT     (170-IR_MAX_PULSE_WIDTH/1000)       //ms    (time between ir frames)
  196. #define IR_RCMM_REPS        (1)                                 //      (minimum number of times to repeat code)
  197. #define IR_RCMM_F_MOD       (36)                                //kHz   (modulation frequency)
  198. #define IR_RCMM_TOL_DIV     (4)
  199.  
  200. /* SIRC Implementation
  201.  * Receiver: DONE
  202.  * Transmitter: DONE
  203.  */
  204. #define IR_PROTO_SIRC       (3)
  205. #define IR_SIRC_ST_BIT      (2400*CYCLES_PER_US/TIMER_PRESC)    //us
  206. #define IR_SIRC_LOW         (600*CYCLES_PER_US/TIMER_PRESC)     //us
  207. #define IR_SIRC_HIGH_ONE    (1200*CYCLES_PER_US/TIMER_PRESC)    //us
  208. #define IR_SIRC_HIGH_ZERO   (600*CYCLES_PER_US/TIMER_PRESC)     //us
  209. #define IR_SIRC_TIMEOUT     (52-IR_MAX_PULSE_WIDTH/1000)                                    //ms    (time between ir frames)
  210. #define IR_SIRC_REPS        (3)                                 //      (minimum number of times to repeat code)
  211. #define IR_SIRC_F_MOD       (40)                                //kHz   (modulation frequency)
  212. #define IR_SIRC_TOL_DIV     (4)
  213.  
  214. /* Sharp Implementation
  215.  * Receiver: DONE
  216.  * Transmitter:
  217.  */
  218. #define IR_PROTO_SHARP      (4)
  219. #define IR_SHARP_HIGH       (280*CYCLES_PER_US/TIMER_PRESC)     //us
  220. #define IR_SHARP_LOW_ONE    (1850*CYCLES_PER_US/TIMER_PRESC)    //us
  221. #define IR_SHARP_LOW_ZERO   (780*CYCLES_PER_US/TIMER_PRESC)     //us
  222. #define IR_SHARP_TIMEOUT    (67-IR_MAX_PULSE_WIDTH/1000)        //ms    (time between ir frames)
  223. #define IR_SHARP_REPS       (2)                                 //      (minimum number of times to repeat code)
  224. #define IR_SHARP_F_MOD      (38)                                //kHz   (modulation frequency)
  225. #define IR_SHARP_TOL_DIV    (4)
  226.  
  227. /* NEC Implementation
  228.  * Receiver: DONE
  229.  * Transmitter: DONE
  230.  */
  231. #define IR_PROTO_NEC        (5)
  232. #define IR_NEC_ST_BIT       (9000*CYCLES_PER_US/TIMER_PRESC)    //us
  233. #define IR_NEC_ST_PAUSE     (4500*CYCLES_PER_US/TIMER_PRESC)    //us
  234. #define IR_NEC_LOW_ONE      (1690*CYCLES_PER_US/TIMER_PRESC)    //us
  235. #define IR_NEC_LOW_ZERO     (560*CYCLES_PER_US/TIMER_PRESC)     //us
  236. #define IR_NEC_HIGH         (560*CYCLES_PER_US/TIMER_PRESC)     //us
  237. #define IR_NEC_TIMEOUT      (122-IR_MAX_PULSE_WIDTH/1000)       //ms    (time between ir frames)
  238. #define IR_NEC_ST_TIMEOUT   (65)                                //ms    (time between first ir frames and second)
  239. #define IR_NEC_REPS         (1)                                 //      (minimum number of times to repeat code)
  240. #define IR_NEC_F_MOD        (38)                                //kHz   (modulation frequency)
  241. #define IR_NEC_TOL_DIV      (4)
  242.  
  243. /* Samsung Implementation
  244.  * Receiver: DONE
  245.  * Transmitter: DONE
  246.  */
  247. #define IR_PROTO_SAMS       (6)
  248. #define IR_SAMS_ST_BIT      (4500*CYCLES_PER_US/TIMER_PRESC)    //us
  249. #define IR_SAMS_ST_PAUSE    (4500*CYCLES_PER_US/TIMER_PRESC)    //us
  250. #define IR_SAMS_LOW_ONE     (1720*CYCLES_PER_US/TIMER_PRESC)    //us
  251. #define IR_SAMS_LOW_ZERO    (650*CYCLES_PER_US/TIMER_PRESC)     //us
  252. #define IR_SAMS_HIGH        (500*CYCLES_PER_US/TIMER_PRESC)     //us
  253. #define IR_SAMS_TIMEOUT     (62-IR_MAX_PULSE_WIDTH/1000)        //ms    (time between ir frames)
  254. #define IR_SAMS_REPS        (1)                                 //      (minimum number of times to repeat code)
  255. #define IR_SAMS_F_MOD       (38)                                //kHz   (modulation frequency)
  256. #define IR_SAMS_TOL_DIV     (4)
  257.  
  258. /* Marantz Implementation
  259.  * Receiver: DONE (has not been tested with odd adressbits)
  260.  * Transmitter: DONE
  261.  */
  262. #define IR_PROTO_MARANTZ        (7)
  263. #define IR_MARANTZ_HALF_BIT     (889*CYCLES_PER_US/TIMER_PRESC)     //us
  264. #define IR_MARANTZ_BIT          (889*2*CYCLES_PER_US/TIMER_PRESC)   //us
  265. #define IR_MARANTZ_TIMEOUT      (117-IR_MAX_PULSE_WIDTH/1000)       //ms    (time between ir frames)
  266. #define IR_MARANTZ_REPS         (1)                                 //      (minimum number of times to repeat code)
  267. #define IR_MARANTZ_F_MOD        (36)                                //kHz   (modulation frequency)
  268. #define IR_MARANTZ_TOL_DIV      (4)
  269.  
  270. /* Panasonic Implementation
  271.  * Receiver: DONE
  272.  * Transmitter: DONE
  273.  */
  274. #define IR_PROTO_PANASONIC  (8)
  275. #define IR_PANA_ST_BIT      (3570*CYCLES_PER_US/TIMER_PRESC)    //us
  276. #define IR_PANA_ST_PAUSE    (1630*CYCLES_PER_US/TIMER_PRESC)    //us
  277. #define IR_PANA_LOW_ONE     (1240*CYCLES_PER_US/TIMER_PRESC)    //us
  278. #define IR_PANA_LOW_ZERO    (400*CYCLES_PER_US/TIMER_PRESC)     //us
  279. #define IR_PANA_HIGH        (495*CYCLES_PER_US/TIMER_PRESC)     //us
  280. #define IR_PANA_TIMEOUT     (92-IR_MAX_PULSE_WIDTH/1000)        //ms    (time between ir frames)
  281. #define IR_PANA_REPS        (1)                                 //      (minimum number of times to repeat code)
  282. #define IR_PANA_F_MOD       (38)                                //kHz   (modulation frequency)
  283. #define IR_PANA_TOL_DIV     (4)
  284.  
  285. /* Sky Implementation
  286.  * Receiver: DONE
  287.  * Transmitter:
  288.  */
  289. #define IR_PROTO_SKY        (9)
  290. #define IR_SKY_ST_BIT       (2800*CYCLES_PER_US/TIMER_PRESC)    //us
  291. #define IR_SKY_SHORT        (460*CYCLES_PER_US/TIMER_PRESC)     //us
  292. #define IR_SKY_LONG         (920*CYCLES_PER_US/TIMER_PRESC)     //us
  293. #define IR_SKY_TIMEOUT      (162-IR_MAX_PULSE_WIDTH/1000)       //ms    (time between ir frames)
  294. #define IR_SKY_REPS         (1)                                 //      (minimum number of times to repeat code)
  295. #define IR_SKY_F_MOD        (38)                                //kHz   (modulation frequency)
  296. #define IR_SKY_TOL_DIV      (4)
  297.  
  298.  
  299. /* Nexa2 Implementation
  300.  * Receiver: DONE
  301.  * Transmitter: DONE
  302.  */
  303. #define IR_PROTO_NEXA2      (10)
  304. #define IR_NEXA2_START1     (10000*CYCLES_PER_US/TIMER_PRESC)   //us
  305. #define IR_NEXA2_START2     (2500*CYCLES_PER_US/TIMER_PRESC)    //us
  306. #define IR_NEXA2_HIGH       (320*CYCLES_PER_US/TIMER_PRESC)     //us
  307. #define IR_NEXA2_LOW_ONE    (210*CYCLES_PER_US/TIMER_PRESC)     //us
  308. #define IR_NEXA2_LOW_ZERO   (1200*CYCLES_PER_US/TIMER_PRESC)    //us
  309. #define IR_NEXA2_TIMEOUT    (200)                               //ms    (time between ir frames)
  310. #define IR_NEXA2_REPS       (5)                                 //      (minimum number of times to repeat code)
  311. #define IR_NEXA2_F_MOD      (38)                                //kHz   (modulation frequency)
  312. #define IR_NEXA2_TOL_DIV    (2)
  313.  
  314.  
  315. /* Nexa1 Implementation
  316.  * Receiver: DONE
  317.  * Transmitter:
  318.  */
  319. #define IR_PROTO_NEXA1      (11)
  320. #define IR_NEXA1_START      (10000*CYCLES_PER_US/TIMER_PRESC)   //us
  321. #define IR_NEXA1_SHORT      (370*CYCLES_PER_US/TIMER_PRESC)     //us
  322. #define IR_NEXA1_LONG       (1050*CYCLES_PER_US/TIMER_PRESC)    //us
  323. #define IR_NEXA1_TIMEOUT    (200)                               //ms    (time between ir frames)
  324. #define IR_NEXA1_REPS       (4)                                 //      (minimum number of times to repeat code)
  325. #define IR_NEXA1_F_MOD      (38)                                //kHz   (modulation frequency)
  326. #define IR_NEXA1_TOL_DIV    (2)
  327.  
  328.  
  329. /* Viking Temperature sensor Implementation
  330.  * Receiver:
  331.  */
  332. #define IR_PROTO_VIKING     (12)
  333. #define IR_VIKING_LOW       (940*CYCLES_PER_US/TIMER_PRESC)     //us
  334. #define IR_VIKING_HIGH_ONE  (1483*CYCLES_PER_US/TIMER_PRESC)        //us
  335. #define IR_VIKING_HIGH_ZERO (550*CYCLES_PER_US/TIMER_PRESC) //us
  336. #define IR_VIKING_TIMEOUT   (0)                                 //ms BURST! (time between ir frames)
  337. #define IR_VIKING_REPS      (1)                                 //      (minimum number of times to repeat code)
  338. #define IR_VIKING_F_MOD     (38)                                //kHz   (modulation frequency)
  339. #define IR_VIKING_TOL_DIV   (3)
  340.  
  341. /* Viking Steak temperature sensor Implementation
  342.  * Receiver:
  343.  */
  344. #define IR_PROTO_VIKING_STEAK       (13)
  345. #define IR_VIKING_STEAK_HIGH        (700*CYCLES_PER_US/TIMER_PRESC)     //us
  346. #define IR_VIKING_STEAK_LOW_ONE (4000*CYCLES_PER_US/TIMER_PRESC)        //us
  347. #define IR_VIKING_STEAK_LOW_ZERO    (1700*CYCLES_PER_US/TIMER_PRESC)    //us
  348. #define IR_VIKING_STEAK_LOW_START   (7800*CYCLES_PER_US/TIMER_PRESC)        //us
  349. #define IR_VIKING_STEAK_TIMEOUT (0)                                 //ms BURST! (time between ir frames)
  350. #define IR_VIKING_STEAK_REPS        (1)                                 //      (minimum number of times to repeat code)
  351. #define IR_VIKING_STEAK_F_MOD       (38)                                //kHz   (modulation frequency)
  352. #define IR_VIKING_STEAK_TOL_DIV (2)
  353.  
  354. #define IR_PROTO_HASH       0xfe
  355. #define IR_PROTO_UNKNOWN    0xff                                //
  356.  
  357.  
  358.  
  359. /**@}*/
  360. #endif /*IR_PROTOCOLS_H_*/
  361.