From 5cb95c4ce6cb3e04d499465decf3a4cec2e2ce1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Tue, 27 Apr 2021 10:38:28 -0700 Subject: [PATCH] drivers: led_gpio: minor tweaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two minor tweaks and a semantics change: - fix a whitespace nit - use gpio_pin_configure_dt() - turn the LED on in case the percentage is nonzero The last change patterns this driver after behavior in the Android lights HAL, which recommends analogous behavior when the user requests a color change in a non-RGB LED: Do your best here. [...] If you can only do on or off, 0 is off, anything else is on. https://source.android.com/reference/hal/structlight__state__t I think this behavior makes more sense. Signed-off-by: Martí Bolívar --- drivers/led/led_gpio.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/led/led_gpio.c b/drivers/led/led_gpio.c index 7282da3b234..25f3567d99a 100644 --- a/drivers/led/led_gpio.c +++ b/drivers/led/led_gpio.c @@ -24,7 +24,6 @@ struct led_gpio_config { const struct gpio_dt_spec *led; }; - static int led_gpio_set_brightness(const struct device *dev, uint32_t led, uint8_t value) { @@ -37,7 +36,7 @@ static int led_gpio_set_brightness(const struct device *dev, uint32_t led, uint8 led_gpio = &config->led[led]; - return gpio_pin_set(led_gpio->port, led_gpio->pin, (value >= 50)); + return gpio_pin_set(led_gpio->port, led_gpio->pin, value > 0); } static int led_gpio_on(const struct device *dev, uint32_t led) @@ -64,8 +63,7 @@ static int led_gpio_init(const struct device *dev) const struct gpio_dt_spec *led = &config->led[i]; if (device_is_ready(led->port)) { - err = gpio_pin_configure(led->port, led->pin, - led->dt_flags | GPIO_OUTPUT_INACTIVE); + err = gpio_pin_configure_dt(led, GPIO_OUTPUT_INACTIVE); if (err) { LOG_ERR("Cannot configure GPIO (err %d)", err);