Skip to content

Commit

Permalink
Default mode for ESP32 that do not have an internal DAC set to PWM
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcombriat committed Jan 20, 2025
1 parent 4964133 commit 1070453
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
12 changes: 7 additions & 5 deletions extras/website/_includes/boards-tested.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ If stereo is supported, in a mode, the cell has a red/blue background, and (wher
Check the [hardware section of the API-documentation](https://sensorium.github.io/Mozzi/doc/html/hardware.html) for platform specific notes and (pin) configuration options.

<style>
td[data-mo] { background-color: rgba(0,0,255,.5); }
td[data-st] { background: linear-gradient(-45deg,rgba(0,0,255,.5) 50%, rgba(255,0,0,.5) 50%); }
td[data-md] { border: 2px solid; background-color: rgba(0,0,255,.5); }
td[data-sd] { border: 2px solid; background: linear-gradient(-45deg,rgba(0,0,255,.5) 50%, rgba(255,0,0,.5) 50%); }
td[data-mo] { background-color: rgba(0,0,255,.5); } <!-- Mono output --->
td[data-st] { background: linear-gradient(-45deg,rgba(0,0,255,.5) 50%, rgba(255,0,0,.5) 50%); } <!-- Stereo output --->
td[data-md] { border: 2px solid; background-color: rgba(0,0,255,.5); } <!-- Mono default --->
td[data-sd] { border: 2px solid; background: linear-gradient(-45deg,rgba(0,0,255,.5) 50%, rgba(255,0,0,.5) 50%); } <!-- Stereo default --->
</style>

<table border="0">
Expand Down Expand Up @@ -42,7 +42,9 @@ td[data-sd] { border: 2px solid; background: linear-gradient(-45deg,rgba(0,0,255
<tr style="border-top: 1px solid">
<td><i>ESP8266</i>: ESP-01, Wemos D1 mini, etc. <i>note: Beware of erratic pin labels</i> </td><td> - </td><td> - </td><td data-md>GPIO2</td><td> - </td><td data-st>yes </td></tr>
<tr style="border-top: 1px solid">
<td><i>ESP32</i>: <i>note: Beware of vastly different pin labels across board variants</i> </td><td> - </td><td> - </td><td data-mo>yes </td><td data-sd>GPIO25 (+GPIO26)</td><td data-st>yes</td></tr>
<td><i>ESP32</i>: that has an internal DAC (only ESP32)<i>note: Beware of vastly different pin labels across board variants</i> </td><td data-st>15 (+16) </td><td> </td><td data-mo>yes </td><td data-sd>GPIO25 (+GPIO26)</td><td data-st>yes</td></tr>
<tr style="border-top: 1px solid">
<td><i>ESP32-S/C/H/P</i>: that do not have an internal DAC<i>note: Beware of vastly different pin labels across board variants</i> </td><td data-sd>15 (+16) </td><td> </td><td data-mo>yes </td><td></td><td data-st>yes</td></tr>
<tr style="border-top: 1px solid">
<td><i>RP2040</i>: Raspberry Pi Pico and friends </td><td data-sd>0 (+1) </td><td data-mo>0, 1 </td><td> - </td><td> - </td><td data-st>yes </td></tr>
</tbody>
Expand Down
23 changes: 18 additions & 5 deletions internal/config_checks_esp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This file is part of Mozzi.
*
* Copyright 2023-2024 Thomas Friedrichsmeier and the Mozzi Team
* Copyright 2025 Thomas Combriat and the Mozzi Team
*
* Mozzi is licensed under the GNU Lesser General Public Licence (LGPL) Version 2.1 or later.
*
Expand Down Expand Up @@ -31,8 +32,9 @@
* - MOZZI_OUTPUT_PDM_VIA_I2S
* - MOZZI_OUTPUT_I2S_DAC
* - MOZZI_OUTPUT_INTERNAL_DAC
* - MOZZI_OUTPUT_PWM
*
* The default mode is @ref esp32_internal_dac .
* The default mode is @ref esp32_internal_dac for the ESP32 (that has a built-in DAC) and @ref esp32_pwm for all other ESP32 flavours.
*
* @section esp32_internal_dac MOZZI_OUTPUT_INTERNAL_DAC
* The internal DAC has 8 bit resolution, and outputs to GPIO pins 25 and 26 (non-configurable). For simplicity of code, both pins are always used.
Expand Down Expand Up @@ -88,6 +90,13 @@
* Output resolution may be adjusted by defining MOZZI_PDM_RESOLUTION , where the default value of 4 means that each audio sample is encoded into four 32 bit blocks
* of ones and zeros. Obviously, more is potentially better, but at the cost of considerable computation power.
*
* @section esp32_pwm MOZZI_OUTPUT_PWM
* This mode outputs a standard PWM signal (10 bits) cadenced at MOZZI_AUDIO_RATE. Allegedly, any pin should qualify but by default it is set to GPIO 15 (left/mono) and GPIO 16 (right). They can be customized by using:
* @code
* #define MOZZI_AUDIO_PIN_1 ... // (default: 15)
* #define MOZZI_AUDIO_PIN_2 ... // (default: 16)
* @endcode
*
* @section esp32_external MOZZI_OUTPUT_EXTERNAL_TIMED and MOZZI_OUTPUT_EXTERNAL_CUSTOM
* See @ref external_audio
*/
Expand All @@ -98,7 +107,11 @@

#include "disable_2pinmode_on_github_workflow.h"
#if !defined(MOZZI_AUDIO_MODE)
#define MOZZI_AUDIO_MODE MOZZI_OUTPUT_INTERNAL_DAC
# if CONFIG_IDF_TARGET_ESP32
# define MOZZI_AUDIO_MODE MOZZI_OUTPUT_INTERNAL_DAC
# else // only ESP32 carries an internal DAC
# define MOZZI_AUDIO_MODE MOZZI_OUTPUT_PWM
# endif
#endif
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)

Expand Down Expand Up @@ -156,12 +169,12 @@ MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_NONE)
#endif

#if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PWM)
# define MOZZI_AUDIO_BITS 10 // not configurable (could be 8)
# define MOZZI_AUDIO_BITS 10 // not configurable (could be 8 at AUDIO_RATE, working combinations are not specified on espressif's doc)
# if !defined(MOZZI_AUDIO_PIN_1)
# define MOZZI_AUDIO_PIN_1 18
# define MOZZI_AUDIO_PIN_1 15
# endif
# if !defined(MOZZI_AUDIO_PIN_2)
# define MOZZI_AUDIO_PIN_2 19
# define MOZZI_AUDIO_PIN_2 16
# endif
#endif

Expand Down

0 comments on commit 1070453

Please sign in to comment.