Go to the documentation of this file.
23 #ifndef IRremoteBoardDefs_h
24 #define IRremoteBoardDefs_h
32 #define HAS_AVR_INTERRUPT_H
38 #define USE_DEFAULT_ENABLE_IR_IN
43 #define SENDING_SUPPORTED
49 #define USE_DEFAULT_ENABLE_IR_OUT
54 #if ! defined(DUTY_CYCLE)
55 #define DUTY_CYCLE 30 // 30 saves power and is compatible to the old existing code
62 #define PULSE_CORRECTION 3
74 #define BLINKLED LED_BUILTIN
79 #define BLINKLED_ON() digitalWrite(BLINKLED, HIGH)
84 #define BLINKLED_OFF() digitalWrite(BLINKLED, HIGH)
89 #define USE_NO_CARRIER
94 #define USE_SOFT_CARRIER
101 #elif ! defined(ARDUINO)
106 #undef HAS_AVR_INTERRUPT_H
108 #elif defined(CORE_LED0_PIN)
109 #define BLINKLED CORE_LED0_PIN
110 #define BLINKLED_ON() (digitalWrite(CORE_LED0_PIN, HIGH))
111 #define BLINKLED_OFF() (digitalWrite(CORE_LED0_PIN, LOW))
114 #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega32U4__)
115 #define BLINKLED LED_BUILTIN
116 #define BLINKLED_ON() (PORTB |= B00100000)
117 #define BLINKLED_OFF() (PORTB &= B11011111)
119 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
121 #define BLINKLED_ON() (PORTB |= B10000000)
122 #define BLINKLED_OFF() (PORTB &= B01111111)
124 #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
126 #define BLINKLED_ON() (PORTD |= B00000001)
127 #define BLINKLED_OFF() (PORTD &= B11111110)
130 #elif defined(__AVR_ATmega4809__)
131 #define BLINKLED LED_BUILTIN
132 #define BLINKLED_ON() (digitalWrite(BLINKLED, HIGH))
133 #define BLINKLED_OFF() (digitalWrite(BLINKLED, LOW))
135 #elif defined(ARDUINO_ARCH_SAMD)
136 #define BLINKLED LED_BUILTIN
137 #define BLINKLED_ON() (digitalWrite(LED_BUILTIN, HIGH))
138 #define BLINKLED_OFF() (digitalWrite(LED_BUILTIN, LOW))
140 #define USE_SOFT_CARRIER
143 #undef USE_DEFAULT_ENABLE_IR_IN
149 #undef HAS_AVR_INTERRUPT_H
152 #undef USE_DEFAULT_ENABLE_IR_IN
153 #undef USE_DEFAULT_ENABLE_IR_OUT
156 #warning No blinking definition found. Check IRremoteBoardDefs.h.
158 #define BLINKLED LED_BUILTIN
159 #define BLINKLED_ON() digitalWrite(BLINKLED, HIGH)
160 #define BLINKLED_OFF() digitalWrite(BLINKLED, LOW)
166 #define USECPERTICK 50
184 #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) // old default clause
185 # if !defined(IR_USE_TIMER1) && !defined(IR_USE_TIMER2)
187 #define IR_USE_TIMER2 // tx = pin 3
191 #elif defined(ARDUINO_AVR_PROMICRO)
192 # if !defined(IR_USE_TIMER1) && !defined(IR_USE_TIMER3) && !defined(IR_USE_TIMER4_HS)
194 #define IR_USE_TIMER3 // tx = pin 5
199 #elif defined(__AVR_ATmega32U4__) && ! defined(TEENSYDUINO)
200 # if !defined(IR_USE_TIMER1) && !defined(IR_USE_TIMER3) && !defined(IR_USE_TIMER4_HS)
202 #define IR_USE_TIMER3 // tx = pin 5
207 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
208 # if !defined(IR_USE_TIMER1) && !defined(IR_USE_TIMER2) && !defined(IR_USE_TIMER3) && !defined(IR_USE_TIMER4) && !defined(IR_USE_TIMER5)
210 #define IR_USE_TIMER2 // tx = pin 9
217 #elif defined(__AVR_ATmega4809__)
218 # if !defined(IR_USE_TIMER_4809_1) && !defined(IR_USE_TIMER_4809_2)
219 #define IR_USE_TIMER_4809_1 // tx = pin 24
224 #elif defined(__AVR_AT90USB162__)
225 # if !defined(IR_USE_TIMER1)
226 #define IR_USE_TIMER1 // tx = pin 17
230 #elif defined(__AVR_ATmega32U4__) && defined(TEENSYDUINO)
231 # if !defined(IR_USE_TIMER1) && !defined(IR_USE_TIMER3) && !defined(IR_USE_TIMER4_HS)
233 #define IR_USE_TIMER3 // tx = pin 9 (Teensy 2.0 - physical pin: C6)
238 #elif defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
239 # if !defined(IR_USE_TIMER_CMT)
240 #define IR_USE_TIMER_CMT // tx = pin 5
244 #elif defined(__MKL26Z64__)
245 # if !defined(IR_USE_TIMER_TPM1)
246 #define IR_USE_TIMER_TPM1 // tx = pin 16
250 #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
251 # if !defined(IR_USE_TIMER1) && !defined(IR_USE_TIMER2) && !defined(IR_USE_TIMER3)
253 #define IR_USE_TIMER2 // tx = pin 1
258 #elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)
259 # if !defined(IR_USE_TIMER1) && !defined(IR_USE_TIMER2) && !defined(IR_USE_TIMER3)
261 #define IR_USE_TIMER2 // tx = pin 14
266 #elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \
267 || defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \
268 || defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \
269 || defined(__AVR_ATmega164P__)
270 # if !defined(IR_USE_TIMER1) && !defined(IR_USE_TIMER2)
272 #define IR_USE_TIMER2 // tx = pin 14
276 #elif defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__)
277 # if !defined(IR_USE_TIMER1)
278 #define IR_USE_TIMER1 // tx = pin 13
282 #elif defined(__AVR_ATmega8535__) || defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__)
283 # if !defined(IR_USE_TIMER1)
284 #define IR_USE_TIMER1 // tx = pin 13
288 #elif defined(__AVR_ATmega8__)
289 # if !defined(IR_USE_TIMER1)
290 #define IR_USE_TIMER1 // tx = pin 9
294 #elif defined(__AVR_ATtiny84__)
295 # if !defined(IR_USE_TIMER1)
296 #define IR_USE_TIMER1 // tx = pin 6
300 #elif defined(__AVR_ATtiny85__)
301 # if !defined(IR_USE_TIMER_TINY0)
302 #define IR_USE_TIMER_TINY0 // tx = pin 1
306 # if !defined(IR_TIMER_USE_ESP32)
307 #define IR_TIMER_USE_ESP32
310 #elif defined(ARDUINO_ARCH_SAMD)
311 #define TIMER_PRESCALER_DIV 64
317 #error Board could not be identified from pre-processor symbols. Please extend IRremoteBoardDefs.h.
329 #define SENDPIN_ON(pin) digitalWrite(pin, HIGH)
336 #define SENDPIN_OFF(pin) digitalWrite(pin, LOW)
342 #if !defined(SYSCLOCK) && defined(ARDUINO) // allow for processor specific code to define SYSCLOCK
344 #error SYSCLOCK cannot be determined. Define it for your board in IRremoteBoardDefs.h.
349 #define SYSCLOCK F_CPU // main Arduino clock
369 #elif ! defined(ARDUINO)
376 #define ISR(f) void do_not_use__(void)
382 #elif defined(IR_USE_TIMER2)
385 #define TIMER_ENABLE_PWM (TCCR2A |= _BV(COM2B1))
386 #define TIMER_DISABLE_PWM (TCCR2A &= ~(_BV(COM2B1)))
387 #define TIMER_ENABLE_INTR (TIMSK2 = _BV(OCIE2A))
388 #define TIMER_DISABLE_INTR (TIMSK2 = 0)
389 #define TIMER_INTR_NAME TIMER2_COMPA_vect
391 #define TIMER_CONFIG_KHZ(val) ({ \
392 const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
393 TCCR2A = _BV(WGM20); \
394 TCCR2B = _BV(WGM22) | _BV(CS20); \
396 OCR2B = pwmval * DUTY_CYCLE / 100; \
399 #define TIMER_COUNT_TOP (SYSCLOCK * USECPERTICK / 1000000)
402 #if (TIMER_COUNT_TOP < 256)
403 #define TIMER_CONFIG_NORMAL() ({ \
404 TCCR2A = _BV(WGM21); \
405 TCCR2B = _BV(CS20); \
406 OCR2A = TIMER_COUNT_TOP; \
410 #define TIMER_CONFIG_NORMAL() ({ \
411 TCCR2A = _BV(WGM21); \
412 TCCR2B = _BV(CS21); \
413 OCR2A = TIMER_COUNT_TOP / 8; \
419 #if defined(CORE_OC2B_PIN)
420 #define IR_SEND_PIN CORE_OC2B_PIN // Teensy
422 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
423 #define IR_SEND_PIN 9 // Arduino Mega
425 #elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \
426 || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \
427 || defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \
428 || defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \
429 || defined(__AVR_ATmega164P__)
430 #define IR_SEND_PIN 14 // MightyCore, MegaCore
433 #define IR_SEND_PIN 3 // Arduino Duemilanove, Diecimila, LilyPad, etc
434 #endif // defined(CORE_OC2B_PIN)
439 #elif defined(IR_USE_TIMER1)
442 #define TIMER_ENABLE_PWM (TCCR1A |= _BV(COM1A1))
443 #define TIMER_DISABLE_PWM (TCCR1A &= ~(_BV(COM1A1)))
446 #if defined(__AVR_ATmega8__) || defined(__AVR_ATmega8535__) \
447 || defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__) \
448 || defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__)
449 #define TIMER_ENABLE_INTR (TIMSK |= _BV(OCIE1A))
450 #define TIMER_DISABLE_INTR (TIMSK &= ~_BV(OCIE1A))
452 #define TIMER_ENABLE_INTR (TIMSK1 = _BV(OCIE1A))
453 #define TIMER_DISABLE_INTR (TIMSK1 = 0)
457 #define TIMER_INTR_NAME TIMER1_COMPA_vect
459 #define TIMER_CONFIG_KHZ(val) ({ \
460 const uint32_t pwmval = SYSCLOCK / 2000 / (val); \
461 TCCR1A = _BV(WGM11); \
462 TCCR1B = _BV(WGM13) | _BV(CS10); \
464 OCR1A = pwmval * DUTY_CYCLE / 100; \
467 #define TIMER_CONFIG_NORMAL() ({ \
469 TCCR1B = _BV(WGM12) | _BV(CS10); \
470 OCR1A = SYSCLOCK * USECPERTICK / 1000000; \
475 #if defined(CORE_OC1A_PIN)
476 #define IR_SEND_PIN CORE_OC1A_PIN // Teensy
478 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
479 #define IR_SEND_PIN 11 // Arduino Mega
481 #elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \
482 || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \
483 || defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \
484 || defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \
485 || defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \
486 || defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) \
487 || defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__)
488 #define IR_SEND_PIN 13 // MightyCore, MegaCore
490 #elif defined(__AVR_ATtiny84__)
491 # define IR_SEND_PIN 6
494 #define IR_SEND_PIN 9 // Arduino Duemilanove, Diecimila, LilyPad, Sparkfun Pro Micro, Leonardo etc.
495 #endif // defined(CORE_OC1A_PIN)
500 #elif defined(IR_USE_TIMER3)
503 #define TIMER_ENABLE_PWM (TCCR3A |= _BV(COM3A1))
504 #define TIMER_DISABLE_PWM (TCCR3A &= ~(_BV(COM3A1)))
505 #define TIMER_ENABLE_INTR (TIMSK3 = _BV(OCIE3A))
506 #define TIMER_DISABLE_INTR (TIMSK3 = 0)
507 #define TIMER_INTR_NAME TIMER3_COMPA_vect
509 #define TIMER_CONFIG_KHZ(val) ({ \
510 const uint32_t pwmval = SYSCLOCK / 2000 / (val); \
511 TCCR3A = _BV(WGM31); \
512 TCCR3B = _BV(WGM33) | _BV(CS30); \
514 OCR3A = pwmval * DUTY_CYCLE / 100; \
517 #define TIMER_CONFIG_NORMAL() ({ \
519 TCCR3B = _BV(WGM32) | _BV(CS30); \
520 OCR3A = SYSCLOCK * USECPERTICK / 1000000; \
525 #if defined(CORE_OC3A_PIN)
526 #define IR_SEND_PIN CORE_OC3A_PIN // Teensy
528 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) \
529 || defined(__AVR_ATmega32U4__) || defined(ARDUINO_AVR_PROMICRO)
530 #define IR_SEND_PIN 5 // Arduino Mega, Arduino Leonardo, Sparkfun Pro Micro
532 #elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)
533 #define IR_SEND_PIN 6 // MightyCore, MegaCore
536 #error "Please add OC3A pin number here\n"
542 #elif defined(IR_USE_TIMER4_HS)
545 #if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro
546 #define TIMER_ENABLE_PWM (TCCR4A |= _BV(COM4A0)) // Use complimentary O̅C̅4̅A̅ output on pin 5
547 #define TIMER_DISABLE_PWM (TCCR4A &= ~(_BV(COM4A0))) // (Pro Micro does not map PC7 (32/ICP3/CLK0/OC4A)
550 #define TIMER_ENABLE_PWM (TCCR4A |= _BV(COM4A1))
551 #define TIMER_DISABLE_PWM (TCCR4A &= ~(_BV(COM4A1)))
553 #define TIMER_ENABLE_INTR (TIMSK4 = _BV(TOIE4))
554 #define TIMER_DISABLE_INTR (TIMSK4 = 0)
555 #define TIMER_INTR_NAME TIMER4_OVF_vect
557 #define TIMER_CONFIG_KHZ(val) ({ \
558 const uint32_t pwmval = SYSCLOCK / 2000 / (val); \
559 TCCR4A = (1<<PWM4A); \
560 TCCR4B = _BV(CS40); \
562 TCCR4D = (1<<WGM40); \
564 TC4H = pwmval >> 8; \
566 TC4H = (pwmval * DUTY_CYCLE / 100) >> 8; \
567 OCR4A = (pwmval * DUTY_CYCLE / 100) & 255; \
570 #define TIMER_CONFIG_NORMAL() ({ \
572 TCCR4B = _BV(CS40); \
576 TC4H = (SYSCLOCK * USECPERTICK / 1000000) >> 8; \
577 OCR4C = (SYSCLOCK * USECPERTICK / 1000000) & 255; \
583 #if defined(CORE_OC4A_PIN)
584 #define IR_SEND_PIN CORE_OC4A_PIN // Teensy
585 #elif defined(ARDUINO_AVR_PROMICRO)
586 # define IR_SEND_PIN 5 // Sparkfun Pro Micro
587 #elif defined(__AVR_ATmega32U4__)
588 #define IR_SEND_PIN 13 // Leonardo
590 #error "Please add OC4A pin number here\n"
596 #elif defined(IR_USE_TIMER4)
599 #define TIMER_ENABLE_PWM (TCCR4A |= _BV(COM4A1))
600 #define TIMER_DISABLE_PWM (TCCR4A &= ~(_BV(COM4A1)))
601 #define TIMER_ENABLE_INTR (TIMSK4 = _BV(OCIE4A))
602 #define TIMER_DISABLE_INTR (TIMSK4 = 0)
603 #define TIMER_INTR_NAME TIMER4_COMPA_vect
605 #define TIMER_CONFIG_KHZ(val) ({ \
606 const uint32_t pwmval = SYSCLOCK / 2000 / (val); \
607 TCCR4A = _BV(WGM41); \
608 TCCR4B = _BV(WGM43) | _BV(CS40); \
610 OCR4A = pwmval * DUTY_CYCLE / 100; \
613 #define TIMER_CONFIG_NORMAL() ({ \
615 TCCR4B = _BV(WGM42) | _BV(CS40); \
616 OCR4A = SYSCLOCK * USECPERTICK / 1000000; \
621 #if defined(CORE_OC4A_PIN)
622 #define IR_SEND_PIN CORE_OC4A_PIN
623 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
624 #define IR_SEND_PIN 6 // Arduino Mega
626 #error "Please add OC4A pin number here\n"
632 #elif defined(IR_USE_TIMER5)
635 #define TIMER_ENABLE_PWM (TCCR5A |= _BV(COM5A1))
636 #define TIMER_DISABLE_PWM (TCCR5A &= ~(_BV(COM5A1)))
637 #define TIMER_ENABLE_INTR (TIMSK5 = _BV(OCIE5A))
638 #define TIMER_DISABLE_INTR (TIMSK5 = 0)
639 #define TIMER_INTR_NAME TIMER5_COMPA_vect
641 #define TIMER_CONFIG_KHZ(val) ({ \
642 const uint32_t pwmval = SYSCLOCK / 2000 / (val); \
643 TCCR5A = _BV(WGM51); \
644 TCCR5B = _BV(WGM53) | _BV(CS50); \
646 OCR5A = pwmval * DUTY_CYCLE / 100; \
649 #define TIMER_CONFIG_NORMAL() ({ \
651 TCCR5B = _BV(WGM52) | _BV(CS50); \
652 OCR5A = SYSCLOCK * USECPERTICK / 1000000; \
657 #if defined(CORE_OC5A_PIN)
658 #define IR_SEND_PIN CORE_OC5A_PIN
659 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
660 #define IR_SEND_PIN 46 // Arduino Mega
662 #error "Please add OC5A pin number here\n"
668 #elif defined(IR_USE_TIMER_CMT)
670 #define TIMER_RESET ({ \
671 uint8_t tmp __attribute__((unused)) = CMT_MSC; \
675 #define TIMER_ENABLE_PWM do { \
676 CORE_PIN5_CONFIG = PORT_PCR_MUX(2) | PORT_PCR_DSE | PORT_PCR_SRE; \
679 #define TIMER_DISABLE_PWM do { \
680 CORE_PIN5_CONFIG = PORT_PCR_MUX(1) | PORT_PCR_DSE | PORT_PCR_SRE; \
683 #define TIMER_ENABLE_INTR NVIC_ENABLE_IRQ(IRQ_CMT)
684 #define TIMER_DISABLE_INTR NVIC_DISABLE_IRQ(IRQ_CMT)
685 #define TIMER_INTR_NAME cmt_isr
691 #define ISR(f) void f(void)
694 #define CMT_PPS_DIV ((F_BUS + 7999999) / 8000000)
696 #error IRremote requires at least 8 MHz on Teensy 3.x
700 #define TIMER_CONFIG_KHZ(val) ({ \
701 SIM_SCGC4 |= SIM_SCGC4_CMT; \
702 SIM_SOPT2 |= SIM_SOPT2_PTD7PAD; \
703 CMT_PPS = CMT_PPS_DIV - 1; \
704 CMT_CGH1 = ((F_BUS / CMT_PPS_DIV / 3000) + ((val)/2)) / (val); \
705 CMT_CGL1 = ((F_BUS / CMT_PPS_DIV / 1500) + ((val)/2)) / (val); \
714 #define TIMER_CONFIG_NORMAL() ({ \
715 SIM_SCGC4 |= SIM_SCGC4_CMT; \
716 CMT_PPS = CMT_PPS_DIV - 1; \
722 CMT_CMD4 = (F_BUS / 160000 + CMT_PPS_DIV / 2) / CMT_PPS_DIV - 31; \
727 #define IR_SEND_PIN 5
730 #elif defined(IR_USE_TIMER_TPM1)
731 #define TIMER_RESET FTM1_SC |= FTM_SC_TOF;
732 #define TIMER_ENABLE_PWM CORE_PIN16_CONFIG = PORT_PCR_MUX(3)|PORT_PCR_DSE|PORT_PCR_SRE
733 #define TIMER_DISABLE_PWM CORE_PIN16_CONFIG = PORT_PCR_MUX(1)|PORT_PCR_SRE
734 #define TIMER_ENABLE_INTR NVIC_ENABLE_IRQ(IRQ_FTM1)
735 #define TIMER_DISABLE_INTR NVIC_DISABLE_IRQ(IRQ_FTM1)
736 #define TIMER_INTR_NAME ftm1_isr
740 #define ISR(f) void f(void)
741 #define TIMER_CONFIG_KHZ(val) ({ \
742 SIM_SCGC6 |= SIM_SCGC6_TPM1; \
745 FTM1_MOD = (F_PLL/2000) / val - 1; \
746 FTM1_C0V = (F_PLL/6000) / val - 1; \
747 FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_PS(0); \
749 #define TIMER_CONFIG_NORMAL() ({ \
750 SIM_SCGC6 |= SIM_SCGC6_TPM1; \
753 FTM1_MOD = (F_PLL/40000) - 1; \
755 FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_PS(0) | FTM_SC_TOF | FTM_SC_TOIE; \
757 #define IR_SEND_PIN 16
760 #elif defined(IR_USE_TIMER_TINY0)
762 #define TIMER_ENABLE_PWM (TCCR0A |= _BV(COM0B1))
763 #define TIMER_DISABLE_PWM (TCCR0A &= ~(_BV(COM0B1)))
764 #define TIMER_ENABLE_INTR (TIMSK |= _BV(OCIE0A))
765 #define TIMER_DISABLE_INTR (TIMSK &= ~(_BV(OCIE0A)))
766 #define TIMER_INTR_NAME TIMER0_COMPA_vect
767 #define TIMER_CONFIG_KHZ(val) ({ \
768 const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
769 TCCR0A = _BV(WGM00); \
770 TCCR0B = _BV(WGM02) | _BV(CS00); \
772 OCR0B = pwmval * DUTY_CYCLE / 100; \
774 #define TIMER_COUNT_TOP (SYSCLOCK * USECPERTICK / 1000000)
775 #if (TIMER_COUNT_TOP < 256)
776 #define TIMER_CONFIG_NORMAL() ({ \
777 TCCR0A = _BV(WGM01); \
778 TCCR0B = _BV(CS00); \
779 OCR0A = TIMER_COUNT_TOP; \
783 #define TIMER_CONFIG_NORMAL() ({ \
784 TCCR0A = _BV(WGM01); \
785 TCCR0B = _BV(CS01); \
786 OCR0A = TIMER_COUNT_TOP / 8; \
791 #define IR_SEND_PIN 1
793 #elif defined(IR_USE_TIMER_4809_1)
795 #define TIMER_RESET TCB0.INTFLAGS = TCB_CAPT_bm
796 #define TIMER_ENABLE_PWM (TCB0.CTRLB = TCB_CNTMODE_PWM8_gc)
797 #define TIMER_DISABLE_PWM (TCB0.CTRLB &= ~(TCB_CNTMODE_PWM8_gc))
798 #define TIMER_ENABLE_INTR (TCB0.INTCTRL = TCB_CAPT_bm)
799 #define TIMER_DISABLE_INTR (TCB0.INTCTRL &= ~(TCB_CAPT_bm))
800 #define TIMER_INTR_NAME TCB0_INT_vect
801 #define TIMER_CONFIG_KHZ(val) ({ \
802 const uint32_t pwmval = SYSCLOCK / 2000 / (val); \
803 TCB0.CTRLB = TCB_CNTMODE_PWM8_gc; \
804 TCB0.CCMPL = pwmval; \
805 TCB0.CCMPH = pwmval * DUTY_CYCLE / 100; \
806 TCB0.CTRLA = (TCB_CLKSEL_CLKDIV1_gc) | (TCB_ENABLE_bm); \
808 #define TIMER_COUNT_TOP ((SYSCLOCK * USECPERTICK / 1000000))
809 #define TIMER_CONFIG_NORMAL() ({ \
810 TCB0.CTRLB = (TCB_CNTMODE_INT_gc); \
811 TCB0.CCMP = TIMER_COUNT_TOP; \
812 TCB0.INTCTRL = TCB_CAPT_bm; \
813 TCB0.CTRLA = (TCB_CLKSEL_CLKDIV1_gc) | (TCB_ENABLE_bm); \
816 #define IR_SEND_PIN 6
831 #elif defined(IR_TIMER_USE_ESP32)
833 #if ! defined(IR_SEND_PIN)
834 #define IR_SEND_PIN 4 // can use any pin, no timer restrictions
837 #if ! defined(LEDCHANNEL)
838 #define LEDCHANNEL 0 // The channel used for PWM 0 to 7 are high speed PWM channels
842 #define TIMER_ENABLE_PWM ledcWrite(LEDCHANNEL, DUTY_CYCLE) // we must use channel here not pin number
843 #define TIMER_DISABLE_PWM ledcWrite(LEDCHANNEL, 0)
848 #define ISR(f) void IRTimer()
850 #elif defined(ARDUINO_ARCH_SAMD)
853 #define IR_SEND_PIN 9
856 #define TIMER_ENABLE_PWM // Not presently used
857 #define TIMER_DISABLE_PWM
858 #define TIMER_ENABLE_INTR NVIC_EnableIRQ(TC3_IRQn) // Not presently used
859 #define TIMER_DISABLE_INTR NVIC_DisableIRQ(TC3_IRQn)
860 #define TIMER_INTR_NAME TC3_Handler // Not presently used
861 #define TIMER_CONFIG_KHZ(f)
866 #define ISR(f) void irs()
872 #error "Internal code configuration error, no known IR_USE_TIMER* defined\n"
875 #endif // ! IRremoteBoardDefs_h