Skip to content

Commit 20ba975

Browse files
committed
Naming conflics with ESP32
1 parent 2c51abb commit 20ba975

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

src/Common.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ typedef enum {
6969
} output_device_t;
7070

7171
/**
72-
* @enum i2s_mode_t
72+
* @enum i2s_master_slave_t
7373
* @brief Select I2S interface operating mode i.e. master or slave for audio
7474
* codec chip
7575
* @ingroup enumerations
7676
*/
7777
typedef enum {
7878
MODE_SLAVE = 0x00, /*!< set slave mode */
7979
MODE_MASTER = 0x01, /*!< set master mode */
80-
} i2s_mode_t;
80+
} i2s_master_slave_t;
8181

8282
/**
8383
* @enum samplerate_t
@@ -164,7 +164,7 @@ typedef enum {
164164
*/
165165
typedef struct {
166166
/*!< Audio codec chip mode: if the microcontroller is master the codec must be slave! */
167-
i2s_mode_t mode;
167+
i2s_master_slave_t mode;
168168
/*!< I2S interface format */
169169
i2s_format_t fmt;
170170
/*!< I2S sample rate in samples per second */

src/Driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class AudioDriver {
189189

190190
/// Sets the PA Power pin to active or inactive
191191
bool setPAPower(bool enable) {
192-
Pin pin = pins().getPinID(PinFunction::PA);
192+
GpioPin pin = pins().getPinID(PinFunction::PA);
193193
if (pin == -1)
194194
return false;
195195
AD_LOGI("setPAPower pin %d -> %d", pin, enable);

src/DriverPins.h

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
5050
struct 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
*/
7676
struct 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
*/
143143
struct 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
*/
199199
struct 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 {
220220
class DriverPins {
221221
public:
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+
364372
protected:
365373
Vector<PinsI2S> i2s{0};
366374
Vector<PinsSPI> spi{0};

0 commit comments

Comments
 (0)