ChibiOS: add support for complementry output timer channels

This commit is contained in:
Alexander Malishev 2018-04-14 01:44:14 +04:00 committed by Andrew Tridgell
parent 1b7eecdf2f
commit 79b5719419
3 changed files with 19 additions and 3 deletions

View File

@ -133,6 +133,11 @@ void RCOutput::set_freq_group(pwm_group &group)
group.pwm_cfg.channels[j].mode = PWM_OUTPUT_ACTIVE_HIGH;
force_reconfig = true;
}
if (group.pwm_cfg.channels[j].mode == PWM_COMPLEMENTARY_OUTPUT_ACTIVE_LOW) {
group.pwm_cfg.channels[j].mode = PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH;
force_reconfig = true;
}
}
if (old_clock != group.pwm_cfg.frequency ||
@ -516,8 +521,13 @@ bool RCOutput::setup_group_DMA(pwm_group &group, uint32_t bitrate, uint32_t bit_
group.bit_width_mul = (freq + (target_frequency/2)) / target_frequency;
for (uint8_t j=0; j<4; j++) {
if (group.pwm_cfg.channels[j].mode != PWM_OUTPUT_DISABLED) {
group.pwm_cfg.channels[j].mode = active_high?PWM_OUTPUT_ACTIVE_HIGH:PWM_OUTPUT_ACTIVE_LOW;
pwmmode_t mode = group.pwm_cfg.channels[j].mode;
if (mode != PWM_OUTPUT_DISABLED) {
if(mode == PWM_COMPLEMENTARY_OUTPUT_ACTIVE_LOW || mode == PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH) {
group.pwm_cfg.channels[j].mode = active_high?PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH:PWM_COMPLEMENTARY_OUTPUT_ACTIVE_LOW;
} else {
group.pwm_cfg.channels[j].mode = active_high?PWM_OUTPUT_ACTIVE_HIGH:PWM_OUTPUT_ACTIVE_LOW;
}
}
}

View File

@ -283,7 +283,9 @@
/*
* PWM driver system settings.
*/
#ifndef STM32_PWM_USE_ADVANCED
#define STM32_PWM_USE_ADVANCED FALSE
#endif
#define STM32_PWM_TIM1_IRQ_PRIORITY 7
#define STM32_PWM_TIM2_IRQ_PRIORITY 7
#define STM32_PWM_TIM3_IRQ_PRIORITY 7

View File

@ -689,6 +689,7 @@ def write_PWM_config(f):
if p.type != t:
continue
chan_str = p.label[7]
is_complementary = p.label[-1] == 'N';
if not is_int(chan_str):
error("Bad channel for PWM %s" % p)
chan = int(chan_str)
@ -696,7 +697,10 @@ def write_PWM_config(f):
error("Bad channel number %u for PWM %s" % (chan, p))
pwm = p.extra_value('PWM', type=int)
chan_list[chan - 1] = pwm - 1
chan_mode[chan - 1] = 'PWM_OUTPUT_ACTIVE_HIGH'
if is_complementary:
chan_mode[chan - 1] = 'PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH'
else:
chan_mode[chan - 1] = 'PWM_OUTPUT_ACTIVE_HIGH'
alt_functions[chan - 1] = p.af
pal_lines[chan - 1] = 'PAL_LINE(GPIO%s, %uU)' % (p.port, p.pin)
groups.append('HAL_PWM_GROUP%u' % group)