From 50b854c5266d02ec9ff9fa0d5715f89347d2c6b6 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 19 Nov 2021 00:34:56 +0100 Subject: [PATCH] remove extra zero bit --- DCCRMT.cpp | 25 ++++++++++++++++--------- GITHUB_SHA.h | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/DCCRMT.cpp b/DCCRMT.cpp index a0d8756..a561917 100644 --- a/DCCRMT.cpp +++ b/DCCRMT.cpp @@ -17,9 +17,13 @@ * along with CommandStation. If not, see . */ +#include "config.h" #include "defines.h" #include "DIAG.h" #include "DCCRMT.h" +#include "DCCWaveform.h" // for MAX_PACKET_SIZE + +#define DATA_LEN(X) ((X)*9+1) // Each byte has one bit extra and we have one EOF marker #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4,2,0) #error wrong IDF version @@ -39,11 +43,12 @@ void setDCCBit0(rmt_item32_t* item) { item->duration1 = DCC_0_HALFPERIOD; } -void setDCCBit0Last(rmt_item32_t* item) { +// special long zero to trigger scope +void setDCCBit0Long(rmt_item32_t* item) { item->level0 = 1; item->duration0 = DCC_0_HALFPERIOD + DCC_0_HALFPERIOD/10; item->level1 = 0; - item->duration1 = DCC_0_HALFPERIOD; + item->duration1 = DCC_0_HALFPERIOD + DCC_0_HALFPERIOD/10; } void setEOT(rmt_item32_t* item) { @@ -62,11 +67,15 @@ RMTPin::RMTPin(byte pin, byte ch, byte plen) { preamble = (rmt_item32_t*)malloc(preambleLen*sizeof(rmt_item32_t)); for (byte n=0; n 0) // we have still old work to do return false; - if (byteCount*9+2 > maxDataLen) // this would overun our allocated memory for data + if (DATA_LEN(byteCount) > 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" @@ -140,7 +148,6 @@ bool RMTPin::RMTfillData(const byte buffer[], byte byteCount, byte repeatCount=1 setDCCBit0(data + bitcounter++); // zero at end of each byte } setDCCBit1(data + bitcounter-1); // overwrite previous zero bit with one bit - setDCCBit0Last(data + bitcounter++); // extra 0 bit after end bit setEOT(data + bitcounter++); // EOT marker dataLen = bitcounter; dataReady = true; diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index c2c1e55..6bcd087 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "ESP32-2021115-23:10" +#define GITHUB_SHA "ESP32-2021119-00:26"