Skip to content

Commit 708d38c

Browse files
committed
Modifying digitalWriteFast.h to be compatible with ATTinyCore Digispark Pro default pin mapping.
1 parent 39eec4c commit 708d38c

File tree

6 files changed

+101
-42
lines changed

6 files changed

+101
-42
lines changed

.github/workflows/LibraryBuild.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ jobs:
5353
- megaTinyCore:megaavr:atxy4:chip=1604,clock=16internal
5454
- digistump:avr:digispark-tiny:clock=clock16
5555
- ATTinyCore:avr:attinyx5micr:LTO=enable,sketchclock=16pll
56+
- ATTinyCore:avr:attinyx7micr:LTO=enable,sketchclock=16external,pinmapping=new,millis=enabled
57+
- ATTinyCore:avr:attinyx8micr:LTO=enable,sketchclock=16external,pinmapping=mhtiny,millis=enabled # ATtiny88 China clone board @16 MHz
5658
- TinyCore:avr:tiny32
5759
- arduino:samd:arduino_zero_native
5860
- MegaCore:avr:128:bootloader=no_bootloader,eeprom=keep,BOD=2v7,LTO=Os_flto,clock=8MHz_internal # ATmega128
@@ -111,12 +113,17 @@ jobs:
111113
required-libraries: ATtinySerialOut
112114
sketch-names: MinimalReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino
113115

114-
- arduino-boards-fqbn: ATTinyCore:avr:attinyx8micr:LTO=enable,sketchclock=16external,pinmapping=mhtiny,millis=enabled # ATtiny88 China clone board @16 MHz
116+
- arduino-boards-fqbn: ATTinyCore:avr:attinyx5micr:LTO=enable,sketchclock=16pll
115117
platform-url: http://drazzy.com/package_drazzy.com_index.json
116118
required-libraries: ATtinySerialOut
117119
sketch-names: MinimalReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino
118120

