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