18 Commits

Author SHA1 Message Date
Rafi Khan
742f72fd0a Merge branch 'beta' of https://github.com/z3t0/Arduino-IRremote into beta 2017-09-23 23:16:52 -04:00
Rafi Khan
3ab30887f4 Merge branch 'LarsWH-master' into beta 2017-09-23 23:15:34 -04:00
Rafi Khan
d2939e2366 Updated README.md for API doc. (#515)
Credits: @bengtmartensson
2017-09-06 20:59:17 -06:00
Bengt Martensson
c6a2fcd8c9 Updated README.md for API doc. 2017-08-27 13:41:28 +02:00
Bengt Martensson
e206e122e5 Doxygen API documentation in the sense of #461 (#512)
* new file: Doxyfile; #461.

* Doxygen related documentation to two files. (Not complete.) #461.
2017-08-23 13:57:05 -06:00
Rafi Khan
5bbd55c650 Fix #510 2017-08-22 15:47:20 -06:00
Bengt Martensson
24dd940107 Moving private includes to sub-directory, #464 (#507)
* Add missing "paragraph" to library.properties.

* Move not-to-be-exported includes to subdirectory.
Remove #include "IRremoteInt.h" from a number of files since it
now does not work any more, and since IRremote.h #includes it already.
This resolves #464.

* Remove #include <IRremoteInt.h> from examples, too.

* Make ir_Lego_PF_BitStreamEncoder.h exported (again).

* Revoked fe24095 (paragraph) to keep 1-1 correspondance to #464.
2017-08-20 15:49:57 -06:00
Bengt Martensson
7245efd2f5 Fix some minor problems in boarddefs.h and IRremote.cpp (#505)
* Removed some trailing spaces in IRremote.cpp.

* IRremote.cpp: fix some compiler warnings (-Wall -Wextra).
Remark: braces necessitated by the macro nature of DBG_PRINTLN.

* boarddefs.h: removed spurious #. Nuked trailing spaces.

Credits: bengtmartensson
2017-08-17 17:32:01 -06:00
Rafi Khan
4eb95a3272 Revert "Removed blinking led"
This reverts commit a406f3b9f9.
2017-08-14 17:12:02 -06:00
Rafi Khan
542516f116 Revert "Removed pronto "protocol""
This reverts commit 563c82c6c4.
2017-08-13 12:03:54 -06:00
Rafi Khan
563c82c6c4 Removed pronto "protocol"
Fixes #466
2017-08-13 11:46:58 -06:00
Rafi Khan
a406f3b9f9 Removed blinking led
It is difficult to maintain this over different architectures and also
not entirely that useful.

Fixes #462
2017-08-13 11:43:32 -06:00
Rafi Khan
31968a4875 Removed redundant preprocessor directives
In the newer versions of the IDE it is sufficient to simply include
the Arduino.h header file.

Fixes #463
2017-08-13 11:30:06 -06:00
Rafi Khan
635e8a923d Restructuring directory as per #464 2017-08-13 11:19:20 -06:00
Rafi Khan
b0d15b6020 Modified library.json 2017-08-13 11:05:50 -06:00
Rafi Khan
622e28bf69 Update library.properties 2017-08-13 11:05:12 -06:00
Rafi Khan
e1768b4deb Added changelog info 2017-08-10 17:01:44 -06:00
Rafi Khan
679348568d merge #437 2017-08-10 16:57:54 -06:00
36 changed files with 2903 additions and 398 deletions

View File

@@ -18,5 +18,7 @@ These are the active contributors of this project that you may contact if there
- [philipphenkel](https://github.com/philipphenkel): Active Contributor - [philipphenkel](https://github.com/philipphenkel): Active Contributor
- [MCUdude](https://github.com/MCUdude): Contributor - [MCUdude](https://github.com/MCUdude): Contributor
- [marcmerlin](https://github.com/marcmerlin): Contributor (ESP32 port) - [marcmerlin](https://github.com/marcmerlin): Contributor (ESP32 port)
- [bengtmartensson](https://github.com/bengtmartensson): Active Contributor
- [MrBryonMiller](https://github.com/MrBryonMiller): Contributor
Note: This list is being updated constantly so please let [z3t0](https://github.com/z3t0) know if you have been missed. Note: This list is being updated constantly so please let [z3t0](https://github.com/z3t0) know if you have been missed.

2417
Doxyfile Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@ This library enables you to send and receive using infra-red signals on an Ardui
Tutorials and more information will be made available on [the official homepage](http://z3t0.github.io/Arduino-IRremote/). Tutorials and more information will be made available on [the official homepage](http://z3t0.github.io/Arduino-IRremote/).
## Version - 2.2.3 ## Version - 2.5.0b
## Installation ## Installation
1. Navigate to the [Releases](https://github.com/z3t0/Arduino-IRremote/releases) page. 1. Navigate to the [Releases](https://github.com/z3t0/Arduino-IRremote/releases) page.
@@ -68,6 +68,20 @@ The table above lists the currently supported timers and corresponding send pins
## Usage ## Usage
- TODO (Check examples for now) - TODO (Check examples for now)
## API documentation
This project documents the library API using [Doxygen](http://www.doxygen.org).
It is planned to make generated and up-to-date API documentation available online.
To generate the API documentation,
Doxygen, as well as [Graphviz](http://www.graphviz.org/) should be installed.
(Note that on Windows, it may be necessary to add the Graphviz binary directory
(something like `C:\Program Files\Graphviz2.38\bin`)
to the `PATH` variable manually.)
With Doxygen and Graphviz installed, issue the command
`doxygen` from the command line in the main project directory, which will
generate the API documentation in HTML format.
The just generated `api-doc/index.html` can now be opened in a browser.
## Contributing ## Contributing
If you want to contribute to this project: If you want to contribute to this project:
- Report bugs and errors - Report bugs and errors

View File

@@ -1,240 +0,0 @@
{
"auto_complete":
{
"selected_items":
[
[
"vb",
"vboMatrix"
]
]
},
"buffers":
[
],
"build_system": "",
"build_system_choices":
[
],
"build_varint": "",
"command_palette":
{
"height": 275.0,
"last_filter": "blame",
"selected_items":
[
[
"blame",
"Git: Blame"
],
[
"install",
"Package Control: Install Package"
],
[
"diff",
"Git: Diff Current File"
],
[
"js",
"Set Syntax: JavaScript"
],
[
"i",
"Package Control: Install Package"
],
[
"instal",
"Package Control: Install Package"
]
],
"width": 510.0
},
"console":
{
"height": 126.0,
"history":
[
"import urllib.request,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa1548d1514676163dafc88'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)"
]
},
"distraction_free":
{
"menu_visible": true,
"show_minimap": false,
"show_open_files": false,
"show_tabs": false,
"side_bar_visible": false,
"status_bar_visible": false
},
"expanded_folders":
[
"/C/Users/Rafi Khan/Documents/Arduino/libraries/Arduino-IRremote"
],
"file_history":
[
"/C/Users/Rafi Khan/Documents/Arduino/libraries/Arduino-IRremote/changelog.md",
"/C/Users/Rafi Khan/Documents/Development/Arduino-IRremote/arduino-irremote.sublime-project",
"/C/Users/Rafi Khan/Documents/Development/Arduino-IRremote/.gitignore",
"/C/Users/Rafi Khan/Documents/Development/magic/README.md",
"/C/Users/Rafi Khan/Documents/Development/magic/shader.frag",
"/C/Users/Rafi Khan/Documents/Development/magic/package.json",
"/C/Users/Rafi Khan/Documents/Development/magic/block.js",
"/C/Users/Rafi Khan/Documents/Development/magic/chunker.js",
"/C/Users/Rafi Khan/Documents/Development/magic/index.js",
"/C/Users/Rafi Khan/Documents/Development/magic/blocks",
"/C/Users/Rafi Khan/AppData/Roaming/Sublime Text 3/Packages/User/Preferences.sublime-settings",
"/C/Users/Rafi Khan/Documents/Development/magic/shader.vert",
"/C/Users/Rafi Khan/Documents/Development/magic/magic.sublime-project",
"/C/Users/Rafi Khan/Documents/Development/magic/node_modules/browserify/node_modules/syntax-error/node_modules/acorn/.tern-project",
"/C/Users/Rafi Khan/OneDrive/Documents/School-RafiKhan/Grade 11/CS30/Python/supermarket.py",
"/C/Users/Rafi Khan/OneDrive/Documents/School-RafiKhan/Grade 11/CS30/Python/takingavacation.py",
"/C/Users/Rafi Khan/OneDrive/Documents/School-RafiKhan/Grade 11/CS30/Python/TipCalculator.py",
"/C/Users/Rafi Khan/OneDrive/Documents/School-RafiKhan/Grade 11/CS30/Python/battleship.py",
"/C/Users/Rafi Khan/OneDrive/Documents/School-RafiKhan/Grade 11/CS30/Python/exam.py",
"/C/Users/Rafi Khan/OneDrive/Documents/School-RafiKhan/Grade 11/CS30/Python/pyglatin.py",
"/C/Users/Rafi Khan/OneDrive/Documents/School-RafiKhan/Grade 11/CS30/Python/student.py"
],
"find":
{
"height": 28.0
},
"find_in_files":
{
"height": 0.0,
"where_history":
[
]
},
"find_state":
{
"case_sensitive": false,
"find_history":
[
"i",
"Direction",
";",
";\n",
"north",
"cubeMatrix",
")\n",
"vec3.set",
"f",
";",
"();\n",
"render",
"this",
"y"
],
"highlight": true,
"in_selection": false,
"preserve_case": false,
"regex": false,
"replace_history":
[
],
"reverse": false,
"show_context": true,
"use_buffer2": true,
"whole_word": false,
"wrap": true
},
"groups":
[
{
"sheets":
[
]
}
],
"incremental_find":
{
"height": 28.0
},
"input":
{
"height": 66.0
},
"layout":
{
"cells":
[
[
0,
0,
1,
1
]
],
"cols":
[
0.0,
1.0
],
"rows":
[
0.0,
1.0
]
},
"menu_visible": true,
"output.find_results":
{
"height": 0.0
},
"pinned_build_system": "",
"project": "arduino-irremote.sublime-project",
"replace":
{
"height": 52.0
},
"save_all_on_build": true,
"select_file":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
[
"json",
"package.json"
],
[
"inde",
"index.js"
]
],
"width": 0.0
},
"select_project":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"select_symbol":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"selected_group": 0,
"settings":
{
},
"show_minimap": true,
"show_open_files": false,
"show_tabs": true,
"side_bar_visible": true,
"side_bar_width": 150.0,
"status_bar_visible": true,
"template_settings":
{
}
}

View File

@@ -1,6 +1,9 @@
## 2.4.3 ## 2.5.0
- Added Philips Extended RC-5 protocol support [PR #522] (https://github.com/z3t0/Arduino-IRremote/pull/522) - Added Philips Extended RC-5 protocol support [PR #522] (https://github.com/z3t0/Arduino-IRremote/pull/522)
## 2.4.0 - 2017/08/10
- Cleanup of hardware dependencies. Merge in SAM support [PR #437](https://github.com/z3t0/Arduino-IRremote/pull/437)
## 2.3.3 - 2017/03/31 ## 2.3.3 - 2017/03/31
- Added ESP32 IR receive support [PR #427](https://github.com/z3t0/Arduino-IRremote/pull/425) - Added ESP32 IR receive support [PR #427](https://github.com/z3t0/Arduino-IRremote/pull/425)

View File

@@ -79,7 +79,7 @@ void dumpTIMER() {
void dumpTimerPin() { void dumpTimerPin() {
Serial.print(F("IR Tx Pin: ")); Serial.print(F("IR Tx Pin: "));
Serial.println(TIMER_PWM_PIN); Serial.println(SEND_PIN);
} }
void dumpClock() { void dumpClock() {

View File

@@ -10,7 +10,6 @@
*/ */
#include <IRremote.h> #include <IRremote.h>
#include <IRremoteInt.h>
// Dumps out the decode_results structure. // Dumps out the decode_results structure.
// Call this after IRrecv::decode() // Call this after IRrecv::decode()

View File

@@ -4,7 +4,6 @@
*/ */
#include <IRremote.h> #include <IRremote.h>
#include <IRremoteInt.h>
IRsend irsend; IRsend irsend;

View File

@@ -7,7 +7,7 @@
"type": "git", "type": "git",
"url": "https://github.com/z3t0/Arduino-IRremote.git" "url": "https://github.com/z3t0/Arduino-IRremote.git"
}, },
"version": "2.3.3", "version": "2.4.0",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "atmelavr", "platforms": "atmelavr",
"authors" : "authors" :

View File

@@ -1,9 +1,9 @@
name=IRremote name=IRremote
version=2.2.3 version=2.4.0
author=shirriff author=shirriff, z3t0
maintainer=shirriff maintainer=z3t0
sentence=Send and receive infrared signals with multiple protocols sentence=Send and receive infrared signals with multiple protocols
paragraph=Send and receive infrared signals with multiple protocols paragraph=Find more information at https://github.com/z3t0/Arduino-IRremote
category=Signal Input/Output category=Communication
url=https://github.com/shirriff/Arduino-IRremote.git url=https://github.com/z3t0/Arduino-IRremote
architectures=* architectures=*

View File

@@ -21,10 +21,9 @@
// Defining IR_GLOBAL here allows us to declare the instantiation of global variables // Defining IR_GLOBAL here allows us to declare the instantiation of global variables
#define IR_GLOBAL #define IR_GLOBAL
#include "IRremote.h" #include "IRremote.h"
# include "IRremoteInt.h"
#undef IR_GLOBAL #undef IR_GLOBAL
#ifndef IR_TIMER_USE_ESP32 #ifdef HAS_AVR_INTERRUPT_H
#include <avr/interrupt.h> #include <avr/interrupt.h>
#endif #endif
@@ -52,10 +51,11 @@ int MATCH (int measured, int desired)
DBG_PRINT(TICKS_HIGH(desired), DEC); DBG_PRINT(TICKS_HIGH(desired), DEC);
bool passed = ((measured >= TICKS_LOW(desired)) && (measured <= TICKS_HIGH(desired))); bool passed = ((measured >= TICKS_LOW(desired)) && (measured <= TICKS_HIGH(desired)));
if (passed) if (passed) {
DBG_PRINTLN(F("?; passed")); DBG_PRINTLN(F("?; passed"));
else } else {
DBG_PRINTLN(F("?; FAILED")); DBG_PRINTLN(F("?; FAILED"));
}
return passed; return passed;
} }
@@ -78,10 +78,11 @@ int MATCH_MARK (int measured_ticks, int desired_us)
bool passed = ((measured_ticks >= TICKS_LOW (desired_us + MARK_EXCESS)) bool passed = ((measured_ticks >= TICKS_LOW (desired_us + MARK_EXCESS))
&& (measured_ticks <= TICKS_HIGH(desired_us + MARK_EXCESS))); && (measured_ticks <= TICKS_HIGH(desired_us + MARK_EXCESS)));
if (passed) if (passed) {
DBG_PRINTLN(F("?; passed")); DBG_PRINTLN(F("?; passed"));
else } else {
DBG_PRINTLN(F("?; FAILED")); DBG_PRINTLN(F("?; FAILED"));
}
return passed; return passed;
} }
@@ -104,10 +105,11 @@ int MATCH_SPACE (int measured_ticks, int desired_us)
bool passed = ((measured_ticks >= TICKS_LOW (desired_us - MARK_EXCESS)) bool passed = ((measured_ticks >= TICKS_LOW (desired_us - MARK_EXCESS))
&& (measured_ticks <= TICKS_HIGH(desired_us - MARK_EXCESS))); && (measured_ticks <= TICKS_HIGH(desired_us - MARK_EXCESS)));
if (passed) if (passed) {
DBG_PRINTLN(F("?; passed")); DBG_PRINTLN(F("?; passed"));
else } else {
DBG_PRINTLN(F("?; FAILED")); DBG_PRINTLN(F("?; FAILED"));
}
return passed; return passed;
} }
@@ -123,11 +125,7 @@ int MATCH_SPACE (int measured_ticks, int desired_us)
// As soon as first MARK arrives: // As soon as first MARK arrives:
// Gap width is recorded; Ready is cleared; New logging starts // Gap width is recorded; Ready is cleared; New logging starts
// //
#ifdef IR_TIMER_USE_ESP32
void IRTimer()
#else
ISR (TIMER_INTR_NAME) ISR (TIMER_INTR_NAME)
#endif
{ {
TIMER_RESET; TIMER_RESET;
@@ -189,6 +187,7 @@ ISR (TIMER_INTR_NAME)
break; break;
} }
#ifdef BLINKLED
// If requested, flash LED while receiving IR data // If requested, flash LED while receiving IR data
if (irparams.blinkflag) { if (irparams.blinkflag) {
if (irdata == MARK) if (irdata == MARK)
@@ -197,4 +196,5 @@ ISR (TIMER_INTR_NAME)
else if (irparams.blinkpin) digitalWrite(irparams.blinkpin, LOW); // Turn user defined pin LED 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 else BLINKLED_OFF() ; // if no user defined LED pin, turn default LED pin for the hardware on
} }
#endif // BLINKLED
} }

View File

@@ -1,3 +1,7 @@
/**
* @file IRremote.h
* @brief Public API to the library.
*/
//****************************************************************************** //******************************************************************************
// IRremote // IRremote
@@ -21,7 +25,7 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// The ISR header contains several useful macros the user may wish to use // The ISR header contains several useful macros the user may wish to use
// //
#include "IRremoteInt.h" #include "private/IRremoteInt.h"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Supported IR protocols // Supported IR protocols
@@ -94,10 +98,10 @@
#define PRONTO_FALLBACK true #define PRONTO_FALLBACK true
#define PRONTO_NOFALLBACK false #define PRONTO_NOFALLBACK false
//------------------------------------------------------------------------------ /**
// An enumerated list of all supported formats * An enum consisting of all supported formats.
// You do NOT need to remove entries from this list when disabling protocols! * You do NOT need to remove entries from this list when disabling protocols!
// */
typedef typedef
enum { enum {
UNKNOWN = -1, UNKNOWN = -1,
@@ -122,9 +126,9 @@ typedef
} }
decode_type_t; decode_type_t;
//------------------------------------------------------------------------------ /**
// Set DEBUG to 1 for lots of lovely debug output * Set DEBUG to 1 for lots of lovely debug output.
// */
#define DEBUG 0 #define DEBUG 0
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -134,7 +138,13 @@ decode_type_t;
# define DBG_PRINT(...) Serial.print(__VA_ARGS__) # define DBG_PRINT(...) Serial.print(__VA_ARGS__)
# define DBG_PRINTLN(...) Serial.println(__VA_ARGS__) # define DBG_PRINTLN(...) Serial.println(__VA_ARGS__)
#else #else
/**
* If DEBUG, print the arguments, otherwise do nothing.
*/
# define DBG_PRINT(...) # define DBG_PRINT(...)
/**
* If DEBUG, print the arguments as a line, otherwise do nothing.
*/
# define DBG_PRINTLN(...) # define DBG_PRINTLN(...)
#endif #endif
@@ -145,39 +155,71 @@ int MATCH (int measured, int desired) ;
int MATCH_MARK (int measured_ticks, int desired_us) ; int MATCH_MARK (int measured_ticks, int desired_us) ;
int MATCH_SPACE (int measured_ticks, int desired_us) ; int MATCH_SPACE (int measured_ticks, int desired_us) ;
//------------------------------------------------------------------------------ /**
// Results returned from the decoder * Results returned from the decoder
// */
class decode_results class decode_results
{ {
public: public:
decode_type_t decode_type; // UNKNOWN, NEC, SONY, RC5, ... decode_type_t decode_type; ///< UNKNOWN, NEC, SONY, RC5, ...
unsigned int address; // Used by Panasonic & Sharp [16-bits] unsigned int address; ///< Used by Panasonic & Sharp [16-bits]
unsigned long value; // Decoded value [max 32-bits] unsigned long value; ///< Decoded value [max 32-bits]
int bits; // Number of bits in decoded value int bits; ///< Number of bits in decoded value
volatile unsigned int *rawbuf; // Raw intervals in 50uS ticks volatile unsigned int *rawbuf; ///< Raw intervals in 50uS ticks
int rawlen; // Number of records in rawbuf int rawlen; ///< Number of records in rawbuf
int overflow; // true iff IR raw code too long int overflow; ///< true iff IR raw code too long
}; };
//------------------------------------------------------------------------------ /**
// Decoded value for NEC when a repeat code is received * Decoded value for NEC when a repeat code is received
// */
#define REPEAT 0xFFFFFFFF #define REPEAT 0xFFFFFFFF
//------------------------------------------------------------------------------ /**
// Main class for receiving IR * Main class for receiving IR
// */
class IRrecv class IRrecv
{ {
public: public:
/**
* Instantiate the IRrecv class. Multiple instantiation is not supported.
* @param recvpin Arduino pin to use. No sanity check is made.
*/
IRrecv (int recvpin) ; IRrecv (int recvpin) ;
/**
* Instantiate the IRrecv class. Multiple instantiation is not supported.
* @param recvpin Arduino pin to use, where a demodulating IR receiver is connected.
* @param blinkpin pin to blink when receiving IR. Not supported by all hardware. No sanity check is made.
*/
IRrecv (int recvpin, int blinkpin); IRrecv (int recvpin, int blinkpin);
/**
* TODO: Why is this public???
* @param blinkflag
*/
void blink13 (int blinkflag) ; void blink13 (int blinkflag) ;
/**
* Attempt to decode the recently receive IR signal
* @param results decode_results instance returning the decode, if any.
* @return success of operation. TODO: convert to bool
*/
int decode (decode_results *results) ; int decode (decode_results *results) ;
/**
* Enable IR reception.
*/
void enableIRIn ( ) ; void enableIRIn ( ) ;
/**
* Returns status of reception
* @return true if no reception is on-going.
*/
bool isIdle ( ) ; bool isIdle ( ) ;
/**
* Called to re-enable IR reception.
*/
void resume ( ) ; void resume ( ) ;
private: private:
@@ -186,10 +228,17 @@ class IRrecv
//...................................................................... //......................................................................
# if (DECODE_RC5 || DECODE_RC6) # if (DECODE_RC5 || DECODE_RC6)
// This helper function is shared by RC5 and RC6 /**
* This helper function is shared by RC5 and RC6
*/
int getRClevel (decode_results *results, int *offset, int *used, int t1) ; int getRClevel (decode_results *results, int *offset, int *used, int t1) ;
# endif # endif
# if DECODE_RC5 # if DECODE_RC5
/**
* Try to decode the recently received IR signal as an RC5 signal-
* @param results decode_results instance returning the decode, if any.
* @return Success of the operation.
*/
bool decodeRC5 (decode_results *results) ; bool decodeRC5 (decode_results *results) ;
# endif # endif
# if DECODE_RC6 # if DECODE_RC6
@@ -253,13 +302,24 @@ class IRrecv
# endif # endif
} ; } ;
//------------------------------------------------------------------------------ /**
// Main class for sending IR * Main class for sending IR
// */
class IRsend class IRsend
{ {
public: public:
IRsend () { } #ifdef USE_SOFT_CARRIER
IRsend(int pin = SEND_PIN)
{
sendPin = pin;
}
#else
IRsend()
{
}
#endif
void custom_delay_usec (unsigned long uSecs); void custom_delay_usec (unsigned long uSecs);
void enableIROut (int khz) ; void enableIROut (int khz) ;
@@ -340,6 +400,20 @@ class IRsend
# if SEND_LEGO_PF # if SEND_LEGO_PF
void sendLegoPowerFunctions (uint16_t data, bool repeat = true) ; void sendLegoPowerFunctions (uint16_t data, bool repeat = true) ;
# endif # endif
#ifdef USE_SOFT_CARRIER
private:
int sendPin;
unsigned int periodTime;
unsigned int periodOnTime;
void sleepMicros(unsigned long us);
void sleepUntilMicros(unsigned long targetTime);
#else
const int sendPin = SEND_PIN;
#endif
} ; } ;
#endif #endif

38
src/esp32.cpp Normal file
View File

@@ -0,0 +1,38 @@
#ifdef ESP32
// This file contains functions specific to the ESP32.
#include "IRremote.h"
// "Idiot check"
#ifdef USE_DEFAULT_ENABLE_IR_IN
#error Must undef USE_DEFAULT_ENABLE_IR_IN
#endif
hw_timer_t *timer;
void IRTimer(); // defined in IRremote.cpp, masqueraded as ISR(TIMER_INTR_NAME)
//+=============================================================================
// initialization
//
void IRrecv::enableIRIn ( )
{
// Interrupt Service Routine - Fires every 50uS
// 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);
// Initialize state machine variables
irparams.rcvstate = STATE_IDLE;
irparams.rawlen = 0;
// Set pin modes
pinMode(irparams.recvpin, INPUT);
}
#endif // ESP32

View File

@@ -1,10 +1,4 @@
#include "IRremote.h" #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 // Decodes the received IR message
@@ -120,19 +114,10 @@ IRrecv::IRrecv (int recvpin, int blinkpin)
//+============================================================================= //+=============================================================================
// initialization // initialization
// //
#ifdef USE_DEFAULT_ENABLE_IR_IN
void IRrecv::enableIRIn ( ) void IRrecv::enableIRIn ( )
{ {
// Interrupt Service Routine - Fires every 50uS // 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(); cli();
// Setup pulse clock timer interrupt // Setup pulse clock timer interrupt
// Prescale /8 (16M/8 = 0.5 microseconds per tick) // Prescale /8 (16M/8 = 0.5 microseconds per tick)
@@ -146,7 +131,6 @@ void IRrecv::enableIRIn ( )
TIMER_RESET; TIMER_RESET;
sei(); // enable interrupts sei(); // enable interrupts
#endif
// Initialize state machine variables // Initialize state machine variables
irparams.rcvstate = STATE_IDLE; irparams.rcvstate = STATE_IDLE;
@@ -155,14 +139,17 @@ void IRrecv::enableIRIn ( )
// Set pin modes // Set pin modes
pinMode(irparams.recvpin, INPUT); pinMode(irparams.recvpin, INPUT);
} }
#endif // USE_DEFAULT_ENABLE_IR_IN
//+============================================================================= //+=============================================================================
// Enable/disable blinking of pin 13 on IR processing // Enable/disable blinking of pin 13 on IR processing
// //
void IRrecv::blink13 (int blinkflag) void IRrecv::blink13 (int blinkflag)
{ {
#ifdef BLINKLED
irparams.blinkflag = blinkflag; irparams.blinkflag = blinkflag;
if (blinkflag) pinMode(BLINKLED, OUTPUT) ; if (blinkflag) pinMode(BLINKLED, OUTPUT) ;
#endif
} }
//+============================================================================= //+=============================================================================

View File

@@ -1,6 +1,6 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
#ifdef SENDING_SUPPORTED
//+============================================================================= //+=============================================================================
void IRsend::sendRaw (const unsigned int buf[], unsigned int len, unsigned int hz) void IRsend::sendRaw (const unsigned int buf[], unsigned int len, unsigned int hz)
{ {
@@ -15,14 +15,59 @@ void IRsend::sendRaw (const unsigned int buf[], unsigned int len, unsigned in
space(0); // Always end with the LED off space(0); // Always end with the LED off
} }
#ifdef USE_SOFT_CARRIER
void inline IRsend::sleepMicros(unsigned long us)
{
#ifdef USE_SPIN_WAIT
sleepUntilMicros(micros() + us);
#else
if (us > 0U) // Is this necessary? (Official docu https://www.arduino.cc/en/Reference/DelayMicroseconds does not tell.)
delayMicroseconds((unsigned int) us);
#endif
}
void inline IRsend::sleepUntilMicros(unsigned long targetTime)
{
#ifdef USE_SPIN_WAIT
while (micros() < targetTime)
;
#else
unsigned long now = micros();
if (now < targetTime)
sleepMicros(targetTime - now);
#endif
}
#endif // USE_SOFT_CARRIER
//+============================================================================= //+=============================================================================
// Sends an IR mark for the specified number of microseconds. // Sends an IR mark for the specified number of microseconds.
// The mark output is modulated at the PWM frequency. // The mark output is modulated at the PWM frequency.
// //
void IRsend::mark(unsigned int time) void IRsend::mark(unsigned int time)
{ {
#ifdef USE_SOFT_CARRIER
unsigned long start = micros();
unsigned long stop = start + time;
if (stop + periodTime < start)
// Counter wrap-around, happens very seldomly, but CAN happen.
// Just give up instead of possibly damaging the hardware.
return;
unsigned long nextPeriodEnding = start;
unsigned long now = micros();
while (now < stop) {
SENDPIN_ON(sendPin);
sleepMicros(periodOnTime);
SENDPIN_OFF(sendPin);
nextPeriodEnding += periodTime;
sleepUntilMicros(nextPeriodEnding);
now = micros();
}
#else
TIMER_ENABLE_PWM; // Enable pin 3 PWM output TIMER_ENABLE_PWM; // Enable pin 3 PWM output
if (time > 0) custom_delay_usec(time); if (time > 0) custom_delay_usec(time);
#endif
} }
//+============================================================================= //+=============================================================================
@@ -54,13 +99,16 @@ void IRsend::space (unsigned int time)
// //
void IRsend::enableIROut (int khz) void IRsend::enableIROut (int khz)
{ {
// FIXME: implement ESP32 support, see IR_TIMER_USE_ESP32 in boarddefs.h #ifdef USE_SOFT_CARRIER
#ifndef ESP32 periodTime = (1000U + khz/2) / khz; // = 1000/khz + 1/2 = round(1000.0/khz)
periodOnTime = periodTime * DUTY_CYCLE / 100U - PULSE_CORRECTION;
#endif
// Disable the Timer2 Interrupt (which is used for receiving IR) // Disable the Timer2 Interrupt (which is used for receiving IR)
TIMER_DISABLE_INTR; //Timer2 Overflow Interrupt TIMER_DISABLE_INTR; //Timer2 Overflow Interrupt
pinMode(TIMER_PWM_PIN, OUTPUT); pinMode(sendPin, OUTPUT);
digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low SENDPIN_OFF(sendPin); // When not sending, we want it low
// COM2A = 00: disconnect OC2A // COM2A = 00: disconnect OC2A
// COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted // COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted
@@ -68,7 +116,6 @@ void IRsend::enableIROut (int khz)
// CS2 = 000: no prescaling // CS2 = 000: no prescaling
// The top value for the timer. The modulation frequency will be SYSCLOCK / 2 / OCR2A. // The top value for the timer. The modulation frequency will be SYSCLOCK / 2 / OCR2A.
TIMER_CONFIG_KHZ(khz); TIMER_CONFIG_KHZ(khz);
#endif
} }
//+============================================================================= //+=============================================================================
@@ -88,3 +135,4 @@ void IRsend::custom_delay_usec(unsigned long uSecs) {
//} //}
} }
#endif // SENDING_SUPPORTED

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
//============================================================================== //==============================================================================
// AAA IIIII W W AAA // AAA IIIII W W AAA

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
// Reverse Engineered by looking at RAW dumps generated by IRremote // Reverse Engineered by looking at RAW dumps generated by IRremote

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
//============================================================================== //==============================================================================
// DDDD IIIII SSSS H H // DDDD IIIII SSSS H H

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
//============================================================================== //==============================================================================
// JJJJJ V V CCCC // JJJJJ V V CCCC

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
//============================================================================== //==============================================================================
// L GGGG // L GGGG

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
#include "ir_Lego_PF_BitStreamEncoder.h" #include "ir_Lego_PF_BitStreamEncoder.h"
//============================================================================== //==============================================================================

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
//============================================================================== //==============================================================================
// MMMMM IIIII TTTTT SSSS U U BBBB IIIII SSSS H H IIIII // MMMMM IIIII TTTTT SSSS U U BBBB IIIII SSSS H H IIIII

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
//============================================================================== //==============================================================================
// N N EEEEE CCCC // N N EEEEE CCCC

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
//============================================================================== //==============================================================================
// PPPP AAA N N AAA SSSS OOO N N IIIII CCCC // PPPP AAA N N AAA SSSS OOO N N IIIII CCCC

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
//+============================================================================= //+=============================================================================
// Gets one undecoded level at a time from the raw buffer. // Gets one undecoded level at a time from the raw buffer.

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
//============================================================================== //==============================================================================
// SSSS AAA MMM SSSS U U N N GGGG // SSSS AAA MMM SSSS U U N N GGGG

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
//============================================================================== //==============================================================================
// SSSS AAA N N Y Y OOO // SSSS AAA N N Y Y OOO

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
//============================================================================== //==============================================================================
// SSSS H H AAA RRRR PPPP // SSSS H H AAA RRRR PPPP

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
//============================================================================== //==============================================================================
// SSSS OOO N N Y Y // SSSS OOO N N Y Y

View File

@@ -92,7 +92,6 @@ Regards,
*/ */
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
//============================================================================== //==============================================================================
// //

View File

@@ -1,5 +1,4 @@
#include "IRremote.h" #include "IRremote.h"
#include "IRremoteInt.h"
//============================================================================== //==============================================================================
// W W H H Y Y N N TTTTT EEEEE RRRRR // W W H H Y Y N N TTTTT EEEEE RRRRR

View File

@@ -18,15 +18,9 @@
#define IRremoteint_h #define IRremoteint_h
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Include the right Arduino header // Include the Arduino header
// //
#if defined(ARDUINO) && (ARDUINO >= 100)
#include <Arduino.h> #include <Arduino.h>
#else
# if !defined(IRPRONTO)
# include <WProgram.h>
# endif
#endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// This handles definition and access to global variables // This handles definition and access to global variables
@@ -40,19 +34,22 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Information for the Interrupt Service Routine // Information for the Interrupt Service Routine
// //
#define RAWBUF 101 // Maximum length of raw duration buffer #define RAWBUF 101 ///< Maximum length of raw duration buffer. Must be odd.
/**
* This struct is used to communicate with the ISR (interrupt service routine).
*/
typedef typedef
struct { struct {
// The fields are ordered to reduce memory over caused by struct-padding // The fields are ordered to reduce memory over caused by struct-padding
uint8_t rcvstate; // State Machine state uint8_t rcvstate; ///< State Machine state
uint8_t recvpin; // Pin connected to IR data from detector uint8_t recvpin; ///< Pin connected to IR data from detector
uint8_t blinkpin; uint8_t blinkpin;
uint8_t blinkflag; // true -> enable blinking of pin on IR processing uint8_t blinkflag; ///< true -> enable blinking of pin on IR processing
uint8_t rawlen; // counter of entries in rawbuf uint8_t rawlen; ///< counter of entries in rawbuf
unsigned int timer; // State timer, counts 50uS ticks. unsigned int timer; ///< State timer, counts 50uS ticks.
unsigned int rawbuf[RAWBUF]; // raw data unsigned int rawbuf[RAWBUF]; ///< raw data
uint8_t overflow; // Raw buffer overflow occurred uint8_t overflow; ///< Raw buffer overflow occurred
} }
irparams_t; irparams_t;
@@ -63,9 +60,11 @@ irparams_t;
#define STATE_STOP 5 #define STATE_STOP 5
#define STATE_OVERFLOW 6 #define STATE_OVERFLOW 6
// Allow all parts of the code access to the ISR data /**
// NB. The data can be changed by the ISR at any time, even mid-function * Allow all parts of the code access to the ISR data
// Therefore we declare it as "volatile" to stop the compiler/CPU caching it * NB. The data can be changed by the ISR at any time, even mid-function
* Therefore we declare it as "volatile" to stop the compiler/CPU caching it
*/
EXTERN volatile irparams_t irparams; EXTERN volatile irparams_t irparams;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -85,8 +84,12 @@ EXTERN volatile irparams_t irparams;
// Pulse parameters in uSec // Pulse parameters in uSec
// //
// Due to sensor lag, when received, Marks tend to be 100us too long and /**
// Spaces tend to be 100us too short * When received, marks tend to be too long and
* spaces tend to be too short.
* To compensate for this, MARK_EXCESS is subtracted from all marks,
* and added to all spaces.
*/
#define MARK_EXCESS 100 #define MARK_EXCESS 100
// Upper and Lower percentage tolerances in measurements // Upper and Lower percentage tolerances in measurements

View File

@@ -20,6 +20,32 @@
#ifndef boarddefs_h #ifndef boarddefs_h
#define boarddefs_h #define boarddefs_h
// Define some defaults, that some boards may like to override
// (This is to avoid negative logic, ! DONT_... is just awkward.)
// This board has/needs the avr/interrupt.h
#define HAS_AVR_INTERRUPT_H
// Define if sending is supported
#define SENDING_SUPPORTED
// If defined, a standard enableIRIn function will be define.
// Undefine for boards supplying their own.
#define USE_DEFAULT_ENABLE_IR_IN
// Duty cycle in percent for sent signals. Presently takes effect only with USE_SOFT_CARRIER
#define DUTY_CYCLE 50
// If USE_SOFT_CARRIER, this amount (in micro seconds) is subtracted from the
// on-time of the pulses.
#define PULSE_CORRECTION 3
// digitalWrite is supposed to be slow. If this is an issue, define faster,
// board-dependent versions of these macros SENDPIN_ON(pin) and SENDPIN_OFF(pin).
// Portable, possibly slow, default definitions are given at the end of this file.
// If defining new versions, feel free to ignore the pin argument if it
// is not configurable on the current board.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Defines for blinking the LED // Defines for blinking the LED
// //
@@ -39,11 +65,31 @@
# define BLINKLED_ON() (PORTD |= B00000001) # define BLINKLED_ON() (PORTD |= B00000001)
# define BLINKLED_OFF() (PORTD &= B11111110) # define BLINKLED_OFF() (PORTD &= B11111110)
// No system LED on ESP32, disable blinking #elif defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD)
# define BLINKLED LED_BUILTIN
# define BLINKLED_ON() (digitalWrite(LED_BUILTIN, HIGH))
# define BLINKLED_OFF() (digitalWrite(LED_BUILTIN, LOW))
# define USE_SOFT_CARRIER
// Define to use spin wait instead of delayMicros()
//# define USE_SPIN_WAIT
# undef USE_DEFAULT_ENABLE_IR_IN
// The default pin used used for sending.
# define SEND_PIN 9
#elif defined(ESP32) #elif defined(ESP32)
# define BLINKLED 255 // No system LED on ESP32, disable blinking by NOT defining BLINKLED
# define BLINKLED_ON() 1
# define BLINKLED_OFF() 1 // avr/interrupt.h is not present
# undef HAS_AVR_INTERRUPT_H
// Sending not implemented
# undef SENDING_SUPPORTED
// Supply own enbleIRIn
# undef USE_DEFAULT_ENABLE_IR_IN
#else #else
# define BLINKLED 13 # define BLINKLED 13
# define BLINKLED_ON() (PORTB |= B00100000) # define BLINKLED_ON() (PORTB |= B00100000)
@@ -138,6 +184,10 @@
#elif defined(ESP32) #elif defined(ESP32)
#define IR_TIMER_USE_ESP32 #define IR_TIMER_USE_ESP32
#elif defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD)
#define TIMER_PRESCALER_DIV 64
#else #else
// Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc // Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc
// ATmega48, ATmega88, ATmega168, ATmega328 // ATmega48, ATmega88, ATmega168, ATmega328
@@ -190,17 +240,17 @@
//----------------- //-----------------
#if defined(CORE_OC2B_PIN) #if defined(CORE_OC2B_PIN)
# define TIMER_PWM_PIN CORE_OC2B_PIN // Teensy # define SEND_PIN CORE_OC2B_PIN // Teensy
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
# define TIMER_PWM_PIN 9 // Arduino Mega # define SEND_PIN 9 // Arduino Mega
#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ #elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \
|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \
|| defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \ || defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \
|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \ || defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \
|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega164P__)
# define TIMER_PWM_PIN 14 // MightyCore # define SEND_PIN 14 // MightyCore
#else #else
# define TIMER_PWM_PIN 3 // Arduino Duemilanove, Diecimila, LilyPad, etc # define SEND_PIN 3 // Arduino Duemilanove, Diecimila, LilyPad, etc
#endif // ATmega48, ATmega88, ATmega168, ATmega328 #endif // ATmega48, ATmega88, ATmega168, ATmega328
//--------------------------------------------------------- //---------------------------------------------------------
@@ -243,22 +293,22 @@
//----------------- //-----------------
#if defined(CORE_OC1A_PIN) #if defined(CORE_OC1A_PIN)
# define TIMER_PWM_PIN CORE_OC1A_PIN // Teensy # define SEND_PIN CORE_OC1A_PIN // Teensy
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
# define TIMER_PWM_PIN 11 // Arduino Mega # define SEND_PIN 11 // Arduino Mega
#elif defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) #elif defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__)
# define TIMER_PWM_PIN 13 // MegaCore # define SEND_PIN 13 // MegaCore
#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ #elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \
|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \
|| defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \ || defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \
|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \ || defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \
|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \ || defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \
|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) || defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__)
# define TIMER_PWM_PIN 13 // MightyCore # define SEND_PIN 13 // MightyCore
#elif defined(__AVR_ATtiny84__) #elif defined(__AVR_ATtiny84__)
# define TIMER_PWM_PIN 6 # define SEND_PIN 6
#else #else
# define TIMER_PWM_PIN 9 // Arduino Duemilanove, Diecimila, LilyPad, etc # define SEND_PIN 9 // Arduino Duemilanove, Diecimila, LilyPad, etc
#endif // ATmega48, ATmega88, ATmega168, ATmega328 #endif // ATmega48, ATmega88, ATmega168, ATmega328
//--------------------------------------------------------- //---------------------------------------------------------
@@ -290,11 +340,11 @@
//----------------- //-----------------
#if defined(CORE_OC3A_PIN) #if defined(CORE_OC3A_PIN)
# define TIMER_PWM_PIN CORE_OC3A_PIN // Teensy # define SEND_PIN CORE_OC3A_PIN // Teensy
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
# define TIMER_PWM_PIN 5 // Arduino Mega # define SEND_PIN 5 // Arduino Mega
#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) #elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)
# define TIMER_PWM_PIN 6 // MightyCore # define SEND_PIN 6 // MightyCore
#else #else
# error "Please add OC3A pin number here\n" # error "Please add OC3A pin number here\n"
#endif #endif
@@ -338,9 +388,9 @@
//----------------- //-----------------
#if defined(CORE_OC4A_PIN) #if defined(CORE_OC4A_PIN)
# define TIMER_PWM_PIN CORE_OC4A_PIN // Teensy # define SEND_PIN CORE_OC4A_PIN // Teensy
#elif defined(__AVR_ATmega32U4__) #elif defined(__AVR_ATmega32U4__)
# define TIMER_PWM_PIN 13 // Leonardo # define SEND_PIN 13 // Leonardo
#else #else
# error "Please add OC4A pin number here\n" # error "Please add OC4A pin number here\n"
#endif #endif
@@ -374,9 +424,9 @@
//----------------- //-----------------
#if defined(CORE_OC4A_PIN) #if defined(CORE_OC4A_PIN)
# define TIMER_PWM_PIN CORE_OC4A_PIN # define SEND_PIN CORE_OC4A_PIN
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
# define TIMER_PWM_PIN 6 // Arduino Mega # define SEND_PIN 6 // Arduino Mega
#else #else
# error "Please add OC4A pin number here\n" # error "Please add OC4A pin number here\n"
#endif #endif
@@ -410,9 +460,9 @@
//----------------- //-----------------
#if defined(CORE_OC5A_PIN) #if defined(CORE_OC5A_PIN)
# define TIMER_PWM_PIN CORE_OC5A_PIN # define SEND_PIN CORE_OC5A_PIN
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
# define TIMER_PWM_PIN 46 // Arduino Mega # define SEND_PIN 46 // Arduino Mega
#else #else
# error "Please add OC5A pin number here\n" # error "Please add OC5A pin number here\n"
#endif #endif
@@ -479,7 +529,7 @@
CMT_MSC = 0x03; \ CMT_MSC = 0x03; \
}) })
#define TIMER_PWM_PIN 5 #define SEND_PIN 5
// defines for TPM1 timer on Teensy-LC // defines for TPM1 timer on Teensy-LC
#elif defined(IR_USE_TIMER_TPM1) #elif defined(IR_USE_TIMER_TPM1)
@@ -509,7 +559,7 @@
FTM1_C0V = 0; \ FTM1_C0V = 0; \
FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_PS(0) | FTM_SC_TOF | FTM_SC_TOIE; \ FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_PS(0) | FTM_SC_TOF | FTM_SC_TOIE; \
}) })
#define TIMER_PWM_PIN 16 #define SEND_PIN 16
// defines for timer_tiny0 (8 bits) // defines for timer_tiny0 (8 bits)
#elif defined(IR_USE_TIMER_TINY0) #elif defined(IR_USE_TIMER_TINY0)
@@ -543,7 +593,7 @@
}) })
#endif #endif
#define TIMER_PWM_PIN 1 /* ATtiny85 */ #define SEND_PIN 1 /* ATtiny85 */
//--------------------------------------------------------- //---------------------------------------------------------
// ESP32 (ESP8266 should likely be added here too) // ESP32 (ESP8266 should likely be added here too)
@@ -560,12 +610,29 @@
// way to do this on ESP32 is using the RMT built in driver like in this incomplete library below // 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 // https://github.com/ExploreEmbedded/ESP32_RMT
#elif defined(IR_TIMER_USE_ESP32) #elif defined(IR_TIMER_USE_ESP32)
#define TIMER_RESET #define TIMER_RESET
#define TIMER_ENABLE_PWM
#define TIMER_DISABLE_PWM Serial.println("IRsend not implemented for ESP32 yet"); #ifdef ISR
#define TIMER_ENABLE_INTR # undef ISR
#define TIMER_DISABLE_INTR #endif
#define TIMER_INTR_NAME #define ISR(f) void IRTimer()
#elif defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD)
// use timer 3 hardcoded at this time
#define TIMER_RESET
#define TIMER_ENABLE_PWM // Not presently used
#define TIMER_DISABLE_PWM
#define TIMER_ENABLE_INTR NVIC_EnableIRQ(TC3_IRQn) // Not presently used
#define TIMER_DISABLE_INTR NVIC_DisableIRQ(TC3_IRQn)
#define TIMER_INTR_NAME TC3_Handler // Not presently used
#define TIMER_CONFIG_KHZ(f)
#ifdef ISR
# undef ISR
#endif
#define ISR(f) void irs()
//--------------------------------------------------------- //---------------------------------------------------------
// Unknown Timer // Unknown Timer
@@ -574,4 +641,13 @@
# error "Internal code configuration error, no known IR_USE_TIMER# defined\n" # error "Internal code configuration error, no known IR_USE_TIMER# defined\n"
#endif #endif
// Provide default definitions, portable but possibly slower than necessary.
#ifndef SENDPIN_ON
#define SENDPIN_ON(pin) digitalWrite(pin, HIGH)
#endif
#ifndef SENDPIN_OFF
#define SENDPIN_OFF(pin) digitalWrite(pin, LOW)
#endif
#endif // ! boarddefs_h #endif // ! boarddefs_h

