/* Internal function used to apply dither on the PWM signal. */
int32_t pwm_dither_apply(struct pwm_desc *dev)
/* Internal function used to apply dither on the PWM signal. */
int32_t pwm_dither_apply(struct pwm_desc *dev)
{
	int32_t ret = 0;
	int32_t duty;
	uint32_t temp;
	if(dev->has_dither == 1) {
		if(dither_period) {
			if (dev->dither_amplitude >= 1) {
				temp = dev->duty_cycle;
				duty = dev->duty_cycle + (int16_t)dith_ampl;
				if(duty < 0)
					duty = 0;
				if(duty > 10000)
					duty = 10000;
				ret = pwm_set_duty_cycle(dev, (uint32_t)duty);
				if(ret != 0)
					return ret;
				dev->duty_cycle = temp;
				dither_period = false;
			}
		}
	}
	return ret;
}