Subversion Repositories HomeAutomation

Rev

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