Mozzi  version v2.0
sound synthesis library for Arduino
config_checks_mbed.h
1 /*
2  * config_checks_mbed.h
3  *
4  * This file is part of Mozzi.
5  *
6  * Copyright 2023-2024 Thomas Friedrichsmeier and the Mozzi Team
7  *
8  * Mozzi is licensed under the GNU Lesser General Public Licence (LGPL) Version 2.1 or later.
9  *
10 */
11 
12 #ifndef CONFIG_CHECK_MBED_H
13 #define CONFIG_CHECK_MBED_H
14 
15 /**
16  * @page hardware_mbed Mozzi on MBED-based boards (Arduino Giga / Portenta).
17  *
18  * port by Thomas Friedrichsmeier & Thomas Combriat
19  *
20  * @section mbed_status Port status and notes
21  * Compiles and runs using Arduino's standard and Arduino_AdvancedAnalog libraries. This port is still **experimental**, testing reveals
22  * some instabilities for some configurations (in particular with @ref MOZZI_AUDIO_INPUT) that are under active investigations.
23  *
24  * This port is not complete yet, in particular:
25  * - Asynchroneous analog reads are not implemented (yet), `mozziAnalogRead()` relays to `analogRead()`. (Note that @ref MOZZI_AUDIO_INPUT @em is implemented!)
26  * - This port should support other MBED based Arduino boards like the Arduino Portenta, in *theory*, but the developer have only tested it on the Giga. Feedback welcome!
27  *
28  * @section mbed_output Output modes
29  * The following audio modes (see @ref MOZZI_AUDIO_MODE) are currently supported on this hardware:
30  * - MOZZI_OUTPUT_EXTERNAL_TIMED
31  * - MOZZI_OUTPUT_EXTERNAL_CUSTOM
32  * - MOZZI_OUTPUT_PDM_VIA_SERIAL
33  * - MOZZI_OUTPUT_INTERNAL_DAC
34  *
35  * The default mode is @ref mbed_internal_dac .
36  *
37  * @section mbed_internal_dac MOZZI_OUTPUT_INTERNAL_DAC
38  * This uses the inbuild DAC on the board. The default is setting is appropriate for the Arduino Giga: 12 bits going to A13 (3.5mm jack connector's tip),
39  * and in stereo mode to pin A12 (3.5mm jack connector's first ring) additionally.
40  *
41  * For other boards is may be appropriate to customize:
42  * @code
43  * #define MOZZI_AUDIO_PIN_1 ... // mono / left channel; default: A13
44  * #define MOZZI_AUDIO_PIN_2 ... // stereo only: right channel; default: A12
45  * #define MOZZI_AUDIO_BITS ... // default is 12
46  * @endcode
47  *
48  * @section mbed_pdm_via_serial MOZZI_PDM_VIA_SERIAL
49  * Returns a pulse-density modulated (mono only) signal on one of the hardware UARTs of the board (Serial ports). Default is using the SERIAL2, on pin D18.
50  * You can confiugre the pins to use, but it must be connected to a hardware UART. Output is written to the TX pin, only, but the RX pin needs to be
51  * claimed as well. Beware of confusing pinout labelling, for instance SERIAL2_TX iss labelled "TX1" on the Arduino Giga. The audio resolution can be enhanced
52  * using @ref MOZZI_PDM_RESOLUTION, which is described in more detail here: @esp32_pdm_via_i2s .
53  *
54  * Configuration options:
55  * @code
56  * #define MOZZI_SERIAL_PIN_TX ... // default: SERIAL2_TX
57  * #define MOZZI_SERIAL_PIN_RX ... // *must* specify the matching one, if customizing the above; default: SERIAL2_RX
58  * #define MOZZI_PDM_RESOLUTION ... // default value is 2, for 2*32 ones and zeros per audio sample
59  * @endcode
60  *
61  * @section mbed_external MOZZI_OUTPUT_EXTERNAL_TIMED and MOZZI_OUTPUT_EXTERNAL_CUSTOM
62  * See @ref external_audio
63 */
64 
65 
66 #if not IS_MBED()
67 #error This header should be included for MBED architecture, only
68 #endif
69 
71 #if !defined(MOZZI_AUDIO_MODE)
72 #define MOZZI_AUDIO_MODE MOZZI_OUTPUT_INTERNAL_DAC
73 #endif
74 MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED, MOZZI_OUTPUT_EXTERNAL_CUSTOM, MOZZI_OUTPUT_PDM_VIA_SERIAL, MOZZI_OUTPUT_INTERNAL_DAC)
75 
76 #if !defined(MOZZI_AUDIO_RATE)
77 #define MOZZI_AUDIO_RATE 32768
78 #endif
79 
80 #if defined(MOZZI_PWM_RATE)
81 #error Configuration of MOZZI_PWM_RATE is not currently supported on this platform (always same as MOZZI_AUDIO_RATE)
82 #endif
83 
84 #if !defined(MOZZI_ANALOG_READ)
85 # define MOZZI_ANALOG_READ MOZZI_ANALOG_READ_NONE
86 #endif
87 
88 // yes, correct: async "single" reads are not implemented, but audio input is
89 MOZZI_CHECK_SUPPORTED(MOZZI_ANALOG_READ, MOZZI_ANALOG_READ_NONE)
90 MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_NONE, MOZZI_AUDIO_INPUT_STANDARD)
91 
92 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_INTERNAL_DAC)
93 # if !defined(MOZZI_AUDIO_BITS)
94 # define MOZZI_AUDIO_BITS 12
95 # endif
96 # if !defined(MOZZI_AUDIO_PIN_1)
97 # define MOZZI_AUDIO_PIN_1 A13
98 # endif
99 # if !defined(MOZZI_AUDIO_PIN_2)
100 # define MOZZI_AUDIO_PIN_2 A12
101 # endif
102 #endif
103 
104 #if !defined(MOZZI_AUDIO_BITS)
105 # define MOZZI_AUDIO_BITS 16
106 #endif
107 
108 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PDM_VIA_SERIAL)
109 # if !defined(MOZZI_PDM_RESOLUTION)
110 # define MOZZI_PDM_RESOLUTION 2
111 # endif
112 # if !defined(MOZZI_SERIAL_PIN_TX)
113 # define MOZZI_SERIAL_PIN_TX SERIAL2_TX
114 # endif
115 # if !defined(MOZZI_SERIAL_PIN_RX)
116 # define MOZZI_SERIAL_PIN_RX SERIAL2_RX
117 # endif
118 #endif
119 
120 // All modes besides timed external bypass the output buffer!
121 #if !MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED)
122 # define BYPASS_MOZZI_OUTPUT_BUFFER true
123 #endif
124 
125 // TODO: This value is correct for Arduino Giga and Arduino Portenta, but not necessarily everywhere else
126 #define MOZZI__INTERNAL_ANALOG_READ_RESOLUTION 16
127 
128 #endif // #ifndef CONFIG_CHECK_MBED_H