AP_HAL_Linux: reset duty cycle before setting period

On kernels 4.7+ duty_cycle should always be less than period.
Otherways, we'll get a EINVAL.

It makes sense to set duty_cycle to 0, as
duty_cycle doesn't really make sense without a proper period.

A proper way to handle these errors might be to call pwm_adjust_config
in every pwmchip backend but it's unrealistic to hope that all vendors
will do it quickly.
This commit is contained in:
Georgii Staroselskii 2017-10-14 00:04:05 +03:00 committed by Lucas De Marchi
parent cc55e5a8fa
commit d214a36e0a
1 changed files with 2 additions and 0 deletions

View File

@ -94,6 +94,8 @@ bool PWM_Sysfs_Base::is_enabled()
void PWM_Sysfs_Base::set_period(uint32_t nsec_period)
{
set_duty_cycle(0);
if (Util::from(hal.util)->write_file(_period_path, "%u", nsec_period) < 0) {
hal.console->printf("LinuxPWM_Sysfs: %s Unable to set period\n",
_period_path);