Subversion Repositories HomeAutomation

Rev

Rev 1871 | Rev 1904 | 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.     uint32_t data;
  24.     uint16_t timeout;
  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. #define IR_PROTOCOLS_USE_SIRC       1
  33. #define IR_PROTOCOLS_USE_RC5        1
  34. #define IR_PROTOCOLS_USE_SHARP      1
  35. #define IR_PROTOCOLS_USE_NEC        1
  36. #define IR_PROTOCOLS_USE_SAMSUNG    1
  37. #define IR_PROTOCOLS_USE_MARANTZ    1
  38. #define IR_PROTOCOLS_USE_PANASONIC  1
  39. #define IR_PROTOCOLS_USE_SKY        1
  40. #define IR_PROTOCOLS_USE_NEXA2      1
  41.  
  42. /* All these functions take a buffer with pulse times and tries to parse it
  43.  * to a Ir_Protocol_Data_t structure. They return IR_OK on success
  44.  * and IR_NOT_CORRECT_DATA if there was no match. */
  45. #if (IR_PROTOCOLS_USE_SIRC)
  46. int8_t parseSIRC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  47. #endif
  48. #if (IR_PROTOCOLS_USE_RC5)
  49. int8_t parseRC5(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  50. #endif
  51. #if (IR_PROTOCOLS_USE_SHARP)
  52. int8_t parseSharp(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  53. #endif
  54. #if (IR_PROTOCOLS_USE_NEC)
  55. int8_t parseNEC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  56. #endif
  57. #if (IR_PROTOCOLS_USE_SAMSUNG)
  58. int8_t parseSamsung(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  59. #endif
  60. #if (IR_PROTOCOLS_USE_MARANTZ)
  61. int8_t parseMarantz(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  62. #endif
  63. #if (IR_PROTOCOLS_USE_PANASONIC)
  64. int8_t parsePanasonic(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  65. #endif
  66. #if (IR_PROTOCOLS_USE_SKY)
  67. int8_t parseSky(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  68. #endif
  69. #if (IR_PROTOCOLS_USE_NEXA2)
  70. int8_t parseNexa2(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  71. #endif
  72.  
  73. /* Try to parse all above protocols until a match is found. */
  74. int8_t parseProtocol(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  75. /* The Hash protocol always succeeds and creates a one-way signature of the
  76.  * pulse times buffer that is supposed to be unique and constant for a specific
  77.  * IR event. It may be used to send a valid event even if the protocol hasn't
  78.  * been implemented or decoded yet. */
  79. int8_t parseHash(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  80.  
  81. /* These functions expand a Ir_Protocol_Data_t structure into a raw buffer with
  82.  * pulse lengths. They return IR_OK on success and IR_NOT_CORRECT_DATA if the
  83.  * Ir_Protocol_Data_t structure is for another protocol or contains invalid
  84.  * data. */
  85. int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  86. int8_t expandRC5(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  87. int8_t expandSharp(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  88. int8_t expandNEC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  89. int8_t expandSamsung(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  90. int8_t expandMarantz(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  91. int8_t expandPanasonic(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  92. int8_t expandSky(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  93. //int8_t expandNexa2(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  94. /* Pass the Ir_Protocol_Data_t automatically to the correct function. */
  95. int8_t expandProtocol(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  96.  
  97.  
  98. #define IR_OK               1
  99. #define IR_NO_PROTOCOL      2
  100. #define IR_TIME_OVFL        3
  101. #define IR_NO_DATA          4
  102. #define IR_NOT_CORRECT_DATA 5
  103. #define IR_TO_MUCH_DATA     6
  104. #define IR_NOT_FINISHED     7
  105.  
  106. #define IR_BUTTON_DOWN      0x0
  107. #define IR_BUTTON_UP        0xf
  108.  
  109. // defined for the module, uses same definitions for pressed and released as other buttons
  110. #define IR_BUTTON_RELEASED  0x0
  111. #define IR_BUTTON_PRESSED   0x1
  112.  
  113.  
  114. #define CYCLES_PER_US       (F_CPU/1000000UL)
  115. #define TIMER_PRESC         (8)
  116.  
  117. #define IR_MIN_PULSE_WIDTH  (0)                                 //us, not used in driver
  118.  
  119. #ifndef IR_MIN_STARTPULSE_WIDTH
  120. #define IR_MIN_STARTPULSE_WIDTH (0UL)                           //us, not used when set to 0
  121. #endif
  122. #ifndef IR_MAX_PULSE_WIDTH
  123. #define IR_MAX_PULSE_WIDTH  (12000UL)                           //us
  124. #endif
  125.  
  126. /* RC5 Implementation
  127.  * Receiver: DONE
  128.  * Transmitter: DONE
  129.  */
  130. #define IR_PROTO_RC5        (0)
  131. #define IR_RC5_HALF_BIT     (889*CYCLES_PER_US/TIMER_PRESC)     //us
  132. #define IR_RC5_BIT          (889*2*CYCLES_PER_US/TIMER_PRESC)   //us
  133. #define IR_RC5_TIMEOUT      (117-IR_MAX_PULSE_WIDTH/1000)       //ms    (time between ir frames)
  134. #define IR_RC5_REPS         (1)                                 //      (minimum number of times to repeat code)
  135. #define IR_RC5_F_MOD        (36)                                //kHz   (modulation frequency)
  136. #define IR_RC5_TOL_DIV      (4)
  137.  
  138. /* RC6 Implementation
  139.  * Receiver:
  140.  * Transmitter:
  141.  */
  142. #define IR_PROTO_RC6        (1)
  143. #define IR_RC6_ST_BIT       (1*CYCLES_PER_US/TIMER_PRESC)       //us
  144. #define IR_RC6_TIMEOUT      (50-IR_MAX_PULSE_WIDTH/1000)        //ms    (time between ir frames)
  145. #define IR_RC6_REPS         (1)                                 //      (minimum number of times to repeat code)
  146. #define IR_RC6_F_MOD        (36)                                //kHz   (modulation frequency)
  147. #define IR_RC6_TOL_DIV      (4)
  148.  
  149. /* RCMM Implementation
  150.  * Receiver:
  151.  * Transmitter:
  152.  */
  153. #define IR_PROTO_RCMM       (2)
  154. #define IR_RCMM_ST_BIT      (256*CYCLES_PER_US/TIMER_PRESC)     //us
  155. #define IR_RCMM_TIMEOUT     (170-IR_MAX_PULSE_WIDTH/1000)       //ms    (time between ir frames)
  156. #define IR_RCMM_REPS        (1)                                 //      (minimum number of times to repeat code)
  157. #define IR_RCMM_F_MOD       (36)                                //kHz   (modulation frequency)
  158. #define IR_RCMM_TOL_DIV     (4)
  159.  
  160. /* SIRC Implementation
  161.  * Receiver: DONE
  162.  * Transmitter: DONE
  163.  */
  164. #define IR_PROTO_SIRC       (3)
  165. #define IR_SIRC_ST_BIT      (2400*CYCLES_PER_US/TIMER_PRESC)    //us
  166. #define IR_SIRC_LOW         (600*CYCLES_PER_US/TIMER_PRESC)     //us
  167. #define IR_SIRC_HIGH_ONE    (1200*CYCLES_PER_US/TIMER_PRESC)    //us
  168. #define IR_SIRC_HIGH_ZERO   (600*CYCLES_PER_US/TIMER_PRESC)     //us
  169. #define IR_SIRC_TIMEOUT     (52-IR_MAX_PULSE_WIDTH/1000)                                    //ms    (time between ir frames)
  170. #define IR_SIRC_REPS        (3)                                 //      (minimum number of times to repeat code)
  171. #define IR_SIRC_F_MOD       (40)                                //kHz   (modulation frequency)
  172. #define IR_SIRC_TOL_DIV     (4)
  173.  
  174. /* Sharp Implementation
  175.  * Receiver: DONE
  176.  * Transmitter:
  177.  */
  178. #define IR_PROTO_SHARP      (4)
  179. #define IR_SHARP_HIGH       (280*CYCLES_PER_US/TIMER_PRESC)     //us
  180. #define IR_SHARP_LOW_ONE    (1850*CYCLES_PER_US/TIMER_PRESC)    //us
  181. #define IR_SHARP_LOW_ZERO   (780*CYCLES_PER_US/TIMER_PRESC)     //us
  182. #define IR_SHARP_TIMEOUT    (67-IR_MAX_PULSE_WIDTH/1000)        //ms    (time between ir frames)
  183. #define IR_SHARP_REPS       (2)                                 //      (minimum number of times to repeat code)
  184. #define IR_SHARP_F_MOD      (38)                                //kHz   (modulation frequency)
  185. #define IR_SHARP_TOL_DIV    (4)
  186.  
  187. /* NEC Implementation
  188.  * Receiver: DONE
  189.  * Transmitter: DONE
  190.  */
  191. #define IR_PROTO_NEC        (5)
  192. #define IR_NEC_ST_BIT       (9000*CYCLES_PER_US/TIMER_PRESC)    //us
  193. #define IR_NEC_ST_PAUSE     (4500*CYCLES_PER_US/TIMER_PRESC)    //us
  194. #define IR_NEC_LOW_ONE      (1690*CYCLES_PER_US/TIMER_PRESC)    //us
  195. #define IR_NEC_LOW_ZERO     (560*CYCLES_PER_US/TIMER_PRESC)     //us
  196. #define IR_NEC_HIGH         (560*CYCLES_PER_US/TIMER_PRESC)     //us
  197. #define IR_NEC_TIMEOUT      (122-IR_MAX_PULSE_WIDTH/1000)       //ms    (time between ir frames)
  198. #define IR_NEC_ST_TIMEOUT   (65)                                //ms    (time between first ir frames and second)
  199. #define IR_NEC_REPS         (1)                                 //      (minimum number of times to repeat code)
  200. #define IR_NEC_F_MOD        (38)                                //kHz   (modulation frequency)
  201. #define IR_NEC_TOL_DIV      (4)
  202.  
  203. /* Samsung Implementation
  204.  * Receiver: DONE
  205.  * Transmitter: DONE
  206.  */
  207. #define IR_PROTO_SAMS       (6)
  208. #define IR_SAMS_ST_BIT      (4500*CYCLES_PER_US/TIMER_PRESC)    //us
  209. #define IR_SAMS_ST_PAUSE    (4500*CYCLES_PER_US/TIMER_PRESC)    //us
  210. #define IR_SAMS_LOW_ONE     (1720*CYCLES_PER_US/TIMER_PRESC)    //us
  211. #define IR_SAMS_LOW_ZERO    (650*CYCLES_PER_US/TIMER_PRESC)     //us
  212. #define IR_SAMS_HIGH        (500*CYCLES_PER_US/TIMER_PRESC)     //us
  213. #define IR_SAMS_TIMEOUT     (62-IR_MAX_PULSE_WIDTH/1000)        //ms    (time between ir frames)
  214. #define IR_SAMS_REPS        (1)                                 //      (minimum number of times to repeat code)
  215. #define IR_SAMS_F_MOD       (38)                                //kHz   (modulation frequency)
  216. #define IR_SAMS_TOL_DIV     (4)
  217.  
  218. /* Marantz Implementation
  219.  * Receiver: DONE (has not been tested with odd adressbits)
  220.  * Transmitter: DONE
  221.  */
  222. #define IR_PROTO_MARANTZ        (7)
  223. #define IR_MARANTZ_HALF_BIT     (889*CYCLES_PER_US/TIMER_PRESC)     //us
  224. #define IR_MARANTZ_BIT          (889*2*CYCLES_PER_US/TIMER_PRESC)   //us
  225. #define IR_MARANTZ_TIMEOUT      (117-IR_MAX_PULSE_WIDTH/1000)       //ms    (time between ir frames)
  226. #define IR_MARANTZ_REPS         (1)                                 //      (minimum number of times to repeat code)
  227. #define IR_MARANTZ_F_MOD        (36)                                //kHz   (modulation frequency)
  228. #define IR_MARANTZ_TOL_DIV      (4)
  229.  
  230. /* Panasonic Implementation
  231.  * Receiver: DONE
  232.  * Transmitter: DONE
  233.  */
  234. #define IR_PROTO_PANASONIC  (8)
  235. #define IR_PANA_ST_BIT      (3570*CYCLES_PER_US/TIMER_PRESC)    //us
  236. #define IR_PANA_ST_PAUSE    (1630*CYCLES_PER_US/TIMER_PRESC)    //us
  237. #define IR_PANA_LOW_ONE     (1240*CYCLES_PER_US/TIMER_PRESC)    //us
  238. #define IR_PANA_LOW_ZERO    (400*CYCLES_PER_US/TIMER_PRESC)     //us
  239. #define IR_PANA_HIGH        (495*CYCLES_PER_US/TIMER_PRESC)     //us
  240. #define IR_PANA_TIMEOUT     (92-IR_MAX_PULSE_WIDTH/1000)        //ms    (time between ir frames)
  241. #define IR_PANA_REPS        (1)                                 //      (minimum number of times to repeat code)
  242. #define IR_PANA_F_MOD       (38)                                //kHz   (modulation frequency)
  243. #define IR_PANA_TOL_DIV     (4)
  244.  
  245. /* Sky Implementation
  246.  * Receiver: DONE
  247.  * Transmitter:
  248.  */
  249. #define IR_PROTO_SKY        (9)
  250. #define IR_SKY_ST_BIT       (2800*CYCLES_PER_US/TIMER_PRESC)    //us
  251. #define IR_SKY_SHORT        (460*CYCLES_PER_US/TIMER_PRESC)     //us
  252. #define IR_SKY_LONG         (920*CYCLES_PER_US/TIMER_PRESC)     //us
  253. #define IR_SKY_TIMEOUT      (162-IR_MAX_PULSE_WIDTH/1000)       //ms    (time between ir frames)
  254. #define IR_SKY_REPS         (1)                                 //      (minimum number of times to repeat code)
  255. #define IR_SKY_F_MOD        (38)                                //kHz   (modulation frequency)
  256. #define IR_SKY_TOL_DIV      (4)
  257.  
  258.  
  259. /* Nexa2 Implementation
  260.  * Receiver:
  261.  * Transmitter:
  262.  */
  263. #define IR_PROTO_NEXA2      (10)
  264. #define IR_NEXA2_START1     (10000*CYCLES_PER_US/TIMER_PRESC)   //us
  265. #define IR_NEXA2_START2     (2500*CYCLES_PER_US/TIMER_PRESC)    //us
  266. #define IR_NEXA2_HIGH       (320*CYCLES_PER_US/TIMER_PRESC)     //us
  267. #define IR_NEXA2_LOW_ONE    (210*CYCLES_PER_US/TIMER_PRESC)     //us
  268. #define IR_NEXA2_LOW_ZERO   (1200*CYCLES_PER_US/TIMER_PRESC)    //us
  269. #define IR_NEXA2_TIMEOUT    (5)                                 //ms    (time between ir frames)
  270. #define IR_NEXA2_REPS       (5)                                 //      (minimum number of times to repeat code)
  271. #define IR_NEXA2_F_MOD      (38)                                //kHz   (modulation frequency)
  272. #define IR_NEXA2_TOL_DIV    (2)
  273.  
  274.  
  275. #define IR_PROTO_HASH       0xfe
  276. #define IR_PROTO_UNKNOWN    0xff                                //
  277.  
  278.  
  279.  
  280. /**@}*/
  281. #endif /*IR_PROTOCOLS_H_*/
  282.