drivers: pwm: remove _pin from API calls

In a first place, the PWM API operates on "channels", not "pins". While
the API calls could have been changed by _channel, this patch takes the
approach of just dropping _pin. The main reason is that all API calls
operate by definition on a channel basis, so it is a bit redundant to
make this part of the name. Because the `_dt` variants of the calls are
going to be introduced soon, the change to `_channels` + `_dt` would
make API function names quite long.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-04-01 10:24:14 +02:00 committed by Carles Cufí
commit 95b56cdffd
4 changed files with 277 additions and 146 deletions

View file

@ -11,21 +11,20 @@
LOG_MODULE_REGISTER(pwm_capture, CONFIG_PWM_LOG_LEVEL);
struct z_pwm_pin_capture_cb_data {
struct z_pwm_capture_cb_data {
uint32_t period;
uint32_t pulse;
struct k_sem sem;
int status;
};
static void z_pwm_pin_capture_cycles_callback(const struct device *dev,
uint32_t channel,
uint32_t period_cycles,
uint32_t pulse_cycles,
int status,
void *user_data)
static void z_pwm_capture_cycles_callback(const struct device *dev,
uint32_t channel,
uint32_t period_cycles,
uint32_t pulse_cycles, int status,
void *user_data)
{
struct z_pwm_pin_capture_cb_data *data = user_data;
struct z_pwm_capture_cb_data *data = user_data;
data->period = period_cycles;
data->pulse = pulse_cycles;
@ -34,11 +33,11 @@ static void z_pwm_pin_capture_cycles_callback(const struct device *dev,
k_sem_give(&data->sem);
}
int z_impl_pwm_pin_capture_cycles(const struct device *dev, uint32_t channel,
pwm_flags_t flags, uint32_t *period,
uint32_t *pulse, k_timeout_t timeout)
int z_impl_pwm_capture_cycles(const struct device *dev, uint32_t channel,
pwm_flags_t flags, uint32_t *period,
uint32_t *pulse, k_timeout_t timeout)
{
struct z_pwm_pin_capture_cb_data data;
struct z_pwm_capture_cb_data data;
int err;
if ((flags & PWM_CAPTURE_MODE_MASK) == PWM_CAPTURE_MODE_CONTINUOUS) {
@ -49,15 +48,14 @@ int z_impl_pwm_pin_capture_cycles(const struct device *dev, uint32_t channel,
flags |= PWM_CAPTURE_MODE_SINGLE;
k_sem_init(&data.sem, 0, 1);
err = pwm_pin_configure_capture(dev, channel, flags,
z_pwm_pin_capture_cycles_callback,
&data);
err = pwm_configure_capture(dev, channel, flags,
z_pwm_capture_cycles_callback, &data);
if (err) {
LOG_ERR("failed to configure pwm capture");
return err;
}
err = pwm_pin_enable_capture(dev, channel);
err = pwm_enable_capture(dev, channel);
if (err) {
LOG_ERR("failed to enable pwm capture");
return err;
@ -65,8 +63,8 @@ int z_impl_pwm_pin_capture_cycles(const struct device *dev, uint32_t channel,
err = k_sem_take(&data.sem, timeout);
if (err == -EAGAIN) {
(void)pwm_pin_disable_capture(dev, channel);
(void)pwm_pin_configure_capture(dev, channel, flags, NULL, NULL);
(void)pwm_disable_capture(dev, channel);
(void)pwm_configure_capture(dev, channel, flags, NULL, NULL);
LOG_WRN("pwm capture timed out");
return err;
}

View file

@ -8,15 +8,15 @@
#include <syscall_handler.h>
#include <drivers/pwm.h>
static inline int z_vrfy_pwm_pin_set_cycles(const struct device *dev,
uint32_t channel, uint32_t period,
uint32_t pulse, pwm_flags_t flags)
static inline int z_vrfy_pwm_set_cycles(const struct device *dev,
uint32_t channel, uint32_t period,
uint32_t pulse, pwm_flags_t flags)
{
Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, pin_set));
return z_impl_pwm_pin_set_cycles((const struct device *)dev, channel,
Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, set_cycles));
return z_impl_pwm_set_cycles((const struct device *)dev, channel,
period, pulse, flags);
}
#include <syscalls/pwm_pin_set_cycles_mrsh.c>
#include <syscalls/pwm_set_cycles_mrsh.c>
static inline int z_vrfy_pwm_get_cycles_per_sec(const struct device *dev,
uint32_t channel,
@ -31,41 +31,38 @@ static inline int z_vrfy_pwm_get_cycles_per_sec(const struct device *dev,
#ifdef CONFIG_PWM_CAPTURE
static inline int z_vrfy_pwm_pin_enable_capture(const struct device *dev,
uint32_t channel)
static inline int z_vrfy_pwm_enable_capture(const struct device *dev,
uint32_t channel)
{
Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, pin_enable_capture));
return z_impl_pwm_pin_enable_capture((const struct device *)dev,
channel);
Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, enable_capture));
return z_impl_pwm_enable_capture((const struct device *)dev, channel);
}
#include <syscalls/pwm_pin_enable_capture_mrsh.c>
#include <syscalls/pwm_enable_capture_mrsh.c>
static inline int z_vrfy_pwm_pin_disable_capture(const struct device *dev,
uint32_t channel)
static inline int z_vrfy_pwm_disable_capture(const struct device *dev,
uint32_t channel)
{
Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, pin_disable_capture));
return z_impl_pwm_pin_disable_capture((const struct device *)dev,
channel);
Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, disable_capture));
return z_impl_pwm_disable_capture((const struct device *)dev, channel);
}
#include <syscalls/pwm_pin_disable_capture_mrsh.c>
#include <syscalls/pwm_disable_capture_mrsh.c>
static inline int z_vrfy_pwm_pin_capture_cycles(const struct device *dev,
uint32_t channel,
pwm_flags_t flags,
uint32_t *period_cycles,
uint32_t *pulse_cycles,
k_timeout_t timeout)
static inline int z_vrfy_pwm_capture_cycles(const struct device *dev,
uint32_t channel, pwm_flags_t flags,
uint32_t *period_cycles,
uint32_t *pulse_cycles,
k_timeout_t timeout)
{
uint32_t period;
uint32_t pulse;
int err;
Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, pin_configure_capture));
Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, pin_enable_capture));
Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, pin_disable_capture));
Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, configure_capture));
Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, enable_capture));
Z_OOPS(Z_SYSCALL_DRIVER_PWM(dev, disable_capture));
err = z_impl_pwm_pin_capture_cycles((const struct device *)dev, channel,
flags, &period, &pulse, timeout);
err = z_impl_pwm_capture_cycles((const struct device *)dev, channel,
flags, &period, &pulse, timeout);
if (period_cycles != NULL) {
Z_OOPS(z_user_to_copy(period_cycles, &period,
sizeof(*period_cycles)));
@ -78,6 +75,6 @@ static inline int z_vrfy_pwm_pin_capture_cycles(const struct device *dev,
return err;
}
#include <syscalls/pwm_pin_capture_cycles_mrsh.c>
#include <syscalls/pwm_capture_cycles_mrsh.c>
#endif /* CONFIG_PWM_CAPTURE */