From: Richard Henderson <richard.henderson@linaro.org>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>, qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Andrew Jeffery" <andrew@aj.id.au>,
qemu-arm@nongnu.org, "Joel Stanley" <joel@jms.id.au>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Cédric Le Goater" <clg@kaod.org>
Subject: Re: [PATCH v3 1/7] hw/misc: Add a LED device
Date: Sat, 20 Jun 2020 19:00:25 -0700 [thread overview]
Message-ID: <f2cc97dc-87c8-5cc8-e0fb-026cf80c25fa@linaro.org> (raw)
In-Reply-To: <20200620230719.32139-2-f4bug@amsat.org>
On 6/20/20 4:07 PM, Philippe Mathieu-Daudé wrote:
> Add a LED device which can be connected to a GPIO output.
> LEDs are limited to a set of colors.
> They can also be dimmed with PWM devices. For now we do
> not implement the dimmed mode, but in preparation of a
> future implementation, we start using the LED intensity.
> When used with GPIOs, the intensity can only be either
> minium or maximum. This depends of the polarity of the
> GPIO.
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> include/hw/misc/led.h | 79 +++++++++++++++++++++++++++
> hw/misc/led.c | 121 ++++++++++++++++++++++++++++++++++++++++++
> MAINTAINERS | 6 +++
> hw/misc/Kconfig | 3 ++
> hw/misc/Makefile.objs | 1 +
> hw/misc/trace-events | 3 ++
> 6 files changed, 213 insertions(+)
> create mode 100644 include/hw/misc/led.h
> create mode 100644 hw/misc/led.c
>
> diff --git a/include/hw/misc/led.h b/include/hw/misc/led.h
> new file mode 100644
> index 0000000000..821ee1247d
> --- /dev/null
> +++ b/include/hw/misc/led.h
> @@ -0,0 +1,79 @@
> +/*
> + * QEMU single LED device
> + *
> + * Copyright (C) 2020 Philippe Mathieu-Daudé <f4bug@amsat.org>
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +#ifndef HW_MISC_LED_H
> +#define HW_MISC_LED_H
> +
> +#include "hw/qdev-core.h"
> +
> +#define TYPE_LED "led"
> +#define LED(obj) OBJECT_CHECK(LEDState, (obj), TYPE_LED)
> +
> +typedef enum {
> + LED_COLOR_UNKNOWN,
> + LED_COLOR_RED,
> + LED_COLOR_ORANGE,
> + LED_COLOR_AMBER,
> + LED_COLOR_YELLOW,
> + LED_COLOR_GREEN,
> + LED_COLOR_BLUE,
> + LED_COLOR_VIOLET, /* PURPLE */
> + LED_COLOR_WHITE,
> + LED_COLOR_COUNT
> +} LEDColor;
Is color especially interesting, given that we only actually "display" the
color via tracing?
> +/* Definitions useful when a LED is connected to a GPIO */
> +#define LED_RESET_INTENSITY_ACTIVE_LOW UINT16_MAX
> +#define LED_RESET_INTENSITY_ACTIVE_HIGH 0U
> +
> +typedef struct LEDState {
> + /* Private */
> + DeviceState parent_obj;
> + /* Public */
> +
> + /* Properties */
> + char *description;
> + char *color;
The enumeration is unused by the actual device, it would seem?
> +/**
> + * led_set_intensity: set the state of a LED device
> + * @s: the LED object
> + * @is_on: boolean indicating whether the LED is emitting
> + *
> + * This utility is meant for LED connected to GPIO.
> + */
> +void led_set_state(LEDState *s, bool is_on);
Comment mismatch.
> +void led_set_intensity(LEDState *s, uint16_t new_intensity)
> +{
> + trace_led_set_intensity(s->description ? s->description : "n/a",
> + s->color, new_intensity);
Why not default description upon reset/realize?
> +static void led_realize(DeviceState *dev, Error **errp)
> +{
> + LEDState *s = LED(dev);
> +
> + if (s->color == NULL) {
> + error_setg(errp, "property 'color' not specified");
> + return;
> + }
> +}
Indeed, why not insist that description is set? If a board is forced to say
that the led is red, should it not also be forced to label it?
> +static Property led_properties[] = {
> + DEFINE_PROP_STRING("color", LEDState, color),
It would appear that one can set any color via properties, including "plaid".
So if you do want the char *color field, what's the point in the enum?
> +# led.c
> +led_set_intensity(const char *color, const char *desc, uint16_t intensity) "LED desc:'%s' color:%s intensity: 0x%04"PRIx16
Is 0...65535 the best set of intensities?
Is that more valuable than e.g. a percentage?
r~
next prev parent reply other threads:[~2020-06-21 2:01 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-20 23:07 [PATCH v3 0/7] hw/misc: Add LED device Philippe Mathieu-Daudé
2020-06-20 23:07 ` [PATCH v3 1/7] hw/misc: Add a " Philippe Mathieu-Daudé
2020-06-21 2:00 ` Richard Henderson [this message]
2020-06-21 20:35 ` Philippe Mathieu-Daudé
2020-06-21 20:50 ` Richard Henderson
2020-06-20 23:07 ` [PATCH v3 2/7] hw/misc/led: Add helper to connect LED to GPIO output Philippe Mathieu-Daudé
2020-06-21 19:09 ` Richard Henderson
2020-06-20 23:07 ` [PATCH v3 3/7] hw/misc/led: Emit a trace event when LED intensity has changed Philippe Mathieu-Daudé
2020-06-21 19:23 ` Richard Henderson
2020-06-21 22:25 ` Philippe Mathieu-Daudé
2020-06-22 16:48 ` Richard Henderson
2020-06-23 7:45 ` Philippe Mathieu-Daudé
2020-06-20 23:07 ` [PATCH v3 4/7] hw/arm/aspeed: Add the 3 front LEDs drived by the PCA9552 #1 Philippe Mathieu-Daudé
2020-06-21 20:51 ` Richard Henderson
2020-06-20 23:07 ` [PATCH v3 5/7] hw/misc/mps2-fpgaio: Use the LED device Philippe Mathieu-Daudé
2020-06-21 21:00 ` Richard Henderson
2020-06-21 21:09 ` Philippe Mathieu-Daudé
2020-06-20 23:07 ` [PATCH v3 6/7] hw/misc/mps2-scc: " Philippe Mathieu-Daudé
2020-06-21 17:31 ` Philippe Mathieu-Daudé
2020-06-21 21:05 ` Richard Henderson
2020-06-20 23:07 ` [PATCH v3 7/7] hw/arm/tosa: Replace fprintf() calls by LED devices Philippe Mathieu-Daudé
2020-06-21 16:52 ` Philippe Mathieu-Daudé
2020-06-20 23:58 ` [PATCH v3 0/7] hw/misc: Add LED device no-reply
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=f2cc97dc-87c8-5cc8-e0fb-026cf80c25fa@linaro.org \
--to=richard.henderson@linaro.org \
--cc=andrew@aj.id.au \
--cc=clg@kaod.org \
--cc=f4bug@amsat.org \
--cc=joel@jms.id.au \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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;
as well as URLs for NNTP newsgroup(s).