diff --git a/ChangeLog b/ChangeLog index 0297310651..246d913890 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11052,4 +11052,10 @@ * Rename ioexpander/ directories to discrete/. This expands the namespace so that other discrete I/O drivers can reside there as well (2015-11-01). + * drivers/discrete/userled_upper.c and include/discrete/userled.h: Add + a generic character driver that may be used by applications to write + to board LEDs (2015-11-01). + * drivers/discrete/userled_lower.c: Add a generic lower-half user LED + driver that may be used by any board that supports the standard + board user LED interfaces (2015-11-01). diff --git a/drivers/discrete/Kconfig b/drivers/discrete/Kconfig index 9bd4492a9d..787c6e541a 100644 --- a/drivers/discrete/Kconfig +++ b/drivers/discrete/Kconfig @@ -65,7 +65,7 @@ config USERLED_LOWER 1. The board implementation must provide the LED interfaces as defined in include/nuttx/board.h 2. The board.h header file must provide the definition - NUM_USERLED, and + BOARD_NLEDS, and 3. The board.h header file must not include any other header files that are not accessibble in this context (such as those in arch//src/) UNLESS those diff --git a/drivers/discrete/userled_lower.c b/drivers/discrete/userled_lower.c new file mode 100644 index 0000000000..52a0daa275 --- /dev/null +++ b/drivers/discrete/userled_lower.c @@ -0,0 +1,141 @@ +/**************************************************************************** + * drivers/discrete/userled_lower.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#undef __KERNEL__ +#include + +#if CONFIG_USERLED_LOWER + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static userled_set_t userled_supported(FAR const struct userled_lowerhalf_s *lower); +static void userled_led(FAR const struct userled_lowerhalf_s *lower, +static void userled_ledset(FAR const struct userled_lowerhalf_s *lower, + userled_set_t ledset); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This is the user LED lower half driver interface */ + +static const struct userled_lowerhalf_s g_userled_lower = +{ + .ll_supported = userled_supported, + .ll_led = userled_led, + .ll_ledset = userled_ledset, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: userled_supported + * + * Description: + * Return the set of LEDs supported by the board + * + ****************************************************************************/ + +static userled_set_t userled_supported(FAR const struct userled_lowerhalf_s *lower) +{ + ivdbg("BOARD_NLEDS: %02x\n", BOARD_NLEDS); + return (userled_set_t)((1 << BOARD_NLEDS) - 1); +} + +/**************************************************************************** + * Name: userled_led + * + * Description: + * Set the current state of one LED + * + ****************************************************************************/ + +static void userled_led(FAR const struct userled_lowerhalf_s *lower, + int led, bool ledon) +{ + board_userled(led, ledon); +} + +/**************************************************************************** + * Name: userled_led + * + * Description: + * Set the state of all LEDs + * + ****************************************************************************/ + +static void userled_ledset(FAR const struct userled_lowerhalf_s *lower, + userled_set_t ledset) +{ + board_userled_all(ledset); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: userled_lower_initialize + * + * Description: + * Initialize the generic LED lower half driver, bind it and register + * it with the upper half LED driver as devname. + * + ****************************************************************************/ + +int userled_lower_initialize(FAR const char *devname) +{ + board_userled_initialize(); + return userled_register(devname, &g_userled_lower); +} + +#endif /* CONFIG_USERLED_LOWER */ diff --git a/drivers/discrete/userled_upper.c b/drivers/discrete/userled_upper.c index 71030ea734..49c3188f97 100644 --- a/drivers/discrete/userled_upper.c +++ b/drivers/discrete/userled_upper.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/button_upper.c + * drivers/discrete/userled_upper.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/drivers/input/button_upper.c b/drivers/input/button_upper.c index deb9492fba..81e2157039 100644 --- a/drivers/input/button_upper.c +++ b/drivers/input/button_upper.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/button_upper.c + * drivers/input/button_upper.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/include/nuttx/discrete/userled.h b/include/nuttx/discrete/userled.h index 7d80e1c5a6..c14fa609de 100644 --- a/include/nuttx/discrete/userled.h +++ b/include/nuttx/discrete/userled.h @@ -43,6 +43,8 @@ #include #include +#ifdef CONFIG_ARCH_HAVE_LEDS + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -177,9 +179,23 @@ extern "C" int userled_register(FAR const char *devname, FAR const struct userled_lowerhalf_s *lower); +/**************************************************************************** + * Name: userled_lower_initialize + * + * Description: + * Initialize the generic LED lower half driver, bind it and register + * it with the upper half LED driver as devname. + * + ****************************************************************************/ + +#ifdef CONFIG_USERLED_LOWER +int userled_lower_initialize(FAR const char *devname); +#endif + #undef EXTERN #ifdef __cplusplus } #endif +#endif /* CONFIG_ARCH_HAVE_LEDS */ #endif /* __INCLUDE_NUTTX_DISCRETE_USERLED_H */