Mozzi  version v2.0
sound synthesis library for Arduino
config_checks_avr.h
1 /*
2  * config_checks_avr.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 /* For Mozzi-internal use: Apply hardware specific config defaults and config checks: AVR */
13 
89 #if not defined(MOZZI_AUDIO_MODE)
90 #define MOZZI_AUDIO_MODE MOZZI_OUTPUT_PWM
91 #endif
92 
93 #if not defined(MOZZI_AUDIO_RATE)
94 #define MOZZI_AUDIO_RATE 16384
95 #endif
96 
97 #if not defined(MOZZI_ANALOG_READ)
98 #define MOZZI_ANALOG_READ MOZZI_ANALOG_READ_STANDARD
99 #endif
100 
101 // Pins for regular PWM output
102 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PWM)
103 # if !defined(MOZZI_AUDIO_PIN_1)
104 #define MOZZI_AUDIO_PIN_1 TIMER1_A_PIN
105 #define MOZZI_AUDIO_PIN_1_REGISTER OCR1A
106 # endif
107 # if (MOZZI_AUDIO_CHANNELS > 1) && !defined(MOZZI_AUDIO_PIN_2)
108 #define MOZZI_AUDIO_PIN_2 TIMER1_B_PIN
109 #define MOZZI_AUDIO_PIN_2_REGISTER OCR1B
110 # endif
111 
112 # if !defined(MOZZI_PWM_RATE)
113 #define MOZZI_PWM_RATE 32768
114 # endif
115 
116 #define MOZZI_AUDIO_BITS 8
117 #define MOZZI_AUDIO_BITS_OPTIMISTIC 9
118 #define MOZZI_AUDIO_BIAS ((uint8_t) 244)
119 #endif
120 
121 // Pins for 2 pin HIFI PWM output
122 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_2PIN_PWM)
123 # if !defined(MOZZI_AUDIO_PIN_1)
124 #define MOZZI_AUDIO_PIN_1 TIMER1_A_PIN
125 #define MOZZI_AUDIO_PIN_1_REGISTER OCR1A
126 # endif
127 # if !defined(MOZZI_AUDIO_PIN_1_LOW)
128 #define MOZZI_AUDIO_PIN_1_LOW TIMER1_B_PIN
129 #define MOZZI_AUDIO_PIN_1_LOW_REGISTER OCR1B
130 # endif
131 
132 # if !defined(MOZZI_PWM_RATE)
133 #define MOZZI_PWM_RATE 125000
134 # endif
135 
136 # if !defined(MOZZI_AUDIO_BITS_PER_CHANNEL)
137 #define MOZZI_AUDIO_BITS_PER_CHANNEL 7
138 # endif
139 
140 #define MOZZI_AUDIO_BITS (2*MOZZI_AUDIO_BITS_PER_CHANNEL)
141 #endif
142 
143 #define MOZZI__INTERNAL_ANALOG_READ_RESOLUTION 10
144 
145 // Step 2: Check
146 // NOTE: This step is not technically required, but a good idea in any port
147 
148 MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PWM, MOZZI_OUTPUT_2PIN_PWM, MOZZI_OUTPUT_EXTERNAL_TIMED, MOZZI_OUTPUT_EXTERNAL_CUSTOM)
149 
150 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PWM)
151 MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_CHANNELS, MOZZI_MONO, MOZZI_STEREO)
152 #endif
153 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_2PIN_PWM)
154 MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_CHANNELS, MOZZI_MONO)
155 #endif
156 
162 MOZZI_CHECK_SUPPORTED(MOZZI_ANALOG_READ, MOZZI_ANALOG_READ_NONE, MOZZI_ANALOG_READ_STANDARD)
163 MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_NONE, MOZZI_AUDIO_INPUT_STANDARD)
164 #include "../config/known_16bit_timers.h"
165 
166 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PWM, MOZZI_OUTPUT_2PIN_PWM)
167 # if defined(TIMER1_C_PIN)
168 MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_PIN_1, TIMER1_A_PIN, TIMER1_B_PIN, TIMER1_C_PIN);
169 # else
170 MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_PIN_1, TIMER1_A_PIN, TIMER1_B_PIN);
171 # endif
172 #endif
#define MOZZI_AUDIO_INPUT
Whether to enable built in audio input feature.
#define MOZZI_AUDIO_CHANNELS
This sets allows to change from a single/mono audio output channel to stereo output.
#define MOZZI_AUDIO_MODE
Configure how Mozzi outputs generated sounds.
#define MOZZI_AUDIO_PIN_1
Only for MOZZI_AUDIO_MODE s MOZZI_OUTPUT_PWM and MOZZI_OUTPUT_2PIN_PWM: The IO pin to use as (first) ...
#define MOZZI_ANALOG_READ
Whether to compile in support for non-blocking analog reads.