cleanup: include/: move pwm.h to drivers/pwm.h

move pwm.h to drivers/pwm.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2019-06-25 15:53:58 -04:00
parent a8167ab17d
commit 5843884887
23 changed files with 206 additions and 191 deletions

View file

@ -14,7 +14,7 @@
#include <drivers/pinmux.h>
#include <drivers/i2c.h>
#include <drivers/gpio.h>
#include <pwm.h>
#include <drivers/pwm.h>
#include <pinmux/pinmux.h>

View file

@ -20,7 +20,7 @@
#include <errno.h>
#include <kernel.h>
#include <pwm.h>
#include <drivers/pwm.h>
/* Register for component version */
#define REG_COMP_VER 0xAC

View file

@ -5,7 +5,7 @@
*/
#include <syscall_handler.h>
#include <pwm.h>
#include <drivers/pwm.h>
Z_SYSCALL_HANDLER(pwm_pin_set_cycles, dev, pwm, period, pulse)
{

View file

@ -5,7 +5,7 @@
*/
#include <errno.h>
#include <pwm.h>
#include <drivers/pwm.h>
#include <soc.h>
#include <device_imx.h>

View file

@ -13,7 +13,7 @@
#include <soc.h>
#include <errno.h>
#include <pwm.h>
#include <drivers/pwm.h>
#include <kernel.h>
#include <drivers/gpio.h>
#include <string.h>

View file

@ -5,7 +5,7 @@
*/
#include <errno.h>
#include <pwm.h>
#include <drivers/pwm.h>
#include <soc.h>
#include <fsl_ftm.h>
#include <fsl_clock.h>

View file

@ -6,7 +6,7 @@
#include <soc.h>
#include "pwm.h"
#include <drivers/pwm.h>
#include <nrf_peripherals.h>
#define LOG_LEVEL CONFIG_PWM_LOG_LEVEL

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <nrfx_pwm.h>
#include <pwm.h>
#include <drivers/pwm.h>
#include <hal/nrf_gpio.h>
#include <stdbool.h>

View file

@ -13,7 +13,7 @@
#include <kernel.h>
#include <drivers/i2c.h>
#include <pwm.h>
#include <drivers/pwm.h>
#include "pwm_pca9685.h"

View file

@ -6,7 +6,7 @@
#include <errno.h>
#include <pwm.h>
#include <drivers/pwm.h>
#include <device.h>
#include <kernel.h>
#include <init.h>

View file

@ -6,7 +6,7 @@
#include <device.h>
#include <errno.h>
#include <pwm.h>
#include <drivers/pwm.h>
#include <soc.h>
#define LOG_LEVEL CONFIG_PWM_LOG_LEVEL

View file

@ -10,7 +10,7 @@ LOG_MODULE_REGISTER(pwm_sifive, CONFIG_PWM_LOG_LEVEL);
#include <sys/sys_io.h>
#include <device.h>
#include <pwm.h>
#include <drivers/pwm.h>
/* Macros */

View file

@ -7,7 +7,7 @@
#include <errno.h>
#include <soc.h>
#include <pwm.h>
#include <drivers/pwm.h>
#include <device.h>
#include <kernel.h>
#include <init.h>

181
include/drivers/pwm.h Normal file
View file

@ -0,0 +1,181 @@
/*
* Copyright (c) 2016 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief Public PWM Driver APIs
*/
#ifndef ZEPHYR_INCLUDE_DRIVERS_PWM_H_
#define ZEPHYR_INCLUDE_DRIVERS_PWM_H_
/**
* @brief PWM Interface
* @defgroup pwm_interface PWM Interface
* @ingroup io_interfaces
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
#define PWM_ACCESS_BY_PIN 0
#define PWM_ACCESS_ALL 1
#include <errno.h>
#include <zephyr/types.h>
#include <stddef.h>
#include <device.h>
/**
* @typedef pwm_pin_set_t
* @brief Callback API upon setting the pin
* See @a pwm_pin_set_cycles() for argument description
*/
typedef int (*pwm_pin_set_t)(struct device *dev, u32_t pwm,
u32_t period_cycles, u32_t pulse_cycles);
/**
* @typedef pwm_get_cycles_per_sec_t
* @brief Callback API upon getting cycles per second
* See @a pwm_get_cycles_per_sec() for argument description
*/
typedef int (*pwm_get_cycles_per_sec_t)(struct device *dev, u32_t pwm,
u64_t *cycles);
/** @brief PWM driver API definition. */
struct pwm_driver_api {
pwm_pin_set_t pin_set;
pwm_get_cycles_per_sec_t get_cycles_per_sec;
};
/**
* @brief Set the period and pulse width for a single PWM output.
*
* @param dev Pointer to the device structure for the driver instance.
* @param pwm PWM pin.
* @param period Period (in clock cycle) set to the PWM. HW specific.
* @param pulse Pulse width (in clock cycle) set to the PWM. HW specific.
*
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
__syscall int pwm_pin_set_cycles(struct device *dev, u32_t pwm,
u32_t period, u32_t pulse);
static inline int z_impl_pwm_pin_set_cycles(struct device *dev, u32_t pwm,
u32_t period, u32_t pulse)
{
struct pwm_driver_api *api;
api = (struct pwm_driver_api *)dev->driver_api;
return api->pin_set(dev, pwm, period, pulse);
}
/**
* @brief Get the clock rate (cycles per second) for a single PWM output.
*
* @param dev Pointer to the device structure for the driver instance.
* @param pwm PWM pin.
* @param cycles Pointer to the memory to store clock rate (cycles per sec).
* HW specific.
*
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
__syscall int pwm_get_cycles_per_sec(struct device *dev, u32_t pwm,
u64_t *cycles);
static inline int z_impl_pwm_get_cycles_per_sec(struct device *dev, u32_t pwm,
u64_t *cycles)
{
struct pwm_driver_api *api;
api = (struct pwm_driver_api *)dev->driver_api;
return api->get_cycles_per_sec(dev, pwm, cycles);
}
/**
* @brief Set the period and pulse width for a single PWM output.
*
* @param dev Pointer to the device structure for the driver instance.
* @param pwm PWM pin.
* @param period Period (in microseconds) set to the PWM.
* @param pulse Pulse width (in microseconds) set to the PWM.
*
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
static inline int pwm_pin_set_usec(struct device *dev, u32_t pwm,
u32_t period, u32_t pulse)
{
u64_t period_cycles, pulse_cycles, cycles_per_sec;
if (pwm_get_cycles_per_sec(dev, pwm, &cycles_per_sec) != 0) {
return -EIO;
}
period_cycles = (period * cycles_per_sec) / USEC_PER_SEC;
if (period_cycles >= ((u64_t)1 << 32)) {
return -ENOTSUP;
}
pulse_cycles = (pulse * cycles_per_sec) / USEC_PER_SEC;
if (pulse_cycles >= ((u64_t)1 << 32)) {
return -ENOTSUP;
}
return pwm_pin_set_cycles(dev, pwm, (u32_t)period_cycles,
(u32_t)pulse_cycles);
}
/**
* @brief Set the period and pulse width for a single PWM output.
*
* @param dev Pointer to the device structure for the driver instance.
* @param pwm PWM pin.
* @param period Period (in nanoseconds) set to the PWM.
* @param pulse Pulse width (in nanoseconds) set to the PWM.
*
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
static inline int pwm_pin_set_nsec(struct device *dev, u32_t pwm,
u32_t period, u32_t pulse)
{
u64_t period_cycles, pulse_cycles, cycles_per_sec;
if (pwm_get_cycles_per_sec(dev, pwm, &cycles_per_sec) != 0) {
return -EIO;
}
period_cycles = (period * cycles_per_sec) / NSEC_PER_SEC;
if (period_cycles >= ((u64_t)1 << 32)) {
return -ENOTSUP;
}
pulse_cycles = (pulse * cycles_per_sec) / NSEC_PER_SEC;
if (pulse_cycles >= ((u64_t)1 << 32)) {
return -ENOTSUP;
}
return pwm_pin_set_cycles(dev, pwm, (u32_t)period_cycles,
(u32_t)pulse_cycles);
}
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#include <syscalls/pwm.h>
#endif /* ZEPHYR_INCLUDE_DRIVERS_PWM_H_ */

View file

@ -1,181 +1,15 @@
/*
* Copyright (c) 2016 Intel Corporation.
* Copyright (c) 2019 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief Public PWM Driver APIs
*/
#ifndef ZEPHYR_INCLUDE_PWM_H_
#define ZEPHYR_INCLUDE_PWM_H_
/**
* @brief PWM Interface
* @defgroup pwm_interface PWM Interface
* @ingroup io_interfaces
* @{
*/
#ifdef __cplusplus
extern "C" {
#ifndef CONFIG_COMPAT_INCLUDES
#warning "This header file has moved, include <drivers/pwm.h> instead."
#endif
#define PWM_ACCESS_BY_PIN 0
#define PWM_ACCESS_ALL 1
#include <errno.h>
#include <zephyr/types.h>
#include <stddef.h>
#include <device.h>
/**
* @typedef pwm_pin_set_t
* @brief Callback API upon setting the pin
* See @a pwm_pin_set_cycles() for argument description
*/
typedef int (*pwm_pin_set_t)(struct device *dev, u32_t pwm,
u32_t period_cycles, u32_t pulse_cycles);
/**
* @typedef pwm_get_cycles_per_sec_t
* @brief Callback API upon getting cycles per second
* See @a pwm_get_cycles_per_sec() for argument description
*/
typedef int (*pwm_get_cycles_per_sec_t)(struct device *dev, u32_t pwm,
u64_t *cycles);
/** @brief PWM driver API definition. */
struct pwm_driver_api {
pwm_pin_set_t pin_set;
pwm_get_cycles_per_sec_t get_cycles_per_sec;
};
/**
* @brief Set the period and pulse width for a single PWM output.
*
* @param dev Pointer to the device structure for the driver instance.
* @param pwm PWM pin.
* @param period Period (in clock cycle) set to the PWM. HW specific.
* @param pulse Pulse width (in clock cycle) set to the PWM. HW specific.
*
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
__syscall int pwm_pin_set_cycles(struct device *dev, u32_t pwm,
u32_t period, u32_t pulse);
static inline int z_impl_pwm_pin_set_cycles(struct device *dev, u32_t pwm,
u32_t period, u32_t pulse)
{
struct pwm_driver_api *api;
api = (struct pwm_driver_api *)dev->driver_api;
return api->pin_set(dev, pwm, period, pulse);
}
/**
* @brief Get the clock rate (cycles per second) for a single PWM output.
*
* @param dev Pointer to the device structure for the driver instance.
* @param pwm PWM pin.
* @param cycles Pointer to the memory to store clock rate (cycles per sec).
* HW specific.
*
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
__syscall int pwm_get_cycles_per_sec(struct device *dev, u32_t pwm,
u64_t *cycles);
static inline int z_impl_pwm_get_cycles_per_sec(struct device *dev, u32_t pwm,
u64_t *cycles)
{
struct pwm_driver_api *api;
api = (struct pwm_driver_api *)dev->driver_api;
return api->get_cycles_per_sec(dev, pwm, cycles);
}
/**
* @brief Set the period and pulse width for a single PWM output.
*
* @param dev Pointer to the device structure for the driver instance.
* @param pwm PWM pin.
* @param period Period (in microseconds) set to the PWM.
* @param pulse Pulse width (in microseconds) set to the PWM.
*
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
static inline int pwm_pin_set_usec(struct device *dev, u32_t pwm,
u32_t period, u32_t pulse)
{
u64_t period_cycles, pulse_cycles, cycles_per_sec;
if (pwm_get_cycles_per_sec(dev, pwm, &cycles_per_sec) != 0) {
return -EIO;
}
period_cycles = (period * cycles_per_sec) / USEC_PER_SEC;
if (period_cycles >= ((u64_t)1 << 32)) {
return -ENOTSUP;
}
pulse_cycles = (pulse * cycles_per_sec) / USEC_PER_SEC;
if (pulse_cycles >= ((u64_t)1 << 32)) {
return -ENOTSUP;
}
return pwm_pin_set_cycles(dev, pwm, (u32_t)period_cycles,
(u32_t)pulse_cycles);
}
/**
* @brief Set the period and pulse width for a single PWM output.
*
* @param dev Pointer to the device structure for the driver instance.
* @param pwm PWM pin.
* @param period Period (in nanoseconds) set to the PWM.
* @param pulse Pulse width (in nanoseconds) set to the PWM.
*
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
static inline int pwm_pin_set_nsec(struct device *dev, u32_t pwm,
u32_t period, u32_t pulse)
{
u64_t period_cycles, pulse_cycles, cycles_per_sec;
if (pwm_get_cycles_per_sec(dev, pwm, &cycles_per_sec) != 0) {
return -EIO;
}
period_cycles = (period * cycles_per_sec) / NSEC_PER_SEC;
if (period_cycles >= ((u64_t)1 << 32)) {
return -ENOTSUP;
}
pulse_cycles = (pulse * cycles_per_sec) / NSEC_PER_SEC;
if (pulse_cycles >= ((u64_t)1 << 32)) {
return -ENOTSUP;
}
return pwm_pin_set_cycles(dev, pwm, (u32_t)period_cycles,
(u32_t)pulse_cycles);
}
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#include <syscalls/pwm.h>
#include <drivers/pwm.h>
#endif /* ZEPHYR_INCLUDE_PWM_H_ */

View file

@ -13,7 +13,7 @@
#include <zephyr.h>
#include <misc/printk.h>
#include <device.h>
#include <pwm.h>
#include <drivers/pwm.h>
#if defined(CONFIG_SOC_STM32F401XE) || defined(CONFIG_SOC_STM32F412ZG) || \
defined(CONFIG_SOC_STM32F413XX) || defined(CONFIG_SOC_STM32L476XX) || \

View file

@ -13,7 +13,7 @@
#include <zephyr.h>
#include <misc/printk.h>
#include <device.h>
#include <pwm.h>
#include <drivers/pwm.h>
#if defined(CONFIG_SOC_STM32F401XE) || defined(CONFIG_SOC_STM32L476XX)
#define PWM_DRIVER DT_PWM_STM32_2_DEV_NAME

View file

@ -13,7 +13,7 @@
#include <zephyr.h>
#include <misc/printk.h>
#include <device.h>
#include <pwm.h>
#include <drivers/pwm.h>
#if defined(RED_PWM_LED_PWM_CONTROLLER) && \
defined(RED_PWM_LED_PWM_CHANNEL) && \

View file

@ -13,7 +13,7 @@
#include <zephyr.h>
#include <misc/printk.h>
#include <device.h>
#include <pwm.h>
#include <drivers/pwm.h>
#if defined(CONFIG_SOC_QUARK_SE_C1000)
#define PWM_DEV CONFIG_PWM_QMSI_DEV_NAME

View file

@ -12,7 +12,7 @@
#include <misc/printk.h>
#include <ctype.h>
#include <drivers/gpio.h>
#include <pwm.h>
#include <drivers/pwm.h>
#include <display/mb_display.h>

View file

@ -10,7 +10,7 @@
#include <drivers/gpio.h>
#include <device.h>
#include <string.h>
#include <pwm.h>
#include <drivers/pwm.h>
#include <misc/stack.h>
#include <display/mb_display.h>

View file

@ -8,7 +8,7 @@
#include <misc/printk.h>
#include <board.h>
#include <drivers/gpio.h>
#include <pwm.h>
#include <drivers/pwm.h>
#include <device.h>
#include <display/mb_display.h>

View file

@ -28,7 +28,7 @@
#include <device.h>
#include <inttypes.h>
#include <pwm.h>
#include <drivers/pwm.h>
#include <zephyr.h>
#include <ztest.h>