diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 78b65c0..c5dc455 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "PORTX-HAL-20220817-1" +#define GITHUB_SHA "PORTX-HAL-20220823" diff --git a/MotorDriver.cpp b/MotorDriver.cpp index 8901fba..3bbf6d3 100644 --- a/MotorDriver.cpp +++ b/MotorDriver.cpp @@ -239,20 +239,29 @@ void MotorDriver::setDCSignal(byte speedcode) { if (invertBrake) brake=255-brake; analogWrite(brakePin,brake); + //DIAG(F("DCSignal %d"), speedcode); if (HAVE_PORTA(fastSignalPin.shadowinout == &PORTA)) { + noInterrupts(); HAVE_PORTA(shadowPORTA=PORTA); setSignal(tDir); HAVE_PORTA(PORTA=shadowPORTA); + interrupts(); } else if (HAVE_PORTB(fastSignalPin.shadowinout == &PORTB)) { + noInterrupts(); HAVE_PORTB(shadowPORTB=PORTB); setSignal(tDir); HAVE_PORTB(PORTB=shadowPORTB); + interrupts(); } else if (HAVE_PORTC(fastSignalPin.shadowinout == &PORTC)) { + noInterrupts(); HAVE_PORTC(shadowPORTC=PORTC); setSignal(tDir); HAVE_PORTC(PORTC=shadowPORTC); + interrupts(); } else { + noInterrupts(); setSignal(tDir); + interrupts(); } } diff --git a/MotorDriver.h b/MotorDriver.h index 1f97cfe..9609832 100644 --- a/MotorDriver.h +++ b/MotorDriver.h @@ -121,8 +121,7 @@ class MotorDriver { // otherwise the call from interrupt context can undo whatever we do // from outside interrupt void setBrake( bool on, bool interruptContext=false); - __attribute__((always_inline)) inline void setSignal( bool high, bool interruptContext=false) { - if (!interruptContext) {noInterrupts();} + __attribute__((always_inline)) inline void setSignal( bool high) { if (trackPWM) { DCCTimer::setPWM(signalPin,high); } @@ -136,7 +135,6 @@ class MotorDriver { if (dualSignal) setHIGH(fastSignalPin2); } } - if (!interruptContext) {interrupts();} }; inline void enableSignal(bool on) { if (on) diff --git a/TrackManager.cpp b/TrackManager.cpp index dd9ad64..9a3952c 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -95,7 +95,7 @@ void TrackManager::setDCCSignal( bool on) { HAVE_PORTA(shadowPORTA=PORTA); HAVE_PORTB(shadowPORTB=PORTB); HAVE_PORTC(shadowPORTC=PORTC); - APPLY_BY_MODE(TRACK_MODE_MAIN,setSignal(on, true)); + APPLY_BY_MODE(TRACK_MODE_MAIN,setSignal(on)); HAVE_PORTA(PORTA=shadowPORTA); HAVE_PORTB(PORTB=shadowPORTB); HAVE_PORTC(PORTC=shadowPORTC); @@ -113,7 +113,7 @@ void TrackManager::setPROGSignal( bool on) { HAVE_PORTA(shadowPORTA=PORTA); HAVE_PORTB(shadowPORTB=PORTB); HAVE_PORTC(shadowPORTC=PORTC); - APPLY_BY_MODE(TRACK_MODE_PROG,setSignal(on, true)); + APPLY_BY_MODE(TRACK_MODE_PROG,setSignal(on)); HAVE_PORTA(PORTA=shadowPORTA); HAVE_PORTB(PORTB=shadowPORTB); HAVE_PORTC(PORTC=shadowPORTC); @@ -169,17 +169,11 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr trackDCAddr[trackToSet]=dcAddr; // When a track is switched, we must clear any side effects of its previous - // state, otherwise trains run away or just dont move. - if (mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX) { - // DC tracks need to be given speed of the throttle for that cab address - // otherwise will not match other tracks on same cab. - // This also needs to allow for inverted DCX - applyDCSpeed(trackToSet); - - } - else { + // state, otherwise trains run away or just dont move. + + // This can be done BEFORE the PWM-Timer evaluation (methinks) + if (!(mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX)) { // DCC tracks need to have set the PWM to zero or they will not work. - // 128 is speed=0 and dir=0 and then loosen brake. track[trackToSet]->detachDCSignal(); track[trackToSet]->setBrake(false); } @@ -221,9 +215,18 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr DCCTimer::clearPWM(); // has to be AFTER trackPWM changes because if trackPWM==true this is undone for that track } #else + // For ESP32 we just reinitialize the DCC Waveform DCCWaveform::begin(); #endif - + + // This block must be AFTER the PWM-Timer modifications + if (mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX) { + // DC tracks need to be given speed of the throttle for that cab address + // otherwise will not match other tracks on same cab. + // This also needs to allow for inverted DCX + applyDCSpeed(trackToSet); + } + // Normal running tracks are set to the global power state track[trackToSet]->setPower( (mode==TRACK_MODE_MAIN || mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX || mode==TRACK_MODE_EXT) ? diff --git a/version.h b/version.h index 6e743e1..ac1f5ea 100644 --- a/version.h +++ b/version.h @@ -4,7 +4,12 @@ #include "StringFormatter.h" -#define VERSION "4.2.2 rc1" +#define VERSION "4.2.3 rc1" +// 4.2.3 Bugfix direction when togging between MAIN and DC +// Bugfix return fail when F/f argument out of range +// More error checking for out of bounds motor driver current trip limit +// 4.2.2 ESP32 beta +// JOIN/UMJOIN on ESP32 // 4.2.1 ESP32 alpha // Ready for alpha test on ESP32. Track switching with <=> untested // Send DCC signal on MAIN