Skip to content

Commit 9b473db

Browse files
committed
Expand signed pin type to 16 bit so we can return 255/-255 (UNUSED_PIN)
1 parent 3160030 commit 9b473db

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

DCCTimer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class DCCTimer {
6767
static void DCCEXanalogWriteFrequency(uint8_t pin, uint32_t frequency);
6868
static void DCCEXanalogWrite(uint8_t pin, int value, bool invert);
6969
static void DCCEXledcDetachPin(uint8_t pin);
70-
static void DCCEXanalogCopyChannel(int8_t frompin, int8_t topin);
70+
static void DCCEXanalogCopyChannel(int16_t frompin, int16_t topin);
7171
static void DCCEXInrushControlOn(uint8_t pin, int duty, bool invert);
7272
static void DCCEXledcAttachPin(uint8_t pin, int8_t channel, bool inverted);
7373

DCCTimerESP.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
// Please refer to DCCTimer.h for general comments about how this class works
2323
// This is to avoid repetition and duplication.
2424

25+
#ifndef UNUSED_PIN // sync define with the one in MotorDrivers.h and MotorDriver.h
26+
#define UNUSED_PIN 255 // inside uint8_t
27+
#endif
28+
2529
#ifdef ARDUINO_ARCH_ESP8266
2630

2731
#include "DCCTimer.h"
@@ -236,16 +240,24 @@ void DCCTimer::DCCEXledcAttachPin(uint8_t pin, int8_t channel, bool inverted) {
236240
gpio_matrix_out(pin, LEDCToMux[channel], inverted, 0);
237241
}
238242

239-
void DCCTimer::DCCEXanalogCopyChannel(int8_t frompin, int8_t topin) {
243+
void DCCTimer::DCCEXanalogCopyChannel(int16_t frompin, int16_t topin) {
240244
// arguments are signed depending on inversion of pins
241-
DIAG(F("Pin %d copied to %d"), frompin, topin);
245+
//DIAG(F("Pin %d copied to %d"), frompin, topin);
242246
bool inverted = false;
243247
if (frompin<0)
244248
frompin = -frompin;
245249
if (topin<0) {
246250
inverted = true;
247251
topin = -topin;
248252
}
253+
if (frompin == UNUSED_PIN) {
254+
DIAG(F("Can not copy from unused frompin"));
255+
return;
256+
}
257+
if (topin == UNUSED_PIN) {
258+
DIAG(F("Can not copy to unused topin"));
259+
return;
260+
}
249261
int channel = pin_to_channel[frompin]; // after abs(frompin)
250262
pin_to_channel[topin] = channel;
251263
DCCTimer::DCCEXledcAttachPin(topin, channel, inverted);

MotorDriver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class MotorDriver {
219219
}
220220
};
221221
inline pinpair getSignalPin() { return pinpair(signalPin,signalPin2); };
222-
inline int8_t getBrakePinSigned() { return invertBrake ? -brakePin : brakePin; };
222+
inline int16_t getBrakePinSigned() { return invertBrake ? -brakePin : brakePin; };
223223
void setDCSignal(byte speedByte, uint8_t frequency=0);
224224
void throttleInrush(bool on);
225225
inline void detachDCSignal() {

0 commit comments

Comments
 (0)