Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/corelibs/tone/test_tone_no_tone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
#define TOLERANCE_DURATION_PERCENTAGE 5
#define TONE_PIN_OUTPUT TEST_PIN_DIGITAL_IO_OUTPUT
#define TONE_PIN_FEEDBACK TEST_PIN_DIGITAL_IO_INPUT
// Architecture-Specific Test Data
#if defined(ARDUINO_ARCH_XMC)
#define TEST_FREQUENCIES_HZ {100, 250, 500} // Test frequencies for XMC
#define DEFAULT_TEST_FREQUENCY 250
#else
#define TEST_FREQUENCIES_HZ {500, 1000, 2000} // Test frequencies for other architectures
#define DEFAULT_TEST_FREQUENCY 1000
#endif

#define TEST_DURATIONS_MS {500, 1000, 2000} // Test durations for all architectures

// Variables
volatile uint32_t current_time = 0; // Timestamp of the last rising/falling edge
Expand Down Expand Up @@ -140,7 +150,7 @@ static TEST_TEAR_DOWN(tone_no_tone) {
* @brief Verify tone functionality for various frequencies without duration.
*/
TEST_IFX(tone_no_tone, test_tone_without_duration) {
const unsigned int test_frequencies_hz[] = {500, 1000, 2000};
const unsigned int test_frequencies_hz[] = TEST_FREQUENCIES_HZ;

for (size_t i = 0; i < sizeof(test_frequencies_hz) / sizeof(test_frequencies_hz[0]); i++) {
reset_tone();
Expand All @@ -163,8 +173,7 @@ TEST_IFX(tone_no_tone, test_tone_without_duration) {
* @brief Verify if the frequency changes correctly on same pin without calling notone.
*/
TEST_IFX(tone_no_tone, test_tone_change_frequency) {
const unsigned int test_frequencies_hz[] = {500, 1000, 2000};

const unsigned int test_frequencies_hz[] = TEST_FREQUENCIES_HZ;
for (size_t i = 0; i < sizeof(test_frequencies_hz) / sizeof(test_frequencies_hz[0]); i++) {
reset_tone();
tone(TONE_PIN_OUTPUT, test_frequencies_hz[i]);
Expand All @@ -182,12 +191,11 @@ TEST_IFX(tone_no_tone, test_tone_change_frequency) {
* @brief Verify tone functionality for various durations with specified frequency.
*/
TEST_IFX(tone_no_tone, test_tone_with_duration) {
const unsigned long test_durations_ms[] = {500, 1000, 2000};
const unsigned long test_durations_ms[] = TEST_DURATIONS_MS;

for (size_t i = 0; i < sizeof(test_durations_ms) / sizeof(test_durations_ms[0]); i++) {
reset_tone();

tone(TONE_PIN_OUTPUT, 2000, test_durations_ms[i]);
tone(TONE_PIN_OUTPUT, DEFAULT_TEST_FREQUENCY, test_durations_ms[i]);
delay(test_durations_ms[i] + 100); // wait for the tone duration to elapse

float tolerance = TOLERANCE_DURATION_PERCENTAGE * test_durations_ms[i] / 100.0f;
Expand All @@ -200,7 +208,7 @@ TEST_IFX(tone_no_tone, test_tone_with_duration) {
* @brief Verify noTone functionality stops the tone immediately.
*/
TEST_IFX(tone_no_tone, test_no_tone) {
tone(TONE_PIN_OUTPUT, 1000);
tone(TONE_PIN_OUTPUT, DEFAULT_TEST_FREQUENCY);
delay(100);
noTone(TONE_PIN_OUTPUT);
delay(1000);
Expand All @@ -218,11 +226,7 @@ TEST_IFX(tone_no_tone, test_no_tone) {
* The tone is expected to change frequency without stopping with duration specified.
*/
TEST_IFX(tone_no_tone, test_tone_overlap_frequency) {
#if defined(ARDUINO_ARCH_XMC)
const unsigned int test_frequencies_hz[] = {35, 50, 39}; //Tested with XMC 4700 minimum frequency working from 35Hz
#else
const unsigned int test_frequencies_hz[] = {5, 10, 20};
#endif
const unsigned int array_size = sizeof(test_frequencies_hz) / sizeof(test_frequencies_hz[0]);
const unsigned int tone_duration_ms = 1000;
const unsigned int delay_introduced_ms = 300;
Expand All @@ -246,8 +250,7 @@ TEST_IFX(tone_no_tone, test_tone_overlap_frequency) {
* @brief Verify that calling tone again with different pin does not affect the output.
*/
TEST_IFX(tone_no_tone, test_tone_second_call) {
const unsigned int test_frequencies_hz = 1000;

const unsigned int test_frequencies_hz = DEFAULT_TEST_FREQUENCY;
tone(TONE_PIN_OUTPUT, test_frequencies_hz);
delay(500);
tone(TEST_PIN_SYNC_IO, test_frequencies_hz); // no effect on the second call
Expand Down