11#include " Arduino.h"
2- # define CCU8V2 // for CCU8 PWM pins configure
2+
33XMC_PWM4_t *pwm4;
44
55class Tone {
@@ -16,7 +16,7 @@ class Tone {
1616 XMC_PWM4_t *pwm4 = &mapping_pwm4[pin_index];
1717 configureTone (pin, frequency);
1818 XMC_GPIO_SetMode (pwm4->port_pin .port , pwm4->port_pin .pin ,
19- XMC_GPIO_MODE_OUTPUT_PUSH_PULL | pwm4->port_mode );
19+ (XMC_GPIO_MODE_t)( XMC_GPIO_MODE_OUTPUT_PUSH_PULL | pwm4->port_mode ) );
2020 XMC_CCU4_SLICE_StartTimer (pwm4->slice );
2121 // count pulses for stop the timer once reached required pulses
2222 // if (duration > 0) {
@@ -46,7 +46,7 @@ class Tone {
4646 XMC_PWM8_t *pwm8 = &mapping_pwm8[pin_index];
4747 configureTone (pin, frequency);
4848 XMC_GPIO_SetMode (pwm8->port_pin .port , pwm8->port_pin .pin ,
49- XMC_GPIO_MODE_OUTPUT_PUSH_PULL | pwm8->port_mode );
49+ (XMC_GPIO_MODE_t)( XMC_GPIO_MODE_OUTPUT_PUSH_PULL | pwm8->port_mode ) );
5050 XMC_CCU8_SLICE_StartTimer (pwm8->slice );
5151 // calculate pulses
5252 // if (duration > 0) {
@@ -77,9 +77,10 @@ class Tone {
7777 void stop (pin_size_t pin) {
7878 int pin_index;
7979 if ((pin_index = scanMapTable (mapping_pin_PWM4, pin)) >= 0 ) {
80- XMC_PWM4_t *pwm4 = &mapping_pwm4[pin_index];
81- XMC_CCU4_SLICE_StopTimer (pwm4->slice ); // stop the timer
82- XMC_CCU4_DisableClock (pwm4->ccu , pwm4->slice_num ); // Disable the clock
80+ XMC_PWM4_t *_XMC_pwm4_config = &mapping_pwm4[pin_index];
81+ XMC_CCU4_SLICE_StopTimer (_XMC_pwm4_config->slice ); // stop the timer
82+ XMC_CCU4_DisableClock (_XMC_pwm4_config->ccu ,
83+ _XMC_pwm4_config->slice_num ); // Disable the clock
8384 }
8485#if defined(CCU8V2) || defined(CCU8V1)
8586 else if ((pin_index = scanMapTable (mapping_pin_PWM8, pin)) >= 0 ) {
@@ -153,27 +154,26 @@ class Tone {
153154 }
154155
155156 void configureTimerInterrupt (unsigned long duration_ms) {
156-
157157 XMC_CCU4_SLICE_COMPARE_CONFIG_t timer_config;
158158 memset (&timer_config, 0 , sizeof (timer_config));
159159 timer_config.prescaler_initval = XMC_CCU4_SLICE_PRESCALER_64;
160160 timer_config.passive_level = XMC_CCU4_SLICE_OUTPUT_PASSIVE_LEVEL_LOW;
161161
162- XMC_CCU4_SLICE_CompareInit (CCU40_CC40 , &timer_config);
162+ XMC_CCU4_SLICE_CompareInit (CCU40_CC42 , &timer_config);
163163
164164 // Calculate period for the timer based on the duration
165165 uint32_t timer_ticks = (PCLK / 64 ) * duration_ms / 1000 ;
166- XMC_CCU4_SLICE_SetTimerPeriodMatch (CCU40_CC40 , timer_ticks);
166+ XMC_CCU4_SLICE_SetTimerPeriodMatch (CCU40_CC42 , timer_ticks);
167167
168- XMC_CCU4_SLICE_EnableEvent (CCU40_CC40 , XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH);
169- XMC_CCU4_SLICE_SetInterruptNode (CCU40_CC40 , XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH,
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,
170170 XMC_CCU4_SLICE_SR_ID_0);
171171
172172 // Enable the NVIC interrupt
173- NVIC_EnableIRQ (CCU40_0_IRQn );
173+ NVIC_EnableIRQ (CCU40_2_IRQn );
174174
175175 // Start the timer
176- XMC_CCU4_SLICE_StartTimer (CCU40_CC40 );
176+ XMC_CCU4_SLICE_StartTimer (CCU40_CC42 );
177177 }
178178};
179179
@@ -186,11 +186,13 @@ void tone(pin_size_t pin, unsigned int frequency, unsigned long duration) {
186186}
187187
188188void noTone (pin_size_t pin) { inst_Tone.stop (pin); }
189-
190- void CCU40_0_IRQHandler (void ) {
191-
192- XMC_CCU4_SLICE_StopTimer (pwm4->slice );
193-
194- XMC_CCU4_SLICE_StopTimer (CCU40_CC40);
195- XMC_CCU4_SLICE_ClearEvent (CCU40_CC40, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH);
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);
196195}
196+ #ifdef __cplusplus
197+ }
198+ #endif
0 commit comments