1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-24 13:21:23 +01:00

Merge branch 'devel-railcom2' of https://github.com/DCC-EX/CommandStation-EX into devel-railcom2

This commit is contained in:
Asbelos 2024-09-28 20:58:44 +01:00
commit d8635de854
8 changed files with 51 additions and 49 deletions

View File

@ -1121,7 +1121,7 @@ bool DCCEXParser::parseC(Print *stream, int16_t params, int16_t p[]) {
DCC::setGlobalSpeedsteps(128);
DIAG(F("128 Speedsteps"));
return true;
#if defined(HAS_ENOUGH_MEMORY) && !defined(ARDUINO_ARCH_UNO)
#if defined(HAS_ENOUGH_MEMORY) && !defined(ARDUINO_ARCH_UNO) && !defined(ARDUINO_ARCH_ESP32)
case "RAILCOM"_hk:
{ // <C RAILCOM ON|OFF|DEBUG >
if (params<2) return false;

View File

@ -84,7 +84,7 @@ void IRAM_ATTR interrupt(rmt_channel_t channel, void *t) {
DCCTimer::updateMinimumFreeMemoryISR(0);
}
RMTChannel::RMTChannel(pinpair pins, bool isMain) {
RMTChannel::RMTChannel(Pinpair pins, bool isMain) {
byte ch;
byte plen;
@ -253,7 +253,7 @@ bool RMTChannel::addPin(byte pin, bool inverted) {
if (err != ESP_OK) return false;
return true;
}
bool RMTChannel::addPin(pinpair pins) {
bool RMTChannel::addPin(Pinpair pins) {
return addPin(pins.pin) && addPin(pins.invpin, true);
}
#endif //ESP32

View File

@ -23,7 +23,7 @@
#include "driver/rmt.h"
#include "soc/rmt_reg.h"
#include "soc/rmt_struct.h"
#include "MotorDriver.h" // for class pinpair
#include "Pinpair.h" // for class Pinpair
// make calculations easy and set up for microseconds
#define RMT_CLOCK_DIVIDER 80
@ -32,9 +32,9 @@
class RMTChannel {
public:
RMTChannel(pinpair pins, bool isMain);
RMTChannel(Pinpair pins, bool isMain);
bool addPin(byte pin, bool inverted=0);
bool addPin(pinpair pins);
bool addPin(Pinpair pins);
void IRAM_ATTR RMTinterrupt();
void RMTprefill();
//int RMTfillData(dccPacket packet);

View File

@ -126,22 +126,6 @@ volatile bool DCCWaveform::railcomActive=false; // switched on by user
volatile bool DCCWaveform::railcomDebug=false; // switched on by user
volatile bool DCCWaveform::railcomSampleWindow=false; // true during packet transmit
bool DCCWaveform::isRailcom() {
return railcomActive;
}
bool DCCWaveform::isRailcomSampleWindow() {
return railcomSampleWindow;
}
bool DCCWaveform::isRailcomPossible() {
return railcomPossible;
}
void DCCWaveform::setRailcomPossible(bool yes) {
railcomPossible=yes;
if (!yes) setRailcom(false,false);
}
bool DCCWaveform::setRailcom(bool on, bool debug) {
if (on && railcomPossible) {
// TODO check possible
@ -179,9 +163,12 @@ void DCCWaveform::interrupt2() {
if (remainingPreambles==1) promotePendingPacket();
else if (isMainTrack && railcomActive) {
// cutout has ended so its now possible to poll the railcom detectors
if (remainingPreambles==5) railcomSampleWindow=true;
// requiredPreambles is one higher that preamble length so
// if preamble length is 16 then this evaluates to 5
if (remainingPreambles==(requiredPreambles-12)) railcomSampleWindow=true;
// cutout can be ended when read
else if (remainingPreambles==14) DCCTimer::ackRailcomTimer();
// see above for requiredPreambles
else if (remainingPreambles==(requiredPreambles-3)) DCCTimer::ackRailcomTimer();
}
// Update free memory diagnostic as we don't have anything else to do this time.
// Allow for checkAck and its called functions using 22 bytes more.
@ -266,11 +253,13 @@ void DCCWaveform::promotePendingPacket() {
transmitRepeats = 0;
if (getResets() < 250) sentResetsSincePacket++; // only place to increment (private!)
}
#endif
#endif //not ARDUINO_ARCH_ESP32
#ifdef ARDUINO_ARCH_ESP32
#include "DCCWaveform.h"
#include "TrackManager.h"
#include "DCCACK.h"
#include "Pinpair.h"
DCCWaveform DCCWaveform::mainTrack(PREAMBLE_BITS_MAIN, true);
DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false);
@ -283,7 +272,7 @@ DCCWaveform::DCCWaveform(byte preambleBits, bool isMain) {
}
void DCCWaveform::begin() {
for(const auto& md: TrackManager::getMainDrivers()) {
pinpair p = md->getSignalPin();
Pinpair p = md->getSignalPin();
if(rmtMainChannel) {
//DIAG(F("added pins %d %d to MAIN channel"), p.pin, p.invpin);
rmtMainChannel->addPin(p); // add pin to existing main channel
@ -294,7 +283,7 @@ void DCCWaveform::begin() {
}
MotorDriver *md = TrackManager::getProgDriver();
if (md) {
pinpair p = md->getSignalPin();
Pinpair p = md->getSignalPin();
if (rmtProgChannel) {
//DIAG(F("added pins %d %d to PROG channel"), p.pin, p.invpin);
rmtProgChannel->addPin(p); // add pin to existing prog channel
@ -352,7 +341,9 @@ void IRAM_ATTR DCCWaveform::loop() {
}
bool DCCWaveform::setRailcom(bool on, bool debug) {
// TODO... ESP32 railcom waveform
// todo
(void)on;
(void)debug;
return false;
}

View File

@ -25,7 +25,7 @@
#define DCCWaveform_h
#ifdef ARDUINO_ARCH_ESP32
#include "DCCRMT.h"
#include "TrackManager.h"
//#include "TrackManager.h"
#endif
@ -84,10 +84,19 @@ class DCCWaveform {
bool isReminderWindowOpen();
void promotePendingPacket();
static bool setRailcom(bool on, bool debug);
static bool isRailcom();
static bool isRailcomSampleWindow();
static bool isRailcomPossible();
static void setRailcomPossible(bool yes);
inline static bool isRailcom() {
return railcomActive;
};
inline static bool isRailcomSampleWindow() {
return railcomSampleWindow;
};
inline static bool isRailcomPossible() {
return railcomPossible;
};
inline static void setRailcomPossible(bool yes) {
railcomPossible=yes;
if (!yes) setRailcom(false,false);
};
private:
#ifndef ARDUINO_ARCH_ESP32
volatile bool packetPending;

View File

@ -124,21 +124,9 @@ enum TRACK_MODE : byte {TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PRO
// Virtualised Motor shield 1-track hardware Interface
#ifndef UNUSED_PIN // sync define with the one in MotorDrivers.h
#define UNUSED_PIN 255 // inside uint8_t
#endif
#include "Pinpair.h" // for class Pinpair
#define MAX_PIN 254
class pinpair {
public:
pinpair(byte p1, byte p2) {
pin = p1;
invpin = p2;
};
byte pin = UNUSED_PIN;
byte invpin = UNUSED_PIN;
};
#if defined(__IMXRT1062__) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32)
typedef uint32_t portreg_t;
#else
@ -209,7 +197,7 @@ class MotorDriver {
pinMode(signalPin2, INPUT);
}
};
inline pinpair getSignalPin() { return pinpair(signalPin,signalPin2); };
inline Pinpair getSignalPin() { return Pinpair(signalPin,signalPin2); };
inline int8_t getBrakePinSigned() { return invertBrake ? -brakePin : brakePin; };
void setDCSignal(byte speedByte, uint8_t frequency=0);
void throttleInrush(bool on);
@ -285,7 +273,7 @@ class MotorDriver {
else
invertPhase = 0;
#if defined(ARDUINO_ARCH_ESP32)
pinpair p = getSignalPin();
Pinpair p = getSignalPin();
uint32_t *outreg = (uint32_t *)(GPIO_FUNC0_OUT_SEL_CFG_REG + 4*p.pin);
if (invertPhase) // set or clear the invert bit in the gpio out register
*outreg |= ((uint32_t)0x1 << GPIO_FUNC0_OUT_INV_SEL_S);

14
Pinpair.h Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#ifndef UNUSED_PIN // sync define with the one in MotorDrivers.h
#define UNUSED_PIN 255 // inside uint8_t
#endif
class Pinpair {
public:
Pinpair(byte p1, byte p2) {
pin = p1;
invpin = p2;
};
byte pin = UNUSED_PIN;
byte invpin = UNUSED_PIN;
};

View File

@ -218,7 +218,7 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
#ifdef ARDUINO_ARCH_ESP32
// remove pin from MUX matrix and turn it off
pinpair p = track[trackToSet]->getSignalPin();
Pinpair p = track[trackToSet]->getSignalPin();
//DIAG(F("Track=%c remove pin %d"),trackToSet+'A', p.pin);
gpio_reset_pin((gpio_num_t)p.pin);
if (p.invpin != UNUSED_PIN) {