Skip to content

Commit 8d7aacd

Browse files
committed
Check for i2c conflicts
1 parent cbaf4ac commit 8d7aacd

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/DriverPins.h

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ struct PinsFunction {
214214
int pin = -1;
215215
int index = 0;
216216
PinLogic pin_logic;
217+
bool active = true; // false if pin conflict
217218
};
218219

219220
/**
@@ -312,18 +313,6 @@ class DriverPins {
312313

313314
virtual bool begin() {
314315
AD_LOGD("DriverPins::begin");
315-
// setup spi
316-
bool result = true;
317-
for (auto &tmp : spi) {
318-
if (tmp.function == PinFunction::SD && sd_active)
319-
result &= tmp.begin();
320-
else
321-
result &= tmp.begin();
322-
}
323-
// setup i2c
324-
for (auto &tmp : i2c) {
325-
result &= tmp.begin();
326-
}
327316
// setup pins
328317
for (auto &tmp : pins) {
329318
if (tmp.pin != -1) {
@@ -348,9 +337,24 @@ class DriverPins {
348337
}
349338
} else {
350339
AD_LOGW("Pin '%d' not set up because of conflict", tmp.pin);
340+
tmp.active = false;
351341
}
352342
}
353343
}
344+
345+
// setup spi
346+
bool result = true;
347+
for (auto &tmp : spi) {
348+
if (tmp.function == PinFunction::SD && sd_active)
349+
result &= tmp.begin();
350+
else
351+
result &= tmp.begin();
352+
}
353+
354+
// setup i2c
355+
for (auto &tmp : i2c) {
356+
result &= tmp.begin();
357+
}
354358
return result;
355359
}
356360

@@ -381,7 +385,11 @@ class DriverPins {
381385
Vector<PinsFunction> pins{0};
382386
bool sd_active = true;
383387

384-
bool hasConflict(int pin) {
388+
bool hasConflict(int pin){
389+
return hasSPIConflict(pin) || hasI2CConflict(pin);
390+
}
391+
392+
bool hasSPIConflict(int pin) {
385393
if (sd_active) {
386394
auto sd = getSPIPins(PinFunction::SD);
387395
if (!sd)
@@ -392,6 +400,15 @@ class DriverPins {
392400
}
393401
return false;
394402
}
403+
404+
bool hasI2CConflict(int pin) {
405+
for(auto &i2c_entry : i2c){
406+
if (i2c_entry.scl == pin || i2c_entry.sda == pin){
407+
return true;
408+
}
409+
}
410+
return false;
411+
}
395412
};
396413

397414
/**

0 commit comments

Comments
 (0)