Skip to content

Commit 1ce638b

Browse files
committed
RP2040 support added.
- Refactored IRTimer.hpp. - Refactored IR_SEND_PIN and IrSender.sendPin handling. - Renamed IR_SEND_DUTY_CYCLE to IR_SEND_DUTY_CYCLE_PERCENT. - Fixed bugs for SEND_PWM_BY_TIMER active.
1 parent 2077fd1 commit 1ce638b

34 files changed

+1560
-728
lines changed

.github/workflows/LibraryBuild.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- arduino:samd:arduino_zero_native
5555
- arduino:mbed:nano33ble
5656
- arduino:mbed_rp2040:pico
57-
- rp2040:rp2040:rpipico:flash=2097152_0,freq=125,opt=Small,rtti=Disabled,dbgport=Disabled,dbglvl=None,usbstack=picosdk
57+
- rp2040:rp2040:arduino_nano_connect
5858
- digistump:avr:digispark-tiny:clock=clock16
5959
- ATTinyCore:avr:attinyx5micr:LTO=enable,sketchclock=16pll
6060
- ATTinyCore:avr:attinyx7micr:LTO=enable,sketchclock=16external,pinmapping=new,millis=enabled
@@ -125,7 +125,7 @@ jobs:
125125
build-properties: # the flags were put in compiler.cpp.extra_flags
126126
IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100
127127

