diff --git a/examples/README.txt b/examples/README.txt index b89d385fd..ce631019f 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -400,6 +400,11 @@ examples/elf LDELFFLAGS = -r -e main -T$(TOPDIR)/binfmt/libelf/gnu-elf.ld +examples/fb +^^^^^^^^^^^ + + A simple test of the framebuffer character driver. + examples/flash_test ^^^^^^^^^^^^^^^^^^^ diff --git a/examples/adc/adc_main.c b/examples/adc/adc_main.c index 37d6c7777..f35546cad 100644 --- a/examples/adc/adc_main.c +++ b/examples/adc/adc_main.c @@ -252,7 +252,6 @@ int adc_main(int argc, char *argv[]) * logic prior to running this test. */ - /* Set the default values */ adc_devpath(&g_adcstate, CONFIG_EXAMPLES_ADC_DEVPATH); diff --git a/examples/fb/.gitignore b/examples/fb/.gitignore new file mode 100644 index 000000000..fa1ec7579 --- /dev/null +++ b/examples/fb/.gitignore @@ -0,0 +1,11 @@ +/Make.dep +/.depend +/.built +/*.asm +/*.obj +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src diff --git a/examples/fb/Kconfig b/examples/fb/Kconfig new file mode 100644 index 000000000..38b68c52f --- /dev/null +++ b/examples/fb/Kconfig @@ -0,0 +1,38 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config EXAMPLES_FB + bool "Framebuffer driver example" + default n + depends on VIDEO_FB + ---help--- + Enable the Framebuffer driver example + +if EXAMPLES_FB + +config EXAMPLES_FB_DEFAULTFB + string "Default framebuffer driver" + default "/dev/fb0" + ---help--- + Default framebuffer drivers. This selection can be overridden from + the command line. + +config EXAMPLES_FB_PROGNAME + string "Program name" + default "fb" + 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_FB_PRIORITY + int "Task priority" + default 100 + +config EXAMPLES_FB_STACKSIZE + int "Stack size" + default 2048 + +endif diff --git a/examples/fb/Make.defs b/examples/fb/Make.defs new file mode 100644 index 000000000..e6414539c --- /dev/null +++ b/examples/fb/Make.defs @@ -0,0 +1,39 @@ +############################################################################ +# apps/examples/fb/Make.defs +# Adds selected applications to apps/ build +# +# 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. +# +############################################################################ + +ifeq ($(CONFIG_EXAMPLES_FB),y) +CONFIGURED_APPS += examples/fb +endif diff --git a/examples/fb/Makefile b/examples/fb/Makefile new file mode 100644 index 000000000..5e087c96f --- /dev/null +++ b/examples/fb/Makefile @@ -0,0 +1,56 @@ +############################################################################ +# apps/examples/fb/Makefile +# +# Copyright (C) 2017 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. +# +############################################################################ + +-include $(TOPDIR)/Make.defs + +# FB, World! built-in application info + +CONFIG_EXAMPLES_FB_PRIORITY ?= SCHED_PRIORITY_DEFAULT +CONFIG_EXAMPLES_FB_STACKSIZE ?= 2048 + +APPNAME = fb +PRIORITY = $(CONFIG_EXAMPLES_FB_PRIORITY) +STACKSIZE = $(CONFIG_EXAMPLES_FB_STACKSIZE) + +# FB, World! Example + +ASRCS = +CSRCS = +MAINSRC = fb_main.c + +CONFIG_EXAMPLES_FB_PROGNAME ?= fb$(EXEEXT) +PROGNAME = $(CONFIG_EXAMPLES_FB_PROGNAME) + +include $(APPDIR)/Application.mk diff --git a/examples/fb/fb_main.c b/examples/fb/fb_main.c new file mode 100644 index 000000000..35b63e69f --- /dev/null +++ b/examples/fb/fb_main.c @@ -0,0 +1,167 @@ +/**************************************************************************** + * examples/fb/fb_main.c + * + * Copyright (C) 2017 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 +#include + +#include + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct fb_state_s +{ + int fd; + struct fb_videoinfo_s vinfo; + struct fb_planeinfo_s pinfo; + FAR void *fbmem; +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const char g_default_fbdev[] = CONFIG_EXAMPLES_FB_DEFAULTFB; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * fb_main + ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int fb_main(int argc, char *argv[]) +#endif +{ + struct fb_state_s state; + FAR const char *fbdev = g_default_fbdev; + int ret; + + /* There is a single required argument: The path to the framebuffer + * driver. + */ + + if (argc == 2) + { + fbdev = argv[1]; + } + else if (argc != 1) + { + fprintf(stderr, "ERROR: Single argument required\n"); + fprintf(stderr, "USAGE: %s []\n", argv[0]); + return EXIT_FAILURE; + } + + /* Open the framebuffer driver */ + + state.fd = open(fbdev, O_RDWR); + if (state.fd < 0) + { + int errcode = errno; + fprintf(stderr, "ERROR: Failed to open %s: %d\n", fbdev, errcode); + return EXIT_FAILURE; + } + + /* Get the characteristics of the framebuffer */ + + ret = ioctl(state.fd, FBIOGET_VIDEOINFO, + (unsigned long)((uintptr_t)&state.vinfo)); + if (ret < 0) + { + int errcode = errno; + fprintf(stderr, "ERROR: ioctl(FBIOGET_VIDEOINFO) failed: %d\n", + errcode); + close(state.fd); + return EXIT_FAILURE; + } + + printf("VideoInfo:\n"); + printf(" fmt: %u\n", state.vinfo.fmt); + printf(" xres: %u\n", state.vinfo.xres); + printf(" yres: %u\n", state.vinfo.yres); + printf(" nplanes: %u\n", state.vinfo.nplanes); + + ret = ioctl(state.fd, FBIOGET_PLANEINFO, + (unsigned long)((uintptr_t)&state.pinfo)); + if (ret < 0) + { + int errcode = errno; + fprintf(stderr, "ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n", + errcode); + close(state.fd); + return EXIT_FAILURE; + } + + printf("PlaneInfo (plane 0):\n"); + printf(" fbmem: %p\n", state.pinfo.fbmem); + printf(" fblen: %lu\n", (unsigned long)state.pinfo.fblen); + printf(" stride: %u\n", state.pinfo.stride); + printf(" display: %u\n", state.pinfo.display); + printf(" bpp: %u\n", state.pinfo.bpp); + + /* mmap() the framebuffer */ + + state.fbmem = mmap(NULL, state.pinfo.fblen, PROT_READ|PROT_WRITE, + MAP_SHARED|MAP_FILE, state.fd, 0); + if (state.fbmem == MAP_FAILED) + { + int errcode = errno; + fprintf(stderr, "ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n", + errcode); + close(state.fd); + return EXIT_FAILURE; + } + + printf("Mapped FB: %p\n", state.fbmem); + + munmap(state.fd, state.fbmem); + close(state.fd); + return EXIT_SUCCESS; +}