1717#define TOLERANCE_DURATION_PERCENTAGE 5
1818#define TONE_PIN_OUTPUT TEST_PIN_DIGITAL_IO_OUTPUT
1919#define TONE_PIN_FEEDBACK TEST_PIN_DIGITAL_IO_INPUT
20+ // Architecture-Specific Test Data
21+ #if defined(ARDUINO_ARCH_XMC)
22+ #define TEST_FREQUENCIES_HZ {100 , 250 , 500 } // Test frequencies for XMC
23+ #define DEFAULT_TEST_FREQUENCY 250
24+ #else
25+ #define TEST_FREQUENCIES_HZ {500 , 1000 , 2000 } // Test frequencies for other architectures
26+ #define DEFAULT_TEST_FREQUENCY 1000
27+ #endif
28+
29+ #define TEST_DURATIONS_MS {500 , 1000 , 2000 } // Test durations for all architectures
2030
2131// Variables
2232volatile uint32_t current_time = 0 ; // Timestamp of the last rising/falling edge
@@ -140,7 +150,7 @@ static TEST_TEAR_DOWN(tone_no_tone) {
140150 * @brief Verify tone functionality for various frequencies without duration.
141151 */
142152TEST_IFX (tone_no_tone, test_tone_without_duration) {
143- const unsigned int test_frequencies_hz[] = { 500 , 1000 , 2000 };
153+ const unsigned int test_frequencies_hz[] = TEST_FREQUENCIES_HZ;
144154
145155 for (size_t i = 0 ; i < sizeof (test_frequencies_hz) / sizeof (test_frequencies_hz[0 ]); i++) {
146156 reset_tone ();
@@ -163,8 +173,7 @@ TEST_IFX(tone_no_tone, test_tone_without_duration) {
163173 * @brief Verify if the frequency changes correctly on same pin without calling notone.
164174 */
165175TEST_IFX (tone_no_tone, test_tone_change_frequency) {
166- const unsigned int test_frequencies_hz[] = {500 , 1000 , 2000 };
167-
176+ const unsigned int test_frequencies_hz[] = TEST_FREQUENCIES_HZ;
168177 for (size_t i = 0 ; i < sizeof (test_frequencies_hz) / sizeof (test_frequencies_hz[0 ]); i++) {
169178 reset_tone ();
170179 tone (TONE_PIN_OUTPUT, test_frequencies_hz[i]);
@@ -182,12 +191,11 @@ TEST_IFX(tone_no_tone, test_tone_change_frequency) {
182191 * @brief Verify tone functionality for various durations with specified frequency.
183192 */
184193TEST_IFX (tone_no_tone, test_tone_with_duration) {
185- const unsigned long test_durations_ms[] = { 500 , 1000 , 2000 };
194+ const unsigned long test_durations_ms[] = TEST_DURATIONS_MS;
186195
187196 for (size_t i = 0 ; i < sizeof (test_durations_ms) / sizeof (test_durations_ms[0 ]); i++) {
188197 reset_tone ();
189-
190- tone (TONE_PIN_OUTPUT, 2000 , test_durations_ms[i]);
198+ tone (TONE_PIN_OUTPUT, DEFAULT_TEST_FREQUENCY, test_durations_ms[i]);
191199 delay (test_durations_ms[i] + 100 ); // wait for the tone duration to elapse
192200
193201 float tolerance = TOLERANCE_DURATION_PERCENTAGE * test_durations_ms[i] / 100 .0f ;
@@ -200,7 +208,7 @@ TEST_IFX(tone_no_tone, test_tone_with_duration) {
200208 * @brief Verify noTone functionality stops the tone immediately.
201209 */
202210TEST_IFX (tone_no_tone, test_no_tone) {
203- tone (TONE_PIN_OUTPUT, 1000 );
211+ tone (TONE_PIN_OUTPUT, DEFAULT_TEST_FREQUENCY );
204212 delay (100 );
205213 noTone (TONE_PIN_OUTPUT);
206214 delay (1000 );
@@ -218,11 +226,7 @@ TEST_IFX(tone_no_tone, test_no_tone) {
218226 * The tone is expected to change frequency without stopping with duration specified.
219227 */
220228TEST_IFX (tone_no_tone, test_tone_overlap_frequency) {
221- #if defined(ARDUINO_ARCH_XMC)
222- const unsigned int test_frequencies_hz[] = {35 , 50 , 39 }; // Tested with XMC 4700 minimum frequency working from 35Hz
223- #else
224229 const unsigned int test_frequencies_hz[] = {5 , 10 , 20 };
225- #endif
226230 const unsigned int array_size = sizeof (test_frequencies_hz) / sizeof (test_frequencies_hz[0 ]);
227231 const unsigned int tone_duration_ms = 1000 ;
228232 const unsigned int delay_introduced_ms = 300 ;
@@ -246,8 +250,7 @@ TEST_IFX(tone_no_tone, test_tone_overlap_frequency) {
246250 * @brief Verify that calling tone again with different pin does not affect the output.
247251 */
248252TEST_IFX (tone_no_tone, test_tone_second_call) {
249- const unsigned int test_frequencies_hz = 1000 ;
250-
253+ const unsigned int test_frequencies_hz = DEFAULT_TEST_FREQUENCY;
251254 tone (TONE_PIN_OUTPUT, test_frequencies_hz);
252255 delay (500 );
253256 tone (TEST_PIN_SYNC_IO, test_frequencies_hz); // no effect on the second call
0 commit comments