mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 16:16:13 +01:00
Compare commits
No commits in common. "7b77d4ce1e9d679cf703da37ac91221a9f57e54b" and "cff407593713f09fdc6d701c3aba742dba49f786" have entirely different histories.
7b77d4ce1e
...
cff4075937
|
@ -65,12 +65,10 @@ class DCCTimer {
|
|||
static void startRailcomTimer(byte brakePin);
|
||||
static void ackRailcomTimer();
|
||||
static void DCCEXanalogWriteFrequency(uint8_t pin, uint32_t frequency);
|
||||
static void DCCEXanalogWrite(uint8_t pin, int value, bool invert);
|
||||
static void DCCEXanalogWrite(uint8_t pin, int value);
|
||||
static void DCCEXledcDetachPin(uint8_t pin);
|
||||
static void DCCEXanalogCopyChannel(int8_t frompin, int8_t topin);
|
||||
static void DCCEXInrushControlOn(uint8_t pin, int duty, bool invert);
|
||||
static void DCCEXledcAttachPin(uint8_t pin, int8_t channel, bool inverted);
|
||||
|
||||
static void DCCEXanalogCopyChannel(uint8_t frompin, uint8_t topin);
|
||||
static void DCCEXInrushControlOn(uint8_t pin, int duty);
|
||||
// Update low ram level. Allow for extra bytes to be specified
|
||||
// by estimation or inspection, that may be used by other
|
||||
// called subroutines. Must be called with interrupts disabled.
|
||||
|
|
|
@ -197,48 +197,13 @@ void DCCTimer::DCCEXledcDetachPin(uint8_t pin) {
|
|||
pinMatrixOutDetach(pin, false, false);
|
||||
}
|
||||
|
||||
static byte LEDCToMux[] = {
|
||||
LEDC_HS_SIG_OUT0_IDX,
|
||||
LEDC_HS_SIG_OUT1_IDX,
|
||||
LEDC_HS_SIG_OUT2_IDX,
|
||||
LEDC_HS_SIG_OUT3_IDX,
|
||||
LEDC_HS_SIG_OUT4_IDX,
|
||||
LEDC_HS_SIG_OUT5_IDX,
|
||||
LEDC_HS_SIG_OUT6_IDX,
|
||||
LEDC_HS_SIG_OUT7_IDX,
|
||||
LEDC_LS_SIG_OUT0_IDX,
|
||||
LEDC_LS_SIG_OUT1_IDX,
|
||||
LEDC_LS_SIG_OUT2_IDX,
|
||||
LEDC_LS_SIG_OUT3_IDX,
|
||||
LEDC_LS_SIG_OUT4_IDX,
|
||||
LEDC_LS_SIG_OUT5_IDX,
|
||||
LEDC_LS_SIG_OUT6_IDX,
|
||||
LEDC_LS_SIG_OUT7_IDX,
|
||||
};
|
||||
|
||||
void DCCTimer::DCCEXledcAttachPin(uint8_t pin, int8_t channel, bool inverted) {
|
||||
DIAG(F("Attaching pin %d to channel %d %c"), pin, channel, inverted ? 'I' : ' ');
|
||||
ledcAttachPin(pin, channel);
|
||||
if (inverted) // we attach again but with inversion
|
||||
gpio_matrix_out(pin, LEDCToMux[channel], inverted, 0);
|
||||
void DCCTimer::DCCEXanalogCopyChannel(uint8_t frompin, uint8_t topin) {
|
||||
DIAG(F("Pin %d copied to %d channel %d"), frompin, topin, pin_to_channel[frompin]);
|
||||
pin_to_channel[topin] = pin_to_channel[frompin];
|
||||
ledcAttachPin(topin, pin_to_channel[topin]);
|
||||
}
|
||||
|
||||
void DCCTimer::DCCEXanalogCopyChannel(int8_t frompin, int8_t topin) {
|
||||
// arguments are signed depending on inversion of pins
|
||||
DIAG(F("Pin %d copied to %d"), frompin, topin);
|
||||
bool inverted = false;
|
||||
if (frompin<0)
|
||||
frompin = -frompin;
|
||||
if (topin<0) {
|
||||
inverted = true;
|
||||
topin = -topin;
|
||||
}
|
||||
int channel = pin_to_channel[frompin]; // after abs(frompin)
|
||||
pin_to_channel[topin] = channel;
|
||||
DCCTimer::DCCEXledcAttachPin(topin, channel, inverted);
|
||||
}
|
||||
|
||||
void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value, bool invert) {
|
||||
void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value) {
|
||||
// This allocates channels 15, 13, 11, ....
|
||||
// so each channel gets its own timer.
|
||||
if (pin < SOC_GPIO_PIN_COUNT) {
|
||||
|
@ -272,20 +237,17 @@ void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value, bool invert) {
|
|||
--cnt_channel; // Now we are at 14, 12, ...
|
||||
}
|
||||
ledcSetup(pin_to_channel[pin], 1000, 8);
|
||||
DCCEXledcAttachPin(pin, pin_to_channel[pin], invert);
|
||||
ledcAttachPin(pin, pin_to_channel[pin]);
|
||||
} else {
|
||||
// This else is only here so we can enable diag
|
||||
// Pin should be already attached to channel
|
||||
// DIAG(F("Pin %d assigned to old channel %d"), pin, pin_to_channel[pin]);
|
||||
//DIAG(F("Pin %d assigned to old channel %d"), pin, pin_to_channel[pin]);
|
||||
ledcAttachPin(pin, pin_to_channel[pin]);
|
||||
}
|
||||
ledcWrite(pin_to_channel[pin], value);
|
||||
}
|
||||
}
|
||||
|
||||
void DCCTimer::DCCEXInrushControlOn(uint8_t pin, int duty, bool inverted) {
|
||||
// this uses hardcoded channel 0
|
||||
void DCCTimer::DCCEXInrushControlOn(uint8_t pin, int duty) {
|
||||
ledcSetup(0, 62500, 8);
|
||||
DCCEXledcAttachPin(pin, 0, inverted);
|
||||
ledcAttachPin(pin, 0);
|
||||
ledcWrite(0, duty);
|
||||
}
|
||||
|
||||
|
|
|
@ -333,9 +333,7 @@ void DCCTimer::DCCEXanalogWriteFrequencyInternal(uint8_t pin, uint32_t frequency
|
|||
return;
|
||||
}
|
||||
|
||||
void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value, bool invert) {
|
||||
if (invert)
|
||||
value = 255-value;
|
||||
void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value) {
|
||||
// Calculate percentage duty cycle from value given
|
||||
uint32_t duty_cycle = (value * 100 / 256) + 1;
|
||||
if (pin_timer[pin] != NULL) {
|
||||
|
|
|
@ -1 +1 @@
|
|||
#define GITHUB_SHA "devel-202404051206Z"
|
||||
#define GITHUB_SHA "devel-202404042311Z"
|
||||
|
|
|
@ -336,6 +336,8 @@ void MotorDriver::setDCSignal(byte speedcode, uint8_t frequency /*default =0*/)
|
|||
if (tSpeed <= 1) brake = 255;
|
||||
else if (tSpeed >= 127) brake = 0;
|
||||
else brake = 2 * (128-tSpeed);
|
||||
if (invertBrake)
|
||||
brake=255-brake;
|
||||
|
||||
{ // new block because of variable f
|
||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_STM32)
|
||||
|
@ -349,10 +351,10 @@ void MotorDriver::setDCSignal(byte speedcode, uint8_t frequency /*default =0*/)
|
|||
#endif
|
||||
//DIAG(F("Brake pin %d freqency %d"), brakePin, f);
|
||||
DCCTimer::DCCEXanalogWriteFrequency(brakePin, f); // set DC PWM frequency
|
||||
DCCTimer::DCCEXanalogWrite(brakePin, brake, invertBrake);
|
||||
DCCTimer::DCCEXanalogWrite(brakePin,brake);
|
||||
#else // all AVR here
|
||||
DCCTimer::DCCEXanalogWriteFrequency(brakePin, frequency); // frequency steps
|
||||
analogWrite(brakePin, invertBrake ? 255-brake : brake);
|
||||
analogWrite(brakePin,brake);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -405,9 +407,11 @@ void MotorDriver::throttleInrush(bool on) {
|
|||
if ( !(trackMode & (TRACK_MODE_MAIN | TRACK_MODE_PROG | TRACK_MODE_EXT | TRACK_MODE_BOOST)))
|
||||
return;
|
||||
byte duty = on ? 207 : 0; // duty of 81% at 62500Hz this gives pauses of 3usec
|
||||
if (invertBrake)
|
||||
duty = 255-duty;
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
if(on) {
|
||||
DCCTimer::DCCEXInrushControlOn(brakePin, duty, invertBrake);
|
||||
DCCTimer::DCCEXInrushControlOn(brakePin, duty);
|
||||
} else {
|
||||
ledcDetachPin(brakePin); // not DCCTimer::DCCEXledcDetachPin() as we have not
|
||||
// registered the pin in the pin to channel array
|
||||
|
@ -415,13 +419,11 @@ void MotorDriver::throttleInrush(bool on) {
|
|||
#elif defined(ARDUINO_ARCH_STM32)
|
||||
if(on) {
|
||||
DCCTimer::DCCEXanalogWriteFrequency(brakePin, 7); // 7 means max
|
||||
DCCTimer::DCCEXanalogWrite(brakePin,duty,invertBrake);
|
||||
DCCTimer::DCCEXanalogWrite(brakePin,duty);
|
||||
} else {
|
||||
pinMode(brakePin, OUTPUT);
|
||||
}
|
||||
#else // all AVR here
|
||||
if (invertBrake)
|
||||
duty = 255-duty;
|
||||
if(on){
|
||||
DCCTimer::DCCEXanalogWriteFrequency(brakePin, 7); // 7 means max
|
||||
}
|
||||
|
|
|
@ -193,7 +193,7 @@ class MotorDriver {
|
|||
}
|
||||
};
|
||||
inline pinpair getSignalPin() { return pinpair(signalPin,signalPin2); };
|
||||
inline int8_t getBrakePinSigned() { return invertBrake ? -brakePin : brakePin; };
|
||||
inline byte getBrakePin() { return brakePin; };
|
||||
void setDCSignal(byte speedByte, uint8_t frequency=0);
|
||||
void throttleInrush(bool on);
|
||||
inline void detachDCSignal() {
|
||||
|
|
|
@ -264,18 +264,14 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
|||
#ifdef ARDUINO_ARCH_ESP32
|
||||
int trackfound = -1;
|
||||
FOR_EACH_TRACK(t) {
|
||||
//DIAG(F("Checking track %c mode %x dcAddr %d"), 'A'+t, track[t]->getMode(), trackDCAddr[t]);
|
||||
if (t != trackToSet // not our track
|
||||
&& (track[t]->getMode() & TRACK_MODE_DC) // right mode
|
||||
&& trackDCAddr[t] == dcAddr) { // right addr
|
||||
//DIAG(F("Found track %c"), 'A'+t);
|
||||
if ((track[t]->getMode() & TRACK_MODE_DC) && trackDCAddr[t] == dcAddr) {
|
||||
trackfound = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (trackfound > -1) {
|
||||
DCCTimer::DCCEXanalogCopyChannel(track[trackfound]->getBrakePinSigned(),
|
||||
track[trackToSet]->getBrakePinSigned());
|
||||
DCCTimer::DCCEXanalogCopyChannel(track[trackfound]->getBrakePin(),
|
||||
track[trackToSet]->getBrakePin());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
|
||||
#include "StringFormatter.h"
|
||||
|
||||
#define VERSION "5.2.44"
|
||||
// 5.2.44 - ESP32 fix PWM LEDC inverted pin mode
|
||||
// ESP32 rewrite PWM LEDC to use pin mux
|
||||
#define VERSION "5.2.43"
|
||||
// 5.2.43 - ESP32 rewrite PWM LEDC to use pin mux
|
||||
// 5.2.42 - ESP32 Bugfix: Uninitialized stack variable
|
||||
// 5.2.41 - Update rotary encoder default address to 0x67
|
||||
// 5.2.40 - Allow no shield
|
||||
|
|
Loading…
Reference in New Issue
Block a user