@@ -12,6 +12,16 @@ namespace audio_driver {
1212
1313using Pin = int16_t ;
1414
15+ /* *
16+ * @enum PinLogic
17+ * @brief input or output
18+ * @ingroup enumerations
19+ */
20+
21+ enum class PinLogic {
22+ InputActiveHigh, InputActiveLow, InputActiveTouch, Input, Output,
23+ };
24+
1525/* *
1626 * @brief I2S pins
1727 * @author Phil Schatzmann
@@ -168,17 +178,17 @@ struct PinsI2C {
168178 */
169179struct PinsFunction {
170180 PinsFunction () = default ;
171- PinsFunction (PinFunctionEnum function, Pin pin, int index = 0 ,
172- ActiveLogic active = ActiveLogic::ActiveLow ) {
181+ PinsFunction (PinFunctionEnum function, Pin pin, PinLogic logic ,
182+ int index = 0 ) {
173183 this ->function = function;
174184 this ->pin = pin;
175185 this ->index = index;
176- this ->active_logic = active ;
186+ this ->pin_logic = logic ;
177187 }
178188 PinFunctionEnum function;
179189 int pin = -1 ;
180190 int index = 0 ;
181- ActiveLogic active_logic ;
191+ PinLogic pin_logic ;
182192};
183193
184194/* *
@@ -211,9 +221,9 @@ class DriverPins {
211221
212222 void addPin (PinsFunction pin) { pins.push_back (pin); }
213223
214- void addPin (PinFunctionEnum function, Pin pinNo, int index = 0 ,
215- ActiveLogic logic = ActiveLogic::ActiveLow ) {
216- PinsFunction pin (function, pinNo, index, logic );
224+ void addPin (PinFunctionEnum function, Pin pinNo, PinLogic logic ,
225+ int index = 0 ) {
226+ PinsFunction pin (function, pinNo, logic, index );
217227 addPin (pin);
218228 }
219229 // / Get pin information by function
@@ -226,7 +236,7 @@ class DriverPins {
226236 }
227237
228238 // / Get pin information by pin ID
229- Optional<PinsFunction> getPin (Pin pinId){
239+ Optional<PinsFunction> getPin (Pin pinId) {
230240 for (PinsFunction &pin : pins) {
231241 if (pin.pin == pinId)
232242 return pin;
@@ -236,11 +246,11 @@ class DriverPins {
236246
237247 Pin getPinID (PinFunctionEnum function, int pos = 0 ) {
238248 auto pin = getPin (function, pos);
239- if (pin) return pin.value ().pin ;
249+ if (pin)
250+ return pin.value ().pin ;
240251 return -1 ;
241252 }
242253
243-
244254 Optional<PinsI2C> getI2CPins (PinFunctionEnum function) {
245255 for (PinsI2C &pin : i2c) {
246256 if (pin.function == function)
@@ -288,23 +298,18 @@ class DriverPins {
288298 // setup pins
289299 for (auto &tmp : pins) {
290300 if (tmp.pin != -1 ) {
291-
292- switch (tmp.function ) {
293- case HEADPHONE_DETECT:
294- pinMode (tmp.pin , INPUT_PULLUP);
301+ switch (tmp.pin_logic ) {
302+ case PinLogic::InputActiveHigh:
303+ pinMode (tmp.pin , INPUT);
295304 break ;
296- case AUXIN_DETECT :
305+ case PinLogic::InputActiveLow :
297306 pinMode (tmp.pin , INPUT_PULLUP);
298307 break ;
299- case KEY :
308+ case PinLogic::Input :
300309 pinMode (tmp.pin , INPUT);
301310 break ;
302- case LED:
303- pinMode (tmp.pin , OUTPUT);
304- break ;
305- case PA:
311+ case PinLogic::Output:
306312 pinMode (tmp.pin , OUTPUT);
307- digitalWrite (tmp.pin , HIGH);
308313 break ;
309314 default :
310315 // do nothing
@@ -349,16 +354,16 @@ class PinsLyrat43Class : public DriverPins {
349354 addI2S (CODEC, 0 , 5 , 25 , 26 , 35 );
350355
351356 // add other pins
352- addPin (KEY, 36 , 1 );
353- addPin (KEY, 39 , 2 );
354- addPin (KEY, 33 , 3 );
355- addPin (KEY, 32 , 4 );
356- addPin (KEY, 13 , 5 );
357- addPin (KEY, 27 , 6 );
358- addPin (AUXIN_DETECT, 12 );
359- addPin (HEADPHONE_DETECT, 19 );
360- addPin (PA, 21 );
361- addPin (LED, 22 );
357+ addPin (KEY, 36 , PinLogic::Input, 1 );
358+ addPin (KEY, 39 , PinLogic::Input, 2 );
359+ addPin (KEY, 33 , PinLogic::Input, 3 );
360+ addPin (KEY, 32 , PinLogic::Input, 4 );
361+ addPin (KEY, 13 , PinLogic::Input, 5 );
362+ addPin (KEY, 27 , PinLogic::Input, 6 );
363+ addPin (AUXIN_DETECT, 12 , PinLogic::InputActiveHigh );
364+ addPin (HEADPHONE_DETECT, 19 , PinLogic::InputActiveHigh );
365+ addPin (PA, 21 , PinLogic::Output );
366+ addPin (LED, 22 , PinLogic::Output );
362367 }
363368};
364369
@@ -378,16 +383,16 @@ class PinsLyrat42Class : public DriverPins {
378383 addI2S (CODEC, 0 , 5 , 25 , 26 , 35 );
379384
380385 // add other pins
381- addPin (KEY, 36 , 1 );
382- addPin (KEY, 39 , 2 );
383- addPin (KEY, 33 , 3 );
384- addPin (KEY, 32 , 4 );
385- addPin (KEY, 13 , 5 );
386- addPin (KEY, 27 , 6 );
387- addPin (AUXIN_DETECT, 12 );
388- addPin (PA, 21 );
389- addPin (LED, 22 , 1 );
390- addPin (LED, 19 , 2 );
386+ addPin (KEY, 36 , PinLogic::Input, 1 );
387+ addPin (KEY, 39 , PinLogic::Input, 2 );
388+ addPin (KEY, 33 , PinLogic::Input, 3 );
389+ addPin (KEY, 32 , PinLogic::Input, 4 );
390+ addPin (KEY, 13 , PinLogic::Input, 5 );
391+ addPin (KEY, 27 , PinLogic::Input, 6 );
392+ addPin (AUXIN_DETECT, 12 , PinLogic::InputActiveLow );
393+ addPin (PA, 21 , PinLogic::Output );
394+ addPin (LED, 22 , PinLogic::Output, 1 );
395+ addPin (LED, 19 , PinLogic::Output, 2 );
391396 }
392397};
393398
@@ -408,17 +413,17 @@ class PinsLyratMiniClass : public DriverPins {
408413 addI2S (CODEC_ADC, 0 , 32 , 33 , -1 , 36 , 1 );
409414
410415 // add other pins
411- addPin (KEY, 5 , 1 );
412- addPin (KEY, 4 , 2 );
413- addPin (KEY, 2 , 3 );
414- addPin (KEY, 3 , 4 );
415- addPin (KEY, 1 , 5 );
416+ addPin (KEY, 5 , PinLogic::Input, 1 );
417+ addPin (KEY, 4 , PinLogic::Input, 2 );
418+ addPin (KEY, 2 , PinLogic::Input, 3 );
419+ addPin (KEY, 3 , PinLogic::Input, 4 );
420+ addPin (KEY, 1 , PinLogic::Input, 5 );
416421 // addPin(KEY, 0, 6};
417- addPin (HEADPHONE_DETECT, 19 );
418- addPin (PA, 21 );
419- addPin (LED, 22 , 1 );
420- addPin (LED, 27 , 2 );
421- addPin (MCLK_SOURCE, 0 );
422+ addPin (HEADPHONE_DETECT, 19 , PinLogic::InputActiveLow );
423+ addPin (PA, 21 , PinLogic::Output );
424+ addPin (LED, 22 , PinLogic::Output, 1 );
425+ addPin (LED, 27 , PinLogic::Output, 2 );
426+ addPin (MCLK_SOURCE, 0 , PinLogic::Output );
422427 }
423428};
424429
@@ -438,16 +443,16 @@ class PinsAudioKitEs8388v1Class : public DriverPins {
438443 addI2S (CODEC, 0 , 27 , 25 , 26 , 35 );
439444
440445 // add other pins
441- addPin (KEY, 36 , 1 );
442- addPin (KEY, 13 , 2 );
443- addPin (KEY, 19 , 3 );
444- addPin (KEY, 23 , 4 );
445- addPin (KEY, 18 , 5 );
446- addPin (KEY, 5 , 6 );
447- addPin (AUXIN_DETECT, 12 );
448- addPin (HEADPHONE_DETECT, 39 );
449- addPin (PA, 21 );
450- addPin (LED, 22 );
446+ addPin (KEY, 36 , PinLogic::Input, 1 );
447+ addPin (KEY, 13 , PinLogic::Input, 2 );
448+ addPin (KEY, 19 , PinLogic::Input, 3 );
449+ addPin (KEY, 23 , PinLogic::Input, 4 );
450+ addPin (KEY, 18 , PinLogic::Input, 5 );
451+ addPin (KEY, 5 , PinLogic::Input, 6 );
452+ addPin (AUXIN_DETECT, 12 , PinLogic::InputActiveLow );
453+ addPin (HEADPHONE_DETECT, 39 , PinLogic::InputActiveLow );
454+ addPin (PA, 21 , PinLogic::Output );
455+ addPin (LED, 22 , PinLogic::Output );
451456 }
452457};
453458
@@ -467,16 +472,16 @@ class PinsAudioKitEs8388v2Class : public DriverPins {
467472 addI2S (CODEC, 0 , 5 , 25 , 26 , 35 );
468473
469474 // add other pins
470- addPin (KEY, 36 , 1 );
471- addPin (KEY, 13 , 2 );
472- addPin (KEY, 19 , 3 );
473- addPin (KEY, 23 , 4 );
474- addPin (KEY, 18 , 5 );
475- addPin (KEY, 5 , 6 );
476- addPin (AUXIN_DETECT, 12 );
477- addPin (HEADPHONE_DETECT, 39 );
478- addPin (PA, 21 );
479- addPin (LED, 22 );
475+ addPin (KEY, 36 , PinLogic::Input, 1 );
476+ addPin (KEY, 13 , PinLogic::Input, 2 );
477+ addPin (KEY, 19 , PinLogic::Input, 3 );
478+ addPin (KEY, 23 , PinLogic::Input, 4 );
479+ addPin (KEY, 18 , PinLogic::Input, 5 );
480+ addPin (KEY, 5 , PinLogic::Input, 6 );
481+ addPin (AUXIN_DETECT, 12 , PinLogic::InputActiveLow );
482+ addPin (HEADPHONE_DETECT, 39 , PinLogic::InputActiveLow );
483+ addPin (PA, 21 , PinLogic::Output );
484+ addPin (LED, 22 , PinLogic::Output );
480485 }
481486};
482487
@@ -496,16 +501,16 @@ class PinsAudioKitAC101Class : public DriverPins {
496501 addI2S (CODEC, 0 , 27 , 26 , 25 , 35 );
497502
498503 // add other pins
499- addPin (KEY, 36 , 1 );
500- addPin (KEY, 13 , 2 );
501- addPin (KEY, 19 , 3 );
502- addPin (KEY, 23 , 4 );
503- addPin (KEY, 18 , 5 );
504- addPin (KEY, 5 , 6 );
505- addPin (LED, 22 );
506- addPin (LED, 19 );
507- addPin (HEADPHONE_DETECT, 5 );
508- addPin (PA, 21 );
504+ addPin (KEY, 36 , PinLogic::Input, 1 );
505+ addPin (KEY, 13 , PinLogic::Input, 2 );
506+ addPin (KEY, 19 , PinLogic::Input, 3 );
507+ addPin (KEY, 23 , PinLogic::Input, 4 );
508+ addPin (KEY, 18 , PinLogic::Input, 5 );
509+ addPin (KEY, 5 , PinLogic::Input, 6 );
510+ addPin (LED, 22 , PinLogic::Output, 0 );
511+ addPin (LED, 19 , PinLogic::Output, 1 );
512+ addPin (HEADPHONE_DETECT, 5 , PinLogic::InputActiveLow );
513+ addPin (PA, 21 , PinLogic::Output );
509514 }
510515};
511516
@@ -525,14 +530,14 @@ class PinsSTM32F411DiscoClass : public DriverPins {
525530 addI2S (CODEC, PC7, PC10, PA4, PC3, PC12);
526531
527532 // add other pins
528- addPin (KEY, PA0); // user button
529- addPin (LED, PD12, 0 ); // green
530- addPin (LED, PD5, 1 ); // red
531- addPin (LED, PD13, 2 ); // orange
532- addPin (LED, PD14, 3 ); // red
533- addPin (LED, PD15, 4 ); // blue
534- addPin (PA, PD4); // reset pin (active high)
535- addPin (CODEC_ADC, PC3); // Microphone
533+ addPin (KEY, PA0, PinLogic::Output); // user button
534+ addPin (LED, PD12, PinLogic::Output, 0 ); // green
535+ addPin (LED, PD5, PinLogic::Output, 1 ); // red
536+ addPin (LED, PD13, PinLogic::Output, 2 ); // orange
537+ addPin (LED, PD14, PinLogic::Output, 3 ); // red
538+ addPin (LED, PD15, PinLogic::Output, 4 ); // blue
539+ addPin (PA, PD4, PinLogic::Output, ); // reset pin (active high)
540+ addPin (CODEC_ADC, PC3, PinLogic::Input ); // Microphone
536541 }
537542} PinsSTM32F411Disco;
538543
0 commit comments