Mozzi  version v2.0
sound synthesis library for Arduino
config_checks_esp32.h
1 /*
2  * config_checks_esp32.h
3  *
4  * This file is part of Mozzi.
5  *
6  * Copyright 2023-2024 Thomas Friedrichsmeier and the Mozzi Team
7  * Copyright 2025 Thomas Combriat and the Mozzi Team
8  *
9  * Mozzi is licensed under the GNU Lesser General Public Licence (LGPL) Version 2.1 or later.
10  *
11 */
12 
13 #ifndef CONFIG_CHECK_ESP32_H
14 #define CONFIG_CHECK_ESP32_H
15 
104 #if not IS_ESP32()
105 #error This header should be included for ESP32 architecture, only
106 #endif
107 
108 #include "disable_2pinmode_on_github_workflow.h"
109 #if !defined(MOZZI_AUDIO_MODE)
110 # if CONFIG_IDF_TARGET_ESP32
111 # define MOZZI_AUDIO_MODE MOZZI_OUTPUT_INTERNAL_DAC
112 # else // only ESP32 carries an internal DAC
113 # define MOZZI_AUDIO_MODE MOZZI_OUTPUT_PWM
114 # endif
115 #endif
116 MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED, MOZZI_OUTPUT_EXTERNAL_CUSTOM, MOZZI_OUTPUT_PDM_VIA_I2S, MOZZI_OUTPUT_I2S_DAC, MOZZI_OUTPUT_INTERNAL_DAC, MOZZI_OUTPUT_PWM)
117 
118 #if !defined(MOZZI_AUDIO_RATE)
119 #define MOZZI_AUDIO_RATE 32768
120 #endif
121 
122 #if defined(MOZZI_PWM_RATE)
123 #error Configuration of MOZZI_PWM_RATE is not currently supported on this platform (always same as MOZZI_AUDIO_RATE)
124 #endif
125 
126 #if !defined(MOZZI_ANALOG_READ)
127 # define MOZZI_ANALOG_READ MOZZI_ANALOG_READ_NONE
128 #endif
129 
130 MOZZI_CHECK_SUPPORTED(MOZZI_ANALOG_READ, MOZZI_ANALOG_READ_NONE)
131 MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_NONE)
132 
133 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_I2S_DAC)
134 # if !defined(MOZZI_I2S_FORMAT)
135 # define MOZZI_I2S_FORMAT MOZZI_I2S_FORMAT_PLAIN
136 # endif
137 # if !defined(MOZZI_I2S_PIN_BCK)
138 # define MOZZI_I2S_PIN_BCK 26
139 # endif
140 # if !defined(MOZZI_I2S_PIN_WS)
141 # define MOZZI_I2S_PIN_WS 25
142 # endif
143 # if !defined(MOZZI_I2S_PIN_DATA)
144 # define MOZZI_I2S_PIN_DATA 33
145 # endif
146 # if !defined(MOZZI_I2S_PIN_MCLK)
147 # define MOZZI_I2S_PIN_MCLK I2S_GPIO_UNUSED
148 # endif
149 # if !defined(MOZZI_I2S_BCK_INV)
150 # define MOZZI_I2S_BCK_INV 0
151 # endif
152 # if !defined(MOZZI_I2S_WS_INV)
153 # if MOZZI_IS(MOZZI_I2S_FORMAT, MOZZI_I2S_FORMAT_PLAIN)
154 # define MOZZI_I2S_WS_INV 0
155 # elif MOZZI_IS(MOZZI_I2S_FORMAT, MOZZI_I2S_FORMAT_LSBJ)
156 # define MOZZI_I2S_WS_INV 1
157 # endif
158 # endif
159 # if !defined(MOZZI_I2S_MBCK_INV)
160 # define MOZZI_I2S_MBCK_INV 0
161 # endif
162 #endif
163 
164 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_I2S_DAC, MOZZI_OUTPUT_PDM_VIA_I2S)
165 # if !defined(MOZZI_I2S_FORMAT)
166 # define MOZZI_I2S_FORMAT MOZZI_I2S_FORMAT_PLAIN
167 # endif
168 # if !defined(MOZZI_I2S_PIN_BCK)
169 # define MOZZI_I2S_PIN_BCK I2S_GPIO_UNUSED
170 # endif
171 # if !defined(MOZZI_I2S_PIN_WS)
172 # define MOZZI_I2S_PIN_WS I2S_GPIO_UNUSED
173 # endif
174 # if !defined(MOZZI_I2S_PIN_DATA)
175 # define MOZZI_I2S_PIN_DATA 33
176 # endif
177 # if !defined(MOZZI_I2S_PIN_MCLK)
178 # define MOZZI_I2S_PIN_MCLK I2S_GPIO_UNUSED
179 # endif
180 # define MOZZI_I2S_WS_INV 0 // unused but need to be defined
181 # define MOZZI_I2S_BCK_INV 0
182 # define MOZZI_I2S_MBCK_INV 0
183 #endif
184 
185 #if MOZZI_IS(MOZZI_AUDIO_MODE/*, MOZZI_OUTPUT_INTERNAL_DAC*/, MOZZI_OUTPUT_I2S_DAC, MOZZI_OUTPUT_PDM_VIA_I2S)
186 //# include <driver/i2s.h>
187 # if !defined(MOZZI_IS2_PORT)
188 # define MOZZI_I2S_PORT I2S_NUM_0
189 # endif
190 #endif
191 
192 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PWM)
193 # define MOZZI_AUDIO_BITS 10 // not configurable (could be 8 at AUDIO_RATE, working combinations are not specified on espressif's doc)
194 # if !defined(MOZZI_AUDIO_PIN_1)
195 # define MOZZI_AUDIO_PIN_1 15
196 # endif
197 # if !defined(MOZZI_AUDIO_PIN_2)
198 # define MOZZI_AUDIO_PIN_2 16
199 # endif
200 #endif
201 
202 #if !defined(MOZZI_AUDIO_BITS)
203 # if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_INTERNAL_DAC)
204 # define MOZZI_AUDIO_BITS 8
205 # else
206 # define MOZZI_AUDIO_BITS 16
207 # endif
208 #endif
209 
210 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PDM_VIA_I2S)
211 # define MOZZI_I2S_FORMAT MOZZI_I2S_FORMAT_LSBJ // pdm codes are for LSBJ format
212 # if !defined(MOZZI_PDM_RESOLUTION)
213 # define MOZZI_PDM_RESOLUTION 8
214 # endif
215 #else
216 # define MOZZI_PDM_RESOLUTION 1 // unconditionally, no other value allowed
217 #endif
218 
219 
220 // All modes besides timed external bypass the output buffer!
221 #if !MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED, MOZZI_OUTPUT_INTERNAL_DAC, MOZZI_OUTPUT_PWM)
222 # define BYPASS_MOZZI_OUTPUT_BUFFER true
223 #endif
224 
225 #define MOZZI__INTERNAL_ANALOG_READ_RESOLUTION 12
226 
227 #endif // #ifndef CONFIG_CHECK_ESP32_H
#define MOZZI_AUDIO_INPUT
Whether to enable built in audio input feature.
#define MOZZI_AUDIO_MODE
Configure how Mozzi outputs generated sounds.
#define MOZZI_ANALOG_READ
Whether to compile in support for non-blocking analog reads.