apps/examples/rgbled: Add an example using the RGB LED driver
This commit is contained in:
parent
336fefee4d
commit
855d2e70bf
@ -1555,4 +1555,7 @@
|
|||||||
* apps/examples/leds: An example to demonstrate use of LED
|
* apps/examples/leds: An example to demonstrate use of LED
|
||||||
driver (2016-02-20).
|
driver (2016-02-20).
|
||||||
* apps/examples/smp: An verifying SMP configurations (2016-02-21).
|
* apps/examples/smp: An verifying SMP configurations (2016-02-21).
|
||||||
|
* apps/examples/rgbled: Example using the RGB LED driver to
|
||||||
|
drive an RGB LED via PWM. From Alan Carvalho de Assis
|
||||||
|
(2016-02-23).
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ source "$APPSDIR/examples/posix_spawn/Kconfig"
|
|||||||
source "$APPSDIR/examples/qencoder/Kconfig"
|
source "$APPSDIR/examples/qencoder/Kconfig"
|
||||||
source "$APPSDIR/examples/random/Kconfig"
|
source "$APPSDIR/examples/random/Kconfig"
|
||||||
source "$APPSDIR/examples/relays/Kconfig"
|
source "$APPSDIR/examples/relays/Kconfig"
|
||||||
|
source "$APPSDIR/examples/rgbled/Kconfig"
|
||||||
source "$APPSDIR/examples/rgmp/Kconfig"
|
source "$APPSDIR/examples/rgmp/Kconfig"
|
||||||
source "$APPSDIR/examples/romfs/Kconfig"
|
source "$APPSDIR/examples/romfs/Kconfig"
|
||||||
source "$APPSDIR/examples/sendmail/Kconfig"
|
source "$APPSDIR/examples/sendmail/Kconfig"
|
||||||
|
@ -1695,6 +1695,12 @@ examples/relays
|
|||||||
NuttX is built as a protected, supervisor kernel (CONFIG_BUILD_PROTECTED
|
NuttX is built as a protected, supervisor kernel (CONFIG_BUILD_PROTECTED
|
||||||
or CONFIG_BUILD_KERNEL).
|
or CONFIG_BUILD_KERNEL).
|
||||||
|
|
||||||
|
examples/rgbled
|
||||||
|
^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
This example demonstrates the use of the RGB led driver to drive an RGB LED
|
||||||
|
with PWM outputs so that all color characteristcs of RGB LED can be controlled.
|
||||||
|
|
||||||
examples/rgmp
|
examples/rgmp
|
||||||
^^^^^^^^^^^^^
|
^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
11
examples/rgbled/.gitignore
vendored
Normal file
11
examples/rgbled/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/Make.dep
|
||||||
|
/.depend
|
||||||
|
/.built
|
||||||
|
/*.asm
|
||||||
|
/*.obj
|
||||||
|
/*.rel
|
||||||
|
/*.lst
|
||||||
|
/*.sym
|
||||||
|
/*.adb
|
||||||
|
/*.lib
|
||||||
|
/*.src
|
30
examples/rgbled/Kconfig
Normal file
30
examples/rgbled/Kconfig
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#
|
||||||
|
# For a description of the syntax of this configuration file,
|
||||||
|
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||||
|
#
|
||||||
|
|
||||||
|
config EXAMPLES_RGBLED
|
||||||
|
bool "RGB LED Test"
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
Enable the RGB LED example
|
||||||
|
|
||||||
|
if EXAMPLES_RGBLED
|
||||||
|
|
||||||
|
config EXAMPLES_RGBLED_PROGNAME
|
||||||
|
string "Program name"
|
||||||
|
default "rgbled"
|
||||||
|
depends on BUILD_KERNEL
|
||||||
|
---help---
|
||||||
|
This is the name of the program that will be use when the NSH ELF
|
||||||
|
program is installed.
|
||||||
|
|
||||||
|
config EXAMPLES_RGBLED_PRIORITY
|
||||||
|
int "RGBLED task priority"
|
||||||
|
default 100
|
||||||
|
|
||||||
|
config EXAMPLES_RGBLED_STACKSIZE
|
||||||
|
int "RGBLED stack size"
|
||||||
|
default 2048
|
||||||
|
|
||||||
|
endif # EXAMPLES_RGBLED
|
39
examples/rgbled/Make.defs
Normal file
39
examples/rgbled/Make.defs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
############################################################################
|
||||||
|
# apps/examples/rgbled/Make.defs
|
||||||
|
# Adds selected applications to apps/ build
|
||||||
|
#
|
||||||
|
# Copyright (C) 2016 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.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_EXAMPLES_RGBLED),y)
|
||||||
|
CONFIGURED_APPS += examples/rgbled
|
||||||
|
endif
|
56
examples/rgbled/Makefile
Normal file
56
examples/rgbled/Makefile
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
############################################################################
|
||||||
|
# apps/examples/rgbled/Makefile
|
||||||
|
#
|
||||||
|
# Copyright (C) 2016 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.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
-include $(TOPDIR)/Make.defs
|
||||||
|
|
||||||
|
# RGBLED built-in application info
|
||||||
|
|
||||||
|
CONFIG_EXAMPLES_RGBLED_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
||||||
|
CONFIG_EXAMPLES_RGBLED_STACKSIZE ?= 2048
|
||||||
|
|
||||||
|
APPNAME = rgbled
|
||||||
|
PRIORITY = $(CONFIG_EXAMPLES_RGBLED_PRIORITY)
|
||||||
|
STACKSIZE = $(CONFIG_EXAMPLES_RGBLED_STACKSIZE)
|
||||||
|
|
||||||
|
# RGBLED Example
|
||||||
|
|
||||||
|
ASRCS =
|
||||||
|
CSRCS =
|
||||||
|
MAINSRC = rgbled.c
|
||||||
|
|
||||||
|
CONFIG_EXAMPLES_RGBLED_PROGNAME ?= rgbled$(EXEEXT)
|
||||||
|
PROGNAME = $(CONFIG_EXAMPLES_RGBLED_PROGNAME)
|
||||||
|
|
||||||
|
include $(APPDIR)/Application.mk
|
116
examples/rgbled/rgbled.c
Normal file
116
examples/rgbled/rgbled.c
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* examples/rgbled/rgbled.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Alan Carvalho de Assis <acassis@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define RGBLED "/dev/rgb0"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* rgbled_main
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_BUILD_KERNEL
|
||||||
|
int main(int argc, FAR char *argv[])
|
||||||
|
#else
|
||||||
|
int rgbled_main(int argc, char *argv[])
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int red = 255;
|
||||||
|
int green = 0;
|
||||||
|
int blue = 0;
|
||||||
|
int sred = -1;
|
||||||
|
int sgreen = 1;
|
||||||
|
int sblue = 0;
|
||||||
|
int fd;
|
||||||
|
char buffer[8];
|
||||||
|
|
||||||
|
fd = open(RGBLED, O_WRONLY);
|
||||||
|
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
printf("Error opening %s!\n", RGBLED);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
red += sred;
|
||||||
|
green += sgreen;
|
||||||
|
blue += sblue;
|
||||||
|
|
||||||
|
if (green == 255)
|
||||||
|
{
|
||||||
|
sred = 0;
|
||||||
|
sgreen = -1;
|
||||||
|
sblue = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blue == 255)
|
||||||
|
{
|
||||||
|
sred = 1;
|
||||||
|
sgreen = 0;
|
||||||
|
sblue = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (red == 255)
|
||||||
|
{
|
||||||
|
sred = -1;
|
||||||
|
sblue = 0;
|
||||||
|
sgreen = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(buffer, "#%02X%02X%02X", red, green, blue);
|
||||||
|
(void)write(fd, buffer, 8);
|
||||||
|
usleep(5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user