Skip to content

Commit cbb144c

Browse files
committed
Conflicting pins
1 parent 8d7aacd commit cbb144c

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

src/DriverPins.h

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -313,34 +313,9 @@ class DriverPins {
313313

314314
virtual bool begin() {
315315
AD_LOGD("DriverPins::begin");
316-
// setup pins
317-
for (auto &tmp : pins) {
318-
if (tmp.pin != -1) {
319-
if (!hasConflict(tmp.pin)) {
320-
AD_LOGD("pinMode %d", tmp.pin);
321-
switch (tmp.pin_logic) {
322-
case PinLogic::InputActiveHigh:
323-
pinMode(tmp.pin, INPUT);
324-
break;
325-
case PinLogic::InputActiveLow:
326-
pinMode(tmp.pin, INPUT_PULLUP);
327-
break;
328-
case PinLogic::Input:
329-
pinMode(tmp.pin, INPUT);
330-
break;
331-
case PinLogic::Output:
332-
pinMode(tmp.pin, OUTPUT);
333-
break;
334-
default:
335-
// do nothing
336-
break;
337-
}
338-
} else {
339-
AD_LOGW("Pin '%d' not set up because of conflict", tmp.pin);
340-
tmp.active = false;
341-
}
342-
}
343-
}
316+
317+
// setup function pins
318+
void setupPinMode();
344319

345320
// setup spi
346321
bool result = true;
@@ -385,7 +360,38 @@ class DriverPins {
385360
Vector<PinsFunction> pins{0};
386361
bool sd_active = true;
387362

388-
bool hasConflict(int pin){
363+
void setupPinMode() {
364+
// setup pins
365+
for (auto &tmp : pins) {
366+
if (tmp.pin != -1) {
367+
if (!hasConflict(tmp.pin)) {
368+
AD_LOGD("pinMode %d", tmp.pin);
369+
switch (tmp.pin_logic) {
370+
case PinLogic::InputActiveHigh:
371+
pinMode(tmp.pin, INPUT);
372+
break;
373+
case PinLogic::InputActiveLow:
374+
pinMode(tmp.pin, INPUT_PULLUP);
375+
break;
376+
case PinLogic::Input:
377+
pinMode(tmp.pin, INPUT);
378+
break;
379+
case PinLogic::Output:
380+
pinMode(tmp.pin, OUTPUT);
381+
break;
382+
default:
383+
// do nothing
384+
break;
385+
}
386+
} else {
387+
AD_LOGW("Pin '%d' not set up because of conflict", tmp.pin);
388+
tmp.active = false;
389+
}
390+
}
391+
}
392+
}
393+
394+
bool hasConflict(int pin) {
389395
return hasSPIConflict(pin) || hasI2CConflict(pin);
390396
}
391397

@@ -402,13 +408,13 @@ class DriverPins {
402408
}
403409

404410
bool hasI2CConflict(int pin) {
405-
for(auto &i2c_entry : i2c){
406-
if (i2c_entry.scl == pin || i2c_entry.sda == pin){
411+
for (auto &i2c_entry : i2c) {
412+
if (i2c_entry.scl == pin || i2c_entry.sda == pin) {
407413
return true;
408414
}
409415
}
410416
return false;
411-
}
417+
}
412418
};
413419

414420
/**
@@ -610,7 +616,7 @@ class PinsSTM32F411DiscoClass : public DriverPins {
610616
addPin(PinFunction::LED, PD14, PinLogic::Output, 3); // red
611617
addPin(PinFunction::LED, PD15, PinLogic::Output, 4); // blue
612618
addPin(PinFunction::PA, PD4, PinLogic::Output); // reset pin (active high)
613-
//addPin(PinFunction::CODEC_ADC, PC3, PinLogic::Input); // Microphone
619+
// addPin(PinFunction::CODEC_ADC, PC3, PinLogic::Input); // Microphone
614620
}
615621
};
616622

0 commit comments

Comments
 (0)