arduino-audio-driver
Loading...
Searching...
No Matches
IDriverDeviceInfo.h
Go to the documentation of this file.
1
2#pragma once
3
4#include "DriverCommon.h"
5#include "Platforms/API_I2C.h"
6#include "Platforms/API_SPI.h"
9#include "Platforms/Logger.h"
10#include "Platforms/Optional.h"
11#include "Platforms/Vector.h"
12
13#if defined(__zephyr__)
14#include "IDriverDeviceInfoZephyr"
15#else
16
17namespace audio_driver {
18
24struct InfoGPIO {
25 InfoGPIO() = default;
27 int index = 0) {
28 this->function = function;
29 this->pin = pin;
30 this->index = index;
31 this->pin_logic = logic;
32 }
35 int index = 0;
37 bool active = true; // false if pin conflict
38};
39
40
41
47struct InfoI2S {
48 InfoI2S() = default;
50 GpioPin data_out, GpioPin data_in = -1, int port = 0) {
51 this->function = function;
52 this->mclk = mclk;
53 this->bck = bck;
54 this->ws = ws;
55 this->data_out = data_out;
56 this->data_in = data_in;
57 this->port = port;
58 }
65 int port; // port number
66};
67
69
76struct InfoSPI : public SPIConfig {
78 this->clk = -1;
79 this->miso = -1;
80 this->mosi = -1;
81 this->cs = -1;
82 this->p_spi = &SPI;
83 };
85 GpioPin cs, SPIClass& spi = SPI) {
86 this->function = function;
87 this->clk = clk;
88 this->miso = miso;
89 this->mosi = mosi;
90 this->cs = cs;
91 this->p_spi = &spi;
92 }
93
95 bool set_active = true;
96 bool pinsAvailable() { return clk != -1 && miso != -1 && mosi != -1; }
97 operator bool() { return pinsAvailable(); }
98 bool begin() {
99 if (set_active) {
100 AD_LOGD("PinsSPI::begin for %d", (int)function);
101 spi_bus_create(this);
102 } else {
103 AD_LOGI("SPI, not active, MOSI, MISO, SCLK, SSEL not modified");
104 }
105 return true;
106 }
107 void end() {
108 AD_LOGD("PinsSPI::end");
110 }
111};
112
114
120static InfoSPI ESP32PinsSD{PinFunction::SD, 14, 2, 15, 13, SPI};
121
127struct InfoI2C : public I2CConfig {
129 port = 0;
130 address = -1;
131 scl = -1;
132 sda = -1;
133 frequency = 100000;
134 set_active = true;
136 };
137
139 uint32_t frequency = 100000, i2c_bus_handle_t wire = DEFAULT_WIRE,
140 bool active = true) {
141 this->function = function;
142 this->scl = scl;
143 this->sda = sda;
144 this->port = 0;
145 this->frequency = frequency;
146 this->p_wire = wire;
147 this->set_active = active;
148 this->address = address;
149 }
150
152 bool set_active = true;
153 bool pinsAvailable() { return scl != -1 && sda != -1 && frequency != 0; }
154 operator bool() { return pinsAvailable(); }
155
156 bool begin() {
157 if (set_active) {
158 AD_LOGD("PinsI2C::begin for function %d on port %d", (int)function, port);
159 return i2c_bus_create(this) == RESULT_OK;
160 }
161 return true;
162 }
163 void end() {
164 if (set_active) i2c_bus_delete(p_wire);
165 }
166};
167
169
170
175
176} // namespace audio_driver
177
178#endif
#define RESULT_OK
Definition DriverCommon.h:74
#define DEFAULT_WIRE
Definition DriverCommon.h:32
#define AD_LOGD(...)
Definition Logger.h:12
#define AD_LOGI(...)
Definition Logger.h:13
Definition IDriverDeviceInfo.h:171
virtual audio_driver_local::Optional< InfoI2C > getI2CPins(PinFunction function)=0
A simple optonal implementation.
Definition Optional.h:10
Namespace for audio driver components.
Definition AudioBoard.h:5
struct audio_driver::SPIClass SPI
int16_t GpioPin
Definition DriverCommon.h:153
PinLogic
Definition DriverCommon.h:328
PinFunction
Definition DriverCommon.h:344
static InfoSPI ESP32PinsSD
Default SPI pins for ESP32 Lyrat, AudioDriver etc CLK, MISO, MOSI, CS.
Definition IDriverDeviceInfo.h:120
void spi_bus_delete(spi_bus_handle_t bus)
Definition API_SPI.h:76
void * i2c_bus_handle_t
Definition DriverCommon.h:155
error_t spi_bus_create(struct SPIConfig *config)
Definition API_SPI.h:71
Definition API_I2C.h:23
GpioPin scl
Definition API_I2C.h:30
int address
Definition API_I2C.h:27
i2c_bus_handle_t p_wire
Definition API_I2C.h:24
int port
Definition API_I2C.h:26
uint32_t frequency
Definition API_I2C.h:25
GpioPin sda
Definition API_I2C.h:31
Pins for LED, Buttons, AMP etc.
Definition IDriverDeviceInfo.h:24
bool active
Definition IDriverDeviceInfo.h:37
GpioPin pin
Definition IDriverDeviceInfo.h:34
InfoGPIO(PinFunction function, GpioPin pin, PinLogic logic, int index=0)
Definition IDriverDeviceInfo.h:26
int index
Definition IDriverDeviceInfo.h:35
PinLogic pin_logic
Definition IDriverDeviceInfo.h:36
PinFunction function
Definition IDriverDeviceInfo.h:33
I2C pins.
Definition IDriverDeviceInfo.h:127
InfoI2C()
Definition IDriverDeviceInfo.h:128
bool begin()
Definition IDriverDeviceInfo.h:156
void end()
Definition IDriverDeviceInfo.h:163
InfoI2C(PinFunction function, GpioPin scl, GpioPin sda, int address=-1, uint32_t frequency=100000, i2c_bus_handle_t wire=DEFAULT_WIRE, bool active=true)
Definition IDriverDeviceInfo.h:138
bool pinsAvailable()
Definition IDriverDeviceInfo.h:153
PinFunction function
Definition IDriverDeviceInfo.h:151
bool set_active
Definition IDriverDeviceInfo.h:152
I2S pins.
Definition IDriverDeviceInfo.h:47
GpioPin ws
Definition IDriverDeviceInfo.h:62
InfoI2S(PinFunction function, GpioPin mclk, GpioPin bck, GpioPin ws, GpioPin data_out, GpioPin data_in=-1, int port=0)
Definition IDriverDeviceInfo.h:49
int port
Definition IDriverDeviceInfo.h:65
GpioPin bck
Definition IDriverDeviceInfo.h:61
GpioPin data_out
Definition IDriverDeviceInfo.h:63
PinFunction function
Definition IDriverDeviceInfo.h:59
GpioPin mclk
Definition IDriverDeviceInfo.h:60
GpioPin data_in
Definition IDriverDeviceInfo.h:64
SPI pins: In Arduino we initialize the SPI, on other platform we just provide the pin information.
Definition IDriverDeviceInfo.h:76
InfoSPI()
Definition IDriverDeviceInfo.h:77
bool begin()
Definition IDriverDeviceInfo.h:98
void end()
Definition IDriverDeviceInfo.h:107
bool pinsAvailable()
Definition IDriverDeviceInfo.h:96
PinFunction function
Definition IDriverDeviceInfo.h:94
InfoSPI(PinFunction function, GpioPin clk, GpioPin miso, GpioPin mosi, GpioPin cs, SPIClass &spi=SPI)
Definition IDriverDeviceInfo.h:84
bool set_active
Definition IDriverDeviceInfo.h:95
Definition API_SPI.h:13
Definition API_SPI.h:18
spi_bus_handle_t p_spi
Definition API_SPI.h:19
GpioPin cs
Definition API_SPI.h:23
GpioPin miso
Definition API_SPI.h:21
GpioPin clk
Definition API_SPI.h:20
GpioPin mosi
Definition API_SPI.h:22