@@ -313,34 +313,9 @@ class DriverPins {
313
313
314
314
virtual bool begin () {
315
315
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 ();
344
319
345
320
// setup spi
346
321
bool result = true ;
@@ -385,7 +360,38 @@ class DriverPins {
385
360
Vector<PinsFunction> pins{0 };
386
361
bool sd_active = true ;
387
362
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) {
389
395
return hasSPIConflict (pin) || hasI2CConflict (pin);
390
396
}
391
397
@@ -402,13 +408,13 @@ class DriverPins {
402
408
}
403
409
404
410
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) {
407
413
return true ;
408
414
}
409
415
}
410
416
return false ;
411
- }
417
+ }
412
418
};
413
419
414
420
/* *
@@ -610,7 +616,7 @@ class PinsSTM32F411DiscoClass : public DriverPins {
610
616
addPin (PinFunction::LED, PD14, PinLogic::Output, 3 ); // red
611
617
addPin (PinFunction::LED, PD15, PinLogic::Output, 4 ); // blue
612
618
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
614
620
}
615
621
};
616
622
0 commit comments