2018-02-18 23:54:11 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* examples/ft80x/ft80x_main.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 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 <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <nuttx/lcd/ft80x.h>
|
|
|
|
|
|
|
|
#include "graphics/ft80x.h"
|
|
|
|
#include "ft80x.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct ft80x_exampleinfo_s
|
|
|
|
{
|
|
|
|
FAR const char *name;
|
|
|
|
ft80x_example_t func;
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-03-09 19:31:29 +01:00
|
|
|
#ifdef CONFIG_EXAMPLES_FT80X_PRIMITIVES
|
2018-02-19 23:32:33 +01:00
|
|
|
/* GPU Primitive display examples. Most primitives are used, but not many of
|
|
|
|
* their various options.
|
2018-02-20 22:23:05 +01:00
|
|
|
*
|
|
|
|
* FUNCTION PRIMITIVE USED DESCRIPTION
|
|
|
|
* ---------------------- --------------- ----------------------------------
|
|
|
|
* ft80x_prim_bitmaps BITMAPS Bitmap drawing primitive
|
|
|
|
* ft80x_prim_points POINTS Point drawing primitive
|
|
|
|
* ft80x_prim_lines LINES Line drawing primitive
|
|
|
|
* ft80x_prim_linestrip LINE_STRIP Line strip drawing primitive
|
|
|
|
* ft80x_prim_edgestrip_r EDGE_STRIP_R Edge strip right side drawing
|
|
|
|
primitive
|
2018-02-22 17:01:50 +01:00
|
|
|
* (To be provided) EDGE_STRIP_L Edge strip left side drawing
|
2018-02-20 22:23:05 +01:00
|
|
|
primitive
|
2018-02-22 17:01:50 +01:00
|
|
|
* (To be provided) EDGE_STRIP_A Edge strip above side drawing
|
2018-02-20 22:23:05 +01:00
|
|
|
primitive
|
2018-02-22 17:01:50 +01:00
|
|
|
* (To be provided) EDGE_STRIP_B Edge strip below side drawing
|
2018-02-20 22:23:05 +01:00
|
|
|
primitive
|
|
|
|
* ft80x_prim_rectangles RECTS Rectangle drawing primitive
|
2018-02-22 02:17:28 +01:00
|
|
|
* ft80x_prim_scissor SCISSOR Scissor primitive
|
2018-02-26 22:26:11 +01:00
|
|
|
* ft80x_prim_stencil STENCIL Stencil primitives
|
2018-02-22 02:17:28 +01:00
|
|
|
* ft80x_prim_alphablend COLOR_A Additive blend
|
2018-02-19 23:32:33 +01:00
|
|
|
*/
|
|
|
|
|
2018-02-18 23:54:11 +01:00
|
|
|
static const struct ft80x_exampleinfo_s g_primitives[] =
|
|
|
|
{
|
2018-02-19 20:14:16 +01:00
|
|
|
#ifndef CONFIG_EXAMPLES_FT80X_EXCLUDE_BITMAPS
|
2018-02-20 22:23:05 +01:00
|
|
|
{ "Bitmaps", ft80x_prim_bitmaps },
|
2018-02-19 20:14:16 +01:00
|
|
|
#endif
|
2018-02-20 22:23:05 +01:00
|
|
|
{ "Points", ft80x_prim_points },
|
|
|
|
{ "Lines", ft80x_prim_lines },
|
|
|
|
{ "Line Strip", ft80x_prim_linestrip },
|
|
|
|
{ "Edge Strip R", ft80x_prim_edgestrip_r },
|
2018-02-22 02:17:28 +01:00
|
|
|
{ "Rectangles", ft80x_prim_rectangles },
|
|
|
|
{ "Scissor", ft80x_prim_scissor },
|
2018-02-26 22:26:11 +01:00
|
|
|
{ "Stencil", ft80x_prim_stencil },
|
2018-02-22 02:17:28 +01:00
|
|
|
{ "Alpha Blend", ft80x_prim_alphablend }
|
2018-02-18 23:54:11 +01:00
|
|
|
};
|
|
|
|
|
2018-03-09 19:31:29 +01:00
|
|
|
#define NPRIMITIVES (sizeof(g_primitives) / sizeof(struct ft80x_exampleinfo_s))
|
|
|
|
#endif /* CONFIG_EXAMPLES_FT80X_PRIMITIVES */
|
2018-02-18 23:54:11 +01:00
|
|
|
|
2018-02-19 23:32:33 +01:00
|
|
|
/* Co-processor display examples. Only a small, but interesting, subset
|
|
|
|
* here co-processor command are exercised and these with only a few of the
|
|
|
|
* possible options.
|
2018-02-20 22:23:05 +01:00
|
|
|
*
|
2018-02-21 01:46:17 +01:00
|
|
|
* FUNCTION CoProc CMD USED DESCRIPTION
|
|
|
|
* ------------------------ --------------- ----------------------------------
|
2018-02-21 22:42:47 +01:00
|
|
|
* ft80x_coproc_button CMD_BUTTON Draw a button
|
2018-02-22 19:30:58 +01:00
|
|
|
* ft80x_coproc_clock CMD_CLOCK Draw an analog clock
|
|
|
|
* ft80x_coproc_gauge CMD_GAUGE Draw a gauge
|
2018-02-22 20:20:00 +01:00
|
|
|
* ft80x_coproc_keys CMD_KEYS Draw a row of keys
|
2018-02-25 18:45:56 +01:00
|
|
|
* ft80x_coproc_interactive CMD_KEYS Interactive keys
|
2018-02-20 22:23:05 +01:00
|
|
|
* ft80x_coproc_progressbar CMD_PROGRESS Draw a progress bar
|
2018-02-21 01:46:17 +01:00
|
|
|
* ft80x_coproc_scrollbar CMD_SCROLLBAR Draw a scroll bar
|
2018-02-21 18:50:06 +01:00
|
|
|
* ft80x_coproc_slider CMD_SLIDER Draw a slider
|
|
|
|
* ft80x_coproc_dial CMD_DIAL Draw a rotary dial control
|
|
|
|
* ft80x_coproc_toggle CMD_TOGGLE Draw a toggle switch
|
2018-02-21 22:42:47 +01:00
|
|
|
* ft80x_coproc_number CMD_NUMBER Draw a decimal number
|
2018-02-21 18:50:06 +01:00
|
|
|
* ft80x_coproc_calibrate CMD_CALIBRATE Execute the touch screen
|
2018-02-21 01:46:17 +01:00
|
|
|
calibration routine
|
2018-02-22 17:01:50 +01:00
|
|
|
* ft80x_coproc_spinner CMD_SPINNER Start an animated spinner
|
2018-02-23 01:43:18 +01:00
|
|
|
* ft80x_coproc_screensaver CMD_SCREENSAVER Start an animated screensaver
|
2018-02-22 17:01:50 +01:00
|
|
|
* (To be provided) CMD_SKETCH Start a continuous sketch update
|
|
|
|
* (To be provided) CMD_SNAPSHOT Take a snapshot of the current
|
2018-02-21 01:46:17 +01:00
|
|
|
screen
|
2018-02-22 02:17:28 +01:00
|
|
|
* ft80x_coproc_logo CMD_LOGO Play device log animation
|
2018-02-19 23:32:33 +01:00
|
|
|
*/
|
|
|
|
|
2018-02-20 22:23:05 +01:00
|
|
|
static const struct ft80x_exampleinfo_s g_coproc[] =
|
|
|
|
{
|
2018-03-09 19:31:29 +01:00
|
|
|
{ "Calibrate", ft80x_coproc_calibrate }, /* Need to calibrate before Interactive. */
|
2018-02-21 21:32:20 +01:00
|
|
|
{ "Button", ft80x_coproc_button },
|
2018-02-22 19:30:58 +01:00
|
|
|
{ "Clock", ft80x_coproc_clock },
|
|
|
|
{ "Gauge", ft80x_coproc_gauge },
|
2018-02-22 20:20:00 +01:00
|
|
|
{ "Keys", ft80x_coproc_keys },
|
2018-03-10 17:29:10 +01:00
|
|
|
{ "Interactive", ft80x_coproc_interactive }, /* Too long!!! */
|
2018-02-21 01:46:17 +01:00
|
|
|
{ "Progress Bar", ft80x_coproc_progressbar },
|
2018-02-21 18:50:06 +01:00
|
|
|
{ "Scroll Bar", ft80x_coproc_scrollbar },
|
|
|
|
{ "Slider", ft80x_coproc_slider },
|
|
|
|
{ "Dial", ft80x_coproc_dial },
|
|
|
|
{ "Toggle", ft80x_coproc_toggle },
|
2018-02-21 22:42:47 +01:00
|
|
|
{ "Number", ft80x_coproc_number },
|
2018-02-22 17:01:50 +01:00
|
|
|
{ "Spinner", ft80x_coproc_spinner },
|
2018-02-24 19:09:15 +01:00
|
|
|
#ifndef CONFIG_EXAMPLES_FT80X_EXCLUDE_BITMAPS
|
2018-02-23 01:43:18 +01:00
|
|
|
{ "Screen Saver", ft80x_coproc_screensaver },
|
2018-02-24 19:09:15 +01:00
|
|
|
#endif
|
2018-02-25 18:45:56 +01:00
|
|
|
{ "Logo", ft80x_coproc_logo }
|
2018-02-20 22:23:05 +01:00
|
|
|
};
|
|
|
|
|
2018-03-09 19:31:29 +01:00
|
|
|
#define NCOPROC (sizeof(g_coproc) / sizeof(struct ft80x_exampleinfo_s))
|
2018-02-19 23:32:33 +01:00
|
|
|
|
2018-02-18 23:54:11 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: ft80x_showname
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Show the name of the test
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int ft80x_showname(int fd, FAR struct ft80x_dlbuffer_s *buffer,
|
|
|
|
FAR const char *name)
|
|
|
|
{
|
2018-02-23 22:40:44 +01:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct ft80x_cmd32_s clearrgb;
|
|
|
|
struct ft80x_cmd32_s clear;
|
|
|
|
struct ft80x_cmd32_s colorrgb;
|
|
|
|
struct ft80x_cmd_text_s text;
|
|
|
|
} cmds;
|
|
|
|
|
2018-02-18 23:54:11 +01:00
|
|
|
int ret;
|
|
|
|
|
2018-02-23 17:49:38 +01:00
|
|
|
/* Mkae sure that the backlight off */
|
|
|
|
|
|
|
|
(void)ft80x_backlight_set(fd, 0);
|
|
|
|
|
2018-02-18 23:54:11 +01:00
|
|
|
/* Create the display list */
|
|
|
|
|
2018-03-09 22:51:55 +01:00
|
|
|
ret = ft80x_dl_start(fd, buffer, true);
|
2018-02-18 23:54:11 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ft80x_err("ERROR: ft80x_dl_start failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-23 22:40:44 +01:00
|
|
|
/* Clear the display */
|
|
|
|
|
|
|
|
cmds.clearrgb.cmd = FT80X_CLEAR_COLOR_RGB(0, 0, 0x80);
|
|
|
|
cmds.clear.cmd = FT80X_CLEAR(1 ,1, 1);
|
|
|
|
cmds.colorrgb.cmd = FT80X_COLOR_RGB(0xff, 0xff, 0xff);
|
|
|
|
|
|
|
|
/* Use the CMD_TEXT co-processor command to show the name of the next
|
|
|
|
* example at the center of the display.
|
|
|
|
*/
|
2018-02-18 23:54:11 +01:00
|
|
|
|
2018-02-23 22:40:44 +01:00
|
|
|
cmds.text.cmd = FT80X_CMD_TEXT;
|
|
|
|
cmds.text.x = FT80X_DISPLAY_WIDTH / 2;
|
|
|
|
cmds.text.y = FT80X_DISPLAY_HEIGHT / 2;
|
|
|
|
cmds.text.font = 31;
|
|
|
|
cmds.text.options = FT80X_OPT_CENTER;
|
2018-02-18 23:54:11 +01:00
|
|
|
|
2018-02-23 22:40:44 +01:00
|
|
|
ret = ft80x_dl_data(fd, buffer, &cmds, sizeof(cmds));
|
2018-02-18 23:54:11 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ft80x_dl_string(fd, buffer, name);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ft80x_err("ERROR: ft80x_dl_string failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And terminate the display list */
|
|
|
|
|
|
|
|
ret = ft80x_dl_end(fd, buffer);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ft80x_err("ERROR: ft80x_dl_end failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-23 22:40:44 +01:00
|
|
|
/* Fade on then wait bit so that the user can read the example name */
|
2018-02-18 23:54:11 +01:00
|
|
|
|
2018-03-09 22:51:55 +01:00
|
|
|
(void)ft80x_backlight_fade(fd, 100, 2000);
|
2018-02-23 17:49:38 +01:00
|
|
|
(void)sleep(1);
|
2018-02-18 23:54:11 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: ft80x_example
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Execute one example
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int ft80x_example(int fd, FAR struct ft80x_dlbuffer_s *buffer,
|
|
|
|
FAR const struct ft80x_exampleinfo_s *example)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2018-02-21 01:46:17 +01:00
|
|
|
ft80x_info("Example %s\n", example->name);
|
|
|
|
|
2018-02-18 23:54:11 +01:00
|
|
|
/* Show the name of the example */
|
|
|
|
|
|
|
|
ret = ft80x_showname(fd, buffer, example->name);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ft80x_err("ERROR: ft80x_showname failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-23 17:49:38 +01:00
|
|
|
/* Then execute the example */
|
2018-02-18 23:54:11 +01:00
|
|
|
|
|
|
|
ret = example->func(fd, buffer);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ft80x_err("ERROR: \"%s\" example failed: %d\n", example->name, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-23 17:49:38 +01:00
|
|
|
/* Wait a bit, then fade out */
|
2018-02-18 23:54:11 +01:00
|
|
|
|
2018-03-09 22:51:55 +01:00
|
|
|
sleep(2);
|
|
|
|
(void)ft80x_backlight_fade(fd, 0, 2000);
|
2018-02-18 23:54:11 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* ft80x_main
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int main(int argc, FAR char *argv[])
|
|
|
|
{
|
|
|
|
FAR struct ft80x_dlbuffer_s *buffer;
|
|
|
|
int fd;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Open the configured FT80x device */
|
|
|
|
|
2018-02-19 20:14:16 +01:00
|
|
|
fd = open(CONFIG_EXAMPLES_FT80X_DEVPATH, O_WRONLY);
|
2018-02-18 23:54:11 +01:00
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
ft80x_err("ERROR: Failed to open %s: %d\n",
|
2018-02-19 20:14:16 +01:00
|
|
|
CONFIG_EXAMPLES_FT80X_DEVPATH, errcode);
|
2018-02-18 23:54:11 +01:00
|
|
|
UNUSED(errcode);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate the display list buffer structure */
|
|
|
|
|
|
|
|
buffer = (FAR struct ft80x_dlbuffer_s *)
|
|
|
|
malloc(sizeof(struct ft80x_dlbuffer_s));
|
|
|
|
|
|
|
|
if (buffer == NULL)
|
|
|
|
{
|
|
|
|
ft80x_err("ERROR: Failed to allocate display list buffer\n");
|
|
|
|
close(fd);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2018-03-09 19:31:29 +01:00
|
|
|
#ifdef CONFIG_EXAMPLES_FT80X_PRIMITIVES
|
2018-02-18 23:54:11 +01:00
|
|
|
/* Perform tests on a few of the FT80x primitive functions */
|
|
|
|
|
2018-02-21 01:46:17 +01:00
|
|
|
ft80x_info("FT80x Primitive Functions\n");
|
|
|
|
|
2018-02-18 23:54:11 +01:00
|
|
|
for (i = 0; i < NPRIMITIVES; i++)
|
|
|
|
{
|
|
|
|
(void)ft80x_example(fd, buffer, &g_primitives[i]);
|
|
|
|
}
|
2018-03-09 19:31:29 +01:00
|
|
|
#endif
|
2018-02-18 23:54:11 +01:00
|
|
|
|
|
|
|
/* Perform tests on a few of the FT80x Co-processor functions */
|
2018-02-20 22:23:05 +01:00
|
|
|
|
2018-02-21 01:46:17 +01:00
|
|
|
ft80x_info("FT80x Co-processor Functions\n");
|
|
|
|
|
2018-02-20 22:23:05 +01:00
|
|
|
for (i = 0; i < NCOPROC; i++)
|
|
|
|
{
|
|
|
|
(void)ft80x_example(fd, buffer, &g_coproc[i]);
|
|
|
|
}
|
2018-02-18 23:54:11 +01:00
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
close(fd);
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|