examples/fb: Add a simple test for the framebuffer character driver. This initial commit just verfies some interfaces and initialization logic. Still need to add to graphics update logic.
This commit is contained in:
parent
fcf26f6bd7
commit
8ac1952d4c
@ -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
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -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);
|
||||
|
11
examples/fb/.gitignore
vendored
Normal file
11
examples/fb/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
examples/fb/Kconfig
Normal file
38
examples/fb/Kconfig
Normal file
@ -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
|
39
examples/fb/Make.defs
Normal file
39
examples/fb/Make.defs
Normal file
@ -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 <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_FB),y)
|
||||
CONFIGURED_APPS += examples/fb
|
||||
endif
|
56
examples/fb/Makefile
Normal file
56
examples/fb/Makefile
Normal file
@ -0,0 +1,56 @@
|
||||
############################################################################
|
||||
# apps/examples/fb/Makefile
|
||||
#
|
||||
# Copyright (C) 2017 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
|
||||
|
||||
# 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
|
167
examples/fb/fb_main.c
Normal file
167
examples/fb/fb_main.c
Normal file
@ -0,0 +1,167 @@
|
||||
/****************************************************************************
|
||||
* examples/fb/fb_main.c
|
||||
*
|
||||
* Copyright (C) 2017 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/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/video/fb.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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 [<fb-driver-path>]\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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user