From b72f1a77875b28dc9b2d790d85cc6bf5296a38de Mon Sep 17 00:00:00 2001 From: Angelo Date: Thu, 22 Jun 2017 13:36:30 +0800 Subject: [PATCH] Add receiving support for Arduino 101 Add receiving support for Arduino 101 Add F() in the serial print Refine the macro define for esp32 --- IRremote.cpp | 4 ++-- boarddefs.h | 20 +++++++++++++++++++- irRecv.cpp | 41 ++++++++++++++++++++++++----------------- irSend.cpp | 2 +- 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/IRremote.cpp b/IRremote.cpp index e811cfc7b..e0748f069 100644 --- a/IRremote.cpp +++ b/IRremote.cpp @@ -24,7 +24,7 @@ # include "IRremoteInt.h" #undef IR_GLOBAL -#ifndef IR_TIMER_USE_ESP32 +#if (!defined(IR_TIMER_USE_ESP32) && !defined(IR_TIMER_USE_CURIE)) #include #endif @@ -123,7 +123,7 @@ 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 +#if (defined(IR_TIMER_USE_ESP32) || defined(IR_TIMER_USE_CURIE)) void IRTimer() #else ISR (TIMER_INTR_NAME) diff --git a/boarddefs.h b/boarddefs.h index 17e25513e..db4b4fd4f 100644 --- a/boarddefs.h +++ b/boarddefs.h @@ -44,6 +44,12 @@ # define BLINKLED 255 # define BLINKLED_ON() 1 # define BLINKLED_OFF() 1 + +#elif defined(CURIE_IDE) || defined(__ARDUINO_ARC__) || defined(ARDUINO_ARCH_ARC32) +# define BLINKLED 13 +# define BLINKLED_ON() (digitalWrite(13, HIGH)) +# define BLINKLED_OFF() (digitalWrite(13, LOW)) + #else # define BLINKLED 13 # define BLINKLED_ON() (PORTB |= B00100000) @@ -138,6 +144,10 @@ #elif defined(ESP32) #define IR_TIMER_USE_ESP32 + +#elif defined(CURIE_IDE) || defined(__ARDUINO_ARC__) || defined(ARDUINO_ARCH_ARC32) + #define IR_TIMER_USE_CURIE + #else // Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc // ATmega48, ATmega88, ATmega168, ATmega328 @@ -562,11 +572,19 @@ #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_DISABLE_PWM Serial.println(F("IRsend not implemented for ESP32 yet")); #define TIMER_ENABLE_INTR #define TIMER_DISABLE_INTR #define TIMER_INTR_NAME +#elif defined(IR_TIMER_USE_CURIE) + +#define TIMER_RESET +#define TIMER_ENABLE_PWM +#define TIMER_DISABLE_PWM Serial.println(F("IRsend not implemented for curie yet")); +#define TIMER_ENABLE_INTR +#define TIMER_DISABLE_INTR +#define TIMER_INTR_NAME //--------------------------------------------------------- // Unknown Timer // diff --git a/irRecv.cpp b/irRecv.cpp index 12b0806b1..7e2688b70 100644 --- a/irRecv.cpp +++ b/irRecv.cpp @@ -1,10 +1,15 @@ #include "IRremote.h" #include "IRremoteInt.h" - -#ifdef IR_TIMER_USE_ESP32 -hw_timer_t *timer; -void IRTimer(); // defined in IRremote.cpp -#endif + +#ifdef IR_TIMER_USE_ESP32 +hw_timer_t *timer; +void IRTimer(); // defined in IRremote.cpp +#endif + +#ifdef IR_TIMER_USE_CURIE +#include "CurieTimerOne.h" +void IRTimer(); // defined in IRremote.cpp +#endif //+============================================================================= // Decodes the received IR message @@ -122,17 +127,19 @@ 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 +// Interrupt Service Routine - Fires every 50uS +#ifdef IR_TIMER_USE_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); +#elif defined(IR_TIMER_USE_CURIE) + CurieTimerOne.start(50, &IRTimer); +#else cli(); // Setup pulse clock timer interrupt // Prescale /8 (16M/8 = 0.5 microseconds per tick) @@ -146,7 +153,7 @@ void IRrecv::enableIRIn ( ) TIMER_RESET; sei(); // enable interrupts -#endif +#endif // Initialize state machine variables irparams.rcvstate = STATE_IDLE; diff --git a/irSend.cpp b/irSend.cpp index c3ef3ffac..1d26c6bdb 100644 --- a/irSend.cpp +++ b/irSend.cpp @@ -55,7 +55,7 @@ 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 +#if (!defined(IR_TIMER_USE_ESP32) && !defined(IR_TIMER_USE_CURIE)) // Disable the Timer2 Interrupt (which is used for receiving IR) TIMER_DISABLE_INTR; //Timer2 Overflow Interrupt