@@ -18,27 +18,12 @@ class Tone {
1818 XMC_GPIO_SetMode (pwm4->port_pin .port , pwm4->port_pin .pin ,
1919 (XMC_GPIO_MODE_t)(XMC_GPIO_MODE_OUTPUT_PUSH_PULL | pwm4->port_mode ));
2020 XMC_CCU4_SLICE_StartTimer (pwm4->slice );
21- // count pulses for stop the timer once reached required pulses
22- // if (duration > 0) {
23- // uint32_t required_pulses = frequency * duration / 1000;
24- // for (uint32_t i = 0; i < required_pulses; i++) {
25- // while (
26- // !XMC_CCU4_SLICE_GetEvent(pwm4->slice,
27- // XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH)) {
28- // }
29- // XMC_CCU4_SLICE_ClearEvent(pwm4->slice, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH);
30- // }
31- // XMC_CCU4_SLICE_StopTimer(pwm4->slice);
32- // }
33- // if(duration >0) {
34- // unsigned long start_time = millis();
35- // while(millis() - start_time < duration) {
36- // delay(1);
37- // }
38- // XMC_CCU4_SLICE_StopTimer(pwm4->slice);
39- // }
40- if (duration > 0 ) {
41- configureTimerInterrupt (duration);
21+ if (duration >0 ) {
22+ unsigned long start_time = millis ();
23+ while (millis () - start_time < duration) {
24+ delay (1 );
25+ }
26+ XMC_CCU4_SLICE_StopTimer (pwm4->slice );
4227 }
4328 }
4429#if defined(CCU8V2) || defined(CCU8V1)
@@ -49,26 +34,12 @@ class Tone {
4934 (XMC_GPIO_MODE_t)(XMC_GPIO_MODE_OUTPUT_PUSH_PULL | pwm8->port_mode ));
5035 XMC_CCU8_SLICE_StartTimer (pwm8->slice );
5136 // calculate pulses
52- // if (duration > 0) {
53- // uint32_t required_pulses = frequency * duration / 1000;
54- // for (uint32_t i = 0; i < required_pulses; i++) {
55- // while (
56- // !XMC_CCU8_SLICE_GetEvent(pwm8->slice,
57- // XMC_CCU8_SLICE_IRQ_ID_PERIOD_MATCH)) {
58- // }
59- // XMC_CCU8_SLICE_ClearEvent(pwm8->slice, XMC_CCU8_SLICE_IRQ_ID_PERIOD_MATCH);
60- // }
61- // XMC_CCU8_SLICE_StopTimer(pwm8->slice);
62- // }
63- // if(duration >0) {
64- // unsigned long start_time = millis();
65- // while(millis() - start_time < duration) {
66- // delay(1);
67- // }
68- // XMC_CCU8_SLICE_StopTimer(pwm8->slice);
69- // }
70- if (duration > 0 ) {
71- configureTimerInterrupt (duration);
37+ if (duration >0 ) {
38+ unsigned long start_time = millis ();
39+ while (millis () - start_time < duration) {
40+ delay (1 );
41+ }
42+ XMC_CCU8_SLICE_StopTimer (pwm8->slice );
7243 }
7344 }
7445#endif
@@ -152,29 +123,6 @@ class Tone {
152123 }
153124 return -1 ;
154125 }
155-
156- void configureTimerInterrupt (unsigned long duration_ms) {
157- XMC_CCU4_SLICE_COMPARE_CONFIG_t timer_config;
158- memset (&timer_config, 0 , sizeof (timer_config));
159- timer_config.prescaler_initval = XMC_CCU4_SLICE_PRESCALER_64;
160- timer_config.passive_level = XMC_CCU4_SLICE_OUTPUT_PASSIVE_LEVEL_LOW;
161-
162- XMC_CCU4_SLICE_CompareInit (CCU40_CC42, &timer_config);
163-
164- // Calculate period for the timer based on the duration
165- uint32_t timer_ticks = (PCLK / 64 ) * duration_ms / 1000 ;
166- XMC_CCU4_SLICE_SetTimerPeriodMatch (CCU40_CC42, timer_ticks);
167-
168- XMC_CCU4_SLICE_EnableEvent (CCU40_CC42, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH);
169- XMC_CCU4_SLICE_SetInterruptNode (CCU40_CC42, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH,
170- XMC_CCU4_SLICE_SR_ID_0);
171-
172- // Enable the NVIC interrupt
173- NVIC_EnableIRQ (CCU40_2_IRQn);
174-
175- // Start the timer
176- XMC_CCU4_SLICE_StartTimer (CCU40_CC42);
177- }
178126};
179127
180128static Tone inst_Tone;
@@ -186,13 +134,4 @@ void tone(pin_size_t pin, unsigned int frequency, unsigned long duration) {
186134}
187135
188136void noTone (pin_size_t pin) { inst_Tone.stop (pin); }
189- #ifdef __cplusplus
190- extern " C" {
191- #endif
192- void CCU40_2_IRQHandler (void ) {
193- XMC_CCU4_SLICE_StopTimer (CCU40_CC42);
194- XMC_CCU4_SLICE_ClearEvent (CCU40_CC42, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH);
195- }
196- #ifdef __cplusplus
197- }
198- #endif
137+
0 commit comments