From d75e8c5089a969f19e23164edf1029729f2544e3 Mon Sep 17 00:00:00 2001 From: Adrian Chadd Date: Sun, 31 Jul 2016 06:24:26 +0000 Subject: [PATCH] [gpioled] add support for inverting the LED polarity. No, this isn't a star trek science joke - sometimes LEDs are wired up to be active low, so this is needed. Submitted by: Dan Nelson --- sys/dev/gpio/gpioled.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sys/dev/gpio/gpioled.c b/sys/dev/gpio/gpioled.c index bd77f5386d53..2c579e404bc3 100644 --- a/sys/dev/gpio/gpioled.c +++ b/sys/dev/gpio/gpioled.c @@ -66,6 +66,7 @@ struct gpioled_softc device_t sc_busdev; struct mtx sc_mtx; struct cdev *sc_leddev; + int sc_invert; }; static void gpioled_control(void *, int); @@ -82,6 +83,8 @@ gpioled_control(void *priv, int onoff) GPIOLED_LOCK(sc); if (GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, GPIOLED_PIN, GPIO_PIN_OUTPUT) == 0) { + if (sc->sc_invert) + onoff = !onoff; GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, GPIOLED_PIN, onoff ? GPIO_PIN_HIGH : GPIO_PIN_LOW); } @@ -199,6 +202,8 @@ gpioled_attach(device_t dev) if (resource_string_value(device_get_name(dev), device_get_unit(dev), "name", &name)) name = NULL; + resource_int_value(device_get_name(dev), + device_get_unit(dev), "invert", &sc->sc_invert); #endif sc->sc_leddev = led_create_state(gpioled_control, sc, name ? name :