forked from apache/nuttx-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
fcf26f6
commit 8ac1952
Showing
7 changed files
with
316 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |