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-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
|
|
|
|
* 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 },
|
|
|
|
{ "Alpha Blend", ft80x_prim_alphablend }
|
2018-02-18 23:54:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NPRIMITIVES (sizeof(g_primitives) / sizeof(ft80x_example_t))
|
|
|
|
|
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-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-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-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 02:17:28 +01:00
|
|
|
{ "Calibrate", ft80x_coproc_calibrate },
|
2018-02-22 17:01:50 +01:00
|
|
|
{ "Spinner", ft80x_coproc_spinner },
|
2018-02-23 01:43:18 +01:00
|
|
|
{ "Screen Saver", ft80x_coproc_screensaver },
|
2018-02-22 02:17:28 +01:00
|
|
|
{ "Logo", ft80x_coproc_logo }
|
2018-02-20 22:23:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NCOPROC (sizeof(g_primitives) / sizeof(ft80x_example_t))
|
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)
|
|
|
|
{
|
|
|
|
struct ft80x_cmd_text_s text;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Create the display list */
|
|
|
|
|
2018-02-20 22:23:05 +01:00
|
|
|
ret = ft80x_dl_start(fd, buffer, false);
|
2018-02-18 23:54:11 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ft80x_err("ERROR: ft80x_dl_start failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use the CMD_TEXT co-processor command */
|
|
|
|
|
|
|
|
text.cmd = FT80X_CMD_TEXT;
|
|
|
|
text.x = 80;
|
|
|
|
text.y = 60;
|
|
|
|
text.font = 31;
|
|
|
|
text.options = FT80X_OPT_CENTER;
|
|
|
|
|
|
|
|
ret = ft80x_dl_data(fd, buffer, &text, sizeof(struct ft80x_cmd_text_s));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait bit so that the user can read the name */
|
|
|
|
|
|
|
|
sleep(2);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then executte the example */
|
|
|
|
|
|
|
|
ret = example->func(fd, buffer);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ft80x_err("ERROR: \"%s\" example failed: %d\n", example->name, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait a bit */
|
|
|
|
|
|
|
|
sleep(4);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* ft80x_main
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_BUILD_KERNEL
|
|
|
|
int main(int argc, FAR char *argv[])
|
|
|
|
#else
|
|
|
|
int ft80x_main(int argc, char *argv[])
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|