101
src/sam.cpp Normal file
View File

@@ -0,0 +1,101 @@
// Support routines for SAM processor boards
#include "IRremote.h"
#if defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD)
// "Idiot check"
#ifdef USE_DEFAULT_ENABLE_IR_IN
#error Must undef USE_DEFAULT_ENABLE_IR_IN
#endif
//+=============================================================================
// ATSAMD Timer setup & IRQ functions
//
// following based on setup from GitHub jdneo/timerInterrupt.ino
static void setTimerFrequency(int frequencyHz)
{
int compareValue = (SYSCLOCK / (TIMER_PRESCALER_DIV * frequencyHz)) - 1;
//Serial.println(compareValue);
TcCount16* TC = (TcCount16*) TC3;
// Make sure the count is in a proportional position to where it was
// to prevent any jitter or disconnect when changing the compare value.
TC->COUNT.reg = map(TC->COUNT.reg, 0, TC->CC[0].reg, 0, compareValue);
TC->CC[0].reg = compareValue;
//Serial.print("COUNT.reg ");
//Serial.println(TC->COUNT.reg);
//Serial.print("CC[0].reg ");
//Serial.println(TC->CC[0].reg);
while (TC->STATUS.bit.SYNCBUSY == 1);
}
static void startTimer()
{
REG_GCLK_CLKCTRL = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID_TCC2_TC3);
while (GCLK->STATUS.bit.SYNCBUSY == 1); // wait for sync
TcCount16* TC = (TcCount16*) TC3;
TC->CTRLA.reg &= ~TC_CTRLA_ENABLE;
while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync
// Use the 16-bit timer
TC->CTRLA.reg |= TC_CTRLA_MODE_COUNT16;
while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync
// Use match mode so that the timer counter resets when the count matches the compare register
TC->CTRLA.reg |= TC_CTRLA_WAVEGEN_MFRQ;
while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync
// Set prescaler to 1024
//TC->CTRLA.reg |= TC_CTRLA_PRESCALER_DIV1024;
TC->CTRLA.reg |= TC_CTRLA_PRESCALER_DIV64;
while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync
setTimerFrequency(1000000 / USECPERTICK);
// Enable the compare interrupt
TC->INTENSET.reg = 0;
TC->INTENSET.bit.MC0 = 1;
NVIC_EnableIRQ(TC3_IRQn);
TC->CTRLA.reg |= TC_CTRLA_ENABLE;
while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync
}
//+=============================================================================
// initialization
//
void IRrecv::enableIRIn()
{
// Interrupt Service Routine - Fires every 50uS
//Serial.println("Starting timer");
startTimer();
//Serial.println("Started timer");
// Initialize state machine variables
irparams.rcvstate = STATE_IDLE;
irparams.rawlen = 0;
// Set pin modes
pinMode(irparams.recvpin, INPUT);
}
void irs(); // Defined in IRRemote as ISR(TIMER_INTR_NAME)
void TC3_Handler(void)
{
TcCount16* TC = (TcCount16*) TC3;
// If this interrupt is due to the compare register matching the timer count
// we toggle the LED.
if (TC->INTFLAG.bit.MC0 == 1) {
TC->INTFLAG.bit.MC0 = 1;
irs();
}
}
#endif // defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD)