From ccf463b5075b6f05922dbd4c744b1be8b6ba02a5 Mon Sep 17 00:00:00 2001 From: Neil McKechnie Date: Mon, 16 Jan 2023 23:03:53 +0000 Subject: [PATCH] IODevice.cpp: Fix error in overlap checking. The checkNoOverlap() function didn't work correctly in the case where one device has nPins=0. All devices configured after that were rejected, even when no overlap was present. --- IODevice.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/IODevice.cpp b/IODevice.cpp index 9cf1221..a51c84b 100644 --- a/IODevice.cpp +++ b/IODevice.cpp @@ -292,16 +292,17 @@ bool IODevice::checkNoOverlap(VPIN firstPin, uint8_t nPins, uint8_t i2cAddress) VPIN lastPin=firstPin+nPins-1; for (IODevice *dev = _firstDevice; dev != 0; dev = dev->_nextDevice) { - // check for pin range overlaps (verbose but compiler will fix that) - VPIN firstDevPin=dev->_firstVpin; - VPIN lastDevPin=firstDevPin+dev->_nPins-1; - bool noOverlap= firstPin>lastDevPin || lastPin 0 && dev->_nPins > 0) { + // check for pin range overlaps (verbose but compiler will fix that) + VPIN firstDevPin=dev->_firstVpin; + VPIN lastDevPin=firstDevPin+dev->_nPins-1; + bool noOverlap= firstPin>lastDevPin || lastPin_I2CAddress==i2cAddress) { DIAG(F("WARNING HAL Overlap. i2c Addr 0x%x ignored."),i2cAddress);