]> cloudbase.mooo.com Git - irmp.git/blob - irmp.h
Version 1.3.1: corrected command bitmask for SAMSUNG32 protocol, added GRUNDIG protoc...
[irmp.git] / irmp.h
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * irmp.h
3 *
4 * Copyright (c) 2009-2010 Frank Meyer - frank(at)fli4l.de
5 *
6 * $Id: irmp.h,v 1.15 2010/05/17 10:31:43 fm Exp $
7 *
8 * ATMEGA88 @ 8 MHz
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *---------------------------------------------------------------------------------------------------------------------------------------------------
15 */
16
17 #ifndef _WC_IRMP_H_
18 #define _WC_IRMP_H_
19
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24
25 /*---------------------------------------------------------------------------------------------------------------------------------------------------
26 * IR protocols
27 *---------------------------------------------------------------------------------------------------------------------------------------------------
28 */
29 #define IRMP_SIRCS_PROTOCOL 1 // Sony
30 #define IRMP_NEC_PROTOCOL 2 // NEC, Pioneer, JVC, Toshiba, NoName etc.
31 #define IRMP_SAMSUNG_PROTOCOL 3 // Samsung
32 #define IRMP_MATSUSHITA_PROTOCOL 4 // Matsushita
33 #define IRMP_KASEIKYO_PROTOCOL 5 // Kaseikyo (Panasonic etc)
34 #define IRMP_RECS80_PROTOCOL 6 // Philips, Thomson, Nordmende, Telefunken, Saba
35 #define IRMP_RC5_PROTOCOL 7 // Philips etc
36 #define IRMP_DENON_PROTOCOL 8 // Denon
37 #define IRMP_RC6_PROTOCOL 9 // Philips etc
38 #define IRMP_SAMSUNG32_PROTOCOL 10 // Samsung32: no sync pulse at bit 16, length 32 instead of 37
39 #define IRMP_APPLE_PROTOCOL 11 // Apple, very similar to NEC
40 #define IRMP_RECS80EXT_PROTOCOL 12 // Philips, Technisat, Thomson, Nordmende, Telefunken, Saba
41 #define IRMP_NUBERT_PROTOCOL 13 // Nubert
42 #define IRMP_BANG_OLUFSEN_PROTOCOL 14 // Bang & Olufsen
43 #define IRMP_GRUNDIG_PROTOCOL 15 // Grundig
44
45 #define SIRCS_START_BIT_PULSE_TIME 2400.0e-6 // 2400 usec pulse
46 #define SIRCS_START_BIT_PAUSE_TIME 600.0e-6 // 600 usec pause
47 #define SIRCS_1_PULSE_TIME 1200.0e-6 // 1200 usec pulse
48 #define SIRCS_0_PULSE_TIME 600.0e-6 // 600 usec pulse
49 #define SIRCS_PAUSE_TIME 600.0e-6 // 600 usec pause
50 #define SIRCS_REPETITION_CNT 3 // SIRCS sends each frame 3 times
51 #define SIRCS_REPETITION_TIME 25.0e-3 // repetition after 25ms
52 #define SIRCS_ADDRESS_OFFSET 15 // skip 15 bits
53 #define SIRCS_ADDRESS_LEN 5 // read up to 5 address bits
54 #define SIRCS_COMMAND_OFFSET 0 // skip 0 bits
55 #define SIRCS_COMMAND_LEN 15 // read 12-15 command bits
56 #define SIRCS_MINIMUM_DATA_LEN 12 // minimum data length
57 #define SIRCS_COMPLETE_DATA_LEN 20 // complete length - may be up to 20
58 #define SIRCS_STOP_BIT 0 // has no stop bit
59 #define SIRCS_LSB 1 // LSB...MSB
60
61 #define NEC_START_BIT_PULSE_TIME 9000.0e-6 // 9000 usec pulse
62 #define NEC_START_BIT_PAUSE_TIME 4500.0e-6 // 4500 usec pause
63 #define NEC_REPEAT_START_BIT_PAUSE_TIME 2250.0e-6 // 2250 usec pause
64 #define NEC_PULSE_TIME 560.0e-6 // 560 usec pulse
65 #define NEC_1_PAUSE_TIME 1690.0e-6 // 1690 usec pause
66 #define NEC_0_PAUSE_TIME 560.0e-6 // 560 usec pause
67 #define NEC_ADDRESS_OFFSET 0 // skip 0 bits
68 #define NEC_ADDRESS_LEN 16 // read 16 address bits
69 #define NEC_COMMAND_OFFSET 16 // skip 16 bits (8 address + 8 /address)
70 #define NEC_COMMAND_LEN 16 // read 16 bits (8 command + 8 /command)
71 #define NEC_COMPLETE_DATA_LEN 32 // complete length
72 #define NEC_STOP_BIT 1 // has stop bit
73 #define NEC_LSB 1 // LSB...MSB
74
75 #define SAMSUNG_START_BIT_PULSE_TIME 4500.0e-6 // 4500 usec pulse
76 #define SAMSUNG_START_BIT_PAUSE_TIME 4500.0e-6 // 4500 usec pause
77 #define SAMSUNG_PULSE_TIME 550.0e-6 // 550 usec pulse
78 #define SAMSUNG_1_PAUSE_TIME 1450.0e-6 // 1450 usec pause
79 #define SAMSUNG_0_PAUSE_TIME 450.0e-6 // 450 usec pause
80 #define SAMSUNG_ADDRESS_OFFSET 0 // skip 0 bits
81 #define SAMSUNG_ADDRESS_LEN 16 // read 16 address bits
82 #define SAMSUNG_ID_OFFSET 17 // skip 16 + 1 sync bit
83 #define SAMSUNG_ID_LEN 4 // read 4 id bits
84 #define SAMSUNG_COMMAND_OFFSET 21 // skip 16 + 1 sync + 4 data bits
85 #define SAMSUNG_COMMAND_LEN 16 // read 16 command bits
86 #define SAMSUNG_COMPLETE_DATA_LEN 37 // complete length
87 #define SAMSUNG_STOP_BIT 1 // has stop bit
88 #define SAMSUNG_LSB 1 // LSB...MSB?
89
90 #define SAMSUNG32_COMMAND_OFFSET 16 // skip 16 bits
91 #define SAMSUNG32_COMMAND_LEN 16 // read 16 command bits
92 #define SAMSUNG32_COMPLETE_DATA_LEN 32 // complete length
93 #define SAMSUNG32_REPETITION_CNT 2 // SAMSUNG32 sends each frame 2 times
94 #define SAMSUNG32_REPETITION_TIME 47.0e-3 // repetition after 47 ms
95
96 #define MATSUSHITA_START_BIT_PULSE_TIME 3488.0e-6 // 3488 usec pulse
97 #define MATSUSHITA_START_BIT_PAUSE_TIME 3488.0e-6 // 3488 usec pause
98 #define MATSUSHITA_PULSE_TIME 872.0e-6 // 872 usec pulse
99 #define MATSUSHITA_1_PAUSE_TIME 2616.0e-6 // 2616 usec pause
100 #define MATSUSHITA_0_PAUSE_TIME 872.0e-6 // 872 usec pause
101 #define MATSUSHITA_ADDRESS_OFFSET 12 // skip 12 bits
102 #define MATSUSHITA_ADDRESS_LEN 12 // read 12 address bits
103 #define MATSUSHITA_COMMAND_OFFSET 0 // skip 0 bits
104 #define MATSUSHITA_COMMAND_LEN 12 // read 12 bits (6 custom + 6 command)
105 #define MATSUSHITA_COMPLETE_DATA_LEN 24 // complete length
106 #define MATSUSHITA_STOP_BIT 1 // has stop bit
107 #define MATSUSHITA_LSB 1 // LSB...MSB?
108
109 #define KASEIKYO_START_BIT_PULSE_TIME 3380.0e-6 // 3380 usec pulse
110 #define KASEIKYO_START_BIT_PAUSE_TIME 1690.0e-6 // 1690 usec pause
111 #define KASEIKYO_PULSE_TIME 423.0e-6 // 525 usec pulse
112 #define KASEIKYO_1_PAUSE_TIME 1269.0e-6 // 525 usec pause
113 #define KASEIKYO_0_PAUSE_TIME 423.0e-6 // 1690 usec pause
114 #define KASEIKYO_ADDRESS_OFFSET 0 // skip 0 bits
115 #define KASEIKYO_ADDRESS_LEN 16 // read 16 address bits
116 #define KASEIKYO_COMMAND_OFFSET 28 // skip 28 bits (16 manufacturer & 4 parity & 8 genre)
117 #define KASEIKYO_COMMAND_LEN 12 // read 12 command bits (10 real command & 2 id)
118 #define KASEIKYO_COMPLETE_DATA_LEN 48 // complete length
119 #define KASEIKYO_STOP_BIT 1 // has stop bit
120 #define KASEIKYO_LSB 1 // LSB...MSB?
121
122 #define RECS80_START_BIT_PULSE_TIME 158.0e-6 // 158 usec pulse
123 #define RECS80_START_BIT_PAUSE_TIME 7432.0e-6 // 7432 usec pause
124 #define RECS80_PULSE_TIME 158.0e-6 // 158 usec pulse
125 #define RECS80_1_PAUSE_TIME 7432.0e-6 // 7432 usec pause
126 #define RECS80_0_PAUSE_TIME 4902.0e-6 // 4902 usec pause
127 #define RECS80_ADDRESS_OFFSET 2 // skip 2 bits (2nd start + 1 toggle)
128 #define RECS80_ADDRESS_LEN 3 // read 3 address bits
129 #define RECS80_COMMAND_OFFSET 5 // skip 5 bits (2nd start + 1 toggle + 3 address)
130 #define RECS80_COMMAND_LEN 6 // read 6 command bits
131 #define RECS80_COMPLETE_DATA_LEN 11 // complete length
132 #define RECS80_STOP_BIT 1 // has stop bit
133 #define RECS80_LSB 0 // MSB...LSB
134
135 #define RC5_BIT_TIME 889.0e-6 // 889 usec pulse/pause
136 #define RC5_ADDRESS_OFFSET 2 // skip 2 bits (2nd start + 1 toggle)
137 #define RC5_ADDRESS_LEN 5 // read 5 address bits
138 #define RC5_COMMAND_OFFSET 7 // skip 5 bits (2nd start + 1 toggle + 5 address)
139 #define RC5_COMMAND_LEN 6 // read 6 command bits
140 #define RC5_COMPLETE_DATA_LEN 13 // complete length
141 #define RC5_STOP_BIT 0 // has no stop bit
142 #define RC5_LSB 0 // MSB...LSB
143
144 #define DENON_PULSE_TIME 275.0e-6 // 275 usec pulse
145 #define DENON_1_PAUSE_TIME 1900.0e-6 // 1900 usec pause
146 #define DENON_0_PAUSE_TIME 1050.0e-6 // 1050 usec pause
147 #define DENON_REPETITION_CNT 2 // DENON sends each frame 2 times
148 #define DENON_REPETITION_TIME 65.0e-3 // inverted repetition after 65ms
149 #define DENON_ADDRESS_OFFSET 0 // skip 0 bits
150 #define DENON_ADDRESS_LEN 5 // read 5 address bits
151 #define DENON_COMMAND_OFFSET 5 // skip 5
152 #define DENON_COMMAND_LEN 10 // read 10 command bits
153 #define DENON_COMPLETE_DATA_LEN 15 // complete length
154 #define DENON_STOP_BIT 1 // has stop bit
155 #define DENON_LSB 0 // MSB...LSB
156
157 #define RC6_START_BIT_PULSE_TIME 2666.0e-6 // 2.666 msec pulse
158 #define RC6_START_BIT_PAUSE_TIME 889.0e-6 // 889 usec pause
159 #define RC6_TOGGLE_BIT_TIME 889.0e-6 // 889 msec pulse/pause
160 #define RC6_BIT_TIME 444.0e-6 // 889 usec pulse/pause
161 #define RC6_ADDRESS_OFFSET 5 // skip "1" + 3 mode bits + 1 toggle bit
162 #define RC6_ADDRESS_LEN 8 // read 8 address bits
163 #define RC6_COMMAND_OFFSET 13 // skip 12 bits ("1" + 3 mode + 1 toggle + 8 address)
164 #define RC6_COMMAND_LEN 8 // read 8 command bits
165 #define RC6_COMPLETE_DATA_LEN_SHORT 21 // complete length
166 #define RC6_COMPLETE_DATA_LEN_LONG 36 // complete length
167 #define RC6_STOP_BIT 0 // has no stop bit
168 #define RC6_LSB 0 // MSB...LSB
169
170 #define RECS80EXT_START_BIT_PULSE_TIME 158.0e-6 // 158 usec pulse
171 #define RECS80EXT_START_BIT_PAUSE_TIME 3637.0e-6 // 3637 usec pause
172 #define RECS80EXT_PULSE_TIME 158.0e-6 // 158 usec pulse
173 #define RECS80EXT_1_PAUSE_TIME 7432.0e-6 // 7432 usec pause
174 #define RECS80EXT_0_PAUSE_TIME 4902.0e-6 // 4902 usec pause
175 #define RECS80EXT_ADDRESS_OFFSET 2 // skip 2 bits (2nd start + 1 toggle)
176 #define RECS80EXT_ADDRESS_LEN 4 // read 3 address bits
177 #define RECS80EXT_COMMAND_OFFSET 6 // skip 6 bits (2nd start + 1 toggle + 4 address)
178 #define RECS80EXT_COMMAND_LEN 6 // read 6 command bits
179 #define RECS80EXT_COMPLETE_DATA_LEN 12 // complete length
180 #define RECS80EXT_STOP_BIT 1 // has stop bit
181 #define RECS80EXT_LSB 0 // MSB...LSB
182
183 #define NUBERT_START_BIT_PULSE_TIME 1340.0e-6 // 1340 usec pulse
184 #define NUBERT_START_BIT_PAUSE_TIME 340.0e-6 // 340 usec pause
185 #define NUBERT_1_PULSE_TIME 1340.0e-6 // 1340 usec pulse
186 #define NUBERT_1_PAUSE_TIME 340.0e-6 // 340 usec pause
187 #define NUBERT_0_PULSE_TIME 500.0e-6 // 500 usec pulse
188 #define NUBERT_0_PAUSE_TIME 1300.0e-6 // 1300 usec pause
189 #define NUBERT_REPETITION_CNT 2 // Nubert sends 2 frames
190 #define NUBERT_REPETITION_TIME 35.0e-3 // repetition after 35ms
191 #define NUBERT_ADDRESS_OFFSET 0 // skip 0 bits
192 #define NUBERT_ADDRESS_LEN 0 // read 0 address bits
193 #define NUBERT_COMMAND_OFFSET 0 // skip 0 bits
194 #define NUBERT_COMMAND_LEN 10 // read 10 bits
195 #define NUBERT_COMPLETE_DATA_LEN 10 // complete length
196 #define NUBERT_STOP_BIT 1 // has stop bit
197 #define NUBERT_LSB 0 // MSB?
198
199 #define BANG_OLUFSEN_START_BIT1_PULSE_TIME 200.0e-6 // 200 usec pulse
200 #define BANG_OLUFSEN_START_BIT1_PAUSE_TIME 3125.0e-6 // 3125 usec pause
201 #define BANG_OLUFSEN_START_BIT2_PULSE_TIME 200.0e-6 // 200 usec pulse
202 #define BANG_OLUFSEN_START_BIT2_PAUSE_TIME 3125.0e-6 // 3125 usec pause
203 #define BANG_OLUFSEN_START_BIT3_PULSE_TIME 200.0e-6 // 200 usec pulse
204 #define BANG_OLUFSEN_START_BIT3_PAUSE_TIME 15625.0e-6 // 15625 usec pause
205 #define BANG_OLUFSEN_START_BIT4_PULSE_TIME 200.0e-6 // 200 usec pulse
206 #define BANG_OLUFSEN_START_BIT4_PAUSE_TIME 3125.0e-6 // 3125 usec pause
207 #define BANG_OLUFSEN_PULSE_TIME 200.0e-6 // 200 usec pulse
208 #define BANG_OLUFSEN_1_PAUSE_TIME 9375.0e-6 // 9375 usec pause
209 #define BANG_OLUFSEN_0_PAUSE_TIME 3125.0e-6 // 3125 usec pause
210 #define BANG_OLUFSEN_R_PAUSE_TIME 6250.0e-6 // 6250 usec pause (repeat last bit)
211 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME 12500.0e-6 // 12500 usec pause (trailer bit)
212 #define BANG_OLUFSEN_ADDRESS_OFFSET 0 // no address bits
213 #define BANG_OLUFSEN_ADDRESS_LEN 0 // no address bits
214 #define BANG_OLUFSEN_COMMAND_OFFSET 3 // skip startbits 2, 3, 4
215 #define BANG_OLUFSEN_COMMAND_LEN 16 // read 16 command bits
216 #define BANG_OLUFSEN_COMPLETE_DATA_LEN 20 // complete length: startbits 2, 3, 4 + 16 data bits + trailer bit
217 #define BANG_OLUFSEN_STOP_BIT 1 // has stop bit
218 #define BANG_OLUFSEN_LSB 0 // MSB...LSB
219
220 #define GRUNDIG_BIT_TIME 528.0e-6 // 528 usec pulse/pause
221 #define GRUNDIG_PRE_PAUSE_TIME 2639.0e-6 // 2639 usec pause after pre bit
222 #define GRUNDIG_REPETITION_CNT 2 // SIRCS sends each frame 3 times
223 #define GRUNDIG_REPETITION_TIME 20.0e-3 // repetition after 20ms
224 #define GRUNDIG_ADDRESS_OFFSET 0 // skip 2 bits (2nd start + 1 toggle)
225 #define GRUNDIG_ADDRESS_LEN 0 // read 5 address bits
226 #define GRUNDIG_COMMAND_OFFSET 1 // skip 2 bits (1 start bit)
227 #define GRUNDIG_COMMAND_LEN 9 // read 9 command bits
228 #define GRUNDIG_COMPLETE_DATA_LEN 10 // complete length: 1 start bit + 9 data bits
229 #define GRUNDIG_STOP_BIT 0 // has no stop bit
230 #define GRUNDIG_LSB 1 // MSB...LSB
231
232 #define AUTO_REPETITION_TIME 50.0e-3 // SIRCS/SAMSUNG32/NUBERT: automatic repetition after 45-50ms
233
234 #define TRUE 1
235 #define FALSE 0
236
237 #define IRMP_FLAG_REPETITION 0x01
238
239 typedef struct
240 {
241 uint8_t protocol; // protocol, i.e. NEC_PROTOCOL
242 uint16_t address; // address
243 uint16_t command; // command
244 uint8_t flags; // flags, e.g. repetition
245 } IRMP_DATA;
246
247
248 /**
249 * Initialize IRMP decoder
250 * @details Configures IRMP input pin
251 */
252 extern void irmp_init (void);
253
254 /**
255 * Get IRMP data
256 * @details gets decoded IRMP data
257 * @param pointer in order to store IRMP data
258 * @return TRUE: successful, FALSE: failed
259 */
260 extern uint8_t irmp_get_data (IRMP_DATA *);
261
262 /**
263 * ISR routine
264 * @details ISR routine, called 10000 times per second
265 */
266 extern void irmp_ISR (void);
267
268 #ifdef __cplusplus
269 }
270 #endif
271
272 #endif /* _WC_IRMP_H_ */