• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Unionman Technology Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __UM_PWM_H__
17 #define __UM_PWM_H__
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 // errno
24 #define PWM_ERR (-1)
25 #define PWM_WRONOG_CHANNEL (-2)
26 #define PWM_FILE_NOT_EXIST (-3)
27 
28 // pwm enable
29 #define PWM_NOT_ENABLED 0
30 #define PWM_IS_ENABLED 1
31 
32 // pwm polarity
33 #define PWM_POLARITY_NORMAL 0
34 #define PWM_POLARITY_INVERSED 1
35 
36 #define PWM1 1
37 #define PWM2 2
38 
39 // pwm的引脚目录
40 #define PWM1_PEX "/sys/class/pwm/pwmchip0"
41 #define PWM2_PEX "/sys/class/pwm/pwmchip2"
42 
43 // Hilog
44 #undef LOG_DOMAIN
45 #undef LOG_TAG
46 #define LOG_DOMAIN 0 // 标识业务领域,范围0x0~0xFFFFF
47 #define LOG_TAG "Pwm_Test"
48 
49 /*
50  * 作用:初始化引脚,生成对应的引脚目录
51  * 参数:pwmChannel 为选择的引脚
52  */
53 int init_pmw(int pwmChannel);
54 
55 /*
56  * 设置pwm的溢出值
57  * 参数:pwmChannel 为选择的引脚,period 为溢出值
58  */
59 int set_pwm_period(int pwmChannel, int period);
60 
61 /*
62  * 设置pwm一个周期高电平时间
63  * 参数:pwmChannel 为选择的引脚,dutyCycle 为一个周期高电平的值
64  */
65 int set_pwm_dutyCycle(int pwmChannel, int dutyCycle);
66 
67 /*
68  * 设置pwm的极性
69  * 参数:pwmChannel 为选择的引脚,polarity 为极性
70  */
71 int set_pwm_polarity(int pwmChannel, int polarity);
72 
73 /*
74  * 打开pwm引脚,使其使能
75  * 参数:pwmChannel 为选择的引脚,isEnable 为开关值
76  */
77 int set_pwm_enable(int pwmChannel, int isEnable);
78 
79 /*
80  * 得到pwm的溢出值
81  * 参数:pwmChannel 为选择的引脚
82  */
83 int get_pwm_period(int pwmChannel);
84 
85 /*
86  * 得到pwm的一个周期高电平的值
87  * 参数:pwmChannel 为选择的引脚
88  */
89 int get_pwm_dutyCycle(int pwmChannel);
90 
91 /*
92  * 得到pwm的极性
93  * 参数:pwmChannel 为选择的引脚
94  */
95 int get_pwm_polarity(int pwmChannel);
96 
97 /*
98  * 查看pwm的引脚使能值
99  * 参数:pwmChannel 为选择的引脚
100  */
101 int is_pwm_enabled(int pwmChannel);
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 #endif // endif __UM_PWM_H__
108