Subversion Repositories HomeAutomation

Rev

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