From 38b91aa1c2638eb7b688a8b6b701645aeb26980e Mon Sep 17 00:00:00 2001 From: Stefanos Boglou Date: Sun, 11 Oct 2015 21:56:32 +0300 Subject: [PATCH] First wave of Atmel Studio compatibility modifications. Dropped support for Arduino versions 0.x . Does anyone still use those? IRsend does not work yet. Will fix at some point tho. --- AtmelStudioCom.cpp | 35 +++++++++++++++++++++++++++++++++++ IRremote.cpp | 12 +++++++++++- IRremote.h | 21 +++++++++++++++++++++ IRremoteInt.h | 23 ++++++++++++++++++----- irRecv.cpp | 34 ++++++++++++++++++++++++++++++++-- irSend.cpp | 4 ++++ 6 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 AtmelStudioCom.cpp diff --git a/AtmelStudioCom.cpp b/AtmelStudioCom.cpp new file mode 100644 index 000000000..de10d6496 --- /dev/null +++ b/AtmelStudioCom.cpp @@ -0,0 +1,35 @@ +#include "IRremote.h" + +/* + * AtmelStudioCom.cpp + * + * Created: 11/10/2015 7:54:03 μμ + * Author: VFXCode + * + * This makes a few functions to make IRremote + * compatible with Atmel Studio. + * Tested on Atmel Studio 7. + * + */ +#ifdef ATMEL_STUDIO +void IRdigitalWrite(volatile uint8_t *port, uint8_t portpin, uint8_t set) { + if (set) { + *port |= (1<>portpin)&0x01); +} + +#endif \ No newline at end of file diff --git a/IRremote.cpp b/IRremote.cpp index 466a4fb80..064d1c7b3 100644 --- a/IRremote.cpp +++ b/IRremote.cpp @@ -109,8 +109,11 @@ ISR (TIMER_INTR_NAME) // Read if IR Receiver -> SPACE [xmt LED off] or a MARK [xmt LED on] // digitalRead() is very slow. Optimisation is possible, but makes the code unportable +#ifdef ATMEL_STUDIO + uint8_t irdata = IRdigitalRead(irparams.recvport, irparams.recvpin); +#else uint8_t irdata = (uint8_t)digitalRead(irparams.recvpin); - +#endif irparams.timer++; // One more 50uS tick if (irparams.rawlen >= RAWBUF) irparams.rcvstate = STATE_OVERFLOW ; // Buffer overflow @@ -167,10 +170,17 @@ ISR (TIMER_INTR_NAME) // If requested, flash LED while receiving IR data if (irparams.blinkflag) { + if (irdata == MARK) +#ifdef ATMEL_STUDIO + IRdigitalWrite(irparams.blinkport, irparams.blinkpin, HIGH); // Turn user defined pin LED on + else + IRdigitalWrite(irparams.blinkport, irparams.blinkpin, LOW); // Turn user defined pin LED on +#else if (irparams.blinkpin) digitalWrite(irparams.blinkpin, HIGH); // Turn user defined pin LED on else BLINKLED_ON() ; // if no user defined LED pin, turn default LED pin for the hardware on else if (irparams.blinkpin) digitalWrite(irparams.blinkpin, LOW); // Turn user defined pin LED on else BLINKLED_OFF() ; // if no user defined LED pin, turn default LED pin for the hardware on +#endif } } diff --git a/IRremote.h b/IRremote.h index 86815b4fb..a896d2046 100644 --- a/IRremote.h +++ b/IRremote.h @@ -121,7 +121,9 @@ decode_type_t; //------------------------------------------------------------------------------ // Set DEBUG to 1 for lots of lovely debug output // +#ifndef DEBUG #define DEBUG 0 +#endif //------------------------------------------------------------------------------ // Debug directives @@ -167,8 +169,13 @@ class decode_results class IRrecv { public: +#ifdef ATMEL_STUDIO + IRrecv (volatile uint8_t *recvport ,int recvpin); + IRrecv (volatile uint8_t *recvport, int recvpin,volatile uint8_t *blinkport, int blinkpin); +#else IRrecv (int recvpin) ; IRrecv (int recvpin, int blinkpin); +#endif void blink13 (int blinkflag) ; int decode (decode_results *results) ; @@ -329,4 +336,18 @@ class IRsend # endif } ; +#ifdef ATMEL_STUDIO +#define INPUT 0 +#define OUTPUT 1 +#define LOW 0 +#define HIGH 1 + +#define delay(x) _delay_ms(x) + +void IRdigitalWrite(volatile uint8_t *port, uint8_t portpin, uint8_t set); +void IRpinMode(volatile uint8_t *port, uint8_t portpin, uint8_t set); +uint8_t IRdigitalRead(volatile uint8_t *port, uint8_t portpin); +#endif + + #endif diff --git a/IRremoteInt.h b/IRremoteInt.h index 125eb7205..46f430698 100644 --- a/IRremoteInt.h +++ b/IRremoteInt.h @@ -23,9 +23,10 @@ #if defined(ARDUINO) && (ARDUINO >= 100) # include #else -# if !defined(IRPRONTO) -# include -# endif +# define ATMEL_STUDIO +# include +# include +# include #endif //------------------------------------------------------------------------------ @@ -46,7 +47,13 @@ typedef struct { // The fields are ordered to reduce memory over caused by struct-padding uint8_t rcvstate; // State Machine state +#ifdef ATMEL_STUDIO + volatile uint8_t *recvport; +#endif uint8_t recvpin; // Pin connected to IR data from detector +#ifdef ATMEL_STUDIO + volatile uint8_t *blinkport; +#endif uint8_t blinkpin; uint8_t blinkflag; // true -> enable blinking of pin on IR processing uint8_t rawlen; // counter of entries in rawbuf @@ -72,6 +79,7 @@ EXTERN volatile irparams_t irparams; // Defines for blinking the LED // + #if defined(CORE_LED0_PIN) # define BLINKLED CORE_LED0_PIN # define BLINKLED_ON() (digitalWrite(CORE_LED0_PIN, HIGH)) @@ -87,10 +95,15 @@ EXTERN volatile irparams_t irparams; # define BLINKLED_ON() (PORTD |= B00000001) # define BLINKLED_OFF() (PORTD &= B11111110) -#else +#elif !defined(ATMEL_STUDIO) # define BLINKLED 13 - #define BLINKLED_ON() (PORTB |= B00100000) +# define BLINKLED_ON() (PORTB |= B00100000) # define BLINKLED_OFF() (PORTB &= B11011111) + +#else +# define BLINKLED +# define BLINKLED_ON() +# define BLINKLED_OFF() #endif //------------------------------------------------------------------------------ diff --git a/irRecv.cpp b/irRecv.cpp index a3ff452e0..e92d73ee2 100644 --- a/irRecv.cpp +++ b/irRecv.cpp @@ -91,6 +91,27 @@ int IRrecv::decode (decode_results *results) } //+============================================================================= +#ifdef ATMEL_STUDIO +IRrecv::IRrecv (volatile uint8_t *recvport ,int recvpin) +{ + irparams.recvpin = recvpin; + irparams.recvport = recvport; + irparams.blinkflag = 0; +} + +IRrecv::IRrecv (volatile uint8_t *recvport, int recvpin,volatile uint8_t *blinkport, int blinkpin) +{ + irparams.recvpin = recvpin; + irparams.recvport = recvport; + irparams.blinkpin = blinkpin; + irparams.blinkport = blinkport; + IRpinMode(blinkport,blinkpin, OUTPUT); + irparams.blinkflag = 0; +} + + + +#else IRrecv::IRrecv (int recvpin) { irparams.recvpin = recvpin; @@ -104,7 +125,7 @@ IRrecv::IRrecv (int recvpin, int blinkpin) pinMode(blinkpin, OUTPUT); irparams.blinkflag = 0; } - +#endif //+============================================================================= @@ -131,7 +152,11 @@ void IRrecv::enableIRIn ( ) irparams.rawlen = 0; // Set pin modes +#ifdef ATMEL_STUDIO + IRpinMode(irparams.recvport,irparams.recvpin, INPUT); +#else pinMode(irparams.recvpin, INPUT); +#endif } //+============================================================================= @@ -139,8 +164,13 @@ void IRrecv::enableIRIn ( ) // void IRrecv::blink13 (int blinkflag) { +#ifdef ATMEL_STUDIO + irparams.blinkflag = 0; +#pragma message "BLINK13 NOT IMPLIMENTED IN ATMEL STUDIO" +#else irparams.blinkflag = blinkflag; if (blinkflag) pinMode(BLINKLED, OUTPUT) ; +#endif } //+============================================================================= @@ -190,7 +220,7 @@ int IRrecv::compare (unsigned int oldval, unsigned int newval) // This isn't a "real" decoding, just an arbitrary value. // #define FNV_PRIME_32 16777619 -#define FNV_BASIS_32 2166136261 +#define FNV_BASIS_32 2166136261LL long IRrecv::decodeHash (decode_results *results) { diff --git a/irSend.cpp b/irSend.cpp index 1340e6390..8bc0887fa 100644 --- a/irSend.cpp +++ b/irSend.cpp @@ -1,6 +1,9 @@ #include "IRremote.h" #include "IRremoteInt.h" +#ifdef ATMEL_STUDIO +#pragma message "IRsend not implemented in Atmel Studio" +#else //+============================================================================= void IRsend::sendRaw (unsigned int buf[], unsigned int len, unsigned int hz) { @@ -85,3 +88,4 @@ void IRsend::custom_delay_usec(unsigned long uSecs) { //} } +#endif \ No newline at end of file