128-
- arduino-boards-fqbn: rp2040:rp2040:rpipico:flash=2097152_0,freq=125,opt=Small,rtti=Disabled,dbgport=Disabled,dbglvl=None,usbstack=picosdk
128+
- arduino-boards-fqbn: rp2040:rp2040:arduino_nano_connect
129129
platform-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
130130
build-properties: # the flags were put in compiler.cpp.extra_flags
131131
IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 -DSEND_PWM_BY_TIMER

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ This library enables you to send and receive using infra-red signals on an Ardui
4141
+ [Incompatibilities to other libraries and Arduino commands like tone() and analogWrite()](https://github.com/Arduino-IRremote/Arduino-IRremote#incompatibilities-to-other-libraries-and-arduino-commands-like-tone-and-analogwrite)
4242
+ [Hardware-PWM signal generation for sending](https://github.com/Arduino-IRremote/Arduino-IRremote#hardware-pwm-signal-generation-for-sending)
4343
+ [Why do we use 33% duty cycle for sending](https://github.com/Arduino-IRremote/Arduino-IRremote#why-do-we-use-33-duty-cycle-for-sending)
44-
4544
- [How we decode signals](https://github.com/Arduino-IRremote/Arduino-IRremote#how-we-decode-signals)
4645
- [NEC encoding diagrams](https://github.com/Arduino-IRremote/Arduino-IRremote#nec-encoding-diagrams)
4746
- [Quick comparison of 4 Arduino IR receiving libraries](https://github.com/Arduino-IRremote/Arduino-IRremote#quick-comparison-of-4-arduino-ir-receiving-libraries)
@@ -330,8 +329,8 @@ Modify them by enabling / disabling them, or change the values if applicable.
330329
| Name | File | Default value | Description |
331330
|-|-|-|-|
332331
| `RAW_BUFFER_LENGTH` | Before `#include <IRremote.hpp>` | 100 | Buffer size of raw input buffer. Must be even! 100 is sufficient for *regular* protocols of up to 48 bits, but for most air conditioner protocols a value of up to 750 is required. Use the ReceiveDump example to find smallest value for your requirements. |
333-
| `IR_SEND_PIN` | Before `#include <IRremote.hpp>` | disabled | If specified (as constant), reduces program size and improves send timing for AVR. |
334-
| `SEND_PWM_BY_TIMER` | Before `#include <IRremote.hpp>` | disabled | Disable carrier PWM generation in software and use (restricted) hardware PWM except for ESP32 where both modes are using the flexible `hw_timer_t`. |
332+
| `IR_SEND_PIN` | Before `#include <IRremote.hpp>` | disabled | If specified (as constant), reduces program size and improves send timing for AVR. If you want to use a runtime valiable send pin e.g. with `setSendPin(uint8_t aSendPinNumber)` , you must disable this macro. |
333+
| `SEND_PWM_BY_TIMER` | Before `#include <IRremote.hpp>` | disabled | Disable carrier PWM generation in software and use (restricted) hardware PWM. Enabled for ESP32 and RP2040 in all examples. |
335334
| `USE_NO_SEND_PWM` | Before `#include <IRremote.hpp>` | disabled | Use no carrier PWM, just simulate an **active low** receiver signal. Overrides `SEND_PWM_BY_TIMER` definition. |
336335
| `USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN` | Before `#include <IRremote.hpp>` | disabled | Use or simulate open drain output mode at send pin. **Attention, active state of open drain is LOW**, so connect the send LED between positive supply and send pin! |
337336
| `EXCLUDE_EXOTIC_PROTOCOLS` | Before `#include <IRremote.hpp>` | disabled | If activated, BOSEWAVE, WHYNTER and LEGO_PF are excluded in `decode()` and in sending with `IrSender.write()`. Saves up to 650 bytes program space. |
@@ -342,7 +341,7 @@ Modify them by enabling / disabling them, or change the values if applicable.
342341
| `NO_LED_FEEDBACK_CODE` | Before `#include <IRremote.hpp>` | disabled | This completely disables the LED feedback code for send and receive, thus saving around 100 bytes program space for receiving, around 500 bytes for sending and halving the receiver ISR processing time. |
343342
| `IR_INPUT_IS_ACTIVE_HIGH` | Before `#include <IRremote.hpp>` | disabled | Enable it if you use a RF receiver, which has an active HIGH output signal. |
344343
| `DEBUG` | IRremoteInt.h | disabled | Enables lots of lovely debug output. |
345-
| `IR_SEND_DUTY_CYCLE` | IRremoteInt.h | 30 | Duty cycle of IR send signal. |
344+
| `IR_SEND_DUTY_CYCLE_PERCENT` | IRremote.h | 30 | Duty cycle of IR send signal. |
346345
| `MICROS_PER_TICK` | IRremoteInt.h | 50 | Resolution of the raw input buffer data. Corresponds to 2 pulses of each 26.3 µs at 38 kHz. |
347346
| `IR_USE_AVR_TIMER*` | private/IRTimer.hpp | | Selection of timer to be used for generating IR receiving sample interval. |
348347
|-|-|-|-|
@@ -377,12 +376,12 @@ ATtiny and Digispark boards are only tested with the recommended [ATTinyCore](ht
377376
- ATmega4809 (Nano every)
378377
- ATtiny84, 85, 167 (Digispark + Digispark Pro)
379378
- SAMD (Zero, MKR*, **but not DUE, which is SAM architecture**)
380-
- ESP32
379+
- ESP32 (ESP32 C3 since board package 2.0.2 from Espressif)
381380
- ESP8266 [This fork](https://github.com/crankyoldgit/IRremoteESP8266) supports an [impressive set of protocols and a lot of air conditioners](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/SupportedProtocols.md)
382381
- Sparkfun Pro Micro
383382
- Nano Every, Uno WiFi Rev2, nRF5 BBC MicroBit, Nano33_BLE
384383
- BluePill with STM32
385-
- RP2040 based boards (Raspberry Pi Pico, etc.)
384+
- RP2040 based boards (Raspberry Pi Pico, Nano RP2040 Connect etc.)
386385
387386
We are open to suggestions for adding support to new boards, however we highly recommend you contact your supplier first and ask them to provide support from their side.<br/>
388387
If you can provide **examples of using a periodic timer for interrupts** for the new board, and the board name for selection in the Arduino IDE, then you have way better chances to get your board supported by IRremote.
@@ -457,9 +456,10 @@ The timer and the pin usage can be adjusted in [private/IRTimer.hpp](https://git
457456
| [Teensy-LC](https://www.pjrc.com/teensy/pinout.html) | **TPM1** | **16** | 17 |
458457
| [Teensy 3.0 - 3.6](https://www.pjrc.com/teensy/pinout.html) | **CMT** | **5** |
459458
| [Teensy 4.0 - 4.1](https://www.pjrc.com/teensy/pinout.html) | **FlexPWM1.3** | **8** | 7, 25 |
460-
| [BluePill / STM32F103C8T6](https://github.com/rogerclarkmelbourne/Arduino_STM32) | **3** | % | **PA6 & PA7 & PB0 & PB1** |
459+
| [BluePill / STM32F103C8T6](https://github.com/stm32duino/Arduino_Core_STM32) | **3** | % | **PA6 & PA7 & PB0 & PB1** |
461460
| [BluePill / STM32F103C8T6](https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill) | **TIM4** | % | **PB6 & PB7 & PB8 & PB9** |
462461
| [RP2040 / Pi Pico](https://github.com/earlephilhower/arduino-pico) | [default alarm pool](https://raspberrypi.github.io/pico-sdk-doxygen/group__repeating__timer.html) | % | |
462+
| [RP2040 / Mbed based](https://github.com/arduino/ArduinoCore-mbed) | [default alarm pool](https://raspberrypi.github.io/pico-sdk-doxygen/group__repeating__timer.html) | % | |
463463

464464
### Why do we use 33% duty cycle for sending
465465
We do it according to the statement in the [Vishay datasheet](https://www.vishay.com/docs/80069/circuit.pdf):

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ The latest version may not be released!
33
See also the commit log at github: https://github.com/Arduino-IRremote/Arduino-IRremote/commits/master
44

55
## 3.5.3
6+
- RP2040 support added.
7+
- Refactored IRTimer.hpp.
8+
- Refactored IR_SEND_PIN and IrSender.sendPin handling.
9+
- Renamed IR_SEND_DUTY_CYCLE to IR_SEND_DUTY_CYCLE_PERCENT.
10+
- Fixed bugs for SEND_PWM_BY_TIMER active.
611

712
## 3.5.2
813
- Improved support for Teensy boards by Paul Stoffregen.

examples/ControlRelay/PinDefinitionsAndMore.h

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,23 @@
3434
* ATtiny167 9 8 5 // Digispark pro number schema
3535
* ATtiny167 3 2 7
3636
* ATtiny3217 10 11 3 // TinyCore schema
37-
* ATtiny1604 2 PA5/3 %
37+
* ATtiny1604 2 PA5|3 %
3838
* SAMD21 3 4 5
39-
* ESP8266 14 // D5 12 // D6 %
39+
* ESP8266 14|D5 12|D6 %
4040
* ESP32 15 4 27
4141
* BluePill PA6 PA7 PA3
4242
* APOLLO3 11 12 5
43+
* RP2040 3|GPIO15 4|GPIO16 5|GPIO17
4344
*/
4445
//#define _IR_MEASURE_TIMING // For debugging purposes.
45-
//
46+
47+
/*
48+
* We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation
49+
*/
50+
#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE)
51+
#define SEND_PWM_BY_TIMER
52+
#endif
53+
4654
#if defined(ESP8266)
4755
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW
4856
#define IR_RECEIVE_PIN 14 // D5
@@ -58,6 +66,7 @@
5866

5967
#elif defined(ESP32)
6068
#include <Arduino.h>
69+
6170
#define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer.
6271
void tone(uint8_t _pin, unsigned int frequency){
6372
ledcAttachPin(_pin, TONE_LEDC_CHANNEL);
@@ -154,24 +163,52 @@ void noTone(uint8_t _pin){
154163
#define IR_SEND_PIN 12
155164
#define TONE_PIN 5
156165

157-
#elif defined(ARDUINO_ARCH_MBED) // Arduino Nano 33 BLE
166+
#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO)
167+
#define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico
168+
#define IR_SEND_PIN 4 // GPIO16
169+
#define TONE_PIN 5
170+
#define APPLICATION_PIN 6
171+
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 7 // E.g. used for examples which use LED_BUILDIN for example output.
172+
#define _IR_TIMING_TEST_PIN 8
173+
174+
#elif defined(ARDUINO_ARCH_RP2040) // Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico
175+
#define IR_RECEIVE_PIN 15 // to be compatible with the Arduino Nano RP2040 Connect (pin3)
176+
#define IR_SEND_PIN 16
177+
#define TONE_PIN 17
178+
#define APPLICATION_PIN 18
179+
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 19 // E.g. used for examples which use LED_BUILDIN for example output.
180+
#define _IR_TIMING_TEST_PIN 20
181+
182+
// If you program the Nano RP2040 Connect with this core, then you must redefine LED_BUILTIN
183+
// and use the external reset with 1 kOhm to ground to enter UF2 mode
184+
#undef LED_BUILTIN
185+
#define LED_BUILTIN 6
186+
187+
#elif defined(PARTICLE) // !!!UNTESTED!!!
188+
#define IR_RECEIVE_PIN A4
189+
#define IR_SEND_PIN A5 // Particle supports multiple pins
190+
191+
/*
192+
* 4 times the same (default) layout for easy adaption in the future
193+
*/
194+
#elif defined(TEENSYDUINO)
158195
#define IR_RECEIVE_PIN 2
159196
#define IR_SEND_PIN 3
160197
#define TONE_PIN 4
161198
#define APPLICATION_PIN 5
162199
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
163200
#define _IR_TIMING_TEST_PIN 7
164201

165-
#elif defined(TEENSYDUINO)
166-
#define IR_RECEIVE_PIN 2
202+
#elif defined(__AVR__) // Default as for ATmega328 like on Uno, Nano etc.
203+
#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here.
167204
#define IR_SEND_PIN 3
168205
#define TONE_PIN 4
169206
#define APPLICATION_PIN 5
170207
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
171208
#define _IR_TIMING_TEST_PIN 7
172209

173-
#elif defined(__AVR__) // Default as for ATmega328 like on Uno, Nano etc.
174-
#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here.
210+
#elif defined(ARDUINO_ARCH_MBED) // Arduino Nano 33 BLE
211+
#define IR_RECEIVE_PIN 2
175212
#define IR_SEND_PIN 3
176213
#define TONE_PIN 4
177214
#define APPLICATION_PIN 5

examples/IRDispatcherDemo/IRCommandDispatcher.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*/
3737
#define IR_COMMAND_FLAG_BLOCKING 0x00 // default - blocking command, repeat not accepted, only one command at a time. Stops an already running command.
3838
#define IR_COMMAND_FLAG_REPEATABLE 0x01 // repeat accepted
39-
#define IR_COMMAND_FLAG_NON_BLOCKING 0x02 // (Non blocking / non regular) Command that can be processed any time and may interrupt other IR commands - used for stop etc.
39+
#define IR_COMMAND_FLAG_NON_BLOCKING 0x02 // (Non blocking / non regular) (short) command that can be processed any time and may interrupt other IR commands - used for stop, set direction etc.
4040
#define IR_COMMAND_FLAG_REPEATABLE_NON_BLOCKING (IR_COMMAND_FLAG_REPEATABLE | IR_COMMAND_FLAG_NON_BLOCKING)
4141
/*
4242
* if this command is received, requestToStopReceived is set until call of next loop.
@@ -67,6 +67,7 @@ struct IRDataForCommandDispatcherStruct {
6767
#define COMMAND_INVALID 0xFF // code for command received, but not in mapping
6868

6969
#define RETURN_IF_STOP if (IRDispatcher.requestToStopReceived) return
70+
#define DELAY_AND_RETURN_IF_STOP(aDurationMillis) if (IRDispatcher.delayAndCheckForStop(aDurationMillis)) return
7071

7172
class IRCommandDispatcher {
7273
public:

0 commit comments

Comments
 (0)