1.优化配置,开关设备将不影响配置。

This commit is contained in:
MacRsh
2023-10-02 23:41:00 +08:00
parent c7af2cf352
commit e870216605
2 changed files with 5 additions and 15 deletions

View File

@@ -30,13 +30,6 @@ static mr_uint32_t err_io_pwm_read(mr_pwm_t pwm, mr_off_t channel)
static mr_err_t mr_pwm_open(mr_device_t device)
{
mr_pwm_t pwm = (mr_pwm_t)device;
struct mr_pwm_config default_config = MR_PWM_CONFIG_DEFAULT;
/* Enable pwm using default config */
if (pwm->config.freq == 0)
{
pwm->config = default_config;
}
return pwm->ops->configure(pwm, &pwm->config);
}
@@ -44,12 +37,9 @@ static mr_err_t mr_pwm_open(mr_device_t device)
static mr_err_t mr_pwm_close(mr_device_t device)
{
mr_pwm_t pwm = (mr_pwm_t)device;
struct mr_pwm_config config = {0};
/* Disable pwm */
pwm->config.freq = 0;
pwm->config.channel._mask = 0;
return pwm->ops->configure(pwm, &pwm->config);
return pwm->ops->configure(pwm, &config);
}
static mr_err_t mr_pwm_ioctl(mr_device_t device, int cmd, void *args)
@@ -150,14 +140,14 @@ mr_err_t mr_pwm_device_add(mr_pwm_t pwm, const char *name, struct mr_pwm_ops *op
mr_pwm_read,
mr_pwm_write,
};
struct mr_pwm_config default_config = MR_PWM_CONFIG_DEFAULT;
MR_ASSERT(pwm != MR_NULL);
MR_ASSERT(name != MR_NULL);
MR_ASSERT(ops != MR_NULL);
/* Initialize the private fields */
pwm->config.freq = 0;
pwm->config.channel._mask = 0;
pwm->config = default_config;
/* Protect every operation of the pwm device */
ops->configure = ops->configure ? ops->configure : err_io_pwm_configure;

View File

@@ -33,7 +33,7 @@ extern "C" {
1000, \
MR_PWM_MODE_NORMAL, \
0, \
0, \
{0}, \
}
/**