Merge pull request #10982 from gschorcht/cpu/esp8266/periph/pwm/pr

cpu/esp8266: fix pwm_set func
This commit is contained in:
Kevin "Bear Puncher" Weiss 2019-06-27 16:35:53 +02:00 committed by GitHub
commit 135ad3817b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -183,23 +183,35 @@ void pwm_set(pwm_t pwm, uint8_t channel, uint16_t value)
CHECK_PARAM (value <= _pwm_dev.res); CHECK_PARAM (value <= _pwm_dev.res);
uint32_t state = irq_disable(); uint32_t state = irq_disable();
uint32_t phase = _pwm_dev.cycles - _pwm_dev.cycles % _pwm_dev.res + _pwm_dev.res; uint32_t phase = _pwm_dev.cycles - _pwm_dev.cycles % _pwm_dev.res;
uint32_t next_on = phase;
uint32_t next_off;
switch (_pwm_dev.mode) { switch (_pwm_dev.mode) {
case PWM_LEFT: case PWM_LEFT:
_pwm_dev.chn[channel].next_on = phase; next_on = phase;
break; break;
case PWM_RIGHT: case PWM_RIGHT:
_pwm_dev.chn[channel].next_on = phase + _pwm_dev.res - value; next_on = phase + _pwm_dev.res - value;
break; break;
case PWM_CENTER: case PWM_CENTER:
_pwm_dev.chn[channel].next_on = phase + (_pwm_dev.res - value) / 2; next_on = phase + (_pwm_dev.res - value) / 2;
break; break;
} }
_pwm_dev.chn[channel].next_off = _pwm_dev.chn[channel].next_on + value; next_off = next_on + value;
if (_pwm_dev.cycles >= next_on) {
next_on += _pwm_dev.res;
}
if (_pwm_dev.cycles >= next_off) {
next_off += _pwm_dev.res;
}
_pwm_dev.chn[channel].next_on = next_on;
_pwm_dev.chn[channel].next_off = next_off;
_pwm_dev.chn[channel].duty = value; _pwm_dev.chn[channel].duty = value;
irq_restore(state); irq_restore(state);