Skip to content

Commit 9ba6628

Browse files
Add support for Teensy 3.0
1 parent 3f70ad2 commit 9ba6628

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
@@ -225,15 +225,15 @@ void IRsend::mark(int time) {
225225
// Sends an IR mark for the specified number of microseconds.
226226
// The mark output is modulated at the PWM frequency.
227227
TIMER_ENABLE_PWM; // Enable pin 3 PWM output
228-
delayMicroseconds(time);
228+
if (time > 0) delayMicroseconds(time);
229229
}
230230

231231
/* Leave pin off for time (given in microseconds) */
232232
void IRsend::space(int time) {
233233
// Sends an IR space for the specified number of microseconds.
234234
// A space is no output, so the PWM output is disabled.
235235
TIMER_DISABLE_PWM; // Disable pin 3 PWM output
236-
delayMicroseconds(time);
236+
if (time > 0) delayMicroseconds(time);
237237
}
238238

239239
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
@@ -426,6 +430,54 @@ extern volatile irparams_t irparams;
426430
#endif
427431

428432

433+
// defines for special carrier modulator timer
434+
#elif defined(IR_USE_TIMER_CMT)
435+
#define TIMER_RESET ({ \
436+
uint8_t tmp = CMT_MSC; \
437+
CMT_CMD2 = 30; \
438+
})
439+
#define TIMER_ENABLE_PWM CORE_PIN5_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_DSE|PORT_PCR_SRE
440+
#define TIMER_DISABLE_PWM CORE_PIN5_CONFIG = PORT_PCR_MUX(1)|PORT_PCR_DSE|PORT_PCR_SRE
441+
#define TIMER_ENABLE_INTR NVIC_ENABLE_IRQ(IRQ_CMT)
442+
#define TIMER_DISABLE_INTR NVIC_DISABLE_IRQ(IRQ_CMT)
443+
#define TIMER_INTR_NAME cmt_isr
444+
#ifdef ISR
445+
#undef ISR
446+
#endif
447+
#define ISR(f) void f(void)
448+
#if F_BUS == 48000000
449+
#define CMT_PPS_VAL 5
450+
#else
451+
#define CMT_PPS_VAL 2
452+
#endif
453+
#define TIMER_CONFIG_KHZ(val) ({ \
454+
SIM_SCGC4 |= SIM_SCGC4_CMT; \
455+
SIM_SOPT2 |= SIM_SOPT2_PTD7PAD; \
456+
CMT_PPS = CMT_PPS_VAL; \
457+
CMT_CGH1 = 2667 / val; \
458+
CMT_CGL1 = 5333 / val; \
459+
CMT_CMD1 = 0; \
460+
CMT_CMD2 = 30; \
461+
CMT_CMD3 = 0; \
462+
CMT_CMD4 = 0; \
463+
CMT_OC = 0x60; \
464+
CMT_MSC = 0x01; \
465+
})
466+
#define TIMER_CONFIG_NORMAL() ({ \
467+
SIM_SCGC4 |= SIM_SCGC4_CMT; \
468+
CMT_PPS = CMT_PPS_VAL; \
469+
CMT_CGH1 = 1; \
470+
CMT_CGL1 = 1; \
471+
CMT_CMD1 = 0; \
472+
CMT_CMD2 = 30; \
473+
CMT_CMD3 = 0; \
474+
CMT_CMD4 = 19; \
475+
CMT_OC = 0; \
476+
CMT_MSC = 0x03; \
477+
})
478+
#define TIMER_PWM_PIN 5
479+
480+
429481
#else // unknown timer
430482
#error "Internal code configuration error, no known IR_USE_TIMER# defined\n"
431483
#endif

0 commit comments

Comments
 (0)