11bd4fe43Sopenharmony_ci/**
21bd4fe43Sopenharmony_ci * @file hi_pwm.h
31bd4fe43Sopenharmony_ci *
41bd4fe43Sopenharmony_ci * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
51bd4fe43Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
61bd4fe43Sopenharmony_ci * you may not use this file except in compliance with the License.
71bd4fe43Sopenharmony_ci * You may obtain a copy of the License at
81bd4fe43Sopenharmony_ci *
91bd4fe43Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
101bd4fe43Sopenharmony_ci *
111bd4fe43Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
121bd4fe43Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
131bd4fe43Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141bd4fe43Sopenharmony_ci * See the License for the specific language governing permissions and
151bd4fe43Sopenharmony_ci * limitations under the License.
161bd4fe43Sopenharmony_ci *
171bd4fe43Sopenharmony_ci * Description: PWM driver interfaces.
181bd4fe43Sopenharmony_ci */
191bd4fe43Sopenharmony_ci
201bd4fe43Sopenharmony_ci/** @defgroup iot_pwm PWM
211bd4fe43Sopenharmony_ci *  @ingroup drivers
221bd4fe43Sopenharmony_ci */
231bd4fe43Sopenharmony_ci#ifndef __HI_PWM_H__
241bd4fe43Sopenharmony_ci#define __HI_PWM_H__
251bd4fe43Sopenharmony_ci
261bd4fe43Sopenharmony_ci#include <hi_types.h>
271bd4fe43Sopenharmony_ci
281bd4fe43Sopenharmony_ci#ifdef __cplusplus
291bd4fe43Sopenharmony_ciextern "C" {
301bd4fe43Sopenharmony_ci#endif
311bd4fe43Sopenharmony_ci
321bd4fe43Sopenharmony_ci/**
331bd4fe43Sopenharmony_ci * @ingroup iot_pwm
341bd4fe43Sopenharmony_ci *
351bd4fe43Sopenharmony_ci * Enumerates the PWM clock sources.CNcomment:PWM时钟源枚举。CNend
361bd4fe43Sopenharmony_ci */
371bd4fe43Sopenharmony_citypedef enum {
381bd4fe43Sopenharmony_ci    PWM_CLK_160M, /**< 160M APB clock.CNcomment:160M 工作时钟 CNend */
391bd4fe43Sopenharmony_ci    PWM_CLK_XTAL, /**< 24M/40M crystal clock.CNcomment:24M或40M 晶体时钟 CNend */
401bd4fe43Sopenharmony_ci    PWM_CLK_MAX   /**< Maximum value, which cannot be used.CNcomment:最大值,不可使用CNend */
411bd4fe43Sopenharmony_ci} hi_pwm_clk_source;
421bd4fe43Sopenharmony_ci
431bd4fe43Sopenharmony_ci/**
441bd4fe43Sopenharmony_ci * @ingroup iot_pwm
451bd4fe43Sopenharmony_ci *
461bd4fe43Sopenharmony_ci * Enumerates the PWM ports.CNcomment:PWM端口枚举。CNend
471bd4fe43Sopenharmony_ci */
481bd4fe43Sopenharmony_citypedef enum {
491bd4fe43Sopenharmony_ci    HI_PWM_PORT_PWM0 = 0, /**< PWM port0. Register base address: 0x40040000, multiplexed with GPIOX.
501bd4fe43Sopenharmony_ci                             CNcomment:PWM0端口。寄存器基址:0x40040000,复用GPIOX。CNend */
511bd4fe43Sopenharmony_ci    HI_PWM_PORT_PWM1 = 1, /**< PWM port1. Register base address: 0x40040100, multiplexed with GPIOX.
521bd4fe43Sopenharmony_ci                             CNcomment:PWM1端口。寄存器基址:0x40040100,复用GPIOX。CNend */
531bd4fe43Sopenharmony_ci    HI_PWM_PORT_PWM2 = 2, /**< PWM port2. Register base address: 0x40040200, multiplexed with GPIOX.
541bd4fe43Sopenharmony_ci                             CNcomment:PWM2端口。寄存器基址:0x40040200,复用GPIOX。CNend */
551bd4fe43Sopenharmony_ci    HI_PWM_PORT_PWM3 = 3, /**< PWM port3. Register base address: 0x40040300, multiplexed with GPIOX.
561bd4fe43Sopenharmony_ci                             CNcomment:PWM3端口。寄存器基址:0x40040300,复用GPIOX。CNend */
571bd4fe43Sopenharmony_ci    HI_PWM_PORT_PWM4 = 4, /**< PWM port4. Register base address: 0x40040400, multiplexed with GPIOX.
581bd4fe43Sopenharmony_ci                             CNcomment:PWM4端口。寄存器基址:0x40040400,复用GPIOX。CNend */
591bd4fe43Sopenharmony_ci    HI_PWM_PORT_PWM5 = 5, /**< PWM port5. Register base address: 0x40040500, multiplexed with GPIOX.
601bd4fe43Sopenharmony_ci                             CNcomment:PWM5端口。寄存器基址:0x40040500,复用GPIOX。CNend */
611bd4fe43Sopenharmony_ci    HI_PWM_PORT_MAX   /**< Maximum value, which cannot be used.CNcomment:最大值,不可使用CNend */
621bd4fe43Sopenharmony_ci} hi_pwm_port;
631bd4fe43Sopenharmony_ci
641bd4fe43Sopenharmony_ci/**
651bd4fe43Sopenharmony_ci* @ingroup iot_pwm
661bd4fe43Sopenharmony_ci* @brief  Initializes the PWM module.CNcomment:PWM初始化。CNend
671bd4fe43Sopenharmony_ci*
681bd4fe43Sopenharmony_ci* @par   描述:
691bd4fe43Sopenharmony_ci*            Initializes the PWM module.CNcomment:PWM初始化。CNend
701bd4fe43Sopenharmony_ci* @attention
711bd4fe43Sopenharmony_ci*        @li Before using the PWM function, ensure that the GPIO multiplexing relationship has been configured.
721bd4fe43Sopenharmony_ciCNcomment:使用PWM功能前需要确认已配置GPIO复用关系。CNend
731bd4fe43Sopenharmony_ci*        @li For details, see Hi3861 V100 API Development Guide.
741bd4fe43Sopenharmony_ciCNcomment:具体配置方法请参见<Hi3861V100 API开发指南>Demo介绍小节相关说明。CNend
751bd4fe43Sopenharmony_ci*        @li For details about the multiplexed GPIO, see the Hi3861 V100 Data Sheet.
761bd4fe43Sopenharmony_ciCNcomment:具体复用的GPIO请参见<Hi3861 芯片 硬件用户指南>。CNend
771bd4fe43Sopenharmony_ci*        @li Before using the PWM function, initialize the PWM.CNcomment:使用PWM功能前需要先初始化。CNend
781bd4fe43Sopenharmony_ci*
791bd4fe43Sopenharmony_ci* @param  port [IN]  type #hi_pwm_port PWM port number.CNcomment:PWM端口号。CNend
801bd4fe43Sopenharmony_ci*
811bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS Success.
821bd4fe43Sopenharmony_ci* @retval #Other          Failure. For details, see hi_errno.h.
831bd4fe43Sopenharmony_ci* @par 依赖:
841bd4fe43Sopenharmony_ci*            @li hi_pwm.h: Describes the APIs of the PWM module.CNcomment:文件用于描述PWM对外接口。CNend
851bd4fe43Sopenharmony_ci* @see hi_pwm_deinit | hi_pwm_start | hi_pwm_stop。
861bd4fe43Sopenharmony_ci*/
871bd4fe43Sopenharmony_cihi_u32 hi_pwm_init(hi_pwm_port port);
881bd4fe43Sopenharmony_ci
891bd4fe43Sopenharmony_ci/**
901bd4fe43Sopenharmony_ci* @ingroup iot_pwm
911bd4fe43Sopenharmony_ci* @brief  Deinitializes the PWM module.CNcomment:PWM去初始化。CNend
921bd4fe43Sopenharmony_ci*
931bd4fe43Sopenharmony_ci* @par   描述:
941bd4fe43Sopenharmony_ci*            Deinitializes the PWM module.CNcomment:PWM去初始化。CNend
951bd4fe43Sopenharmony_ci*
961bd4fe43Sopenharmony_ci* @attention Deinitialize the PWM module when the function iss not used.
971bd4fe43Sopenharmony_ciCNcomment:不使用PWM功能时去初始化。CNend
981bd4fe43Sopenharmony_ci*
991bd4fe43Sopenharmony_ci* @param  port [IN]  type #hi_pwm_port PWM port number.CNcomment:PWM端口号。CNend
1001bd4fe43Sopenharmony_ci*
1011bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS Success.
1021bd4fe43Sopenharmony_ci* @retval #Other          Failure. For details, see hi_errno.h.
1031bd4fe43Sopenharmony_ci* @par 依赖:
1041bd4fe43Sopenharmony_ci*            @li hi_pwm.h: Describes the APIs of the PWM module.CNcomment:文件用于描述PWM对外接口。CNend
1051bd4fe43Sopenharmony_ci* @see hi_pwm_init。
1061bd4fe43Sopenharmony_ci*/
1071bd4fe43Sopenharmony_cihi_u32 hi_pwm_deinit(hi_pwm_port port);
1081bd4fe43Sopenharmony_ci
1091bd4fe43Sopenharmony_ci/**
1101bd4fe43Sopenharmony_ci* @ingroup iot_pwm
1111bd4fe43Sopenharmony_ci* @brief  Sets the clock type of the PWM module.CNcomment:设置PWM模块时钟类型。CNend
1121bd4fe43Sopenharmony_ci*
1131bd4fe43Sopenharmony_ci* @par   描述:
1141bd4fe43Sopenharmony_ci*            This function is used to set the clock type of the PWM module.
1151bd4fe43Sopenharmony_ciCNcomment:该函数用于设置PWM模块时钟类型。CNend
1161bd4fe43Sopenharmony_ci*
1171bd4fe43Sopenharmony_ci* @attention This setting takes effect for all PWM modules. The 160 MHz clock is used by default.
1181bd4fe43Sopenharmony_ciCNcomment:该设置对所有PWM模块均生效。默认为160M时钟。CNend
1191bd4fe43Sopenharmony_ci*
1201bd4fe43Sopenharmony_ci* @param  clk_type [IN] type #hi_pwm_clk_source Clock type. CNcomment:时钟类型。CNend
1211bd4fe43Sopenharmony_ci*
1221bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS Success.
1231bd4fe43Sopenharmony_ci* @retval #Other          Failure. For details, see hi_errno.h.
1241bd4fe43Sopenharmony_ci* @par 依赖:
1251bd4fe43Sopenharmony_ci*            @li hi_pwm.h: Describes the APIs of the PWM module.CNcomment:文件用于描述PWM对外接口。CNend
1261bd4fe43Sopenharmony_ci* @see None
1271bd4fe43Sopenharmony_ci*/
1281bd4fe43Sopenharmony_cihi_u32 hi_pwm_set_clock(hi_pwm_clk_source clk_type);
1291bd4fe43Sopenharmony_ci
1301bd4fe43Sopenharmony_ci/**
1311bd4fe43Sopenharmony_ci* @ingroup iot_pwm
1321bd4fe43Sopenharmony_ci* @brief  Outputs the PWM signal according to the configured parameter.
1331bd4fe43Sopenharmony_ci*         PWM signal duty cycle = duty/freq Frequency = Clock source frequency/freq.
1341bd4fe43Sopenharmony_ciCNcomment:按配置的参数输出PWM信号。PWM信号占空比=duty/freq。频率=时钟源频率/freq。CNend
1351bd4fe43Sopenharmony_ci*
1361bd4fe43Sopenharmony_ci* @par   描述:
1371bd4fe43Sopenharmony_ci*            Starts the PWM signal output.CNcomment:启动PWM信号输出。CNend
1381bd4fe43Sopenharmony_ci*
1391bd4fe43Sopenharmony_ci* @attention This API cannot be called in an interrupt.CNcomment:不支持在中断中调用。CNend
1401bd4fe43Sopenharmony_ci*
1411bd4fe43Sopenharmony_ci* @param  port [IN] type #hi_pwm_port PWM port number.CNcomment:PWM端口号。CNend
1421bd4fe43Sopenharmony_ci* @param  duty [IN] type #hi_u16 PWM duty cycle count. Value range: [1, 65535]. The default value is 750.
1431bd4fe43Sopenharmony_ciCNcomment:PWM占空比计数值。取值范围为:[1, 65535]。默认值为750。CNend
1441bd4fe43Sopenharmony_ci* @param  freq [IN] type #hi_u16 Frequency division multiple. Value range: [1, 65535]. The default value is 1500.
1451bd4fe43Sopenharmony_ciCNcomment:分频倍数。取值范围为:[1, 65535]。默认值为1500。CNend
1461bd4fe43Sopenharmony_ci*
1471bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS Success.
1481bd4fe43Sopenharmony_ci* @retval #Other          Failure. For details, see hi_errno.h.
1491bd4fe43Sopenharmony_ci* @par 依赖:
1501bd4fe43Sopenharmony_ci*            @li hi_pwm.h: Describes the APIs of the PWM module.CNcomment:文件用于描述PWM对外接口。CNend
1511bd4fe43Sopenharmony_ci* @see  hi_pwm_init | hi_pwm_stop。
1521bd4fe43Sopenharmony_ci*/
1531bd4fe43Sopenharmony_cihi_u32 hi_pwm_start(hi_pwm_port port, hi_u16 duty, hi_u16 freq);
1541bd4fe43Sopenharmony_ci
1551bd4fe43Sopenharmony_ci/**
1561bd4fe43Sopenharmony_ci* @ingroup iot_pwm
1571bd4fe43Sopenharmony_ci* @brief  Stops the PWM signal output.CNcomment:停止PWM信号输出。CNend
1581bd4fe43Sopenharmony_ci*
1591bd4fe43Sopenharmony_ci* @par   描述:
1601bd4fe43Sopenharmony_ci*          Stops the PWM signal output.CNcomment: 停止PWM信号输出。CNend
1611bd4fe43Sopenharmony_ci*
1621bd4fe43Sopenharmony_ci* @attention This API cannot be called in an interrupt.CNcomment:不支持在中断中调用。CNend
1631bd4fe43Sopenharmony_ci*
1641bd4fe43Sopenharmony_ci* @param  port [IN] type #hi_pwm_port PWM port number.CNcomment:PWM端口号。CNend
1651bd4fe43Sopenharmony_ci*
1661bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS Success.
1671bd4fe43Sopenharmony_ci* @retval #Other          Failure. For details, see hi_errno.h.
1681bd4fe43Sopenharmony_ci* @par 依赖:
1691bd4fe43Sopenharmony_ci*            @li hi_pwm.h: Describes the APIs of the PWM module.CNcomment:文件用于描述PWM对外接口。CNend
1701bd4fe43Sopenharmony_ci* @see  hi_pwm_init | hi_pwm_start。
1711bd4fe43Sopenharmony_ci*/
1721bd4fe43Sopenharmony_cihi_u32 hi_pwm_stop(hi_pwm_port port);
1731bd4fe43Sopenharmony_ci
1741bd4fe43Sopenharmony_ci#ifdef __cplusplus
1751bd4fe43Sopenharmony_ci}
1761bd4fe43Sopenharmony_ci#endif
1771bd4fe43Sopenharmony_ci#endif
178