@@ -59,10 +59,10 @@ IRsend::IRsend(uint16_t IRsendPin, bool inverted,
5959 // TX specific configurations
6060 _rmt_config.tx_config .loop_en = false ;
6161 _rmt_config.tx_config .carrier_en = true ;
62+ _rmt_config.tx_config .carrier_level = RMT_CARRIER_LEVEL_HIGH;
6263 _rmt_config.tx_config .carrier_duty_percent = _dutycycle;
6364 _rmt_config.tx_config .carrier_freq_hz = 38000 ; // Default IR TX frequency.
64-
65- _rmt_config.tx_config .idle_output_en = false ;
65+ _rmt_config.tx_config .idle_output_en = true ;
6666 _rmt_config.tx_config .idle_level = inverted ? RMT_IDLE_LEVEL_HIGH :
6767 RMT_IDLE_LEVEL_LOW;
6868#endif // ENABLE_ESP32_RMT_USAGE
@@ -82,8 +82,9 @@ IRsend::~IRsend(void) {
8282void IRsend::begin () {
8383#ifndef UNIT_TEST
8484#if ENABLE_ESP32_RMT_USAGE
85- _rmt_config.tx_config .idle_output_en = true ;
86- rmt_config (&_rmt_config) && rmt_driver_install (_rmt_config.channel , 0 , 0 );
85+ assert (!rmt_config (&_rmt_config));
86+ assert (!rmt_driver_install (_rmt_config.channel , 0 , 0 ));
87+ _is_rmt_driver_installed = true ;
8788#else
8889 pinMode (IRpin, OUTPUT);
8990#endif // ENABLE_ESP32_RMT_USAGE
@@ -94,35 +95,27 @@ void IRsend::begin() {
9495#if ENABLE_ESP32_RMT_USAGE
9596// / Disable the pin for output.
9697void IRsend::end () {
97- rmt_driver_uninstall (_rmt_config.channel );
98+ if (_is_rmt_driver_installed)
99+ _is_rmt_driver_installed = rmt_driver_uninstall (_rmt_config.channel );
98100}
99101#endif // ENABLE_ESP32_RMT_USAGE
100102
101103// / Turn off the IR LED.
102104void IRsend::ledOff () {
103105#ifndef UNIT_TEST
104- #if ENABLE_ESP32_RMT_USAGE
105- rmt_set_idle_level (_rmt_config.channel ,
106- _rmt_config.tx_config .idle_output_en ,
107- (outputOn == LOW) ? RMT_IDLE_LEVEL_HIGH
108- : RMT_IDLE_LEVEL_LOW);
109- #else
106+ #if !(ENABLE_ESP32_RMT_USAGE)
110107 digitalWrite (IRpin, outputOff);
111- #endif // ENABLE_ESP32_RMT_USAGE
108+ #endif // !(ENABLE_ESP32_RMT_USAGE)
109+
112110#endif // UNIT_TEST
113111}
114112
115113// / Turn on the IR LED.
116114void IRsend::ledOn () {
117115#ifndef UNIT_TEST
118- #if ENABLE_ESP32_RMT_USAGE
119- rmt_set_idle_level (_rmt_config.channel ,
120- _rmt_config.tx_config .idle_output_en ,
121- (outputOn == HIGH) ? RMT_IDLE_LEVEL_HIGH
122- : RMT_IDLE_LEVEL_LOW);
123- #else
116+ #if !(ENABLE_ESP32_RMT_USAGE)
124117 digitalWrite (IRpin, outputOn);
125- #endif // ENABLE_ESP32_RMT_USAGE
118+ #endif // !( ENABLE_ESP32_RMT_USAGE)
126119#endif // UNIT_TEST
127120}
128121
@@ -172,8 +165,8 @@ void IRsend::enableIROut(uint32_t freq, uint8_t duty) {
172165#if ENABLE_ESP32_RMT_USAGE
173166 _rmt_config.tx_config .carrier_duty_percent = _dutycycle;
174167 _rmt_config.tx_config .carrier_freq_hz = freq;
175- // (Re)Load up the rmt config and if the config is okay, install the driver .
176- rmt_config (&_rmt_config);
168+ // Update rmt config.
169+ assert (! rmt_config (&_rmt_config) );
177170#endif // ENABLE_ESP32_RMT_USAGE
178171}
179172
@@ -227,15 +220,11 @@ uint16_t IRsend::mark(uint16_t usec) {
227220#if ENABLE_ESP32_RMT_USAGE
228221 // ESP32 does this very differently if using the RMT drvier
229222 _rmt_config.tx_config .carrier_duty_percent = _dutycycle;
230- static const rmt_item32_t payload[] = {
231- // mark signal
223+ static const rmt_item32_t mark_signal[] = {
232224 {{{ usec, 1 , 0 , 0 }}}, // mark
233- // RMT end marker
234- {{{ 0 , 1 , 0 , 0 }}}
235225 };
236226 // Try sending the mark signal via rmt.
237- if (!rmt_write_items (RMT_CHANNEL_0, payload,
238- sizeof (payload) / sizeof (payload[0 ]), true ))
227+ if (!rmt_write_items (_rmt_config.channel , mark_signal, 1 , true ))
239228 return 0 ; // We failed. So report no pulses.
240229 // Calculate & return how many pulses we should have sent. We can't actually
241230 // counthow many were really sent.
0 commit comments