From 97065e892dedcbc04130803b700fa83783c5c893 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sun, 14 Nov 2021 14:48:32 +0100 Subject: [PATCH] transmit preamble and idle --- DCCRMT.cpp | 64 ++++++++++++++++++++----------------------------- DCCRMT.h | 4 ++-- DCCWaveform.cpp | 3 --- 3 files changed, 28 insertions(+), 43 deletions(-) diff --git a/DCCRMT.cpp b/DCCRMT.cpp index 5186ecf..abe1cf8 100644 --- a/DCCRMT.cpp +++ b/DCCRMT.cpp @@ -41,34 +41,37 @@ void setDCCBit0(rmt_item32_t* item) { item->duration1 = DCC_0_HALFPERIOD; } +void setEOT(rmt_item32_t* item) { + item->val = 0; +} + void IRAM_ATTR interrupt(rmt_channel_t channel, void *t) { - BaseType_t wtf = pdFALSE; RMTPin *tt = (RMTPin *)t; - //DIAG(F("interrupt %d"), tt->idleLen); - tt->RMTinterrupt(channel,t); - rmt_tx_start(channel,true); - portYIELD_FROM_ISR(wtf); + tt->RMTinterrupt(channel); } RMTPin::RMTPin(byte pin, byte ch, byte plen) { // preamble - preambleLen = plen+1; + preambleLen = plen+2; // plen 1 bits, one 0 bit and one EOF marker preamble = (rmt_item32_t*)malloc(preambleLen*sizeof(rmt_item32_t)); for (byte n=0; npreambleNext) { - rmt_fill_tx_items(channel, obj->preamble, obj->preambleLen, 0); - //obj->preambleNext = false; +void IRAM_ATTR RMTPin::RMTinterrupt(rmt_channel_t channel) { + + if (preambleNext) { + rmt_fill_tx_items(channel, preamble, preambleLen, 0); + preambleNext = false; } else { - if (obj->dataNext) { - rmt_fill_tx_items(channel, obj->packetBits, obj->packetLen, 0); + if (dataNext) { + rmt_fill_tx_items(channel, packetBits, packetLen, 0); } else { // here we should not get as now we need to send idle packet - rmt_fill_tx_items(channel, obj->idle, obj->idleLen, 0); + rmt_fill_tx_items(channel, idle, idleLen, 0); } - obj->preambleNext = true; + preambleNext = true; } rmt_tx_start(channel,true); - DIAG(F("START")); - */ } diff --git a/DCCRMT.h b/DCCRMT.h index 58f77de..78eaaa3 100644 --- a/DCCRMT.h +++ b/DCCRMT.h @@ -29,12 +29,12 @@ class RMTPin { public: RMTPin(byte pin, byte ch, byte plen); - void IRAM_ATTR RMTinterrupt(rmt_channel_t, void *t); + void IRAM_ATTR RMTinterrupt(rmt_channel_t); static RMTPin mainRMTPin; static RMTPin progRMTPin; - // private: + private: rmt_channel_t channel; // 3 types of data to send, preamble and then idle or data diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 505583f..ee3e9f1 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -51,14 +51,11 @@ void DCCWaveform::begin(MotorDriver * mainDriver, MotorDriver * progDriver) { && (mainDriver->getFaultPin() != UNUSED_PIN)); // Only use PWM if both pins are PWM capable. Otherwise JOIN does not work MotorDriver::usePWM= mainDriver->isPWMCapable() && progDriver->isPWMCapable(); - /* if (MotorDriver::usePWM) DIAG(F("Signal pin config: high accuracy waveform")); else DIAG(F("Signal pin config: normal accuracy waveform")); DCCTimer::begin(DCCWaveform::interruptHandler); - */ - DIAG(F("No waveform")); } #ifdef SLOW_ANALOG_READ