4G_module/include/cmiot/cm_pwm.h

126 lines
3.6 KiB
C
Raw Normal View History

2024-09-02 17:54:29 +08:00
/**
* @file cm_pwm.h
* @brief PWM接口
* @copyright Copyright © 2021 China Mobile IOT. All rights reserved.
* @author By ZHANGXW
* @date 2021/03/09
*
* @defgroup pwm pwm
* @ingroup PI
* @{
*/
#ifndef __CM_PWM_H__
#define __CM_PWM_H__
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/** 设备ID详情参照资源综述 */
typedef enum{
CM_PWM_DEV_0, /*!< 设备0*/
CM_PWM_DEV_1, /*!< 设备1*/
CM_PWM_DEV_2, /*!< 设备2*/
CM_PWM_DEV_3, /*!< 设备3*/
CM_PWM_DEV_NUM
} cm_pwm_dev_e;
/** 时钟源枚举 */
typedef enum{
CM_PWM_CLK_32K = 32000, /*!< 32k时钟源支持低功耗下使用*/
CM_PWM_CLK_12800K = 12800000, /*!< 12.8M时钟源,不支持低功耗下使用*/
CM_PWM_CLK_END
} cm_pwm_clk_e;
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/**
* @brief PWM
*
* @param [in] dev PWM设备ID
* @param [in] clk
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details clk可以选择32k的时钟12.8M的时钟32k的时钟open函数之前设置
*/
int32_t cm_pwm_set_clk(cm_pwm_dev_e dev, cm_pwm_clk_e clk);
/**
* @brief PWM设备
*
* @param [in] dev PWM设备ID
* @param [in] period (ns),5120000
* @param [in] period_h (ns)
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details PWM由于分频和算法设计存在一定的误差period和period_h需根据下面备注进行设置\n
* How to get the PV(The value of after scaled clock cycles per cycle/T): \n
* InputClockT=13M;PWM_T=period;
* InputClockT * ('PV(The value of before scaled clock cycles per cycle)) = PWM_T \n
* 'PV = PWM_T / InputClockT \n
* = PWM_T * InputClockF \n
* PV = 'PV /(prescale + 1) -1 \n
* How to get the prescale: \n
* Because the internal clock period counter is 10-bit, to avoid overun. We can use the prescale.\n
* prescale real value = ('PV - 1(if > 1024, then need prescale)) / 1024 \n
*
* How to get the Duty cycle: \n
* Duty cycle = (PV(the cycles per T) + 1) * ratio(Duty time/PWM_T)
*/
int32_t cm_pwm_open_ns(cm_pwm_dev_e dev, uint32_t period, uint32_t period_h);
/**
* @brief PWM设备
*
* @param [in] dev PWM设备ID
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details More details
*/
int32_t cm_pwm_close(cm_pwm_dev_e dev);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __CM_PWM_H__ */
/** @}*/