mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-02-17 06:29:15 +01:00
HAL catch pin overlaps
This commit is contained in:
parent
9a98d10a86
commit
e11d2d08d1
12
IODevice.cpp
12
IODevice.cpp
@ -275,6 +275,18 @@ IODevice *IODevice::findDevice(VPIN vpin) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Private helper function to check for vpin overlap. Run during setup only.
|
||||||
|
// returns true if pins DONT overlap with existing device
|
||||||
|
bool IODevice::checkNoOverlap(VPIN firstPin, uint8_t nPins) {
|
||||||
|
for (VPIN testPin=firstPin; testPin< (firstPin+nPins); testPin++)
|
||||||
|
if (findDevice(testPin)) {
|
||||||
|
DIAG(F("WARNING HAL Pin %d overlap, re-definition of pins %d to %d ignored."),
|
||||||
|
testPin, firstPin, firstPin+nPins);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//==================================================================================================================
|
//==================================================================================================================
|
||||||
// Static data
|
// Static data
|
||||||
//------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -228,6 +228,9 @@ protected:
|
|||||||
// pin low if an input changes state.
|
// pin low if an input changes state.
|
||||||
int16_t _gpioInterruptPin = -1;
|
int16_t _gpioInterruptPin = -1;
|
||||||
|
|
||||||
|
// Method to check if pins will overlap before creating new device.
|
||||||
|
static bool checkNoOverlap(VPIN firstPin, uint8_t nPins=1);
|
||||||
|
|
||||||
// Static support function for subclass creation
|
// Static support function for subclass creation
|
||||||
static void addDevice(IODevice *newDevice);
|
static void addDevice(IODevice *newDevice);
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public:
|
|||||||
addDevice(this);
|
addDevice(this);
|
||||||
}
|
}
|
||||||
static void create(VPIN firstVpin, int nPins, uint8_t i2cAddress) {
|
static void create(VPIN firstVpin, int nPins, uint8_t i2cAddress) {
|
||||||
new ADS111x(firstVpin, nPins, i2cAddress);
|
if (checkNoOverlap(firstVpin,nPins)) new ADS111x(firstVpin, nPins, i2cAddress);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
void _begin() {
|
void _begin() {
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
#define ADDRESS(packedaddr) ((packedaddr) >> 2)
|
#define ADDRESS(packedaddr) ((packedaddr) >> 2)
|
||||||
#define SUBADDRESS(packedaddr) ((packedaddr) % 4)
|
#define SUBADDRESS(packedaddr) ((packedaddr) % 4)
|
||||||
|
|
||||||
void DCCAccessoryDecoder::create(VPIN vpin, int nPins, int DCCAddress, int DCCSubaddress) {
|
void DCCAccessoryDecoder::create(VPIN firstVpin, int nPins, int DCCAddress, int DCCSubaddress) {
|
||||||
new DCCAccessoryDecoder(vpin, nPins, DCCAddress, DCCSubaddress);
|
if (checkNoOverlap(firstVpin,nPins)) new DCCAccessoryDecoder(firstVpin, nPins, DCCAddress, DCCSubaddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
@ -78,7 +78,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void create(VPIN firstVpin, int nPins, HardwareSerial &serial) {
|
static void create(VPIN firstVpin, int nPins, HardwareSerial &serial) {
|
||||||
new DFPlayer(firstVpin, nPins, serial);
|
if (checkNoOverlap(firstVpin,nPins)) new DFPlayer(firstVpin, nPins, serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -36,7 +36,7 @@ IO_ExampleSerial::IO_ExampleSerial(VPIN firstVpin, int nPins, HardwareSerial *se
|
|||||||
|
|
||||||
// Static create method for one module.
|
// Static create method for one module.
|
||||||
void IO_ExampleSerial::create(VPIN firstVpin, int nPins, HardwareSerial *serial, unsigned long baud) {
|
void IO_ExampleSerial::create(VPIN firstVpin, int nPins, HardwareSerial *serial, unsigned long baud) {
|
||||||
new IO_ExampleSerial(firstVpin, nPins, serial, baud);
|
if (checkNoOverlap(firstVpin,nPins)) new IO_ExampleSerial(firstVpin, nPins, serial, baud);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Device-specific initialisation
|
// Device-specific initialisation
|
||||||
|
@ -86,7 +86,8 @@ public:
|
|||||||
|
|
||||||
// Static create function provides alternative way to create object
|
// Static create function provides alternative way to create object
|
||||||
static void create(VPIN vpin, int trigPin, int echoPin, uint16_t onThreshold, uint16_t offThreshold) {
|
static void create(VPIN vpin, int trigPin, int echoPin, uint16_t onThreshold, uint16_t offThreshold) {
|
||||||
new HCSR04(vpin, trigPin, echoPin, onThreshold, offThreshold);
|
if (checkNoOverlap(vpin) && checkNoOverlap(trigPin) && checkNoOverlap(echoPin))
|
||||||
|
new HCSR04(vpin, trigPin, echoPin, onThreshold, offThreshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
class MCP23008 : public GPIOBase<uint8_t> {
|
class MCP23008 : public GPIOBase<uint8_t> {
|
||||||
public:
|
public:
|
||||||
static void create(VPIN firstVpin, uint8_t nPins, uint8_t I2CAddress, int interruptPin=-1) {
|
static void create(VPIN firstVpin, uint8_t nPins, uint8_t I2CAddress, int interruptPin=-1) {
|
||||||
new MCP23008(firstVpin, nPins, I2CAddress, interruptPin);
|
if (checkNoOverlap(firstVpin, nPins)) new MCP23008(firstVpin, nPins, I2CAddress, interruptPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
class MCP23017 : public GPIOBase<uint16_t> {
|
class MCP23017 : public GPIOBase<uint16_t> {
|
||||||
public:
|
public:
|
||||||
static void create(VPIN vpin, int nPins, uint8_t I2CAddress, int interruptPin=-1) {
|
static void create(VPIN vpin, int nPins, uint8_t I2CAddress, int interruptPin=-1) {
|
||||||
new MCP23017(vpin, min(nPins,16), I2CAddress, interruptPin);
|
if (checkNoOverlap(vpin, nPins)) new MCP23017(vpin, min(nPins,16), I2CAddress, interruptPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
|
@ -39,7 +39,7 @@ static void writeRegister(byte address, byte reg, byte value);
|
|||||||
|
|
||||||
// Create device driver instance.
|
// Create device driver instance.
|
||||||
void PCA9685::create(VPIN firstVpin, int nPins, uint8_t I2CAddress) {
|
void PCA9685::create(VPIN firstVpin, int nPins, uint8_t I2CAddress) {
|
||||||
new PCA9685(firstVpin, nPins, I2CAddress);
|
if (checkNoOverlap(firstVpin, nPins)) new PCA9685(firstVpin, nPins, I2CAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure a port on the PCA9685.
|
// Configure a port on the PCA9685.
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
class PCF8574 : public GPIOBase<uint8_t> {
|
class PCF8574 : public GPIOBase<uint8_t> {
|
||||||
public:
|
public:
|
||||||
static void create(VPIN firstVpin, uint8_t nPins, uint8_t I2CAddress, int interruptPin=-1) {
|
static void create(VPIN firstVpin, uint8_t nPins, uint8_t I2CAddress, int interruptPin=-1) {
|
||||||
new PCF8574(firstVpin, nPins, I2CAddress, interruptPin);
|
if (checkNoOverlap(firstVpin, nPins)) new PCF8574(firstVpin, nPins, I2CAddress, interruptPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
PCF8574(VPIN firstVpin, uint8_t nPins, uint8_t I2CAddress, int interruptPin=-1)
|
PCF8574(VPIN firstVpin, uint8_t nPins, uint8_t I2CAddress, int interruptPin=-1)
|
||||||
|
@ -139,7 +139,7 @@ public:
|
|||||||
addDevice(this);
|
addDevice(this);
|
||||||
}
|
}
|
||||||
static void create(VPIN firstVpin, int nPins, uint8_t i2cAddress, uint16_t onThreshold, uint16_t offThreshold, VPIN xshutPin = VPIN_NONE) {
|
static void create(VPIN firstVpin, int nPins, uint8_t i2cAddress, uint16_t onThreshold, uint16_t offThreshold, VPIN xshutPin = VPIN_NONE) {
|
||||||
new VL53L0X(firstVpin, nPins, i2cAddress, onThreshold, offThreshold, xshutPin);
|
if (checkNoOverlap(firstVpin, nPins)) new VL53L0X(firstVpin, nPins, i2cAddress, onThreshold, offThreshold, xshutPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
Reference in New Issue
Block a user