@@ -10,7 +10,7 @@ namespace audio_driver {
1010
1111/* * @file */
1212
13- using Pin = int16_t ;
13+ using GpioPin = int16_t ;
1414
1515/* *
1616 * @enum PinLogic
@@ -49,8 +49,8 @@ enum class PinFunction {
4949 */
5050struct PinsI2S {
5151 PinsI2S () = default ;
52- PinsI2S (PinFunction function, Pin mclk, Pin bck, Pin ws, Pin data_out,
53- Pin data_in = -1 , int port = 0 ) {
52+ PinsI2S (PinFunction function, GpioPin mclk, GpioPin bck, GpioPin ws, GpioPin data_out,
53+ GpioPin data_in = -1 , int port = 0 ) {
5454 this ->function = function;
5555 this ->mclk = mclk;
5656 this ->bck = bck;
@@ -60,11 +60,11 @@ struct PinsI2S {
6060 this ->port = port;
6161 }
6262 PinFunction function;
63- Pin mclk;
64- Pin bck;
65- Pin ws;
66- Pin data_out;
67- Pin data_in;
63+ GpioPin mclk;
64+ GpioPin bck;
65+ GpioPin ws;
66+ GpioPin data_out;
67+ GpioPin data_in;
6868 int port; // port number
6969};
7070
@@ -75,7 +75,7 @@ struct PinsI2S {
7575 */
7676struct PinsSPI {
7777 PinsSPI () = default ;
78- PinsSPI (PinFunction function, Pin clk, Pin miso, Pin mosi, Pin cs,
78+ PinsSPI (PinFunction function, GpioPin clk, GpioPin miso, GpioPin mosi, GpioPin cs,
7979 SPIClass &spi = SPI) {
8080 this ->function = function;
8181 this ->clk = clk;
@@ -87,10 +87,10 @@ struct PinsSPI {
8787
8888 PinFunction function;
8989 SPIClass *p_spi = &SPI;
90- Pin clk = -1 ;
91- Pin miso = -1 ;
92- Pin mosi = -1 ;
93- Pin cs = -1 ;
90+ GpioPin clk = -1 ;
91+ GpioPin miso = -1 ;
92+ GpioPin mosi = -1 ;
93+ GpioPin cs = -1 ;
9494 bool set_active = true ;
9595 bool pinsAvailable () { return clk != -1 && miso != -1 && mosi != -1 ; }
9696 operator bool () { return pinsAvailable (); }
@@ -142,7 +142,7 @@ PinsSPI ESP32PinsSD{PinFunction::SD, 14, 2, 15, 13, SPI};
142142 */
143143struct PinsI2C {
144144 PinsI2C () = default ;
145- PinsI2C (PinFunction function, Pin scl, Pin sda, int port = -1 ,
145+ PinsI2C (PinFunction function, GpioPin scl, GpioPin sda, int port = -1 ,
146146 uint32_t frequency = 100000 , TwoWire &wire = Wire) {
147147 this ->function = function;
148148 this ->scl = scl;
@@ -155,8 +155,8 @@ struct PinsI2C {
155155 PinFunction function;
156156 uint32_t frequency = 100000 ;
157157 int port = -1 ;
158- Pin scl = -1 ;
159- Pin sda = -1 ;
158+ GpioPin scl = -1 ;
159+ GpioPin sda = -1 ;
160160 bool set_active = true ;
161161 TwoWire *p_wire;
162162 bool pinsAvailable () { return scl != -1 && sda != -1 && frequency != 0 ; }
@@ -198,7 +198,7 @@ struct PinsI2C {
198198 */
199199struct PinsFunction {
200200 PinsFunction () = default ;
201- PinsFunction (PinFunction function, Pin pin, PinLogic logic,
201+ PinsFunction (PinFunction function, GpioPin pin, PinLogic logic,
202202 int index = 0 ) {
203203 this ->function = function;
204204 this ->pin = pin;
@@ -220,28 +220,28 @@ struct PinsFunction {
220220class DriverPins {
221221public:
222222 void addI2S (PinsI2S pin) { i2s.push_back (pin); }
223- void addI2S (PinFunction function, Pin mclk, Pin bck, Pin ws, Pin data_out,
224- Pin data_in = -1 , int port = 0 ) {
223+ void addI2S (PinFunction function, GpioPin mclk, GpioPin bck, GpioPin ws, GpioPin data_out,
224+ GpioPin data_in = -1 , int port = 0 ) {
225225 PinsI2S pin{function, mclk, bck, ws, data_out, data_in, port};
226226 addI2S (pin);
227227 }
228228 void addSPI (PinsSPI pin) { spi.push_back (pin); }
229- void addSPI (PinFunction function, Pin clk, Pin miso, Pin mosi, Pin cs,
229+ void addSPI (PinFunction function, GpioPin clk, GpioPin miso, GpioPin mosi, GpioPin cs,
230230 SPIClass &spi = SPI) {
231231 PinsSPI pin (function, clk, miso, mosi, cs, spi);
232232 addSPI (pin);
233233 }
234234
235235 void addI2C (PinsI2C pin) { i2c.push_back (pin); }
236- void addI2C (PinFunction function, Pin scl, Pin sda, int port = -1 ,
236+ void addI2C (PinFunction function, GpioPin scl, GpioPin sda, int port = -1 ,
237237 uint32_t frequency = 100000 , TwoWire &wire = Wire) {
238238 PinsI2C pin (function, scl, sda, port, frequency);
239239 addI2C (pin);
240240 }
241241
242242 void addPin (PinsFunction pin) { pins.push_back (pin); }
243243
244- void addPin (PinFunction function, Pin pinNo, PinLogic logic,
244+ void addPin (PinFunction function, GpioPin pinNo, PinLogic logic,
245245 int index = 0 ) {
246246 PinsFunction pin (function, pinNo, logic, index);
247247 addPin (pin);
@@ -256,15 +256,15 @@ class DriverPins {
256256 }
257257
258258 // / Get pin information by pin ID
259- Optional<PinsFunction> getPin (Pin pinId) {
259+ Optional<PinsFunction> getPin (GpioPin pinId) {
260260 for (PinsFunction &pin : pins) {
261261 if (pin.pin == pinId)
262262 return pin;
263263 }
264264 return {};
265265 }
266266
267- Pin getPinID (PinFunction function, int pos = 0 ) {
267+ GpioPin getPinID (PinFunction function, int pos = 0 ) {
268268 auto pin = getPin (function, pos);
269269 if (pin)
270270 return pin.value ().pin ;
@@ -354,13 +354,21 @@ class DriverPins {
354354 }
355355 }
356356
357+ // / Defines if SPI for SD should be started (by default true)
357358 void setSPIActiveForSD (bool active){
358359 sd_active = active;
359360 }
361+
362+ // / Check if SPI for SD should be started automatically
360363 bool isSPIActiveForSD (){
361364 return sd_active;
362365 }
363366
367+ // / Returns true if some function pins have been defined
368+ bool hasPins (){
369+ return !pins.empty ();
370+ }
371+
364372protected:
365373 Vector<PinsI2S> i2s{0 };
366374 Vector<PinsSPI> spi{0 };
0 commit comments