mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jules Maselbas <jmaselbas@zdiv.net>
To: Marc Reilly <marc@cpdesign.com.au>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2 2/3] commands: pwm: add pwm_get command
Date: Mon, 29 May 2023 11:06:24 +0200	[thread overview]
Message-ID: <ZHRrEFarvSLes3Zd@tour> (raw)
In-Reply-To: <20230529001318.12309-3-marc@cpdesign.com.au>

Hi Marc,

I have some minor remarks/suggestions, see below

On Mon, May 29, 2023 at 10:13:17AM +1000, Marc Reilly wrote:
> Signed-off-by: Marc Reilly <marc@cpdesign.com.au>
> ---
>  commands/Kconfig |  7 ++++++
>  commands/pwm.c   | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 64 insertions(+)
> 
> diff --git a/commands/Kconfig b/commands/Kconfig
> index cc7585bbb2..f2a6d22f69 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -1940,6 +1940,13 @@ config CMD_PWM
>  
>  	  Controls the pwm values such as period and duty cycle
>  
> +
> +	  pwm_get - get pwm state
> +
> +	  Usage: pwm_get [d]
> +
> +	  Displays the pwm values such as period and duty cycle
> +
>  config CMD_LED
>  	bool
>  	depends on LED
> diff --git a/commands/pwm.c b/commands/pwm.c
> index a21b918c89..d344f7e1ec 100644
> --- a/commands/pwm.c
> +++ b/commands/pwm.c
> @@ -141,3 +141,60 @@ BAREBOX_CMD_START(pwm_set)
>  	BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
>  	BAREBOX_CMD_HELP(cmd_pwm_set_help)
>  BAREBOX_CMD_END
> +
> +#define HZ_FROM_NANOSECONDS(x) (1000000000UL/(x))
> +
> +static int do_pwm_get(int argc, char *argv[])
> +{
> +	struct pwm_device *pwm = NULL;
> +	struct pwm_state state;
> +	int error = 0;
> +	char *devname = NULL;
> +	int opt;
> +
> +	while ((opt = getopt(argc, argv, "d:")) > 0) {
> +		switch (opt) {
> +		case 'd':
> +			devname = optarg;
> +			break;
> +		}
> +	}
> +
> +	if (!devname) {
> +		printf(" need to specify a device\n");
> +		return COMMAND_ERROR_USAGE;
> +	}
> +
> +	pwm = pwm_request(devname);
> +	if (!pwm) {
> +		printf(" pwm device %s not found\n", devname);
> +		return -ENODEV;
> +	}
> +
> +	pwm_get_state(pwm, &state);
> +
> +	printf(" pwm params for '%s':\n\x13", devname);
typo: You have inserted a control S (^S) character at the of the string

> +	printf("  period_ns: %u (ns)\n", state.period_ns);
> +	printf("  duty_ns  : %u (ns)\n", state.duty_ns);
nitpicking: maybe you can remove the _ns suffix when priting period/duty,
it is already added in parenthesis.

> +	printf("  enabled  : %d\n", state.p_enable);
> +	printf("  polarity : %s\n", state.polarity == 0 ? "Normal" : "Inverted");
> +	printf("  freq     : %lu (Hz)\n", HZ_FROM_NANOSECONDS(state.period_ns));
> +
> +	pwm_free(pwm);
> +	return error;
nit: error is not used, you can remove the variable and directly return 0

> +}
> +
> +BAREBOX_CMD_HELP_START(pwm_get)
> +BAREBOX_CMD_HELP_TEXT("Gets a pwm device parameters.")
> +BAREBOX_CMD_HELP_TEXT(" Specify the device by device name")
> +BAREBOX_CMD_HELP_TEXT("Options:")
> +BAREBOX_CMD_HELP_OPT("-d string", "device name (eg 'pwm0')")
> +BAREBOX_CMD_HELP_END
> +
> +BAREBOX_CMD_START(pwm_get)
> +	.cmd		= do_pwm_get,
> +	BAREBOX_CMD_DESC("get pwm")
> +	BAREBOX_CMD_OPTS("[-d]")
> +	BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
> +	BAREBOX_CMD_HELP(cmd_pwm_get_help)
> +BAREBOX_CMD_END
> -- 
> 2.35.3
> 
> 



  reply	other threads:[~2023-05-29  9:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-29  0:13 Adding PWM Commands Marc Reilly
2023-05-29  0:13 ` [PATCH v2 1/3] commands: add pwm manipulation command Marc Reilly
2023-05-29  9:23   ` Jules Maselbas
2023-05-29 11:03     ` marc
2023-05-29 12:18       ` Jules Maselbas
2023-05-29  0:13 ` [PATCH v2 2/3] commands: pwm: add pwm_get command Marc Reilly
2023-05-29  9:06   ` Jules Maselbas [this message]
2023-05-29  0:13 ` [PATCH v2 3/3] include: pwm: minor function doc fix for pwm_set_relative_duty_cycle() Marc Reilly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZHRrEFarvSLes3Zd@tour \
    --to=jmaselbas@zdiv.net \
    --cc=barebox@lists.infradead.org \
    --cc=marc@cpdesign.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox