Skip to content

Commit 7741645

Browse files
author
Peter Max
committed
- changes to work with V3 Arduino
1 parent 0056717 commit 7741645

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/IRrecv.cpp

+23-22
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static void USE_IRAM_ATTR gpio_intr() {
243243
timer->dev->config.alarm_en = 1;
244244
#else // _ESP32_IRRECV_TIMER_HACK
245245
timerWrite(timer, 0);
246-
timerAlarmEnable(timer);
246+
timerAlarm(timer,MS_TO_USEC(params.timeout),0,1);
247247
#endif // _ESP32_IRRECV_TIMER_HACK
248248
#endif // ESP32
249249
}
@@ -356,10 +356,22 @@ void IRrecv::enableIRIn(const bool pullup) {
356356
pinMode(params.recvpin, INPUT);
357357
#endif // UNIT_TEST
358358
}
359+
360+
#ifndef UNIT_TEST
361+
#if defined(ESP8266)
362+
// Initialise ESP8266 timer.
363+
os_timer_disarm(&timer);
364+
os_timer_setfn(&timer, reinterpret_cast<os_timer_func_t *>(read_timeout),
365+
NULL);
366+
#endif // ESP8266
367+
// Attach Interrupt
368+
attachInterrupt(params.recvpin, gpio_intr, CHANGE);
369+
#endif // UNIT_TEST
370+
359371
#if defined(ESP32)
360372
// Initialise the ESP32 timer.
361373
// 80MHz / 80 = 1 uSec granularity.
362-
timer = timerBegin(_timer_num, 80, true);
374+
timer = timerBegin(1000000);
363375
#ifdef DEBUG
364376
if (timer == NULL) {
365377
DPRINT("FATAL: Unable enable system timer: ");
@@ -368,26 +380,17 @@ void IRrecv::enableIRIn(const bool pullup) {
368380
#endif // DEBUG
369381
assert(timer != NULL); // Check we actually got the timer.
370382
// Set the timer so it only fires once, and set it's trigger in uSeconds.
371-
timerAlarmWrite(timer, MS_TO_USEC(params.timeout), ONCE);
383+
timerAlarm(timer, MS_TO_USEC(params.timeout), 0,1);
372384
// Note: Interrupt needs to be attached before it can be enabled or disabled.
373385
// Note: EDGE (true) is not supported, use LEVEL (false). Ref: #1713
374386
// See: https://github.com/espressif/arduino-esp32/blob/caef4006af491130136b219c1205bdcf8f08bf2b/cores/esp32/esp32-hal-timer.c#L224-L227
375-
timerAttachInterrupt(timer, &read_timeout, false);
387+
timerAttachInterrupt(timer, &read_timeout);
376388
#endif // ESP32
377389

378390
// Initialise state machine variables
379391
resume();
380392

381-
#ifndef UNIT_TEST
382-
#if defined(ESP8266)
383-
// Initialise ESP8266 timer.
384-
os_timer_disarm(&timer);
385-
os_timer_setfn(&timer, reinterpret_cast<os_timer_func_t *>(read_timeout),
386-
NULL);
387-
#endif // ESP8266
388-
// Attach Interrupt
389-
attachInterrupt(params.recvpin, gpio_intr, CHANGE);
390-
#endif // UNIT_TEST
393+
391394
}
392395

393396
/// Stop collection of any received IR data.
@@ -398,7 +401,7 @@ void IRrecv::disableIRIn(void) {
398401
os_timer_disarm(&timer);
399402
#endif // ESP8266
400403
#if defined(ESP32)
401-
timerAlarmDisable(timer);
404+
//timerAlarmDisable(timer);
402405
timerDetachInterrupt(timer);
403406
timerEnd(timer);
404407
#endif // ESP32
@@ -413,7 +416,8 @@ void IRrecv::pause(void) {
413416
params.rawlen = 0;
414417
params.overflow = false;
415418
#if defined(ESP32)
416-
gpio_intr_disable((gpio_num_t)params.recvpin);
419+
//gpio_intr_disable((gpio_num_t)params.recvpin);
420+
detachInterrupt((gpio_num_t)params.recvpin);
417421
#endif // ESP32
418422
}
419423

@@ -426,8 +430,9 @@ void IRrecv::resume(void) {
426430
params.rawlen = 0;
427431
params.overflow = false;
428432
#if defined(ESP32)
429-
timerAlarmDisable(timer);
430-
gpio_intr_enable((gpio_num_t)params.recvpin);
433+
//timerAlarmDisable(timer);
434+
//gpio_intr_enable((gpio_num_t)params.recvpin);
435+
attachInterrupt(params.recvpin, gpio_intr, CHANGE);
431436
#endif // ESP32
432437
}
433438

@@ -1185,10 +1190,6 @@ bool IRrecv::decode(decode_results *results, irparams_t *save,
11851190
DPRINTLN("Attempting York decode");
11861191
if (decodeYork(results, offset, kYorkBits)) return true;
11871192
#endif // DECODE_YORK
1188-
#if DECODE_BLUESTARHEAVY
1189-
DPRINTLN("Attempting BluestarHeavy decode");
1190-
if (decodeBluestarHeavy(results, offset, kBluestarHeavyBits)) return true;
1191-
#endif // DECODE_BLUESTARHEAVY
11921193
// Typically new protocols are added above this line.
11931194
}
11941195
#if DECODE_HASH

0 commit comments

Comments
 (0)