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

shadow PORTX (PoC)

This commit is contained in:
Harald Barth 2022-05-10 23:42:21 +02:00
parent 4a56998553
commit af0d381e45
2 changed files with 38 additions and 4 deletions

View File

@ -28,6 +28,10 @@
bool MotorDriver::usePWM=false;
bool MotorDriver::commonFaultPin=false;
volatile byte fakePORTA;
volatile byte fakePORTB;
volatile byte fakePORTC;
MotorDriver::MotorDriver(VPIN power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin,
byte current_pin, float sense_factor, unsigned int trip_milliamps, byte fault_pin) {
powerPin=power_pin;
@ -37,6 +41,19 @@ MotorDriver::MotorDriver(VPIN power_pin, byte signal_pin, byte signal_pin2, int8
getFastPin(F("SIG"),signalPin,fastSignalPin);
pinMode(signalPin, OUTPUT);
if (fastSignalPin.inout == &PORTA) {
DIAG(F("Found PORTA pin %d"),signalPin);
fastSignalPin.inout = &fakePORTA;
}
if (fastSignalPin.inout == &PORTB) {
DIAG(F("Found PORTB pin %d"),signalPin);
fastSignalPin.inout = &fakePORTB;
}
if (fastSignalPin.inout == &PORTC) {
DIAG(F("Found PORTC pin %d"),signalPin);
fastSignalPin.inout = &fakePORTC;
}
signalPin2=signal_pin2;
if (signalPin2!=UNUSED_PIN) {
dualSignal=true;
@ -50,6 +67,7 @@ MotorDriver::MotorDriver(VPIN power_pin, byte signal_pin, byte signal_pin2, int8
invertBrake=brake_pin < 0;
brakePin=invertBrake ? 0-brake_pin : brake_pin;
getFastPin(F("BRAKE"),brakePin,fastBrakePin);
// if brake is used for railcom cutout we need to do PORTX register trick here as well
pinMode(brakePin, OUTPUT);
setBrake(true); // start with brake on in case we hace DC stuff going on
}

View File

@ -85,18 +85,34 @@ void TrackManager::addTrack(byte t, MotorDriver* driver) {
track[t]->setPower(POWERMODE::OFF);
}
}
extern byte fakePORTA;
extern byte fakePORTB;
extern byte fakePORTC;
void TrackManager::setDCCSignal( bool on) {
fakePORTA=PORTA;
fakePORTB=PORTB;
fakePORTC=PORTC;
APPLY_BY_MODE(TRACK_MODE_MAIN,setSignal(on));
PORTA=fakePORTA;
PORTB=fakePORTB;
PORTC=fakePORTC;
}
void TrackManager::setCutout( bool on) {
(void) on;
// TODO Cutout needs fake ports as well
// TODO APPLY_BY_MODE(TRACK_MODE_MAIN,setCutout(on));
}
void TrackManager::setPROGSignal( bool on) {
fakePORTA=PORTA;
fakePORTB=PORTB;
fakePORTC=PORTC;
APPLY_BY_MODE(TRACK_MODE_PROG,setSignal(on));
PORTA=fakePORTA;
PORTB=fakePORTB;
PORTC=fakePORTC;
}
void TrackManager::setDCSignal(int16_t cab, byte speedbyte) {