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