Pin handling supports pins up to 254

This commit is contained in:
Harald Barth 2023-05-21 11:54:46 +02:00
parent 8786285624
commit b80d7bd517
5 changed files with 32 additions and 15 deletions

View File

@ -1 +1 @@
#define GITHUB_SHA "devel-202305202114Z"
#define GITHUB_SHA "devel-202305210948Z"

View File

@ -33,9 +33,10 @@ volatile portreg_t shadowPORTA;
volatile portreg_t shadowPORTB;
volatile portreg_t shadowPORTC;
MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin,
byte current_pin, float sense_factor, unsigned int trip_milliamps, int8_t fault_pin) {
powerPin=power_pin;
MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, int16_t brake_pin,
byte current_pin, float sense_factor, unsigned int trip_milliamps, int16_t fault_pin) {
bool pinWarning = false;
invertPower=power_pin < 0;
if (invertPower) {
powerPin = 0-power_pin;
@ -91,28 +92,38 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
}
else dualSignal=false;
brakePin=brake_pin;
if (brake_pin!=UNUSED_PIN){
invertBrake=brake_pin < 0;
brakePin=invertBrake ? 0-brake_pin : brake_pin;
if (invertBrake)
brake_pin = 0-brake_pin;
if (brake_pin > MAX_PIN)
pinWarning = true;
brakePin=(byte)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
} else {
brakePin=UNUSED_PIN;
}
else brakePin=UNUSED_PIN;
currentPin=current_pin;
if (currentPin!=UNUSED_PIN) ADCee::init(currentPin);
if (currentPin!=UNUSED_PIN)
ADCee::init(currentPin);
senseOffset=0; // value can not be obtained until waveform is activated
faultPin=fault_pin;
if (faultPin != UNUSED_PIN) {
invertFault=fault_pin < 0;
faultPin=invertFault ? 0-fault_pin : fault_pin;
if (invertFault)
fault_pin = 0-fault_pin;
if (fault_pin > MAX_PIN)
pinWarning = true;
faultPin=(byte)fault_pin;
DIAG(F("Fault pin = %d invert %d"), faultPin, invertFault);
getFastPin(F("FAULT"),faultPin, 1 /*input*/, fastFaultPin);
pinMode(faultPin, INPUT);
} else {
faultPin=UNUSED_PIN;
}
// This conversion performed at compile time so the remainder of the code never needs
@ -143,6 +154,10 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
// senseFactorInternal, raw2mA(1000),mA2raw(1000));
}
// give general warning if pin values out of range were encountered
if (pinWarning)
DIAG(F("** WARNING ** Pin values > 255"));
// prepare values for current detection
sampleDelay = 0;
lastSampleTaken = millis();

View File

@ -74,8 +74,9 @@
// Virtualised Motor shield 1-track hardware Interface
#ifndef UNUSED_PIN // sync define with the one in MotorDrivers.h
#define UNUSED_PIN 127 // inside int8_t
#define UNUSED_PIN 255 // inside uint8_t
#endif
#define MAX_PIN 254
class pinpair {
public:
@ -111,8 +112,8 @@ enum class POWERMODE : byte { OFF, ON, OVERLOAD };
class MotorDriver {
public:
MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin,
byte current_pin, float senseFactor, unsigned int tripMilliamps, int8_t fault_pin);
MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, int16_t brake_pin,
byte current_pin, float senseFactor, unsigned int tripMilliamps, int16_t fault_pin);
void setPower( POWERMODE mode);
POWERMODE getPower() { return powerMode;}
// as the port registers can be shadowed to get syncronized DCC signals

View File

@ -36,7 +36,7 @@
// custom defines in config.h.
#ifndef UNUSED_PIN // sync define with the one in MotorDriver.h
#define UNUSED_PIN 127 // inside int8_t
#define UNUSED_PIN 255 // inside uint8_t
#endif
// The MotorDriver definition is:

View File

@ -4,7 +4,8 @@
#include "StringFormatter.h"
#define VERSION "4.2.53"
#define VERSION "4.2.54pre1"
// 4.2.54 - Fix: Pin handling supports pins up to 254
// 4.2.53 - Fix: Fault pin handling made more straight forward
// 4.2.52 - Experimental support for sabertooth motor controller on ESP32
// 4.2.51 - Add DISABLE_PROG to disable programming to save RAM/Flash