Skip to content

Commit 5cb95c4

Browse files
mbolivar-nordicioannisg
authored andcommitted
drivers: led_gpio: minor tweaks
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 <marti.bolivar@nordicsemi.no>
1 parent d6b5023 commit 5cb95c4

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

drivers/led/led_gpio.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ struct led_gpio_config {
2424
const struct gpio_dt_spec *led;
2525
};
2626

27-
2827
static int led_gpio_set_brightness(const struct device *dev, uint32_t led, uint8_t value)
2928
{
3029

@@ -37,7 +36,7 @@ static int led_gpio_set_brightness(const struct device *dev, uint32_t led, uint8
3736

3837
led_gpio = &config->led[led];
3938

40-
return gpio_pin_set(led_gpio->port, led_gpio->pin, (value >= 50));
39+
return gpio_pin_set(led_gpio->port, led_gpio->pin, value > 0);
4140
}
4241

4342
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)
6463
const struct gpio_dt_spec *led = &config->led[i];
6564

6665
if (device_is_ready(led->port)) {
67-
err = gpio_pin_configure(led->port, led->pin,
68-
led->dt_flags | GPIO_OUTPUT_INACTIVE);
66+
err = gpio_pin_configure_dt(led, GPIO_OUTPUT_INACTIVE);
6967

7068
if (err) {
7169
LOG_ERR("Cannot configure GPIO (err %d)", err);

0 commit comments

Comments
 (0)