10000 Merge pull request #22 from PaulStoffregen/master · githubgrax/Arduino-IRremote@a881523 · GitHub
[go: up one dir, main page]

Skip to content

Commit a881523

Browse files
committed
Merge pull request Arduino-IRremote#22 from PaulStoffregen/master
Teensy 3.0 compatibility
2 parents f2dafe5 + 9ba6628 commit a881523

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

IRremote.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,15 @@ void IRsend::mark(int time) {
252252
// Sends an IR mark for the specified number of microseconds.
253253
// The mark output is modulated at the PWM frequency.
254254
TIMER_ENABLE_PWM; // Enable pin 3 PWM output
255-
delayMicroseconds(time);
255+
if (time > 0) delayMicroseconds(time);
256256
}
257257

258258
/* Leave pin off for time (given in microseconds) */
259259
void IRsend::space(int time) {
260260
// Sends an IR space for the specified number of microseconds.
261261
// A space is no output, so the PWM output is disabled.
262262
TIMER_DISABLE_PWM; // Disable pin 3 PWM output
263-
delayMicroseconds(time);
263+
if (time > 0) delayMicroseconds(time);
264264
}
265265

266266
void IRsend::enableIROut(int khz) {

IRremoteInt.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
//#define IR_USE_TIMER3 // tx = pin 9
4747
#define IR_USE_TIMER4_HS // tx = pin 10
4848

49+
// Teensy 3.0
50+
#elif defined(__MK20DX128__)
51+
#define IR_USE_TIMER_CMT // tx = pin 5
52+
4953
// Teensy++ 1.0 & 2.0
5054
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
5155
//#define IR_USE_TIMER1 // tx = pin 25
@@ -436,6 +440,54 @@ extern volatile irparams_t irparams;
436440
#endif
437441

438442

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+
439491
#else // unknown timer
440492
#error "Internal code configuration error, no known IR_USE_TIMER# defined\n"
441493
#endif

0 commit comments

Comments
 (0)
0