/* Set pulse duration of the PWM channel. Make sure PWM clock is ON for writing registers.  */
static rt_err_t pwm_channel_pulse(struct rt_device_pwm *device, uint32_t channel, uint32_t pulse)
/* Set pulse duration of the PWM channel. Make sure PWM clock is ON for writing registers.  */
static rt_err_t pwm_channel_pulse(struct rt_device_pwm *device, uint32_t channel, uint32_t pulse)
{
    struct pwm_device *pwm_device = (struct pwm_device *)device;
    uint32_t pdata, period;
    period = pwm_device->period;
    if (!period || pulse > period)
        return -RT_EINVAL;
    pdata = (pulse * PWM_CYCLE_MAX + (period >> 1)) / period;
    pwm_device->reg_base->PWM_DATA[channel] = pdata;
    return RT_EOK;
}