]> cloudbase.mooo.com Git - irmp.git/blob - irsnd.c
Version 2.1.2:
[irmp.git] / irsnd.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * @file irsnd.c
3 *
4 * Copyright (c) 2010-2011 Frank Meyer - frank(at)fli4l.de
5 *
6 * Supported mikrocontrollers:
7 *
8 * ATtiny45, ATtiny85
9 * ATtiny84
10 * ATmega8, ATmega16, ATmega32
11 * ATmega162
12 * ATmega164, ATmega324, ATmega644, ATmega644P, ATmega1284
13 * ATmega88, ATmega88P, ATmega168, ATmega168P, ATmega328P
14 *
15 * $Id: irsnd.c,v 1.48 2012/02/24 14:24:28 fm Exp $
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *---------------------------------------------------------------------------------------------------------------------------------------------------
22 */
23
24 #if defined(__18CXX)
25 #define PIC_C18 // Microchip C18
26 #include <p18cxxx.h> // basic P18 lib
27 #include "timers.h" // timer lib
28 #include "pwm.h" // pwm lib
29 #endif
30
31 #ifdef unix // test/debug on linux/unix
32 #include <stdio.h>
33 #include <unistd.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <inttypes.h>
37
38 #define DEBUG
39 #define F_CPU 8000000L
40
41 #else // not unix:
42
43 #ifdef WIN32 // test/debug on windows
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
47
48 #define F_CPU 8000000L
49 typedef unsigned char uint8_t;
50 typedef unsigned short uint16_t;
51 #define DEBUG
52
53 #else
54
55 #ifdef CODEVISION
56 #define COM2A0 6
57 #define WGM21 1
58 #define CS20 0
59 #elif defined(PIC_C18)
60 //nothing to do here
61 #else
62 #include <inttypes.h>
63 #include <avr/io.h>
64 #include <util/delay.h>
65 #include <avr/pgmspace.h>
66 #endif // CODEVISION
67
68 #endif // WIN32
69 #endif // unix
70
71 #include "irmp.h"
72 #include "irsndconfig.h"
73 #include "irsnd.h"
74
75 /*---------------------------------------------------------------------------------------------------------------------------------------------------
76 * ATtiny pin definition of OC0A / OC0B
77 * ATmega pin definition of OC2 / OC2A / OC2B / OC0 / OC0A / OC0B
78 *---------------------------------------------------------------------------------------------------------------------------------------------------
79 */
80 #if defined (__AVR_ATtiny84__) // ATtiny84 uses OC0A = PB2 or OC0B = PA7
81 #if IRSND_OCx == IRSND_OC0A // OC0A
82 #define IRSND_PORT PORTB // port B
83 #define IRSND_DDR DDRB // ddr B
84 #define IRSND_BIT 2 // OC0A
85 #elif IRSND_OCx == IRSND_OC0B // OC0B
86 #define IRSND_PORT PORTA // port A
87 #define IRSND_DDR DDRA // ddr A
88 #define IRSND_BIT 7 // OC0B
89 #else
90 #error Wrong value for IRSND_OCx, choose IRSND_OC0A or IRSND_OC0B in irsndconfig.h
91 #endif // IRSND_OCx
92
93 #elif defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) // ATtiny45/85 uses OC0A = PB0 or OC0B = PB1
94 #if IRSND_OCx == IRSND_OC0A // OC0A
95 #define IRSND_PORT PORTB // port B
96 #define IRSND_DDR DDRB // ddr B
97 #define IRSND_BIT 0 // OC0A
98 #elif IRSND_OCx == IRSND_OC0B // OC0B
99 #define IRSND_PORT PORTB // port B
100 #define IRSND_DDR DDRB // ddr B
101 #define IRSND_BIT 1 // OC0B
102 #else
103 #error Wrong value for IRSND_OCx, choose IRSND_OC0A or IRSND_OC0B in irsndconfig.h
104 #endif // IRSND_OCx
105
106 #elif defined (__AVR_ATmega8__) // ATmega8 uses only OC2 = PB3
107 #if IRSND_OCx == IRSND_OC2 // OC0A
108 #define IRSND_PORT PORTB // port B
109 #define IRSND_DDR DDRB // ddr B
110 #define IRSND_BIT 3 // OC0A
111 #else
112 #error Wrong value for IRSND_OCx, choose IRSND_OC2 in irsndconfig.h
113 #endif // IRSND_OCx
114
115
116 #elif defined (__AVR_ATmega16__) \
117 || defined (__AVR_ATmega32__) // ATmega16|32 uses OC2 = PD7
118 #if IRSND_OCx == IRSND_OC2 // OC2
119 #define IRSND_PORT PORTD // port D
120 #define IRSND_DDR DDRD // ddr D
121 #define IRSND_BIT 7 // OC2
122 #else
123 #error Wrong value for IRSND_OCx, choose IRSND_OC2 in irsndconfig.h
124 #endif // IRSND_OCx
125
126 #elif defined (__AVR_ATmega162__) // ATmega162 uses OC2 = PB1 or OC0 = PB0
127 #if IRSND_OCx == IRSND_OC2 // OC2
128 #define IRSND_PORT PORTB // port B
129 #define IRSND_DDR DDRB // ddr B
130 #define IRSND_BIT 1 // OC2
131
132 #elif IRSND_OCx == IRSND_OC0 // OC0
133 #define IRSND_PORT PORTB // port B
134 #define IRSND_DDR DDRB // ddr B
135 #define IRSND_BIT 0 // OC0
136 #else
137 #error Wrong value for IRSND_OCx, choose IRSND_OC2 or IRSND_OC0 in irsndconfig.h
138 #endif // IRSND_OCx
139
140 #elif defined (__AVR_ATmega164__) \
141 || defined (__AVR_ATmega324__) \
142 || defined (__AVR_ATmega644__) \
143 || defined (__AVR_ATmega644P__) \
144 || defined (__AVR_ATmega1284__) \
145 || defined (__AVR_ATmega1284P__) // ATmega164|324|644|644P|1284 uses OC2A = PD7 or OC2B = PD6 or OC0A = PB3 or OC0B = PB4
146 #if IRSND_OCx == IRSND_OC2A // OC2A
147 #define IRSND_PORT PORTD // port D
148 #define IRSND_DDR DDRD // ddr D
149 #define IRSND_BIT 7 // OC2A
150 #elif IRSND_OCx == IRSND_OC2B // OC2B
151 #define IRSND_PORT PORTD // port D
152 #define IRSND_DDR DDRD // ddr D
153 #define IRSND_BIT 6 // OC2B
154 #elif IRSND_OCx == IRSND_OC0A // OC0A
155 #define IRSND_PORT PORTB // port B
156 #define IRSND_DDR DDRB // ddr B
157 #define IRSND_BIT 3 // OC0A
158 #elif IRSND_OCx == IRSND_OC0B // OC0B
159 #define IRSND_PORT PORTB // port B
160 #define IRSND_DDR DDRB // ddr B
161 #define IRSND_BIT 4 // OC0B
162 #else
163 #error Wrong value for IRSND_OCx, choose IRSND_OC2A, IRSND_OC2B, IRSND_OC0A, or IRSND_OC0B in irsndconfig.h
164 #endif // IRSND_OCx
165
166 #elif defined (__AVR_ATmega48__) \
167 || defined (__AVR_ATmega88__) \
168 || defined (__AVR_ATmega88P__) \
169 || defined (__AVR_ATmega168__) \
170 || defined (__AVR_ATmega168P__) \
171 || defined (__AVR_ATmega328P__) // ATmega48|88|168|168|328 uses OC2A = PB3 or OC2B = PD3 or OC0A = PD6 or OC0B = PD5
172 #if IRSND_OCx == IRSND_OC2A // OC2A
173 #define IRSND_PORT PORTB // port B
174 #define IRSND_DDR DDRB // ddr B
175 #define IRSND_BIT 3 // OC2A
176 #elif IRSND_OCx == IRSND_OC2B // OC2B
177 #define IRSND_PORT PORTD // port D
178 #define IRSND_DDR DDRD // ddr D
179 #define IRSND_BIT 3 // OC2B
180 #elif IRSND_OCx == IRSND_OC0A // OC0A
181 #define IRSND_PORT PORTB // port B
182 #define IRSND_DDR DDRB // ddr B
183 #define IRSND_BIT 6 // OC0A
184 #elif IRSND_OCx == IRSND_OC0B // OC0B
185 #define IRSND_PORT PORTD // port D
186 #define IRSND_DDR DDRD // ddr D
187 #define IRSND_BIT 5 // OC0B
188 #else
189 #error Wrong value for IRSND_OCx, choose IRSND_OC2A, IRSND_OC2B, IRSND_OC0A, or IRSND_OC0B in irsndconfig.h
190 #endif // IRSND_OCx
191 #elif defined (__AVR_ATmega8515__)
192 #if IRSND_OCx == IRSND_OC0
193 #define IRSND_PORT PORTB // port B
194 #define IRSND_DDR DDRB // ddr B
195 #define IRSND_BIT 0 // OC0
196 #elif IRSND_OCx == IRSND_OC1A
197 #define IRSND_PORT PORTD // port D
198 #define IRSND_DDR DDRD // ddr D
199 #define IRSND_BIT 5 // OC1A
200 #elif IRSND_OCx == IRSND_OC1B
201 #define IRSND_PORT PORTE // port E
202 #define IRSND_DDR DDRE // ddr E
203 #define IRSND_BIT 2 // OC1E
204 #error Wrong value for IRSND_OCx, choose IRSND_OC0, IRSND_OC1A, or IRSND_OC1B in irsndconfig.h
205 #endif // IRSND_OCx
206
207 #elif defined (PIC_C18) //Microchip C18 compiler
208 //Nothing here to do here -> See irsndconfig.h
209
210 #else
211 #if !defined (unix) && !defined (WIN32)
212 #error mikrocontroller not defined, please fill in definitions here.
213 #endif // unix, WIN32
214 #endif // __AVR...
215
216 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
217 typedef uint16_t IRSND_PAUSE_LEN;
218 #else
219 typedef uint8_t IRSND_PAUSE_LEN;
220 #endif
221
222 /*---------------------------------------------------------------------------------------------------------------------------------------------------
223 * IR timings
224 *---------------------------------------------------------------------------------------------------------------------------------------------------
225 */
226 #define SIRCS_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME + 0.5)
227 #define SIRCS_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME + 0.5)
228 #define SIRCS_1_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME + 0.5)
229 #define SIRCS_0_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME + 0.5)
230 #define SIRCS_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME + 0.5)
231 #define SIRCS_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIRCS_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
232 #define SIRCS_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIRCS_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
233
234 #define NEC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME + 0.5)
235 #define NEC_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME + 0.5)
236 #define NEC_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME + 0.5)
237 #define NEC_PULSE_LEN (uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME + 0.5)
238 #define NEC_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME + 0.5)
239 #define NEC_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME + 0.5)
240 #define NEC_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NEC_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
241
242 #define SAMSUNG_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME + 0.5)
243 #define SAMSUNG_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME + 0.5)
244 #define SAMSUNG_PULSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME + 0.5)
245 #define SAMSUNG_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME + 0.5)
246 #define SAMSUNG_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME + 0.5)
247 #define SAMSUNG_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
248
249 #define SAMSUNG32_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG32_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
250 #define SAMSUNG32_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG32_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
251
252 #define MATSUSHITA_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME + 0.5)
253 #define MATSUSHITA_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME + 0.5)
254 #define MATSUSHITA_PULSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME + 0.5)
255 #define MATSUSHITA_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME + 0.5)
256 #define MATSUSHITA_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME + 0.5)
257 #define MATSUSHITA_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * MATSUSHITA_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
258
259 #define KASEIKYO_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME + 0.5)
260 #define KASEIKYO_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME + 0.5)
261 #define KASEIKYO_PULSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME + 0.5)
262 #define KASEIKYO_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME + 0.5)
263 #define KASEIKYO_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME + 0.5)
264 #define KASEIKYO_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * KASEIKYO_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
265 #define KASEIKYO_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * KASEIKYO_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
266
267 #define RECS80_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME + 0.5)
268 #define RECS80_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME + 0.5)
269 #define RECS80_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME + 0.5)
270 #define RECS80_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME + 0.5)
271 #define RECS80_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME + 0.5)
272 #define RECS80_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RECS80_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
273
274 #define RC5_START_BIT_LEN (uint8_t)(F_INTERRUPTS * RC5_BIT_TIME + 0.5)
275 #define RC5_BIT_LEN (uint8_t)(F_INTERRUPTS * RC5_BIT_TIME + 0.5)
276 #define RC5_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RC5_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
277
278 #define RC6_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME + 0.5)
279 #define RC6_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME + 0.5)
280 #define RC6_TOGGLE_BIT_LEN (uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME + 0.5)
281 #define RC6_BIT_LEN (uint8_t)(F_INTERRUPTS * RC6_BIT_TIME + 0.5)
282 #define RC6_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RC6_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
283
284 #define DENON_PULSE_LEN (uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME + 0.5)
285 #define DENON_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME + 0.5)
286 #define DENON_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME + 0.5)
287 #define DENON_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * DENON_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
288 #define DENON_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * DENON_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
289
290 #define THOMSON_PULSE_LEN (uint8_t)(F_INTERRUPTS * THOMSON_PULSE_TIME + 0.5)
291 #define THOMSON_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * THOMSON_1_PAUSE_TIME + 0.5)
292 #define THOMSON_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * THOMSON_0_PAUSE_TIME + 0.5)
293 #define THOMSON_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * THOMSON_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
294 #define THOMSON_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * THOMSON_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
295
296 #define RECS80EXT_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME + 0.5)
297 #define RECS80EXT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME + 0.5)
298 #define RECS80EXT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME + 0.5)
299 #define RECS80EXT_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME + 0.5)
300 #define RECS80EXT_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME + 0.5)
301 #define RECS80EXT_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RECS80EXT_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
302
303 #define NUBERT_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME + 0.5)
304 #define NUBERT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME + 0.5)
305 #define NUBERT_1_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME + 0.5)
306 #define NUBERT_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME + 0.5)
307 #define NUBERT_0_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME + 0.5)
308 #define NUBERT_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME + 0.5)
309 #define NUBERT_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NUBERT_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
310 #define NUBERT_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NUBERT_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
311
312 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME + 0.5)
313 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME + 0.5)
314 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME + 0.5)
315 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME + 0.5)
316 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME + 0.5)
317 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME + 0.5)
318 #define BANG_OLUFSEN_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME + 0.5)
319 #define BANG_OLUFSEN_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME + 0.5)
320 #define BANG_OLUFSEN_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME + 0.5)
321 #define BANG_OLUFSEN_R_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME + 0.5)
322 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME + 0.5)
323 #define BANG_OLUFSEN_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * BANG_OLUFSEN_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
324
325 #define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN (uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME + 0.5)
326 #define GRUNDIG_NOKIA_IR60_BIT_LEN (uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME + 0.5)
327 #define GRUNDIG_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * GRUNDIG_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
328 #define NOKIA_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NOKIA_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
329 #define GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
330
331 #define IR60_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * IR60_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
332
333 #define SIEMENS_START_BIT_LEN (uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME + 0.5)
334 #define SIEMENS_BIT_LEN (uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME + 0.5)
335 #define SIEMENS_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
336
337
338 #ifdef PIC_C18
339 #define IRSND_FREQ_30_KHZ (uint8_t) ((F_CPU / 30000 / 2 / Pre_Scaler / PIC_Scaler) - 1)
340 #define IRSND_FREQ_32_KHZ (uint8_t) ((F_CPU / 32000 / 2 / Pre_Scaler / PIC_Scaler) - 1)
341 #define IRSND_FREQ_36_KHZ (uint8_t) ((F_CPU / 36000 / 2 / Pre_Scaler / PIC_Scaler) - 1)
342 #define IRSND_FREQ_38_KHZ (uint8_t) ((F_CPU / 38000 / 2 / Pre_Scaler / PIC_Scaler) - 1)
343 #define IRSND_FREQ_40_KHZ (uint8_t) ((F_CPU / 40000 / 2 / Pre_Scaler / PIC_Scaler) - 1)
344 #define IRSND_FREQ_56_KHZ (uint8_t) ((F_CPU / 56000 / 2 / Pre_Scaler / PIC_Scaler) - 1)
345 #define IRSND_FREQ_455_KHZ (uint8_t) ((F_CPU / 455000 / 2 / Pre_Scaler / PIC_Scaler) - 1)
346 #else // AVR
347 #define IRSND_FREQ_30_KHZ (uint8_t) ((F_CPU / 30000 / 2) - 1)
348 #define IRSND_FREQ_32_KHZ (uint8_t) ((F_CPU / 32000 / 2) - 1)
349 #define IRSND_FREQ_36_KHZ (uint8_t) ((F_CPU / 36000 / 2) - 1)
350 #define IRSND_FREQ_38_KHZ (uint8_t) ((F_CPU / 38000 / 2) - 1)
351 #define IRSND_FREQ_40_KHZ (uint8_t) ((F_CPU / 40000 / 2) - 1)
352 #define IRSND_FREQ_56_KHZ (uint8_t) ((F_CPU / 56000 / 2) - 1)
353 #define IRSND_FREQ_455_KHZ (uint8_t) ((F_CPU / 455000 / 2) - 1)
354 #endif
355
356 #define FDC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME + 0.5)
357 #define FDC_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME + 0.5)
358 #define FDC_PULSE_LEN (uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME + 0.5)
359 #define FDC_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME + 0.5)
360 #define FDC_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME + 0.5)
361 #define FDC_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * FDC_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
362
363 #define RCCAR_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME + 0.5)
364 #define RCCAR_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME + 0.5)
365 #define RCCAR_PULSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME + 0.5)
366 #define RCCAR_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME + 0.5)
367 #define RCCAR_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME + 0.5)
368 #define RCCAR_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RCCAR_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
369
370 #define JVC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME + 0.5)
371 #define JVC_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * JVC_START_BIT_PAUSE_TIME + 0.5)
372 #define JVC_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * JVC_REPEAT_START_BIT_PAUSE_TIME + 0.5)
373 #define JVC_PULSE_LEN (uint8_t)(F_INTERRUPTS * JVC_PULSE_TIME + 0.5)
374 #define JVC_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * JVC_1_PAUSE_TIME + 0.5)
375 #define JVC_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * JVC_0_PAUSE_TIME + 0.5)
376 #define JVC_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * JVC_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
377
378 #define NIKON_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_START_BIT_PULSE_TIME + 0.5)
379 #define NIKON_START_BIT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NIKON_START_BIT_PAUSE_TIME + 0.5)
380 #define NIKON_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_REPEAT_START_BIT_PAUSE_TIME + 0.5)
381 #define NIKON_PULSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_PULSE_TIME + 0.5)
382 #define NIKON_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME + 0.5)
383 #define NIKON_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME + 0.5)
384 #define NIKON_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NIKON_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
385
386 #define LEGO_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME + 0.5)
387 #define LEGO_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME + 0.5)
388 #define LEGO_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_REPEAT_START_BIT_PAUSE_TIME + 0.5)
389 #define LEGO_PULSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME + 0.5)
390 #define LEGO_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME + 0.5)
391 #define LEGO_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME + 0.5)
392 #define LEGO_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * LEGO_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
393
394 static volatile uint8_t irsnd_busy = 0;
395 static volatile uint8_t irsnd_protocol = 0;
396 static volatile uint8_t irsnd_buffer[6] = {0};
397 static volatile uint8_t irsnd_repeat = 0;
398 static volatile uint8_t irsnd_is_on = FALSE;
399
400 #if IRSND_USE_CALLBACK == 1
401 static void (*irsnd_callback_ptr) (uint8_t);
402 #endif // IRSND_USE_CALLBACK == 1
403
404 /*---------------------------------------------------------------------------------------------------------------------------------------------------
405 * Switch PWM on
406 * @details Switches PWM on with a narrow spike on all 3 channels -> leds glowing
407 *---------------------------------------------------------------------------------------------------------------------------------------------------
408 */
409 static void
410 irsnd_on (void)
411 {
412 if (! irsnd_is_on)
413 {
414 #ifndef DEBUG
415
416 #if defined(PIC_C18)
417 IRSND_PIN = 0; // output mode -> enable PWM outout pin (0=PWM on, 1=PWM off)
418 #else
419
420 #if IRSND_OCx == IRSND_OC2 // use OC2
421 TCCR2 |= (1<<COM20)|(1<<WGM21); // toggle OC2 on compare match, clear Timer 2 at compare match OCR2
422 #elif IRSND_OCx == IRSND_OC2A // use OC2A
423 TCCR2A |= (1<<COM2A0)|(1<<WGM21); // toggle OC2A on compare match, clear Timer 2 at compare match OCR2A
424 #elif IRSND_OCx == IRSND_OC2B // use OC2B
425 TCCR2A |= (1<<COM2B0)|(1<<WGM21); // toggle OC2B on compare match, clear Timer 2 at compare match OCR2A (yes: A, not B!)
426 #elif IRSND_OCx == IRSND_OC0 // use OC0
427 TCCR0 |= (1<<COM00)|(1<<WGM01); // toggle OC0 on compare match, clear Timer 0 at compare match OCR0
428 #elif IRSND_OCx == IRSND_OC0A // use OC0A
429 TCCR0A |= (1<<COM0A0)|(1<<WGM01); // toggle OC0A on compare match, clear Timer 0 at compare match OCR0A
430 #elif IRSND_OCx == IRSND_OC0B // use OC0B
431 TCCR0A |= (1<<COM0B0)|(1<<WGM01); // toggle OC0B on compare match, clear Timer 0 at compare match OCR0A (yes: A, not B!)
432 #else
433 #error wrong value of IRSND_OCx
434 #endif // IRSND_OCx
435
436 #endif //C18
437 #endif // DEBUG
438
439 #if IRSND_USE_CALLBACK == 1
440 if (irsnd_callback_ptr)
441 {
442 (*irsnd_callback_ptr) (TRUE);
443 }
444 #endif // IRSND_USE_CALLBACK == 1
445
446 irsnd_is_on = TRUE;
447 }
448 }
449
450 /*---------------------------------------------------------------------------------------------------------------------------------------------------
451 * Switch PWM off
452 * @details Switches PWM off
453 *---------------------------------------------------------------------------------------------------------------------------------------------------
454 */
455 static void
456 irsnd_off (void)
457 {
458 if (irsnd_is_on)
459 {
460 #ifndef DEBUG
461
462 #if defined(PIC_C18)
463 IRSND_PIN = 1; //input mode -> disbale PWM output pin (0=PWM on, 1=PWM off)
464 #else //AVR
465
466 #if IRSND_OCx == IRSND_OC2 // use OC2
467 TCCR2 &= ~(1<<COM20); // normal port operation, OC2 disconnected.
468 #elif IRSND_OCx == IRSND_OC2A // use OC2A
469 TCCR2A &= ~(1<<COM2A0); // normal port operation, OC2A disconnected.
470 #elif IRSND_OCx == IRSND_OC2B // use OC2B
471 TCCR2A &= ~(1<<COM2B0); // normal port operation, OC2B disconnected.
472 #elif IRSND_OCx == IRSND_OC0 // use OC0
473 TCCR0 &= ~(1<<COM00); // normal port operation, OC0 disconnected.
474 #elif IRSND_OCx == IRSND_OC0A // use OC0A
475 TCCR0A &= ~(1<<COM0A0); // normal port operation, OC0A disconnected.
476 #elif IRSND_OCx == IRSND_OC0B // use OC0B
477 TCCR0A &= ~(1<<COM0B0); // normal port operation, OC0B disconnected.
478 #else
479 #error wrong value of IRSND_OCx
480 #endif // IRSND_OCx
481 IRSND_PORT &= ~(1<<IRSND_BIT); // set IRSND_BIT to low
482 #endif //C18
483 #endif // DEBUG
484
485 #if IRSND_USE_CALLBACK == 1
486 if (irsnd_callback_ptr)
487 {
488 (*irsnd_callback_ptr) (FALSE);
489 }
490 #endif // IRSND_USE_CALLBACK == 1
491
492 irsnd_is_on = FALSE;
493 }
494 }
495
496 /*---------------------------------------------------------------------------------------------------------------------------------------------------
497 * Set PWM frequency
498 * @details sets pwm frequency
499 *---------------------------------------------------------------------------------------------------------------------------------------------------
500 */
501 static void
502 irsnd_set_freq (uint8_t freq)
503 {
504 #ifndef DEBUG
505
506 #if defined(PIC_C18)
507 OpenPWM(freq);
508 SetDCPWM( (uint16_t) freq * 2); // freq*2 = Duty cycles 50%
509 #else //AVR
510
511 #if IRSND_OCx == IRSND_OC2
512 OCR2 = freq; // use register OCR2 for OC2
513 #elif IRSND_OCx == IRSND_OC2A // use OC2A
514 OCR2A = freq; // use register OCR2A for OC2A and OC2B!
515 #elif IRSND_OCx == IRSND_OC2B // use OC2B
516 OCR2A = freq; // use register OCR2A for OC2A and OC2B!
517 #elif IRSND_OCx == IRSND_OC0 // use OC0
518 OCR0 = freq; // use register OCR2 for OC2
519 #elif IRSND_OCx == IRSND_OC0A // use OC0A
520 OCR0A = freq; // use register OCR0A for OC0A and OC0B!
521 #elif IRSND_OCx == IRSND_OC0B // use OC0B
522 OCR0A = freq; // use register OCR0A for OC0A and OC0B!
523 #else
524 #error wrong value of IRSND_OCx
525 #endif
526 #endif //PIC_C18
527 #endif // DEBUG
528 }
529
530 /*---------------------------------------------------------------------------------------------------------------------------------------------------
531 * Initialize the PWM
532 * @details Configures 0CR0A, 0CR0B and 0CR2B as PWM channels
533 *---------------------------------------------------------------------------------------------------------------------------------------------------
534 */
535 void
536 irsnd_init (void)
537 {
538 #ifndef DEBUG
539 #if defined(PIC_C18)
540 OpenTimer;
541 irsnd_set_freq (IRSND_FREQ_36_KHZ); //default frequency
542 IRSND_PIN = 1; //default PWM output pin off (0=PWM on, 1=PWM off)
543 #else
544 IRSND_PORT &= ~(1<<IRSND_BIT); // set IRSND_BIT to low
545 IRSND_DDR |= (1<<IRSND_BIT); // set IRSND_BIT to output
546
547 #if IRSND_OCx == IRSND_OC2 // use OC2
548 TCCR2 = (1<<WGM21); // CTC mode
549 TCCR2 |= (1<<CS20); // 0x01, start Timer 2, no prescaling
550 #elif IRSND_OCx == IRSND_OC2A || IRSND_OCx == IRSND_OC2B // use OC2A or OC2B
551 TCCR2A = (1<<WGM21); // CTC mode
552 TCCR2B |= (1<<CS20); // 0x01, start Timer 2, no prescaling
553 #elif IRSND_OCx == IRSND_OC0 // use OC0
554 TCCR0 = (1<<WGM01); // CTC mode
555 TCCR0 |= (1<<CS00); // 0x01, start Timer 0, no prescaling
556 #elif IRSND_OCx == IRSND_OC0A || IRSND_OCx == IRSND_OC0B // use OC0A or OC0B
557 TCCR0A = (1<<WGM01); // CTC mode
558 TCCR0B |= (1<<CS00); // 0x01, start Timer 0, no prescaling
559 #else
560 #error wrong value of IRSND_OCx
561 #endif
562 irsnd_set_freq (IRSND_FREQ_36_KHZ); // default frequency
563 #endif //PIC_C18
564 #endif // DEBUG
565 }
566
567 #if IRSND_USE_CALLBACK == 1
568 void
569 irsnd_set_callback_ptr (void (*cb)(uint8_t))
570 {
571 irsnd_callback_ptr = cb;
572 }
573 #endif // IRSND_USE_CALLBACK == 1
574
575 uint8_t
576 irsnd_is_busy (void)
577 {
578 return irsnd_busy;
579 }
580
581 static uint16_t
582 bitsrevervse (uint16_t x, uint8_t len)
583 {
584 uint16_t xx = 0;
585
586 while(len)
587 {
588 xx <<= 1;
589 if (x & 1)
590 {
591 xx |= 1;
592 }
593 x >>= 1;
594 len--;
595 }
596 return xx;
597 }
598
599
600 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
601 static uint8_t sircs_additional_bitlen;
602 #endif // IRSND_SUPPORT_SIRCS_PROTOCOL == 1
603
604 uint8_t
605 irsnd_send_data (IRMP_DATA * irmp_data_p, uint8_t do_wait)
606 {
607 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
608 static uint8_t toggle_bit_recs80;
609 #endif
610 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
611 static uint8_t toggle_bit_recs80ext;
612 #endif
613 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
614 static uint8_t toggle_bit_rc5;
615 #endif
616 #if IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1
617 static uint8_t toggle_bit_rc6;
618 #endif
619 #if IRSND_SUPPORT_THOMSON_PROTOCOL == 1
620 static uint8_t toggle_bit_thomson;
621 #endif
622 uint16_t address;
623 uint16_t command;
624
625 if (do_wait)
626 {
627 while (irsnd_busy)
628 {
629 // do nothing;
630 }
631 }
632 else if (irsnd_busy)
633 {
634 return (FALSE);
635 }
636
637 irsnd_protocol = irmp_data_p->protocol;
638 irsnd_repeat = irmp_data_p->flags & IRSND_REPETITION_MASK;
639
640 switch (irsnd_protocol)
641 {
642 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
643 case IRMP_SIRCS_PROTOCOL:
644 {
645 uint8_t sircs_additional_command_len;
646 uint8_t sircs_additional_address_len;
647
648 sircs_additional_bitlen = (irmp_data_p->address & 0xFF00) >> 8; // additional bitlen
649
650 if (sircs_additional_bitlen > 15 - SIRCS_MINIMUM_DATA_LEN)
651 {
652 sircs_additional_command_len = 15 - SIRCS_MINIMUM_DATA_LEN;
653 sircs_additional_address_len = sircs_additional_bitlen - (15 - SIRCS_MINIMUM_DATA_LEN);
654 }
655 else
656 {
657 sircs_additional_command_len = sircs_additional_bitlen;
658 sircs_additional_address_len = 0;
659 }
660
661 command = bitsrevervse (irmp_data_p->command, 15);
662
663 irsnd_buffer[0] = (command & 0x7F80) >> 7; // CCCCCCCC
664 irsnd_buffer[1] = (command & 0x007F) << 1; // CCCC****
665
666 if (sircs_additional_address_len > 0)
667 {
668 address = bitsrevervse (irmp_data_p->address, 5);
669 irsnd_buffer[1] |= (address & 0x0010) >> 4;
670 irsnd_buffer[2] = (address & 0x000F) << 4;
671 }
672 irsnd_busy = TRUE;
673 break;
674 }
675 #endif
676 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
677 case IRMP_APPLE_PROTOCOL:
678 {
679 command = irmp_data_p->command | (irmp_data_p->address << 8); // store address as ID in upper byte of command
680 address = 0x87EE; // set fixed NEC-lookalike address (customer ID of apple)
681
682 address = bitsrevervse (address, NEC_ADDRESS_LEN);
683 command = bitsrevervse (command, NEC_COMMAND_LEN);
684
685 irsnd_protocol = IRMP_NEC_PROTOCOL; // APPLE protocol is NEC with id instead of inverted command
686
687 irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA
688 irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA
689 irsnd_buffer[2] = (command & 0xFF00) >> 8; // CCCCCCCC
690 irsnd_buffer[3] = 0x8B; // 10001011 (id)
691 irsnd_busy = TRUE;
692 break;
693 }
694 case IRMP_NEC_PROTOCOL:
695 {
696 address = bitsrevervse (irmp_data_p->address, NEC_ADDRESS_LEN);
697 command = bitsrevervse (irmp_data_p->command, NEC_COMMAND_LEN);
698
699 irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA
700 irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA
701 irsnd_buffer[2] = (command & 0xFF00) >> 8; // CCCCCCCC
702 irsnd_buffer[3] = ~((command & 0xFF00) >> 8); // cccccccc
703 irsnd_busy = TRUE;
704 break;
705 }
706 #endif
707 #if IRSND_SUPPORT_NEC16_PROTOCOL == 1
708 case IRMP_NEC16_PROTOCOL:
709 {
710 address = bitsrevervse (irmp_data_p->address, NEC16_ADDRESS_LEN);
711 command = bitsrevervse (irmp_data_p->command, NEC16_COMMAND_LEN);
712
713 irsnd_buffer[0] = (address & 0x00FF); // AAAAAAAA
714 irsnd_buffer[1] = (command & 0x00FF); // CCCCCCCC
715 irsnd_busy = TRUE;
716 break;
717 }
718 #endif
719 #if IRSND_SUPPORT_NEC42_PROTOCOL == 1
720 case IRMP_NEC42_PROTOCOL:
721 {
722 address = bitsrevervse (irmp_data_p->address, NEC42_ADDRESS_LEN);
723 command = bitsrevervse (irmp_data_p->command, NEC42_COMMAND_LEN);
724
725 irsnd_buffer[0] = ( (address & 0x1FE0) >> 5); // AAAAAAAA
726 irsnd_buffer[1] = ( (address & 0x001F) << 3) | ((~address & 0x1C00) >> 10); // AAAAAaaa
727 irsnd_buffer[2] = ((~address & 0x03FC) >> 2); // aaaaaaaa
728 irsnd_buffer[3] = ((~address & 0x0003) << 6) | ( (command & 0x00FC) >> 2); // aaCCCCCC
729 irsnd_buffer[4] = ( (command & 0x0003) << 6) | ((~command & 0x00FC) >> 2); // CCcccccc
730 irsnd_buffer[5] = ((~command & 0x0003) << 6); // cc
731 irsnd_busy = TRUE;
732 break;
733 }
734 #endif
735 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
736 case IRMP_SAMSUNG_PROTOCOL:
737 {
738 address = bitsrevervse (irmp_data_p->address, SAMSUNG_ADDRESS_LEN);
739 command = bitsrevervse (irmp_data_p->command, SAMSUNG_COMMAND_LEN);
740
741 irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA
742 irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA
743 irsnd_buffer[2] = (command & 0x00F0) | ((command & 0xF000) >> 12); // IIIICCCC
744 irsnd_buffer[3] = ((command & 0x0F00) >> 4) | ((~(command & 0xF000) >> 12) & 0x0F); // CCCCcccc
745 irsnd_buffer[4] = (~(command & 0x0F00) >> 4) & 0xF0; // cccc0000
746 irsnd_busy = TRUE;
747 break;
748 }
749 case IRMP_SAMSUNG32_PROTOCOL:
750 {
751 address = bitsrevervse (irmp_data_p->address, SAMSUNG_ADDRESS_LEN);
752 command = bitsrevervse (irmp_data_p->command, SAMSUNG32_COMMAND_LEN);
753
754 irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA
755 irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA
756 irsnd_buffer[2] = (command & 0xFF00) >> 8; // CCCCCCCC
757 irsnd_buffer[3] = (command & 0x00FF); // CCCCCCCC
758 irsnd_busy = TRUE;
759 break;
760 }
761 #endif
762 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
763 case IRMP_MATSUSHITA_PROTOCOL:
764 {
765 address = bitsrevervse (irmp_data_p->address, MATSUSHITA_ADDRESS_LEN);
766 command = bitsrevervse (irmp_data_p->command, MATSUSHITA_COMMAND_LEN);
767
768 irsnd_buffer[0] = (command & 0x0FF0) >> 4; // CCCCCCCC
769 irsnd_buffer[1] = ((command & 0x000F) << 4) | ((address & 0x0F00) >> 8); // CCCCAAAA
770 irsnd_buffer[2] = (address & 0x00FF); // AAAAAAAA
771 irsnd_busy = TRUE;
772 break;
773 }
774 #endif
775 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1
776 case IRMP_KASEIKYO_PROTOCOL:
777 {
778 uint8_t xor;
779 uint16_t genre2;
780
781 address = bitsrevervse (irmp_data_p->address, KASEIKYO_ADDRESS_LEN);
782 command = bitsrevervse (irmp_data_p->command, KASEIKYO_COMMAND_LEN + 4);
783 genre2 = bitsrevervse ((irmp_data_p->flags & ~IRSND_REPETITION_MASK) >> 4, 4);
784
785 xor = ((address & 0x000F) ^ ((address & 0x00F0) >> 4) ^ ((address & 0x0F00) >> 8) ^ ((address & 0xF000) >> 12)) & 0x0F;
786
787 irsnd_buffer[0] = (address & 0xFF00) >> 8; // AAAAAAAA
788 irsnd_buffer[1] = (address & 0x00FF); // AAAAAAAA
789 irsnd_buffer[2] = xor << 4 | (command & 0x000F); // XXXXCCCC
790 irsnd_buffer[3] = (genre2 << 4) | (command & 0xF000) >> 12; // ggggCCCC
791 irsnd_buffer[4] = (command & 0x0FF0) >> 4; // CCCCCCCC
792
793 xor = irsnd_buffer[2] ^ irsnd_buffer[3] ^ irsnd_buffer[4];
794
795 irsnd_buffer[5] = xor;
796 irsnd_busy = TRUE;
797 break;
798 }
799 #endif
800 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
801 case IRMP_RECS80_PROTOCOL:
802 {
803 toggle_bit_recs80 = toggle_bit_recs80 ? 0x00 : 0x40;
804
805 irsnd_buffer[0] = 0x80 | toggle_bit_recs80 | ((irmp_data_p->address & 0x0007) << 3) |
806 ((irmp_data_p->command & 0x0038) >> 3); // STAAACCC
807 irsnd_buffer[1] = (irmp_data_p->command & 0x07) << 5; // CCC00000
808 irsnd_busy = TRUE;
809 break;
810 }
811 #endif
812 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
813 case IRMP_RECS80EXT_PROTOCOL:
814 {
815 toggle_bit_recs80ext = toggle_bit_recs80ext ? 0x00 : 0x40;
816
817 irsnd_buffer[0] = 0x80 | toggle_bit_recs80ext | ((irmp_data_p->address & 0x000F) << 2) |
818 ((irmp_data_p->command & 0x0030) >> 4); // STAAAACC
819 irsnd_buffer[1] = (irmp_data_p->command & 0x0F) << 4; // CCCC0000
820 irsnd_busy = TRUE;
821 break;
822 }
823 #endif
824 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
825 case IRMP_RC5_PROTOCOL:
826 {
827 toggle_bit_rc5 = toggle_bit_rc5 ? 0x00 : 0x40;
828
829 irsnd_buffer[0] = ((irmp_data_p->command & 0x40) ? 0x00 : 0x80) | toggle_bit_rc5 |
830 ((irmp_data_p->address & 0x001F) << 1) | ((irmp_data_p->command & 0x20) >> 5); // CTAAAAAC
831 irsnd_buffer[1] = (irmp_data_p->command & 0x1F) << 3; // CCCCC000
832 irsnd_busy = TRUE;
833 break;
834 }
835 #endif
836 #if IRSND_SUPPORT_RC6_PROTOCOL == 1
837 case IRMP_RC6_PROTOCOL:
838 {
839 toggle_bit_rc6 = toggle_bit_rc6 ? 0x00 : 0x08;
840
841 irsnd_buffer[0] = 0x80 | toggle_bit_rc6 | ((irmp_data_p->address & 0x00E0) >> 5); // 1MMMTAAA, MMM = 000
842 irsnd_buffer[1] = ((irmp_data_p->address & 0x001F) << 3) | ((irmp_data_p->command & 0xE0) >> 5); // AAAAACCC
843 irsnd_buffer[2] = (irmp_data_p->command & 0x1F) << 3; // CCCCC
844 irsnd_busy = TRUE;
845 break;
846 }
847 #endif
848 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1
849 case IRMP_RC6A_PROTOCOL:
850 {
851 toggle_bit_rc6 = toggle_bit_rc6 ? 0x00 : 0x08;
852
853 irsnd_buffer[0] = 0x80 | 0x60 | ((irmp_data_p->address & 0x3000) >> 12); // 1MMMT0AA, MMM = 110
854 irsnd_buffer[1] = ((irmp_data_p->address & 0x0FFF) >> 4) ; // AAAAAAAA
855 irsnd_buffer[2] = ((irmp_data_p->address & 0x000F) << 4) | ((irmp_data_p->command & 0xF000) >> 12) | toggle_bit_rc6; // AAAACCCC
856 irsnd_buffer[3] = (irmp_data_p->command & 0x0FF0) >> 4; // CCCCCCCC
857 irsnd_buffer[4] = (irmp_data_p->command & 0x000F) << 4; // CCCC
858 irsnd_busy = TRUE;
859 break;
860 }
861 #endif
862 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
863 case IRMP_DENON_PROTOCOL:
864 {
865 irsnd_buffer[0] = ((irmp_data_p->address & 0x1F) << 3) | ((irmp_data_p->command & 0x0380) >> 7); // AAAAACCC (1st frame)
866 irsnd_buffer[1] = (irmp_data_p->command & 0x7F) << 1; // CCCCCCC
867 irsnd_buffer[2] = ((irmp_data_p->address & 0x1F) << 3) | (((~irmp_data_p->command) & 0x0380) >> 7); // AAAAACCC (2nd frame)
868 irsnd_buffer[3] = (~(irmp_data_p->command) & 0x7F) << 1; // CCCCCCC
869 irsnd_busy = TRUE;
870 break;
871 }
872 #endif
873 #if IRSND_SUPPORT_THOMSON_PROTOCOL == 1
874 case IRMP_THOMSON_PROTOCOL:
875 {
876 toggle_bit_thomson = toggle_bit_thomson ? 0x00 : 0x08;
877
878 irsnd_buffer[0] = ((irmp_data_p->address & 0x0F) << 4) | toggle_bit_thomson | ((irmp_data_p->command & 0x0070) >> 4); // AAAATCCC (1st frame)
879 irsnd_buffer[1] = (irmp_data_p->command & 0x0F) << 4; // CCCC
880 irsnd_busy = TRUE;
881 break;
882 }
883 #endif
884 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
885 case IRMP_NUBERT_PROTOCOL:
886 {
887 irsnd_buffer[0] = irmp_data_p->command >> 2; // CCCCCCCC
888 irsnd_buffer[1] = (irmp_data_p->command & 0x0003) << 6; // CC000000
889 irsnd_busy = TRUE;
890 break;
891 }
892 #endif
893 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
894 case IRMP_BANG_OLUFSEN_PROTOCOL:
895 {
896 irsnd_buffer[0] = irmp_data_p->command >> 11; // SXSCCCCC
897 irsnd_buffer[1] = irmp_data_p->command >> 3; // CCCCCCCC
898 irsnd_buffer[2] = (irmp_data_p->command & 0x0007) << 5; // CCC00000
899 irsnd_busy = TRUE;
900 break;
901 }
902 #endif
903 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
904 case IRMP_GRUNDIG_PROTOCOL:
905 {
906 command = bitsrevervse (irmp_data_p->command, GRUNDIG_COMMAND_LEN);
907
908 irsnd_buffer[0] = 0xFF; // S1111111 (1st frame)
909 irsnd_buffer[1] = 0xC0; // 11
910 irsnd_buffer[2] = 0x80 | (command >> 2); // SCCCCCCC (2nd frame)
911 irsnd_buffer[3] = (command << 6) & 0xC0; // CC
912
913 irsnd_busy = TRUE;
914 break;
915 }
916 #endif
917 #if IRSND_SUPPORT_IR60_PROTOCOL == 1
918 case IRMP_IR60_PROTOCOL:
919 {
920 command = (bitsrevervse (0x7d, IR60_COMMAND_LEN) << 7) | bitsrevervse (irmp_data_p->command, IR60_COMMAND_LEN);
921 irsnd_buffer[0] = command >> 6 | 0x01; // 1011111S (start instruction frame)
922 irsnd_buffer[1] = (command & 0x7F) << 1; // CCCCCCC_ (2nd frame)
923
924 irsnd_busy = TRUE;
925 break;
926 }
927 #endif
928 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
929 case IRMP_NOKIA_PROTOCOL:
930 {
931 address = bitsrevervse (irmp_data_p->address, NOKIA_ADDRESS_LEN);
932 command = bitsrevervse (irmp_data_p->command, NOKIA_COMMAND_LEN);
933
934 irsnd_buffer[0] = 0xBF; // S0111111 (1st + 3rd frame)
935 irsnd_buffer[1] = 0xFF; // 11111111
936 irsnd_buffer[2] = 0x80; // 1
937 irsnd_buffer[3] = 0x80 | command >> 1; // SCCCCCCC (2nd frame)
938 irsnd_buffer[4] = (command << 7) | (address >> 1); // CAAAAAAA
939 irsnd_buffer[5] = (address << 7); // A
940
941 irsnd_busy = TRUE;
942 break;
943 }
944 #endif
945 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
946 case IRMP_SIEMENS_PROTOCOL:
947 {
948 irsnd_buffer[0] = ((irmp_data_p->address & 0x0FFF) >> 5); // SAAAAAAA
949 irsnd_buffer[1] = ((irmp_data_p->address & 0x1F) << 3) | ((irmp_data_p->command & 0x7F) >> 5); // AAAAA0CC
950 irsnd_buffer[2] = (irmp_data_p->command << 3) | ((~irmp_data_p->command & 0x01) << 2); // CCCCCc
951
952 irsnd_busy = TRUE;
953 break;
954 }
955 #endif
956 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
957 case IRMP_FDC_PROTOCOL:
958 {
959 address = bitsrevervse (irmp_data_p->address, FDC_ADDRESS_LEN);
960 command = bitsrevervse (irmp_data_p->command, FDC_COMMAND_LEN);
961
962 irsnd_buffer[0] = (address & 0xFF); // AAAAAAAA
963 irsnd_buffer[1] = 0; // 00000000
964 irsnd_buffer[2] = 0; // 0000RRRR
965 irsnd_buffer[3] = (command & 0xFF); // CCCCCCCC
966 irsnd_buffer[4] = ~(command & 0xFF); // cccccccc
967 irsnd_busy = TRUE;
968 break;
969 }
970 #endif
971 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1
972 case IRMP_RCCAR_PROTOCOL:
973 {
974 address = bitsrevervse (irmp_data_p->address, 2); // A0 A1
975 command = bitsrevervse (irmp_data_p->command, RCCAR_COMMAND_LEN - 2); // D0 D1 D2 D3 D4 D5 D6 D7 C0 C1 V
976
977 irsnd_buffer[0] = ((command & 0x06) << 5) | ((address & 0x0003) << 4) | ((command & 0x0780) >> 7); // C0 C1 A0 A1 D0 D1 D2 D3
978 irsnd_buffer[1] = ((command & 0x78) << 1) | ((command & 0x0001) << 3); // D4 D5 D6 D7 V 0 0 0
979
980 irsnd_busy = TRUE;
981 break;
982 }
983 #endif
984 #if IRSND_SUPPORT_JVC_PROTOCOL == 1
985 case IRMP_JVC_PROTOCOL:
986 {
987 address = bitsrevervse (irmp_data_p->address, JVC_ADDRESS_LEN);
988 command = bitsrevervse (irmp_data_p->command, JVC_COMMAND_LEN);
989
990 irsnd_buffer[0] = ((address & 0x000F) << 4) | (command & 0x0F00) >> 8; // AAAACCCC
991 irsnd_buffer[1] = (command & 0x00FF); // CCCCCCCC
992
993 irsnd_busy = TRUE;
994 break;
995 }
996 #endif
997 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
998 case IRMP_NIKON_PROTOCOL:
999 {
1000 irsnd_buffer[0] = (irmp_data_p->command & 0x0003) << 6; // CC
1001 irsnd_busy = TRUE;
1002 break;
1003 }
1004 #endif
1005 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1
1006 case IRMP_LEGO_PROTOCOL:
1007 {
1008 uint8_t crc = 0x0F ^ ((irmp_data_p->command & 0x0F00) >> 8) ^ ((irmp_data_p->command & 0x00F0) >> 4) ^ (irmp_data_p->command & 0x000F);
1009
1010 irsnd_buffer[0] = (irmp_data_p->command & 0x0FF0) >> 4; // CCCCCCCC
1011 irsnd_buffer[1] = ((irmp_data_p->command & 0x000F) << 4) | crc; // CCCCcccc
1012
1013 irsnd_protocol = IRMP_LEGO_PROTOCOL;
1014 irsnd_busy = TRUE;
1015 break;
1016 }
1017 #endif
1018 default:
1019 {
1020 break;
1021 }
1022 }
1023
1024 return irsnd_busy;
1025 }
1026
1027 void
1028 irsnd_stop (void)
1029 {
1030 irsnd_repeat = 0;
1031 }
1032
1033 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1034 * ISR routine
1035 * @details ISR routine, called 10000 times per second
1036 *---------------------------------------------------------------------------------------------------------------------------------------------------
1037 */
1038 uint8_t
1039 irsnd_ISR (void)
1040 {
1041 static uint8_t send_trailer = FALSE;
1042 static uint8_t current_bit = 0xFF;
1043 static uint8_t pulse_counter = 0;
1044 static IRSND_PAUSE_LEN pause_counter = 0;
1045 static uint8_t startbit_pulse_len = 0;
1046 static IRSND_PAUSE_LEN startbit_pause_len = 0;
1047 static uint8_t pulse_1_len = 0;
1048 static uint8_t pause_1_len = 0;
1049 static uint8_t pulse_0_len = 0;
1050 static uint8_t pause_0_len = 0;
1051 static uint8_t has_stop_bit = 0;
1052 static uint8_t new_frame = TRUE;
1053 static uint8_t complete_data_len = 0;
1054 static uint8_t n_repeat_frames = 0; // number of repetition frames
1055 static uint8_t n_auto_repetitions = 0; // number of auto_repetitions
1056 static uint8_t auto_repetition_counter = 0; // auto_repetition counter
1057 static uint16_t auto_repetition_pause_len = 0; // pause before auto_repetition, uint16_t!
1058 static uint16_t auto_repetition_pause_counter = 0; // pause before auto_repetition, uint16_t!
1059 static uint8_t repeat_counter = 0; // repeat counter
1060 static uint16_t repeat_frame_pause_len = 0; // pause before repeat, uint16_t!
1061 static uint16_t packet_repeat_pause_counter = 0; // pause before repeat, uint16_t!
1062 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1063 static uint8_t last_bit_value;
1064 #endif
1065 static uint8_t pulse_len = 0xFF;
1066 static IRSND_PAUSE_LEN pause_len = 0xFF;
1067
1068 if (irsnd_busy)
1069 {
1070 if (current_bit == 0xFF && new_frame) // start of transmission...
1071 {
1072 if (auto_repetition_counter > 0)
1073 {
1074 auto_repetition_pause_counter++;
1075
1076 if (auto_repetition_pause_counter >= auto_repetition_pause_len)
1077 {
1078 auto_repetition_pause_counter = 0;
1079
1080 if (irsnd_protocol == IRMP_DENON_PROTOCOL) // n'th denon frame
1081 {
1082 current_bit = 16;
1083 complete_data_len = 2 * DENON_COMPLETE_DATA_LEN + 1;
1084 }
1085 else if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL) // n'th grundig frame
1086 {
1087 current_bit = 15;
1088 complete_data_len = 16 + GRUNDIG_COMPLETE_DATA_LEN;
1089 }
1090 else if (irsnd_protocol == IRMP_IR60_PROTOCOL) // n'th IR60 frame
1091 {
1092 current_bit = 7;
1093 complete_data_len = 2 * IR60_COMPLETE_DATA_LEN + 1;
1094 }
1095 else if (irsnd_protocol == IRMP_NOKIA_PROTOCOL) // n'th nokia frame
1096 {
1097 if (auto_repetition_counter + 1 < n_auto_repetitions)
1098 {
1099 current_bit = 23;
1100 complete_data_len = 24 + NOKIA_COMPLETE_DATA_LEN;
1101 }
1102 else // nokia stop frame
1103 {
1104 current_bit = 0xFF;
1105 complete_data_len = NOKIA_COMPLETE_DATA_LEN;
1106 }
1107 }
1108 }
1109 else
1110 {
1111 #ifdef DEBUG
1112 if (irsnd_is_on)
1113 {
1114 putchar ('0');
1115 }
1116 else
1117 {
1118 putchar ('1');
1119 }
1120 #endif
1121 return irsnd_busy;
1122 }
1123 }
1124 #if 0
1125 else if (repeat_counter > 0 && packet_repeat_pause_counter < repeat_frame_pause_len)
1126 #else
1127 else if (packet_repeat_pause_counter < repeat_frame_pause_len)
1128 #endif
1129 {
1130 packet_repeat_pause_counter++;
1131
1132 #ifdef DEBUG
1133 if (irsnd_is_on)
1134 {
1135 putchar ('0');
1136 }
1137 else
1138 {
1139 putchar ('1');
1140 }
1141 #endif
1142 return irsnd_busy;
1143 }
1144 else
1145 {
1146
1147 if (send_trailer)
1148 {
1149 irsnd_busy = FALSE;
1150 send_trailer = FALSE;
1151 return irsnd_busy;
1152 }
1153
1154 n_repeat_frames = irsnd_repeat;
1155
1156 if (n_repeat_frames == IRSND_ENDLESS_REPETITION)
1157 {
1158 n_repeat_frames = 255;
1159 }
1160
1161 packet_repeat_pause_counter = 0;
1162 pulse_counter = 0;
1163 pause_counter = 0;
1164
1165 switch (irsnd_protocol)
1166 {
1167 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
1168 case IRMP_SIRCS_PROTOCOL:
1169 {
1170 startbit_pulse_len = SIRCS_START_BIT_PULSE_LEN;
1171 startbit_pause_len = SIRCS_START_BIT_PAUSE_LEN - 1;
1172 pulse_1_len = SIRCS_1_PULSE_LEN;
1173 pause_1_len = SIRCS_PAUSE_LEN - 1;
1174 pulse_0_len = SIRCS_0_PULSE_LEN;
1175 pause_0_len = SIRCS_PAUSE_LEN - 1;
1176 has_stop_bit = SIRCS_STOP_BIT;
1177 complete_data_len = SIRCS_MINIMUM_DATA_LEN + sircs_additional_bitlen;
1178 n_auto_repetitions = (repeat_counter == 0) ? SIRCS_FRAMES : 1; // 3 frames auto repetition if first frame
1179 auto_repetition_pause_len = SIRCS_AUTO_REPETITION_PAUSE_LEN; // 25ms pause
1180 repeat_frame_pause_len = SIRCS_FRAME_REPEAT_PAUSE_LEN;
1181 irsnd_set_freq (IRSND_FREQ_40_KHZ);
1182 break;
1183 }
1184 #endif
1185 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
1186 case IRMP_NEC_PROTOCOL:
1187 {
1188 startbit_pulse_len = NEC_START_BIT_PULSE_LEN;
1189
1190 if (repeat_counter > 0)
1191 {
1192 startbit_pause_len = NEC_REPEAT_START_BIT_PAUSE_LEN - 1;
1193 complete_data_len = 0;
1194 }
1195 else
1196 {
1197 startbit_pause_len = NEC_START_BIT_PAUSE_LEN - 1;
1198 complete_data_len = NEC_COMPLETE_DATA_LEN;
1199 }
1200
1201 pulse_1_len = NEC_PULSE_LEN;
1202 pause_1_len = NEC_1_PAUSE_LEN - 1;
1203 pulse_0_len = NEC_PULSE_LEN;
1204 pause_0_len = NEC_0_PAUSE_LEN - 1;
1205 has_stop_bit = NEC_STOP_BIT;
1206 n_auto_repetitions = 1; // 1 frame
1207 auto_repetition_pause_len = 0;
1208 repeat_frame_pause_len = NEC_FRAME_REPEAT_PAUSE_LEN;
1209 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1210 break;
1211 }
1212 #endif
1213 #if IRSND_SUPPORT_NEC16_PROTOCOL == 1
1214 case IRMP_NEC16_PROTOCOL:
1215 {
1216 startbit_pulse_len = NEC_START_BIT_PULSE_LEN;
1217 startbit_pause_len = NEC_START_BIT_PAUSE_LEN - 1;
1218 pulse_1_len = NEC_PULSE_LEN;
1219 pause_1_len = NEC_1_PAUSE_LEN - 1;
1220 pulse_0_len = NEC_PULSE_LEN;
1221 pause_0_len = NEC_0_PAUSE_LEN - 1;
1222 has_stop_bit = NEC_STOP_BIT;
1223 complete_data_len = NEC16_COMPLETE_DATA_LEN + 1; // 1 more: sync bit
1224 n_auto_repetitions = 1; // 1 frame
1225 auto_repetition_pause_len = 0;
1226 repeat_frame_pause_len = NEC_FRAME_REPEAT_PAUSE_LEN;
1227 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1228 break;
1229 }
1230 #endif
1231 #if IRSND_SUPPORT_NEC42_PROTOCOL == 1
1232 case IRMP_NEC42_PROTOCOL:
1233 {
1234 startbit_pulse_len = NEC_START_BIT_PULSE_LEN;
1235 startbit_pause_len = NEC_START_BIT_PAUSE_LEN - 1;
1236 pulse_1_len = NEC_PULSE_LEN;
1237 pause_1_len = NEC_1_PAUSE_LEN - 1;
1238 pulse_0_len = NEC_PULSE_LEN;
1239 pause_0_len = NEC_0_PAUSE_LEN - 1;
1240 has_stop_bit = NEC_STOP_BIT;
1241 complete_data_len = NEC42_COMPLETE_DATA_LEN;
1242 n_auto_repetitions = 1; // 1 frame
1243 auto_repetition_pause_len = 0;
1244 repeat_frame_pause_len = NEC_FRAME_REPEAT_PAUSE_LEN;
1245 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1246 break;
1247 }
1248 #endif
1249 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
1250 case IRMP_SAMSUNG_PROTOCOL:
1251 {
1252 startbit_pulse_len = SAMSUNG_START_BIT_PULSE_LEN;
1253 startbit_pause_len = SAMSUNG_START_BIT_PAUSE_LEN - 1;
1254 pulse_1_len = SAMSUNG_PULSE_LEN;
1255 pause_1_len = SAMSUNG_1_PAUSE_LEN - 1;
1256 pulse_0_len = SAMSUNG_PULSE_LEN;
1257 pause_0_len = SAMSUNG_0_PAUSE_LEN - 1;
1258 has_stop_bit = SAMSUNG_STOP_BIT;
1259 complete_data_len = SAMSUNG_COMPLETE_DATA_LEN;
1260 n_auto_repetitions = 1; // 1 frame
1261 auto_repetition_pause_len = 0;
1262 repeat_frame_pause_len = SAMSUNG_FRAME_REPEAT_PAUSE_LEN;
1263 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1264 break;
1265 }
1266
1267 case IRMP_SAMSUNG32_PROTOCOL:
1268 {
1269 startbit_pulse_len = SAMSUNG_START_BIT_PULSE_LEN;
1270 startbit_pause_len = SAMSUNG_START_BIT_PAUSE_LEN - 1;
1271 pulse_1_len = SAMSUNG_PULSE_LEN;
1272 pause_1_len = SAMSUNG_1_PAUSE_LEN - 1;
1273 pulse_0_len = SAMSUNG_PULSE_LEN;
1274 pause_0_len = SAMSUNG_0_PAUSE_LEN - 1;
1275 has_stop_bit = SAMSUNG_STOP_BIT;
1276 complete_data_len = SAMSUNG32_COMPLETE_DATA_LEN;
1277 n_auto_repetitions = SAMSUNG32_FRAMES; // 2 frames
1278 auto_repetition_pause_len = SAMSUNG32_AUTO_REPETITION_PAUSE_LEN; // 47 ms pause
1279 repeat_frame_pause_len = SAMSUNG32_FRAME_REPEAT_PAUSE_LEN;
1280 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1281 break;
1282 }
1283 #endif
1284 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
1285 case IRMP_MATSUSHITA_PROTOCOL:
1286 {
1287 startbit_pulse_len = MATSUSHITA_START_BIT_PULSE_LEN;
1288 startbit_pause_len = MATSUSHITA_START_BIT_PAUSE_LEN - 1;
1289 pulse_1_len = MATSUSHITA_PULSE_LEN;
1290 pause_1_len = MATSUSHITA_1_PAUSE_LEN - 1;
1291 pulse_0_len = MATSUSHITA_PULSE_LEN;
1292 pause_0_len = MATSUSHITA_0_PAUSE_LEN - 1;
1293 has_stop_bit = MATSUSHITA_STOP_BIT;
1294 complete_data_len = MATSUSHITA_COMPLETE_DATA_LEN;
1295 n_auto_repetitions = 1; // 1 frame
1296 auto_repetition_pause_len = 0;
1297 repeat_frame_pause_len = MATSUSHITA_FRAME_REPEAT_PAUSE_LEN;
1298 irsnd_set_freq (IRSND_FREQ_36_KHZ);
1299 break;
1300 }
1301 #endif
1302 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1
1303 case IRMP_KASEIKYO_PROTOCOL:
1304 {
1305 startbit_pulse_len = KASEIKYO_START_BIT_PULSE_LEN;
1306 startbit_pause_len = KASEIKYO_START_BIT_PAUSE_LEN - 1;
1307 pulse_1_len = KASEIKYO_PULSE_LEN;
1308 pause_1_len = KASEIKYO_1_PAUSE_LEN - 1;
1309 pulse_0_len = KASEIKYO_PULSE_LEN;
1310 pause_0_len = KASEIKYO_0_PAUSE_LEN - 1;
1311 has_stop_bit = KASEIKYO_STOP_BIT;
1312 complete_data_len = KASEIKYO_COMPLETE_DATA_LEN;
1313 n_auto_repetitions = (repeat_counter == 0) ? KASEIKYO_FRAMES : 1; // 2 frames auto repetition if first frame
1314 auto_repetition_pause_len = KASEIKYO_AUTO_REPETITION_PAUSE_LEN; // 75 ms pause
1315 repeat_frame_pause_len = KASEIKYO_FRAME_REPEAT_PAUSE_LEN;
1316 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1317 break;
1318 }
1319 #endif
1320 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
1321 case IRMP_RECS80_PROTOCOL:
1322 {
1323 startbit_pulse_len = RECS80_START_BIT_PULSE_LEN;
1324 startbit_pause_len = RECS80_START_BIT_PAUSE_LEN - 1;
1325 pulse_1_len = RECS80_PULSE_LEN;
1326 pause_1_len = RECS80_1_PAUSE_LEN - 1;
1327 pulse_0_len = RECS80_PULSE_LEN;
1328 pause_0_len = RECS80_0_PAUSE_LEN - 1;
1329 has_stop_bit = RECS80_STOP_BIT;
1330 complete_data_len = RECS80_COMPLETE_DATA_LEN;
1331 n_auto_repetitions = 1; // 1 frame
1332 auto_repetition_pause_len = 0;
1333 repeat_frame_pause_len = RECS80_FRAME_REPEAT_PAUSE_LEN;
1334 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1335 break;
1336 }
1337 #endif
1338 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
1339 case IRMP_RECS80EXT_PROTOCOL:
1340 {
1341 startbit_pulse_len = RECS80EXT_START_BIT_PULSE_LEN;
1342 startbit_pause_len = RECS80EXT_START_BIT_PAUSE_LEN - 1;
1343 pulse_1_len = RECS80EXT_PULSE_LEN;
1344 pause_1_len = RECS80EXT_1_PAUSE_LEN - 1;
1345 pulse_0_len = RECS80EXT_PULSE_LEN;
1346 pause_0_len = RECS80EXT_0_PAUSE_LEN - 1;
1347 has_stop_bit = RECS80EXT_STOP_BIT;
1348 complete_data_len = RECS80EXT_COMPLETE_DATA_LEN;
1349 n_auto_repetitions = 1; // 1 frame
1350 auto_repetition_pause_len = 0;
1351 repeat_frame_pause_len = RECS80EXT_FRAME_REPEAT_PAUSE_LEN;
1352 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1353 break;
1354 }
1355 #endif
1356 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
1357 case IRMP_RC5_PROTOCOL:
1358 {
1359 startbit_pulse_len = RC5_BIT_LEN;
1360 startbit_pause_len = RC5_BIT_LEN;
1361 pulse_len = RC5_BIT_LEN;
1362 pause_len = RC5_BIT_LEN;
1363 has_stop_bit = RC5_STOP_BIT;
1364 complete_data_len = RC5_COMPLETE_DATA_LEN;
1365 n_auto_repetitions = 1; // 1 frame
1366 auto_repetition_pause_len = 0;
1367 repeat_frame_pause_len = RC5_FRAME_REPEAT_PAUSE_LEN;
1368 irsnd_set_freq (IRSND_FREQ_36_KHZ);
1369 break;
1370 }
1371 #endif
1372 #if IRSND_SUPPORT_RC6_PROTOCOL == 1
1373 case IRMP_RC6_PROTOCOL:
1374 {
1375 startbit_pulse_len = RC6_START_BIT_PULSE_LEN;
1376 startbit_pause_len = RC6_START_BIT_PAUSE_LEN - 1;
1377 pulse_len = RC6_BIT_LEN;
1378 pause_len = RC6_BIT_LEN;
1379 has_stop_bit = RC6_STOP_BIT;
1380 complete_data_len = RC6_COMPLETE_DATA_LEN_SHORT;
1381 n_auto_repetitions = 1; // 1 frame
1382 auto_repetition_pause_len = 0;
1383 repeat_frame_pause_len = RC6_FRAME_REPEAT_PAUSE_LEN;
1384 irsnd_set_freq (IRSND_FREQ_36_KHZ);
1385 break;
1386 }
1387 #endif
1388 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1
1389 case IRMP_RC6A_PROTOCOL:
1390 {
1391 startbit_pulse_len = RC6_START_BIT_PULSE_LEN;
1392 startbit_pause_len = RC6_START_BIT_PAUSE_LEN - 1;
1393 pulse_len = RC6_BIT_LEN;
1394 pause_len = RC6_BIT_LEN;
1395 has_stop_bit = RC6_STOP_BIT;
1396 complete_data_len = RC6_COMPLETE_DATA_LEN_LONG;
1397 n_auto_repetitions = 1; // 1 frame
1398 auto_repetition_pause_len = 0;
1399 repeat_frame_pause_len = RC6_FRAME_REPEAT_PAUSE_LEN;
1400 irsnd_set_freq (IRSND_FREQ_36_KHZ);
1401 break;
1402 }
1403 #endif
1404 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
1405 case IRMP_DENON_PROTOCOL:
1406 {
1407 startbit_pulse_len = 0x00;
1408 startbit_pause_len = 0x00;
1409 pulse_1_len = DENON_PULSE_LEN;
1410 pause_1_len = DENON_1_PAUSE_LEN - 1;
1411 pulse_0_len = DENON_PULSE_LEN;
1412 pause_0_len = DENON_0_PAUSE_LEN - 1;
1413 has_stop_bit = DENON_STOP_BIT;
1414 complete_data_len = DENON_COMPLETE_DATA_LEN;
1415 n_auto_repetitions = DENON_FRAMES; // 2 frames, 2nd with inverted command
1416 auto_repetition_pause_len = DENON_AUTO_REPETITION_PAUSE_LEN; // 65 ms pause after 1st frame
1417 repeat_frame_pause_len = DENON_FRAME_REPEAT_PAUSE_LEN;
1418 irsnd_set_freq (IRSND_FREQ_36_KHZ); // in theory 32kHz, in practice 36kHz is better
1419 break;
1420 }
1421 #endif
1422 #if IRSND_SUPPORT_THOMSON_PROTOCOL == 1
1423 case IRMP_THOMSON_PROTOCOL:
1424 {
1425 startbit_pulse_len = 0x00;
1426 startbit_pause_len = 0x00;
1427 pulse_1_len = THOMSON_PULSE_LEN;
1428 pause_1_len = THOMSON_1_PAUSE_LEN - 1;
1429 pulse_0_len = THOMSON_PULSE_LEN;
1430 pause_0_len = THOMSON_0_PAUSE_LEN - 1;
1431 has_stop_bit = THOMSON_STOP_BIT;
1432 complete_data_len = THOMSON_COMPLETE_DATA_LEN;
1433 n_auto_repetitions = THOMSON_FRAMES; // only 1 frame
1434 auto_repetition_pause_len = THOMSON_AUTO_REPETITION_PAUSE_LEN;
1435 repeat_frame_pause_len = DENON_FRAME_REPEAT_PAUSE_LEN;
1436 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1437 break;
1438 }
1439 #endif
1440 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
1441 case IRMP_NUBERT_PROTOCOL:
1442 {
1443 startbit_pulse_len = NUBERT_START_BIT_PULSE_LEN;
1444 startbit_pause_len = NUBERT_START_BIT_PAUSE_LEN - 1;
1445 pulse_1_len = NUBERT_1_PULSE_LEN;
1446 pause_1_len = NUBERT_1_PAUSE_LEN - 1;
1447 pulse_0_len = NUBERT_0_PULSE_LEN;
1448 pause_0_len = NUBERT_0_PAUSE_LEN - 1;
1449 has_stop_bit = NUBERT_STOP_BIT;
1450 complete_data_len = NUBERT_COMPLETE_DATA_LEN;
1451 n_auto_repetitions = NUBERT_FRAMES; // 2 frames
1452 auto_repetition_pause_len = NUBERT_AUTO_REPETITION_PAUSE_LEN; // 35 ms pause
1453 repeat_frame_pause_len = NUBERT_FRAME_REPEAT_PAUSE_LEN;
1454 irsnd_set_freq (IRSND_FREQ_36_KHZ);
1455 break;
1456 }
1457 #endif
1458 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1459 case IRMP_BANG_OLUFSEN_PROTOCOL:
1460 {
1461 startbit_pulse_len = BANG_OLUFSEN_START_BIT1_PULSE_LEN;
1462 startbit_pause_len = BANG_OLUFSEN_START_BIT1_PAUSE_LEN - 1;
1463 pulse_1_len = BANG_OLUFSEN_PULSE_LEN;
1464 pause_1_len = BANG_OLUFSEN_1_PAUSE_LEN - 1;
1465 pulse_0_len = BANG_OLUFSEN_PULSE_LEN;
1466 pause_0_len = BANG_OLUFSEN_0_PAUSE_LEN - 1;
1467 has_stop_bit = BANG_OLUFSEN_STOP_BIT;
1468 complete_data_len = BANG_OLUFSEN_COMPLETE_DATA_LEN;
1469 n_auto_repetitions = 1; // 1 frame
1470 auto_repetition_pause_len = 0;
1471 repeat_frame_pause_len = BANG_OLUFSEN_FRAME_REPEAT_PAUSE_LEN;
1472 last_bit_value = 0;
1473 irsnd_set_freq (IRSND_FREQ_455_KHZ);
1474 break;
1475 }
1476 #endif
1477 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
1478 case IRMP_GRUNDIG_PROTOCOL:
1479 {
1480 startbit_pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1481 startbit_pause_len = GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN - 1;
1482 pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1483 pause_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1484 has_stop_bit = GRUNDIG_NOKIA_IR60_STOP_BIT;
1485 complete_data_len = GRUNDIG_COMPLETE_DATA_LEN;
1486 n_auto_repetitions = GRUNDIG_FRAMES; // 2 frames
1487 auto_repetition_pause_len = GRUNDIG_AUTO_REPETITION_PAUSE_LEN; // 20m sec pause
1488 repeat_frame_pause_len = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN; // 117 msec pause
1489 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1490 break;
1491 }
1492 #endif
1493 #if IRSND_SUPPORT_IR60_PROTOCOL == 1
1494 case IRMP_IR60_PROTOCOL:
1495 {
1496 startbit_pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1497 startbit_pause_len = GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN - 1;
1498 pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1499 pause_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1500 has_stop_bit = GRUNDIG_NOKIA_IR60_STOP_BIT;
1501 complete_data_len = IR60_COMPLETE_DATA_LEN;
1502 n_auto_repetitions = IR60_FRAMES; // 2 frames
1503 auto_repetition_pause_len = IR60_AUTO_REPETITION_PAUSE_LEN; // 20m sec pause
1504 repeat_frame_pause_len = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN; // 117 msec pause
1505 irsnd_set_freq (IRSND_FREQ_30_KHZ);
1506 break;
1507 }
1508 #endif
1509 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1510 case IRMP_NOKIA_PROTOCOL:
1511 {
1512 startbit_pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1513 startbit_pause_len = GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN - 1;
1514 pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1515 pause_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1516 has_stop_bit = GRUNDIG_NOKIA_IR60_STOP_BIT;
1517 complete_data_len = NOKIA_COMPLETE_DATA_LEN;
1518 n_auto_repetitions = NOKIA_FRAMES; // 2 frames
1519 auto_repetition_pause_len = NOKIA_AUTO_REPETITION_PAUSE_LEN; // 20 msec pause
1520 repeat_frame_pause_len = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN; // 117 msec pause
1521 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1522 break;
1523 }
1524 #endif
1525 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
1526 case IRMP_SIEMENS_PROTOCOL:
1527 {
1528 startbit_pulse_len = SIEMENS_BIT_LEN;
1529 startbit_pause_len = SIEMENS_BIT_LEN;
1530 pulse_len = SIEMENS_BIT_LEN;
1531 pause_len = SIEMENS_BIT_LEN;
1532 has_stop_bit = SIEMENS_OR_RUWIDO_STOP_BIT;
1533 complete_data_len = SIEMENS_COMPLETE_DATA_LEN - 1;
1534 n_auto_repetitions = 1; // 1 frame
1535 auto_repetition_pause_len = 0;
1536 repeat_frame_pause_len = SIEMENS_FRAME_REPEAT_PAUSE_LEN;
1537 irsnd_set_freq (IRSND_FREQ_36_KHZ);
1538 break;
1539 }
1540 #endif
1541 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
1542 case IRMP_FDC_PROTOCOL:
1543 {
1544 startbit_pulse_len = FDC_START_BIT_PULSE_LEN;
1545 startbit_pause_len = FDC_START_BIT_PAUSE_LEN - 1;
1546 complete_data_len = FDC_COMPLETE_DATA_LEN;
1547 pulse_1_len = FDC_PULSE_LEN;
1548 pause_1_len = FDC_1_PAUSE_LEN - 1;
1549 pulse_0_len = FDC_PULSE_LEN;
1550 pause_0_len = FDC_0_PAUSE_LEN - 1;
1551 has_stop_bit = FDC_STOP_BIT;
1552 n_auto_repetitions = 1; // 1 frame
1553 auto_repetition_pause_len = 0;
1554 repeat_frame_pause_len = FDC_FRAME_REPEAT_PAUSE_LEN;
1555 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1556 break;
1557 }
1558 #endif
1559 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1
1560 case IRMP_RCCAR_PROTOCOL:
1561 {
1562 startbit_pulse_len = RCCAR_START_BIT_PULSE_LEN;
1563 startbit_pause_len = RCCAR_START_BIT_PAUSE_LEN - 1;
1564 complete_data_len = RCCAR_COMPLETE_DATA_LEN;
1565 pulse_1_len = RCCAR_PULSE_LEN;
1566 pause_1_len = RCCAR_1_PAUSE_LEN - 1;
1567 pulse_0_len = RCCAR_PULSE_LEN;
1568 pause_0_len = RCCAR_0_PAUSE_LEN - 1;
1569 has_stop_bit = RCCAR_STOP_BIT;
1570 n_auto_repetitions = 1; // 1 frame
1571 auto_repetition_pause_len = 0;
1572 repeat_frame_pause_len = RCCAR_FRAME_REPEAT_PAUSE_LEN;
1573 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1574 break;
1575 }
1576 #endif
1577 #if IRSND_SUPPORT_JVC_PROTOCOL == 1
1578 case IRMP_JVC_PROTOCOL:
1579 {
1580 if (repeat_counter != 0) // skip start bit if repetition frame
1581 {
1582 current_bit = 0;
1583 }
1584
1585 startbit_pulse_len = JVC_START_BIT_PULSE_LEN;
1586 startbit_pause_len = JVC_START_BIT_PAUSE_LEN - 1;
1587 complete_data_len = JVC_COMPLETE_DATA_LEN;
1588 pulse_1_len = JVC_PULSE_LEN;
1589 pause_1_len = JVC_1_PAUSE_LEN - 1;
1590 pulse_0_len = JVC_PULSE_LEN;
1591 pause_0_len = JVC_0_PAUSE_LEN - 1;
1592 has_stop_bit = JVC_STOP_BIT;
1593 n_auto_repetitions = 1; // 1 frame
1594 auto_repetition_pause_len = 0;
1595 repeat_frame_pause_len = JVC_FRAME_REPEAT_PAUSE_LEN;
1596 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1597 break;
1598 }
1599 #endif
1600 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
1601 case IRMP_NIKON_PROTOCOL:
1602 {
1603 startbit_pulse_len = NIKON_START_BIT_PULSE_LEN;
1604 startbit_pause_len = 271 - 1; // NIKON_START_BIT_PAUSE_LEN;
1605 complete_data_len = NIKON_COMPLETE_DATA_LEN;
1606 pulse_1_len = NIKON_PULSE_LEN;
1607 pause_1_len = NIKON_1_PAUSE_LEN - 1;
1608 pulse_0_len = NIKON_PULSE_LEN;
1609 pause_0_len = NIKON_0_PAUSE_LEN - 1;
1610 has_stop_bit = NIKON_STOP_BIT;
1611 n_auto_repetitions = 1; // 1 frame
1612 auto_repetition_pause_len = 0;
1613 repeat_frame_pause_len = NIKON_FRAME_REPEAT_PAUSE_LEN;
1614 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1615 break;
1616 }
1617 #endif
1618 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1
1619 case IRMP_LEGO_PROTOCOL:
1620 {
1621 startbit_pulse_len = LEGO_START_BIT_PULSE_LEN;
1622 startbit_pause_len = LEGO_START_BIT_PAUSE_LEN - 1;
1623 complete_data_len = LEGO_COMPLETE_DATA_LEN;
1624 pulse_1_len = LEGO_PULSE_LEN;
1625 pause_1_len = LEGO_1_PAUSE_LEN - 1;
1626 pulse_0_len = LEGO_PULSE_LEN;
1627 pause_0_len = LEGO_0_PAUSE_LEN - 1;
1628 has_stop_bit = LEGO_STOP_BIT;
1629 n_auto_repetitions = 1; // 1 frame
1630 auto_repetition_pause_len = 0;
1631 repeat_frame_pause_len = LEGO_FRAME_REPEAT_PAUSE_LEN;
1632 irsnd_set_freq (IRSND_FREQ_38_KHZ);
1633 break;
1634 }
1635 #endif
1636 default:
1637 {
1638 irsnd_busy = FALSE;
1639 break;
1640 }
1641 }
1642 }
1643 }
1644
1645 if (irsnd_busy)
1646 {
1647 new_frame = FALSE;
1648
1649 switch (irsnd_protocol)
1650 {
1651 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
1652 case IRMP_SIRCS_PROTOCOL:
1653 #endif
1654 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
1655 case IRMP_NEC_PROTOCOL:
1656 #endif
1657 #if IRSND_SUPPORT_NEC16_PROTOCOL == 1
1658 case IRMP_NEC16_PROTOCOL:
1659 #endif
1660 #if IRSND_SUPPORT_NEC42_PROTOCOL == 1
1661 case IRMP_NEC42_PROTOCOL:
1662 #endif
1663 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
1664 case IRMP_SAMSUNG_PROTOCOL:
1665 case IRMP_SAMSUNG32_PROTOCOL:
1666 #endif
1667 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
1668 case IRMP_MATSUSHITA_PROTOCOL:
1669 #endif
1670 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1
1671 case IRMP_KASEIKYO_PROTOCOL:
1672 #endif
1673 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
1674 case IRMP_RECS80_PROTOCOL:
1675 #endif
1676 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
1677 case IRMP_RECS80EXT_PROTOCOL:
1678 #endif
1679 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
1680 case IRMP_DENON_PROTOCOL:
1681 #endif
1682 #if IRSND_SUPPORT_THOMSON_PROTOCOL == 1
1683 case IRMP_THOMSON_PROTOCOL:
1684 #endif
1685 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
1686 case IRMP_NUBERT_PROTOCOL:
1687 #endif
1688 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1689 case IRMP_BANG_OLUFSEN_PROTOCOL:
1690 #endif
1691 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
1692 case IRMP_FDC_PROTOCOL:
1693 #endif
1694 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1
1695 case IRMP_RCCAR_PROTOCOL:
1696 #endif
1697 #if IRSND_SUPPORT_JVC_PROTOCOL == 1
1698 case IRMP_JVC_PROTOCOL:
1699 #endif
1700 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
1701 case IRMP_NIKON_PROTOCOL:
1702 #endif
1703 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1
1704 case IRMP_LEGO_PROTOCOL:
1705 #endif
1706
1707
1708 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1 || IRSND_SUPPORT_NEC_PROTOCOL == 1 || IRSND_SUPPORT_NEC16_PROTOCOL == 1 || IRSND_SUPPORT_NEC42_PROTOCOL == 1 || \
1709 IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1 || IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1 || \
1710 IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1 || IRSND_SUPPORT_RECS80_PROTOCOL == 1 || IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1 || IRSND_SUPPORT_DENON_PROTOCOL == 1 || \
1711 IRSND_SUPPORT_NUBERT_PROTOCOL == 1 || IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 || IRSND_SUPPORT_FDC_PROTOCOL == 1 || IRSND_SUPPORT_RCCAR_PROTOCOL == 1 || \
1712 IRSND_SUPPORT_JVC_PROTOCOL == 1 || IRSND_SUPPORT_NIKON_PROTOCOL == 1 || IRSND_SUPPORT_LEGO_PROTOCOL == 1 || IRSND_SUPPORT_THOMSON_PROTOCOL == 1
1713 {
1714 if (pulse_counter == 0)
1715 {
1716 if (current_bit == 0xFF) // send start bit
1717 {
1718 pulse_len = startbit_pulse_len;
1719 pause_len = startbit_pause_len;
1720 }
1721 else if (current_bit < complete_data_len) // send n'th bit
1722 {
1723 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
1724 if (irsnd_protocol == IRMP_SAMSUNG_PROTOCOL)
1725 {
1726 if (current_bit < SAMSUNG_ADDRESS_LEN) // send address bits
1727 {
1728 pulse_len = SAMSUNG_PULSE_LEN;
1729 pause_len = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ?
1730 (SAMSUNG_1_PAUSE_LEN - 1) : (SAMSUNG_0_PAUSE_LEN - 1);
1731 }
1732 else if (current_bit == SAMSUNG_ADDRESS_LEN) // send SYNC bit (16th bit)
1733 {
1734 pulse_len = SAMSUNG_PULSE_LEN;
1735 pause_len = SAMSUNG_START_BIT_PAUSE_LEN - 1;
1736 }
1737 else if (current_bit < SAMSUNG_COMPLETE_DATA_LEN) // send n'th bit
1738 {
1739 uint8_t cur_bit = current_bit - 1; // sync skipped, offset = -1 !
1740
1741 pulse_len = SAMSUNG_PULSE_LEN;
1742 pause_len = (irsnd_buffer[cur_bit / 8] & (1<<(7-(cur_bit % 8)))) ?
1743 (SAMSUNG_1_PAUSE_LEN - 1) : (SAMSUNG_0_PAUSE_LEN - 1);
1744 }
1745 }
1746 else
1747 #endif
1748
1749 #if IRSND_SUPPORT_NEC16_PROTOCOL == 1
1750 if (irsnd_protocol == IRMP_NEC16_PROTOCOL)
1751 {
1752 if (current_bit < NEC16_ADDRESS_LEN) // send address bits
1753 {
1754 pulse_len = NEC_PULSE_LEN;
1755 pause_len = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ?
1756 (NEC_1_PAUSE_LEN - 1) : (NEC_0_PAUSE_LEN - 1);
1757 }
1758 else if (current_bit == NEC16_ADDRESS_LEN) // send SYNC bit (8th bit)
1759 {
1760 pulse_len = NEC_PULSE_LEN;
1761 pause_len = NEC_START_BIT_PAUSE_LEN - 1;
1762 }
1763 else if (current_bit < NEC16_COMPLETE_DATA_LEN + 1) // send n'th bit
1764 {
1765 uint8_t cur_bit = current_bit - 1; // sync skipped, offset = -1 !
1766
1767 pulse_len = NEC_PULSE_LEN;
1768 pause_len = (irsnd_buffer[cur_bit / 8] & (1<<(7-(cur_bit % 8)))) ?
1769 (NEC_1_PAUSE_LEN - 1) : (NEC_0_PAUSE_LEN - 1);
1770 }
1771 }
1772 else
1773 #endif
1774
1775 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1776 if (irsnd_protocol == IRMP_BANG_OLUFSEN_PROTOCOL)
1777 {
1778 if (current_bit == 0) // send 2nd start bit
1779 {
1780 pulse_len = BANG_OLUFSEN_START_BIT2_PULSE_LEN;
1781 pause_len = BANG_OLUFSEN_START_BIT2_PAUSE_LEN - 1;
1782 }
1783 else if (current_bit == 1) // send 3rd start bit
1784 {
1785 pulse_len = BANG_OLUFSEN_START_BIT3_PULSE_LEN;
1786 pause_len = BANG_OLUFSEN_START_BIT3_PAUSE_LEN - 1;
1787 }
1788 else if (current_bit == 2) // send 4th start bit
1789 {
1790 pulse_len = BANG_OLUFSEN_START_BIT2_PULSE_LEN;
1791 pause_len = BANG_OLUFSEN_START_BIT2_PAUSE_LEN - 1;
1792 }
1793 else if (current_bit == 19) // send trailer bit
1794 {
1795 pulse_len = BANG_OLUFSEN_PULSE_LEN;
1796 pause_len = BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN - 1;
1797 }
1798 else if (current_bit < BANG_OLUFSEN_COMPLETE_DATA_LEN) // send n'th bit
1799 {
1800 uint8_t cur_bit_value = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? 1 : 0;
1801 pulse_len = BANG_OLUFSEN_PULSE_LEN;
1802
1803 if (cur_bit_value == last_bit_value)
1804 {
1805 pause_len = BANG_OLUFSEN_R_PAUSE_LEN - 1;
1806 }
1807 else
1808 {
1809 pause_len = cur_bit_value ? (BANG_OLUFSEN_1_PAUSE_LEN - 1) : (BANG_OLUFSEN_0_PAUSE_LEN - 1);
1810 last_bit_value = cur_bit_value;
1811 }
1812 }
1813 }
1814 else
1815 #endif
1816 if (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8))))
1817 {
1818 pulse_len = pulse_1_len;
1819 pause_len = pause_1_len;
1820 }
1821 else
1822 {
1823 pulse_len = pulse_0_len;
1824 pause_len = pause_0_len;
1825 }
1826 }
1827 else if (has_stop_bit) // send stop bit
1828 {
1829 pulse_len = pulse_0_len;
1830
1831 if (auto_repetition_counter < n_auto_repetitions)
1832 {
1833 pause_len = pause_0_len;
1834 }
1835 else
1836 {
1837 pause_len = 255; // last frame: pause of 255
1838 }
1839 }
1840 }
1841
1842 if (pulse_counter < pulse_len)
1843 {
1844 if (pulse_counter == 0)
1845 {
1846 irsnd_on ();
1847 }
1848 pulse_counter++;
1849 }
1850 else if (pause_counter < pause_len)
1851 {
1852 if (pause_counter == 0)
1853 {
1854 irsnd_off ();
1855 }
1856 pause_counter++;
1857 }
1858 else
1859 {
1860 current_bit++;
1861
1862 if (current_bit >= complete_data_len + has_stop_bit)
1863 {
1864 current_bit = 0xFF;
1865 auto_repetition_counter++;
1866
1867 if (auto_repetition_counter == n_auto_repetitions)
1868 {
1869 irsnd_busy = FALSE;
1870 auto_repetition_counter = 0;
1871 }
1872 new_frame = TRUE;
1873 }
1874
1875 pulse_counter = 0;
1876 pause_counter = 0;
1877 }
1878 break;
1879 }
1880 #endif
1881
1882 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
1883 case IRMP_RC5_PROTOCOL:
1884 #endif
1885 #if IRSND_SUPPORT_RC6_PROTOCOL == 1
1886 case IRMP_RC6_PROTOCOL:
1887 #endif
1888 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1
1889 case IRMP_RC6A_PROTOCOL:
1890 #endif
1891 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
1892 case IRMP_SIEMENS_PROTOCOL:
1893 #endif
1894 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
1895 case IRMP_GRUNDIG_PROTOCOL:
1896 #endif
1897 #if IRSND_SUPPORT_IR60_PROTOCOL == 1
1898 case IRMP_IR60_PROTOCOL:
1899 #endif
1900 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1901 case IRMP_NOKIA_PROTOCOL:
1902 #endif
1903
1904 #if IRSND_SUPPORT_RC5_PROTOCOL == 1 || IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1 || IRSND_SUPPORT_SIEMENS_PROTOCOL == 1 || \
1905 IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_IR60_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1906 {
1907 if (pulse_counter == pulse_len && pause_counter == pause_len)
1908 {
1909 current_bit++;
1910
1911 if (current_bit >= complete_data_len)
1912 {
1913 current_bit = 0xFF;
1914
1915 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_IR60_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1916 if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL || irsnd_protocol == IRMP_IR60_PROTOCOL || irsnd_protocol == IRMP_NOKIA_PROTOCOL)
1917 {
1918 auto_repetition_counter++;
1919
1920 if (repeat_counter > 0)
1921 { // set 117 msec pause time
1922 auto_repetition_pause_len = GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN;
1923 }
1924
1925 if (repeat_counter < n_repeat_frames) // tricky: repeat n info frames per auto repetition before sending last stop frame
1926 {
1927 n_auto_repetitions++; // increment number of auto repetitions
1928 repeat_counter++;
1929 }
1930 else if (auto_repetition_counter == n_auto_repetitions)
1931 {
1932 irsnd_busy = FALSE;
1933 auto_repetition_counter = 0;
1934 }
1935 }
1936 else
1937 #endif
1938 {
1939 irsnd_busy = FALSE;
1940 }
1941
1942 new_frame = TRUE;
1943 irsnd_off ();
1944 }
1945
1946 pulse_counter = 0;
1947 pause_counter = 0;
1948 }
1949
1950 if (! new_frame)
1951 {
1952 uint8_t first_pulse;
1953
1954 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_IR60_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1955 if (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL || irsnd_protocol == IRMP_IR60_PROTOCOL || irsnd_protocol == IRMP_NOKIA_PROTOCOL)
1956 {
1957 if (current_bit == 0xFF || // start bit of start-frame
1958 (irsnd_protocol == IRMP_GRUNDIG_PROTOCOL && current_bit == 15) || // start bit of info-frame (Grundig)
1959 (irsnd_protocol == IRMP_IR60_PROTOCOL && current_bit == 7) || // start bit of data frame (IR60)
1960 (irsnd_protocol == IRMP_NOKIA_PROTOCOL && (current_bit == 23 || current_bit == 47))) // start bit of info- or stop-frame (Nokia)
1961 {
1962 pulse_len = startbit_pulse_len;
1963 pause_len = startbit_pause_len;
1964 first_pulse = TRUE;
1965 }
1966 else // send n'th bit
1967 {
1968 pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1969 pause_len = GRUNDIG_NOKIA_IR60_BIT_LEN;
1970 first_pulse = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? TRUE : FALSE;
1971 }
1972 }
1973 else // if (irsnd_protocol == IRMP_RC5_PROTOCOL || irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL ||
1974 // irsnd_protocol == IRMP_SIEMENS_PROTOCOL)
1975 #endif
1976 {
1977 if (current_bit == 0xFF) // 1 start bit
1978 {
1979 #if IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1
1980 if (irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL)
1981 {
1982 pulse_len = startbit_pulse_len;
1983 pause_len = startbit_pause_len;
1984 }
1985 #endif
1986 first_pulse = TRUE;
1987 }
1988 else // send n'th bit
1989 {
1990 #if IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1
1991 if (irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL)
1992 {
1993 pulse_len = RC6_BIT_LEN;
1994 pause_len = RC6_BIT_LEN;
1995
1996 if (irsnd_protocol == IRMP_RC6_PROTOCOL)
1997 {
1998 if (current_bit == 4) // toggle bit (double len)
1999 {
2000 pulse_len = 2 * RC6_BIT_LEN;
2001 pause_len = 2 * RC6_BIT_LEN;
2002 }
2003 }
2004 else // if (irsnd_protocol == IRMP_RC6A_PROTOCOL)
2005 {
2006 if (current_bit == 4) // toggle bit (double len)
2007 {
2008 pulse_len = 2 * RC6_BIT_LEN + RC6_BIT_LEN; // hack!
2009 pause_len = 2 * RC6_BIT_LEN;
2010 }
2011 else if (current_bit == 5) // toggle bit (double len)
2012 {
2013 pause_len = 2 * RC6_BIT_LEN;
2014 }
2015 }
2016 }
2017 #endif
2018 first_pulse = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? TRUE : FALSE;
2019 }
2020
2021 if (irsnd_protocol == IRMP_RC5_PROTOCOL)
2022 {
2023 first_pulse = first_pulse ? FALSE : TRUE;
2024 }
2025 }
2026
2027 if (first_pulse)
2028 {
2029 if (pulse_counter < pulse_len)
2030 {
2031 if (pulse_counter == 0)
2032 {
2033 irsnd_on ();
2034 }
2035 pulse_counter++;
2036 }
2037 else // if (pause_counter < pause_len)
2038 {
2039 if (pause_counter == 0)
2040 {
2041 irsnd_off ();
2042 }
2043 pause_counter++;
2044 }
2045 }
2046 else
2047 {
2048 if (pause_counter < pause_len)
2049 {
2050 if (pause_counter == 0)
2051 {
2052 irsnd_off ();
2053 }
2054 pause_counter++;
2055 }
2056 else // if (pulse_counter < pulse_len)
2057 {
2058 if (pulse_counter == 0)
2059 {
2060 irsnd_on ();
2061 }
2062 pulse_counter++;
2063 }
2064 }
2065 }
2066 break;
2067 }
2068 #endif // IRSND_SUPPORT_RC5_PROTOCOL == 1 || IRSND_SUPPORT_RC6_PROTOCOL == 1 || || IRSND_SUPPORT_RC6A_PROTOCOL == 1 || IRSND_SUPPORT_SIEMENS_PROTOCOL == 1 ||
2069 // IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_IR60_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
2070
2071 default:
2072 {
2073 irsnd_busy = FALSE;
2074 break;
2075 }
2076 }
2077 }
2078
2079 if (! irsnd_busy)
2080 {
2081 if (repeat_counter < n_repeat_frames)
2082 {
2083 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
2084 if (irsnd_protocol == IRMP_FDC_PROTOCOL)
2085 {
2086 irsnd_buffer[2] |= 0x0F;
2087 }
2088 #endif
2089 repeat_counter++;
2090 irsnd_busy = TRUE;
2091 }
2092 else
2093 {
2094 irsnd_busy = TRUE; //Rainer
2095 send_trailer = TRUE;
2096 n_repeat_frames = 0;
2097 repeat_counter = 0;
2098 }
2099 }
2100 }
2101
2102 #ifdef DEBUG
2103 if (irsnd_is_on)
2104 {
2105 putchar ('0');
2106 }
2107 else
2108 {
2109 putchar ('1');
2110 }
2111 #endif
2112
2113 return irsnd_busy;
2114 }
2115
2116 #ifdef DEBUG
2117
2118 // main function - for unix/linux + windows only!
2119 // AVR: see main.c!
2120 // Compile it under linux with:
2121 // cc irsnd.c -o irsnd
2122 //
2123 // usage: ./irsnd protocol hex-address hex-command >filename
2124
2125 int
2126 main (int argc, char ** argv)
2127 {
2128 int protocol;
2129 int address;
2130 int command;
2131 IRMP_DATA irmp_data;
2132
2133 if (argc != 4 && argc != 5)
2134 {
2135 fprintf (stderr, "usage: %s protocol hex-address hex-command [repeat] > filename\n", argv[0]);
2136 return 1;
2137 }
2138
2139 if (sscanf (argv[1], "%d", &protocol) == 1 &&
2140 sscanf (argv[2], "%x", &address) == 1 &&
2141 sscanf (argv[3], "%x", &command) == 1)
2142 {
2143 irmp_data.protocol = protocol;
2144 irmp_data.address = address;
2145 irmp_data.command = command;
2146
2147 if (argc == 5)
2148 {
2149 irmp_data.flags = atoi (argv[4]);
2150 }
2151 else
2152 {
2153 irmp_data.flags = 0;
2154 }
2155
2156 irsnd_init ();
2157
2158 (void) irsnd_send_data (&irmp_data, TRUE);
2159
2160 while (irsnd_busy)
2161 {
2162 irsnd_ISR ();
2163 }
2164
2165 putchar ('\n');
2166 }
2167 else
2168 {
2169 fprintf (stderr, "%s: wrong arguments\n", argv[0]);
2170 return 1;
2171 }
2172 return 0;
2173 }
2174
2175 #endif // DEBUG