* [PATCH libpwm] pwmtestperf: Implement -I for inversed polarity requests
@ 2026-04-15 14:37 Uwe Kleine-König
2026-04-28 16:54 ` Uwe Kleine-König
0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2026-04-15 14:37 UTC (permalink / raw)
To: linux-pwm; +Cc: Andrea della Porta
The driver handling for .duty_offset_ns > 0 isn't always trivial to get
right. So make pwmtestperf capable to do some tests with a non-zero duty
offset.
Fix a typo in the manpage en passant.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
Hello,
triggered by a driver submission by Andrea della Porta[1], this increases
test coverage to (hopefully) catch issues around driver handling of
duty offset.
Tesing that on stm32 indeed found a bug, will send a patch for that
later.
Best regards
Uwe
[1] https://lore.kernel.org/linux-pwm/adkrHkANCzxO8KUP@monoceros/
pwmtestperf.1 | 13 +++++++++++--
pwmtestperf.c | 17 ++++++++++++++++-
2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/pwmtestperf.1 b/pwmtestperf.1
index 74dc8e30f32a..944564c14a0b 100644
--- a/pwmtestperf.1
+++ b/pwmtestperf.1
@@ -13,6 +13,7 @@ pwmtestperf \- Applies a simple test pattern to a PWM output
.IB periodlength ]
.RB [ \-S\~\c
.IB step ]
+.RB [ \-I ]
.RB [ \-v ]
.YS
.SH Description
@@ -27,7 +28,7 @@ and
The fixed period is specified by
.I periodlength
-and the duty length is increased in each steps by
+and the duty length is increased in each step by
.I step
up from 0 to
.IR periodlength .
@@ -35,7 +36,11 @@ up from 0 to
.I step
is negative, it decreases from
.I periodlength
-to 0.
+to 0. With
+.B \-I
+given the duty offset in each request is chosen to describe an inversed
+polarity waveform, that is a falling edge at the end of each period. Otherwise
+the duty offset is zero.
.
.SH Options
.
@@ -68,6 +73,10 @@ in nanoseconds defines the length of the periods of the waveform to be set.
in nanoseconds defines the step the duty length is increased in each step. (Or decreased if negative.)
.
.TP
+.B \-I
+Use requests with inverted polarity.
+.
+.TP
.B \-v
Emit some information during runtime.
.
diff --git a/pwmtestperf.c b/pwmtestperf.c
index 72abf3987459..95be2b6fe64e 100644
--- a/pwmtestperf.c
+++ b/pwmtestperf.c
@@ -22,16 +22,21 @@ int main(int argc, char *const argv[])
int ret;
int opt;
long long step = 1;
+ bool inverted = false;
unsigned int chipno = 0;
unsigned int pwmno = 0;
- while ((opt = getopt(argc, argv, "c:p:P:S:")) != -1) {
+ while ((opt = getopt(argc, argv, "c:Ip:P:S:")) != -1) {
switch (opt) {
case 'c':
chipno = atoi(optarg);
break;
+ case 'I':
+ inverted = true;
+ break;
+
case 'p':
pwmno = atoi(optarg);
break;
@@ -67,6 +72,16 @@ int main(int argc, char *const argv[])
}
for (wf.duty_length_ns = (step > 0 ? 0 : wf.period_length_ns); wf.duty_length_ns <= wf.period_length_ns; wf.duty_length_ns += step) {
+
+ /*
+ * .duty_length_ns must be < .period_length_ns, so don't invert
+ * for .duty_length_ns == 0.
+ */
+ if (inverted && wf.duty_length_ns)
+ wf.duty_offset_ns = wf.period_length_ns - wf.duty_length_ns;
+ else
+ wf.duty_offset_ns = 0;
+
ret = pwm_set_waveform(pwm, &wf);
if (ret < 0) {
perror("Failed to configure PWM");
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-28 16:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-15 14:37 [PATCH libpwm] pwmtestperf: Implement -I for inversed polarity requests Uwe Kleine-König
2026-04-28 16:54 ` Uwe Kleine-König
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox