diff options
author | Emmanuel Vadot <manu@FreeBSD.org> | 2018-12-14 18:38:10 +0000 |
---|---|---|
committer | Emmanuel Vadot <manu@FreeBSD.org> | 2018-12-14 18:38:10 +0000 |
commit | 50a123aad896cf917d2187a49cb28bd9eeb80c3d (patch) | |
tree | 84d1edc7c24471e6685c4590bd24005d1527fe2a /usr.sbin/pwm | |
parent | 6a9997ed67b564bf37552df18335fa6c49815671 (diff) | |
download | src-test2-50a123aad896cf917d2187a49cb28bd9eeb80c3d.tar.gz src-test2-50a123aad896cf917d2187a49cb28bd9eeb80c3d.zip |
Notes
Diffstat (limited to 'usr.sbin/pwm')
-rw-r--r-- | usr.sbin/pwm/pwm.8 | 8 | ||||
-rw-r--r-- | usr.sbin/pwm/pwm.c | 13 |
2 files changed, 16 insertions, 5 deletions
diff --git a/usr.sbin/pwm/pwm.8 b/usr.sbin/pwm/pwm.8 index 08bb1f1c7425..92ef83705ed0 100644 --- a/usr.sbin/pwm/pwm.8 +++ b/usr.sbin/pwm/pwm.8 @@ -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 , diff --git a/usr.sbin/pwm/pwm.c b/usr.sbin/pwm/pwm.c index ebb4349635fd..62e15bf18455 100644 --- a/usr.sbin/pwm/pwm.c +++ b/usr.sbin/pwm/pwm.c @@ -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"); |