2018-02-18 20:36:08 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/graphics/ft80x/ft80x_regs.c
|
|
|
|
*
|
2022-03-09 15:16:28 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2018-02-18 20:36:08 +01:00
|
|
|
*
|
2022-03-09 15:16:28 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-18 20:36:08 +01:00
|
|
|
*
|
2022-03-09 15:16:28 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2018-02-18 20:36:08 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-02-22 13:30:54 +01:00
|
|
|
* Pre-processor Definitions
|
2018-02-18 20:36:08 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Sleep for 10 MS between each REG_DLSWAP poll */
|
|
|
|
|
|
|
|
#define DLSWAP_DELAY_USEC (10 * 1000)
|
|
|
|
|
2022-10-08 10:31:21 +02:00
|
|
|
/* But timeout after 5 seconds (5 * 100 * 10 MS = 5 S) */
|
2018-02-18 20:36:08 +01:00
|
|
|
|
|
|
|
#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.
|
2018-02-21 18:50:06 +01:00
|
|
|
* addr - The 32-bit aligned, 22-bit register address
|
2018-02-18 20:36:08 +01:00
|
|
|
* 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)®));
|
|
|
|
|
2018-02-21 18:50:06 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
ft80x_err("ERROR: ioctl(FT80X_IOC_GETREG8) failed: %d\n", errcode);
|
|
|
|
ret = -errcode;
|
|
|
|
}
|
|
|
|
else
|
2018-02-18 20:36:08 +01:00
|
|
|
{
|
|
|
|
*value = reg.value.u8;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)®));
|
|
|
|
|
2018-02-21 18:50:06 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
ft80x_err("ERROR: ioctl(FT80X_IOC_GETREG16) failed: %d\n", errcode);
|
|
|
|
ret = -errcode;
|
|
|
|
}
|
|
|
|
else
|
2018-02-18 20:36:08 +01:00
|
|
|
{
|
|
|
|
*value = reg.value.u16;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-25 18:20:39 +01:00
|
|
|
int ft80x_getreg32(int fd, uint32_t addr, FAR uint32_t *value)
|
2018-02-18 20:36:08 +01:00
|
|
|
{
|
|
|
|
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)®));
|
|
|
|
|
2018-02-21 18:50:06 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
ft80x_err("ERROR: ioctl(FT80X_IOC_GETREG32) failed: %d\n", errcode);
|
|
|
|
ret = -errcode;
|
|
|
|
}
|
|
|
|
else
|
2018-02-18 20:36:08 +01:00
|
|
|
{
|
|
|
|
*value = reg.value.u32;
|
2018-02-21 18:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: ft80x_getregs
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read multiple 32-bit FT80x register values.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* fd - The file descriptor of the FT80x device. Opened by the caller
|
|
|
|
* with write access.
|
|
|
|
* addr - The 32-bit aligned, 22-bit start register address
|
|
|
|
* nregs - The number of registers to read.
|
|
|
|
* value - The location to return the register values
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) on success. A negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int ft80x_getregs(int fd, uint32_t addr, uint8_t nregs, FAR uint32_t *value)
|
|
|
|
{
|
|
|
|
struct ft80x_registers_s regs;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
DEBUGASSERT(value != NULL && (addr & 3) == 0 && addr < 0xffc00000);
|
|
|
|
|
|
|
|
/* Perform the IOCTL to get the register value */
|
|
|
|
|
|
|
|
regs.addr = addr;
|
|
|
|
regs.nregs = nregs;
|
|
|
|
regs.value = value;
|
|
|
|
|
|
|
|
ret = ioctl(fd, FT80X_IOC_GETREGS, (unsigned long)((uintptr_t)®s));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
ft80x_err("ERROR: ioctl(FT80X_IOC_GETREGS) failed: %d\n", errcode);
|
|
|
|
ret = -errcode;
|
2018-02-18 20:36:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2018-02-21 18:50:06 +01:00
|
|
|
* addr - The 32-bit aligned, 22-bit register address
|
2018-02-18 20:36:08 +01:00
|
|
|
* 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;
|
2018-02-21 18:50:06 +01:00
|
|
|
int ret;
|
2018-02-18 20:36:08 +01:00
|
|
|
|
2018-03-09 19:31:29 +01:00
|
|
|
DEBUGASSERT((addr & 3) == 0 && addr < 0xffc00000);
|
2018-02-18 20:36:08 +01:00
|
|
|
|
|
|
|
/* Perform the IOCTL to get the register value */
|
|
|
|
|
|
|
|
reg.addr = addr;
|
|
|
|
reg.value.u8 = value;
|
2018-02-21 18:50:06 +01:00
|
|
|
|
|
|
|
ret = ioctl(fd, FT80X_IOC_PUTREG8, (unsigned long)((uintptr_t)®));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
ft80x_err("ERROR: ioctl(FT80X_IOC_PUTREG8) failed: %d\n", errcode);
|
|
|
|
ret = -errcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2018-02-18 20:36:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int ft80x_putreg16(int fd, uint32_t addr, uint16_t value)
|
|
|
|
{
|
|
|
|
struct ft80x_register_s reg;
|
2018-02-21 18:50:06 +01:00
|
|
|
int ret;
|
2018-02-18 20:36:08 +01:00
|
|
|
|
2018-03-09 19:31:29 +01:00
|
|
|
DEBUGASSERT((addr & 3) == 0 && addr < 0xffc00000);
|
2018-02-18 20:36:08 +01:00
|
|
|
|
|
|
|
/* Perform the IOCTL to get the register value */
|
|
|
|
|
|
|
|
reg.addr = addr;
|
|
|
|
reg.value.u16 = value;
|
2018-02-21 18:50:06 +01:00
|
|
|
|
|
|
|
ret = ioctl(fd, FT80X_IOC_PUTREG16, (unsigned long)((uintptr_t)®));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
ft80x_err("ERROR: ioctl(FT80X_IOC_PUTREG16) failed: %d\n", errcode);
|
|
|
|
ret = -errcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2018-02-18 20:36:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int ft80x_putreg32(int fd, uint32_t addr, uint32_t value)
|
|
|
|
{
|
|
|
|
struct ft80x_register_s reg;
|
2018-02-21 18:50:06 +01:00
|
|
|
int ret;
|
2018-02-18 20:36:08 +01:00
|
|
|
|
2018-03-09 19:31:29 +01:00
|
|
|
DEBUGASSERT((addr & 3) == 0 && addr < 0xffc00000);
|
2018-02-18 20:36:08 +01:00
|
|
|
|
|
|
|
/* Perform the IOCTL to get the register value */
|
|
|
|
|
|
|
|
reg.addr = addr;
|
|
|
|
reg.value.u32 = value;
|
2018-02-21 18:50:06 +01:00
|
|
|
|
|
|
|
ret = ioctl(fd, FT80X_IOC_PUTREG32, (unsigned long)((uintptr_t)®));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
ft80x_err("ERROR: ioctl(FT80X_IOC_PUTREG32) failed: %d\n", errcode);
|
|
|
|
ret = -errcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: ft80x_putregs
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Write multiple 32-bit FT80x register values.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* fd - The file descriptor of the FT80x device. Opened by the caller
|
|
|
|
* with write access.
|
|
|
|
* addr - The 32-bit aligned, 22-bit start register address
|
|
|
|
* nregs - The number of registers to write.
|
|
|
|
* value - The of the register values to be written.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) on success. A negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int ft80x_putregs(int fd, uint32_t addr, uint8_t nregs,
|
|
|
|
FAR const uint32_t *value)
|
|
|
|
{
|
|
|
|
struct ft80x_registers_s regs;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
DEBUGASSERT(value != NULL && (addr & 3) == 0 && addr < 0xffc00000);
|
|
|
|
|
|
|
|
/* Perform the IOCTL to get the register value */
|
|
|
|
|
|
|
|
regs.addr = addr;
|
|
|
|
regs.nregs = nregs;
|
|
|
|
regs.value = (FAR uint32_t *)value; /* Discard const qualifier */
|
|
|
|
|
|
|
|
ret = ioctl(fd, FT80X_IOC_PUTREGS, (unsigned long)((uintptr_t)®s));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
ft80x_err("ERROR: ioctl(FT80X_IOC_PUTREGS) failed: %d\n", errcode);
|
|
|
|
ret = -errcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2018-02-18 20:36:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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)
|
|
|
|
{
|
2018-02-21 01:46:17 +01:00
|
|
|
ft80x_warn("WARNING: Timed out waiting for DLSWAP to complete\n");
|
2018-02-18 20:36:08 +01:00
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No.. Wait a bit and try again */
|
|
|
|
|
|
|
|
usleep(DLSWAP_DELAY_USEC);
|
|
|
|
}
|
|
|
|
}
|