1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
4 * Copyright (c) 2010-2011 Frank Meyer - frank(at)fli4l.de
6 * $Id: irsnd.c,v 1.35 2011/04/11 13:26:17 fm Exp $
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *---------------------------------------------------------------------------------------------------------------------------------------------------
15 #ifdef unix // test/debug on linux/unix
23 #define F_CPU 8000000L
27 #ifdef WIN32 // test/debug on windows
32 #define F_CPU 8000000L
33 typedef unsigned char uint8_t;
34 typedef unsigned short uint16_t;
46 #include <util/delay.h>
47 #include <avr/pgmspace.h>
54 #include "irsndconfig.h"
57 /*---------------------------------------------------------------------------------------------------------------------------------------------------
58 * ATmega pin definition of OC2 / OC2A / OC2B
59 *---------------------------------------------------------------------------------------------------------------------------------------------------
61 #if defined (__AVR_ATmega8__) // ATmega8 uses OC2 = PB3
62 #undef IRSND_OC2 // has no OC2A / OC2B
63 #define IRSND_OC2 0 // magic: use OC2
64 #define IRSND_PORT PORTB // port B
65 #define IRSND_DDR DDRB // ddr B
66 #define IRSND_BIT 3 // OC2A
68 #elif defined (__AVR_ATmega16__) \
69 || defined (__AVR_ATmega32__) // ATmega16|32 uses OC2 = PD7
70 #undef IRSND_OC2 // has no OC2A / OC2B
71 #define IRSND_OC2 0 // magic: use OC2
72 #define IRSND_PORT PORTD // port D
73 #define IRSND_DDR DDRD // ddr D
74 #define IRSND_BIT 7 // OC2
76 #elif defined (__AVR_ATmega162__) // ATmega162 uses OC2 = PB1
77 #undef IRSND_OC2 // has no OC2A / OC2B
78 #define IRSND_OC2 0 // magic: use OC2
79 #define IRSND_PORT PORTB // port B
80 #define IRSND_DDR DDRB // ddr B
81 #define IRSND_BIT 1 // OC2
83 #elif defined (__AVR_ATmega164__) \
84 || defined (__AVR_ATmega324__) \
85 || defined (__AVR_ATmega644__) \
86 || defined (__AVR_ATmega644P__) \
87 || defined (__AVR_ATmega1284__) // ATmega164|324|644|644P|1284 uses OC2A = PD7 or OC2B = PD6
88 #if IRSND_OC2 == 1 // OC2A
89 #define IRSND_PORT PORTD // port D
90 #define IRSND_DDR DDRD // ddr D
91 #define IRSND_BIT 7 // OC2A
92 #elif IRSND_OC2 == 2 // OC2B
93 #define IRSND_PORT PORTD // port D
94 #define IRSND_DDR DDRD // ddr D
95 #define IRSND_BIT 6 // OC2B
97 #error Wrong value for IRSND_OC2, choose 1 or 2 in irsndconfig.h
100 #elif defined (__AVR_ATmega48__) \
101 || defined (__AVR_ATmega88__) \
102 || defined (__AVR_ATmega168__) \
103 || defined (__AVR_ATmega168__) \
104 || defined (__AVR_ATmega328__) \
105 || defined (__AVR_ATmega328P__) // ATmega48|88|168|328P uses OC2A = PB3 or OC2B = PD3
106 #if IRSND_OC2 == 1 // OC2A
107 #define IRSND_PORT PORTB // port B
108 #define IRSND_DDR DDRB // ddr B
109 #define IRSND_BIT 3 // OC2A
110 #elif IRSND_OC2 == 2 // OC2B
111 #define IRSND_PORT PORTD // port D
112 #define IRSND_DDR DDRD // ddr D
113 #define IRSND_BIT 3 // OC2B
115 #error Wrong value for IRSND_OC2, choose 1 or 2 in irsndconfig.h
119 #if !defined (unix) && !defined (WIN32)
120 #error OC2A/OC2B not defined, please fill in definitions here.
121 #endif // unix, WIN32
124 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
125 typedef uint16_t IRSND_PAUSE_LEN
;
127 typedef uint8_t IRSND_PAUSE_LEN
;
130 /*---------------------------------------------------------------------------------------------------------------------------------------------------
132 *---------------------------------------------------------------------------------------------------------------------------------------------------
134 #define SIRCS_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME + 0.5)
135 #define SIRCS_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME + 0.5)
136 #define SIRCS_1_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME + 0.5)
137 #define SIRCS_0_PULSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME + 0.5)
138 #define SIRCS_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME + 0.5)
139 #define SIRCS_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIRCS_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
140 #define SIRCS_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIRCS_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
142 #define NEC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME + 0.5)
143 #define NEC_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME + 0.5)
144 #define NEC_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME + 0.5)
145 #define NEC_PULSE_LEN (uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME + 0.5)
146 #define NEC_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME + 0.5)
147 #define NEC_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME + 0.5)
148 #define NEC_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NEC_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
150 #define SAMSUNG_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME + 0.5)
151 #define SAMSUNG_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME + 0.5)
152 #define SAMSUNG_PULSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME + 0.5)
153 #define SAMSUNG_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME + 0.5)
154 #define SAMSUNG_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME + 0.5)
155 #define SAMSUNG_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
157 #define SAMSUNG32_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG32_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
158 #define SAMSUNG32_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SAMSUNG32_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
160 #define MATSUSHITA_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME + 0.5)
161 #define MATSUSHITA_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME + 0.5)
162 #define MATSUSHITA_PULSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME + 0.5)
163 #define MATSUSHITA_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME + 0.5)
164 #define MATSUSHITA_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME + 0.5)
165 #define MATSUSHITA_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * MATSUSHITA_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
167 #define KASEIKYO_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME + 0.5)
168 #define KASEIKYO_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME + 0.5)
169 #define KASEIKYO_PULSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME + 0.5)
170 #define KASEIKYO_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME + 0.5)
171 #define KASEIKYO_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME + 0.5)
172 #define KASEIKYO_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * KASEIKYO_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
173 #define KASEIKYO_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * KASEIKYO_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
175 #define RECS80_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME + 0.5)
176 #define RECS80_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME + 0.5)
177 #define RECS80_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME + 0.5)
178 #define RECS80_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME + 0.5)
179 #define RECS80_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME + 0.5)
180 #define RECS80_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RECS80_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
182 #define RC5_START_BIT_LEN (uint8_t)(F_INTERRUPTS * RC5_BIT_TIME + 0.5)
183 #define RC5_BIT_LEN (uint8_t)(F_INTERRUPTS * RC5_BIT_TIME + 0.5)
184 #define RC5_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RC5_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
186 #define RC6_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME + 0.5)
187 #define RC6_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME + 0.5)
188 #define RC6_TOGGLE_BIT_LEN (uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME + 0.5)
189 #define RC6_BIT_LEN (uint8_t)(F_INTERRUPTS * RC6_BIT_TIME + 0.5)
190 #define RC6_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RC6_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
192 #define DENON_PULSE_LEN (uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME + 0.5)
193 #define DENON_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME + 0.5)
194 #define DENON_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME + 0.5)
195 #define DENON_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * DENON_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
196 #define DENON_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * DENON_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
198 #define RECS80EXT_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME + 0.5)
199 #define RECS80EXT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME + 0.5)
200 #define RECS80EXT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME + 0.5)
201 #define RECS80EXT_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME + 0.5)
202 #define RECS80EXT_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME + 0.5)
203 #define RECS80EXT_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RECS80EXT_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
205 #define NUBERT_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME + 0.5)
206 #define NUBERT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME + 0.5)
207 #define NUBERT_1_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME + 0.5)
208 #define NUBERT_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME + 0.5)
209 #define NUBERT_0_PULSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME + 0.5)
210 #define NUBERT_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME + 0.5)
211 #define NUBERT_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NUBERT_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
212 #define NUBERT_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NUBERT_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
214 #define BANG_OLUFSEN_START_BIT1_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME + 0.5)
215 #define BANG_OLUFSEN_START_BIT1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME + 0.5)
216 #define BANG_OLUFSEN_START_BIT2_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME + 0.5)
217 #define BANG_OLUFSEN_START_BIT2_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME + 0.5)
218 #define BANG_OLUFSEN_START_BIT3_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME + 0.5)
219 #define BANG_OLUFSEN_START_BIT3_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME + 0.5)
220 #define BANG_OLUFSEN_PULSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME + 0.5)
221 #define BANG_OLUFSEN_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME + 0.5)
222 #define BANG_OLUFSEN_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME + 0.5)
223 #define BANG_OLUFSEN_R_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME + 0.5)
224 #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME + 0.5)
225 #define BANG_OLUFSEN_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * BANG_OLUFSEN_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
227 #define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN (uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME + 0.5)
228 #define GRUNDIG_NOKIA_IR60_BIT_LEN (uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME + 0.5)
229 #define GRUNDIG_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * GRUNDIG_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
230 #define NOKIA_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NOKIA_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
231 #define GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
233 #define SIEMENS_START_BIT_LEN (uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME + 0.5)
234 #define SIEMENS_BIT_LEN (uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME + 0.5)
235 #define SIEMENS_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
237 #define IRSND_FREQ_32_KHZ (uint8_t) ((F_CPU / 32000 / 2) - 1)
238 #define IRSND_FREQ_36_KHZ (uint8_t) ((F_CPU / 36000 / 2) - 1)
239 #define IRSND_FREQ_38_KHZ (uint8_t) ((F_CPU / 38000 / 2) - 1)
240 #define IRSND_FREQ_40_KHZ (uint8_t) ((F_CPU / 40000 / 2) - 1)
241 #define IRSND_FREQ_56_KHZ (uint8_t) ((F_CPU / 56000 / 2) - 1)
242 #define IRSND_FREQ_455_KHZ (uint8_t) ((F_CPU / 455000 / 2) - 1)
244 #define FDC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME + 0.5)
245 #define FDC_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME + 0.5)
246 #define FDC_PULSE_LEN (uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME + 0.5)
247 #define FDC_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME + 0.5)
248 #define FDC_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME + 0.5)
249 #define FDC_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * FDC_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
251 #define RCCAR_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME + 0.5)
252 #define RCCAR_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME + 0.5)
253 #define RCCAR_PULSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME + 0.5)
254 #define RCCAR_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME + 0.5)
255 #define RCCAR_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME + 0.5)
256 #define RCCAR_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * RCCAR_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
258 #define JVC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME + 0.5)
259 #define JVC_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * JVC_START_BIT_PAUSE_TIME + 0.5)
260 #define JVC_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * JVC_REPEAT_START_BIT_PAUSE_TIME + 0.5)
261 #define JVC_PULSE_LEN (uint8_t)(F_INTERRUPTS * JVC_PULSE_TIME + 0.5)
262 #define JVC_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * JVC_1_PAUSE_TIME + 0.5)
263 #define JVC_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * JVC_0_PAUSE_TIME + 0.5)
264 #define JVC_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * JVC_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
266 #define NIKON_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_START_BIT_PULSE_TIME + 0.5)
267 #define NIKON_START_BIT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NIKON_START_BIT_PAUSE_TIME + 0.5)
268 #define NIKON_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_REPEAT_START_BIT_PAUSE_TIME + 0.5)
269 #define NIKON_PULSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_PULSE_TIME + 0.5)
270 #define NIKON_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME + 0.5)
271 #define NIKON_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME + 0.5)
272 #define NIKON_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NIKON_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
274 #define LEGO_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME + 0.5)
275 #define LEGO_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME + 0.5)
276 #define LEGO_REPEAT_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_REPEAT_START_BIT_PAUSE_TIME + 0.5)
277 #define LEGO_PULSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME + 0.5)
278 #define LEGO_1_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME + 0.5)
279 #define LEGO_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME + 0.5)
280 #define LEGO_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * LEGO_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t!
282 static volatile uint8_t irsnd_busy
;
283 static volatile uint8_t irsnd_protocol
;
284 static volatile uint8_t irsnd_buffer
[6];
285 static volatile uint8_t irsnd_repeat
;
286 static volatile uint8_t irsnd_is_on
= FALSE
;
288 #if IRSND_USE_CALLBACK == 1
289 static void (*irsnd_callback_ptr
) (uint8_t);
290 #endif // IRSND_USE_CALLBACK == 1
292 /*---------------------------------------------------------------------------------------------------------------------------------------------------
294 * @details Switches PWM on with a narrow spike on all 3 channels -> leds glowing
295 *---------------------------------------------------------------------------------------------------------------------------------------------------
303 #if IRSND_OC2 == 0 // use OC2
304 TCCR2
|= (1<<COM20
)|(1<<WGM21
); // toggle OC2 on compare match, clear Timer 2 at compare match OCR2
305 #elif IRSND_OC2 == 1 // use OC2A
306 TCCR2A
|= (1<<COM2A0
)|(1<<WGM21
); // toggle OC2A on compare match, clear Timer 2 at compare match OCR2A
308 TCCR2A
|= (1<<COM2B0
)|(1<<WGM21
); // toggle OC2B on compare match, clear Timer 2 at compare match OCR2A (yes: A, not B!)
312 #if IRSND_USE_CALLBACK == 1
313 if (irsnd_callback_ptr
)
315 (*irsnd_callback_ptr
) (TRUE
);
317 #endif // IRSND_USE_CALLBACK == 1
323 /*---------------------------------------------------------------------------------------------------------------------------------------------------
325 * @details Switches PWM off
326 *---------------------------------------------------------------------------------------------------------------------------------------------------
334 #if IRSND_OC2 == 0 // use OC2
335 TCCR2
&= ~(1<<COM20
); // normal port operation, OC2 disconnected.
336 #elif IRSND_OC2 == 1 // use OC2A
337 TCCR2A
&= ~(1<<COM2A0
); // normal port operation, OC2A disconnected.
339 TCCR2A
&= ~(1<<COM2B0
); // normal port operation, OC2B disconnected.
341 IRSND_PORT
&= ~(1<<IRSND_BIT
); // set IRSND_BIT to low
344 #if IRSND_USE_CALLBACK == 1
345 if (irsnd_callback_ptr
)
347 (*irsnd_callback_ptr
) (FALSE
);
349 #endif // IRSND_USE_CALLBACK == 1
355 /*---------------------------------------------------------------------------------------------------------------------------------------------------
357 * @details sets pwm frequency
358 *---------------------------------------------------------------------------------------------------------------------------------------------------
361 irsnd_set_freq (uint8_t freq
)
365 OCR2
= freq
; // use register OCR2 for OC2
367 OCR2A
= freq
; // use register OCR2A for OC2A and OC2B!
372 /*---------------------------------------------------------------------------------------------------------------------------------------------------
374 * @details Configures 0CR0A, 0CR0B and 0CR2B as PWM channels
375 *---------------------------------------------------------------------------------------------------------------------------------------------------
381 IRSND_PORT
&= ~(1<<IRSND_BIT
); // set IRSND_BIT to low
382 IRSND_DDR
|= (1<<IRSND_BIT
); // set IRSND_BIT to output
384 #if defined (__AVR_ATmega32__)
385 TCCR2
= (1<<WGM21
); // CTC mode
386 TCCR2
|= (1<<CS20
); // 0x01, start Timer 2, no prescaling
388 TCCR2A
= (1<<WGM21
); // CTC mode
389 TCCR2B
|= (1<<CS20
); // 0x01, start Timer 2, no prescaling
392 irsnd_set_freq (IRSND_FREQ_36_KHZ
); // default frequency
396 #if IRSND_USE_CALLBACK == 1
398 irsnd_set_callback_ptr (void (*cb
)(uint8_t))
400 irsnd_callback_ptr
= cb
;
402 #endif // IRSND_USE_CALLBACK == 1
411 bitsrevervse (uint16_t x
, uint8_t len
)
429 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
430 static uint8_t sircs_additional_bitlen
;
431 #endif // IRSND_SUPPORT_SIRCS_PROTOCOL == 1
434 irsnd_send_data (IRMP_DATA
* irmp_data_p
, uint8_t do_wait
)
436 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
437 static uint8_t toggle_bit_recs80
;
439 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
440 static uint8_t toggle_bit_recs80ext
;
442 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
443 static uint8_t toggle_bit_rc5
;
445 #if IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1
446 static uint8_t toggle_bit_rc6
;
463 irsnd_protocol
= irmp_data_p
->protocol
;
464 irsnd_repeat
= irmp_data_p
->flags
;
466 switch (irsnd_protocol
)
468 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
469 case IRMP_SIRCS_PROTOCOL
:
471 uint8_t sircs_additional_command_len
;
472 uint8_t sircs_additional_address_len
;
474 sircs_additional_bitlen
= (irmp_data_p
->address
& 0xFF00) >> 8; // additional bitlen
476 if (sircs_additional_bitlen
> 15 - SIRCS_MINIMUM_DATA_LEN
)
478 sircs_additional_command_len
= 15 - SIRCS_MINIMUM_DATA_LEN
;
479 sircs_additional_address_len
= sircs_additional_bitlen
- (15 - SIRCS_MINIMUM_DATA_LEN
);
483 sircs_additional_command_len
= sircs_additional_bitlen
;
484 sircs_additional_address_len
= 0;
487 command
= bitsrevervse (irmp_data_p
->command
, 15);
489 irsnd_buffer
[0] = (command
& 0x7F80) >> 7; // CCCCCCCC
490 irsnd_buffer
[1] = (command
& 0x007F) << 1; // CCCC****
492 if (sircs_additional_address_len
> 0)
494 address
= bitsrevervse (irmp_data_p
->address
, 5);
495 irsnd_buffer
[1] |= (address
& 0x0010) >> 4;
496 irsnd_buffer
[2] = (address
& 0x000F) << 4;
502 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
503 case IRMP_APPLE_PROTOCOL
:
505 command
= irmp_data_p
->command
| (irmp_data_p
->address
<< 8); // store address as ID in upper byte of command
506 address
= 0x87EE; // set fixed NEC-lookalike address (customer ID of apple)
508 address
= bitsrevervse (address
, NEC_ADDRESS_LEN
);
509 command
= bitsrevervse (command
, NEC_COMMAND_LEN
);
511 irsnd_protocol
= IRMP_NEC_PROTOCOL
; // APPLE protocol is NEC with id instead of inverted command
513 irsnd_buffer
[0] = (address
& 0xFF00) >> 8; // AAAAAAAA
514 irsnd_buffer
[1] = (address
& 0x00FF); // AAAAAAAA
515 irsnd_buffer
[2] = (command
& 0xFF00) >> 8; // CCCCCCCC
516 irsnd_buffer
[3] = (command
& 0x00FF); // CCCCCCCC
521 case IRMP_NEC_PROTOCOL
:
523 address
= bitsrevervse (irmp_data_p
->address
, NEC_ADDRESS_LEN
);
524 command
= bitsrevervse (irmp_data_p
->command
, NEC_COMMAND_LEN
);
526 irsnd_buffer
[0] = (address
& 0xFF00) >> 8; // AAAAAAAA
527 irsnd_buffer
[1] = (address
& 0x00FF); // AAAAAAAA
528 irsnd_buffer
[2] = (command
& 0xFF00) >> 8; // CCCCCCCC
530 irsnd_protocol
= IRMP_NEC_PROTOCOL
; // APPLE protocol is NEC with fix bitmask instead of inverted command
531 irsnd_buffer
[3] = 0x8B; // 10001011
533 irsnd_buffer
[3] = ~((command
& 0xFF00) >> 8); // cccccccc
540 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
541 case IRMP_SAMSUNG_PROTOCOL
:
543 address
= bitsrevervse (irmp_data_p
->address
, SAMSUNG_ADDRESS_LEN
);
544 command
= bitsrevervse (irmp_data_p
->command
, SAMSUNG_COMMAND_LEN
);
546 irsnd_buffer
[0] = (address
& 0xFF00) >> 8; // AAAAAAAA
547 irsnd_buffer
[1] = (address
& 0x00FF); // AAAAAAAA
548 irsnd_buffer
[2] = (command
& 0x00F0) | ((command
& 0xF000) >> 12); // IIIICCCC
549 irsnd_buffer
[3] = ((command
& 0x0F00) >> 4) | ((~(command
& 0xF000) >> 12) & 0x0F); // CCCCcccc
550 irsnd_buffer
[4] = (~(command
& 0x0F00) >> 4) & 0xF0; // cccc0000
554 case IRMP_SAMSUNG32_PROTOCOL
:
556 address
= bitsrevervse (irmp_data_p
->address
, SAMSUNG_ADDRESS_LEN
);
557 command
= bitsrevervse (irmp_data_p
->command
, SAMSUNG32_COMMAND_LEN
);
559 irsnd_buffer
[0] = (address
& 0xFF00) >> 8; // AAAAAAAA
560 irsnd_buffer
[1] = (address
& 0x00FF); // AAAAAAAA
561 irsnd_buffer
[2] = (command
& 0xFF00) >> 8; // CCCCCCCC
562 irsnd_buffer
[3] = (command
& 0x00FF); // CCCCCCCC
567 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
568 case IRMP_MATSUSHITA_PROTOCOL
:
570 address
= bitsrevervse (irmp_data_p
->address
, MATSUSHITA_ADDRESS_LEN
);
571 command
= bitsrevervse (irmp_data_p
->command
, MATSUSHITA_COMMAND_LEN
);
573 irsnd_buffer
[0] = (command
& 0x0FF0) >> 4; // CCCCCCCC
574 irsnd_buffer
[1] = ((command
& 0x000F) << 4) | ((address
& 0x0F00) >> 8); // CCCCAAAA
575 irsnd_buffer
[2] = (address
& 0x00FF); // AAAAAAAA
580 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1
581 case IRMP_KASEIKYO_PROTOCOL
:
585 address
= bitsrevervse (irmp_data_p
->address
, KASEIKYO_ADDRESS_LEN
);
586 command
= bitsrevervse (irmp_data_p
->command
, KASEIKYO_COMMAND_LEN
+ 4);
588 xor = ((address
& 0x000F) ^ ((address
& 0x00F0) >> 4) ^ ((address
& 0x0F00) >> 8) ^ ((address
& 0xF000) >> 12)) & 0x0F;
590 irsnd_buffer
[0] = (address
& 0xFF00) >> 8; // AAAAAAAA
591 irsnd_buffer
[1] = (address
& 0x00FF); // AAAAAAAA
592 irsnd_buffer
[2] = xor << 4 | (command
& 0x000F); // XXXXCCCC
593 irsnd_buffer
[3] = 0 | (command
& 0xF000) >> 12; // 0000CCCC
594 irsnd_buffer
[4] = (command
& 0x0FF0) >> 4; // CCCCCCCC
596 xor = irsnd_buffer
[2] ^ irsnd_buffer
[3] ^ irsnd_buffer
[4];
598 irsnd_buffer
[5] = xor;
603 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
604 case IRMP_RECS80_PROTOCOL
:
606 toggle_bit_recs80
= toggle_bit_recs80
? 0x00 : 0x40;
608 irsnd_buffer
[0] = 0x80 | toggle_bit_recs80
| ((irmp_data_p
->address
& 0x0007) << 3) |
609 ((irmp_data_p
->command
& 0x0038) >> 3); // STAAACCC
610 irsnd_buffer
[1] = (irmp_data_p
->command
& 0x07) << 5; // CCC00000
615 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
616 case IRMP_RECS80EXT_PROTOCOL
:
618 toggle_bit_recs80ext
= toggle_bit_recs80ext
? 0x00 : 0x40;
620 irsnd_buffer
[0] = 0x80 | toggle_bit_recs80ext
| ((irmp_data_p
->address
& 0x000F) << 2) |
621 ((irmp_data_p
->command
& 0x0030) >> 4); // STAAAACC
622 irsnd_buffer
[1] = (irmp_data_p
->command
& 0x0F) << 4; // CCCC0000
627 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
628 case IRMP_RC5_PROTOCOL
:
630 toggle_bit_rc5
= toggle_bit_rc5
? 0x00 : 0x40;
632 irsnd_buffer
[0] = ((irmp_data_p
->command
& 0x40) ? 0x00 : 0x80) | toggle_bit_rc5
|
633 ((irmp_data_p
->address
& 0x001F) << 1) | ((irmp_data_p
->command
& 0x20) >> 5); // CTAAAAAC
634 irsnd_buffer
[1] = (irmp_data_p
->command
& 0x1F) << 3; // CCCCC000
639 #if IRSND_SUPPORT_RC6_PROTOCOL == 1
640 case IRMP_RC6_PROTOCOL
:
642 toggle_bit_rc6
= toggle_bit_rc6
? 0x00 : 0x08;
644 irsnd_buffer
[0] = 0x80 | toggle_bit_rc6
| ((irmp_data_p
->address
& 0x00E0) >> 5); // 1MMMTAAA, MMM = 000
645 irsnd_buffer
[1] = ((irmp_data_p
->address
& 0x001F) << 3) | ((irmp_data_p
->command
& 0xE0) >> 5); // AAAAACCC
646 irsnd_buffer
[2] = (irmp_data_p
->command
& 0x1F) << 3; // CCCCC
651 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1
652 case IRMP_RC6A_PROTOCOL
:
654 toggle_bit_rc6
= toggle_bit_rc6
? 0x00 : 0x08;
656 irsnd_buffer
[0] = 0x80 | 0x60 | ((irmp_data_p
->address
& 0x3000) >> 12); // 1MMMT0AA, MMM = 110
657 irsnd_buffer
[1] = ((irmp_data_p
->address
& 0x0FFF) >> 4) ; // AAAAAAAA
658 irsnd_buffer
[2] = ((irmp_data_p
->address
& 0x000F) << 4) | ((irmp_data_p
->command
& 0xF000) >> 12) | toggle_bit_rc6
; // AAAACCCC
659 irsnd_buffer
[3] = (irmp_data_p
->command
& 0x0FF0) >> 4; // CCCCCCCC
660 irsnd_buffer
[4] = (irmp_data_p
->command
& 0x000F) << 4; // CCCC
665 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
666 case IRMP_DENON_PROTOCOL
:
668 irsnd_buffer
[0] = ((irmp_data_p
->address
& 0x1F) << 3) | ((irmp_data_p
->command
& 0x0380) >> 7); // AAAAACCC (1st frame)
669 irsnd_buffer
[1] = (irmp_data_p
->command
& 0x7F) << 1; // CCCCCCC
670 irsnd_buffer
[2] = ((irmp_data_p
->address
& 0x1F) << 3) | (((~irmp_data_p
->command
) & 0x0380) >> 7); // AAAAACCC (2nd frame)
671 irsnd_buffer
[3] = (~(irmp_data_p
->command
) & 0x7F) << 1; // CCCCCCC
676 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
677 case IRMP_NUBERT_PROTOCOL
:
679 irsnd_buffer
[0] = irmp_data_p
->command
>> 2; // CCCCCCCC
680 irsnd_buffer
[1] = (irmp_data_p
->command
& 0x0003) << 6; // CC000000
685 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
686 case IRMP_BANG_OLUFSEN_PROTOCOL
:
688 irsnd_buffer
[0] = irmp_data_p
->command
>> 11; // SXSCCCCC
689 irsnd_buffer
[1] = irmp_data_p
->command
>> 3; // CCCCCCCC
690 irsnd_buffer
[2] = (irmp_data_p
->command
& 0x0007) << 5; // CCC00000
695 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
696 case IRMP_GRUNDIG_PROTOCOL
:
698 command
= bitsrevervse (irmp_data_p
->command
, GRUNDIG_COMMAND_LEN
);
700 irsnd_buffer
[0] = 0xFF; // S1111111 (1st frame)
701 irsnd_buffer
[1] = 0xC0; // 11
702 irsnd_buffer
[2] = 0x80 | (command
>> 2); // SCCCCCCC (2nd frame)
703 irsnd_buffer
[3] = (command
<< 6) & 0xC0; // CC
709 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
710 case IRMP_NOKIA_PROTOCOL
:
712 address
= bitsrevervse (irmp_data_p
->address
, NOKIA_ADDRESS_LEN
);
713 command
= bitsrevervse (irmp_data_p
->command
, NOKIA_COMMAND_LEN
);
715 irsnd_buffer
[0] = 0xBF; // S0111111 (1st + 3rd frame)
716 irsnd_buffer
[1] = 0xFF; // 11111111
717 irsnd_buffer
[2] = 0x80; // 1
718 irsnd_buffer
[3] = 0x80 | command
>> 1; // SCCCCCCC (2nd frame)
719 irsnd_buffer
[4] = (command
<< 7) | (address
>> 1); // CAAAAAAA
720 irsnd_buffer
[5] = (address
<< 7); // A
726 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
727 case IRMP_SIEMENS_PROTOCOL
:
729 irsnd_buffer
[0] = ((irmp_data_p
->address
& 0x0FFF) >> 5); // SAAAAAAA
730 irsnd_buffer
[1] = ((irmp_data_p
->address
& 0x1F) << 3) | ((irmp_data_p
->command
& 0x7F) >> 5); // AAAAA0CC
731 irsnd_buffer
[2] = (irmp_data_p
->command
<< 3) | ((~irmp_data_p
->command
& 0x01) << 2); // CCCCCc
737 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
738 case IRMP_FDC_PROTOCOL
:
740 address
= bitsrevervse (irmp_data_p
->address
, FDC_ADDRESS_LEN
);
741 command
= bitsrevervse (irmp_data_p
->command
, FDC_COMMAND_LEN
);
743 irsnd_buffer
[0] = (address
& 0xFF); // AAAAAAAA
744 irsnd_buffer
[1] = 0; // 00000000
745 irsnd_buffer
[2] = 0; // 0000RRRR
746 irsnd_buffer
[3] = (command
& 0xFF); // CCCCCCCC
747 irsnd_buffer
[4] = ~(command
& 0xFF); // cccccccc
752 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1
753 case IRMP_RCCAR_PROTOCOL
:
755 address
= bitsrevervse (irmp_data_p
->address
, 2); // A0 A1
756 command
= bitsrevervse (irmp_data_p
->command
, RCCAR_COMMAND_LEN
- 2); // D0 D1 D2 D3 D4 D5 D6 D7 C0 C1 V
758 irsnd_buffer
[0] = ((command
& 0x06) << 5) | ((address
& 0x0003) << 4) | ((command
& 0x0780) >> 7); // C0 C1 A0 A1 D0 D1 D2 D3
759 irsnd_buffer
[1] = ((command
& 0x78) << 1) | ((command
& 0x0001) << 3); // D4 D5 D6 D7 V 0 0 0
765 #if IRSND_SUPPORT_JVC_PROTOCOL == 1
766 case IRMP_JVC_PROTOCOL
:
768 address
= bitsrevervse (irmp_data_p
->address
, JVC_ADDRESS_LEN
);
769 command
= bitsrevervse (irmp_data_p
->command
, JVC_COMMAND_LEN
);
771 irsnd_buffer
[0] = ((address
& 0x000F) << 4) | (command
& 0x0F00) >> 8; // AAAACCCC
772 irsnd_buffer
[1] = (command
& 0x00FF); // CCCCCCCC
778 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
779 case IRMP_NIKON_PROTOCOL
:
781 irsnd_buffer
[0] = (irmp_data_p
->command
& 0x0003) << 6; // CC
786 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1
787 case IRMP_LEGO_PROTOCOL
:
789 uint8_t crc
= 0x0F ^ ((irmp_data_p
->command
& 0x0F00) >> 8) ^ ((irmp_data_p
->command
& 0x00F0) >> 4) ^ (irmp_data_p
->command
& 0x000F);
791 irsnd_buffer
[0] = (irmp_data_p
->command
& 0x0FF0) >> 4; // CCCCCCCC
792 irsnd_buffer
[1] = ((irmp_data_p
->command
& 0x000F) << 4) | crc
; // CCCCcccc
794 irsnd_protocol
= IRMP_LEGO_PROTOCOL
;
808 /*---------------------------------------------------------------------------------------------------------------------------------------------------
810 * @details ISR routine, called 10000 times per second
811 *---------------------------------------------------------------------------------------------------------------------------------------------------
816 static uint8_t current_bit
= 0xFF;
817 static uint8_t pulse_counter
;
818 static IRSND_PAUSE_LEN pause_counter
;
819 static uint8_t startbit_pulse_len
;
820 static IRSND_PAUSE_LEN startbit_pause_len
;
821 static uint8_t pulse_1_len
;
822 static uint8_t pause_1_len
;
823 static uint8_t pulse_0_len
;
824 static uint8_t pause_0_len
;
825 static uint8_t has_stop_bit
;
826 static uint8_t new_frame
= TRUE
;
827 static uint8_t complete_data_len
;
828 static uint8_t n_auto_repetitions
; // number of auto_repetitions
829 static uint8_t auto_repetition_counter
; // auto_repetition counter
830 static uint16_t auto_repetition_pause_len
; // pause before auto_repetition, uint16_t!
831 static uint16_t auto_repetition_pause_counter
; // pause before auto_repetition, uint16_t!
832 static uint8_t n_repeat_frames
; // number of repeat frames
833 static uint8_t repeat_counter
; // repeat counter
834 static uint16_t repeat_frame_pause_len
; // pause before repeat, uint16_t!
835 static uint16_t packet_repeat_pause_counter
; // pause before repeat, uint16_t!
836 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
837 static uint8_t last_bit_value
;
839 static uint8_t pulse_len
= 0xFF;
840 static IRSND_PAUSE_LEN pause_len
= 0xFF;
844 if (current_bit
== 0xFF && new_frame
) // start of transmission...
846 if (auto_repetition_counter
> 0)
848 auto_repetition_pause_counter
++;
850 if (auto_repetition_pause_counter
>= auto_repetition_pause_len
)
852 auto_repetition_pause_counter
= 0;
854 if (irsnd_protocol
== IRMP_DENON_PROTOCOL
)
857 complete_data_len
= 2 * DENON_COMPLETE_DATA_LEN
+ 1;
859 else if (irsnd_protocol
== IRMP_GRUNDIG_PROTOCOL
) // n'th grundig info frame
862 complete_data_len
= 16 + GRUNDIG_COMPLETE_DATA_LEN
;
864 else if (irsnd_protocol
== IRMP_NOKIA_PROTOCOL
) // n'th nokia info frame
866 if (auto_repetition_counter
+ 1 < n_auto_repetitions
)
869 complete_data_len
= 24 + NOKIA_COMPLETE_DATA_LEN
;
871 else // nokia stop frame
874 complete_data_len
= NOKIA_COMPLETE_DATA_LEN
;
893 else if (repeat_counter
> 0 && packet_repeat_pause_counter
< repeat_frame_pause_len
)
895 packet_repeat_pause_counter
++;
911 n_repeat_frames
= irsnd_repeat
;
912 packet_repeat_pause_counter
= 0;
916 switch (irsnd_protocol
)
918 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
919 case IRMP_SIRCS_PROTOCOL
:
921 startbit_pulse_len
= SIRCS_START_BIT_PULSE_LEN
;
922 startbit_pause_len
= SIRCS_START_BIT_PAUSE_LEN
- 1;
923 pulse_1_len
= SIRCS_1_PULSE_LEN
;
924 pause_1_len
= SIRCS_PAUSE_LEN
- 1;
925 pulse_0_len
= SIRCS_0_PULSE_LEN
;
926 pause_0_len
= SIRCS_PAUSE_LEN
- 1;
927 has_stop_bit
= SIRCS_STOP_BIT
;
928 complete_data_len
= SIRCS_MINIMUM_DATA_LEN
+ sircs_additional_bitlen
;
929 n_auto_repetitions
= (repeat_counter
== 0) ? SIRCS_FRAMES
: 1; // 3 frames auto repetition if first frame
930 auto_repetition_pause_len
= SIRCS_AUTO_REPETITION_PAUSE_LEN
; // 25ms pause
931 repeat_frame_pause_len
= SIRCS_FRAME_REPEAT_PAUSE_LEN
;
932 irsnd_set_freq (IRSND_FREQ_40_KHZ
);
936 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
937 case IRMP_NEC_PROTOCOL
:
939 startbit_pulse_len
= NEC_START_BIT_PULSE_LEN
;
941 if (repeat_counter
> 0)
943 startbit_pause_len
= NEC_REPEAT_START_BIT_PAUSE_LEN
- 1;
944 complete_data_len
= 0;
948 startbit_pause_len
= NEC_START_BIT_PAUSE_LEN
- 1;
949 complete_data_len
= NEC_COMPLETE_DATA_LEN
;
952 pulse_1_len
= NEC_PULSE_LEN
;
953 pause_1_len
= NEC_1_PAUSE_LEN
- 1;
954 pulse_0_len
= NEC_PULSE_LEN
;
955 pause_0_len
= NEC_0_PAUSE_LEN
- 1;
956 has_stop_bit
= NEC_STOP_BIT
;
957 n_auto_repetitions
= 1; // 1 frame
958 auto_repetition_pause_len
= 0;
959 repeat_frame_pause_len
= NEC_FRAME_REPEAT_PAUSE_LEN
;
960 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
964 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
965 case IRMP_SAMSUNG_PROTOCOL
:
967 startbit_pulse_len
= SAMSUNG_START_BIT_PULSE_LEN
;
968 startbit_pause_len
= SAMSUNG_START_BIT_PAUSE_LEN
- 1;
969 pulse_1_len
= SAMSUNG_PULSE_LEN
;
970 pause_1_len
= SAMSUNG_1_PAUSE_LEN
- 1;
971 pulse_0_len
= SAMSUNG_PULSE_LEN
;
972 pause_0_len
= SAMSUNG_0_PAUSE_LEN
- 1;
973 has_stop_bit
= SAMSUNG_STOP_BIT
;
974 complete_data_len
= SAMSUNG_COMPLETE_DATA_LEN
;
975 n_auto_repetitions
= 1; // 1 frame
976 auto_repetition_pause_len
= 0;
977 repeat_frame_pause_len
= SAMSUNG_FRAME_REPEAT_PAUSE_LEN
;
978 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
982 case IRMP_SAMSUNG32_PROTOCOL
:
984 startbit_pulse_len
= SAMSUNG_START_BIT_PULSE_LEN
;
985 startbit_pause_len
= SAMSUNG_START_BIT_PAUSE_LEN
- 1;
986 pulse_1_len
= SAMSUNG_PULSE_LEN
;
987 pause_1_len
= SAMSUNG_1_PAUSE_LEN
- 1;
988 pulse_0_len
= SAMSUNG_PULSE_LEN
;
989 pause_0_len
= SAMSUNG_0_PAUSE_LEN
- 1;
990 has_stop_bit
= SAMSUNG_STOP_BIT
;
991 complete_data_len
= SAMSUNG32_COMPLETE_DATA_LEN
;
992 n_auto_repetitions
= SAMSUNG32_FRAMES
; // 2 frames
993 auto_repetition_pause_len
= SAMSUNG32_AUTO_REPETITION_PAUSE_LEN
; // 47 ms pause
994 repeat_frame_pause_len
= SAMSUNG32_FRAME_REPEAT_PAUSE_LEN
;
995 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
999 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
1000 case IRMP_MATSUSHITA_PROTOCOL
:
1002 startbit_pulse_len
= MATSUSHITA_START_BIT_PULSE_LEN
;
1003 startbit_pause_len
= MATSUSHITA_START_BIT_PAUSE_LEN
- 1;
1004 pulse_1_len
= MATSUSHITA_PULSE_LEN
;
1005 pause_1_len
= MATSUSHITA_1_PAUSE_LEN
- 1;
1006 pulse_0_len
= MATSUSHITA_PULSE_LEN
;
1007 pause_0_len
= MATSUSHITA_0_PAUSE_LEN
- 1;
1008 has_stop_bit
= MATSUSHITA_STOP_BIT
;
1009 complete_data_len
= MATSUSHITA_COMPLETE_DATA_LEN
;
1010 n_auto_repetitions
= 1; // 1 frame
1011 auto_repetition_pause_len
= 0;
1012 repeat_frame_pause_len
= MATSUSHITA_FRAME_REPEAT_PAUSE_LEN
;
1013 irsnd_set_freq (IRSND_FREQ_36_KHZ
);
1017 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1
1018 case IRMP_KASEIKYO_PROTOCOL
:
1020 startbit_pulse_len
= KASEIKYO_START_BIT_PULSE_LEN
;
1021 startbit_pause_len
= KASEIKYO_START_BIT_PAUSE_LEN
- 1;
1022 pulse_1_len
= KASEIKYO_PULSE_LEN
;
1023 pause_1_len
= KASEIKYO_1_PAUSE_LEN
- 1;
1024 pulse_0_len
= KASEIKYO_PULSE_LEN
;
1025 pause_0_len
= KASEIKYO_0_PAUSE_LEN
- 1;
1026 has_stop_bit
= KASEIKYO_STOP_BIT
;
1027 complete_data_len
= KASEIKYO_COMPLETE_DATA_LEN
;
1028 n_auto_repetitions
= (repeat_counter
== 0) ? KASEIKYO_FRAMES
: 1; // 2 frames auto repetition if first frame
1029 auto_repetition_pause_len
= KASEIKYO_AUTO_REPETITION_PAUSE_LEN
; // 75 ms pause
1030 repeat_frame_pause_len
= KASEIKYO_FRAME_REPEAT_PAUSE_LEN
;
1031 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
1035 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
1036 case IRMP_RECS80_PROTOCOL
:
1038 startbit_pulse_len
= RECS80_START_BIT_PULSE_LEN
;
1039 startbit_pause_len
= RECS80_START_BIT_PAUSE_LEN
- 1;
1040 pulse_1_len
= RECS80_PULSE_LEN
;
1041 pause_1_len
= RECS80_1_PAUSE_LEN
- 1;
1042 pulse_0_len
= RECS80_PULSE_LEN
;
1043 pause_0_len
= RECS80_0_PAUSE_LEN
- 1;
1044 has_stop_bit
= RECS80_STOP_BIT
;
1045 complete_data_len
= RECS80_COMPLETE_DATA_LEN
;
1046 n_auto_repetitions
= 1; // 1 frame
1047 auto_repetition_pause_len
= 0;
1048 repeat_frame_pause_len
= RECS80_FRAME_REPEAT_PAUSE_LEN
;
1049 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
1053 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
1054 case IRMP_RECS80EXT_PROTOCOL
:
1056 startbit_pulse_len
= RECS80EXT_START_BIT_PULSE_LEN
;
1057 startbit_pause_len
= RECS80EXT_START_BIT_PAUSE_LEN
- 1;
1058 pulse_1_len
= RECS80EXT_PULSE_LEN
;
1059 pause_1_len
= RECS80EXT_1_PAUSE_LEN
- 1;
1060 pulse_0_len
= RECS80EXT_PULSE_LEN
;
1061 pause_0_len
= RECS80EXT_0_PAUSE_LEN
- 1;
1062 has_stop_bit
= RECS80EXT_STOP_BIT
;
1063 complete_data_len
= RECS80EXT_COMPLETE_DATA_LEN
;
1064 n_auto_repetitions
= 1; // 1 frame
1065 auto_repetition_pause_len
= 0;
1066 repeat_frame_pause_len
= RECS80EXT_FRAME_REPEAT_PAUSE_LEN
;
1067 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
1071 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
1072 case IRMP_RC5_PROTOCOL
:
1074 startbit_pulse_len
= RC5_BIT_LEN
;
1075 startbit_pause_len
= RC5_BIT_LEN
;
1076 pulse_len
= RC5_BIT_LEN
;
1077 pause_len
= RC5_BIT_LEN
;
1078 has_stop_bit
= RC5_STOP_BIT
;
1079 complete_data_len
= RC5_COMPLETE_DATA_LEN
;
1080 n_auto_repetitions
= 1; // 1 frame
1081 auto_repetition_pause_len
= 0;
1082 repeat_frame_pause_len
= RC5_FRAME_REPEAT_PAUSE_LEN
;
1083 irsnd_set_freq (IRSND_FREQ_36_KHZ
);
1087 #if IRSND_SUPPORT_RC6_PROTOCOL == 1
1088 case IRMP_RC6_PROTOCOL
:
1090 startbit_pulse_len
= RC6_START_BIT_PULSE_LEN
;
1091 startbit_pause_len
= RC6_START_BIT_PAUSE_LEN
- 1;
1092 pulse_len
= RC6_BIT_LEN
;
1093 pause_len
= RC6_BIT_LEN
;
1094 has_stop_bit
= RC6_STOP_BIT
;
1095 complete_data_len
= RC6_COMPLETE_DATA_LEN_SHORT
;
1096 n_auto_repetitions
= 1; // 1 frame
1097 auto_repetition_pause_len
= 0;
1098 repeat_frame_pause_len
= RC6_FRAME_REPEAT_PAUSE_LEN
;
1099 irsnd_set_freq (IRSND_FREQ_36_KHZ
);
1103 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1
1104 case IRMP_RC6A_PROTOCOL
:
1106 startbit_pulse_len
= RC6_START_BIT_PULSE_LEN
;
1107 startbit_pause_len
= RC6_START_BIT_PAUSE_LEN
- 1;
1108 pulse_len
= RC6_BIT_LEN
;
1109 pause_len
= RC6_BIT_LEN
;
1110 has_stop_bit
= RC6_STOP_BIT
;
1111 complete_data_len
= RC6_COMPLETE_DATA_LEN_LONG
;
1112 n_auto_repetitions
= 1; // 1 frame
1113 auto_repetition_pause_len
= 0;
1114 repeat_frame_pause_len
= RC6_FRAME_REPEAT_PAUSE_LEN
;
1115 irsnd_set_freq (IRSND_FREQ_36_KHZ
);
1119 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
1120 case IRMP_DENON_PROTOCOL
:
1122 startbit_pulse_len
= 0x00;
1123 startbit_pause_len
= 0x00;
1124 pulse_1_len
= DENON_PULSE_LEN
;
1125 pause_1_len
= DENON_1_PAUSE_LEN
- 1;
1126 pulse_0_len
= DENON_PULSE_LEN
;
1127 pause_0_len
= DENON_0_PAUSE_LEN
- 1;
1128 has_stop_bit
= DENON_STOP_BIT
;
1129 complete_data_len
= DENON_COMPLETE_DATA_LEN
;
1130 n_auto_repetitions
= DENON_FRAMES
; // 2 frames, 2nd with inverted command
1131 auto_repetition_pause_len
= DENON_AUTO_REPETITION_PAUSE_LEN
; // 65 ms pause after 1st frame
1132 repeat_frame_pause_len
= DENON_FRAME_REPEAT_PAUSE_LEN
;
1133 irsnd_set_freq (IRSND_FREQ_36_KHZ
); // in theory 32kHz, in practice 36kHz is better
1137 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
1138 case IRMP_NUBERT_PROTOCOL
:
1140 startbit_pulse_len
= NUBERT_START_BIT_PULSE_LEN
;
1141 startbit_pause_len
= NUBERT_START_BIT_PAUSE_LEN
- 1;
1142 pulse_1_len
= NUBERT_1_PULSE_LEN
;
1143 pause_1_len
= NUBERT_1_PAUSE_LEN
- 1;
1144 pulse_0_len
= NUBERT_0_PULSE_LEN
;
1145 pause_0_len
= NUBERT_0_PAUSE_LEN
- 1;
1146 has_stop_bit
= NUBERT_STOP_BIT
;
1147 complete_data_len
= NUBERT_COMPLETE_DATA_LEN
;
1148 n_auto_repetitions
= NUBERT_FRAMES
; // 2 frames
1149 auto_repetition_pause_len
= NUBERT_AUTO_REPETITION_PAUSE_LEN
; // 35 ms pause
1150 repeat_frame_pause_len
= NUBERT_FRAME_REPEAT_PAUSE_LEN
;
1151 irsnd_set_freq (IRSND_FREQ_36_KHZ
);
1155 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1156 case IRMP_BANG_OLUFSEN_PROTOCOL
:
1158 startbit_pulse_len
= BANG_OLUFSEN_START_BIT1_PULSE_LEN
;
1159 startbit_pause_len
= BANG_OLUFSEN_START_BIT1_PAUSE_LEN
- 1;
1160 pulse_1_len
= BANG_OLUFSEN_PULSE_LEN
;
1161 pause_1_len
= BANG_OLUFSEN_1_PAUSE_LEN
- 1;
1162 pulse_0_len
= BANG_OLUFSEN_PULSE_LEN
;
1163 pause_0_len
= BANG_OLUFSEN_0_PAUSE_LEN
- 1;
1164 has_stop_bit
= BANG_OLUFSEN_STOP_BIT
;
1165 complete_data_len
= BANG_OLUFSEN_COMPLETE_DATA_LEN
;
1166 n_auto_repetitions
= 1; // 1 frame
1167 auto_repetition_pause_len
= 0;
1168 repeat_frame_pause_len
= BANG_OLUFSEN_FRAME_REPEAT_PAUSE_LEN
;
1170 irsnd_set_freq (IRSND_FREQ_455_KHZ
);
1174 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
1175 case IRMP_GRUNDIG_PROTOCOL
:
1177 startbit_pulse_len
= GRUNDIG_NOKIA_IR60_BIT_LEN
;
1178 startbit_pause_len
= GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN
- 1;
1179 pulse_len
= GRUNDIG_NOKIA_IR60_BIT_LEN
;
1180 pause_len
= GRUNDIG_NOKIA_IR60_BIT_LEN
;
1181 has_stop_bit
= GRUNDIG_NOKIA_IR60_STOP_BIT
;
1182 complete_data_len
= GRUNDIG_COMPLETE_DATA_LEN
;
1183 n_auto_repetitions
= GRUNDIG_FRAMES
; // 2 frames
1184 auto_repetition_pause_len
= GRUNDIG_AUTO_REPETITION_PAUSE_LEN
; // 20m sec pause
1185 repeat_frame_pause_len
= GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN
; // 117 msec pause
1186 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
1191 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1192 case IRMP_NOKIA_PROTOCOL
:
1194 startbit_pulse_len
= GRUNDIG_NOKIA_IR60_BIT_LEN
;
1195 startbit_pause_len
= GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN
- 1;
1196 pulse_len
= GRUNDIG_NOKIA_IR60_BIT_LEN
;
1197 pause_len
= GRUNDIG_NOKIA_IR60_BIT_LEN
;
1198 has_stop_bit
= GRUNDIG_NOKIA_IR60_STOP_BIT
;
1199 complete_data_len
= NOKIA_COMPLETE_DATA_LEN
;
1200 n_auto_repetitions
= NOKIA_FRAMES
; // 2 frames
1201 auto_repetition_pause_len
= NOKIA_AUTO_REPETITION_PAUSE_LEN
; // 20 msec pause
1202 repeat_frame_pause_len
= GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN
; // 117 msec pause
1203 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
1207 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
1208 case IRMP_SIEMENS_PROTOCOL
:
1210 startbit_pulse_len
= SIEMENS_BIT_LEN
;
1211 startbit_pause_len
= SIEMENS_BIT_LEN
;
1212 pulse_len
= SIEMENS_BIT_LEN
;
1213 pause_len
= SIEMENS_BIT_LEN
;
1214 has_stop_bit
= SIEMENS_OR_RUWIDO_STOP_BIT
;
1215 complete_data_len
= SIEMENS_COMPLETE_DATA_LEN
- 1;
1216 n_auto_repetitions
= 1; // 1 frame
1217 auto_repetition_pause_len
= 0;
1218 repeat_frame_pause_len
= SIEMENS_FRAME_REPEAT_PAUSE_LEN
;
1219 irsnd_set_freq (IRSND_FREQ_36_KHZ
);
1223 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
1224 case IRMP_FDC_PROTOCOL
:
1226 startbit_pulse_len
= FDC_START_BIT_PULSE_LEN
;
1227 startbit_pause_len
= FDC_START_BIT_PAUSE_LEN
- 1;
1228 complete_data_len
= FDC_COMPLETE_DATA_LEN
;
1229 pulse_1_len
= FDC_PULSE_LEN
;
1230 pause_1_len
= FDC_1_PAUSE_LEN
- 1;
1231 pulse_0_len
= FDC_PULSE_LEN
;
1232 pause_0_len
= FDC_0_PAUSE_LEN
- 1;
1233 has_stop_bit
= FDC_STOP_BIT
;
1234 n_auto_repetitions
= 1; // 1 frame
1235 auto_repetition_pause_len
= 0;
1236 repeat_frame_pause_len
= FDC_FRAME_REPEAT_PAUSE_LEN
;
1237 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
1241 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1
1242 case IRMP_RCCAR_PROTOCOL
:
1244 startbit_pulse_len
= RCCAR_START_BIT_PULSE_LEN
;
1245 startbit_pause_len
= RCCAR_START_BIT_PAUSE_LEN
- 1;
1246 complete_data_len
= RCCAR_COMPLETE_DATA_LEN
;
1247 pulse_1_len
= RCCAR_PULSE_LEN
;
1248 pause_1_len
= RCCAR_1_PAUSE_LEN
- 1;
1249 pulse_0_len
= RCCAR_PULSE_LEN
;
1250 pause_0_len
= RCCAR_0_PAUSE_LEN
- 1;
1251 has_stop_bit
= RCCAR_STOP_BIT
;
1252 n_auto_repetitions
= 1; // 1 frame
1253 auto_repetition_pause_len
= 0;
1254 repeat_frame_pause_len
= RCCAR_FRAME_REPEAT_PAUSE_LEN
;
1255 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
1259 #if IRSND_SUPPORT_JVC_PROTOCOL == 1
1260 case IRMP_JVC_PROTOCOL
:
1262 if (repeat_counter
!= 0) // skip start bit if repetition frame
1267 startbit_pulse_len
= JVC_START_BIT_PULSE_LEN
;
1268 startbit_pause_len
= JVC_START_BIT_PAUSE_LEN
- 1;
1269 complete_data_len
= JVC_COMPLETE_DATA_LEN
;
1270 pulse_1_len
= JVC_PULSE_LEN
;
1271 pause_1_len
= JVC_1_PAUSE_LEN
- 1;
1272 pulse_0_len
= JVC_PULSE_LEN
;
1273 pause_0_len
= JVC_0_PAUSE_LEN
- 1;
1274 has_stop_bit
= JVC_STOP_BIT
;
1275 n_auto_repetitions
= 1; // 1 frame
1276 auto_repetition_pause_len
= 0;
1277 repeat_frame_pause_len
= JVC_FRAME_REPEAT_PAUSE_LEN
;
1278 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
1283 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
1284 case IRMP_NIKON_PROTOCOL
:
1286 startbit_pulse_len
= NIKON_START_BIT_PULSE_LEN
;
1287 startbit_pause_len
= 271 - 1; // NIKON_START_BIT_PAUSE_LEN;
1288 complete_data_len
= NIKON_COMPLETE_DATA_LEN
;
1289 pulse_1_len
= NIKON_PULSE_LEN
;
1290 pause_1_len
= NIKON_1_PAUSE_LEN
- 1;
1291 pulse_0_len
= NIKON_PULSE_LEN
;
1292 pause_0_len
= NIKON_0_PAUSE_LEN
- 1;
1293 has_stop_bit
= NIKON_STOP_BIT
;
1294 n_auto_repetitions
= 1; // 1 frame
1295 auto_repetition_pause_len
= 0;
1296 repeat_frame_pause_len
= NIKON_FRAME_REPEAT_PAUSE_LEN
;
1297 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
1302 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1
1303 case IRMP_LEGO_PROTOCOL
:
1305 startbit_pulse_len
= LEGO_START_BIT_PULSE_LEN
;
1306 startbit_pause_len
= LEGO_START_BIT_PAUSE_LEN
- 1;
1307 complete_data_len
= LEGO_COMPLETE_DATA_LEN
;
1308 pulse_1_len
= LEGO_PULSE_LEN
;
1309 pause_1_len
= LEGO_1_PAUSE_LEN
- 1;
1310 pulse_0_len
= LEGO_PULSE_LEN
;
1311 pause_0_len
= LEGO_0_PAUSE_LEN
- 1;
1312 has_stop_bit
= LEGO_STOP_BIT
;
1313 n_auto_repetitions
= 1; // 1 frame
1314 auto_repetition_pause_len
= 0;
1315 repeat_frame_pause_len
= LEGO_FRAME_REPEAT_PAUSE_LEN
;
1316 irsnd_set_freq (IRSND_FREQ_38_KHZ
);
1333 switch (irsnd_protocol
)
1335 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
1336 case IRMP_SIRCS_PROTOCOL
:
1338 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
1339 case IRMP_NEC_PROTOCOL
:
1341 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
1342 case IRMP_SAMSUNG_PROTOCOL
:
1343 case IRMP_SAMSUNG32_PROTOCOL
:
1345 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
1346 case IRMP_MATSUSHITA_PROTOCOL
:
1348 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1
1349 case IRMP_KASEIKYO_PROTOCOL
:
1351 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
1352 case IRMP_RECS80_PROTOCOL
:
1354 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
1355 case IRMP_RECS80EXT_PROTOCOL
:
1357 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
1358 case IRMP_DENON_PROTOCOL
:
1360 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
1361 case IRMP_NUBERT_PROTOCOL
:
1363 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1364 case IRMP_BANG_OLUFSEN_PROTOCOL
:
1366 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
1367 case IRMP_FDC_PROTOCOL
:
1369 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1
1370 case IRMP_RCCAR_PROTOCOL
:
1372 #if IRSND_SUPPORT_JVC_PROTOCOL == 1
1373 case IRMP_JVC_PROTOCOL
:
1375 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
1376 case IRMP_NIKON_PROTOCOL
:
1378 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1
1379 case IRMP_LEGO_PROTOCOL
:
1383 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1 || IRSND_SUPPORT_NEC_PROTOCOL == 1 || IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1 || IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1 || \
1384 IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1 || IRSND_SUPPORT_RECS80_PROTOCOL == 1 || IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1 || IRSND_SUPPORT_DENON_PROTOCOL == 1 || \
1385 IRSND_SUPPORT_NUBERT_PROTOCOL == 1 || IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 || IRSND_SUPPORT_FDC_PROTOCOL == 1 || IRSND_SUPPORT_RCCAR_PROTOCOL == 1 || \
1386 IRSND_SUPPORT_JVC_PROTOCOL == 1 || IRSND_SUPPORT_NIKON_PROTOCOL == 1 || IRSND_SUPPORT_LEGO_PROTOCOL == 1
1388 if (pulse_counter
== 0)
1390 if (current_bit
== 0xFF) // send start bit
1392 pulse_len
= startbit_pulse_len
;
1393 pause_len
= startbit_pause_len
;
1395 else if (current_bit
< complete_data_len
) // send n'th bit
1397 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
1398 if (irsnd_protocol
== IRMP_SAMSUNG_PROTOCOL
)
1400 if (current_bit
< SAMSUNG_ADDRESS_LEN
) // send address bits
1402 pulse_len
= SAMSUNG_PULSE_LEN
;
1403 pause_len
= (irsnd_buffer
[current_bit
/ 8] & (1<<(7-(current_bit
% 8)))) ?
1404 (SAMSUNG_1_PAUSE_LEN
- 1) : (SAMSUNG_0_PAUSE_LEN
- 1);
1406 else if (current_bit
== SAMSUNG_ADDRESS_LEN
) // send SYNC bit (16th bit)
1408 pulse_len
= SAMSUNG_PULSE_LEN
;
1409 pause_len
= SAMSUNG_START_BIT_PAUSE_LEN
- 1;
1411 else if (current_bit
< SAMSUNG_COMPLETE_DATA_LEN
) // send n'th bit
1413 uint8_t cur_bit
= current_bit
- 1; // sync skipped, offset = -1 !
1415 pulse_len
= SAMSUNG_PULSE_LEN
;
1416 pause_len
= (irsnd_buffer
[cur_bit
/ 8] & (1<<(7-(cur_bit
% 8)))) ?
1417 (SAMSUNG_1_PAUSE_LEN
- 1) : (SAMSUNG_0_PAUSE_LEN
- 1);
1423 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1424 if (irsnd_protocol
== IRMP_BANG_OLUFSEN_PROTOCOL
)
1426 if (current_bit
== 0) // send 2nd start bit
1428 pulse_len
= BANG_OLUFSEN_START_BIT2_PULSE_LEN
;
1429 pause_len
= BANG_OLUFSEN_START_BIT2_PAUSE_LEN
- 1;
1431 else if (current_bit
== 1) // send 3rd start bit
1433 pulse_len
= BANG_OLUFSEN_START_BIT3_PULSE_LEN
;
1434 pause_len
= BANG_OLUFSEN_START_BIT3_PAUSE_LEN
- 1;
1436 else if (current_bit
== 2) // send 4th start bit
1438 pulse_len
= BANG_OLUFSEN_START_BIT2_PULSE_LEN
;
1439 pause_len
= BANG_OLUFSEN_START_BIT2_PAUSE_LEN
- 1;
1441 else if (current_bit
== 19) // send trailer bit
1443 pulse_len
= BANG_OLUFSEN_PULSE_LEN
;
1444 pause_len
= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN
- 1;
1446 else if (current_bit
< BANG_OLUFSEN_COMPLETE_DATA_LEN
) // send n'th bit
1448 uint8_t cur_bit_value
= (irsnd_buffer
[current_bit
/ 8] & (1<<(7-(current_bit
% 8)))) ? 1 : 0;
1449 pulse_len
= BANG_OLUFSEN_PULSE_LEN
;
1451 if (cur_bit_value
== last_bit_value
)
1453 pause_len
= BANG_OLUFSEN_R_PAUSE_LEN
- 1;
1457 pause_len
= cur_bit_value
? (BANG_OLUFSEN_1_PAUSE_LEN
- 1) : (BANG_OLUFSEN_0_PAUSE_LEN
- 1);
1458 last_bit_value
= cur_bit_value
;
1464 if (irsnd_buffer
[current_bit
/ 8] & (1<<(7-(current_bit
% 8))))
1466 pulse_len
= pulse_1_len
;
1467 pause_len
= pause_1_len
;
1471 pulse_len
= pulse_0_len
;
1472 pause_len
= pause_0_len
;
1475 else if (has_stop_bit
) // send stop bit
1477 pulse_len
= pulse_0_len
;
1479 if (auto_repetition_counter
< n_auto_repetitions
)
1481 pause_len
= pause_0_len
;
1485 pause_len
= 255; // last frame: pause of 255
1490 if (pulse_counter
< pulse_len
)
1492 if (pulse_counter
== 0)
1498 else if (pause_counter
< pause_len
)
1500 if (pause_counter
== 0)
1510 if (current_bit
>= complete_data_len
+ has_stop_bit
)
1513 auto_repetition_counter
++;
1515 if (auto_repetition_counter
== n_auto_repetitions
)
1518 auto_repetition_counter
= 0;
1530 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
1531 case IRMP_RC5_PROTOCOL
:
1533 #if IRSND_SUPPORT_RC6_PROTOCOL == 1
1534 case IRMP_RC6_PROTOCOL
:
1536 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1
1537 case IRMP_RC6A_PROTOCOL
:
1539 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
1540 case IRMP_SIEMENS_PROTOCOL
:
1542 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
1543 case IRMP_GRUNDIG_PROTOCOL
:
1545 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1546 case IRMP_NOKIA_PROTOCOL
:
1549 #if IRSND_SUPPORT_RC5_PROTOCOL == 1 || IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1 || IRSND_SUPPORT_SIEMENS_PROTOCOL == 1 || \
1550 IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1552 if (pulse_counter
== pulse_len
&& pause_counter
== pause_len
)
1556 if (current_bit
>= complete_data_len
)
1560 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1561 if (irsnd_protocol
== IRMP_GRUNDIG_PROTOCOL
|| irsnd_protocol
== IRMP_NOKIA_PROTOCOL
)
1563 auto_repetition_counter
++;
1565 if (repeat_counter
> 0)
1566 { // set 117 msec pause time
1567 auto_repetition_pause_len
= GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN
;
1570 if (repeat_counter
< n_repeat_frames
) // tricky: repeat n info frames per auto repetition before sending last stop frame
1572 n_auto_repetitions
++; // increment number of auto repetitions
1575 else if (auto_repetition_counter
== n_auto_repetitions
)
1578 auto_repetition_counter
= 0;
1597 uint8_t first_pulse
;
1599 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1600 if (irsnd_protocol
== IRMP_GRUNDIG_PROTOCOL
|| irsnd_protocol
== IRMP_NOKIA_PROTOCOL
)
1602 if (current_bit
== 0xFF || // start bit of start-frame
1603 (irsnd_protocol
== IRMP_GRUNDIG_PROTOCOL
&& current_bit
== 15) || // start bit of info-frame (Grundig)
1604 (irsnd_protocol
== IRMP_NOKIA_PROTOCOL
&& (current_bit
== 23 || current_bit
== 47))) // start bit of info- or stop-frame (Nokia)
1606 pulse_len
= startbit_pulse_len
;
1607 pause_len
= startbit_pause_len
;
1610 else // send n'th bit
1612 pulse_len
= GRUNDIG_NOKIA_IR60_BIT_LEN
;
1613 pause_len
= GRUNDIG_NOKIA_IR60_BIT_LEN
;
1614 first_pulse
= (irsnd_buffer
[current_bit
/ 8] & (1<<(7-(current_bit
% 8)))) ? TRUE
: FALSE
;
1617 else // if (irsnd_protocol == IRMP_RC5_PROTOCOL || irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL ||
1618 // irsnd_protocol == IRMP_SIEMENS_PROTOCOL)
1621 if (current_bit
== 0xFF) // 1 start bit
1623 #if IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1
1624 if (irsnd_protocol
== IRMP_RC6_PROTOCOL
|| irsnd_protocol
== IRMP_RC6A_PROTOCOL
)
1626 pulse_len
= startbit_pulse_len
;
1627 pause_len
= startbit_pause_len
;
1632 else // send n'th bit
1634 #if IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1
1635 if (irsnd_protocol
== IRMP_RC6_PROTOCOL
|| irsnd_protocol
== IRMP_RC6A_PROTOCOL
)
1637 pulse_len
= RC6_BIT_LEN
;
1638 pause_len
= RC6_BIT_LEN
;
1640 if (irsnd_protocol
== IRMP_RC6_PROTOCOL
)
1642 if (current_bit
== 4) // toggle bit (double len)
1644 pulse_len
= 2 * RC6_BIT_LEN
;
1645 pause_len
= 2 * RC6_BIT_LEN
;
1648 else // if (irsnd_protocol == IRMP_RC6A_PROTOCOL)
1650 if (current_bit
== 4) // toggle bit (double len)
1652 pulse_len
= 2 * RC6_BIT_LEN
+ RC6_BIT_LEN
; // hack!
1653 pause_len
= 2 * RC6_BIT_LEN
;
1655 else if (current_bit
== 5) // toggle bit (double len)
1657 pause_len
= 2 * RC6_BIT_LEN
;
1662 first_pulse
= (irsnd_buffer
[current_bit
/ 8] & (1<<(7-(current_bit
% 8)))) ? TRUE
: FALSE
;
1665 if (irsnd_protocol
== IRMP_RC5_PROTOCOL
)
1667 first_pulse
= first_pulse
? FALSE
: TRUE
;
1673 if (pulse_counter
< pulse_len
)
1675 if (pulse_counter
== 0)
1681 else // if (pause_counter < pause_len)
1683 if (pause_counter
== 0)
1692 if (pause_counter
< pause_len
)
1694 if (pause_counter
== 0)
1700 else // if (pulse_counter < pulse_len)
1702 if (pulse_counter
== 0)
1712 #endif // IRSND_SUPPORT_RC5_PROTOCOL == 1 || IRSND_SUPPORT_RC6_PROTOCOL == 1 || || IRSND_SUPPORT_RC6A_PROTOCOL == 1 || IRSND_SUPPORT_SIEMENS_PROTOCOL == 1 ||
1713 // IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1725 if (repeat_counter
< n_repeat_frames
)
1727 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
1728 if (irsnd_protocol
== IRMP_FDC_PROTOCOL
)
1730 irsnd_buffer
[2] |= 0x0F;
1738 n_repeat_frames
= 0;
1760 // main function - for unix/linux + windows only!
1762 // Compile it under linux with:
1763 // cc irsnd.c -o irsnd
1765 // usage: ./irsnd protocol hex-address hex-command >filename
1768 main (int argc
, char ** argv
)
1774 IRMP_DATA irmp_data
;
1776 if (argc
!= 4 && argc
!= 5)
1778 fprintf (stderr
, "usage: %s protocol hex-address hex-command [repeat] > filename\n", argv
[0]);
1782 if (sscanf (argv
[1], "%d", &protocol
) == 1 &&
1783 sscanf (argv
[2], "%x", &address
) == 1 &&
1784 sscanf (argv
[3], "%x", &command
) == 1)
1786 irmp_data
.protocol
= protocol
;
1787 irmp_data
.address
= address
;
1788 irmp_data
.command
= command
;
1792 irmp_data
.flags
= atoi (argv
[4]);
1796 irmp_data
.flags
= 0;
1801 (void) irsnd_send_data (&irmp_data
, TRUE
);
1807 for (idx
= 0; idx
< 20; idx
++)
1816 fprintf (stderr
, "%s: wrong arguments\n", argv
[0]);