Subversion Repositories HomeAutomation

Rev

Rev 533 | Blame | Last modification | View Log | SVN | RSS feed

  1. #ifndef IRCOMMON_H_
  2. #define IRCOMMON_H_
  3.  
  4. /*-----------------------------------------------------------------------------
  5.  * Includes
  6.  *---------------------------------------------------------------------------*/
  7. #include <stdio.h>
  8.  
  9. /*-----------------------------------------------------------------------------
  10.  * Defines
  11.  *---------------------------------------------------------------------------*/
  12.  
  13. #define IR_OK               1
  14. #define IR_NO_PROTOCOL      2
  15. #define IR_TIME_OVFL        3
  16. #define IR_NO_DATA          4
  17. #define IR_NOT_CORRECT_DATA 5
  18. #define IR_TO_MUCH_DATA     6
  19. #define IR_NOT_FINISHED     7
  20.  
  21. #define IR_BUTTON_DOWN      0x0
  22. #define IR_BUTTON_UP        0xf
  23.  
  24. #define CYCLES_PER_US       (F_CPU/1000000)
  25. #define TIMER_PRESC         8
  26.  
  27. #define IR_MIN_PULSE_WIDTH  5                                   //us
  28. #define IR_MAX_PULSE_WIDTH  12000                               //us
  29.  
  30. #define TIM_OVFL_RELOAD_VAL (65536-(IR_MAX_PULSE_WIDTH*CYCLES_PER_US/TIMER_PRESC))  //timeout of 12ms, no pulses may be longer than this
  31.  
  32. #define TIM_1MS_RELOAD_VAL (65536-(1000*CYCLES_PER_US/TIMER_PRESC))
  33.  
  34. /* RC5 Implementation
  35.  * Receiver: DONE
  36.  * Transmitter:
  37.  */
  38. #define IR_PROTO_RC5        0
  39. #define IR_RC5_HALF_BIT     889*CYCLES_PER_US/TIMER_PRESC       //us
  40. #define IR_RC5_BIT          889*2*CYCLES_PER_US/TIMER_PRESC     //us
  41. #define IR_RC5_REPETITION   105                                 //ms    (time between ir frames)
  42. #define IR_RC5_REPS         1                                   //      (minimum number of times to repeat code)
  43. #define IR_RC5_F_MOD        36                                  //kHz   (modulation frequency)
  44. #define IR_RC5_TOL_DIV      4
  45.  
  46. /* RC6 Implementation
  47.  * Receiver:
  48.  * Transmitter:
  49.  */
  50. #define IR_PROTO_RC6        1
  51. #define IR_RC6_ST_BIT       1*CYCLES_PER_US/TIMER_PRESC         //us
  52. #define IR_RC6_REPETITION   1                                   //ms    (time between ir frames)
  53. #define IR_RC6_REPS         1                                   //      (minimum number of times to repeat code)
  54. #define IR_RC6_F_MOD        36                                  //kHz   (modulation frequency)
  55. #define IR_RC6_TOL_DIV      4
  56.  
  57. /* RCMM Implementation
  58.  * Receiver:
  59.  * Transmitter:
  60.  */
  61. #define IR_PROTO_RCMM       2
  62. #define IR_RCMM_ST_BIT      256*CYCLES_PER_US/TIMER_PRESC       //us
  63. #define IR_RCMM_REPETITION 158                                  //ms    (time between ir frames)
  64. #define IR_RCMM_REPS        1                                   //      (minimum number of times to repeat code)
  65. #define IR_RCMM_F_MOD       36                                  //kHz   (modulation frequency)
  66. #define IR_RCMM_TOL_DIV     4
  67.  
  68. /* SIRC Implementation
  69.  * Receiver: DONE
  70.  * Transmitter:
  71.  */
  72. #define IR_PROTO_SIRC       3
  73. #define IR_SIRC_ST_BIT      2400*CYCLES_PER_US/TIMER_PRESC      //us
  74. #define IR_SIRC_LOW         600*CYCLES_PER_US/TIMER_PRESC       //us
  75. #define IR_SIRC_HIGH_ONE    1200*CYCLES_PER_US/TIMER_PRESC      //us
  76. #define IR_SIRC_HIGH_ZERO   600*CYCLES_PER_US/TIMER_PRESC       //us
  77. #define IR_SIRC_REPETITION  40                                  //ms    (time between ir frames)
  78. #define IR_SIRC_REPS        1                                   //      (minimum number of times to repeat code)
  79. #define IR_SIRC_F_MOD       40                                  //kHz   (modulation frequency)
  80. #define IR_SIRC_TOL_DIV     4
  81.  
  82. /* Sharp Implementation
  83.  * Receiver: DONE
  84.  * Transmitter:
  85.  */
  86. #define IR_PROTO_SHARP      4
  87. #define IR_SHARP_HIGH       280*CYCLES_PER_US/TIMER_PRESC       //us
  88. #define IR_SHARP_LOW_ONE    1850*CYCLES_PER_US/TIMER_PRESC      //us
  89. #define IR_SHARP_LOW_ZERO   780*CYCLES_PER_US/TIMER_PRESC       //us
  90. #define IR_SHARP_REPETITION 55                                  //ms    (time between ir frames)
  91. #define IR_SHARP_REPS       2                                   //      (minimum number of times to repeat code)
  92. #define IR_SHARP_F_MOD      38                                  //kHz   (modulation frequency)
  93. #define IR_SHARP_TOL_DIV    4
  94.  
  95. /* NEC Implementation
  96.  * Receiver: DONE
  97.  * Transmitter:
  98.  */
  99. #define IR_PROTO_NEC        5
  100. #define IR_NEC_ST_BIT       9000*CYCLES_PER_US/TIMER_PRESC      //us
  101. #define IR_NEC_ST_PAUSE     4500*CYCLES_PER_US/TIMER_PRESC      //us
  102. #define IR_NEC_LOW_ONE      1690*CYCLES_PER_US/TIMER_PRESC      //us
  103. #define IR_NEC_LOW_ZERO     560*CYCLES_PER_US/TIMER_PRESC       //us
  104. #define IR_NEC_HIGH         560*CYCLES_PER_US/TIMER_PRESC       //us
  105. #define IR_NEC_REPETITION   110                                 //ms    (time between ir frames)
  106. #define IR_NEC_REPS         1                                   //      (minimum number of times to repeat code)
  107. #define IR_NEC_F_MOD        38                                  //kHz   (modulation frequency)
  108. #define IR_NEC_TOL_DIV      4
  109.  
  110. /* Samsung Implementation
  111.  * Receiver: DONE
  112.  * Transmitter:
  113.  */
  114. #define IR_PROTO_SAMS       6
  115. #define IR_SAMS_ST_BIT      4500*CYCLES_PER_US/TIMER_PRESC      //us
  116. #define IR_SAMS_ST_PAUSE    4500*CYCLES_PER_US/TIMER_PRESC      //us
  117. #define IR_SAMS_LOW_ONE     1720*CYCLES_PER_US/TIMER_PRESC      //us
  118. #define IR_SAMS_LOW_ZERO    650*CYCLES_PER_US/TIMER_PRESC       //us
  119. #define IR_SAMS_HIGH        500*CYCLES_PER_US/TIMER_PRESC       //us
  120. #define IR_SAMS_REPETITION  50                                  //ms    (time between ir frames)
  121. #define IR_SAMS_REPS        1                                   //      (minimum number of times to repeat code)
  122. #define IR_SAMS_F_MOD       38                                  //kHz   (modulation frequency)
  123. #define IR_SAMS_TOL_DIV     4
  124.  
  125. #define IR_PROTO_UNKNOWN    0xff                                //
  126.  
  127. /*-----------------------------------------------------------------------------
  128.  * Public Function Prototypes
  129.  *---------------------------------------------------------------------------*/
  130.  
  131. void initTimer(void);
  132. uint8_t isTimerOvfl(void);
  133. uint16_t getTimerVal(void);
  134. void setTimerVal(uint16_t value);
  135.  
  136. #endif /*IRCOMMON_H_*/
  137.