1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-30 03:26:13 +01:00

use ugly macros to make PORTX code portable

This commit is contained in:
Harald Barth 2022-05-13 00:05:25 +02:00
parent af0d381e45
commit d7a17b10b4
3 changed files with 43 additions and 16 deletions

View File

@ -41,15 +41,15 @@ MotorDriver::MotorDriver(VPIN power_pin, byte signal_pin, byte signal_pin2, int8
getFastPin(F("SIG"),signalPin,fastSignalPin);
pinMode(signalPin, OUTPUT);
if (fastSignalPin.inout == &PORTA) {
if (HAVE_PORTA(fastSignalPin.inout == &PORTA)) {
DIAG(F("Found PORTA pin %d"),signalPin);
fastSignalPin.inout = &fakePORTA;
}
if (fastSignalPin.inout == &PORTB) {
if (HAVE_PORTB(fastSignalPin.inout == &PORTB)) {
DIAG(F("Found PORTB pin %d"),signalPin);
fastSignalPin.inout = &fakePORTB;
}
if (fastSignalPin.inout == &PORTC) {
if (HAVE_PORTC(fastSignalPin.inout == &PORTC)) {
DIAG(F("Found PORTC pin %d"),signalPin);
fastSignalPin.inout = &fakePORTC;
}

View File

@ -30,6 +30,31 @@
#define isHIGH(fastpin) (*fastpin.inout & fastpin.maskHIGH)
#define isLOW(fastpin) (!isHIGH(fastpin))
#define TOKENPASTE(x, y) x ## y
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
#if defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560)
#define HAVE_PORTA(X) X
#define HAVE_PORTB(X) X
#define HAVE_PORTC(X) X
#endif
#if defined(ARDUINO_AVR_UNO)
#define HAVE_PORTB(X) X
#endif
// if macros not defined as pass-through we define
// them here as someting that is valid as a
// statement and evaluates to false.
#ifndef HAVE_PORTA
#define HAVE_PORTA(X) byte TOKENPASTE2(Unique_, __LINE__) __attribute__((unused)) =0
#endif
#ifndef HAVE_PORTB
#define HAVE_PORTB(X) byte TOKENPASTE2(Unique_, __LINE__) __attribute__((unused)) =0
#endif
#ifndef HAVE_PORTC
#define HAVE_PORTC(X) byte TOKENPASTE2(Unique_, __LINE__) __attribute__((unused)) =0
#endif
// Virtualised Motor shield 1-track hardware Interface
#ifndef UNUSED_PIN // sync define with the one in MotorDrivers.h

View File

@ -84,19 +84,21 @@ void TrackManager::addTrack(byte t, MotorDriver* driver) {
lastTrack=t;
track[t]->setPower(POWERMODE::OFF);
}
}
}
// defined in Motordriver.cpp
extern byte fakePORTA;
extern byte fakePORTB;
extern byte fakePORTC;
void TrackManager::setDCCSignal( bool on) {
fakePORTA=PORTA;
fakePORTB=PORTB;
fakePORTC=PORTC;
HAVE_PORTA(fakePORTA=PORTA);
HAVE_PORTB(fakePORTB=PORTB);
HAVE_PORTC(fakePORTC=PORTC);
APPLY_BY_MODE(TRACK_MODE_MAIN,setSignal(on));
PORTA=fakePORTA;
PORTB=fakePORTB;
PORTC=fakePORTC;
HAVE_PORTA(PORTA=fakePORTA);
HAVE_PORTB(PORTB=fakePORTB);
HAVE_PORTC(PORTC=fakePORTC);
}
void TrackManager::setCutout( bool on) {
@ -106,13 +108,13 @@ void TrackManager::setCutout( bool on) {
}
void TrackManager::setPROGSignal( bool on) {
fakePORTA=PORTA;
fakePORTB=PORTB;
fakePORTC=PORTC;
HAVE_PORTA(fakePORTA=PORTA);
HAVE_PORTB(fakePORTB=PORTB);
HAVE_PORTC(fakePORTC=PORTC);
APPLY_BY_MODE(TRACK_MODE_PROG,setSignal(on));
PORTA=fakePORTA;
PORTB=fakePORTB;
PORTC=fakePORTC;
HAVE_PORTA(PORTA=fakePORTA);
HAVE_PORTB(PORTB=fakePORTB);
HAVE_PORTC(PORTC=fakePORTC);
}
void TrackManager::setDCSignal(int16_t cab, byte speedbyte) {