Subversion Repositories HomeAutomation

Rev

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