Skip to content

Commit

Permalink
examples/fb: Add a simple test for the framebuffer character driver. …
Browse files Browse the repository at this point in the history
…This initial commit just verfies some interfaces and initialization logic. Still need to add to graphics update logic.
  • Loading branch information
gregory-nutt committed Sep 12, 2017
1 parent fcf26f6 commit 8ac1952
Show file tree
Hide file tree
Showing 7 changed files with 316 additions and 1 deletion.
5 changes: 5 additions & 0 deletions examples/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^

Expand Down
1 change: 0 additions & 1 deletion examples/adc/adc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions examples/fb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/Make.dep
/.depend
/.built
/*.asm
/*.obj
/*.rel
/*.lst
/*.sym
/*.adb
/*.lib
/*.src
38 changes: 38 additions & 0 deletions examples/fb/Kconfig
Original file line number Diff line number Diff line change
@@ -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 changes: 39 additions & 0 deletions examples/fb/Make.defs
Original file line number Diff line number Diff line change
@@ -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 changes: 56 additions & 0 deletions examples/fb/Makefile
Original file line number Diff line number Diff line change
@@ -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 changes: 167 additions & 0 deletions examples/fb/fb_main.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 8ac1952

Please sign in to comment.