Add support for a general user LED lower-half driver
This commit is contained in:
parent
0dea00177e
commit
fc91ded815
|
@ -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).
|
||||
|
||||
|
|
|
@ -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/<arch>/src/<chip>) UNLESS those
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
/****************************************************************************
|
||||
* drivers/discrete/userled_lower.c
|
||||
*
|
||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/board.h>
|
||||
#include <nuttx/discrete/userled.h>
|
||||
|
||||
#undef __KERNEL__
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#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 */
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* drivers/button_upper.c
|
||||
* drivers/discrete/userled_upper.c
|
||||
*
|
||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* drivers/button_upper.c
|
||||
* drivers/input/button_upper.c
|
||||
*
|
||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
#include <nuttx/config.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
|
||||
#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 */
|
||||
|
|
Loading…
Reference in New Issue