@@ -35,7 +35,7 @@ enum class PinLogic {
35
35
enum class PinFunction {
36
36
HEADPHONE_DETECT,
37
37
AUXIN_DETECT,
38
- PA, // Power Amplifier
38
+ PA, // Power Amplifier
39
39
POWER,
40
40
LED,
41
41
KEY,
@@ -68,7 +68,7 @@ struct PinsI2S {
68
68
GpioPin ws;
69
69
GpioPin data_out;
70
70
GpioPin data_in;
71
- int port; // port number
71
+ int port; // port number
72
72
};
73
73
74
74
/* *
@@ -177,7 +177,7 @@ struct PinsI2C {
177
177
p_wire->begin ();
178
178
} else {
179
179
// begin with defined pins, if supported
180
- #if defined(ESP32)
180
+ #if defined(ESP32)
181
181
AD_LOGI (" setting up I2C scl: %d, sda: %d" , scl, sda);
182
182
p_wire->begin (sda, scl);
183
183
#elif defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32)
@@ -218,7 +218,7 @@ struct PinsFunction {
218
218
int pin = -1 ;
219
219
int index = 0 ;
220
220
PinLogic pin_logic;
221
- bool active = true ; // false if pin conflict
221
+ bool active = true ; // false if pin conflict
222
222
};
223
223
224
224
/* *
@@ -228,7 +228,7 @@ struct PinsFunction {
228
228
* @copyright GPLv3
229
229
*/
230
230
class DriverPins {
231
- public:
231
+ public:
232
232
void addI2S (PinsI2S pin) { i2s.push_back (pin); }
233
233
void addI2S (PinFunction function, GpioPin mclk, GpioPin bck, GpioPin ws,
234
234
GpioPin data_out, GpioPin data_in = -1 , int port = 0 ) {
@@ -259,58 +259,51 @@ class DriverPins {
259
259
// / Get pin information by function
260
260
Optional<PinsFunction> getPin (PinFunction function, int pos = 0 ) {
261
261
for (PinsFunction &pin : pins) {
262
- if (pin.function == function && pin.index == pos)
263
- return pin;
262
+ if (pin.function == function && pin.index == pos) return pin;
264
263
}
265
264
return {};
266
265
}
267
266
268
267
// / Get pin information by pin ID
269
268
Optional<PinsFunction> getPin (GpioPin pinId) {
270
269
for (PinsFunction &pin : pins) {
271
- if (pin.pin == pinId)
272
- return pin;
270
+ if (pin.pin == pinId) return pin;
273
271
}
274
272
return {};
275
273
}
276
274
277
275
GpioPin getPinID (PinFunction function, int pos = 0 ) {
278
276
auto pin = getPin (function, pos);
279
- if (pin)
280
- return pin.value ().pin ;
277
+ if (pin) return pin.value ().pin ;
281
278
return -1 ;
282
279
}
283
280
284
281
Optional<PinsI2C> getI2CPins (PinFunction function) {
285
282
for (PinsI2C &pin : i2c) {
286
- if (pin.function == function)
287
- return pin;
283
+ if (pin.function == function) return pin;
288
284
}
289
285
return {};
290
286
}
291
287
292
288
Optional<PinsSPI> getSPIPins (PinFunction function) {
293
289
for (PinsSPI &pins : spi) {
294
- if (pins.function == function)
295
- return pins;
290
+ if (pins.function == function) return pins;
296
291
}
297
292
return {};
298
293
}
299
294
300
295
// / Finds the I2S pins with the help of the port
301
296
Optional<PinsI2S> getI2SPins (int port) {
302
297
for (PinsI2S &pins : i2s) {
303
- if (pins.port == port)
304
- return pins;
298
+ if (pins.port == port) return pins;
305
299
}
306
300
return {};
307
301
}
308
302
309
303
// / Finds the I2S pins with the help of the function
310
304
Optional<PinsI2S> getI2SPins (PinFunction function = PinFunction::CODEC) {
311
305
for (PinsI2S &pins : i2s) {
312
- if (pins.function == function)
313
- return pins;
306
+ if (pins.function == function) return pins;
314
307
}
315
308
return {};
316
309
}
@@ -327,12 +320,11 @@ class DriverPins {
327
320
bool result = true ;
328
321
for (auto &tmp : spi) {
329
322
AD_LOGD (" DriverPins::begin::SPI::begin" );
330
- if (tmp.function == PinFunction::SD)
331
- {
323
+ if (tmp.function == PinFunction::SD) {
332
324
if (sd_active)
333
325
result &= tmp.begin ();
334
- else
335
- result &= tmp.begin ();
326
+ else
327
+ result &= tmp.begin ();
336
328
}
337
329
}
338
330
@@ -367,7 +359,7 @@ class DriverPins {
367
359
// / Returns true if some function pins have been defined
368
360
bool hasPins () { return !pins.empty (); }
369
361
370
- protected:
362
+ protected:
371
363
Vector<PinsI2S> i2s{0 };
372
364
Vector<PinsSPI> spi{0 };
373
365
Vector<PinsI2C> i2c{0 };
@@ -381,21 +373,21 @@ class DriverPins {
381
373
if (!hasConflict (tmp.pin )) {
382
374
AD_LOGD (" pinMode %d" , tmp.pin );
383
375
switch (tmp.pin_logic ) {
384
- case PinLogic::InputActiveHigh:
385
- pinMode (tmp.pin , INPUT);
386
- break ;
387
- case PinLogic::InputActiveLow:
388
- pinMode (tmp.pin , INPUT_PULLUP);
389
- break ;
390
- case PinLogic::Input:
391
- pinMode (tmp.pin , INPUT);
392
- break ;
393
- case PinLogic::Output:
394
- pinMode (tmp.pin , OUTPUT);
395
- break ;
396
- default :
397
- // do nothing
398
- break ;
376
+ case PinLogic::InputActiveHigh:
377
+ pinMode (tmp.pin , INPUT);
378
+ break ;
379
+ case PinLogic::InputActiveLow:
380
+ pinMode (tmp.pin , INPUT_PULLUP);
381
+ break ;
382
+ case PinLogic::Input:
383
+ pinMode (tmp.pin , INPUT);
384
+ break ;
385
+ case PinLogic::Output:
386
+ pinMode (tmp.pin , OUTPUT);
387
+ break ;
388
+ default :
389
+ // do nothing
390
+ break ;
399
391
}
400
392
} else {
401
393
AD_LOGW (" Pin '%d' not set up because of conflict" , tmp.pin );
@@ -415,8 +407,7 @@ class DriverPins {
415
407
bool hasSPIConflict (int pin) {
416
408
if (sd_active) {
417
409
auto sd = getSPIPins (PinFunction::SD);
418
- if (!sd)
419
- return false ;
410
+ if (!sd) return false ;
420
411
PinsSPI spi = sd.value ();
421
412
return spi.cs == pin || spi.clk == pin || spi.miso == pin ||
422
413
spi.mosi == pin;
@@ -440,7 +431,7 @@ class DriverPins {
440
431
* @copyright GPLv3
441
432
*/
442
433
class PinsLyrat43Class : public DriverPins {
443
- public:
434
+ public:
444
435
PinsLyrat43Class () {
445
436
// sd pins
446
437
addSPI (ESP32PinsSD);
@@ -469,7 +460,7 @@ class PinsLyrat43Class : public DriverPins {
469
460
* @copyright GPLv3
470
461
*/
471
462
class PinsLyrat42Class : public DriverPins {
472
- public:
463
+ public:
473
464
PinsLyrat42Class () {
474
465
// sd pins
475
466
addSPI (ESP32PinsSD);
@@ -498,7 +489,7 @@ class PinsLyrat42Class : public DriverPins {
498
489
* @copyright GPLv3
499
490
*/
500
491
class PinsLyratMiniClass : public DriverPins {
501
- public:
492
+ public:
502
493
PinsLyratMiniClass () {
503
494
// sd pins
504
495
addSPI (ESP32PinsSD);
@@ -529,7 +520,7 @@ class PinsLyratMiniClass : public DriverPins {
529
520
* @copyright GPLv3
530
521
*/
531
522
class PinsAudioKitEs8388v1Class : public DriverPins {
532
- public:
523
+ public:
533
524
PinsAudioKitEs8388v1Class () {
534
525
// sd pins
535
526
addSPI (ESP32PinsSD);
@@ -558,7 +549,7 @@ class PinsAudioKitEs8388v1Class : public DriverPins {
558
549
* @copyright GPLv3
559
550
*/
560
551
class PinsAudioKitEs8388v2Class : public DriverPins {
561
- public:
552
+ public:
562
553
PinsAudioKitEs8388v2Class () {
563
554
// sd pins
564
555
addSPI (ESP32PinsSD);
@@ -587,7 +578,7 @@ class PinsAudioKitEs8388v2Class : public DriverPins {
587
578
* @copyright GPLv3
588
579
*/
589
580
class PinsAudioKitAC101Class : public DriverPins {
590
- public:
581
+ public:
591
582
PinsAudioKitAC101Class () {
592
583
// sd pins
593
584
addSPI (ESP32PinsSD);
@@ -618,21 +609,21 @@ class PinsAudioKitAC101Class : public DriverPins {
618
609
* @copyright GPLv3
619
610
*/
620
611
class PinsSTM32F411DiscoClass : public DriverPins {
621
- public:
612
+ public:
622
613
PinsSTM32F411DiscoClass () {
623
614
// add i2c codec pins: scl, sda, port, frequency
624
615
addI2C (PinFunction::CODEC, PB6, PB9);
625
616
// add i2s pins: mclk, bck, ws,data_out, data_in ,(port)
626
617
addI2S (PinFunction::CODEC, PC7, PC10, PA4, PC3, PC12);
627
618
628
619
// add other pins
629
- addPin (PinFunction::KEY, PA0, PinLogic::Output); // user button
630
- addPin (PinFunction::LED, PD12, PinLogic::Output, 0 ); // green
631
- addPin (PinFunction::LED, PD5, PinLogic::Output, 1 ); // red
632
- addPin (PinFunction::LED, PD13, PinLogic::Output, 2 ); // orange
633
- addPin (PinFunction::LED, PD14, PinLogic::Output, 3 ); // red
634
- addPin (PinFunction::LED, PD15, PinLogic::Output, 4 ); // blue
635
- addPin (PinFunction::PA, PD4, PinLogic::Output); // reset pin (active high)
620
+ addPin (PinFunction::KEY, PA0, PinLogic::Output); // user button
621
+ addPin (PinFunction::LED, PD12, PinLogic::Output, 0 ); // green
622
+ addPin (PinFunction::LED, PD5, PinLogic::Output, 1 ); // red
623
+ addPin (PinFunction::LED, PD13, PinLogic::Output, 2 ); // orange
624
+ addPin (PinFunction::LED, PD14, PinLogic::Output, 3 ); // red
625
+ addPin (PinFunction::LED, PD15, PinLogic::Output, 4 ); // blue
626
+ addPin (PinFunction::PA, PD4, PinLogic::Output); // reset pin (active high)
636
627
// addPin(PinFunction::CODEC_ADC, PC3, PinLogic::Input); // Microphone
637
628
}
638
629
};
@@ -660,4 +651,4 @@ static PinsAudioKitEs8388v2Class PinsAudioKitEs8388v2;
660
651
// / @ingroup audio_driver
661
652
static PinsAudioKitAC101Class PinsAudioKitAC101;
662
653
663
- } // namespace audio_driver
654
+ } // namespace audio_driver
0 commit comments