Userled driver: Add option to check actual pin state with getall

This commit is contained in:
Jari van Ewijk 2021-10-18 10:03:33 +02:00 committed by David Sidrane
parent 9a0146f15f
commit b1d5eff52d
5 changed files with 69 additions and 1 deletions

View file

@ -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

View file

@ -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
****************************************************************************/

View file

@ -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;
}
}

View file

@ -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 <arch/board/board.h>
*
* 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
*

View file

@ -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
};
/****************************************************************************