blob: ad7273449432aa3cdc9afcd37b6ea6d9534d0ffd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/* SPDX-License-Identifier: 0BSD */
/* SPDX-FileCopyrightText: 2023 Uwe Kleine-König <u.kleine-koenig@pengutronix.de> */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pwm.h>
int main(int argc, char *const argv[])
{
struct pwm_chip *chip;
struct pwm *pwm;
struct pwm_state state = {
.period = 50000,
.duty_cycle = 0,
.duty_offset = 0,
};
int ret;
int opt;
unsigned int chipno = 0;
unsigned int pwmno = 0;
while ((opt = getopt(argc, argv, "c:p:P:")) != -1) {
switch (opt) {
case 'c':
chipno = atoi(optarg);
break;
case 'p':
pwmno = atoi(optarg);
break;
case 'P':
state.period = atoll(optarg);
break;
default:
return EXIT_FAILURE;
}
}
chip = pwm_chip_open_by_number(chipno);
if (!chip) {
perror("Failed to open pwmchip0");
return EXIT_FAILURE;
}
pwm = pwm_chip_get_pwm(chip, pwmno);
if (!pwm) {
perror("Failed to get pwm0");
return EXIT_FAILURE;
}
for (state.duty_cycle = 0; state.duty_cycle <= state.period; ++state.duty_cycle) {
ret = pwm_apply_state(pwm, &state);
if (ret < 0) {
perror("Failed to configure PWM");
return EXIT_FAILURE;
}
}
pwm_chip_close(chip);
return EXIT_SUCCESS;
}
|