@@ -87,15 +87,15 @@ void xbar_init() {
87
87
IMXRT_FLEXPWM_t* get_flexpwm (uint8_t pin){
88
88
89
89
const struct pwm_pin_info_struct *info;
90
- if (pin >= CORE_NUM_DIGITAL) {
90
+ info = pwm_pin_info + pin;
91
+ if (pin >= CORE_NUM_DIGITAL || info->type == 2 ) {
91
92
#ifdef SIMPLEFOC_TEENSY_DEBUG
92
93
char s[60 ];
93
94
sprintf (s, " TEENSY-DRV: ERR: Pin: %d not Flextimer pin!" , pin);
94
95
SIMPLEFOC_DEBUG (s);
95
96
#endif
96
97
return nullptr ;
97
98
}
98
- info = pwm_pin_info + pin;
99
99
// FlexPWM pin
100
100
IMXRT_FLEXPWM_t *flexpwm;
101
101
switch ((info->module >> 4 ) & 3 ) {
@@ -236,17 +236,16 @@ int get_submodule(uint8_t pin, uint8_t pin1){
236
236
// 1 - A
237
237
// 2 - B
238
238
int get_channel (uint8_t pin){
239
-
240
239
const struct pwm_pin_info_struct *info;
241
- if (pin >= CORE_NUM_DIGITAL){
240
+ info = pwm_pin_info + pin;
241
+ if (pin >= CORE_NUM_DIGITAL || info->type == 2 ){
242
242
#ifdef SIMPLEFOC_TEENSY_DEBUG
243
- char s[60 ];
243
+ char s[90 ];
244
244
sprintf (s, " TEENSY-DRV: ERR: Pin: %d not Flextimer pin!" , pin);
245
245
SIMPLEFOC_DEBUG (s);
246
246
#endif
247
247
return -1 ;
248
248
}
249
- info = pwm_pin_info + pin;
250
249
#ifdef SIMPLEFOC_TEENSY_DEBUG
251
250
char s[60 ];
252
251
sprintf (s, " TEENSY-DRV: Pin: %d on channel %s." , pin, info->channel ==0 ? " X" : info->channel ==1 ? " A" : " B" );
@@ -598,7 +597,7 @@ void write_pwm_on_pin(IMXRT_FLEXPWM_t *p, unsigned int submodule, uint8_t channe
598
597
// we can configure the center-aligned pwm
599
598
if ((flexpwmA != nullptr ) && (flexpwmB != nullptr ) && (flexpwmC != nullptr ) && (channelA > 0 ) && (channelB > 0 ) && (channelC > 0 ) ){
600
599
#ifdef SIMPLEFOC_TEENSY_DEBUG
601
- SIMPLEFOC_DEBUG (" TEENSY-DRV: All pins on Flexpwm A or B submodules - Configuring center-aligned pwm!" );
600
+ SIMPLEFOC_DEBUG (" TEENSY-DRV: All pins on Flexpwm A or B channels - Configuring center-aligned pwm!" );
602
601
#endif
603
602
604
603
// Configure FlexPWM units
@@ -645,7 +644,7 @@ void write_pwm_on_pin(IMXRT_FLEXPWM_t *p, unsigned int submodule, uint8_t channe
645
644
return params;
646
645
}else {
647
646
#ifdef SIMPLEFOC_TEENSY_DEBUG
648
- SIMPLEFOC_DEBUG (" TEENSY-DRV: Not all pins on Flexpwm A and B submodules - cannot configure center-aligned pwm!" );
647
+ SIMPLEFOC_DEBUG (" TEENSY-DRV: Not all pins on Flexpwm A and B channels - cannot configure center-aligned pwm!" );
649
648
#endif
650
649
return SIMPLEFOC_DRIVER_INIT_FAILED;
651
650
}
0 commit comments