Infrared4Arduino
IRremoteInt.h
Go to the documentation of this file.
1 //******************************************************************************
2 // IRremote
3 // Version 2.0.1 June, 2015
4 // Copyright 2009 Ken Shirriff
5 // For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
6 //
7 // Modified by Paul Stoffregen <paul@pjrc.com> to support other boards and timers
8 //
9 // Interrupt code based on NECIRrcv by Joe Knapp
10 // http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
11 // Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/
12 //
13 // JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
14 // Whynter A/C ARC-110WD added by Francesco Meschia
15 //******************************************************************************
16 
17 #ifndef IRremoteint_h
18 #define IRremoteint_h
19 
20 //------------------------------------------------------------------------------
21 // Include the right Arduino header
22 //
23 #if defined(ARDUINO) && (ARDUINO >= 100)
24 # include <Arduino.h>
25 #else
26 # if !defined(IRPRONTO)
27 # include <WProgram.h>
28 # endif
29 #endif
30 
31 //------------------------------------------------------------------------------
32 // This handles definition and access to global variables
33 //
34 #ifdef IR_GLOBAL
35 # define EXTERN
36 #else
37 # define EXTERN extern
38 #endif
39 
40 //------------------------------------------------------------------------------
41 // Information for the Interrupt Service Routine
42 //
43 #define RAWBUF 101 // Maximum length of raw duration buffer
44 
45 typedef
46  struct {
47  // The fields are ordered to reduce memory over caused by struct-padding
48  uint8_t rcvstate; // State Machine state
49  uint8_t recvpin; // Pin connected to IR data from detector
50  uint8_t blinkpin;
51  uint8_t blinkflag; // true -> enable blinking of pin on IR processing
52  uint8_t rawlen; // counter of entries in rawbuf
53  unsigned int timer; // State timer, counts 50uS ticks.
54  unsigned int rawbuf[RAWBUF]; // raw data
55  uint8_t overflow; // Raw buffer overflow occurred
56  }
58 
59 // ISR State-Machine : Receiver States
60 #define STATE_IDLE 2
61 #define STATE_MARK 3
62 #define STATE_SPACE 4
63 #define STATE_STOP 5
64 #define STATE_OVERFLOW 6
65 
66 // Allow all parts of the code access to the ISR data
67 // NB. The data can be changed by the ISR at any time, even mid-function
68 // Therefore we declare it as "volatile" to stop the compiler/CPU caching it
70 
71 //------------------------------------------------------------------------------
72 // Defines for blinking the LED
73 //
74 
75 #if defined(CORE_LED0_PIN)
76 # define BLINKLED CORE_LED0_PIN
77 # define BLINKLED_ON() (digitalWrite(CORE_LED0_PIN, HIGH))
78 # define BLINKLED_OFF() (digitalWrite(CORE_LED0_PIN, LOW))
79 
80 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
81 # define BLINKLED 13
82 # define BLINKLED_ON() (PORTB |= B10000000)
83 # define BLINKLED_OFF() (PORTB &= B01111111)
84 
85 #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
86 # define BLINKLED 0
87 # define BLINKLED_ON() (PORTD |= B00000001)
88 # define BLINKLED_OFF() (PORTD &= B11111110)
89 
90 #else
91 # define BLINKLED 13
92  #define BLINKLED_ON() (PORTB |= B00100000)
93 # define BLINKLED_OFF() (PORTB &= B11011111)
94 #endif
95 
96 //------------------------------------------------------------------------------
97 // CPU Frequency
98 //
99 #ifdef F_CPU
100 # define SYSCLOCK F_CPU // main Arduino clock
101 #else
102 # define SYSCLOCK 16000000 // main Arduino clock
103 #endif
104 
105 //------------------------------------------------------------------------------
106 // Defines for setting and clearing register bits
107 //
108 #ifndef cbi
109 # define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
110 #endif
111 
112 #ifndef sbi
113 # define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
114 #endif
115 
116 //------------------------------------------------------------------------------
117 // Pulse parms are ((X*50)-100) for the Mark and ((X*50)+100) for the Space.
118 // First MARK is the one after the long gap
119 // Pulse parameters in uSec
120 //
121 
122 // Due to sensor lag, when received, Marks tend to be 100us too long and
123 // Spaces tend to be 100us too short
124 #define MARK_EXCESS 100
125 
126 // microseconds per clock interrupt tick
127 #define USECPERTICK 50
128 
129 // Upper and Lower percentage tolerances in measurements
130 #define TOLERANCE 25
131 #define LTOL (1.0 - (TOLERANCE/100.))
132 #define UTOL (1.0 + (TOLERANCE/100.))
133 
134 // Minimum gap between IR transmissions
135 #define _GAP 5000
136 #define GAP_TICKS (_GAP/USECPERTICK)
137 
138 #define TICKS_LOW(us) ((int)(((us)*LTOL/USECPERTICK)))
139 #define TICKS_HIGH(us) ((int)(((us)*UTOL/USECPERTICK + 1)))
140 
141 //------------------------------------------------------------------------------
142 // IR detector output is active low
143 //
144 #define MARK 0
145 #define SPACE 1
146 
147 //------------------------------------------------------------------------------
148 // Define which timer to use
149 //
150 // Uncomment the timer you wish to use on your board.
151 // If you are using another library which uses timer2, you have options to
152 // switch IRremote to use a different timer.
153 //
154 
155 // Arduino Mega
156 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
157  //#define IR_USE_TIMER1 // tx = pin 11
158  #define IR_USE_TIMER2 // tx = pin 9
159  //#define IR_USE_TIMER3 // tx = pin 5
160  //#define IR_USE_TIMER4 // tx = pin 6
161  //#define IR_USE_TIMER5 // tx = pin 46
162 
163 // Teensy 1.0
164 #elif defined(__AVR_AT90USB162__)
165  #define IR_USE_TIMER1 // tx = pin 17
166 
167 // Teensy 2.0
168 #elif defined(__AVR_ATmega32U4__)
169 #ifdef CORE_TEENSY
170  // it's Teensy 2.0
171  //#define IR_SEND_TIMER1 // tx = pin 14
172  //#define IR_SEND_TIMER3 // tx = pin 9
173  #define IR_SEND_TIMER4_HS // tx = pin 10
174 #else
175  // it's probably Leonardo or Micro
176  #define IR_USE_TIMER1 // tx = pin 9
177  //#define IR_USE_TIMER3 // tx = pin 5
178  //#define IR_USE_TIMER4_HS // tx = pin 13
179 #endif
180 
181 // Teensy 3.0 / Teensy 3.1
182 #elif defined(__MK20DX128__) || defined(__MK20DX256__)
183  #define IR_USE_TIMER_CMT // tx = pin 5
184 
185 // Teensy-LC
186 #elif defined(__MKL26Z64__)
187  #define IR_USE_TIMER_TPM1 // tx = pin 16
188 
189 // Teensy++ 1.0 & 2.0
190 #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
191  //#define IR_USE_TIMER1 // tx = pin 25
192  #define IR_USE_TIMER2 // tx = pin 1
193  //#define IR_USE_TIMER3 // tx = pin 16
194 
195 // Sanguino
196 #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
197  //#define IR_USE_TIMER1 // tx = pin 13
198  #define IR_USE_TIMER2 // tx = pin 14
199 
200 // Atmega8
201 #elif defined(__AVR_ATmega8P__) || defined(__AVR_ATmega8__)
202  #define IR_USE_TIMER1 // tx = pin 9
203 
204 // ATtiny84
205 #elif defined(__AVR_ATtiny84__)
206  #define IR_USE_TIMER1 // tx = pin 6
207 
208 //ATtiny85
209 #elif defined(__AVR_ATtiny85__)
210  #define IR_USE_TIMER_TINY0 // tx = pin 1
211 
212 // Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc
213 #else
214  //#define IR_USE_TIMER1 // tx = pin 9
215  #define IR_USE_TIMER2 // tx = pin 3
216 
217 #endif
218 
219 //------------------------------------------------------------------------------
220 // Defines for Timer
221 
222 //---------------------------------------------------------
223 // Timer2 (8 bits)
224 //
225 #if defined(IR_USE_TIMER2)
226 
227 #define TIMER_RESET
228 #define TIMER_ENABLE_PWM (TCCR2A |= _BV(COM2B1))
229 #define TIMER_DISABLE_PWM (TCCR2A &= ~(_BV(COM2B1)))
230 #define TIMER_ENABLE_INTR (TIMSK2 = _BV(OCIE2A))
231 #define TIMER_DISABLE_INTR (TIMSK2 = 0)
232 #define TIMER_INTR_NAME TIMER2_COMPA_vect
233 
234 #define TIMER_CONFIG_KHZ(val) ({ \
235  const uint8_t pwmval = SYSCLOCK / 2000 / (val); \
236  TCCR2A = _BV(WGM20); \
237  TCCR2B = _BV(WGM22) | _BV(CS20); \
238  OCR2A = pwmval; \
239  OCR2B = pwmval / 3; \
240 })
241 
242 #define TIMER_COUNT_TOP (SYSCLOCK * USECPERTICK / 1000000)
243 
244 //-----------------
245 #if (TIMER_COUNT_TOP < 256)
246 # define TIMER_CONFIG_NORMAL() ({ \
247  TCCR2A = _BV(WGM21); \
248  TCCR2B = _BV(CS20); \
249  OCR2A = TIMER_COUNT_TOP; \
250  TCNT2 = 0; \
251  })
252 #else
253 # define TIMER_CONFIG_NORMAL() ({ \
254  TCCR2A = _BV(WGM21); \
255  TCCR2B = _BV(CS21); \
256  OCR2A = TIMER_COUNT_TOP / 8; \
257  TCNT2 = 0; \
258  })
259 #endif
260 
261 //-----------------
262 #if defined(CORE_OC2B_PIN)
263 # define TIMER_PWM_PIN CORE_OC2B_PIN // Teensy
264 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
265 # define TIMER_PWM_PIN 9 // Arduino Mega
266 #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
267 # define TIMER_PWM_PIN 14 // Sanguino
268 #else
269 # define TIMER_PWM_PIN 3 // Arduino Duemilanove, Diecimila, LilyPad, etc
270 #endif
271 
272 //---------------------------------------------------------
273 // Timer1 (16 bits)
274 //
275 #elif defined(IR_USE_TIMER1)
276 
277 #define TIMER_RESET
278 #define TIMER_ENABLE_PWM (TCCR1A |= _BV(COM1A1))
279 #define TIMER_DISABLE_PWM (TCCR1A &= ~(_BV(COM1A1)))
280 
281 //-----------------
282 #if defined(__AVR_ATmega8P__) || defined(__AVR_ATmega8__)
283 # define TIMER_ENABLE_INTR (TIMSK |= _BV(OCIE1A))
284 # define TIMER_DISABLE_INTR (TIMSK &= ~_BV(OCIE1A))
285 #else
286 # define TIMER_ENABLE_INTR (TIMSK1 = _BV(OCIE1A))
287 # define TIMER_DISABLE_INTR (TIMSK1 = 0)
288 #endif
289 
290 //-----------------
291 #define TIMER_INTR_NAME TIMER1_COMPA_vect
292 
293 #define TIMER_CONFIG_KHZ(val) ({ \
294  const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
295  TCCR1A = _BV(WGM11); \
296  TCCR1B = _BV(WGM13) | _BV(CS10); \
297  ICR1 = pwmval; \
298  OCR1A = pwmval / 3; \
299 })
300 
301 #define TIMER_CONFIG_NORMAL() ({ \
302  TCCR1A = 0; \
303  TCCR1B = _BV(WGM12) | _BV(CS10); \
304  OCR1A = SYSCLOCK * USECPERTICK / 1000000; \
305  TCNT1 = 0; \
306 })
307 
308 //-----------------
309 #if defined(CORE_OC1A_PIN)
310 # define TIMER_PWM_PIN CORE_OC1A_PIN // Teensy
311 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
312 # define TIMER_PWM_PIN 11 // Arduino Mega
313 #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
314 # define TIMER_PWM_PIN 13 // Sanguino
315 #elif defined(__AVR_ATtiny84__)
316 # define TIMER_PWM_PIN 6
317 #else
318 # define TIMER_PWM_PIN 9 // Arduino Duemilanove, Diecimila, LilyPad, etc
319 #endif
320 
321 //---------------------------------------------------------
322 // Timer3 (16 bits)
323 //
324 #elif defined(IR_USE_TIMER3)
325 
326 #define TIMER_RESET
327 #define TIMER_ENABLE_PWM (TCCR3A |= _BV(COM3A1))
328 #define TIMER_DISABLE_PWM (TCCR3A &= ~(_BV(COM3A1)))
329 #define TIMER_ENABLE_INTR (TIMSK3 = _BV(OCIE3A))
330 #define TIMER_DISABLE_INTR (TIMSK3 = 0)
331 #define TIMER_INTR_NAME TIMER3_COMPA_vect
332 
333 #define TIMER_CONFIG_KHZ(val) ({ \
334  const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
335  TCCR3A = _BV(WGM31); \
336  TCCR3B = _BV(WGM33) | _BV(CS30); \
337  ICR3 = pwmval; \
338  OCR3A = pwmval / 3; \
339 })
340 
341 #define TIMER_CONFIG_NORMAL() ({ \
342  TCCR3A = 0; \
343  TCCR3B = _BV(WGM32) | _BV(CS30); \
344  OCR3A = SYSCLOCK * USECPERTICK / 1000000; \
345  TCNT3 = 0; \
346 })
347 
348 //-----------------
349 #if defined(CORE_OC3A_PIN)
350 # define TIMER_PWM_PIN CORE_OC3A_PIN // Teensy
351 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
352 # define TIMER_PWM_PIN 5 // Arduino Mega
353 #else
354 # error "Please add OC3A pin number here\n"
355 #endif
356 
357 //---------------------------------------------------------
358 // Timer4 (10 bits, high speed option)
359 //
360 #elif defined(IR_USE_TIMER4_HS)
361 
362 #define TIMER_RESET
363 #define TIMER_ENABLE_PWM (TCCR4A |= _BV(COM4A1))
364 #define TIMER_DISABLE_PWM (TCCR4A &= ~(_BV(COM4A1)))
365 #define TIMER_ENABLE_INTR (TIMSK4 = _BV(TOIE4))
366 #define TIMER_DISABLE_INTR (TIMSK4 = 0)
367 #define TIMER_INTR_NAME TIMER4_OVF_vect
368 
369 #define TIMER_CONFIG_KHZ(val) ({ \
370  const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
371  TCCR4A = (1<<PWM4A); \
372  TCCR4B = _BV(CS40); \
373  TCCR4C = 0; \
374  TCCR4D = (1<<WGM40); \
375  TCCR4E = 0; \
376  TC4H = pwmval >> 8; \
377  OCR4C = pwmval; \
378  TC4H = (pwmval / 3) >> 8; \
379  OCR4A = (pwmval / 3) & 255; \
380 })
381 
382 #define TIMER_CONFIG_NORMAL() ({ \
383  TCCR4A = 0; \
384  TCCR4B = _BV(CS40); \
385  TCCR4C = 0; \
386  TCCR4D = 0; \
387  TCCR4E = 0; \
388  TC4H = (SYSCLOCK * USECPERTICK / 1000000) >> 8; \
389  OCR4C = (SYSCLOCK * USECPERTICK / 1000000) & 255; \
390  TC4H = 0; \
391  TCNT4 = 0; \
392 })
393 
394 //-----------------
395 #if defined(CORE_OC4A_PIN)
396 # define TIMER_PWM_PIN CORE_OC4A_PIN // Teensy
397 #elif defined(__AVR_ATmega32U4__)
398 # define TIMER_PWM_PIN 13 // Leonardo
399 #else
400 # error "Please add OC4A pin number here\n"
401 #endif
402 
403 //---------------------------------------------------------
404 // Timer4 (16 bits)
405 //
406 #elif defined(IR_USE_TIMER4)
407 
408 #define TIMER_RESET
409 #define TIMER_ENABLE_PWM (TCCR4A |= _BV(COM4A1))
410 #define TIMER_DISABLE_PWM (TCCR4A &= ~(_BV(COM4A1)))
411 #define TIMER_ENABLE_INTR (TIMSK4 = _BV(OCIE4A))
412 #define TIMER_DISABLE_INTR (TIMSK4 = 0)
413 #define TIMER_INTR_NAME TIMER4_COMPA_vect
414 
415 #define TIMER_CONFIG_KHZ(val) ({ \
416  const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
417  TCCR4A = _BV(WGM41); \
418  TCCR4B = _BV(WGM43) | _BV(CS40); \
419  ICR4 = pwmval; \
420  OCR4A = pwmval / 3; \
421 })
422 
423 #define TIMER_CONFIG_NORMAL() ({ \
424  TCCR4A = 0; \
425  TCCR4B = _BV(WGM42) | _BV(CS40); \
426  OCR4A = SYSCLOCK * USECPERTICK / 1000000; \
427  TCNT4 = 0; \
428 })
429 
430 //-----------------
431 #if defined(CORE_OC4A_PIN)
432 # define TIMER_PWM_PIN CORE_OC4A_PIN
433 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
434 # define TIMER_PWM_PIN 6 // Arduino Mega
435 #else
436 # error "Please add OC4A pin number here\n"
437 #endif
438 
439 //---------------------------------------------------------
440 // Timer5 (16 bits)
441 //
442 #elif defined(IR_USE_TIMER5)
443 
444 #define TIMER_RESET
445 #define TIMER_ENABLE_PWM (TCCR5A |= _BV(COM5A1))
446 #define TIMER_DISABLE_PWM (TCCR5A &= ~(_BV(COM5A1)))
447 #define TIMER_ENABLE_INTR (TIMSK5 = _BV(OCIE5A))
448 #define TIMER_DISABLE_INTR (TIMSK5 = 0)
449 #define TIMER_INTR_NAME TIMER5_COMPA_vect
450 
451 #define TIMER_CONFIG_KHZ(val) ({ \
452  const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
453  TCCR5A = _BV(WGM51); \
454  TCCR5B = _BV(WGM53) | _BV(CS50); \
455  ICR5 = pwmval; \
456  OCR5A = pwmval / 3; \
457 })
458 
459 #define TIMER_CONFIG_NORMAL() ({ \
460  TCCR5A = 0; \
461  TCCR5B = _BV(WGM52) | _BV(CS50); \
462  OCR5A = SYSCLOCK * USECPERTICK / 1000000; \
463  TCNT5 = 0; \
464 })
465 
466 //-----------------
467 #if defined(CORE_OC5A_PIN)
468 # define TIMER_PWM_PIN CORE_OC5A_PIN
469 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
470 # define TIMER_PWM_PIN 46 // Arduino Mega
471 #else
472 # error "Please add OC5A pin number here\n"
473 #endif
474 
475 //---------------------------------------------------------
476 // Special carrier modulator timer
477 //
478 #elif defined(IR_USE_TIMER_CMT)
479 
480 #define TIMER_RESET ({ \
481  uint8_t tmp = CMT_MSC; \
482  CMT_CMD2 = 30; \
483 })
484 
485 #define TIMER_ENABLE_PWM do { \
486  CORE_PIN5_CONFIG = PORT_PCR_MUX(2) | PORT_PCR_DSE | PORT_PCR_SRE; \
487 } while(0)
488 
489 #define TIMER_DISABLE_PWM do { \
490  CORE_PIN5_CONFIG = PORT_PCR_MUX(1) | PORT_PCR_DSE | PORT_PCR_SRE; \
491 } while(0)
492 
493 #define TIMER_ENABLE_INTR NVIC_ENABLE_IRQ(IRQ_CMT)
494 #define TIMER_DISABLE_INTR NVIC_DISABLE_IRQ(IRQ_CMT)
495 #define TIMER_INTR_NAME cmt_isr
496 
497 //-----------------
498 #ifdef ISR
499 # undef ISR
500 #endif
501 #define ISR(f) void f(void)
502 
503 //-----------------
504 #if (F_BUS == 48000000)
505 # define CMT_PPS_VAL 5
506 #else
507 # define CMT_PPS_VAL 2
508 #endif
509 
510 //-----------------
511 #define TIMER_CONFIG_KHZ(val) ({ \
512  SIM_SCGC4 |= SIM_SCGC4_CMT; \
513  SIM_SOPT2 |= SIM_SOPT2_PTD7PAD; \
514  CMT_PPS = CMT_PPS_VAL; \
515  CMT_CGH1 = 2667 / val; \
516  CMT_CGL1 = 5333 / val; \
517  CMT_CMD1 = 0; \
518  CMT_CMD2 = 30; \
519  CMT_CMD3 = 0; \
520  CMT_CMD4 = 0; \
521  CMT_OC = 0x60; \
522  CMT_MSC = 0x01; \
523 })
524 
525 #define TIMER_CONFIG_NORMAL() ({ \
526  SIM_SCGC4 |= SIM_SCGC4_CMT; \
527  CMT_PPS = CMT_PPS_VAL; \
528  CMT_CGH1 = 1; \
529  CMT_CGL1 = 1; \
530  CMT_CMD1 = 0; \
531  CMT_CMD2 = 30 \
532  CMT_CMD3 = 0; \
533  CMT_CMD4 = 19; \
534  CMT_OC = 0; \
535  CMT_MSC = 0x03; \
536 })
537 
538 #define TIMER_PWM_PIN 5
539 
540 // defines for TPM1 timer on Teensy-LC
541 #elif defined(IR_USE_TIMER_TPM1)
542 #define TIMER_RESET FTM1_SC |= FTM_SC_TOF;
543 #define TIMER_ENABLE_PWM CORE_PIN16_CONFIG = PORT_PCR_MUX(3)|PORT_PCR_DSE|PORT_PCR_SRE
544 #define TIMER_DISABLE_PWM CORE_PIN16_CONFIG = PORT_PCR_MUX(1)|PORT_PCR_SRE
545 #define TIMER_ENABLE_INTR NVIC_ENABLE_IRQ(IRQ_FTM1)
546 #define TIMER_DISABLE_INTR NVIC_DISABLE_IRQ(IRQ_FTM1)
547 #define TIMER_INTR_NAME ftm1_isr
548 #ifdef ISR
549 #undef ISR
550 #endif
551 #define ISR(f) void f(void)
552 #define TIMER_CONFIG_KHZ(val) ({ \
553  SIM_SCGC6 |= SIM_SCGC6_TPM1; \
554  FTM1_SC = 0; \
555  FTM1_CNT = 0; \
556  FTM1_MOD = (F_PLL/2000) / val - 1; \
557  FTM1_C0V = (F_PLL/6000) / val - 1; \
558  FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_PS(0); \
559 })
560 #define TIMER_CONFIG_NORMAL() ({ \
561  SIM_SCGC6 |= SIM_SCGC6_TPM1; \
562  FTM1_SC = 0; \
563  FTM1_CNT = 0; \
564  FTM1_MOD = (F_PLL/40000) - 1; \
565  FTM1_C0V = 0; \
566  FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_PS(0) | FTM_SC_TOF | FTM_SC_TOIE; \
567 })
568 #define TIMER_PWM_PIN 16
569 
570 // defines for timer_tiny0 (8 bits)
571 #elif defined(IR_USE_TIMER_TINY0)
572 #define TIMER_RESET
573 #define TIMER_ENABLE_PWM (TCCR0A |= _BV(COM0B1))
574 #define TIMER_DISABLE_PWM (TCCR0A &= ~(_BV(COM0B1)))
575 #define TIMER_ENABLE_INTR (TIMSK |= _BV(OCIE0A))
576 #define TIMER_DISABLE_INTR (TIMSK &= ~(_BV(OCIE0A)))
577 #define TIMER_INTR_NAME TIMER0_COMPA_vect
578 #define TIMER_CONFIG_KHZ(val) ({ \
579  const uint8_t pwmval = SYSCLOCK / 2000 / (val); \
580  TCCR0A = _BV(WGM00); \
581  TCCR0B = _BV(WGM02) | _BV(CS00); \
582  OCR0A = pwmval; \
583  OCR0B = pwmval / 3; \
584 })
585 #define TIMER_COUNT_TOP (SYSCLOCK * USECPERTICK / 1000000)
586 #if (TIMER_COUNT_TOP < 256)
587 #define TIMER_CONFIG_NORMAL() ({ \
588  TCCR0A = _BV(WGM01); \
589  TCCR0B = _BV(CS00); \
590  OCR0A = TIMER_COUNT_TOP; \
591  TCNT0 = 0; \
592 })
593 #else
594 #define TIMER_CONFIG_NORMAL() ({ \
595  TCCR0A = _BV(WGM01); \
596  TCCR0B = _BV(CS01); \
597  OCR0A = TIMER_COUNT_TOP / 8; \
598  TCNT0 = 0; \
599 })
600 #endif
601 
602 #define TIMER_PWM_PIN 1 /* ATtiny85 */
603 
604 //---------------------------------------------------------
605 // Unknown Timer
606 //
607 #else
608 # error "Internal code configuration error, no known IR_USE_TIMER# defined\n"
609 #endif
610 #endif
uint8_t blinkpin
Definition: IRremoteInt.h:50
unsigned int timer
Definition: IRremoteInt.h:53
#define EXTERN
Definition: IRremoteInt.h:37
uint8_t recvpin
Definition: IRremoteInt.h:49
EXTERN volatile irparams_t irparams
Definition: IRremoteInt.h:69
uint8_t blinkflag
Definition: IRremoteInt.h:51
#define RAWBUF
Definition: IRremoteInt.h:43
uint8_t rcvstate
Definition: IRremoteInt.h:48
uint8_t overflow
Definition: IRremoteInt.h:55
uint8_t rawlen
Definition: IRremoteInt.h:52