apps/graphics/ft80x: Add register access helpers.
This commit is contained in:
parent
7d245e4b79
commit
5dd5908d86
@ -40,7 +40,7 @@ include $(APPDIR)/Make.defs
|
||||
# FTDI/BridgeTek FT80x library
|
||||
|
||||
ASRCS =
|
||||
CSRCS = ft80x_dl.c
|
||||
CSRCS = ft80x_dl.c ft80x_regs.c
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <debug.h>
|
||||
|
||||
#ifdef CONFIG_GRAPHICS_FT80X
|
||||
@ -113,6 +114,65 @@ extern "C"
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ft80x_getreg8/16/32
|
||||
*
|
||||
* Description:
|
||||
* Read an 8-, 16-, or 32-bit FT80x register value.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fd - The file descriptor of the FT80x device. Opened by the caller
|
||||
* with write access.
|
||||
* addr - The 32-bit aligned, 22-bit register value
|
||||
* value - The location to return the register value
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success. A negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int ft80x_getreg8(int fd, uint32_t addr, FAR uint8_t *value);
|
||||
int ft80x_getreg16(int fd, uint32_t addr, FAR uint16_t *value);
|
||||
int ft80x_getreg32(int fd, uint32_t addr, FAR uint16_t *value);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ft80x_putreg8/16/32
|
||||
*
|
||||
* Description:
|
||||
* Wtite an 8-, 16-, or 32-bit FT80x register value.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fd - The file descriptor of the FT80x device. Opened by the caller
|
||||
* with write access.
|
||||
* addr - The 32-bit aligned, 22-bit register value
|
||||
* value - The register value to write.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success. A negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int ft80x_putreg8(int fd, uint32_t addr, uint8_t value);
|
||||
int ft80x_putreg16(int fd, uint32_t addr, uint16_t value);
|
||||
int ft80x_putreg32(int fd, uint32_t addr, uint32_t value);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ft80x_dl_swap
|
||||
*
|
||||
* Description:
|
||||
* Perform the display swap operation.
|
||||
*
|
||||
* 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_dl_swap(int fd);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/lcd/ft80x.h>
|
||||
@ -50,8 +51,6 @@
|
||||
#include "graphics/ft80x.h"
|
||||
#include "ft80x.h"
|
||||
|
||||
#ifdef CONFIG_GRAPHICS_FT80X
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@ -184,10 +183,9 @@ int ft80x_dl_start(int fd, FAR struct ft80x_dlbuffer_s *buffer)
|
||||
*
|
||||
* 1) Add the DISPLAY command to the local display list buffer to finish
|
||||
* the last display
|
||||
* 2) Add the CMD_DLSWAP command to the local display list buffer to swap
|
||||
* to the newly created display list.
|
||||
* 3) Flush the local display buffer to hardware and set the display list
|
||||
* 2) Flush the local display buffer to hardware and set the display list
|
||||
* buffer offset to zero.
|
||||
* 3) Swap to the newly created display list.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fd - The file descriptor of the FT80x device. Opened by the caller
|
||||
@ -201,11 +199,7 @@ int ft80x_dl_start(int fd, FAR struct ft80x_dlbuffer_s *buffer)
|
||||
|
||||
int ft80x_dl_end(int fd, FAR struct ft80x_dlbuffer_s *buffer)
|
||||
{
|
||||
union
|
||||
{
|
||||
struct ft80x_dlcmd_s display;
|
||||
struct ft80x_cmd_swap_s swap;
|
||||
} u;
|
||||
struct ft80x_dlcmd_s display;
|
||||
int ret;
|
||||
|
||||
ft80x_info("fd=%d buffer=%p\n", fd, buffer);
|
||||
@ -215,27 +209,15 @@ int ft80x_dl_end(int fd, FAR struct ft80x_dlbuffer_s *buffer)
|
||||
* the last display
|
||||
*/
|
||||
|
||||
u.display.cmd = FT80X_DISPLAY();
|
||||
ret = ft80x_dl_data(fd, buffer, &u.display, sizeof(struct ft80x_dlcmd_s));
|
||||
display.cmd = FT80X_DISPLAY();
|
||||
ret = ft80x_dl_data(fd, buffer, &display, sizeof(struct ft80x_dlcmd_s));
|
||||
if (ret < 0)
|
||||
{
|
||||
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* 2) Add the CMD_DLSWAP command to the local display list buffer to swap
|
||||
* to the newly created display list.
|
||||
*/
|
||||
|
||||
u.swap.cmd = FT80X_CMD_SWAP;
|
||||
ret = ft80x_dl_data(fd, buffer, &u.swap, sizeof(struct ft80x_cmd_swap_s));
|
||||
if (ret < 0)
|
||||
{
|
||||
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* 3) Flush the local display buffer to hardware and set the display list
|
||||
/* 2) Flush the local display buffer to hardware and set the display list
|
||||
* buffer offset to zero.
|
||||
*/
|
||||
|
||||
@ -245,6 +227,15 @@ int ft80x_dl_end(int fd, FAR struct ft80x_dlbuffer_s *buffer)
|
||||
ft80x_err("ERROR: ft80x_dl_flush failed: %d\n", ret);
|
||||
}
|
||||
|
||||
/* 3) Swap to the newly created display list. */
|
||||
|
||||
ret = ft80x_dl_swap(fd);
|
||||
if (ret < 0)
|
||||
{
|
||||
ft80x_err("ERROR: ft80x_dl_swap failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -560,5 +551,3 @@ int ft80x_dl_flush(int fd, FAR struct ft80x_dlbuffer_s *buffer)
|
||||
buffer->dloffset = 0;
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_GRAPHICS_FT80X */
|
||||
|
266
graphics/ft80x/ft80x_regs.c
Normal file
266
graphics/ft80x/ft80x_regs.c
Normal file
@ -0,0 +1,266 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/ft80x/ft80x_regs.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/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/lcd/ft80x.h>
|
||||
|
||||
#include "ft80x.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Defitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Sleep for 10 MS between each REG_DLSWAP poll */
|
||||
|
||||
#define DLSWAP_DELAY_USEC (10 * 1000)
|
||||
|
||||
/* But timeout after 5 seconds ( 5 * 100 * 10 MS = 5 S) */
|
||||
|
||||
#define DLSWAP_TIMEOUT_CSEC (5 * 100)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ft80x_getreg8/16/32
|
||||
*
|
||||
* Description:
|
||||
* Read an 8-, 16-, or 32-bit FT80x register value.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fd - The file descriptor of the FT80x device. Opened by the caller
|
||||
* with write access.
|
||||
* addr - The 32-bit aligned, 22-bit register value
|
||||
* value - The location to return the register value
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success. A negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int ft80x_getreg8(int fd, uint32_t addr, FAR uint8_t *value)
|
||||
{
|
||||
struct ft80x_register_s reg;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(value != NULL && (addr & 3) == 0 && addr < 0xffc00000);
|
||||
|
||||
/* Perform the IOCTL to get the register value */
|
||||
|
||||
reg.addr = addr;
|
||||
ret = ioctl(fd, FT80X_IOC_GETREG8, (unsigned long)((uintptr_t)®));
|
||||
|
||||
if (ret >= 0)
|
||||
{
|
||||
*value = reg.value.u8;
|
||||
ret = OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ft80x_getreg16(int fd, uint32_t addr, FAR uint16_t *value)
|
||||
{
|
||||
struct ft80x_register_s reg;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(value != NULL && (addr & 3) == 0 && addr < 0xffc00000);
|
||||
|
||||
/* Perform the IOCTL to get the register value */
|
||||
|
||||
reg.addr = addr;
|
||||
ret = ioctl(fd, FT80X_IOC_GETREG16, (unsigned long)((uintptr_t)®));
|
||||
|
||||
if (ret >= 0)
|
||||
{
|
||||
*value = reg.value.u16;
|
||||
ret = OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ft80x_getreg32(int fd, uint32_t addr, FAR uint16_t *value)
|
||||
{
|
||||
struct ft80x_register_s reg;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(value != NULL && (addr & 3) == 0 && addr < 0xffc00000);
|
||||
|
||||
/* Perform the IOCTL to get the register value */
|
||||
|
||||
reg.addr = addr;
|
||||
ret = ioctl(fd, FT80X_IOC_GETREG32, (unsigned long)((uintptr_t)®));
|
||||
|
||||
if (ret >= 0)
|
||||
{
|
||||
*value = reg.value.u32;
|
||||
ret = OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ft80x_putreg8/16/32
|
||||
*
|
||||
* Description:
|
||||
* Wtite an 8-, 16-, or 32-bit FT80x register value.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fd - The file descriptor of the FT80x device. Opened by the caller
|
||||
* with write access.
|
||||
* addr - The 32-bit aligned, 22-bit register value
|
||||
* value - The register value to write.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success. A negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int ft80x_putreg8(int fd, uint32_t addr, uint8_t value)
|
||||
{
|
||||
struct ft80x_register_s reg;
|
||||
|
||||
DEBUGASSERT(value != NULL && (addr & 3) == 0 && addr < 0xffc00000);
|
||||
|
||||
/* Perform the IOCTL to get the register value */
|
||||
|
||||
reg.addr = addr;
|
||||
reg.value.u8 = value;
|
||||
return ioctl(fd, FT80X_IOC_PUTREG8, (unsigned long)((uintptr_t)®));
|
||||
}
|
||||
|
||||
int ft80x_putreg16(int fd, uint32_t addr, uint16_t value)
|
||||
{
|
||||
struct ft80x_register_s reg;
|
||||
|
||||
DEBUGASSERT(value != NULL && (addr & 3) == 0 && addr < 0xffc00000);
|
||||
|
||||
/* Perform the IOCTL to get the register value */
|
||||
|
||||
reg.addr = addr;
|
||||
reg.value.u16 = value;
|
||||
return ioctl(fd, FT80X_IOC_PUTREG16, (unsigned long)((uintptr_t)®));
|
||||
}
|
||||
|
||||
int ft80x_putreg32(int fd, uint32_t addr, uint32_t value)
|
||||
{
|
||||
struct ft80x_register_s reg;
|
||||
|
||||
DEBUGASSERT(value != NULL && (addr & 3) == 0 && addr < 0xffc00000);
|
||||
|
||||
/* Perform the IOCTL to get the register value */
|
||||
|
||||
reg.addr = addr;
|
||||
reg.value.u32 = value;
|
||||
return ioctl(fd, FT80X_IOC_PUTREG32, (unsigned long)((uintptr_t)®));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ft80x_dl_swap
|
||||
*
|
||||
* Description:
|
||||
* Perform the display swap operation.
|
||||
*
|
||||
* 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_dl_swap(int fd)
|
||||
{
|
||||
unsigned int timeout;
|
||||
uint8_t regval8;
|
||||
int ret;
|
||||
|
||||
/* Perform the DL swap */
|
||||
|
||||
ret = ft80x_putreg8(fd, FT80X_REG_DLSWAP, DLSWAP_FRAME);
|
||||
if (ret < 0)
|
||||
{
|
||||
ft80x_err("ERROR: ft80x_putreg8 failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Now wait for the swap to complete */
|
||||
|
||||
timeout = 0;
|
||||
for (; ; )
|
||||
{
|
||||
/* Read REG_DLSWAP again */
|
||||
|
||||
ret = ft80x_getreg8(fd, FT80X_REG_DLSWAP, ®val8);
|
||||
if (ret < 0)
|
||||
{
|
||||
ft80x_err("ERROR: ft80x_putreg8 failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Check if the swap is complete */
|
||||
|
||||
if (regval8 == DLSWAP_DONE)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
if (++timeout > DLSWAP_TIMEOUT_CSEC)
|
||||
{
|
||||
ft80x_err("ERROR: Timed out waiting for DLSWAP to complete\n");
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
/* No.. Wait a bit and try again */
|
||||
|
||||
usleep(DLSWAP_DELAY_USEC);
|
||||
}
|
||||
}
|
@ -113,10 +113,9 @@ int ft80x_dl_start(int fd, FAR struct ft80x_dlbuffer_s *buffer);
|
||||
*
|
||||
* 1) Add the DISPLAY command to the local display list buffer to finish
|
||||
* the last display
|
||||
* 2) Add the CMD_DLSWAP command to the local display list buffer to swap
|
||||
* to the newly created display list.
|
||||
* 3) Flush the local display buffer to hardware and set the display list
|
||||
* 2) Flush the local display buffer to hardware and set the display list
|
||||
* buffer offset to zero.
|
||||
* 3) Swap to the newly created display list.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fd - The file descriptor of the FT80x device. Opened by the caller
|
||||
|
Loading…
x
Reference in New Issue
Block a user