• 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 // errno
20 #define PWM_ERR (-1)
21 #define PWM_WRONOG_CHANNEL (-2)
22 #define PWM_FILE_NOT_EXIST (-3)
23 
24 // pwm enable
25 #define PWM_NOT_ENABLED 0
26 #define PWM_IS_ENABLED 1
27 
28 // pwm polarity
29 #define PWM_POLARITY_NORMAL 0
30 #define PWM_POLARITY_INVERSED 1
31 
32 #define PWM1 1
33 #define PWM2 2
34 
35 // pwm的引脚目录
36 #define PWM1_PEX "/sys/class/pwm/pwmchip0"
37 #define PWM2_PEX "/sys/class/pwm/pwmchip2"
38 
39 // Hilog
40 #undef LOG_DOMAIN
41 #undef LOG_TAG
42 #define LOG_DOMAIN 0  // 标识业务领域,范围0x0~0xFFFFF
43 #define LOG_TAG "Pwm_Test"
44 
45 /*
46  * 作用:初始化引脚,生成对应的引脚目录
47  * 参数:pwmChannel 为选择的引脚
48  */
49 int init_pmw(int pwmChannel);
50 
51 /*
52  * 设置pwm的溢出值
53  * 参数:pwmChannel 为选择的引脚,period 为溢出值
54  */
55 int set_pwm_period(int pwmChannel, int period);
56 
57 /*
58  * 设置pwm一个周期高电平时间
59  * 参数:pwmChannel 为选择的引脚,dutyCycle 为一个周期高电平的值
60  */
61 int set_pwm_dutyCycle(int pwmChannel, int dutyCycle);
62 
63 /*
64  * 设置pwm的极性
65  * 参数:pwmChannel 为选择的引脚,polarity 为极性
66  */
67 int set_pwm_polarity(int pwmChannel, int polarity);
68 
69 /*
70  * 打开pwm引脚,使其使能
71  * 参数:pwmChannel 为选择的引脚,isEnable 为开关值
72  */
73 int set_pwm_enable(int pwmChannel, int isEnable);
74 
75 /*
76  * 得到pwm的溢出值
77  * 参数:pwmChannel 为选择的引脚
78  */
79 int get_pwm_period(int pwmChannel);
80 
81 /*
82  * 得到pwm的一个周期高电平的值
83  * 参数:pwmChannel 为选择的引脚
84  */
85 int get_pwm_dutyCycle(int pwmChannel);
86 
87 /*
88  * 得到pwm的极性
89  * 参数:pwmChannel 为选择的引脚
90  */
91 int get_pwm_polarity(int pwmChannel);
92 
93 /*
94  * 查看pwm的引脚使能值
95  * 参数:pwmChannel 为选择的引脚
96  */
97 int is_pwm_enabled(int pwmChannel);
98 
99 #endif // endif __UM_PWM_H__
100