/* * © 2021, Harald Barth. * * This file is part of DCC-EX * * This is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * It is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with CommandStation. If not, see . */ #include "config.h" #include "defines.h" #if defined(ARDUINO_ARCH_ESP32) #include "DIAG.h" #include "DCCRMT.h" #include "DCCWaveform.h" // for MAX_PACKET_SIZE #include "soc/gpio_sig_map.h" #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 #endif void setDCCBit1(rmt_item32_t* item) { item->level0 = 1; item->duration0 = DCC_1_HALFPERIOD; item->level1 = 0; item->duration1 = DCC_1_HALFPERIOD; } void setDCCBit0(rmt_item32_t* item) { item->level0 = 1; item->duration0 = DCC_0_HALFPERIOD; item->level1 = 0; item->duration1 = DCC_0_HALFPERIOD; } // 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 + DCC_0_HALFPERIOD/10; } void setEOT(rmt_item32_t* item) { item->val = 0; } void IRAM_ATTR interrupt(rmt_channel_t channel, void *t) { RMTChannel *tt = (RMTChannel *)t; tt->RMTinterrupt(); } RMTChannel::RMTChannel(byte pin, byte ch, byte plen) { // preamble 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; n 0) // we have still old work to do return false; if (DATA_LEN(packet.length) > maxDataLen) { // this would overun our allocated memory for data DIAG(F("Can not convert DCC bytes # %d to DCC bits %d, buffer too small"), packet.length, maxDataLen); return false; // something very broken, can not convert packet } byte *buffer = packet.data; // convert bytes to RMT stream of "bits" byte bitcounter = 0; for(byte n=0; n 0) // if a repeat count was specified, work on that dataRepeat--; return; } #endif //ESP32