/******************************************************************************* * * * File: hal_pwm.h * Description: pwm HAL层头文件 * Version: V0.1 * Date: 2021-03-17 * Author: wuc *******************************************************************************/ #ifndef __HAL_PWM_H__ #define __HAL_PWM_H__ /******************************************************************************* * 1.Included files *******************************************************************************/ #include "tau_device_datatype.h" #include "tau_common.h" #include "hal_gpio.h" /******************************************************************************* * 2.Global constant and macro definitions using #define *******************************************************************************/ /******************************************************************************* * 3.Global structures, unions and enumerations using typedef *******************************************************************************/ /*! @brief PWM触发功能的定义 */ typedef enum _pwm_out_ctrl_e { PWMO_CTRL_KEEP = 0, PWMO_CTRL_LOW = 1, PWMO_CTRL_HIGH = 2, PWMO_CTRL_TOGGLE = 3, PWMO_CTRL_MAX } pwm_out_ctrl_e; /******************************************************************************* * 4.Global variable extern declarations *******************************************************************************/ /******************************************************************************* * 5.Global function prototypes *******************************************************************************/ /** * @brief PWMO初始化 * @param 无 * @retval 无 */ void hal_pwm_out_init(void); /** * @brief PWMO反初始化 * @param 无 * @retval 无 */ void hal_pwm_out_deinit(void); /** * @brief PWMO输出脉冲暂停、恢复 * @param state:开关控制 * @retval 无 */ void hal_pwm_out_pause(function_state_e state); /** * @brief 配置PWMO脉冲并开始输出 * @param ctl0:到达阈值thr0时的操作,参考枚举类型pwm_out_ctrl_e * @param ctl1:到达阈值thr1时的操作,参考枚举类型pwm_out_ctrl_e * @param thr0:阈值0,单位us * @param thr1:阈值1,单位us * @param period:一个周期的时间,单位us * @retval 无 */ void hal_pwm_out_config_all(pwm_out_ctrl_e ctl0, pwm_out_ctrl_e ctl1, uint32_t thr0, uint32_t thr1, uint32_t period); /** * @brief 在同步所有模式下配置PWMO脉冲所有参数 * @param ctl0:到达阈值thr0时的操作,参考枚举类型pwm_out_ctrl_e * @param ctl1:到达阈值thr1时的操作,参考枚举类型pwm_out_ctrl_e * @param thr0:阈值0,单位us * @param thr1:阈值1,单位us * @param period:一个周期的时间,单位us * @retval 无 */ void hal_pwm_out_sync_all(pwm_out_ctrl_e ctl0, pwm_out_ctrl_e ctl1, uint32_t thr0, uint32_t thr1, uint32_t period); /** * @brief 调制pwm输出以控制背光 * @param polarity: 极性,false:先高后低,true:先低后高 * @param duty_ratio: 占空比(0-total_ratio) * @param total_ratio: 可细分总量 * @param frequency: 频率,单位HZ * @retval 无 */ void hal_pwm_out_config_duty_ratio(bool polarity, uint16_t duty_ratio, uint16_t total_ratio, uint32_t frequency); /** * @brief 在同步周期模式下配置PWMO脉冲的周期 * @param period:一个周期的时间,单位us * @retval 无 */ void hal_pwm_out_sync_period(uint32_t period); /** * @brief 在同步控制模式下配置PWMO脉冲的控制 * @param ctl0:到达阈值thr0时的操作,参考枚举类型pwm_out_ctrl_e * @param ctl1:到达阈值thr1时的操作,参考枚举类型pwm_out_ctrl_e * @retval 无 */ void hal_pwm_out_sync_ctl(pwm_out_ctrl_e ctl0, pwm_out_ctrl_e ctl1); /** * @brief 在同步阈值模式下配置PWMO脉冲的阈值 * @param thr0:阈值0,单位us * @param thr1:阈值1,单位us * @retval 无 */ void hal_pwm_out_sync_thr(uint32_t thr0, uint32_t thr1); /** * @brief 在同步暂停模式下暂停或恢复PWMO脉冲 * @param pause_state:暂停或恢复 * @retval 无 */ void hal_pwm_out_sync_pause(function_state_e pause_state); /** * @brief PWMI初始化 * @param 无 * @retval 无 */ void hal_pwm_in_init(void); /** * @brief PWMI反初始化 * @param 无 * @retval 无 */ void hal_pwm_in_deinit(void); /** * @brief 注册PWMI中断回调函数,回传PWMI中断类型指针,参考pwm_int_type_e * @param cb_func:回调函数地址 * @retval 无 */ void hal_pwm_in_register_callback(fcb_type cb_func); /** * @brief 配置PWMI所有中断的开关 * @param high_overflow_en:high overflow中断使能开关 * @param low_overflow_en:low overflow中断使能开关 * @param total_overflow_en:total overflow中断使能开关 * @param high_done_en:high done中断使能开关 * @param low_done_en:low done中断使能开关 * @param total_done_en:total done中断使能开关 * @retval 无 */ void hal_pwm_in_config_int(function_state_e high_overflow_en, function_state_e low_overflow_en, function_state_e total_overflow_en, function_state_e high_done_en, function_state_e low_done_en, function_state_e total_done_en); /** * @brief 配置PWMI单个中断的开关 * @param pwm_int:中断类型,参考枚举类型pwm_int_type_e * @param enable:控制开关 * @retval 无 */ void hal_pwm_in_set_int(pwm_int_type_e pwm_int, function_state_e enable); /** * @brief 关闭PWMI所有中断 * @param 无 * @retval 无 */ void hal_pwm_in_clear_int(void); /** * @brief 开关PWMI中断 * @param state:开关控制 * @retval 无 */ void hal_pwm_in_ctrl_int(function_state_e state); /** * @brief 获取PWMI脉冲周期时长 * @param 无 * @retval 周期时长,单位us */ uint32_t hal_pwm_in_get_total_period(void); /** * @brief 获取PWMI脉冲高电平时长 * @param 无 * @retval 高电平时长,单位us */ uint32_t hal_pwm_in_get_high_period(void); /** * @brief 获取PWMI脉冲低电平时长 * @param 无 * @retval 低电平时长,单位us */ uint32_t hal_pwm_in_get_low_period(void); /** * @brief 获取PWMI上升沿累积个数 * @param 无 * @retval 从模块使能到当前时间的上升沿个数,超过32位宽后清零重新计数 */ uint32_t hal_pwm_in_get_current_count(void); #if defined(ISP_568) || defined(ISP_368) /** * @brief 选择PWMO输出的IO口 * @param pad: PWMO输出的IO口,默认为IO_PAD_AP_SWIRE,可选通过IO_PAD_TD_SPIM_MISO、IO_PAD_TD_LEDPWM输出 * @retval 无 */ void hal_pwm_out_sel_io(io_pad_e pad); #endif #endif /* __HAL_PWM_H__ */