pwm(8): Add percentage value support for duty cycle
This commit is contained in:
parent
7e40e33031
commit
5088b48b10
@ -67,7 +67,7 @@ Show the configuration of the pwm channel
|
||||
.It Fl p Ar period
|
||||
Configure the period (in nanoseconds) of the pwm channel
|
||||
.It Fl d Ar duty
|
||||
Configure the duty (in nanoseconds) of the pwm channel
|
||||
Configure the duty (in nanoseconds or percentage) of the pwm channel
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
.Bl -bullet
|
||||
@ -76,9 +76,13 @@ Show the configuration of the pwm channel:
|
||||
.Pp
|
||||
pwm -f /dev/pwmc0 -C
|
||||
.It
|
||||
Configure a 50000 ns period and a 25000 duty cycles:
|
||||
Configure a 50000 ns period and a 25000 duty cycle:
|
||||
.Pp
|
||||
pwm -f /dev/pwmc0 -p 50000 -d 25000
|
||||
.It
|
||||
Configure a 50% duty cycle:
|
||||
.Pp
|
||||
pwm -f /dev/pwmc0 -d 50%
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr pwm 9 ,
|
||||
|
@ -71,6 +71,7 @@ main(int argc, char *argv[])
|
||||
int action, ch;
|
||||
cap_rights_t right_ioctl;
|
||||
const unsigned long pwm_ioctls[] = {PWMGETSTATE, PWMSETSTATE, PWMMAXCHANNEL};
|
||||
char *percent;
|
||||
|
||||
action = 0;
|
||||
fd = -1;
|
||||
@ -104,7 +105,9 @@ main(int argc, char *argv[])
|
||||
if (action & ~(PWM_PERIOD | PWM_DUTY))
|
||||
usage();
|
||||
action = PWM_DUTY;
|
||||
duty = strtol(optarg, NULL, 10);
|
||||
duty = strtol(optarg, &percent, 10);
|
||||
if (*percent != '\0' && *percent != '%')
|
||||
usage();
|
||||
break;
|
||||
case 'c':
|
||||
if (channel != -1)
|
||||
@ -199,8 +202,12 @@ main(int argc, char *argv[])
|
||||
case PWM_DUTY:
|
||||
if (period != -1)
|
||||
state.period = period;
|
||||
if (duty != -1)
|
||||
state.duty = duty;
|
||||
if (duty != -1) {
|
||||
if (*percent != '\0')
|
||||
state.duty = state.period * duty / 100;
|
||||
else
|
||||
state.duty = duty;
|
||||
}
|
||||
if (ioctl(fd, PWMSETSTATE, &state) == -1) {
|
||||
fprintf(stderr,
|
||||
"Cannot configure the pwm controller\n");
|
||||
|
Loading…
Reference in New Issue
Block a user