From 87fd1b887ef80badbf4744402f2485ecf0112db0 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Thu, 4 Aug 2022 01:19:11 +0200 Subject: [PATCH] ESP32 RMT pin add function --- DCCRMT.cpp | 11 +++++++++++ DCCRMT.h | 1 + 2 files changed, 12 insertions(+) diff --git a/DCCRMT.cpp b/DCCRMT.cpp index 8fe4270..dcf3ac7 100644 --- a/DCCRMT.cpp +++ b/DCCRMT.cpp @@ -210,4 +210,15 @@ void IRAM_ATTR RMTChannel::RMTinterrupt() { if (dataRepeat > 0) // if a repeat count was specified, work on that dataRepeat--; } + +bool RMTChannel::addPin(byte pin) { + gpio_num_t gpioNum = (gpio_num_t)(pin); + esp_err_t err; + PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[gpioNum], PIN_FUNC_GPIO); + err = gpio_set_direction(gpioNum, GPIO_MODE_OUTPUT); + if (err != ESP_OK) return false; + gpio_matrix_out(gpioNum, RMT_SIG_OUT0_IDX+channel, 0, 0); + if (err != ESP_OK) return false; + return true; +} #endif //ESP32 diff --git a/DCCRMT.h b/DCCRMT.h index bae4bb9..ff790cd 100644 --- a/DCCRMT.h +++ b/DCCRMT.h @@ -32,6 +32,7 @@ class RMTChannel { public: RMTChannel(byte pin, bool isMain); + bool addPin(byte pin); void IRAM_ATTR RMTinterrupt(); void RMTprefill(); //int RMTfillData(dccPacket packet);