mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 17:46:14 +01:00
Make Raicom code compile on ESP32 by moving out class Pinpair
This commit is contained in:
parent
77de250996
commit
cbec612b0f
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
6
DCCRMT.h
6
DCCRMT.h
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
@ -266,11 +250,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 +269,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 +280,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 +338,9 @@ void IRAM_ATTR DCCWaveform::loop() {
|
|||
}
|
||||
|
||||
bool DCCWaveform::setRailcom(bool on, bool debug) {
|
||||
// TODO... ESP32 railcom waveform
|
||||
// todo
|
||||
(void)on;
|
||||
(void)debug;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
14
Pinpair.h
Normal 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;
|
||||
};
|
||||
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user