From b1d5eff52d93af05542f444db3e9319ca122abcf Mon Sep 17 00:00:00 2001 From: Jari van Ewijk Date: Mon, 18 Oct 2021 10:03:33 +0200 Subject: [PATCH] Userled driver: Add option to check actual pin state with getall --- drivers/leds/Kconfig | 10 ++++++++++ drivers/leds/userled_lower.c | 23 +++++++++++++++++++++++ drivers/leds/userled_upper.c | 8 +++++++- include/nuttx/board.h | 22 ++++++++++++++++++++++ include/nuttx/leds/userled.h | 7 +++++++ 5 files changed, 69 insertions(+), 1 deletion(-) diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 54ee61590e..b4e2997567 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -32,6 +32,16 @@ config USERLED_LOWER board src/ directory and modified for your specific board requirements. +config USERLED_LOWER_READSTATE + bool "LED Driver Read Actual Pin State" + default n + depends on USERLED_LOWER + ---help--- + Extends the standard LED interface as defined in the + include/nuttx/board.h header file with a function that + checks the actual state of the pin controlling the LED, + which can be used to find malfunctioning LEDs. + endif # USERLED config LEDS_APA102 diff --git a/drivers/leds/userled_lower.c b/drivers/leds/userled_lower.c index 6834cc80fe..b2830381c4 100644 --- a/drivers/leds/userled_lower.c +++ b/drivers/leds/userled_lower.c @@ -44,6 +44,10 @@ static void userled_setled(FAR const struct userled_lowerhalf_s *lower, int led, bool ledon); static void userled_setall(FAR const struct userled_lowerhalf_s *lower, userled_set_t ledset); +#ifdef CONFIG_USERLED_LOWER_READSTATE +static void userled_getall(FAR const struct userled_lowerhalf_s *lower, + userled_set_t *ledset); +#endif /**************************************************************************** * Private Data @@ -58,6 +62,9 @@ static const struct userled_lowerhalf_s g_userled_lower = .ll_supported = userled_supported, .ll_setled = userled_setled, .ll_setall = userled_setall, +#ifdef CONFIG_USERLED_LOWER_READSTATE + .ll_getall = userled_getall, +#endif }; /**************************************************************************** @@ -107,6 +114,22 @@ static void userled_setall(FAR const struct userled_lowerhalf_s *lower, board_userled_all(ledset); } +#ifdef CONFIG_USERLED_LOWER_READSTATE +/**************************************************************************** + * Name: userled_getall + * + * Description: + * Get the state of all LEDs + * + ****************************************************************************/ + +static void userled_getall(FAR const struct userled_lowerhalf_s *lower, + userled_set_t *ledset) +{ + board_userled_getall(ledset); +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/drivers/leds/userled_upper.c b/drivers/leds/userled_upper.c index a2fe68ba90..499f3ea638 100644 --- a/drivers/leds/userled_upper.c +++ b/drivers/leds/userled_upper.c @@ -454,7 +454,7 @@ static int userled_ioctl(FAR struct file *filep, int cmd, unsigned long arg) break; /* Command: ULEDIOC_GETALL - * Description: Get the state of one LED. + * Description: Get the state of all LEDs. * Argument: A write-able pointer to a userled_set_t memory location * in which to return the LED state. * Return: Zero (OK) on success. Minus one will be returned on @@ -469,7 +469,13 @@ static int userled_ioctl(FAR struct file *filep, int cmd, unsigned long arg) if (ledset) { +#ifdef CONFIG_USERLED_LOWER_READSTATE + lower = priv->lu_lower; + DEBUGASSERT(lower != NULL && lower->ll_getall != NULL); + lower->ll_getall(lower, ledset); +#else *ledset = priv->lu_ledset; +#endif ret = OK; } } diff --git a/include/nuttx/board.h b/include/nuttx/board.h index f379a41ef6..39a0836a15 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -673,6 +673,28 @@ void board_userled(int led, bool ledon); void board_userled_all(uint32_t ledset); #endif +/**************************************************************************** + * Name: board_userled_getall + * + * Description: + * This interface may be used by application specific logic to read the + * state of all board LEDs. Definitions for the led set member + * identification is provided in the board-specific board.h header file + * that may be included like: + * + * #included + * + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board + * LEDs. If CONFIG_ARCH_LEDS is not defined, then this interfaces may be + * available to check the LEDs directly from user board logic or indirectly + * user applications (via the common LED character driver). + * + ****************************************************************************/ + +#if defined(CONFIG_ARCH_HAVE_LEDS) && defined(CONFIG_USERLED_LOWER_READSTATE) +void board_userled_getall(uint32_t *ledset); +#endif + /**************************************************************************** * Name: board_button_initialize * diff --git a/include/nuttx/leds/userled.h b/include/nuttx/leds/userled.h index 51024f9410..e613d201b7 100644 --- a/include/nuttx/leds/userled.h +++ b/include/nuttx/leds/userled.h @@ -126,6 +126,13 @@ struct userled_lowerhalf_s CODE void (*ll_setall)(FAR const struct userled_lowerhalf_s *lower, userled_set_t ledset); + +#ifdef CONFIG_USERLED_LOWER_READSTATE + /* Get the state of all LEDs */ + + CODE void (*ll_getall)(FAR const struct userled_lowerhalf_s *lower, + userled_set_t *ledset); +#endif }; /****************************************************************************