2021-12-21 08:47:42 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Commonwealth Scientific and Industrial Research
|
|
|
|
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is not a real PWM driver. It is used to instantiate struct
|
|
|
|
* devices for the "vnd,pwm" devicetree compatible used in test code.
|
|
|
|
*/
|
|
|
|
|
includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.
The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.
NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-25 15:58:46 +08:00
|
|
|
#include <zephyr/kernel.h>
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/drivers/pwm.h>
|
2021-12-21 08:47:42 +08:00
|
|
|
|
|
|
|
#define DT_DRV_COMPAT vnd_pwm
|
|
|
|
|
2022-04-01 17:06:43 +08:00
|
|
|
static int vnd_pwm_set_cycles(const struct device *dev, uint32_t channel,
|
|
|
|
uint32_t period_cycles, uint32_t pulse_cycles,
|
|
|
|
pwm_flags_t flags)
|
2021-12-21 08:47:42 +08:00
|
|
|
{
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PWM_CAPTURE
|
2022-04-01 17:06:43 +08:00
|
|
|
static int vnd_pwm_configure_capture(const struct device *dev, uint32_t channel,
|
|
|
|
pwm_flags_t flags,
|
|
|
|
pwm_capture_callback_handler_t cb,
|
|
|
|
void *user_data)
|
2021-12-21 08:47:42 +08:00
|
|
|
{
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2022-04-01 17:06:43 +08:00
|
|
|
static int vnd_pwm_enable_capture(const struct device *dev, uint32_t channel)
|
2021-12-21 08:47:42 +08:00
|
|
|
{
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2022-04-01 17:06:43 +08:00
|
|
|
static int vnd_pwm_disable_capture(const struct device *dev, uint32_t channel)
|
2021-12-21 08:47:42 +08:00
|
|
|
{
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_PWM_CAPTURE */
|
|
|
|
|
|
|
|
static int vnd_pwm_get_cycles_per_sec(const struct device *dev,
|
2022-04-04 22:35:22 +08:00
|
|
|
uint32_t channel, uint64_t *cycles)
|
2021-12-21 08:47:42 +08:00
|
|
|
{
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct pwm_driver_api vnd_pwm_api = {
|
2022-04-01 17:06:43 +08:00
|
|
|
.set_cycles = vnd_pwm_set_cycles,
|
2021-12-21 08:47:42 +08:00
|
|
|
#ifdef CONFIG_PWM_CAPTURE
|
2022-04-01 17:06:43 +08:00
|
|
|
.configure_capture = vnd_pwm_configure_capture,
|
|
|
|
.enable_capture = vnd_pwm_enable_capture,
|
|
|
|
.disable_capture = vnd_pwm_disable_capture,
|
2021-12-21 08:47:42 +08:00
|
|
|
#endif /* CONFIG_PWM_CAPTURE */
|
|
|
|
.get_cycles_per_sec = vnd_pwm_get_cycles_per_sec,
|
|
|
|
};
|
|
|
|
|
2023-04-18 18:25:15 +08:00
|
|
|
#define VND_PWM_INIT(n) \
|
|
|
|
DEVICE_DT_INST_DEFINE(n, NULL, NULL, NULL, NULL, POST_KERNEL, \
|
|
|
|
CONFIG_PWM_INIT_PRIORITY, &vnd_pwm_api);
|
2021-12-21 08:47:42 +08:00
|
|
|
|
|
|
|
DT_INST_FOREACH_STATUS_OKAY(VND_PWM_INIT)
|