apps/graphics/ft80x: Add routine to wait for logo animation to complete. apps/examples/ft80x: Add more graphic demonstrations.

This commit is contained in:
Gregory Nutt 2018-02-21 19:17:28 -06:00
parent a7356b34de
commit 2436e3f85a
7 changed files with 278 additions and 5 deletions

View File

@ -148,6 +148,8 @@ int ft80x_prim_lines(int fd, FAR struct ft80x_dlbuffer_s *buffer);
int ft80x_prim_linestrip(int fd, FAR struct ft80x_dlbuffer_s *buffer);
int ft80x_prim_edgestrip_r(int fd, FAR struct ft80x_dlbuffer_s *buffer);
int ft80x_prim_rectangles(int fd, FAR struct ft80x_dlbuffer_s *buffer);
int ft80x_prim_scissor(int fd, FAR struct ft80x_dlbuffer_s *buffer);
int ft80x_prim_alphablend(int fd, FAR struct ft80x_dlbuffer_s *buffer);
/* Co-processor display examples */
@ -159,6 +161,7 @@ int ft80x_coproc_dial(int fd, FAR struct ft80x_dlbuffer_s *buffer);
int ft80x_coproc_toggle(int fd, FAR struct ft80x_dlbuffer_s *buffer);
int ft80x_coproc_number(int fd, FAR struct ft80x_dlbuffer_s *buffer);
int ft80x_coproc_calibrate(int fd, FAR struct ft80x_dlbuffer_s *buffer);
int ft80x_coproc_logo(int fd, FAR struct ft80x_dlbuffer_s *buffer);
#undef EXTERN
#ifdef __cplusplus

View File

@ -2222,3 +2222,50 @@ int ft80x_coproc_calibrate(int fd, FAR struct ft80x_dlbuffer_s *buffer)
matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
return OK;
}
/****************************************************************************
* Name: ft80x_coproc_logo
*
* Description:
* Demonstrate the logo command. The logo command causes the co-processor
* engine to play back a short animation of the FTDI logo. During logo
* playback the MCU should not access any FT800 resources.
*
****************************************************************************/
int ft80x_coproc_logo(int fd, FAR struct ft80x_dlbuffer_s *buffer)
{
struct ft80x_cmd_logo_s logo;
int ret;
/* Enqueue the command (no display list is used) */
logo.cmd = FT80X_CMD_LOGO;
ret = ft80x_dl_data(fd, buffer, &logo, sizeof(struct ft80x_cmd_logo_s));
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret;
}
/* Flush the command to hardware */
ret = ft80x_dl_flush(fd, buffer);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_flush failed: %d\n", ret);
return ret;
}
/* Wait for the logo animation to complete. */
ret = ft80x_coproc_waitlogo(fd);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_coproc_waitlogo failed: %d\n", ret);
}
return ret;
}

View File

@ -82,6 +82,8 @@ struct ft80x_exampleinfo_s
* --None-- EDGE_STRIP_B Edge strip below side drawing
primitive
* ft80x_prim_rectangles RECTS Rectangle drawing primitive
* ft80x_prim_scissor SCISSOR Scissor primitive
* ft80x_prim_alphablend COLOR_A Additive blend
*/
static const struct ft80x_exampleinfo_s g_primitives[] =
@ -93,7 +95,9 @@ static const struct ft80x_exampleinfo_s g_primitives[] =
{ "Lines", ft80x_prim_lines },
{ "Line Strip", ft80x_prim_linestrip },
{ "Edge Strip R", ft80x_prim_edgestrip_r },
{ "Rectangles", ft80x_prim_rectangles }
{ "Rectangles", ft80x_prim_rectangles },
{ "Scissor", ft80x_prim_scissor },
{ "Alpha Blend", ft80x_prim_alphablend }
};
#define NPRIMITIVES (sizeof(g_primitives) / sizeof(ft80x_example_t))
@ -121,7 +125,7 @@ static const struct ft80x_exampleinfo_s g_primitives[] =
* --None-- CMD_SKETCH Start a continuous sketch update
* --None-- CMD_SNAPSHOT Take a snapshot of the current
screen
* --None-- CMD_LOGO Play device log animation
* ft80x_coproc_logo CMD_LOGO Play device log animation
*/
static const struct ft80x_exampleinfo_s g_coproc[] =
@ -133,7 +137,8 @@ static const struct ft80x_exampleinfo_s g_coproc[] =
{ "Dial", ft80x_coproc_dial },
{ "Toggle", ft80x_coproc_toggle },
{ "Number", ft80x_coproc_number },
{ "Calibrate", ft80x_coproc_calibrate }
{ "Calibrate", ft80x_coproc_calibrate },
{ "Logo", ft80x_coproc_logo }
};
#define NCOPROC (sizeof(g_primitives) / sizeof(ft80x_example_t))

View File

