IRremote
esp32.cpp
Go to the documentation of this file.
1 #ifdef ESP32
2 
3 // This file contains functions specific to the ESP32.
4 
5 #include "IRremote.h"
6 
7 // "Idiot check"
8 #ifdef USE_DEFAULT_ENABLE_IR_IN
9 #error Must undef USE_DEFAULT_ENABLE_IR_IN
10 #endif
11 
12 hw_timer_t *timer;
13 IRAM_ATTR void IRTimer(); // defined in IRremote.cpp, masqueraded as ISR(TIMER_INTR_NAME)
14 
15 //+=============================================================================
16 // initialization
17 //
18 void IRrecv::enableIRIn() {
19 // Interrupt Service Routine - Fires every 50uS
20  // ESP32 has a proper API to setup timers, no weird chip macros needed
21  // simply call the readable API versions :)
22  // 3 timers, choose #1, 80 divider nanosecond precision, 1 to count up
23  timer = timerBegin(1, 80, 1);
24  timerAttachInterrupt(timer, &IRTimer, 1);
25  // every 50ns, autoreload = true
26  timerAlarmWrite(timer, 50, true);
27  timerAlarmEnable(timer);
28 
29  // Initialize state machine variables
31  irparams.rawlen = 0;
32 
33  // Set pin modes
34  pinMode(irparams.recvpin, INPUT);
35 }
36 
37 void IRrecv::disableIRIn() {
38  timerEnd(timer);
39  timerDetachInterrupt(timer);
40 }
41 
42 void IRsend::enableIROut(int khz) {
43  ledcSetup(LEDCHANNEL, khz * 1000, 8); // 8 bit PWM resolution
44  ledcAttachPin(IR_SEND_PIN, LEDCHANNEL); // bind pin to channel
45 }
46 
47 #endif // ESP32
IRrecv::disableIRIn
void disableIRIn()
Disable IR reception.
Definition: irRecv.cpp:185
IRrecv::enableIRIn
void enableIRIn()
Enable IR reception.
Definition: irRecv.cpp:160
irparams_t::recvpin
uint8_t recvpin
Pin connected to IR data from detector.
Definition: IRremoteInt.h:42
IRsend::enableIROut
void enableIROut(int khz)
Definition: irSend.cpp:127
irparams_t::rcvstate
uint8_t rcvstate
State Machine state.
Definition: IRremoteInt.h:41
irparams
volatile irparams_t irparams
Allow all parts of the code access to the ISR data NB.
IRremote.h
Public API to the library.
IR_SEND_PIN
#define IR_SEND_PIN
If applicable, pin number for sending IR.
Definition: IRremoteBoardDefs.h:362
irparams_t::rawlen
unsigned int rawlen
counter of entries in rawbuf
Definition: IRremoteInt.h:45
IR_REC_STATE_IDLE
#define IR_REC_STATE_IDLE
Definition: IRremoteInt.h:52