1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
4 * Copyright (c) 2010-2011 Frank Meyer - frank(at)fli4l.de
6 * Supported mikrocontrollers:
10 * ATmega8, ATmega16, ATmega32
12 * ATmega164, ATmega324, ATmega644, ATmega644P, ATmega1284
13 * ATmega88, ATmega88P, ATmega168, ATmega168P, ATmega328P
15 * $Id: irsnd.c,v 1.48 2012/02/24 14:24:28 fm Exp $
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 *---------------------------------------------------------------------------------------------------------------------------------------------------
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
31 #ifdef unix // test/debug on linux/unix
39 #define F_CPU 8000000L
43 #ifdef WIN32 // test/debug on windows
48 #define F_CPU 8000000L
49 typedef unsigned char uint8_t;
50 typedef unsigned short uint16_t;
59 #elif defined(PIC_C18)
64 #include <util/delay.h>
65 #include <avr/pgmspace.h>
72 #include "irsndconfig.h"
75 /*---------------------------------------------------------------------------------------------------------------------------------------------------
76 * ATtiny pin definition of OC0A / OC0B
77 * ATmega pin definition of OC2 / OC2A / OC2B / OC0 / OC0A / OC0B
78 *---------------------------------------------------------------------------------------------------------------------------------------------------
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
90 #error Wrong value for IRSND_OCx, choose IRSND_OC0A or IRSND_OC0B in irsndconfig.h
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
103 #error Wrong value for IRSND_OCx, choose IRSND_OC0A or IRSND_OC0B in irsndconfig.h
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
112 #error Wrong value for IRSND_OCx, choose IRSND_OC2 in irsndconfig.h
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
123 #error Wrong value for IRSND_OCx, choose IRSND_OC2 in irsndconfig.h
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
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
137 #error Wrong value for IRSND_OCx, choose IRSND_OC2 or IRSND_OC0 in irsndconfig.h
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
163 #error Wrong value for IRSND_OCx, choose IRSND_OC2A, IRSND_OC2B, IRSND_OC0A, or IRSND_OC0B in irsndconfig.h
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
189 #error Wrong value for IRSND_OCx, choose IRSND_OC2A, IRSND_OC2B, IRSND_OC0A, or IRSND_OC0B in irsndconfig.h
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
207 #elif defined (PIC_C18) //Microchip C18 compiler
208 //Nothing here to do here -> See irsndconfig.h
211 #if !defined (unix) && !defined (WIN32)
212 #error mikrocontroller not defined, please fill in definitions here.
213 #endif // unix, WIN32
216 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
217 typedef uint16_t IRSND_PAUSE_LEN
;
219 typedef uint8_t IRSND_PAUSE_LEN
;
222 /*---------------------------------------------------------------------------------------------------------------------------------------------------
224 *---------------------------------------------------------------------------------------------------------------------------------------------------
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!
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!
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!
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!
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!
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!
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!
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!
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!
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!
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!
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!
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!
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!
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!
331 #define IR60_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * IR60_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t!
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!
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)
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)
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!
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!
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!
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!
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!
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
;
400 #if IRSND_USE_CALLBACK == 1
401 static void (*irsnd_callback_ptr
) (uint8_t);
402 #endif // IRSND_USE_CALLBACK == 1
404 /*---------------------------------------------------------------------------------------------------------------------------------------------------
406 * @details Switches PWM on with a narrow spike on all 3 channels -> leds glowing
407 *---------------------------------------------------------------------------------------------------------------------------------------------------
417 IRSND_PIN
= 0; // output mode -> enable PWM outout pin (0=PWM on, 1=PWM off)
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!)
433 #error wrong value of IRSND_OCx
439 #if IRSND_USE_CALLBACK == 1
440 if (irsnd_callback_ptr
)
442 (*irsnd_callback_ptr
) (TRUE
);
444 #endif // IRSND_USE_CALLBACK == 1
450 /*---------------------------------------------------------------------------------------------------------------------------------------------------
452 * @details Switches PWM off
453 *---------------------------------------------------------------------------------------------------------------------------------------------------
463 IRSND_PIN
= 1; //input mode -> disbale PWM output pin (0=PWM on, 1=PWM off)
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.
479 #error wrong value of IRSND_OCx
481 IRSND_PORT
&= ~(1<<IRSND_BIT
); // set IRSND_BIT to low
485 #if IRSND_USE_CALLBACK == 1
486 if (irsnd_callback_ptr
)
488 (*irsnd_callback_ptr
) (FALSE
);
490 #endif // IRSND_USE_CALLBACK == 1
496 /*---------------------------------------------------------------------------------------------------------------------------------------------------
498 * @details sets pwm frequency
499 *---------------------------------------------------------------------------------------------------------------------------------------------------
502 irsnd_set_freq (uint8_t freq
)
508 SetDCPWM( (uint16_t) freq
* 2); // freq*2 = Duty cycles 50%
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!
524 #error wrong value of IRSND_OCx
530 /*---------------------------------------------------------------------------------------------------------------------------------------------------
532 * @details Configures 0CR0A, 0CR0B and 0CR2B as PWM channels
533 *---------------------------------------------------------------------------------------------------------------------------------------------------
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)
544 IRSND_PORT
&= ~(1<<IRSND_BIT
); // set IRSND_BIT to low
545 IRSND_DDR
|= (1<<IRSND_BIT
); // set IRSND_BIT to output
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
560 #error wrong value of IRSND_OCx
562 irsnd_set_freq (IRSND_FREQ_36_KHZ
); // default frequency
567 #if IRSND_USE_CALLBACK == 1
569 irsnd_set_callback_ptr (void (*cb
)(uint8_t))
571 irsnd_callback_ptr
= cb
;
573 #endif // IRSND_USE_CALLBACK == 1
582 bitsrevervse (uint16_t x
, uint8_t len
)
600 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
601 static uint8_t sircs_additional_bitlen
;
602 #endif // IRSND_SUPPORT_SIRCS_PROTOCOL == 1
605 irsnd_send_data (IRMP_DATA
* irmp_data_p
, uint8_t do_wait
)
607 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
608 static uint8_t toggle_bit_recs80
;
610 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
611 static uint8_t toggle_bit_recs80ext
;
613 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
614 static uint8_t toggle_bit_rc5
;
616 #if IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1
617 static uint8_t toggle_bit_rc6
;
619 #if IRSND_SUPPORT_THOMSON_PROTOCOL == 1
620 static uint8_t toggle_bit_thomson
;
637 irsnd_protocol
= irmp_data_p
->protocol
;
638 irsnd_repeat
= irmp_data_p
->flags
& IRSND_REPETITION_MASK
;
640 switch (irsnd_protocol
)
642 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
643 case IRMP_SIRCS_PROTOCOL
:
645 uint8_t sircs_additional_command_len
;
646 uint8_t sircs_additional_address_len
;
648 sircs_additional_bitlen
= (irmp_data_p
->address
& 0xFF00) >> 8; // additional bitlen
650 if (sircs_additional_bitlen
> 15 - SIRCS_MINIMUM_DATA_LEN
)
652 sircs_additional_command_len
= 15 - SIRCS_MINIMUM_DATA_LEN
;
653 sircs_additional_address_len
= sircs_additional_bitlen
- (15 - SIRCS_MINIMUM_DATA_LEN
);
657 sircs_additional_command_len
= sircs_additional_bitlen
;
658 sircs_additional_address_len
= 0;
661 command
= bitsrevervse (irmp_data_p
->command
, 15);
663 irsnd_buffer
[0] = (command
& 0x7F80) >> 7; // CCCCCCCC
664 irsnd_buffer
[1] = (command
& 0x007F) << 1; // CCCC****
666 if (sircs_additional_address_len
> 0)
668 address
= bitsrevervse (irmp_data_p
->address
, 5);
669 irsnd_buffer
[1] |= (address
& 0x0010) >> 4;
670 irsnd_buffer
[2] = (address
& 0x000F) << 4;
676 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
677 case IRMP_APPLE_PROTOCOL
:
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)
682 address
= bitsrevervse (address
, NEC_ADDRESS_LEN
);
683 command
= bitsrevervse (command
, NEC_COMMAND_LEN
);
685 irsnd_protocol
= IRMP_NEC_PROTOCOL
; // APPLE protocol is NEC with id instead of inverted command
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)
694 case IRMP_NEC_PROTOCOL
:
696 address
= bitsrevervse (irmp_data_p
->address
, NEC_ADDRESS_LEN
);
697 command
= bitsrevervse (irmp_data_p
->command
, NEC_COMMAND_LEN
);
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
707 #if IRSND_SUPPORT_NEC16_PROTOCOL == 1
708 case IRMP_NEC16_PROTOCOL
:
710 address
= bitsrevervse (irmp_data_p
->address
, NEC16_ADDRESS_LEN
);
711 command
= bitsrevervse (irmp_data_p
->command
, NEC16_COMMAND_LEN
);
713 irsnd_buffer
[0] = (address
& 0x00FF); // AAAAAAAA
714 irsnd_buffer
[1] = (command
& 0x00FF); // CCCCCCCC
719 #if IRSND_SUPPORT_NEC42_PROTOCOL == 1
720 case IRMP_NEC42_PROTOCOL
:
722 address
= bitsrevervse (irmp_data_p
->address
, NEC42_ADDRESS_LEN
);
723 command
= bitsrevervse (irmp_data_p
->command
, NEC42_COMMAND_LEN
);
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
735 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
736 case IRMP_SAMSUNG_PROTOCOL
:
738 address
= bitsrevervse (irmp_data_p
->address
, SAMSUNG_ADDRESS_LEN
);
739 command
= bitsrevervse (irmp_data_p
->command
, SAMSUNG_COMMAND_LEN
);
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
749 case IRMP_SAMSUNG32_PROTOCOL
:
751 address
= bitsrevervse (irmp_data_p
->address
, SAMSUNG_ADDRESS_LEN
);
752 command
= bitsrevervse (irmp_data_p
->command
, SAMSUNG32_COMMAND_LEN
);
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
762 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
763 case IRMP_MATSUSHITA_PROTOCOL
:
765 address
= bitsrevervse (irmp_data_p
->address
, MATSUSHITA_ADDRESS_LEN
);
766 command
= bitsrevervse (irmp_data_p
->command
, MATSUSHITA_COMMAND_LEN
);
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
775 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1
776 case IRMP_KASEIKYO_PROTOCOL
:
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);
785 xor = ((address
& 0x000F) ^ ((address
& 0x00F0) >> 4) ^ ((address
& 0x0F00) >> 8) ^ ((address
& 0xF000) >> 12)) & 0x0F;
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
793 xor = irsnd_buffer
[2] ^ irsnd_buffer
[3] ^ irsnd_buffer
[4];
795 irsnd_buffer
[5] = xor;
800 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
801 case IRMP_RECS80_PROTOCOL
:
803 toggle_bit_recs80
= toggle_bit_recs80
? 0x00 : 0x40;
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
812 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
813 case IRMP_RECS80EXT_PROTOCOL
:
815 toggle_bit_recs80ext
= toggle_bit_recs80ext
? 0x00 : 0x40;
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
824 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
825 case IRMP_RC5_PROTOCOL
:
827 toggle_bit_rc5
= toggle_bit_rc5
? 0x00 : 0x40;
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
836 #if IRSND_SUPPORT_RC6_PROTOCOL == 1
837 case IRMP_RC6_PROTOCOL
:
839 toggle_bit_rc6
= toggle_bit_rc6
? 0x00 : 0x08;
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
848 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1
849 case IRMP_RC6A_PROTOCOL
:
851 toggle_bit_rc6
= toggle_bit_rc6
? 0x00 : 0x08;
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
862 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
863 case IRMP_DENON_PROTOCOL
:
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
873 #if IRSND_SUPPORT_THOMSON_PROTOCOL == 1
874 case IRMP_THOMSON_PROTOCOL
:
876 toggle_bit_thomson
= toggle_bit_thomson
? 0x00 : 0x08;
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
884 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
885 case IRMP_NUBERT_PROTOCOL
:
887 irsnd_buffer
[0] = irmp_data_p
->command
>> 2; // CCCCCCCC
888 irsnd_buffer
[1] = (irmp_data_p
->command
& 0x0003) << 6; // CC000000
893 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
894 case IRMP_BANG_OLUFSEN_PROTOCOL
:
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
903 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
904 case IRMP_GRUNDIG_PROTOCOL
:
906 command
= bitsrevervse (irmp_data_p
->command
, GRUNDIG_COMMAND_LEN
);
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
917 #if IRSND_SUPPORT_IR60_PROTOCOL == 1
918 case IRMP_IR60_PROTOCOL
:
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)
928 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
929 case IRMP_NOKIA_PROTOCOL
:
931 address
= bitsrevervse (irmp_data_p
->address
, NOKIA_ADDRESS_LEN
);
932 command
= bitsrevervse (irmp_data_p
->command
, NOKIA_COMMAND_LEN
);
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
945 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
946 case IRMP_SIEMENS_PROTOCOL
:
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
956 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
957 case IRMP_FDC_PROTOCOL
:
959 address
= bitsrevervse (irmp_data_p
->address
, FDC_ADDRESS_LEN
);
960 command
= bitsrevervse (irmp_data_p
->command
, FDC_COMMAND_LEN
);
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
971 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1
972 case IRMP_RCCAR_PROTOCOL
:
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
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
984 #if IRSND_SUPPORT_JVC_PROTOCOL == 1
985 case IRMP_JVC_PROTOCOL
:
987 address
= bitsrevervse (irmp_data_p
->address
, JVC_ADDRESS_LEN
);
988 command
= bitsrevervse (irmp_data_p
->command
, JVC_COMMAND_LEN
);
990 irsnd_buffer
[0] = ((address
& 0x000F) << 4) | (command
& 0x0F00) >> 8; // AAAACCCC
991 irsnd_buffer
[1] = (command
& 0x00FF); // CCCCCCCC
997 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
998 case IRMP_NIKON_PROTOCOL
:
1000 irsnd_buffer
[0] = (irmp_data_p
->command
& 0x0003) << 6; // CC
1005 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1
1006 case IRMP_LEGO_PROTOCOL
:
1008 uint8_t crc
= 0x0F ^ ((irmp_data_p
->command
& 0x0F00) >> 8) ^ ((irmp_data_p
->command
& 0x00F0) >> 4) ^ (irmp_data_p
->command
& 0x000F);
1010 irsnd_buffer
[0] = (irmp_data_p
->command
& 0x0FF0) >> 4; // CCCCCCCC
1011 irsnd_buffer
[1] = ((irmp_data_p
->command
& 0x000F) << 4) | crc
; // CCCCcccc
1013 irsnd_protocol
= IRMP_LEGO_PROTOCOL
;
1033 /*---------------------------------------------------------------------------------------------------------------------------------------------------
1035 * @details ISR routine, called 10000 times per second
1036 *---------------------------------------------------------------------------------------------------------------------------------------------------
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
;
1065 static uint8_t pulse_len
= 0xFF;
1066 static IRSND_PAUSE_LEN pause_len
= 0xFF;
1070 if (current_bit
== 0xFF && new_frame
) // start of transmission...
1072 if (auto_repetition_counter
> 0)
1074 auto_repetition_pause_counter
++;
1076 if (auto_repetition_pause_counter
>= auto_repetition_pause_len
)
1078 auto_repetition_pause_counter
= 0;
1080 if (irsnd_protocol
== IRMP_DENON_PROTOCOL
) // n'th denon frame
1083 complete_data_len
= 2 * DENON_COMPLETE_DATA_LEN
+ 1;
1085 else if (irsnd_protocol
== IRMP_GRUNDIG_PROTOCOL
) // n'th grundig frame
1088 complete_data_len
= 16 + GRUNDIG_COMPLETE_DATA_LEN
;
1090 else if (irsnd_protocol
== IRMP_IR60_PROTOCOL
) // n'th IR60 frame
1093 complete_data_len
= 2 * IR60_COMPLETE_DATA_LEN
+ 1;
1095 else if (irsnd_protocol
== IRMP_NOKIA_PROTOCOL
) // n'th nokia frame
1097 if (auto_repetition_counter
+ 1 < n_auto_repetitions
)
1100 complete_data_len
= 24 + NOKIA_COMPLETE_DATA_LEN
;
1102 else // nokia stop frame
1105 complete_data_len
= NOKIA_COMPLETE_DATA_LEN
;
1125 else if (repeat_counter
> 0 && packet_repeat_pause_counter
< repeat_frame_pause_len
)
1127 else if (packet_repeat_pause_counter
< repeat_frame_pause_len
)
1130 packet_repeat_pause_counter
++;
1150 send_trailer
= FALSE
;
1154 n_repeat_frames
= irsnd_repeat
;
1156 if (n_repeat_frames
== IRSND_ENDLESS_REPETITION
)
1158 n_repeat_frames
= 255;
1161 packet_repeat_pause_counter
= 0;
1165 switch (irsnd_protocol
)
1167 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
1168 case IRMP_SIRCS_PROTOCOL
:
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
);
1185 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
1186 case IRMP_NEC_PROTOCOL
:
1188 startbit_pulse_len
= NEC_START_BIT_PULSE_LEN
;
1190 if (repeat_counter
> 0)
1192 startbit_pause_len
= NEC_REPEAT_START_BIT_PAUSE_LEN
- 1;
1193 complete_data_len
= 0;
1197 startbit_pause_len
= NEC_START_BIT_PAUSE_LEN
- 1;
1198 complete_data_len
= NEC_COMPLETE_DATA_LEN
;
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
);
1213 #if IRSND_SUPPORT_NEC16_PROTOCOL == 1
1214 case IRMP_NEC16_PROTOCOL
:
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
);
1231 #if IRSND_SUPPORT_NEC42_PROTOCOL == 1
1232 case IRMP_NEC42_PROTOCOL
:
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
);
1249 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
1250 case IRMP_SAMSUNG_PROTOCOL
:
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
);
1267 case IRMP_SAMSUNG32_PROTOCOL
:
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
);
1284 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
1285 case IRMP_MATSUSHITA_PROTOCOL
:
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
);
1302 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1
1303 case IRMP_KASEIKYO_PROTOCOL
:
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
);
1320 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
1321 case IRMP_RECS80_PROTOCOL
:
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
);
1338 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
1339 case IRMP_RECS80EXT_PROTOCOL
:
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
);
1356 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
1357 case IRMP_RC5_PROTOCOL
:
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
);
1372 #if IRSND_SUPPORT_RC6_PROTOCOL == 1
1373 case IRMP_RC6_PROTOCOL
:
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
);
1388 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1
1389 case IRMP_RC6A_PROTOCOL
:
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
);
1404 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
1405 case IRMP_DENON_PROTOCOL
:
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
1422 #if IRSND_SUPPORT_THOMSON_PROTOCOL == 1
1423 case IRMP_THOMSON_PROTOCOL
:
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
);
1440 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
1441 case IRMP_NUBERT_PROTOCOL
:
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
);
1458 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1459 case IRMP_BANG_OLUFSEN_PROTOCOL
:
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
;
1473 irsnd_set_freq (IRSND_FREQ_455_KHZ
);
1477 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
1478 case IRMP_GRUNDIG_PROTOCOL
:
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
);
1493 #if IRSND_SUPPORT_IR60_PROTOCOL == 1
1494 case IRMP_IR60_PROTOCOL
:
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
);
1509 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1510 case IRMP_NOKIA_PROTOCOL
:
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
);
1525 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
1526 case IRMP_SIEMENS_PROTOCOL
:
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
);
1541 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
1542 case IRMP_FDC_PROTOCOL
:
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
);
1559 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1
1560 case IRMP_RCCAR_PROTOCOL
:
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
);
1577 #if IRSND_SUPPORT_JVC_PROTOCOL == 1
1578 case IRMP_JVC_PROTOCOL
:
1580 if (repeat_counter
!= 0) // skip start bit if repetition frame
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
);
1600 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
1601 case IRMP_NIKON_PROTOCOL
:
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
);
1618 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1
1619 case IRMP_LEGO_PROTOCOL
:
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
);
1649 switch (irsnd_protocol
)
1651 #if IRSND_SUPPORT_SIRCS_PROTOCOL == 1
1652 case IRMP_SIRCS_PROTOCOL
:
1654 #if IRSND_SUPPORT_NEC_PROTOCOL == 1
1655 case IRMP_NEC_PROTOCOL
:
1657 #if IRSND_SUPPORT_NEC16_PROTOCOL == 1
1658 case IRMP_NEC16_PROTOCOL
:
1660 #if IRSND_SUPPORT_NEC42_PROTOCOL == 1
1661 case IRMP_NEC42_PROTOCOL
:
1663 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
1664 case IRMP_SAMSUNG_PROTOCOL
:
1665 case IRMP_SAMSUNG32_PROTOCOL
:
1667 #if IRSND_SUPPORT_MATSUSHITA_PROTOCOL == 1
1668 case IRMP_MATSUSHITA_PROTOCOL
:
1670 #if IRSND_SUPPORT_KASEIKYO_PROTOCOL == 1
1671 case IRMP_KASEIKYO_PROTOCOL
:
1673 #if IRSND_SUPPORT_RECS80_PROTOCOL == 1
1674 case IRMP_RECS80_PROTOCOL
:
1676 #if IRSND_SUPPORT_RECS80EXT_PROTOCOL == 1
1677 case IRMP_RECS80EXT_PROTOCOL
:
1679 #if IRSND_SUPPORT_DENON_PROTOCOL == 1
1680 case IRMP_DENON_PROTOCOL
:
1682 #if IRSND_SUPPORT_THOMSON_PROTOCOL == 1
1683 case IRMP_THOMSON_PROTOCOL
:
1685 #if IRSND_SUPPORT_NUBERT_PROTOCOL == 1
1686 case IRMP_NUBERT_PROTOCOL
:
1688 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1689 case IRMP_BANG_OLUFSEN_PROTOCOL
:
1691 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
1692 case IRMP_FDC_PROTOCOL
:
1694 #if IRSND_SUPPORT_RCCAR_PROTOCOL == 1
1695 case IRMP_RCCAR_PROTOCOL
:
1697 #if IRSND_SUPPORT_JVC_PROTOCOL == 1
1698 case IRMP_JVC_PROTOCOL
:
1700 #if IRSND_SUPPORT_NIKON_PROTOCOL == 1
1701 case IRMP_NIKON_PROTOCOL
:
1703 #if IRSND_SUPPORT_LEGO_PROTOCOL == 1
1704 case IRMP_LEGO_PROTOCOL
:
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
1714 if (pulse_counter
== 0)
1716 if (current_bit
== 0xFF) // send start bit
1718 pulse_len
= startbit_pulse_len
;
1719 pause_len
= startbit_pause_len
;
1721 else if (current_bit
< complete_data_len
) // send n'th bit
1723 #if IRSND_SUPPORT_SAMSUNG_PROTOCOL == 1
1724 if (irsnd_protocol
== IRMP_SAMSUNG_PROTOCOL
)
1726 if (current_bit
< SAMSUNG_ADDRESS_LEN
) // send address bits
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);
1732 else if (current_bit
== SAMSUNG_ADDRESS_LEN
) // send SYNC bit (16th bit)
1734 pulse_len
= SAMSUNG_PULSE_LEN
;
1735 pause_len
= SAMSUNG_START_BIT_PAUSE_LEN
- 1;
1737 else if (current_bit
< SAMSUNG_COMPLETE_DATA_LEN
) // send n'th bit
1739 uint8_t cur_bit
= current_bit
- 1; // sync skipped, offset = -1 !
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);
1749 #if IRSND_SUPPORT_NEC16_PROTOCOL == 1
1750 if (irsnd_protocol
== IRMP_NEC16_PROTOCOL
)
1752 if (current_bit
< NEC16_ADDRESS_LEN
) // send address bits
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);
1758 else if (current_bit
== NEC16_ADDRESS_LEN
) // send SYNC bit (8th bit)
1760 pulse_len
= NEC_PULSE_LEN
;
1761 pause_len
= NEC_START_BIT_PAUSE_LEN
- 1;
1763 else if (current_bit
< NEC16_COMPLETE_DATA_LEN
+ 1) // send n'th bit
1765 uint8_t cur_bit
= current_bit
- 1; // sync skipped, offset = -1 !
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);
1775 #if IRSND_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1
1776 if (irsnd_protocol
== IRMP_BANG_OLUFSEN_PROTOCOL
)
1778 if (current_bit
== 0) // send 2nd start bit
1780 pulse_len
= BANG_OLUFSEN_START_BIT2_PULSE_LEN
;
1781 pause_len
= BANG_OLUFSEN_START_BIT2_PAUSE_LEN
- 1;
1783 else if (current_bit
== 1) // send 3rd start bit
1785 pulse_len
= BANG_OLUFSEN_START_BIT3_PULSE_LEN
;
1786 pause_len
= BANG_OLUFSEN_START_BIT3_PAUSE_LEN
- 1;
1788 else if (current_bit
== 2) // send 4th start bit
1790 pulse_len
= BANG_OLUFSEN_START_BIT2_PULSE_LEN
;
1791 pause_len
= BANG_OLUFSEN_START_BIT2_PAUSE_LEN
- 1;
1793 else if (current_bit
== 19) // send trailer bit
1795 pulse_len
= BANG_OLUFSEN_PULSE_LEN
;
1796 pause_len
= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN
- 1;
1798 else if (current_bit
< BANG_OLUFSEN_COMPLETE_DATA_LEN
) // send n'th bit
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
;
1803 if (cur_bit_value
== last_bit_value
)
1805 pause_len
= BANG_OLUFSEN_R_PAUSE_LEN
- 1;
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
;
1816 if (irsnd_buffer
[current_bit
/ 8] & (1<<(7-(current_bit
% 8))))
1818 pulse_len
= pulse_1_len
;
1819 pause_len
= pause_1_len
;
1823 pulse_len
= pulse_0_len
;
1824 pause_len
= pause_0_len
;
1827 else if (has_stop_bit
) // send stop bit
1829 pulse_len
= pulse_0_len
;
1831 if (auto_repetition_counter
< n_auto_repetitions
)
1833 pause_len
= pause_0_len
;
1837 pause_len
= 255; // last frame: pause of 255
1842 if (pulse_counter
< pulse_len
)
1844 if (pulse_counter
== 0)
1850 else if (pause_counter
< pause_len
)
1852 if (pause_counter
== 0)
1862 if (current_bit
>= complete_data_len
+ has_stop_bit
)
1865 auto_repetition_counter
++;
1867 if (auto_repetition_counter
== n_auto_repetitions
)
1870 auto_repetition_counter
= 0;
1882 #if IRSND_SUPPORT_RC5_PROTOCOL == 1
1883 case IRMP_RC5_PROTOCOL
:
1885 #if IRSND_SUPPORT_RC6_PROTOCOL == 1
1886 case IRMP_RC6_PROTOCOL
:
1888 #if IRSND_SUPPORT_RC6A_PROTOCOL == 1
1889 case IRMP_RC6A_PROTOCOL
:
1891 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1
1892 case IRMP_SIEMENS_PROTOCOL
:
1894 #if IRSND_SUPPORT_GRUNDIG_PROTOCOL == 1
1895 case IRMP_GRUNDIG_PROTOCOL
:
1897 #if IRSND_SUPPORT_IR60_PROTOCOL == 1
1898 case IRMP_IR60_PROTOCOL
:
1900 #if IRSND_SUPPORT_NOKIA_PROTOCOL == 1
1901 case IRMP_NOKIA_PROTOCOL
:
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
1907 if (pulse_counter
== pulse_len
&& pause_counter
== pause_len
)
1911 if (current_bit
>= complete_data_len
)
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
)
1918 auto_repetition_counter
++;
1920 if (repeat_counter
> 0)
1921 { // set 117 msec pause time
1922 auto_repetition_pause_len
= GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN
;
1925 if (repeat_counter
< n_repeat_frames
) // tricky: repeat n info frames per auto repetition before sending last stop frame
1927 n_auto_repetitions
++; // increment number of auto repetitions
1930 else if (auto_repetition_counter
== n_auto_repetitions
)
1933 auto_repetition_counter
= 0;
1952 uint8_t first_pulse
;
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
)
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)
1962 pulse_len
= startbit_pulse_len
;
1963 pause_len
= startbit_pause_len
;
1966 else // send n'th bit
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
;
1973 else // if (irsnd_protocol == IRMP_RC5_PROTOCOL || irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL ||
1974 // irsnd_protocol == IRMP_SIEMENS_PROTOCOL)
1977 if (current_bit
== 0xFF) // 1 start bit
1979 #if IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1
1980 if (irsnd_protocol
== IRMP_RC6_PROTOCOL
|| irsnd_protocol
== IRMP_RC6A_PROTOCOL
)
1982 pulse_len
= startbit_pulse_len
;
1983 pause_len
= startbit_pause_len
;
1988 else // send n'th bit
1990 #if IRSND_SUPPORT_RC6_PROTOCOL == 1 || IRSND_SUPPORT_RC6A_PROTOCOL == 1
1991 if (irsnd_protocol
== IRMP_RC6_PROTOCOL
|| irsnd_protocol
== IRMP_RC6A_PROTOCOL
)
1993 pulse_len
= RC6_BIT_LEN
;
1994 pause_len
= RC6_BIT_LEN
;
1996 if (irsnd_protocol
== IRMP_RC6_PROTOCOL
)
1998 if (current_bit
== 4) // toggle bit (double len)
2000 pulse_len
= 2 * RC6_BIT_LEN
;
2001 pause_len
= 2 * RC6_BIT_LEN
;
2004 else // if (irsnd_protocol == IRMP_RC6A_PROTOCOL)
2006 if (current_bit
== 4) // toggle bit (double len)
2008 pulse_len
= 2 * RC6_BIT_LEN
+ RC6_BIT_LEN
; // hack!
2009 pause_len
= 2 * RC6_BIT_LEN
;
2011 else if (current_bit
== 5) // toggle bit (double len)
2013 pause_len
= 2 * RC6_BIT_LEN
;
2018 first_pulse
= (irsnd_buffer
[current_bit
/ 8] & (1<<(7-(current_bit
% 8)))) ? TRUE
: FALSE
;
2021 if (irsnd_protocol
== IRMP_RC5_PROTOCOL
)
2023 first_pulse
= first_pulse
? FALSE
: TRUE
;
2029 if (pulse_counter
< pulse_len
)
2031 if (pulse_counter
== 0)
2037 else // if (pause_counter < pause_len)
2039 if (pause_counter
== 0)
2048 if (pause_counter
< pause_len
)
2050 if (pause_counter
== 0)
2056 else // if (pulse_counter < pulse_len)
2058 if (pulse_counter
== 0)
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
2081 if (repeat_counter
< n_repeat_frames
)
2083 #if IRSND_SUPPORT_FDC_PROTOCOL == 1
2084 if (irsnd_protocol
== IRMP_FDC_PROTOCOL
)
2086 irsnd_buffer
[2] |= 0x0F;
2094 irsnd_busy
= TRUE
; //Rainer
2095 send_trailer
= TRUE
;
2096 n_repeat_frames
= 0;
2118 // main function - for unix/linux + windows only!
2120 // Compile it under linux with:
2121 // cc irsnd.c -o irsnd
2123 // usage: ./irsnd protocol hex-address hex-command >filename
2126 main (int argc
, char ** argv
)
2131 IRMP_DATA irmp_data
;
2133 if (argc
!= 4 && argc
!= 5)
2135 fprintf (stderr
, "usage: %s protocol hex-address hex-command [repeat] > filename\n", argv
[0]);
2139 if (sscanf (argv
[1], "%d", &protocol
) == 1 &&
2140 sscanf (argv
[2], "%x", &address
) == 1 &&
2141 sscanf (argv
[3], "%x", &command
) == 1)
2143 irmp_data
.protocol
= protocol
;
2144 irmp_data
.address
= address
;
2145 irmp_data
.command
= command
;
2149 irmp_data
.flags
= atoi (argv
[4]);
2153 irmp_data
.flags
= 0;
2158 (void) irsnd_send_data (&irmp_data
, TRUE
);
2169 fprintf (stderr
, "%s: wrong arguments\n", argv
[0]);