[136] | 1 | /*
|
---|
| 2 | * IRremote
|
---|
| 3 | * Version 0.1 July, 2009
|
---|
| 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 | */
|
---|
| 15 |
|
---|
| 16 | #ifndef IRremoteint_h
|
---|
| 17 | #define IRremoteint_h
|
---|
| 18 |
|
---|
| 19 | #if defined(ARDUINO) && ARDUINO >= 100
|
---|
| 20 | #include <Arduino.h>
|
---|
| 21 | #else
|
---|
| 22 | #include <WProgram.h>
|
---|
| 23 | #endif
|
---|
| 24 |
|
---|
| 25 | // define which timer to use
|
---|
| 26 | //
|
---|
| 27 | // Uncomment the timer you wish to use on your board. If you
|
---|
| 28 | // are using another library which uses timer2, you have options
|
---|
| 29 | // to switch IRremote to use a different timer.
|
---|
| 30 |
|
---|
| 31 | // Arduino Mega
|
---|
| 32 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
---|
| 33 | //#define IR_USE_TIMER1 // tx = pin 11
|
---|
| 34 | #define IR_USE_TIMER2 // tx = pin 9
|
---|
| 35 | //#define IR_USE_TIMER3 // tx = pin 5
|
---|
| 36 | //#define IR_USE_TIMER4 // tx = pin 6
|
---|
| 37 | //#define IR_USE_TIMER5 // tx = pin 46
|
---|
| 38 |
|
---|
| 39 | // Teensy 1.0
|
---|
| 40 | #elif defined(__AVR_AT90USB162__)
|
---|
| 41 | #define IR_USE_TIMER1 // tx = pin 17
|
---|
| 42 |
|
---|
| 43 | // Teensy 2.0
|
---|
| 44 | #elif defined(__AVR_ATmega32U4__)
|
---|
| 45 | //#define IR_USE_TIMER1 // tx = pin 14
|
---|
| 46 | //#define IR_USE_TIMER3 // tx = pin 9
|
---|
| 47 | #define IR_USE_TIMER4_HS // tx = pin 10
|
---|
| 48 |
|
---|
| 49 | // Teensy++ 1.0 & 2.0
|
---|
| 50 | #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
|
---|
| 51 | //#define IR_USE_TIMER1 // tx = pin 25
|
---|
| 52 | #define IR_USE_TIMER2 // tx = pin 1
|
---|
| 53 | //#define IR_USE_TIMER3 // tx = pin 16
|
---|
| 54 |
|
---|
| 55 | // Sanguino
|
---|
| 56 | #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
|
---|
| 57 | //#define IR_USE_TIMER1 // tx = pin 13
|
---|
| 58 | #define IR_USE_TIMER2 // tx = pin 14
|
---|
| 59 |
|
---|
| 60 | // Atmega8
|
---|
| 61 | #elif defined(__AVR_ATmega8P__) || defined(__AVR_ATmega8__)
|
---|
| 62 | #define IR_USE_TIMER1 // tx = pin 9
|
---|
| 63 |
|
---|
| 64 | // Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, etc
|
---|
| 65 | #else
|
---|
| 66 | //#define IR_USE_TIMER1 // tx = pin 9
|
---|
| 67 | #define IR_USE_TIMER2 // tx = pin 3
|
---|
| 68 | #endif
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | #ifdef F_CPU
|
---|
| 73 | #define SYSCLOCK F_CPU // main Arduino clock
|
---|
| 74 | #else
|
---|
| 75 | #define SYSCLOCK 16000000 // main Arduino clock
|
---|
| 76 | #endif
|
---|
| 77 |
|
---|
| 78 | #define ERR 0
|
---|
| 79 | #define DECODED 1
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | // defines for setting and clearing register bits
|
---|
| 83 | #ifndef cbi
|
---|
| 84 | #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
|
---|
| 85 | #endif
|
---|
| 86 | #ifndef sbi
|
---|
| 87 | #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
|
---|
| 88 | #endif
|
---|
| 89 |
|
---|
| 90 | // Pulse parms are *50-100 for the Mark and *50+100 for the space
|
---|
| 91 | // First MARK is the one after the long gap
|
---|
| 92 | // pulse parameters in usec
|
---|
| 93 | #define NEC_HDR_MARK 9000
|
---|
| 94 | #define NEC_HDR_SPACE 4500
|
---|
| 95 | #define NEC_BIT_MARK 560
|
---|
| 96 | #define NEC_ONE_SPACE 1600
|
---|
| 97 | #define NEC_ZERO_SPACE 560
|
---|
| 98 | #define NEC_RPT_SPACE 2250
|
---|
| 99 |
|
---|
| 100 | #define SONY_HDR_MARK 2400
|
---|
| 101 | #define SONY_HDR_SPACE 600
|
---|
| 102 | #define SONY_ONE_MARK 1200
|
---|
| 103 | #define SONY_ZERO_MARK 600
|
---|
| 104 | #define SONY_RPT_LENGTH 45000
|
---|
| 105 | #define SONY_DOUBLE_SPACE_USECS 500 // usually ssee 713 - not using ticks as get number wrapround
|
---|
| 106 |
|
---|
| 107 | // SA 8650B
|
---|
| 108 | #define SANYO_HDR_MARK 3500 // seen range 3500
|
---|
| 109 | #define SANYO_HDR_SPACE 950 // seen 950
|
---|
| 110 | #define SANYO_ONE_MARK 2400 // seen 2400
|
---|
| 111 | #define SANYO_ZERO_MARK 700 // seen 700
|
---|
| 112 | #define SANYO_DOUBLE_SPACE_USECS 800 // usually ssee 713 - not using ticks as get number wrapround
|
---|
| 113 | #define SANYO_RPT_LENGTH 45000
|
---|
| 114 |
|
---|
| 115 | // Mitsubishi RM 75501
|
---|
| 116 | // 14200 7 41 7 42 7 42 7 17 7 17 7 18 7 41 7 18 7 17 7 17 7 18 7 41 8 17 7 17 7 18 7 17 7
|
---|
| 117 |
|
---|
| 118 | // #define MITSUBISHI_HDR_MARK 250 // seen range 3500
|
---|
| 119 | #define MITSUBISHI_HDR_SPACE 350 // 7*50+100
|
---|
| 120 | #define MITSUBISHI_ONE_MARK 1950 // 41*50-100
|
---|
| 121 | #define MITSUBISHI_ZERO_MARK 750 // 17*50-100
|
---|
| 122 | // #define MITSUBISHI_DOUBLE_SPACE_USECS 800 // usually ssee 713 - not using ticks as get number wrapround
|
---|
| 123 | // #define MITSUBISHI_RPT_LENGTH 45000
|
---|
| 124 |
|
---|
| 125 |
|
---|
| 126 | #define RC5_T1 889
|
---|
| 127 | #define RC5_RPT_LENGTH 46000
|
---|
| 128 |
|
---|
| 129 | #define RC6_HDR_MARK 2666
|
---|
| 130 | #define RC6_HDR_SPACE 889
|
---|
| 131 | #define RC6_T1 444
|
---|
| 132 | #define RC6_RPT_LENGTH 46000
|
---|
| 133 |
|
---|
| 134 | #define SHARP_BIT_MARK 245
|
---|
| 135 | #define SHARP_ONE_SPACE 1805
|
---|
| 136 | #define SHARP_ZERO_SPACE 795
|
---|
| 137 | #define SHARP_GAP 600000
|
---|
| 138 | #define SHARP_TOGGLE_MASK 0x3FF
|
---|
| 139 | #define SHARP_RPT_SPACE 3000
|
---|
| 140 |
|
---|
| 141 | #define DISH_HDR_MARK 400
|
---|
| 142 | #define DISH_HDR_SPACE 6100
|
---|
| 143 | #define DISH_BIT_MARK 400
|
---|
| 144 | #define DISH_ONE_SPACE 1700
|
---|
| 145 | #define DISH_ZERO_SPACE 2800
|
---|
| 146 | #define DISH_RPT_SPACE 6200
|
---|
| 147 | #define DISH_TOP_BIT 0x8000
|
---|
| 148 |
|
---|
| 149 | #define PANASONIC_HDR_MARK 3502
|
---|
| 150 | #define PANASONIC_HDR_SPACE 1750
|
---|
| 151 | #define PANASONIC_BIT_MARK 502
|
---|
| 152 | #define PANASONIC_ONE_SPACE 1244
|
---|
| 153 | #define PANASONIC_ZERO_SPACE 400
|
---|
| 154 |
|
---|
| 155 | #define JVC_HDR_MARK 8000
|
---|
| 156 | #define JVC_HDR_SPACE 4000
|
---|
| 157 | #define JVC_BIT_MARK 600
|
---|
| 158 | #define JVC_ONE_SPACE 1600
|
---|
| 159 | #define JVC_ZERO_SPACE 550
|
---|
| 160 | #define JVC_RPT_LENGTH 60000
|
---|
| 161 |
|
---|
| 162 | #define SHARP_BITS 15
|
---|
| 163 | #define DISH_BITS 16
|
---|
| 164 |
|
---|
| 165 | #define TOLERANCE 25 // percent tolerance in measurements
|
---|
| 166 | #define LTOL (1.0 - TOLERANCE/100.)
|
---|
| 167 | #define UTOL (1.0 + TOLERANCE/100.)
|
---|
| 168 |
|
---|
| 169 | #define _GAP 5000 // Minimum map between transmissions
|
---|
| 170 | #define GAP_TICKS (_GAP/USECPERTICK)
|
---|
| 171 |
|
---|
| 172 | #define TICKS_LOW(us) (int) (((us)*LTOL/USECPERTICK))
|
---|
| 173 | #define TICKS_HIGH(us) (int) (((us)*UTOL/USECPERTICK + 1))
|
---|
| 174 |
|
---|
| 175 | // receiver states
|
---|
| 176 | #define STATE_IDLE 2
|
---|
| 177 | #define STATE_MARK 3
|
---|
| 178 | #define STATE_SPACE 4
|
---|
| 179 | #define STATE_STOP 5
|
---|
| 180 |
|
---|
| 181 | // information for the interrupt handler
|
---|
| 182 | typedef struct {
|
---|
| 183 | uint8_t recvpin; // pin for IR data from detector
|
---|
| 184 | uint8_t rcvstate; // state machine
|
---|
| 185 | uint8_t blinkflag; // TRUE to enable blinking of pin 13 on IR processing
|
---|
| 186 | unsigned int timer; // state timer, counts 50uS ticks.
|
---|
| 187 | unsigned int rawbuf[RAWBUF]; // raw data
|
---|
| 188 | uint8_t rawlen; // counter of entries in rawbuf
|
---|
| 189 | }
|
---|
| 190 | irparams_t;
|
---|
| 191 |
|
---|
| 192 | // Defined in IRremote.cpp
|
---|
| 193 | extern volatile irparams_t irparams;
|
---|
| 194 |
|
---|
| 195 | // IR detector output is active low
|
---|
| 196 | #define MARK 0
|
---|
| 197 | #define SPACE 1
|
---|
| 198 |
|
---|
| 199 | #define TOPBIT 0x80000000
|
---|
| 200 |
|
---|
| 201 | #define NEC_BITS 32
|
---|
| 202 | #define SONY_BITS 12
|
---|
| 203 | #define SANYO_BITS 12
|
---|
| 204 | #define MITSUBISHI_BITS 16
|
---|
| 205 | #define MIN_RC5_SAMPLES 11
|
---|
| 206 | #define MIN_RC6_SAMPLES 1
|
---|
| 207 | #define PANASONIC_BITS 48
|
---|
| 208 | #define JVC_BITS 16
|
---|
| 209 |
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 |
|
---|
| 213 | // defines for timer2 (8 bits)
|
---|
| 214 | #if defined(IR_USE_TIMER2)
|
---|
| 215 | #define TIMER_RESET
|
---|
| 216 | #define TIMER_ENABLE_PWM (TCCR2A |= _BV(COM2B1))
|
---|
| 217 | #define TIMER_DISABLE_PWM (TCCR2A &= ~(_BV(COM2B1)))
|
---|
| 218 | #define TIMER_ENABLE_INTR (TIMSK2 = _BV(OCIE2A))
|
---|
| 219 | #define TIMER_DISABLE_INTR (TIMSK2 = 0)
|
---|
| 220 | #define TIMER_INTR_NAME TIMER2_COMPA_vect
|
---|
| 221 | #define TIMER_CONFIG_KHZ(val) ({ \
|
---|
| 222 | const uint8_t pwmval = SYSCLOCK / 2000 / (val); \
|
---|
| 223 | TCCR2A = _BV(WGM20); \
|
---|
| 224 | TCCR2B = _BV(WGM22) | _BV(CS20); \
|
---|
| 225 | OCR2A = pwmval; \
|
---|
| 226 | OCR2B = pwmval / 3; \
|
---|
| 227 | })
|
---|
| 228 | #define TIMER_COUNT_TOP (SYSCLOCK * USECPERTICK / 1000000)
|
---|
| 229 | #if (TIMER_COUNT_TOP < 256)
|
---|
| 230 | #define TIMER_CONFIG_NORMAL() ({ \
|
---|
| 231 | TCCR2A = _BV(WGM21); \
|
---|
| 232 | TCCR2B = _BV(CS20); \
|
---|
| 233 | OCR2A = TIMER_COUNT_TOP; \
|
---|
| 234 | TCNT2 = 0; \
|
---|
| 235 | })
|
---|
| 236 | #else
|
---|
| 237 | #define TIMER_CONFIG_NORMAL() ({ \
|
---|
| 238 | TCCR2A = _BV(WGM21); \
|
---|
| 239 | TCCR2B = _BV(CS21); \
|
---|
| 240 | OCR2A = TIMER_COUNT_TOP / 8; \
|
---|
| 241 | TCNT2 = 0; \
|
---|
| 242 | })
|
---|
| 243 | #endif
|
---|
| 244 | #if defined(CORE_OC2B_PIN)
|
---|
| 245 | #define TIMER_PWM_PIN CORE_OC2B_PIN /* Teensy */
|
---|
| 246 | #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
---|
| 247 | #define TIMER_PWM_PIN 9 /* Arduino Mega */
|
---|
| 248 | #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
|
---|
| 249 | #define TIMER_PWM_PIN 14 /* Sanguino */
|
---|
| 250 | #else
|
---|
| 251 | #define TIMER_PWM_PIN 3 /* Arduino Duemilanove, Diecimila, LilyPad, etc */
|
---|
| 252 | #endif
|
---|
| 253 |
|
---|
| 254 |
|
---|
| 255 | // defines for timer1 (16 bits)
|
---|
| 256 | #elif defined(IR_USE_TIMER1)
|
---|
| 257 | #define TIMER_RESET
|
---|
| 258 | #define TIMER_ENABLE_PWM (TCCR1A |= _BV(COM1A1))
|
---|
| 259 | #define TIMER_DISABLE_PWM (TCCR1A &= ~(_BV(COM1A1)))
|
---|
| 260 | #if defined(__AVR_ATmega8P__) || defined(__AVR_ATmega8__)
|
---|
| 261 | #define TIMER_ENABLE_INTR (TIMSK = _BV(OCIE1A))
|
---|
| 262 | #define TIMER_DISABLE_INTR (TIMSK = 0)
|
---|
| 263 | #else
|
---|
| 264 | #define TIMER_ENABLE_INTR (TIMSK1 = _BV(OCIE1A))
|
---|
| 265 | #define TIMER_DISABLE_INTR (TIMSK1 = 0)
|
---|
| 266 | #endif
|
---|
| 267 | #define TIMER_INTR_NAME TIMER1_COMPA_vect
|
---|
| 268 | #define TIMER_CONFIG_KHZ(val) ({ \
|
---|
| 269 | const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
|
---|
| 270 | TCCR1A = _BV(WGM11); \
|
---|
| 271 | TCCR1B = _BV(WGM13) | _BV(CS10); \
|
---|
| 272 | ICR1 = pwmval; \
|
---|
| 273 | OCR1A = pwmval / 3; \
|
---|
| 274 | })
|
---|
| 275 | #define TIMER_CONFIG_NORMAL() ({ \
|
---|
| 276 | TCCR1A = 0; \
|
---|
| 277 | TCCR1B = _BV(WGM12) | _BV(CS10); \
|
---|
| 278 | OCR1A = SYSCLOCK * USECPERTICK / 1000000; \
|
---|
| 279 | TCNT1 = 0; \
|
---|
| 280 | })
|
---|
| 281 | #if defined(CORE_OC1A_PIN)
|
---|
| 282 | #define TIMER_PWM_PIN CORE_OC1A_PIN /* Teensy */
|
---|
| 283 | #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
---|
| 284 | #define TIMER_PWM_PIN 11 /* Arduino Mega */
|
---|
| 285 | #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
|
---|
| 286 | #define TIMER_PWM_PIN 13 /* Sanguino */
|
---|
| 287 | #else
|
---|
| 288 | #define TIMER_PWM_PIN 9 /* Arduino Duemilanove, Diecimila, LilyPad, etc */
|
---|
| 289 | #endif
|
---|
| 290 |
|
---|
| 291 |
|
---|
| 292 | // defines for timer3 (16 bits)
|
---|
| 293 | #elif defined(IR_USE_TIMER3)
|
---|
| 294 | #define TIMER_RESET
|
---|
| 295 | #define TIMER_ENABLE_PWM (TCCR3A |= _BV(COM3A1))
|
---|
| 296 | #define TIMER_DISABLE_PWM (TCCR3A &= ~(_BV(COM3A1)))
|
---|
| 297 | #define TIMER_ENABLE_INTR (TIMSK3 = _BV(OCIE3A))
|
---|
| 298 | #define TIMER_DISABLE_INTR (TIMSK3 = 0)
|
---|
| 299 | #define TIMER_INTR_NAME TIMER3_COMPA_vect
|
---|
| 300 | #define TIMER_CONFIG_KHZ(val) ({ \
|
---|
| 301 | const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
|
---|
| 302 | TCCR3A = _BV(WGM31); \
|
---|
| 303 | TCCR3B = _BV(WGM33) | _BV(CS30); \
|
---|
| 304 | ICR3 = pwmval; \
|
---|
| 305 | OCR3A = pwmval / 3; \
|
---|
| 306 | })
|
---|
| 307 | #define TIMER_CONFIG_NORMAL() ({ \
|
---|
| 308 | TCCR3A = 0; \
|
---|
| 309 | TCCR3B = _BV(WGM32) | _BV(CS30); \
|
---|
| 310 | OCR3A = SYSCLOCK * USECPERTICK / 1000000; \
|
---|
| 311 | TCNT3 = 0; \
|
---|
| 312 | })
|
---|
| 313 | #if defined(CORE_OC3A_PIN)
|
---|
| 314 | #define TIMER_PWM_PIN CORE_OC3A_PIN /* Teensy */
|
---|
| 315 | #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
---|
| 316 | #define TIMER_PWM_PIN 5 /* Arduino Mega */
|
---|
| 317 | #else
|
---|
| 318 | #error "Please add OC3A pin number here\n"
|
---|
| 319 | #endif
|
---|
| 320 |
|
---|
| 321 |
|
---|
| 322 | // defines for timer4 (10 bits, high speed option)
|
---|
| 323 | #elif defined(IR_USE_TIMER4_HS)
|
---|
| 324 | #define TIMER_RESET
|
---|
| 325 | #define TIMER_ENABLE_PWM (TCCR4A |= _BV(COM4A1))
|
---|
| 326 | #define TIMER_DISABLE_PWM (TCCR4A &= ~(_BV(COM4A1)))
|
---|
| 327 | #define TIMER_ENABLE_INTR (TIMSK4 = _BV(TOIE4))
|
---|
| 328 | #define TIMER_DISABLE_INTR (TIMSK4 = 0)
|
---|
| 329 | #define TIMER_INTR_NAME TIMER4_OVF_vect
|
---|
| 330 | #define TIMER_CONFIG_KHZ(val) ({ \
|
---|
| 331 | const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
|
---|
| 332 | TCCR4A = (1<<PWM4A); \
|
---|
| 333 | TCCR4B = _BV(CS40); \
|
---|
| 334 | TCCR4C = 0; \
|
---|
| 335 | TCCR4D = (1<<WGM40); \
|
---|
| 336 | TCCR4E = 0; \
|
---|
| 337 | TC4H = pwmval >> 8; \
|
---|
| 338 | OCR4C = pwmval; \
|
---|
| 339 | TC4H = (pwmval / 3) >> 8; \
|
---|
| 340 | OCR4A = (pwmval / 3) & 255; \
|
---|
| 341 | })
|
---|
| 342 | #define TIMER_CONFIG_NORMAL() ({ \
|
---|
| 343 | TCCR4A = 0; \
|
---|
| 344 | TCCR4B = _BV(CS40); \
|
---|
| 345 | TCCR4C = 0; \
|
---|
| 346 | TCCR4D = 0; \
|
---|
| 347 | TCCR4E = 0; \
|
---|
| 348 | TC4H = (SYSCLOCK * USECPERTICK / 1000000) >> 8; \
|
---|
| 349 | OCR4C = (SYSCLOCK * USECPERTICK / 1000000) & 255; \
|
---|
| 350 | TC4H = 0; \
|
---|
| 351 | TCNT4 = 0; \
|
---|
| 352 | })
|
---|
| 353 | #if defined(CORE_OC4A_PIN)
|
---|
| 354 | #define TIMER_PWM_PIN CORE_OC4A_PIN /* Teensy */
|
---|
| 355 | #elif defined(__AVR_ATmega32U4__)
|
---|
| 356 | #define TIMER_PWM_PIN 13 /* Leonardo */
|
---|
| 357 | #else
|
---|
| 358 | #error "Please add OC4A pin number here\n"
|
---|
| 359 | #endif
|
---|
| 360 |
|
---|
| 361 |
|
---|
| 362 | // defines for timer4 (16 bits)
|
---|
| 363 | #elif defined(IR_USE_TIMER4)
|
---|
| 364 | #define TIMER_RESET
|
---|
| 365 | #define TIMER_ENABLE_PWM (TCCR4A |= _BV(COM4A1))
|
---|
| 366 | #define TIMER_DISABLE_PWM (TCCR4A &= ~(_BV(COM4A1)))
|
---|
| 367 | #define TIMER_ENABLE_INTR (TIMSK4 = _BV(OCIE4A))
|
---|
| 368 | #define TIMER_DISABLE_INTR (TIMSK4 = 0)
|
---|
| 369 | #define TIMER_INTR_NAME TIMER4_COMPA_vect
|
---|
| 370 | #define TIMER_CONFIG_KHZ(val) ({ \
|
---|
| 371 | const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
|
---|
| 372 | TCCR4A = _BV(WGM41); \
|
---|
| 373 | TCCR4B = _BV(WGM43) | _BV(CS40); \
|
---|
| 374 | ICR4 = pwmval; \
|
---|
| 375 | OCR4A = pwmval / 3; \
|
---|
| 376 | })
|
---|
| 377 | #define TIMER_CONFIG_NORMAL() ({ \
|
---|
| 378 | TCCR4A = 0; \
|
---|
| 379 | TCCR4B = _BV(WGM42) | _BV(CS40); \
|
---|
| 380 | OCR4A = SYSCLOCK * USECPERTICK / 1000000; \
|
---|
| 381 | TCNT4 = 0; \
|
---|
| 382 | })
|
---|
| 383 | #if defined(CORE_OC4A_PIN)
|
---|
| 384 | #define TIMER_PWM_PIN CORE_OC4A_PIN
|
---|
| 385 | #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
---|
| 386 | #define TIMER_PWM_PIN 6 /* Arduino Mega */
|
---|
| 387 | #else
|
---|
| 388 | #error "Please add OC4A pin number here\n"
|
---|
| 389 | #endif
|
---|
| 390 |
|
---|
| 391 |
|
---|
| 392 | // defines for timer5 (16 bits)
|
---|
| 393 | #elif defined(IR_USE_TIMER5)
|
---|
| 394 | #define TIMER_RESET
|
---|
| 395 | #define TIMER_ENABLE_PWM (TCCR5A |= _BV(COM5A1))
|
---|
| 396 | #define TIMER_DISABLE_PWM (TCCR5A &= ~(_BV(COM5A1)))
|
---|
| 397 | #define TIMER_ENABLE_INTR (TIMSK5 = _BV(OCIE5A))
|
---|
| 398 | #define TIMER_DISABLE_INTR (TIMSK5 = 0)
|
---|
| 399 | #define TIMER_INTR_NAME TIMER5_COMPA_vect
|
---|
| 400 | #define TIMER_CONFIG_KHZ(val) ({ \
|
---|
| 401 | const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
|
---|
| 402 | TCCR5A = _BV(WGM51); \
|
---|
| 403 | TCCR5B = _BV(WGM53) | _BV(CS50); \
|
---|
| 404 | ICR5 = pwmval; \
|
---|
| 405 | OCR5A = pwmval / 3; \
|
---|
| 406 | })
|
---|
| 407 | #define TIMER_CONFIG_NORMAL() ({ \
|
---|
| 408 | TCCR5A = 0; \
|
---|
| 409 | TCCR5B = _BV(WGM52) | _BV(CS50); \
|
---|
| 410 | OCR5A = SYSCLOCK * USECPERTICK / 1000000; \
|
---|
| 411 | TCNT5 = 0; \
|
---|
| 412 | })
|
---|
| 413 | #if defined(CORE_OC5A_PIN)
|
---|
| 414 | #define TIMER_PWM_PIN CORE_OC5A_PIN
|
---|
| 415 | #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
---|
| 416 | #define TIMER_PWM_PIN 46 /* Arduino Mega */
|
---|
| 417 | #else
|
---|
| 418 | #error "Please add OC5A pin number here\n"
|
---|
| 419 | #endif
|
---|
| 420 |
|
---|
| 421 |
|
---|
| 422 | #else // unknown timer
|
---|
| 423 | #error "Internal code configuration error, no known IR_USE_TIMER# defined\n"
|
---|
| 424 | #endif
|
---|
| 425 |
|
---|
| 426 |
|
---|
| 427 | // defines for blinking the LED
|
---|
| 428 | #if defined(CORE_LED0_PIN)
|
---|
| 429 | #define BLINKLED CORE_LED0_PIN
|
---|
| 430 | #define BLINKLED_ON() (digitalWrite(CORE_LED0_PIN, HIGH))
|
---|
| 431 | #define BLINKLED_OFF() (digitalWrite(CORE_LED0_PIN, LOW))
|
---|
| 432 | #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
---|
| 433 | #define BLINKLED 13
|
---|
| 434 | #define BLINKLED_ON() (PORTB |= B10000000)
|
---|
| 435 | #define BLINKLED_OFF() (PORTB &= B01111111)
|
---|
| 436 | #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
|
---|
| 437 | #define BLINKLED 0
|
---|
| 438 | #define BLINKLED_ON() (PORTD |= B00000001)
|
---|
| 439 | #define BLINKLED_OFF() (PORTD &= B11111110)
|
---|
| 440 | #else
|
---|
| 441 | #define BLINKLED 13
|
---|
| 442 | #define BLINKLED_ON() (PORTB |= B00100000)
|
---|
| 443 | #define BLINKLED_OFF() (PORTB &= B11011111)
|
---|
| 444 | #endif
|
---|
| 445 |
|
---|
| 446 | #endif
|
---|