Added ESP32 IR receive support (IRsend not implemented yet).

- disable a lot of defines not relevant to ESP32, set them to 1 (no-op)
- change default IR pin to 35 from 11
- changed serial speed to 115200 (9600 is too slow to keep up with IR input)
- irSend disables code that will not compile on ESP32. It won't work,
  but it won't break compilation either.
This commit is contained in:
Marc MERLIN
2017-03-19 20:27:56 -07:00
parent 048efb23a2
commit aa8f7b31fe
7 changed files with 52 additions and 5 deletions

View File

@@ -18,7 +18,9 @@
// Whynter A/C ARC-110WD added by Francesco Meschia
//******************************************************************************
#ifndef ESP32
#include <avr/interrupt.h>
#endif
// Defining IR_GLOBAL here allows us to declare the instantiation of global variables
#define IR_GLOBAL
@@ -120,7 +122,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 ESP32
void onTimer()
#else
ISR (TIMER_INTR_NAME)
#endif
{
TIMER_RESET;

View File

@@ -39,6 +39,10 @@
# define BLINKLED_ON() (PORTD |= B00000001)
# define BLINKLED_OFF() (PORTD &= B11111110)
#elif defined(ESP32)
# define BLINKLED 255
# define BLINKLED_ON() 1
# define BLINKLED_OFF() 1
#else
# define BLINKLED 13
#define BLINKLED_ON() (PORTB |= B00100000)
@@ -147,12 +151,21 @@
//
#if defined(IR_USE_TIMER2)
#ifdef ESP32 // Used in irSend, not implemented yet (FIXME)
#define TIMER_RESET 1
#define TIMER_ENABLE_PWM 1
#define TIMER_DISABLE_PWM Serial.println("IRsend not implemented for ESP32 yet");
#define TIMER_ENABLE_INTR 1
#define TIMER_DISABLE_INTR 1
#define TIMER_INTR_NAME 1
#else
#define TIMER_RESET
#define TIMER_ENABLE_PWM (TCCR2A |= _BV(COM2B1))
#define TIMER_DISABLE_PWM (TCCR2A &= ~(_BV(COM2B1)))
#define TIMER_ENABLE_INTR (TIMSK2 = _BV(OCIE2A))
#define TIMER_DISABLE_INTR (TIMSK2 = 0)
#define TIMER_INTR_NAME TIMER2_COMPA_vect
#endif
#define TIMER_CONFIG_KHZ(val) ({ \
const uint8_t pwmval = SYSCLOCK / 2000 / (val); \

View File

@@ -8,7 +8,11 @@
#include <IRremote.h>
#ifdef ESP32
int RECV_PIN = 35;
#else
int RECV_PIN = 11;
#endif
IRrecv irrecv(RECV_PIN);
@@ -16,8 +20,10 @@ decode_results results;
void setup()
{
Serial.begin(9600);
Serial.begin(115200);
Serial.println("Enabling IRin");
irrecv.enableIRIn(); // Start the receiver
Serial.println("Enabled IRin");
}
void loop() {

View File

@@ -15,7 +15,11 @@
* You can change this to another available Arduino Pin.
* Your IR receiver should be connected to the pin defined here
*/
#ifdef ESP32
int RECV_PIN = 35;
#else
int RECV_PIN = 11;
#endif
IRrecv irrecv(RECV_PIN);
@@ -23,7 +27,7 @@ decode_results results;
void setup()
{
Serial.begin(9600);
Serial.begin(115200);
irrecv.enableIRIn(); // Start the receiver
}

View File

@@ -6,7 +6,7 @@
//------------------------------------------------------------------------------
// Tell IRremote which Arduino pin is connected to the IR Receiver (TSOP4838)
//
int recvPin = 11;
int recvPin = 35;
IRrecv irrecv(recvPin);
//+=============================================================================
@@ -14,7 +14,7 @@ IRrecv irrecv(recvPin);
//
void setup ( )
{
Serial.begin(9600); // Status message will be sent to PC at 9600 baud
Serial.begin(115200); // Status message will be sent to PC at 9600 baud
irrecv.enableIRIn(); // Start the receiver
}

View File

@@ -1,6 +1,11 @@
#include "IRremote.h"
#include "IRremoteInt.h"
#ifdef ESP32
hw_timer_t *timer;
void onTimer(); // defined in IRremote.cpp
#endif
//+=============================================================================
// Decodes the received IR message
// Returns 0 if no data ready, 1 if data ready.
@@ -117,6 +122,15 @@ IRrecv::IRrecv (int recvpin, int blinkpin)
//
void IRrecv::enableIRIn ( )
{
// Interrupt Service Routine - Fires every 50uS
#ifdef ESP32
// 3 timers, choose #1, 80 divider nanosecond precision, 1 to count up
timer = timerBegin(1, 80, 1);
timerAttachInterrupt(timer, &onTimer, 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 +144,7 @@ void IRrecv::enableIRIn ( )
TIMER_RESET;
sei(); // enable interrupts
#endif
// Initialize state machine variables
irparams.rcvstate = STATE_IDLE;

View File

@@ -54,6 +54,8 @@ void IRsend::space (unsigned int time)
//
void IRsend::enableIROut (int khz)
{
// FIXME: implement ESP32 support
#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
}
//+=============================================================================