1
1
#include " Arduino.h"
2
- # define CCU8V2 // for CCU8 PWM pins configure
2
+
3
3
XMC_PWM4_t *pwm4;
4
4
5
5
class Tone {
@@ -16,7 +16,7 @@ class Tone {
16
16
XMC_PWM4_t *pwm4 = &mapping_pwm4[pin_index];
17
17
configureTone (pin, frequency);
18
18
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 ) );
20
20
XMC_CCU4_SLICE_StartTimer (pwm4->slice );
21
21
// count pulses for stop the timer once reached required pulses
22
22
// if (duration > 0) {
@@ -46,7 +46,7 @@ class Tone {
46
46
XMC_PWM8_t *pwm8 = &mapping_pwm8[pin_index];
47
47
configureTone (pin, frequency);
48
48
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 ) );
50
50
XMC_CCU8_SLICE_StartTimer (pwm8->slice );
51
51
// calculate pulses
52
52
// if (duration > 0) {
@@ -77,9 +77,10 @@ class Tone {
77
77
void stop (pin_size_t pin) {
78
78
int pin_index;
79
79
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
83
84
}
84
85
#if defined(CCU8V2) || defined(CCU8V1)
85
86
else if ((pin_index = scanMapTable (mapping_pin_PWM8, pin)) >= 0 ) {
@@ -153,27 +154,26 @@ class Tone {
153
154
}
154
155
155
156
void configureTimerInterrupt (unsigned long duration_ms) {
156
-
157
157
XMC_CCU4_SLICE_COMPARE_CONFIG_t timer_config;
158
158
memset (&timer_config, 0 , sizeof (timer_config));
159
159
timer_config.prescaler_initval = XMC_CCU4_SLICE_PRESCALER_64;
160
160
timer_config.passive_level = XMC_CCU4_SLICE_OUTPUT_PASSIVE_LEVEL_LOW;
161
161
162
- XMC_CCU4_SLICE_CompareInit (CCU40_CC40 , &timer_config);
162
+ XMC_CCU4_SLICE_CompareInit (CCU40_CC42 , &timer_config);
163
163
164
164
// Calculate period for the timer based on the duration
165
165
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);
167
167
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,
170
170
XMC_CCU4_SLICE_SR_ID_0);
171
171
172
172
// Enable the NVIC interrupt
173
- NVIC_EnableIRQ (CCU40_0_IRQn );
173
+ NVIC_EnableIRQ (CCU40_2_IRQn );
174
174
175
175
// Start the timer
176
- XMC_CCU4_SLICE_StartTimer (CCU40_CC40 );
176
+ XMC_CCU4_SLICE_StartTimer (CCU40_CC42 );
177
177
}
178
178
};
179
179
@@ -186,11 +186,13 @@ void tone(pin_size_t pin, unsigned int frequency, unsigned long duration) {
186
186
}
187
187
188
188
void 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);
196
195
}
196
+ #ifdef __cplusplus
197
+ }
198
+ #endif
0 commit comments