From 114686d124105803c0b81e109812764a41df59f5 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Mon, 15 Nov 2021 23:10:23 +0100 Subject: [PATCH] cleanup comments --- DCCRMT.cpp | 33 ++++++++++----------------------- DCCRMT.h | 3 ++- DCCWaveform.cpp | 2 +- GITHUB_SHA.h | 2 +- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/DCCRMT.cpp b/DCCRMT.cpp index 5287e16..c07805b 100644 --- a/DCCRMT.cpp +++ b/DCCRMT.cpp @@ -21,9 +21,6 @@ #include "DIAG.h" #include "DCCRMT.h" -//#include "soc/periph_defs.h" -//#include "driver/periph_ctrl.h" - #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4,2,0) #error wrong IDF version #endif @@ -82,8 +79,8 @@ RMTPin::RMTPin(byte pin, byte ch, byte plen) { setEOT(idle + 28); // EOT marker // data: max packet size today is 5 + checksum - dataLen = (5+1)*9+2; // Each byte has one bit extra and one 0 bit and one EOF marker - data = (rmt_item32_t*)malloc(dataLen*sizeof(rmt_item32_t)); + maxDataLen = (5+1)*9+2; // Each byte has one bit extra and one 0 bit and one EOF marker + data = (rmt_item32_t*)malloc(maxDataLen*sizeof(rmt_item32_t)); rmt_config_t config; // Configure the RMT channel for TX @@ -97,10 +94,6 @@ RMTPin::RMTPin(byte pin, byte ch, byte plen) { // 11*9 + extrazero + EOT = 124 // 2 mem block of 64 RMT items should be enough - // this was not our problem https://esp32.com/viewtopic.php?t=5252 - //periph_module_disable(PERIPH_RMT_MODULE); - //periph_module_enable(PERIPH_RMT_MODULE); - ESP_ERROR_CHECK(rmt_config(&config)); // NOTE: ESP_INTR_FLAG_IRAM is *NOT* included in this bitmask ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, ESP_INTR_FLAG_LOWMED|ESP_INTR_FLAG_SHARED)); @@ -110,11 +103,6 @@ RMTPin::RMTPin(byte pin, byte ch, byte plen) { rmt_register_tx_end_callback(interrupt, this); rmt_set_tx_intr_en(channel, true); - // rmt_set_source_clk() // not needed as APB only supported currently - - - //rmt_register_tx_end_callback() - DIAG(F("Starting channel %d signal generator"), config.channel); // send one bit to kickstart the signal, remaining data will come from the @@ -133,9 +121,13 @@ void RMTPin::RMTprefill() { const byte transmitMask[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; -bool RMTPin::fillData(const byte buffer[], byte byteCount, byte repeatCount=1) { +bool RMTPin::RMTfillData(const byte buffer[], byte byteCount, byte repeatCount=1) { if (dataReady == true || dataRepeat > 0) // we have still old work to do return false; + if (byteCount*9+2 > maxDataLen) // this would overun our allocated memory for data + return false; // something very broken, can not convert packet + + // convert bytes to RMT stream of "bits" byte bitcounter = 0; for(byte n=0; n 0) + if (dataRepeat > 0) // if a repeat count was specified, work on that dataRepeat--; return; } diff --git a/DCCRMT.h b/DCCRMT.h index c197757..2e119e6 100644 --- a/DCCRMT.h +++ b/DCCRMT.h @@ -31,7 +31,7 @@ class RMTPin { RMTPin(byte pin, byte ch, byte plen); void IRAM_ATTR RMTinterrupt(); void RMTprefill(); - bool fillData(const byte buffer[], byte byteCount, byte repeatCount); + bool RMTfillData(const byte buffer[], byte byteCount, byte repeatCount); static RMTPin mainRMTPin; static RMTPin progRMTPin; @@ -47,6 +47,7 @@ class RMTPin { byte preambleLen; rmt_item32_t *data; byte dataLen; + byte maxDataLen; // flags volatile bool preambleNext = true; // alternate between preamble and content volatile bool dataReady = false; // do we have real data available or send idle diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 0e32c70..24f6050 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -65,7 +65,7 @@ volatile bool ackflag = 0; void IRAM_ATTR DCCWaveform::loop(bool ackManagerActive) { if (mainTrack.packetPendingRMT) { - mainTrack.rmtPin->fillData(mainTrack.pendingPacket, mainTrack.pendingLength, mainTrack.pendingRepeats); + mainTrack.rmtPin->RMTfillData(mainTrack.pendingPacket, mainTrack.pendingLength, mainTrack.pendingRepeats); mainTrack.packetPendingRMT=false; // sentResetsSincePacket = 0 // later when progtrack } diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 512e544..c2c1e55 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "ESP32-2021115-22:27" +#define GITHUB_SHA "ESP32-2021115-23:10"