Subversion Repositories HomeAutomation

Rev

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

  1. #ifndef IR_PROTOCOLS_H_
  2. #define IR_PROTOCOLS_H_
  3. #include <stdio.h>
  4. #include <config.h>
  5.  
  6. /* Protocol data structure */
  7. typedef struct {
  8.     uint8_t protocol;
  9.     uint32_t data;
  10.     uint16_t timeout;
  11.     uint8_t repeats;
  12.     uint8_t modfreq;
  13. } Ir_Protocol_Data_t;
  14.  
  15. /* Which protocols to use. These should perhaps be configuration options
  16.  * (config.inc). Only applies to receiver right now */
  17. #define IR_PROTOCOLS_USE_SIRC       1
  18. #define IR_PROTOCOLS_USE_RC5        1
  19. #define IR_PROTOCOLS_USE_SHARP      1
  20. #define IR_PROTOCOLS_USE_NEC        1
  21. #define IR_PROTOCOLS_USE_SAMSUNG    1
  22.  
  23. /* All these functions take a buffer with pulse times and tries to parse it
  24.  * to a Ir_Protocol_Data_t structure. They return IR_OK on success
  25.  * and IR_NOT_CORRECT_DATA if there was no match. */
  26. #if (IR_PROTOCOLS_USE_SIRC)
  27. int8_t parseSIRC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  28. #endif
  29. #if (IR_PROTOCOLS_USE_RC5)
  30. int8_t parseRC5(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  31. #endif
  32. #if (IR_PROTOCOLS_USE_SHARP)
  33. int8_t parseSharp(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  34. #endif
  35. #if (IR_PROTOCOLS_USE_NEC)
  36. int8_t parseNEC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  37. #endif
  38. #if (IR_PROTOCOLS_USE_SAMSUNG)
  39. int8_t parseSamsung(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  40. #endif
  41. /* Try to parse all above protocols until a match is found. */
  42. int8_t parseProtocol(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  43. /* The Hash protocol always succeeds and creates a one-way signature of the
  44.  * pulse times buffer that is supposed to be unique and constant for a specific
  45.  * IR event. It may be used to send a valid event even if the protocol hasn't
  46.  * been implemented or decoded yet. */
  47. int8_t parseHash(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto);
  48.  
  49. /* These functions expand a Ir_Protocol_Data_t structure into a raw buffer with
  50.  * pulse lengths. They return IR_OK on success and IR_NOT_CORRECT_DATA if the
  51.  * Ir_Protocol_Data_t structure is for another protocol or contains invalid
  52.  * data. */
  53. int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  54. int8_t expandRC5(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  55. int8_t expandSharp(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  56. int8_t expandNEC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  57. int8_t expandSamsung(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  58. /* Pass the Ir_Protocol_Data_t automatically to the correct function. */
  59. int8_t expandProtocol(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto);
  60.  
  61.  
  62. #define IR_OK               1
  63. #define IR_NO_PROTOCOL      2
  64. #define IR_TIME_OVFL        3
  65. #define IR_NO_DATA          4
  66. #define IR_NOT_CORRECT_DATA 5
  67. #define IR_TO_MUCH_DATA     6
  68. #define IR_NOT_FINISHED     7
  69.  
  70. #define IR_BUTTON_DOWN      0x0
  71. #define IR_BUTTON_UP        0xf
  72.  
  73. #define CYCLES_PER_US       (F_CPU/1000000)
  74. #define TIMER_PRESC         8
  75.  
  76. #define IR_MIN_PULSE_WIDTH  5                                   //us
  77. #define IR_MAX_PULSE_WIDTH  12000                               //us
  78.  
  79. /* RC5 Implementation
  80.  * Receiver: DONE
  81.  * Transmitter:
  82.  */
  83. #define IR_PROTO_RC5        0
  84. #define IR_RC5_HALF_BIT     889*CYCLES_PER_US/TIMER_PRESC       //us
  85. #define IR_RC5_BIT          889*2*CYCLES_PER_US/TIMER_PRESC     //us
  86. #define IR_RC5_TIMEOUT      105                                 //ms    (time between ir frames)
  87. #define IR_RC5_REPS         1                                   //      (minimum number of times to repeat code)
  88. #define IR_RC5_F_MOD        36                                  //kHz   (modulation frequency)
  89. #define IR_RC5_TOL_DIV      4
  90.  
  91. /* RC6 Implementation
  92.  * Receiver:
  93.  * Transmitter:
  94.  */
  95. #define IR_PROTO_RC6        1
  96. #define IR_RC6_ST_BIT       1*CYCLES_PER_US/TIMER_PRESC         //us
  97. #define IR_RC6_TIMEOUT      1                                   //ms    (time between ir frames)
  98. #define IR_RC6_REPS         1                                   //      (minimum number of times to repeat code)
  99. #define IR_RC6_F_MOD        36                                  //kHz   (modulation frequency)
  100. #define IR_RC6_TOL_DIV      4
  101.  
  102. /* RCMM Implementation
  103.  * Receiver:
  104.  * Transmitter:
  105.  */
  106. #define IR_PROTO_RCMM       2
  107. #define IR_RCMM_ST_BIT      256*CYCLES_PER_US/TIMER_PRESC       //us
  108. #define IR_RCMM_TIMEOUT     158                                 //ms    (time between ir frames)
  109. #define IR_RCMM_REPS        1                                   //      (minimum number of times to repeat code)
  110. #define IR_RCMM_F_MOD       36                                  //kHz   (modulation frequency)
  111. #define IR_RCMM_TOL_DIV     4
  112.  
  113. /* SIRC Implementation
  114.  * Receiver: DONE
  115.  * Transmitter:
  116.  */
  117. #define IR_PROTO_SIRC       3
  118. #define IR_SIRC_ST_BIT      2400*CYCLES_PER_US/TIMER_PRESC      //us
  119. #define IR_SIRC_LOW         600*CYCLES_PER_US/TIMER_PRESC       //us
  120. #define IR_SIRC_HIGH_ONE    1200*CYCLES_PER_US/TIMER_PRESC      //us
  121. #define IR_SIRC_HIGH_ZERO   600*CYCLES_PER_US/TIMER_PRESC       //us
  122. #define IR_SIRC_TIMEOUT     40                                  //ms    (time between ir frames)
  123. #define IR_SIRC_REPS        1                                   //      (minimum number of times to repeat code)
  124. #define IR_SIRC_F_MOD       40                                  //kHz   (modulation frequency)
  125. #define IR_SIRC_TOL_DIV     4
  126.  
  127. /* Sharp Implementation
  128.  * Receiver: DONE
  129.  * Transmitter:
  130.  */
  131. #define IR_PROTO_SHARP      4
  132. #define IR_SHARP_HIGH       280*CYCLES_PER_US/TIMER_PRESC       //us
  133. #define IR_SHARP_LOW_ONE    1850*CYCLES_PER_US/TIMER_PRESC      //us
  134. #define IR_SHARP_LOW_ZERO   780*CYCLES_PER_US/TIMER_PRESC       //us
  135. #define IR_SHARP_TIMEOUT    55                                  //ms    (time between ir frames)
  136. #define IR_SHARP_REPS       2                                   //      (minimum number of times to repeat code)
  137. #define IR_SHARP_F_MOD      38                                  //kHz   (modulation frequency)
  138. #define IR_SHARP_TOL_DIV    4
  139.  
  140. /* NEC Implementation
  141.  * Receiver: DONE
  142.  * Transmitter: DONE
  143.  */
  144. #define IR_PROTO_NEC        5
  145. #define IR_NEC_ST_BIT       9000*CYCLES_PER_US/TIMER_PRESC      //us
  146. #define IR_NEC_ST_PAUSE     4500*CYCLES_PER_US/TIMER_PRESC      //us
  147. #define IR_NEC_LOW_ONE      1690*CYCLES_PER_US/TIMER_PRESC      //us
  148. #define IR_NEC_LOW_ZERO     560*CYCLES_PER_US/TIMER_PRESC       //us
  149. #define IR_NEC_HIGH         560*CYCLES_PER_US/TIMER_PRESC       //us
  150. #define IR_NEC_TIMEOUT      110                                 //ms    (time between ir frames)
  151. #define IR_NEC_REPS         1                                   //      (minimum number of times to repeat code)
  152. #define IR_NEC_F_MOD        38                                  //kHz   (modulation frequency)
  153. #define IR_NEC_TOL_DIV      4
  154.  
  155. /* Samsung Implementation
  156.  * Receiver: DONE
  157.  * Transmitter: DONE
  158.  */
  159. #define IR_PROTO_SAMS       6
  160. #define IR_SAMS_ST_BIT      4500*CYCLES_PER_US/TIMER_PRESC      //us
  161. #define IR_SAMS_ST_PAUSE    4500*CYCLES_PER_US/TIMER_PRESC      //us
  162. #define IR_SAMS_LOW_ONE     1720*CYCLES_PER_US/TIMER_PRESC      //us
  163. #define IR_SAMS_LOW_ZERO    650*CYCLES_PER_US/TIMER_PRESC       //us
  164. #define IR_SAMS_HIGH        500*CYCLES_PER_US/TIMER_PRESC       //us
  165. #define IR_SAMS_TIMEOUT 50                                  //ms    (time between ir frames)
  166. #define IR_SAMS_REPS        1                                   //      (minimum number of times to repeat code)
  167. #define IR_SAMS_F_MOD       38                                  //kHz   (modulation frequency)
  168. #define IR_SAMS_TOL_DIV     4
  169.  
  170. #define IR_PROTO_HASH       0xfe
  171. #define IR_PROTO_UNKNOWN    0xff                                //
  172.  
  173.  
  174. #endif /*IR_PROTOCOLS_H_*/
  175.