@ -367,3 +367,68 @@ int ft80x_prim_rectangles(int fd, FAR struct ft80x_dlbuffer_s *buffer)
return OK;
}
/****************************************************************************
* Name: ft80x_prim_scissor
*
* Description:
* Demonstrate the scissor primitive
*
****************************************************************************/
int ft80x_prim_scissor(int fd, FAR struct ft80x_dlbuffer_s *buffer)
{
uint32_t cmds[5];
int ret;
cmds[0] = FT80X_CLEAR(1, 1, 1); /* Clear to black */
cmds[1] = FT80X_SCISSOR_XY(40, 20); /* Scissor rectangle top left at (40, 20) */
cmds[2] = FT80X_SCISSOR_SIZE(40, 40); /* Scissor rectangle is 40 x 40 pixels */
cmds[3] = FT80X_CLEAR_COLOR_RGB(255, 255, 0); /* Clear to yellow */
cmds[4] = FT80X_CLEAR(1, 1, 1);
/* Create the hardware display list */
ret = ft80x_dl_create(fd, buffer, cmds, 5, false);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_create failed: %d\n", ret);
return ret;
}
return OK;
}
/****************************************************************************
* Name: ft80x_prim_alphablend
*
* Description:
* Demonstrate additive blend
*
****************************************************************************/
int ft80x_prim_alphablend(int fd, FAR struct ft80x_dlbuffer_s *buffer)
{
uint32_t cmds[8];
int ret;
cmds[0] = FT80X_CLEAR(1, 1, 1); /* Clear screen */
cmds[1] = FT80X_BEGIN(FT80X_PRIM_BITMAPS);
cmds[2] = FT80X_VERTEX2II(50, 30, 31, 0x47);
cmds[3] = FT80X_COLOR_A(128);
cmds[4] = FT80X_VERTEX2II(58, 38, 31, 0x47);
cmds[5] = FT80X_COLOR_A(64);
cmds[6] = FT80X_VERTEX2II(66, 46, 31, 0x47);
cmds[7] = FT80X_END();
/* Create the hardware display list */
ret = ft80x_dl_create(fd, buffer, cmds, 8, false);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_create failed: %d\n", ret);
return ret;
}
return OK;
}

View File

@ -40,8 +40,8 @@ include $(APPDIR)/Make.defs
# FTDI/BridgeTek FT80x library
ASRCS =
CSRCS = ft80x_dl.c ft80x_ramg.c ft80x_ramdl.c ft80x_ramcmd.c ft80x_touch.c
CSRCS += ft80x_regs.c
CSRCS = ft80x_dl.c ft80x_ramg.c ft80x_ramdl.c ft80x_ramcmd.c ft80x_coproc.c
CSRCS += ft80x_touch.c ft80x_regs.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))

View File

@ -0,0 +1,130 @@
/****************************************************************************
* apps/graphics/ft80x/ft80x_coproc.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 <sys/ioctl.h>
#include <stdint.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#include <nuttx/lcd/ft80x.h>
#include "graphics/ft80x.h"
#include "ft80x.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: ft80x_coproc_waitlogo
*
* Description:
* Wait for the logo animation to complete. The logo command causes the
* co-processor engine to play back a short animation of the FTDI logo.
* During logo playback the MCU should not access any FT800 resources.
* After 2.5 seconds have elapsed, the co-processor engine writes zero to
* REG_CMD_READ and REG_CMD_WRITE, and starts waiting for commands. After
* this command is complete, the MCU shall write the next command to the
* starting address of RAM_CMD.
*
* Input Parameters:
* fd - The file descriptor of the FT80x device. Opened by the caller
* with write access.
*
* Returned Value:
* Zero (OK) on success. A negated errno value on failure.
*
****************************************************************************/
int ft80x_coproc_waitlogo(int fd)
{
uint16_t head;
uint16_t tail;
int elapsed;
int ret;
/* Loop until both REG_CMD_READ and REG_CMD_WRITE are zero or until 5
* seconds elapses.
*/
for (elapsed = 0; elapsed < 10; elapsed++)
{
/* Read REG_CMD_WRITE */
ret = ft80x_getreg16(fd, FT80X_REG_CMD_WRITE, &head);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_getreg16 failed: %d\n", ret);
return ret;
}
/* Check if FT80X_REG_CMD_WRITE is zero */
if (head == 0)
{
/* Read REG_CMD_READ */
ret = ft80x_getreg16(fd, FT80X_REG_CMD_READ, &tail);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_getreg16 failed: %d\n", ret);
return ret;
}
/* If REG_CMD_READ is also zero, then we are done */
if (tail == 0)
{
/* The animation is done! */
return OK;
}
/* Wait for a half a second */
(void)usleep(500 * 1000 * 1000);
}
}
ft80x_err("ERROR: Timed out! Last head/tail = %u/%u\n", head, tail);
return -ETIMEDOUT;
}

View File

@ -238,6 +238,29 @@ int ft80x_dl_create(int fd, FAR struct ft80x_dlbuffer_s *buffer,
FAR const uint32_t *cmds, unsigned int nwords,
bool coproc);
/****************************************************************************
* Name: ft80x_coproc_waitlogo
*
* Description:
* Wait for the logo animation to complete. The logo command causes the
* co-processor engine to play back a short animation of the FTDI logo.
* During logo playback the MCU should not access any FT800 resources.
* After 2.5 seconds have elapsed, the co-processor engine writes zero to
* REG_CMD_READ and REG_CMD_WRITE, and starts waiting for commands. After
* this command is complete, the MCU shall write the next command to the
* starting address of RAM_CMD.
*
* Input Parameters:
* fd - The file descriptor of the FT80x device. Opened by the caller
* with write access.
*
* Returned Value:
* Zero (OK) on success. A negated errno value on failure.
*
****************************************************************************/
int ft80x_coproc_waitlogo(int fd);
/****************************************************************************
* Name: ft80x_ramg_write
*