/* Enable or disable PWM channel output. Make sure PWM clock is ON for writing registers.  */
static void pwm_channel_enable(struct rt_device_pwm *device, uint32_t channel, rt_bool_t enable)
/* Enable or disable PWM channel output. Make sure PWM clock is ON for writing registers.  */
static void pwm_channel_enable(struct rt_device_pwm *device, uint32_t channel, rt_bool_t enable)
{
    struct pwm_device *pwm_device = (struct pwm_device *)device;
    volatile struct pwm_registers *pxreg = pwm_device->reg_base;
    uint8_t ctrl_mod, polar;
    if (enable)
    {
        ctrl_mod = pxreg->CTRL_MOD.reg;
        pxreg->CTRL_MOD.reg = ctrl_mod | (RB_PWM0_OUT_EN << channel);
    }
    else
    {
        ctrl_mod = pxreg->CTRL_MOD.reg;
        polar = ctrl_mod & (RB_PWM0_POLAR << channel);
        rt_pin_write(pwmx_pin[channel], polar ? PIN_HIGH : PIN_LOW);
        ctrl_mod &= ~(RB_PWM0_OUT_EN << channel);
        pxreg->CTRL_MOD.reg = ctrl_mod;
    }
}