Skip to content

Commit c8aa554

Browse files
committed
Merge branch 'master' of git://github.com/PaulStoffregen/Arduino-IRremote
2 parents 8fe8187 + 9ba6628 commit c8aa554

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

IRremote.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,15 @@ void IRsend::mark(int16_t time) {
321321
// Sends an IR mark for the specified number of microseconds.
322322
// The mark output is modulated at the PWM frequency.
323323
TIMER_ENABLE_PWM; // Enable pin 3 PWM output
324-
delayMicroseconds(time);
324+
if (time > 0) delayMicroseconds(time);
325325
}
326326

327327
/* Leave pin off for time (given in microseconds) */
328328
void IRsend::space(int16_t time) {
329329
// Sends an IR space for the specified number of microseconds.
330330
// A space is no output, so the PWM output is disabled.
331331
TIMER_DISABLE_PWM; // Disable pin 3 PWM output
332-
delayMicroseconds(time);
332+
if (time > 0) delayMicroseconds(time);
333333
}
334334

335335
void IRsend::enableIROut(int16_t khz) {
@@ -1316,4 +1316,4 @@ uint8_t UseriesChecksum(uint32_t val)
13161316
}
13171317
p = (p ^ (p >> 1) ^ (p >> 2) ^ (p >> 4)) & 7;
13181318
return(map[p]);
1319-
}
1319+
}

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
@@ -459,6 +463,54 @@ extern volatile irparams_t irparams;
459463
#endif
460464

461465

466+
// defines for special carrier modulator timer
467+
#elif defined(IR_USE_TIMER_CMT)
468+
#define TIMER_RESET ({ \
469+
uint8_t tmp = CMT_MSC; \
470+
CMT_CMD2 = 30; \
471+
})
472+
#define TIMER_ENABLE_PWM CORE_PIN5_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_DSE|PORT_PCR_SRE
473+
#define TIMER_DISABLE_PWM CORE_PIN5_CONFIG = PORT_PCR_MUX(1)|PORT_PCR_DSE|PORT_PCR_SRE
474+
#define TIMER_ENABLE_INTR NVIC_ENABLE_IRQ(IRQ_CMT)
475+
#define TIMER_DISABLE_INTR NVIC_DISABLE_IRQ(IRQ_CMT)
476+
#define TIMER_INTR_NAME cmt_isr
477+
#ifdef ISR
478+
#undef ISR
479+
#endif
480+
#define ISR(f) void f(void)
481+
#if F_BUS == 48000000
482+
#define CMT_PPS_VAL 5
483+
#else
484+
#define CMT_PPS_VAL 2
485+
#endif
486+
#define TIMER_CONFIG_KHZ(val) ({ \
487+
SIM_SCGC4 |= SIM_SCGC4_CMT; \
488+
SIM_SOPT2 |= SIM_SOPT2_PTD7PAD; \
489+
CMT_PPS = CMT_PPS_VAL; \
490+
CMT_CGH1 = 2667 / val; \
491+
CMT_CGL1 = 5333 / val; \
492+
CMT_CMD1 = 0; \
493+
CMT_CMD2 = 30; \
494+
CMT_CMD3 = 0; \
495+
CMT_CMD4 = 0; \
496+
CMT_OC = 0x60; \
497+
CMT_MSC = 0x01; \
498+
})
499+
#define TIMER_CONFIG_NORMAL() ({ \
500+
SIM_SCGC4 |= SIM_SCGC4_CMT; \
501+
CMT_PPS = CMT_PPS_VAL; \
502+
CMT_CGH1 = 1; \
503+
CMT_CGL1 = 1; \
504+
CMT_CMD1 = 0; \
505+
CMT_CMD2 = 30; \
506+
CMT_CMD3 = 0; \
507+
CMT_CMD4 = 19; \
508+
CMT_OC = 0; \
509+
CMT_MSC = 0x03; \
510+
})
511+
#define TIMER_PWM_PIN 5
512+
513+
462514
#else // unknown timer
463515
#error "Internal code configuration error, no known IR_USE_TIMER# defined\n"
464516
#endif

0 commit comments

Comments
 (0)