119-
- arduino-boards-fqbn: ATTinyCore:avr:attinyx5micr:LTO=enable,sketchclock=16pll
121+
- arduino-boards-fqbn: ATTinyCore:avr:attinyx7micr:LTO=enable,sketchclock=16external,pinmapping=new,millis=enabled
122+
platform-url: http://drazzy.com/package_drazzy.com_index.json
123+
required-libraries: ATtinySerialOut
124+
sketch-names: MinimalReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino
125+
126+
- arduino-boards-fqbn: ATTinyCore:avr:attinyx8micr:LTO=enable,sketchclock=16external,pinmapping=mhtiny,millis=enabled # ATtiny88 China clone board @16 MHz
120127
platform-url: http://drazzy.com/package_drazzy.com_index.json
121128
required-libraries: ATtinySerialOut
122129
sketch-names: MinimalReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,15 @@ If you are using Sloeber as your IDE, you can easily define global symbols with
217217
![Sloeber settings](https://github.com/ArminJo/ServoEasing/blob/master/pictures/SloeberDefineSymbols.png)
218218

219219
# Supported Boards
220+
Digispark boards are tested with the recommended [ATTinyCore](https://github.com/SpenceKonde/ATTinyCore) using `New Style` pin mapping for the pro board.
220221
- Arduino Uno / Mega / Leonardo / Duemilanove / Diecimila / LilyPad / Mini / Fio / Nano etc.
221222
- Teensy 1.0 / 1.0++ / 2.0 / 2++ / 3.0 / 3.1 / Teensy-LC; Credits: PaulStoffregen (Teensy Team)
222223
- Sanguino
223224
- ATmega8, 48, 88, 168, 328
224225
- ATmega8535, 16, 32, 164, 324, 644, 1284,
225226
- ATmega64, 128
226227
- ATmega4809 (Nano every)
227-
- ATtiny84, 85
228+
- ATtiny84, 85, 167 (Digispark + Digispark Pro)
228229
- SAMD21 (DUE, Zero)
229230
- ESP32
230231
- ESP8266. [This fork](https://github.com/crankyoldgit/IRremoteESP8266) supports an [impressive set of protocols](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/SupportedProtocols.md).

examples/SendLGAirConditionerDemo/SendLGAirConditionerDemo.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
#include <Arduino.h>
3434

35-
#define USE_LG2_PROTOCOL // Try it if you do not have success with the default LG protocol
35+
//#define USE_LG2_PROTOCOL // Try it if you do not have success with the default LG protocol
3636

3737
/*
3838
* Define macros for input and output pin etc.

src/IRremoteInt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,9 @@ class IRsend {
400400

401401
IRsend();
402402
void begin(bool aEnableLEDFeedback, uint8_t aFeedbackLEDPin = USE_DEFAULT_FEEDBACK_LED_PIN)
403+
#if !defined (DOXYGEN)
403404
__attribute__ ((deprecated ("Please use begin(<sendPin>, <EnableLEDFeedback>, <LEDFeedbackPin>)")));
405+
#endif
404406

405407
size_t write(IRData *aIRSendData, uint_fast8_t aNumberOfRepeats = NO_REPEATS);
406408

@@ -428,7 +430,9 @@ class IRsend {
428430
void sendBoseWave(uint8_t aCommand, uint_fast8_t aNumberOfRepeats = NO_REPEATS);
429431
void sendDenon(uint8_t aAddress, uint8_t aCommand, uint_fast8_t aNumberOfRepeats, bool aSendSharp = false);
430432
void sendDenonRaw(uint16_t aRawData, uint_fast8_t aNumberOfRepeats = 0)
433+
#if !defined (DOXYGEN)
431434
__attribute__ ((deprecated ("Please use sendDenon(aAddress, aCommand, aNumberOfRepeats).")));
435+
#endif
432436
void sendJVC(uint8_t aAddress, uint8_t aCommand, uint_fast8_t aNumberOfRepeats);
433437

434438
void sendLGRepeat(bool aUseLG2Protocol = false);

src/digitalWriteFast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@
407407

408408
// --- ATtinyX4 + ATtinyX7 ---
409409
#elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
410-
# if defined(ARDUINO_AVR_DIGISPARKPRO)
410+
# if defined(ARDUINO_AVR_DIGISPARKPRO) || PIN_PA7 == 5
411411
// Strange enumeration of pins on Digispark board and core library
412412
#define __digitalPinToPortReg(P) (((P) <= 4) ? &PORTB : &PORTA)
413413
#define __digitalPinToDDRReg(P) (((P) <= 4) ? &DDRB : &DDRA)

src/private/IRTimer.cpp.h

Lines changed: 84 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@
120120
#define IR_USE_AVR_TIMER1 // send pin = pin 6
121121
# endif
122122

123+
#elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
124+
# if !defined(IR_USE_AVR_TIMER1)
125+
#define IR_USE_AVR_TIMER1
126+
# endif
127+
#define USE_TIMER_CHANNEL_B // send pin = pin PB1
128+
123129
//ATtiny85
124130
#elif defined(__AVR_ATtiny85__)
125131
# if !defined(IR_USE_AVR_TIMER_TINY0) && !defined(IR_USE_AVR_TIMER_TINY1)
@@ -246,16 +252,26 @@
246252
#define IR_SEND_PIN 13
247253

248254
# elif defined(__AVR_ATtiny84__)
249-
# define IR_SEND_PIN 6
255+
#define IR_SEND_PIN 6
256+
257+
# elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
258+
#define IR_SEND_PIN PIN_PB1 // OC1BU at ATTinyCore (BU/PB1, BV/PB3, BW/PB5 and BX/PB7 are available) see ENABLE_SEND_PWM_BY_TIMER
250259

251260
# else
252261
#define IR_SEND_PIN 9 // OC1A Arduino Duemilanove, Diecimila, LilyPad, Sparkfun Pro Micro, Leonardo, MH-ET Tiny88 etc.
253262
# endif // defined(CORE_OC1A_PIN)
254-
# endif // defined(SEND_PWM_BY_TIMER)
255263

256-
#define TIMER_RESET_INTR_PENDING
264+
# if defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
265+
// Clear OC1A/OC1B on Compare Match when up-counting. Set OC1A/OC1B on Compare Match when downcounting.
266+
#define ENABLE_SEND_PWM_BY_TIMER TCNT1 = 0; (TCCR1A |= _BV(COM1A1); (TCCR1D |= _BV(OC1BU)) // + enable OC1BU as output
267+
#define DISABLE_SEND_PWM_BY_TIMER (TCCR1D = 0)
268+
# else
257269
#define ENABLE_SEND_PWM_BY_TIMER TCNT1 = 0; (TCCR1A |= _BV(COM1A1)) // Clear OC1A/OC1B on Compare Match when up-counting. Set OC1A/OC1B on Compare Match when downcounting.
258270
#define DISABLE_SEND_PWM_BY_TIMER (TCCR1A &= ~(_BV(COM1A1)))
271+
# endif
272+
# endif // defined(SEND_PWM_BY_TIMER)
273+
274+
#define TIMER_RESET_INTR_PENDING
259275

260276
# if defined(__AVR_ATmega8__) || defined(__AVR_ATmega8515__) \
261277
|| defined(__AVR_ATmega8535__) || defined(__AVR_ATmega16__) \
@@ -268,10 +284,18 @@
268284
#define TIMER_DISABLE_RECEIVE_INTR (TIMSK1 = 0)
269285
# endif
270286

271-
# if defined(TIMER1_COMPA_vect)
287+
# if defined(USE_TIMER_CHANNEL_B)
288+
# if defined(TIMER1_COMPB_vect)
289+
#define TIMER_INTR_NAME TIMER1_COMPB_vect
290+
# elif defined(TIM1_COMPB_vect)
291+
#define TIMER_INTR_NAME TIM1_COMPB_vect
292+
# endif
293+
#else
294+
# if defined(TIMER1_COMPA_vect)
272295
#define TIMER_INTR_NAME TIMER1_COMPA_vect
273-
# elif defined(TIM1_COMPA_vect)
296+
# elif defined(TIM1_COMPA_vect)
274297
#define TIMER_INTR_NAME TIM1_COMPA_vect
298+
# endif
275299
# endif
276300

277301
void timerConfigForSend(uint8_t aFrequencyKHz) {
@@ -280,14 +304,22 @@ void timerConfigForSend(uint8_t aFrequencyKHz) {
280304
TCCR1A = _BV(WGM11);// PWM, Phase Correct, Top is ICR1
281305
TCCR1B = _BV(WGM13) | _BV(CS10);// CS10 -> no prescaling
282306
ICR1 = pwmval - 1;
307+
# if defined(USE_TIMER_CHANNEL_B)
308+
OCR1A = ((pwmval * IR_SEND_DUTY_CYCLE) / 100) - 1;
309+
# else
283310
OCR1A = ((pwmval * IR_SEND_DUTY_CYCLE) / 100) - 1;
311+
# endif
284312
TCNT1 = 0;// not really required, since we have an 8 bit counter, but makes the signal more reproducible
285313
# else
286314
const uint16_t pwmval = ((F_CPU / 8) / 2000) / (aFrequencyKHz); // 2000 instead of 1000 because of Phase Correct PWM
287315
TCCR1A = _BV(WGM11);// PWM, Phase Correct, Top is ICR1
288316
TCCR1B = _BV(WGM13) | _BV(CS11);// CS11 -> Prescaling by 8
289317
ICR1 = pwmval - 1;
318+
# if defined(USE_TIMER_CHANNEL_B)
290319
OCR1A = ((pwmval * IR_SEND_DUTY_CYCLE) / 100) - 1;
320+
# else
321+
OCR1A = ((pwmval * IR_SEND_DUTY_CYCLE) / 100) - 1;
322+
# endif
291323
TCNT1 = 0;// not really required, since we have an 8 bit counter, but makes the signal more reproducible
292324
# endif
293325
}
@@ -320,11 +352,12 @@ void timerConfigForReceive() {
320352
# else
321353
#define IR_SEND_PIN 3 // Arduino Duemilanove, Diecimila, LilyPad, etc
322354
# endif // defined(CORE_OC2B_PIN)
323-
# endif
324355

325-
#define TIMER_RESET_INTR_PENDING
326356
#define ENABLE_SEND_PWM_BY_TIMER TCNT2 = 0; (TCCR2A |= _BV(COM2B1)) // Clear OC2B on Compare Match
327357
#define DISABLE_SEND_PWM_BY_TIMER (TCCR2A &= ~(_BV(COM2B1))) // Normal port operation, OC2B disconnected.
358+
# endif // defined(SEND_PWM_BY_TIMER)
359+
360+
#define TIMER_RESET_INTR_PENDING
328361
#define TIMER_ENABLE_RECEIVE_INTR (TIMSK2 = _BV(OCIE2B)) // Output Compare Match A Interrupt Enable
329362
#define TIMER_DISABLE_RECEIVE_INTR (TIMSK2 = 0)
330363
#define TIMER_INTR_NAME TIMER2_COMPB_vect // We use TIMER2_COMPB_vect to be compatible with tone() library
@@ -391,11 +424,12 @@ void timerConfigForReceive() {
391424
# else
392425
#error Please add OC3A pin number here
393426
# endif
394-
# endif
395427

396-
#define TIMER_RESET_INTR_PENDING
397428
#define ENABLE_SEND_PWM_BY_TIMER TCNT3 = 0; (TCCR3A |= _BV(COM3A1))
398429
#define DISABLE_SEND_PWM_BY_TIMER (TCCR3A &= ~(_BV(COM3A1)))
430+
# endif
431+
432+
#define TIMER_RESET_INTR_PENDING
399433
#define TIMER_ENABLE_RECEIVE_INTR (TIMSK3 = _BV(OCIE3B))
400434
#define TIMER_DISABLE_RECEIVE_INTR (TIMSK3 = 0)
401435
#define TIMER_INTR_NAME TIMER3_COMPB_vect
@@ -432,11 +466,12 @@ void timerConfigForReceive() {
432466
# else
433467
#error Please add OC4A pin number here
434468
# endif
435-
# endif
436469

437-
#define TIMER_RESET_INTR_PENDING
438470
#define ENABLE_SEND_PWM_BY_TIMER TCNT4 = 0; (TCCR4A |= _BV(COM4A1))
439471
#define DISABLE_SEND_PWM_BY_TIMER (TCCR4A &= ~(_BV(COM4A1)))
472+
# endif
473+
474+
#define TIMER_RESET_INTR_PENDING
440475
#define TIMER_ENABLE_RECEIVE_INTR (TIMSK4 = _BV(OCIE4A))
441476
#define TIMER_DISABLE_RECEIVE_INTR (TIMSK4 = 0)
442477
#define TIMER_INTR_NAME TIMER4_COMPA_vect
@@ -474,17 +509,18 @@ void timerConfigForReceive() {
474509
# else
475510
#error Please add OC4A pin number here
476511
# endif
477-
# endif
478512

479-
#define TIMER_RESET_INTR_PENDING
480-
# if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro
513+
# if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro
481514
#define ENABLE_SEND_PWM_BY_TIMER TCNT4 = 0; (TCCR4A |= _BV(COM4A0)) // Use complementary OC4A output on pin 5
482515
#define DISABLE_SEND_PWM_BY_TIMER (TCCR4A &= ~(_BV(COM4A0))) // (Pro Micro does not map PC7 (32/ICP3/CLK0/OC4A)
483516
// of ATmega32U4 )
484-
# else
517+
# else
485518
#define ENABLE_SEND_PWM_BY_TIMER TCNT4 = 0; (TCCR4A |= _BV(COM4A1))
486519
#define DISABLE_SEND_PWM_BY_TIMER (TCCR4A &= ~(_BV(COM4A1)))
520+
# endif
487521
# endif
522+
523+
#define TIMER_RESET_INTR_PENDING
488524
#define TIMER_ENABLE_RECEIVE_INTR (TIMSK4 = _BV(TOIE4))
489525
#define TIMER_DISABLE_RECEIVE_INTR (TIMSK4 = 0)
490526
#define TIMER_INTR_NAME TIMER4_OVF_vect
@@ -530,11 +566,12 @@ void timerConfigForReceive() {
530566
# else
531567
#error Please add OC5A pin number here
532568
# endif
533-
# endif
534569

535-
#define TIMER_RESET_INTR_PENDING
536570
#define ENABLE_SEND_PWM_BY_TIMER TCNT5 = 0; (TCCR5A |= _BV(COM5A1))
537571
#define DISABLE_SEND_PWM_BY_TIMER (TCCR5A &= ~(_BV(COM5A1)))
572+
# endif
573+
574+
#define TIMER_RESET_INTR_PENDING
538575
#define TIMER_ENABLE_RECEIVE_INTR (TIMSK5 = _BV(OCIE5A))
539576
#define TIMER_DISABLE_RECEIVE_INTR (TIMSK5 = 0)
540577
#define TIMER_INTR_NAME TIMER5_COMPA_vect
@@ -564,11 +601,12 @@ void timerConfigForReceive() {
564601
#elif defined(IR_USE_AVR_TIMER_TINY0)
565602
# if defined(SEND_PWM_BY_TIMER)
566603
#define IR_SEND_PIN 1
567-
# endif
568604

569-
#define TIMER_RESET_INTR_PENDING
570605
#define ENABLE_SEND_PWM_BY_TIMER TCNT0 = 0; (TCCR0A |= _BV(COM0B1))
571606
#define DISABLE_SEND_PWM_BY_TIMER (TCCR0A &= ~(_BV(COM0B1)))
607+
# endif
608+
609+
#define TIMER_RESET_INTR_PENDING
572610
#define TIMER_ENABLE_RECEIVE_INTR (TIMSK |= _BV(OCIE0A))
573611
#define TIMER_DISABLE_RECEIVE_INTR (TIMSK &= ~(_BV(OCIE0A)))
574612
#define TIMER_INTR_NAME TIMER0_COMPA_vect
@@ -606,11 +644,12 @@ void timerConfigForReceive() {
606644
#elif defined(IR_USE_AVR_TIMER_TINY1)
607645
# if defined(SEND_PWM_BY_TIMER)
608646
#define IR_SEND_PIN 4
609-
# endif
610647

611-
#define TIMER_RESET_INTR_PENDING
612648
#define ENABLE_SEND_PWM_BY_TIMER TCNT1 = 0; GTCCR |= _BV(PWM1B) | _BV(COM1B0) // Enable pin 4 PWM output (PB4 - Arduino D4)
613649
#define DISABLE_SEND_PWM_BY_TIMER (GTCCR &= ~(_BV(PWM1B) | _BV(COM1B0)))
650+
# endif
651+
652+
#define TIMER_RESET_INTR_PENDING
614653
#define TIMER_ENABLE_RECEIVE_INTR (TIMSK |= _BV(OCIE1B))
615654
#define TIMER_DISABLE_RECEIVE_INTR (TIMSK &= ~(_BV(OCIE1B)))
616655
#define TIMER_INTR_NAME TIMER1_COMPB_vect
@@ -654,12 +693,13 @@ void timerConfigForReceive() {
654693
#elif defined(IR_USE_AVR_TIMER_B)
655694
# if defined(SEND_PWM_BY_TIMER)
656695
#define IR_SEND_PIN A4 // PA2 - A4 on Nano Every, PA5 on ATtiny1604
696+
697+
#define ENABLE_SEND_PWM_BY_TIMER TCB0.CNT = 0; (TCB0.CTRLB |= TCB_CCMPEN_bm)
698+
#define DISABLE_SEND_PWM_BY_TIMER (TCB0.CTRLB &= ~(TCB_CCMPEN_bm))
657699
# endif
658700

659701
// ATmega4809 TCB0
660702
#define TIMER_RESET_INTR_PENDING TCB0.INTFLAGS = TCB_CAPT_bm
661-
#define ENABLE_SEND_PWM_BY_TIMER TCB0.CNT = 0; (TCB0.CTRLB |= TCB_CCMPEN_bm)
662-
#define DISABLE_SEND_PWM_BY_TIMER (TCB0.CTRLB &= ~(TCB_CCMPEN_bm))
663703
#define TIMER_ENABLE_RECEIVE_INTR (TCB0.INTCTRL = TCB_CAPT_bm)
664704
#define TIMER_DISABLE_RECEIVE_INTR (TCB0.INTCTRL &= ~(TCB_CAPT_bm))
665705
#define TIMER_INTR_NAME TCB0_INT_vect
@@ -690,11 +730,12 @@ void timerConfigForReceive() {
690730
#elif defined(IR_USE_AVR_TIMER_D)
691731
# if defined(SEND_PWM_BY_TIMER)
692732
#define IR_SEND_PIN 13
693-
# endif
694733

695-
#define TIMER_RESET_INTR_PENDING (TCD0.INTFLAGS = TCD_OVF_bm)
696734
#define ENABLE_SEND_PWM_BY_TIMER (timerEnablSendPWM())
697735
#define DISABLE_SEND_PWM_BY_TIMER (TCD0.CTRLA = 0) // do not disable output, disable complete timer
736+
# endif
737+
738+
#define TIMER_RESET_INTR_PENDING (TCD0.INTFLAGS = TCD_OVF_bm)
698739
#define TIMER_ENABLE_RECEIVE_INTR (TCD0.INTCTRL = TCD_OVF_bm)
699740
#define TIMER_DISABLE_RECEIVE_INTR (TCD0.INTCTRL = 0)
700741
#define TIMER_INTR_NAME TCD0_OVF_vect
@@ -754,12 +795,13 @@ void timerConfigForReceive() {
754795
#elif defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
755796
# if defined(SEND_PWM_BY_TIMER)
756797
#define IR_SEND_PIN 5
798+
799+
#define ENABLE_SEND_PWM_BY_TIMER do { CORE_PIN5_CONFIG = PORT_PCR_MUX(2) | PORT_PCR_DSE | PORT_PCR_SRE; } while(0)
800+
#define DISABLE_SEND_PWM_BY_TIMER do { CORE_PIN5_CONFIG = PORT_PCR_MUX(1) | PORT_PCR_DSE | PORT_PCR_SRE; } while(0)
757801
# endif
758802

759803
// Special carrier modulator timer for Teensy 3.0 / Teensy 3.1
760804
#define TIMER_RESET_INTR_PENDING uint8_t tmp __attribute__((unused)) = CMT_MSC; CMT_CMD2 = 30
761-
#define ENABLE_SEND_PWM_BY_TIMER do { CORE_PIN5_CONFIG = PORT_PCR_MUX(2) | PORT_PCR_DSE | PORT_PCR_SRE; } while(0)
762-
#define DISABLE_SEND_PWM_BY_TIMER do { CORE_PIN5_CONFIG = PORT_PCR_MUX(1) | PORT_PCR_DSE | PORT_PCR_SRE; } while(0)
763805
#define TIMER_ENABLE_RECEIVE_INTR NVIC_ENABLE_IRQ(IRQ_CMT)
764806
#define TIMER_DISABLE_RECEIVE_INTR NVIC_DISABLE_IRQ(IRQ_CMT)
765807
#define TIMER_INTR_NAME cmt_isr
@@ -807,12 +849,13 @@ void timerConfigForReceive() {
807849
#elif defined(__MKL26Z64__)
808850
# if defined(SEND_PWM_BY_TIMER)
809851
#define IR_SEND_PIN 16
852+
853+
#define ENABLE_SEND_PWM_BY_TIMER FTM1_CNT = 0; CORE_PIN16_CONFIG = PORT_PCR_MUX(3)|PORT_PCR_DSE|PORT_PCR_SRE
854+
#define DISABLE_SEND_PWM_BY_TIMER CORE_PIN16_CONFIG = PORT_PCR_MUX(1)|PORT_PCR_SRE
810855
# endif
811856

812857
// defines for TPM1 timer on Teensy-LC
813858
#define TIMER_RESET_INTR_PENDING FTM1_SC |= FTM_SC_TOF;
814-
#define ENABLE_SEND_PWM_BY_TIMER FTM1_CNT = 0; CORE_PIN16_CONFIG = PORT_PCR_MUX(3)|PORT_PCR_DSE|PORT_PCR_SRE
815-
#define DISABLE_SEND_PWM_BY_TIMER CORE_PIN16_CONFIG = PORT_PCR_MUX(1)|PORT_PCR_SRE
816859
#define TIMER_ENABLE_RECEIVE_INTR NVIC_ENABLE_IRQ(IRQ_FTM1)
817860
#define TIMER_DISABLE_RECEIVE_INTR NVIC_DISABLE_IRQ(IRQ_FTM1)
818861
#define TIMER_INTR_NAME ftm1_isr
@@ -873,22 +916,25 @@ void timerConfigForReceive() {
873916
}
874917

875918
/***************************************
876-
* ESP32 boards
919+
* ESP32 boards - can use any pin for timer
877920
***************************************/
878921
#elif defined(ESP32)
879-
# if defined(SEND_PWM_BY_TIMER)
922+
//# if defined(SEND_PWM_BY_TIMER)
923+
#if !defined(IR_SEND_PIN)
880924
#define IR_SEND_PIN 4 // can use any pin, no timer restrictions
881-
# endif
925+
#endif
926+
927+
#define ENABLE_SEND_PWM_BY_TIMER ledcWrite(LED_CHANNEL, IR_SEND_DUTY_CYCLE) // we must use channel here not pin number
928+
#define DISABLE_SEND_PWM_BY_TIMER ledcWrite(LED_CHANNEL, 0)
929+
//# endif
882930

883931
# if ! defined(LED_CHANNEL)
884932
#define LED_CHANNEL 0 // The channel used for PWM 0 to 7 are high speed PWM channels
885933
# endif
886934

935+
#define TIMER_RESET_INTR_PENDING
887936
#define TIMER_ENABLE_RECEIVE_INTR timerAlarmEnable(timer)
888937
#define TIMER_DISABLE_RECEIVE_INTR timerEnd(timer); timerDetachInterrupt(timer)
889-
#define TIMER_RESET_INTR_PENDING
890-
#define ENABLE_SEND_PWM_BY_TIMER ledcWrite(LED_CHANNEL, IR_SEND_DUTY_CYCLE) // we must use channel here not pin number
891-
#define DISABLE_SEND_PWM_BY_TIMER ledcWrite(LED_CHANNEL, 0)
892938
// Redefinition of ISR macro which creates a plain function now
893939
# ifdef ISR
894940
#undef ISR
@@ -1152,6 +1198,9 @@ void timerConfigForReceive() {
11521198

11531199
# if defined(SEND_PWM_BY_TIMER)
11541200
#define IR_SEND_PIN A5 // Particle supports multiple pins
1201+
1202+
#define ENABLE_SEND_PWM_BY_TIMER analogWrite(IrSender.sendPin, 128, ir_out_kHz*1000)
1203+
#define DISABLE_SEND_PWM_BY_TIMER analogWrite(IrSender.sendPin, 0, ir_out_kHz*1000)
11551204
# endif
11561205

11571206
# ifndef IR_OUT_KHZ
@@ -1163,8 +1212,6 @@ extern int ir_out_kHz;
11631212
//void IRTimerInterruptHandler();
11641213

11651214
#define TIMER_RESET_INTR_PENDING
1166-
#define ENABLE_SEND_PWM_BY_TIMER analogWrite(IrSender.sendPin, 128, ir_out_kHz*1000)
1167-
#define DISABLE_SEND_PWM_BY_TIMER analogWrite(IrSender.sendPin, 0, ir_out_kHz*1000)
11681215
#define TIMER_ENABLE_RECEIVE_INTR timer.begin(IRTimerInterruptHandler, MICROS_PER_TICK, uSec)
11691216
#define TIMER_DISABLE_RECEIVE_INTR timer.end()
11701217

0 commit comments

Comments
 (0)