Skip to content

Commit 0b66125

Browse files
committed
Documentation
1 parent e8f8f2d commit 0b66125

File tree

4 files changed

+60
-40
lines changed

4 files changed

+60
-40
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,27 @@ Whether you use the Adafruit Neopixel lib, or FastLED, interrupts get disabled o
2323

2424
# Supported IR Protocols
2525
Aiwa, BoseWave, Denon, Dish, JVC, Lego, LG, MagiQuest, Mitsubishi, NEC, Panasonic, RC5, RC6, Samsung, Sanyo, Sharp, Sony, Whynter, (Pronto).<br/>
26-
To receive IR signals in NEC standard format, you must comment out the line `#define USE_NEC_STANDARD` in [IRremote.h](src/IRremote.h#L74).
26+
Protocols can be switched off and on by changing the lines in *IRremote.h*:
27+
28+
```
29+
#define DECODE_<PROTOCOL_NAME> 1
30+
#define SEND_<PROTOCOL_NAME> 1
31+
```
32+
33+
# Useful defines
34+
You may modify the behavior of the library by changing this values in the source code or just defining a new value for compile (the latter is not possible with the Arduino IDE, so consider to use [sloeber](https://eclipse.baeyens.it).
35+
| Name | File | Default value | Description |
36+
|-|-|-|-|
37+
| `DEBUG` | IRremote.h | disabled | Enables lots of lovely debug output. |
38+
| `USE_NEC_STANDARD` | IRremote.h | disabled | Use LSB first, address/code schema for encoding. |
39+
| `USE_NO_SEND_PWM` | IRremote.h | disabled | Use no carrier PWM, just simulate an active low receiver signal. |
40+
| `USE_SOFT_SEND_PWM` | IRremote.h | disabled | Use carrier PWM generation in software, instead of hardware PWM. |
41+
| `PULSE_CORRECTION_MICROS` | IRremote.h | 3 | If USE_SOFT_SEND_PWM, this amount is subtracted from the on-time of the pulses. |
42+
| `USE_SPIN_WAIT` | IRremote.h | disabled | If USE_SOFT_SEND_PWM, use spin wait instead of delayMicros(). |
43+
| `RAW_BUFFER_LENGTH` | IRremoteint.h | 101 | Buffer size of raw input buffer. Must be odd! |
44+
| `IR_SEND_DUTY_CYCLE` | IRremoteBoardDefs.h | 30 | Duty cycle of IR send signal. |
45+
| `MICROS_PER_TICK` | IRremoteBoardDefs.h | 50 | Resolution of the raw input buffer data. |
46+
2747

2848
# Handling unknown Protocols
2949
## Disclaimer

src/IRremote.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,8 @@
2323
#define IRremote_h
2424

2525
//------------------------------------------------------------------------------
26-
// The ISR header contains several useful macros the user may wish to use
27-
//
2826
#include "private/IRremoteInt.h"
2927

30-
#ifdef ARDUINO_ARCH_AVR
31-
#include <avr/pgmspace.h>
32-
#define HAS_FLASH_READ 1
33-
#define STRCPY_PF_CAST(x) (x)
34-
#else
35-
#define HAS_FLASH_READ 0
36-
#endif
37-
3828
/****************************************************
3929
* PROTOCOLS
4030
****************************************************/
@@ -200,7 +190,7 @@ struct decode_results {
200190
/**
201191
* DEPRECATED
202192
* Decoded value for NEC and others when a repeat code is received
203-
* Use Flag isRepeat instead
193+
* Use Flag decode_results.isRepeat (see above) instead
204194
*/
205195
#define REPEAT 0xFFFFFFFF
206196

@@ -392,15 +382,21 @@ class IRrecv {
392382
* SENDING
393383
****************************************************/
394384
/**
395-
* Define to use no carrier PWM, just simulate a receiver signal.
385+
* Define to use no carrier PWM, just simulate an active low receiver signal.
396386
*/
397387
//#define USE_NO_SEND_PWM
398388
/**
399389
* Define to use carrier PWM generation in software, instead of hardware PWM.
400390
*/
401391
//#define USE_SOFT_SEND_PWM
402392
/**
403-
* Define to use spin wait instead of delayMicros() for USE_SOFT_SEND_PWM.
393+
* If USE_SOFT_SEND_PWM, this amount is subtracted from the on-time of the pulses.
394+
*/
395+
#ifndef PULSE_CORRECTION_MICROS
396+
#define PULSE_CORRECTION_MICROS 3
397+
#endif
398+
/**
399+
* If USE_SOFT_SEND_PWM, use spin wait instead of delayMicros().
404400
*/
405401
//#define USE_SPIN_WAIT
406402
/**
@@ -559,8 +555,8 @@ class IRsend {
559555
int sendPin;
560556

561557
# if defined(USE_SOFT_SEND_PWM)
562-
unsigned int periodTime;
563-
unsigned int periodOnTime;
558+
unsigned int periodTimeMicros;
559+
unsigned int periodOnTimeMicros;
564560

565561
void sleepMicros(unsigned long us);
566562
void sleepUntilMicros(unsigned long targetTime);

src/irSend.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void IRsend::mark(unsigned int time) {
108108
#ifdef USE_SOFT_SEND_PWM
109109
unsigned long start = micros();
110110
unsigned long stop = start + time;
111-
if (stop + periodTime < start) {
111+
if (stop + periodTimeMicros < start) {
112112
// Counter wrap-around, happens very seldomly, but CAN happen.
113113
// Just give up instead of possibly damaging the hardware.
114114
return;
@@ -117,9 +117,9 @@ void IRsend::mark(unsigned int time) {
117117
unsigned long now = micros();
118118
while (now < stop) {
119119
SENDPIN_ON(sendPin);
120-
sleepMicros (periodOnTime);
120+
sleepMicros (periodOnTimeMicros);
121121
SENDPIN_OFF(sendPin);
122-
nextPeriodEnding += periodTime;
122+
nextPeriodEnding += periodTimeMicros;
123123
sleepUntilMicros(nextPeriodEnding);
124124
now = micros();
125125
}
@@ -164,8 +164,8 @@ void IRsend::space(unsigned int time) {
164164
//
165165
void IRsend::enableIROut(int khz) {
166166
#ifdef USE_SOFT_SEND_PWM
167-
periodTime = (1000U + khz / 2) / khz; // = 1000/khz + 1/2 = round(1000.0/khz)
168-
periodOnTime = periodTime * DUTY_CYCLE / 100U - PULSE_CORRECTION;
167+
periodTimeMicros = (1000U + khz / 2) / khz; // = 1000/khz + 1/2 = round(1000.0/khz)
168+
periodOnTimeMicros = periodTimeMicros * IR_SEND_DUTY_CYCLE / 100U - PULSE_CORRECTION_MICROS;
169169
#endif
170170

171171
#if defined(USE_NO_SEND_PWM)

src/private/IRremoteBoardDefs.h

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
#ifndef IRremoteBoardDefs_h
2424
#define IRremoteBoardDefs_h
2525

26+
#ifdef ARDUINO_ARCH_AVR
27+
#include <avr/pgmspace.h>
28+
#define HAS_FLASH_READ 1
29+
#define STRCPY_PF_CAST(x) (x)
30+
#else
31+
#define HAS_FLASH_READ 0
32+
#endif
33+
2634
// Define some defaults, that some boards may like to override
2735
// (This is to avoid negative logic, ! DONT_... is just awkward.)
2836

@@ -47,16 +55,10 @@
4755
/**
4856
* Duty cycle in percent for sent signals.
4957
*/
50-
#if ! defined(DUTY_CYCLE)
51-
#define DUTY_CYCLE 30 // 30 saves power and is compatible to the old existing code
58+
#if ! defined(IR_SEND_DUTY_CYCLE)
59+
#define IR_SEND_DUTY_CYCLE 30 // 30 saves power and is compatible to the old existing code
5260
#endif
5361

54-
/**
55-
* If USE_SOFT_SEND_PWM or USE_NO_SEND_PWM, this amount (in micro seconds) is subtracted from the
56-
* on-time of the pulses.
57-
*/
58-
#define PULSE_CORRECTION 3
59-
6062
//------------------------------------------------------------------------------
6163
// This first #ifdef statement contains defines for blinking the LED,
6264
// as well as all other board specific information, with the exception of
@@ -154,7 +156,9 @@
154156

155157
//------------------------------------------------------------------------------
156158
// microseconds per clock interrupt tick
159+
#if ! defined(MICROS_PER_TICK)
157160
#define MICROS_PER_TICK 50
161+
#endif
158162

159163
//------------------------------------------------------------------------------
160164
// Define which timer to use
@@ -439,7 +443,7 @@ static void timerConfigForSend(uint16_t frequency) {
439443
TCCR2A = _BV(WGM20);
440444
TCCR2B = _BV(WGM22) | _BV(CS20);
441445
OCR2A = pwmval;
442-
OCR2B = pwmval * DUTY_CYCLE / 100;
446+
OCR2B = pwmval * IR_SEND_DUTY_CYCLE / 100;
443447
}
444448

445449
#define TIMER_COUNT_TOP (SYSCLOCK * MICROS_PER_TICK / 1000000)
@@ -508,7 +512,7 @@ static void timerConfigForSend(uint16_t frequency) {
508512
TCCR1A = _BV(WGM11);
509513
TCCR1B = _BV(WGM13) | _BV(CS10);
510514
ICR1 = pwmval;
511-
OCR1A = pwmval * DUTY_CYCLE / 100;
515+
OCR1A = pwmval * IR_SEND_DUTY_CYCLE / 100;
512516
}
513517

514518
static void timerConfigForReceive() {
@@ -560,7 +564,7 @@ static void timerConfigForSend(uint16_t frequency) {
560564
TCCR3A = _BV(WGM31);
561565
TCCR3B = _BV(WGM33) | _BV(CS30);
562566
ICR3 = pwmval;
563-
OCR3A = pwmval * DUTY_CYCLE / 100;
567+
OCR3A = pwmval * IR_SEND_DUTY_CYCLE / 100;
564568
}
565569

566570
static void timerConfigForReceive() {
@@ -612,8 +616,8 @@ static void timerConfigForSend(uint16_t frequency) {
612616
TCCR4E = 0;
613617
TC4H = pwmval >> 8;
614618
OCR4C = pwmval;
615-
TC4H = (pwmval * DUTY_CYCLE / 100) >> 8;
616-
OCR4A = (pwmval * DUTY_CYCLE / 100) & 255;
619+
TC4H = (pwmval * IR_SEND_DUTY_CYCLE / 100) >> 8;
620+
OCR4A = (pwmval * IR_SEND_DUTY_CYCLE / 100) & 255;
617621
}
618622

619623
static void timerConfigForReceive() {
@@ -656,7 +660,7 @@ static void timerConfigForSend(uint16_t frequency) {
656660
TCCR4A = _BV(WGM41);
657661
TCCR4B = _BV(WGM43) | _BV(CS40);
658662
ICR4 = pwmval;
659-
OCR4A = pwmval * DUTY_CYCLE / 100;
663+
OCR4A = pwmval * IR_SEND_DUTY_CYCLE / 100;
660664
}
661665

662666
static void timerConfigForReceive() {
@@ -692,7 +696,7 @@ static void timerConfigForSend(uint16_t frequency) {
692696
TCCR5A = _BV(WGM51);
693697
TCCR5B = _BV(WGM53) | _BV(CS50);
694698
ICR5 = pwmval;
695-
OCR5A = pwmval * DUTY_CYCLE / 100;
699+
OCR5A = pwmval * IR_SEND_DUTY_CYCLE / 100;
696700
}
697701

698702
static void timerConfigForReceive() {
@@ -820,7 +824,7 @@ static void timerConfigForSend(uint16_t frequency) {
820824
TCCR0A = _BV(WGM00);
821825
TCCR0B = _BV(WGM02) | _BV(CS00);
822826
OCR0A = pwmval;
823-
OCR0B = pwmval * DUTY_CYCLE / 100;
827+
OCR0B = pwmval * IR_SEND_DUTY_CYCLE / 100;
824828
}
825829

826830
#define TIMER_COUNT_TOP (SYSCLOCK * MICROS_PER_TICK / 1000000)
@@ -854,7 +858,7 @@ static void timerConfigForSend(uint16_t frequency) {
854858
TCCR0A = _BV(WGM00);
855859
TCCR0B = _BV(WGM02) | _BV(CS00);
856860
OCR0A = pwmval;
857-
OCR0B = pwmval * DUTY_CYCLE / 100;
861+
OCR0B = pwmval * IR_SEND_DUTY_CYCLE / 100;
858862
}
859863

860864
#define IR_SEND_PIN 1
@@ -872,7 +876,7 @@ static void timerConfigForSend(uint16_t frequency) {
872876
const uint32_t pwmval = (SYSCLOCK / 2000) / (frequency);
873877
TCB0.CTRLB = TCB_CNTMODE_PWM8_gc;
874878
TCB0.CCMPL = pwmval;
875-
TCB0.CCMPH = (pwmval * DUTY_CYCLE) / 100;
879+
TCB0.CCMPH = (pwmval * IR_SEND_DUTY_CYCLE) / 100;
876880
TCB0.CTRLA = (TCB_CLKSEL_CLKDIV2_gc) | (TCB_ENABLE_bm);
877881
}
878882

@@ -906,7 +910,7 @@ static void timerConfigForReceive() {
906910
#endif
907911

908912
#define TIMER_RESET_INTR_PENDING
909-
#define TIMER_ENABLE_SEND_PWM ledcWrite(LED_CHANNEL, DUTY_CYCLE) // we must use channel here not pin number
913+
#define TIMER_ENABLE_SEND_PWM ledcWrite(LED_CHANNEL, IR_SEND_DUTY_CYCLE) // we must use channel here not pin number
910914
#define TIMER_DISABLE_SEND_PWM ledcWrite(LED_CHANNEL, 0)
911915

912916
#ifdef ISR

0 commit comments

Comments
 (0)