34 InfoI2S pin{function, mclk, bck, ws, data_out, data_in, port};
49 InfoSPI pin(function, clk, miso, mosi, cs,
spi);
65 PinsI2C pin(function, -1, -1, -1, -1, &wire, setActive);
70 uint32_t frequency, TwoWire& wire,
bool active =
true) {
71 PinsI2C pin(function, scl, sda, port, frequency, &wire, active);
79 InfoI2C pin(function, scl, sda, port, frequency, wire, active);
93 InfoGPIO pin(function, pinNo, logic, index);
100 if (pin.function == updatedPin.
function &&
101 pin.index == updatedPin.
index) {
112 if (pin.pin == gpioPin) {
122 auto pin =
getPin(func, idx);
124 auto value = pin.value();
125 value.active = active;
136 if (pin.function == function && pin.index == pos)
return pin;
144 if (pin.pin == pinId)
return pin;
150 auto pin =
getPin(function, pos);
151 if (pin)
return pin.value().pin;
156 auto pin =
getPin(function, pos);
157 if (pin)
return pin.value().pin_logic;
165 if (
pins ==
nullptr)
return {};
172 if (
pins ==
nullptr)
return {};
188 if (
pins ==
nullptr)
return {};
194 AD_LOGD(
"DriverDeviceInfo::begin");
201 for (
auto& tmp :
spi) {
204 result &= tmp.begin();
206 result &= tmp.begin();
211 for (
auto& tmp :
i2c) {
212 result &= tmp.begin();
219 for (
auto& tmp :
spi) {
228 for (
auto& tmp :
i2c) {
229 AD_LOGD(
"DriverDeviceInfo::begin::I2C::end");
236 AD_LOGD(
"DriverDeviceInfo::setSPIActiveForSD: %d", active);
244 AD_LOGD(
"DriverDeviceInfo::setSDMMCActive: %d", active);
258 if (!pin_opt)
return false;
259 auto pin = pin_opt.value();
275 template <
typename T>
277 for (
auto&
pins : vect) {
278 if (
pins.function == function)
return &
pins;
283 template <
typename T>
285 T*
pins = getPtr<T>(pin.function, vect);
286 if (
pins ==
nullptr)
return false;
293 AD_LOGD(
"DriverDeviceInfo::setupPinMode");
295 for (
auto& tmp :
pins) {
298 AD_LOGD(
"pinMode for %d", tmp.pin);
299 switch (tmp.pin_logic) {
318 AD_LOGW(
"Pin '%d' not set up because of conflict", tmp.pin);
334 if (!sd)
return false;
336 return spi.
cs == pin ||
spi.clk == pin ||
spi.miso == pin ||
343 for (
auto& i2c_entry :
i2c) {
344 if (i2c_entry.scl == pin || i2c_entry.sda == pin) {
360 bool isKeyPressed(uint8_t key)
override {
362#if defined(ESP32) && defined(ARDUINO)
363#if SOC_TOUCH_SENSOR_SUPPORTED
365 if (!pin_opt)
return false;
366 auto pin = pin_opt.value();
367 int value = touchRead(pin.pin);
371 value = touchRead(pin.pin);
378 void setTouchLimit(
int limit) {
touch_limit = limit; }
#define INPUT
Definition DriverCommon.h:41
#define OUTPUT
Definition DriverCommon.h:44
#define INPUT_PULLUP
Definition DriverCommon.h:47
#define DEFAULT_WIRE
Definition DriverCommon.h:32
#define TOUCH_LIMIT
Definition DriverCommon.h:59
Simple GPIO abstraction for digital input/output.
#define AD_LOGD(...)
Definition Logger.h:12
#define AD_LOGW(...)
Definition Logger.h:14
All pins for i2s, spi, i2c and other pins.
Definition DriverDeviceInfo.h:20
audio_driver_local::Optional< InfoI2S > getI2SPins(PinFunction function=PinFunction::CODEC)
Finds the I2S pin info with the help of the function.
Definition DriverDeviceInfo.h:185
GpioPin getPinID(PinFunction function, int pos=0)
Definition DriverDeviceInfo.h:149
DriverDeviceInfo & operator=(const DriverDeviceInfo &)=delete
API_GPIO & getGPIO()
Definition DriverDeviceInfo.h:264
PinLogic getPinLogic(PinFunction function, int pos=0)
Definition DriverDeviceInfo.h:155
bool sdmmc_active
Definition DriverDeviceInfo.h:273
bool setI2C(InfoI2C pin)
Updates the I2C pin information using the function as key.
Definition DriverDeviceInfo.h:84
bool isSDMMCActive()
Check if SDMMC has been activated.
Definition DriverDeviceInfo.h:250
GPIOExt gpio
Definition DriverDeviceInfo.h:271
bool setPinActive(PinFunction func, int idx, bool active)
Updates an existing pin active flag for the indicated gpio.
Definition DriverDeviceInfo.h:121
bool addI2S(PinFunction function, GpioPin mclk, GpioPin bck, GpioPin ws, GpioPin data_out, GpioPin data_in=-1, int port=0)
Definition DriverDeviceInfo.h:32
audio_driver_local::Optional< InfoSPI > getSPIPins(PinFunction function)
Finds the SPI pin info with the help of the function.
Definition DriverDeviceInfo.h:170
virtual bool begin()
Sets up all pins e.g. by calling pinMode()
Definition DriverDeviceInfo.h:193
DriverDeviceInfo(const DriverDeviceInfo &)=delete
audio_driver_local::Optional< InfoI2C > getI2CPins(PinFunction function) override
Finds the I2C pin info with the help of the function.
Definition DriverDeviceInfo.h:162
bool addI2C(InfoI2C pin)
Definition DriverDeviceInfo.h:56
bool addPin(PinFunction function, GpioPin pinNo, PinLogic logic, int index=0)
Definition DriverDeviceInfo.h:91
T * getPtr(PinFunction function, audio_driver_local::Vector< T > &vect)
Definition DriverDeviceInfo.h:276
bool addI2S(InfoI2S pin)
Definition DriverDeviceInfo.h:26
audio_driver_local::Vector< InfoGPIO > pins
Definition DriverDeviceInfo.h:270
bool isSPIActiveForSD()
Check if SPI for SD should be started automatically.
Definition DriverDeviceInfo.h:240
bool hasConflict(int pin)
Definition DriverDeviceInfo.h:327
audio_driver_local::Optional< InfoGPIO > getPin(GpioPin pinId)
Get pin information by pin ID.
Definition DriverDeviceInfo.h:142
bool setSPI(InfoSPI pin)
Updates the SPI pin information using the function as key.
Definition DriverDeviceInfo.h:54
bool setPin(InfoGPIO updatedPin)
Updates an existing pin information using the function and index as key.
Definition DriverDeviceInfo.h:98
bool addSPI(PinFunction function, GpioPin clk, GpioPin miso, GpioPin mosi, GpioPin cs, SPIClass &spi)
Definition DriverDeviceInfo.h:47
bool setPinActive(int gpioPin, bool active)
Updates an existing pin active flag for the indicated gpio.
Definition DriverDeviceInfo.h:110
void setSDMMCActive(bool active)
Defines if SPI for SD should be started (by default true)
Definition DriverDeviceInfo.h:243
void end()
Definition DriverDeviceInfo.h:217
bool addPin(InfoGPIO pin)
Definition DriverDeviceInfo.h:86
void setupPinMode()
Definition DriverDeviceInfo.h:291
bool sd_active
Definition DriverDeviceInfo.h:272
void setSPIActiveForSD(bool active)
Defines if SPI for SD should be started (by default true)
Definition DriverDeviceInfo.h:235
bool addI2C(PinFunction function, GpioPin scl, GpioPin sda, int port=-1, uint32_t frequency=100000, i2c_bus_handle_t wire=DEFAULT_WIRE, bool active=true)
Definition DriverDeviceInfo.h:76
bool set(T pin, audio_driver_local::Vector< T > &vect)
Definition DriverDeviceInfo.h:284
bool hasPins()
Returns true if some function pins have been defined.
Definition DriverDeviceInfo.h:253
audio_driver_local::Vector< InfoSPI > spi
Definition DriverDeviceInfo.h:268
audio_driver_local::Optional< InfoGPIO > getPin(PinFunction function, int pos=0)
Get pin information by function.
Definition DriverDeviceInfo.h:133
audio_driver_local::Vector< InfoI2S > i2s
Definition DriverDeviceInfo.h:267
bool hasI2CConflict(int pin)
Definition DriverDeviceInfo.h:342
DriverDeviceInfo()=default
bool hasSPIConflict(int pin)
Definition DriverDeviceInfo.h:331
audio_driver_local::Vector< InfoI2C > i2c
Definition DriverDeviceInfo.h:269
bool addSPI(InfoSPI pin)
Definition DriverDeviceInfo.h:41
audio_driver_local::Optional< InfoI2S > getI2SPins(int port)
Finds the I2S pin info with the help of the port.
Definition DriverDeviceInfo.h:177
virtual bool isKeyPressed(uint8_t key)
returns true if pressed
Definition DriverDeviceInfo.h:256
bool setI2S(InfoI2S pin)
Updates the I2S pin information using the function as key.
Definition DriverDeviceInfo.h:39
Support for Touch.
Definition DriverDeviceInfo.h:359
int touch_limit
Definition DriverDeviceInfo.h:381
bool digitalRead(GpioPin pin) override
Definition GPIOExt.h:50
void pinMode(GpioPin pin, int mode) override
Definition GPIOExt.h:35
bool begin(IDriverDeviceInfo &pins) override
Definition GPIOExt.h:26
Definition IDriverDeviceInfo.h:171
A simple optonal implementation.
Definition Optional.h:10
Vector implementation which provides the most important methods as defined by std::vector....
Definition Vector.h:15
static DriverDeviceInfo NoPins
Pins need to be set up in the sketch.
Definition DriverDeviceInfo.h:390
Namespace for audio driver components.
Definition AudioBoard.h:5
int16_t GpioPin
Definition DriverCommon.h:153
PinLogic
Definition DriverCommon.h:328
PinFunction
Definition DriverCommon.h:344
InfoI2C PinsI2C
Definition IDriverDeviceInfo.h:168
void * i2c_bus_handle_t
Definition DriverCommon.h:155
Pins for LED, Buttons, AMP etc.
Definition IDriverDeviceInfo.h:24
int index
Definition IDriverDeviceInfo.h:35
PinFunction function
Definition IDriverDeviceInfo.h:33
I2C pins.
Definition IDriverDeviceInfo.h:127
PinFunction function
Definition IDriverDeviceInfo.h:151
I2S pins.
Definition IDriverDeviceInfo.h:47
PinFunction function
Definition IDriverDeviceInfo.h:59
SPI pins: In Arduino we initialize the SPI, on other platform we just provide the pin information.
Definition IDriverDeviceInfo.h:76
PinFunction function
Definition IDriverDeviceInfo.h:94
GpioPin cs
Definition API_SPI.h:23