1 /** 2 * @file hi_pwm.h 3 * 4 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 * Description: PWM driver interfaces. 18 */ 19 20 /** @defgroup iot_pwm PWM 21 * @ingroup drivers 22 */ 23 #ifndef __HI_PWM_H__ 24 #define __HI_PWM_H__ 25 26 #include <hi_types.h> 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 /** 33 * @ingroup iot_pwm 34 * 35 * Enumerates the PWM clock sources.CNcomment:PWM时钟源枚举。CNend 36 */ 37 typedef enum { 38 PWM_CLK_160M, /**< 160M APB clock.CNcomment:160M 工作时钟 CNend */ 39 PWM_CLK_XTAL, /**< 24M/40M crystal clock.CNcomment:24M或40M 晶体时钟 CNend */ 40 PWM_CLK_MAX /**< Maximum value, which cannot be used.CNcomment:最大值,不可使用CNend */ 41 } hi_pwm_clk_source; 42 43 /** 44 * @ingroup iot_pwm 45 * 46 * Enumerates the PWM ports.CNcomment:PWM端口枚举。CNend 47 */ 48 typedef enum { 49 HI_PWM_PORT_PWM0 = 0, /**< PWM port0. Register base address: 0x40040000, multiplexed with GPIOX. 50 CNcomment:PWM0端口。寄存器基址:0x40040000,复用GPIOX。CNend */ 51 HI_PWM_PORT_PWM1 = 1, /**< PWM port1. Register base address: 0x40040100, multiplexed with GPIOX. 52 CNcomment:PWM1端口。寄存器基址:0x40040100,复用GPIOX。CNend */ 53 HI_PWM_PORT_PWM2 = 2, /**< PWM port2. Register base address: 0x40040200, multiplexed with GPIOX. 54 CNcomment:PWM2端口。寄存器基址:0x40040200,复用GPIOX。CNend */ 55 HI_PWM_PORT_PWM3 = 3, /**< PWM port3. Register base address: 0x40040300, multiplexed with GPIOX. 56 CNcomment:PWM3端口。寄存器基址:0x40040300,复用GPIOX。CNend */ 57 HI_PWM_PORT_PWM4 = 4, /**< PWM port4. Register base address: 0x40040400, multiplexed with GPIOX. 58 CNcomment:PWM4端口。寄存器基址:0x40040400,复用GPIOX。CNend */ 59 HI_PWM_PORT_PWM5 = 5, /**< PWM port5. Register base address: 0x40040500, multiplexed with GPIOX. 60 CNcomment:PWM5端口。寄存器基址:0x40040500,复用GPIOX。CNend */ 61 HI_PWM_PORT_MAX /**< Maximum value, which cannot be used.CNcomment:最大值,不可使用CNend */ 62 } hi_pwm_port; 63 64 /** 65 * @ingroup iot_pwm 66 * @brief Initializes the PWM module.CNcomment:PWM初始化。CNend 67 * 68 * @par 描述: 69 * Initializes the PWM module.CNcomment:PWM初始化。CNend 70 * @attention 71 * @li Before using the PWM function, ensure that the GPIO multiplexing relationship has been configured. 72 CNcomment:使用PWM功能前需要确认已配置GPIO复用关系。CNend 73 * @li For details, see Hi3861 V100 API Development Guide. 74 CNcomment:具体配置方法请参见<Hi3861V100 API开发指南>Demo介绍小节相关说明。CNend 75 * @li For details about the multiplexed GPIO, see the Hi3861 V100 Data Sheet. 76 CNcomment:具体复用的GPIO请参见<Hi3861 芯片 硬件用户指南>。CNend 77 * @li Before using the PWM function, initialize the PWM.CNcomment:使用PWM功能前需要先初始化。CNend 78 * 79 * @param port [IN] type #hi_pwm_port PWM port number.CNcomment:PWM端口号。CNend 80 * 81 * @retval #HI_ERR_SUCCESS Success. 82 * @retval #Other Failure. For details, see hi_errno.h. 83 * @par 依赖: 84 * @li hi_pwm.h: Describes the APIs of the PWM module.CNcomment:文件用于描述PWM对外接口。CNend 85 * @see hi_pwm_deinit | hi_pwm_start | hi_pwm_stop。 86 */ 87 hi_u32 hi_pwm_init(hi_pwm_port port); 88 89 /** 90 * @ingroup iot_pwm 91 * @brief Deinitializes the PWM module.CNcomment:PWM去初始化。CNend 92 * 93 * @par 描述: 94 * Deinitializes the PWM module.CNcomment:PWM去初始化。CNend 95 * 96 * @attention Deinitialize the PWM module when the function iss not used. 97 CNcomment:不使用PWM功能时去初始化。CNend 98 * 99 * @param port [IN] type #hi_pwm_port PWM port number.CNcomment:PWM端口号。CNend 100 * 101 * @retval #HI_ERR_SUCCESS Success. 102 * @retval #Other Failure. For details, see hi_errno.h. 103 * @par 依赖: 104 * @li hi_pwm.h: Describes the APIs of the PWM module.CNcomment:文件用于描述PWM对外接口。CNend 105 * @see hi_pwm_init。 106 */ 107 hi_u32 hi_pwm_deinit(hi_pwm_port port); 108 109 /** 110 * @ingroup iot_pwm 111 * @brief Sets the clock type of the PWM module.CNcomment:设置PWM模块时钟类型。CNend 112 * 113 * @par 描述: 114 * This function is used to set the clock type of the PWM module. 115 CNcomment:该函数用于设置PWM模块时钟类型。CNend 116 * 117 * @attention This setting takes effect for all PWM modules. The 160 MHz clock is used by default. 118 CNcomment:该设置对所有PWM模块均生效。默认为160M时钟。CNend 119 * 120 * @param clk_type [IN] type #hi_pwm_clk_source Clock type. CNcomment:时钟类型。CNend 121 * 122 * @retval #HI_ERR_SUCCESS Success. 123 * @retval #Other Failure. For details, see hi_errno.h. 124 * @par 依赖: 125 * @li hi_pwm.h: Describes the APIs of the PWM module.CNcomment:文件用于描述PWM对外接口。CNend 126 * @see None 127 */ 128 hi_u32 hi_pwm_set_clock(hi_pwm_clk_source clk_type); 129 130 /** 131 * @ingroup iot_pwm 132 * @brief Outputs the PWM signal according to the configured parameter. 133 * PWM signal duty cycle = duty/freq Frequency = Clock source frequency/freq. 134 CNcomment:按配置的参数输出PWM信号。PWM信号占空比=duty/freq。频率=时钟源频率/freq。CNend 135 * 136 * @par 描述: 137 * Starts the PWM signal output.CNcomment:启动PWM信号输出。CNend 138 * 139 * @attention This API cannot be called in an interrupt.CNcomment:不支持在中断中调用。CNend 140 * 141 * @param port [IN] type #hi_pwm_port PWM port number.CNcomment:PWM端口号。CNend 142 * @param duty [IN] type #hi_u16 PWM duty cycle count. Value range: [1, 65535]. The default value is 750. 143 CNcomment:PWM占空比计数值。取值范围为:[1, 65535]。默认值为750。CNend 144 * @param freq [IN] type #hi_u16 Frequency division multiple. Value range: [1, 65535]. The default value is 1500. 145 CNcomment:分频倍数。取值范围为:[1, 65535]。默认值为1500。CNend 146 * 147 * @retval #HI_ERR_SUCCESS Success. 148 * @retval #Other Failure. For details, see hi_errno.h. 149 * @par 依赖: 150 * @li hi_pwm.h: Describes the APIs of the PWM module.CNcomment:文件用于描述PWM对外接口。CNend 151 * @see hi_pwm_init | hi_pwm_stop。 152 */ 153 hi_u32 hi_pwm_start(hi_pwm_port port, hi_u16 duty, hi_u16 freq); 154 155 /** 156 * @ingroup iot_pwm 157 * @brief Stops the PWM signal output.CNcomment:停止PWM信号输出。CNend 158 * 159 * @par 描述: 160 * Stops the PWM signal output.CNcomment: 停止PWM信号输出。CNend 161 * 162 * @attention This API cannot be called in an interrupt.CNcomment:不支持在中断中调用。CNend 163 * 164 * @param port [IN] type #hi_pwm_port PWM port number.CNcomment:PWM端口号。CNend 165 * 166 * @retval #HI_ERR_SUCCESS Success. 167 * @retval #Other Failure. For details, see hi_errno.h. 168 * @par 依赖: 169 * @li hi_pwm.h: Describes the APIs of the PWM module.CNcomment:文件用于描述PWM对外接口。CNend 170 * @see hi_pwm_init | hi_pwm_start。 171 */ 172 hi_u32 hi_pwm_stop(hi_pwm_port port); 173 174 #ifdef __cplusplus 175 } 176 #endif 177 #endif 178