mirror of
https://github.com/Theaninova/Arduino-IRremote.git
synced 2025-12-11 08:56:14 +00:00
Merge pull request #425 from marcmerlin/master
Added ESP32 IR receive support (IRsend not implemented yet).
This commit is contained in:
@@ -18,5 +18,6 @@ These are the active contributors of this project that you may contact if there
|
||||
- [ElectricRCAircraftGuy](https://github.com/electricrcaircraftguy): Active Contributor
|
||||
- [philipphenkel](https://github.com/philipphenkel): Active Contributor
|
||||
- [MCUdude](https://github.com/MCUdude): Contributor
|
||||
- [marcmerlin](https://github.com/marcmerlin): Contributor (ESP32 port)
|
||||
|
||||
Note: This list is being updated constantly so please let [z3t0](https://github.com/z3t0) know if you have been missed.
|
||||
|
||||
11
IRremote.cpp
11
IRremote.cpp
@@ -18,14 +18,17 @@
|
||||
// Whynter A/C ARC-110WD added by Francesco Meschia
|
||||
//******************************************************************************
|
||||
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
// Defining IR_GLOBAL here allows us to declare the instantiation of global variables
|
||||
#define IR_GLOBAL
|
||||
# include "IRremote.h"
|
||||
# include "IRremoteInt.h"
|
||||
#undef IR_GLOBAL
|
||||
|
||||
#ifndef IR_TIMER_USE_ESP32
|
||||
#include <avr/interrupt.h>
|
||||
#endif
|
||||
|
||||
|
||||
//+=============================================================================
|
||||
// The match functions were (apparently) originally MACROs to improve code speed
|
||||
// (although this would have bloated the code) hence the names being CAPS
|
||||
@@ -120,7 +123,11 @@ int MATCH_SPACE (int measured_ticks, int desired_us)
|
||||
// As soon as first MARK arrives:
|
||||
// Gap width is recorded; Ready is cleared; New logging starts
|
||||
//
|
||||
#ifdef IR_TIMER_USE_ESP32
|
||||
void IRTimer()
|
||||
#else
|
||||
ISR (TIMER_INTR_NAME)
|
||||
#endif
|
||||
{
|
||||
TIMER_RESET;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ Tutorials and more information will be made available on [the official homepage]
|
||||
- ATmega8535, 16, 32, 164, 324, 644, 1284,
|
||||
- ATmega64, 128
|
||||
- ATtiny 84 / 85
|
||||
- ESP32 (receive only)
|
||||
|
||||
We are open to suggestions for adding support to new boards, however we highly recommend you contact your supplier first and ask them to provide support from their side.
|
||||
|
||||
@@ -42,6 +43,7 @@ We are open to suggestions for adding support to new boards, however we highly r
|
||||
| [ATmega8535 ATmega16, ATmega32](https://github.com/MCUdude/MightyCore) | **13** | **1** |
|
||||
| [ATmega64, ATmega128](https://github.com/MCUdude/MegaCore) | **13** | **1** |
|
||||
| ATmega1280, ATmega2560 | 5, 6, **9**, 11, 46 | 1, **2**, 3, 4, 5 |
|
||||
| [ESP32](http://esp32.net/) | N/A (not supported) | **1** |
|
||||
| [Teensy 1.0](https://www.pjrc.com/teensy/) | **17** | **1** |
|
||||
| [Teensy 2.0](https://www.pjrc.com/teensy/) | 9, **10**, 14 | 1, 3, **4_HS** |
|
||||
| [Teensy++ 1.0 / 2.0](https://www.pjrc.com/teensy/) | **1**, 16, 25 | 1, **2**, 3 |
|
||||
|
||||
37
boarddefs.h
37
boarddefs.h
@@ -39,9 +39,14 @@
|
||||
# define BLINKLED_ON() (PORTD |= B00000001)
|
||||
# define BLINKLED_OFF() (PORTD &= B11111110)
|
||||
|
||||
// No system LED on ESP32, disable blinking
|
||||
#elif defined(ESP32)
|
||||
# define BLINKLED 255
|
||||
# define BLINKLED_ON() 1
|
||||
# define BLINKLED_OFF() 1
|
||||
#else
|
||||
# define BLINKLED 13
|
||||
#define BLINKLED_ON() (PORTB |= B00100000)
|
||||
# define BLINKLED_ON() (PORTB |= B00100000)
|
||||
# define BLINKLED_OFF() (PORTB &= B11011111)
|
||||
#endif
|
||||
|
||||
@@ -125,15 +130,17 @@
|
||||
|
||||
// ATtiny84
|
||||
#elif defined(__AVR_ATtiny84__)
|
||||
#define IR_USE_TIMER1 // tx = pin 6
|
||||
#define IR_USE_TIMER1 // tx = pin 6
|
||||
|
||||
//ATtiny85
|
||||
#elif defined(__AVR_ATtiny85__)
|
||||
#define IR_USE_TIMER_TINY0 // tx = pin 1
|
||||
#define IR_USE_TIMER_TINY0 // tx = pin 1
|
||||
|
||||
#elif defined(ESP32)
|
||||
#define IR_TIMER_USE_ESP32
|
||||
#else
|
||||
// Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc
|
||||
// ATmega48, ATmega88, ATmega168, ATmega328
|
||||
#else
|
||||
//#define IR_USE_TIMER1 // tx = pin 9
|
||||
#define IR_USE_TIMER2 // tx = pin 3
|
||||
|
||||
@@ -538,6 +545,28 @@
|
||||
|
||||
#define TIMER_PWM_PIN 1 /* ATtiny85 */
|
||||
|
||||
//---------------------------------------------------------
|
||||
// ESP32 (ESP8266 should likely be added here too)
|
||||
//
|
||||
|
||||
// ESP32 has it own timer API and does not use these macros, but to avoid ifdef'ing
|
||||
// them out in the common code, they are defined to no-op. This allows the code to compile
|
||||
// (which it wouldn't otherwise) but irsend will not work until ESP32 specific code is written
|
||||
// for that -- merlin
|
||||
// As a warning, sending timing specific code from an ESP32 can be challenging if you need 100%
|
||||
// reliability because the arduino code may be interrupted and cause your sent waveform to be the
|
||||
// wrong length. This is specifically an issue for neopixels which require 800Khz resolution.
|
||||
// IR may just work as is with the common code since it's lower frequency, but if not, the other
|
||||
// way to do this on ESP32 is using the RMT built in driver like in this incomplete library below
|
||||
// https://github.com/ExploreEmbedded/ESP32_RMT
|
||||
#elif defined(IR_TIMER_USE_ESP32)
|
||||
#define TIMER_RESET
|
||||
#define TIMER_ENABLE_PWM
|
||||
#define TIMER_DISABLE_PWM Serial.println("IRsend not implemented for ESP32 yet");
|
||||
#define TIMER_ENABLE_INTR
|
||||
#define TIMER_DISABLE_INTR
|
||||
#define TIMER_INTR_NAME
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Unknown Timer
|
||||
//
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
## 2.3.3 - 2017/03/31
|
||||
- Added ESP32 IR receive support [PR #427](https://github.com/z3t0/Arduino-IRremote/pull/425)
|
||||
|
||||
## 2.2.3 - 2017/03/27
|
||||
- Fix calculation of pause length in LEGO PF protocol [PR #427](https://github.com/z3t0/Arduino-IRremote/pull/427)
|
||||
|
||||
|
||||
@@ -17,7 +17,11 @@ decode_results results;
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
// In case the interrupt driver crashes on setup, give a clue
|
||||
// to the user what's going on.
|
||||
Serial.println("Enabling IRin");
|
||||
irrecv.enableIRIn(); // Start the receiver
|
||||
Serial.println("Enabled IRin");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* You can change this to another available Arduino Pin.
|
||||
* Your IR receiver should be connected to the pin defined here
|
||||
*/
|
||||
int RECV_PIN = 11;
|
||||
int RECV_PIN = 11;
|
||||
|
||||
IRrecv irrecv(RECV_PIN);
|
||||
|
||||
|
||||
17
irRecv.cpp
17
irRecv.cpp
@@ -1,5 +1,10 @@
|
||||
#include "IRremote.h"
|
||||
#include "IRremoteInt.h"
|
||||
|
||||
#ifdef IR_TIMER_USE_ESP32
|
||||
hw_timer_t *timer;
|
||||
void IRTimer(); // defined in IRremote.cpp
|
||||
#endif
|
||||
|
||||
//+=============================================================================
|
||||
// Decodes the received IR message
|
||||
@@ -117,6 +122,17 @@ IRrecv::IRrecv (int recvpin, int blinkpin)
|
||||
//
|
||||
void IRrecv::enableIRIn ( )
|
||||
{
|
||||
// Interrupt Service Routine - Fires every 50uS
|
||||
#ifdef ESP32
|
||||
// ESP32 has a proper API to setup timers, no weird chip macros needed
|
||||
// simply call the readable API versions :)
|
||||
// 3 timers, choose #1, 80 divider nanosecond precision, 1 to count up
|
||||
timer = timerBegin(1, 80, 1);
|
||||
timerAttachInterrupt(timer, &IRTimer, 1);
|
||||
// every 50ns, autoreload = true
|
||||
timerAlarmWrite(timer, 50, true);
|
||||
timerAlarmEnable(timer);
|
||||
#else
|
||||
cli();
|
||||
// Setup pulse clock timer interrupt
|
||||
// Prescale /8 (16M/8 = 0.5 microseconds per tick)
|
||||
@@ -130,6 +146,7 @@ void IRrecv::enableIRIn ( )
|
||||
TIMER_RESET;
|
||||
|
||||
sei(); // enable interrupts
|
||||
#endif
|
||||
|
||||
// Initialize state machine variables
|
||||
irparams.rcvstate = STATE_IDLE;
|
||||
|
||||
@@ -54,6 +54,8 @@ void IRsend::space (unsigned int time)
|
||||
//
|
||||
void IRsend::enableIROut (int khz)
|
||||
{
|
||||
// FIXME: implement ESP32 support, see IR_TIMER_USE_ESP32 in boarddefs.h
|
||||
#ifndef ESP32
|
||||
// Disable the Timer2 Interrupt (which is used for receiving IR)
|
||||
TIMER_DISABLE_INTR; //Timer2 Overflow Interrupt
|
||||
|
||||
@@ -66,6 +68,7 @@ void IRsend::enableIROut (int khz)
|
||||
// CS2 = 000: no prescaling
|
||||
// The top value for the timer. The modulation frequency will be SYSCLOCK / 2 / OCR2A.
|
||||
TIMER_CONFIG_KHZ(khz);
|
||||
#endif
|
||||
}
|
||||
|
||||
//+=============================================================================
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/z3t0/Arduino-IRremote.git"
|
||||
},
|
||||
"version": "2.2.3",
|
||||
"version": "2.3.3",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "atmelavr",
|
||||
"authors" :
|
||||
|
||||
Reference in New Issue
Block a user