2018-02-22 02:17:28 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* 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"
|
|
|
|
|
2018-02-22 13:30:54 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define HALF_SECOND (500 * 1000) /* 500 milliseconds (units = microseconds) */
|
|
|
|
#define FIVE_SECONDS (5 * 2) /* 5 seconds (units = half seconds) */
|
|
|
|
|
2018-02-22 02:17:28 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-02-22 17:01:50 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: ft80x_coproc_send
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Send commands to the co-processor via the CMD RAM FIFO. This function
|
|
|
|
* will not return until the command has been consumed by the co-processor.
|
|
|
|
*
|
|
|
|
* NOTE: This command is not appropriate use while a display is being
|
|
|
|
* formed. It is will mess up the CMD RAM FIFO offsets managed by the
|
|
|
|
* display list logic.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-02-26 16:58:52 +01:00
|
|
|
* fd - The file descriptor of the FT80x device. Opened by the caller
|
|
|
|
* with write access.
|
|
|
|
* cmds - A list of 32-bit commands to be sent.
|
|
|
|
* ncmds - The number of commands in the list.
|
2018-02-22 17:01:50 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) on success. A negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int ft80x_coproc_send(int fd, FAR const uint32_t *cmds, size_t ncmds)
|
|
|
|
{
|
2018-02-26 03:26:24 +01:00
|
|
|
return ft80x_ramcmd_append(fd, cmds, ncmds << 2);
|
2018-02-22 17:01:50 +01:00
|
|
|
}
|
|
|
|
|
2018-02-22 02:17:28 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* 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:
|
2018-02-26 16:58:52 +01:00
|
|
|
* fd - The file descriptor of the FT80x device. Opened by the caller
|
|
|
|
* with write access.
|
2018-02-22 02:17:28 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) on success. A negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int ft80x_coproc_waitlogo(int fd)
|
|
|
|
{
|
2018-02-22 17:01:50 +01:00
|
|
|
uint32_t regs[2];
|
2018-02-22 02:17:28 +01:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2018-02-22 13:30:54 +01:00
|
|
|
for (elapsed = 0; elapsed < FIVE_SECONDS; elapsed++)
|
2018-02-22 02:17:28 +01:00
|
|
|
{
|
2018-02-22 17:01:50 +01:00
|
|
|
/* Read both the FT80X_REG_CMD_WRITE and FT80X_REG_CMD_READ registers. */
|
2018-02-22 02:17:28 +01:00
|
|
|
|
2018-02-22 17:01:50 +01:00
|
|
|
ret = ft80x_getregs(fd, FT80X_REG_CMD_READ, 2, regs);
|
2018-02-22 02:17:28 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2018-02-22 17:01:50 +01:00
|
|
|
ft80x_err("ERROR: ft80x_getregs failed: %d\n", ret);
|
2018-02-22 02:17:28 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-22 17:01:50 +01:00
|
|
|
/* Check if both have been reset to zero. */
|
2018-02-22 02:17:28 +01:00
|
|
|
|
2018-02-22 17:01:50 +01:00
|
|
|
head = regs[1] & FT80X_CMDFIFO_MASK;
|
|
|
|
tail = regs[0] & FT80X_CMDFIFO_MASK;
|
2018-02-22 02:17:28 +01:00
|
|
|
|
2018-02-22 17:01:50 +01:00
|
|
|
if (head == 0 && tail == 0)
|
|
|
|
{
|
|
|
|
/* The animation is done! */
|
2018-02-22 02:17:28 +01:00
|
|
|
|
2018-02-22 17:01:50 +01:00
|
|
|
return OK;
|
2018-02-22 02:44:08 +01:00
|
|
|
}
|
2018-02-22 02:17:28 +01:00
|
|
|
|
2018-02-22 17:01:50 +01:00
|
|
|
/* Wait for a half of a second */
|
2018-02-22 02:17:28 +01:00
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
usleep(HALF_SECOND);
|
2018-02-22 02:17:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ft80x_err("ERROR: Timed out! Last head/tail = %u/%u\n", head, tail);
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|