From cdfd5afb3308a1ef4df6dca1318e7ca560dfc99f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 25 Feb 2018 20:26:24 -0600 Subject: [PATCH] apps/graphics/ft80x: Simplify some interfaces. --- graphics/ft80x/ft80x.h | 19 ++++--- graphics/ft80x/ft80x_audio.c | 17 +------ graphics/ft80x/ft80x_coproc.c | 95 +---------------------------------- graphics/ft80x/ft80x_dl.c | 8 +-- graphics/ft80x/ft80x_ramcmd.c | 36 ++++++++++--- graphics/ft80x/ft80x_ramdl.c | 17 +++---- 6 files changed, 50 insertions(+), 142 deletions(-) diff --git a/graphics/ft80x/ft80x.h b/graphics/ft80x/ft80x.h index fc77effa3..7cc9ede3a 100644 --- a/graphics/ft80x/ft80x.h +++ b/graphics/ft80x/ft80x.h @@ -208,16 +208,15 @@ int ft80x_putregs(int fd, uint32_t addr, uint8_t nregs, * Reset to the start of RAM DL memory * * Input Parameters: - * fd - The file descriptor of the FT80x device. Opened by the caller - * with write access. - * buffer - An instance of struct ft80x_dlbuffer_s allocated by the caller. + * 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_ramdl_rewind(int fd, FAR struct ft80x_dlbuffer_s *buffer); +int ft80x_ramdl_rewind(int fd); /**************************************************************************** * Name: ft80x_ramdl_append @@ -228,15 +227,15 @@ int ft80x_ramdl_rewind(int fd, FAR struct ft80x_dlbuffer_s *buffer); * Input Parameters: * fd - The file descriptor of the FT80x device. Opened by the caller * with write access. - * buffer - An instance of struct ft80x_dlbuffer_s allocated by the caller. + * data - A pointer to the start of the data to be written. + * len - The number of bytes to be written. * * Returned Value: * Zero (OK) on success. A negated errno value on failure. * ****************************************************************************/ -int ft80x_ramdl_append(int fd, FAR struct ft80x_dlbuffer_s *buffer, - FAR const void *data, size_t len); +int ft80x_ramdl_append(int fd, FAR const void *data, size_t len); /**************************************************************************** * Name: ft80x_ramcmd_append @@ -247,15 +246,15 @@ int ft80x_ramdl_append(int fd, FAR struct ft80x_dlbuffer_s *buffer, * Input Parameters: * fd - The file descriptor of the FT80x device. Opened by the caller * with write access. - * buffer - An instance of struct ft80x_dlbuffer_s allocated by the caller. + * data - A pointer to the start of the data to be append to RAM CMD. + * len - The number of bytes to be appended. * * Returned Value: * Zero (OK) on success. A negated errno value on failure. * ****************************************************************************/ -int ft80x_ramcmd_append(int fd, FAR struct ft80x_dlbuffer_s *buffer, - FAR const void *data, size_t len); +int ft80x_ramcmd_append(int fd, FAR const void *data, size_t len); /**************************************************************************** * Name: ft80x_ramcmd_freespace diff --git a/graphics/ft80x/ft80x_audio.c b/graphics/ft80x/ft80x_audio.c index e97077518..e05898e95 100644 --- a/graphics/ft80x/ft80x_audio.c +++ b/graphics/ft80x/ft80x_audio.c @@ -290,8 +290,7 @@ int ft80x_audio_playfile(int fd, FAR struct ft80x_dlbuffer_s *buffer, /* Mute the sound clearing by clearing RAM_G after the current offset. * - * REVISIT: There is an ugly hack into the display list logic in the - * following 8( I also suspect that the logic is not even correct. + * REVISIT: I suspect that this logic is not correct. */ memset.cmd = FT80X_CMD_MEMSET; @@ -299,25 +298,13 @@ int ft80x_audio_playfile(int fd, FAR struct ft80x_dlbuffer_s *buffer, memset.value = 0; memset.num = RAMG_MAXOFFSET - offset; - buffer->coproc = true; - buffer->dlsize = 0; - buffer->dloffset = sizeof(struct ft80x_cmd_memset_s); - - ret = ft80x_ramcmd_append(fd, buffer, &memset, - sizeof(ft80x_ramcmd_append)); + ret = ft80x_coproc_send(fd, (FAR const uint32_t *)&memset, 4); if (ret < 0) { ft80x_err("ERROR: ft80x_ramcmd_append failed: %d\n", ret); goto errout_with_fd; } - ret = ft80x_ramcmd_waitfifoempty(fd); - if (ret < 0) - { - ft80x_err("ERROR: ft80x_ramcmd_waitfifoempty failed: %d\n", ret); - goto errout_with_fd; - } - /* If the read pointer is already passed over write pointer */ do diff --git a/graphics/ft80x/ft80x_coproc.c b/graphics/ft80x/ft80x_coproc.c index 663388606..5daf2ee8e 100644 --- a/graphics/ft80x/ft80x_coproc.c +++ b/graphics/ft80x/ft80x_coproc.c @@ -68,9 +68,6 @@ * 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. * - * This function is similar to ft80x_ramcmd_append() but does not depend - * on a display list. - * * 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. @@ -88,97 +85,7 @@ int ft80x_coproc_send(int fd, FAR const uint32_t *cmds, size_t ncmds) { - struct ft80x_relmem_s wrdesc; - FAR const uint8_t *src; - ssize_t remaining; - size_t wrsize; - uint16_t offset; - uint16_t maxsize; - int ret; - - /* Loop until all of the display list commands have been transferred to - * FIFO. - */ - - src = (FAR const uint8_t *)cmds; - remaining = ncmds << 2; - - do - { - /* Write the number of bytes remaining to be transferred */ - - wrsize = remaining; - - /* Get the amount of free space in the FIFO. */ - - maxsize = 0; - ret = ft80x_ramcmd_freespace(fd, &offset, &maxsize); - if (ret < 0) - { - ft80x_err("ERROR: ft80x_ramcmd_freespace() failed: %d\n", ret); - return ret; - } - - /* If the FIFO full? */ - - if (maxsize == 0) - { - /* Yes.. wait a bit and try again */ - - ft80x_warn("WARNING: FIFO is full: %d\n", ret); - usleep(50 * 1000); - continue; - } - - /* Limit the write size to the size of the available FIFO memory */ - - if (wrsize > (size_t)maxsize) - { - wrsize = (size_t)maxsize; - } - - /* Perform the transfer */ - - wrdesc.offset = offset; - wrdesc.nbytes = wrsize; - wrdesc.value = (FAR void *)src; /* Discards 'const' qualifier */ - - ret = ioctl(fd, FT80X_IOC_PUTRAMCMD, - (unsigned long)((uintptr_t)&wrdesc)); - if (ret < 0) - { - int errcode = errno; - ft80x_err("ERROR: ioctl() FT80X_IOC_PUTRAMCMD failed: %d\n", - errcode); - return -errcode; - } - - /* Update the command FIFO */ - - ret = ft80x_putreg16(fd, FT80X_REG_CMD_WRITE, offset + wrsize); - if (ret < 0) - { - ft80x_err("ERROR: ft80x_putreg16() failed: %d\n", ret); - return ret; - } - - /* Wait for the FIFO to empty */ - - ret = ft80x_ramcmd_waitfifoempty(fd); - if (ret < 0) - { - ft80x_err("ERROR: ft80x_ramcmd_waitfifoempty() failed: %d\n", ret); - return ret; - } - - /* Set up for the next time through the loop */ - - remaining -= wrsize; - src += wrsize; - } - while (remaining > 0); - - return OK; + return ft80x_ramcmd_append(fd, cmds, ncmds << 2); } /**************************************************************************** diff --git a/graphics/ft80x/ft80x_dl.c b/graphics/ft80x/ft80x_dl.c index 361e406cb..7ae4080e3 100644 --- a/graphics/ft80x/ft80x_dl.c +++ b/graphics/ft80x/ft80x_dl.c @@ -152,13 +152,13 @@ static int ft80x_dl_append(int fd, FAR struct ft80x_dlbuffer_s *buffer, { /* Append data to RAM CMD */ - ret = ft80x_ramcmd_append(fd, buffer, data, len); + ret = ft80x_ramcmd_append(fd, data, len); } else { /* Append data to RAM DL */ - ret = ft80x_ramdl_append(fd, buffer, data, len); + ret = ft80x_ramdl_append(fd, data, len); } return ret; @@ -215,7 +215,7 @@ int ft80x_dl_start(int fd, FAR struct ft80x_dlbuffer_s *buffer, bool coproc) * beginning of the hardware display list. */ - ret = ft80x_ramdl_rewind(fd, buffer); + ret = ft80x_ramdl_rewind(fd); if (ret < 0) { ft80x_err("ERROR: ft80x_ramdl_rewind failed: %d\n", ret); @@ -641,7 +641,7 @@ int ft80x_dl_flush(int fd, FAR struct ft80x_dlbuffer_s *buffer, bool wait) /* Write the content of the local display buffer to hardware. */ - ret = ft80x_dl_append(fd, buffer, buffer->dlbuffer, buffer->dloffset); + ret = ft80x_dl_append(fd, buffer, buffer->dlbuffer, buffer->dloffset); if (ret < 0) { ft80x_err("ERROR: ft80x_dl_append failed: %d\n", ret); diff --git a/graphics/ft80x/ft80x_ramcmd.c b/graphics/ft80x/ft80x_ramcmd.c index 1b006513f..6020e1440 100644 --- a/graphics/ft80x/ft80x_ramcmd.c +++ b/graphics/ft80x/ft80x_ramcmd.c @@ -64,17 +64,15 @@ * Input Parameters: * fd - The file descriptor of the FT80x device. Opened by the caller * with write access. - * buffer - An instance of struct ft80x_dlbuffer_s allocated by the caller. - * data - A pointer to the start of the data to be written. - * len - The number of bytes to be written. + * data - A pointer to the start of the data to be append to RAM CMD. + * len - The number of bytes to be appended. * * Returned Value: * Zero (OK) on success. A negated errno value on failure. * ****************************************************************************/ -int ft80x_ramcmd_append(int fd, FAR struct ft80x_dlbuffer_s *buffer, - FAR const void *data, size_t len) +int ft80x_ramcmd_append(int fd, FAR const void *data, size_t len) { struct ft80x_relmem_s wrdesc; FAR const uint8_t *src; @@ -84,6 +82,9 @@ int ft80x_ramcmd_append(int fd, FAR struct ft80x_dlbuffer_s *buffer, uint16_t maxsize; int ret; + DEBUGASSERT(data != NULL && ((uintptr_t)data & 3) == 0 && + len > 0 && (len & 3) == 0); + /* Loop until all of the display list commands have been transferred to * FIFO. */ @@ -116,8 +117,27 @@ int ft80x_ramcmd_append(int fd, FAR struct ft80x_dlbuffer_s *buffer, if (maxsize == 0) { +#if 1 + /* Yes.. wait for the FIFO to empty, then try again. + * + * REVISIT: Would it not be sufficient to wait only until the + * FIFO is not full? + */ + + ft80x_warn("WARNING: FIFO is full: %d\n", ret); + ret = ft80x_ramcmd_waitfifoempty(fd); + if (ret < 0) + { + ft80x_err("ERROR: ft80x_ramcmd_waitfifoempty() failed: %d\n", + ret); + return ret; + } + + continue; +#else ft80x_err("ERROR: FIFO is full: %d\n", ret); return -ENOSPC; +#endif } /* Limit the write size to the size of the available FIFO memory */ @@ -152,7 +172,7 @@ int ft80x_ramcmd_append(int fd, FAR struct ft80x_dlbuffer_s *buffer, return ret; } - /* Wait for the FIFO to empty if there is more to be sent */ + /* Wait for the FIFO to empty */ if (remaining > wrsize) { @@ -167,8 +187,8 @@ int ft80x_ramcmd_append(int fd, FAR struct ft80x_dlbuffer_s *buffer, /* Set up for the next time through the loop. */ - remaining -= wrsize; - src += wrsize; + remaining -= wrsize; + src += wrsize; } while (remaining > 0); diff --git a/graphics/ft80x/ft80x_ramdl.c b/graphics/ft80x/ft80x_ramdl.c index 9439695d4..47b9cf16a 100644 --- a/graphics/ft80x/ft80x_ramdl.c +++ b/graphics/ft80x/ft80x_ramdl.c @@ -61,21 +61,18 @@ * Reset to the start of RAM DL memory * * Input Parameters: - * fd - The file descriptor of the FT80x device. Opened by the caller - * with write access. - * buffer - An instance of struct ft80x_dlbuffer_s allocated by the caller. + * 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_ramdl_rewind(int fd, FAR struct ft80x_dlbuffer_s *buffer) +int ft80x_ramdl_rewind(int fd) { off_t pos; - DEBUGASSERT(fd >= 0 && buffer != NULL); - /* Reposition the VFSso that subsequent writes will be to the beginning of * the hardware display list. */ @@ -100,7 +97,6 @@ int ft80x_ramdl_rewind(int fd, FAR struct ft80x_dlbuffer_s *buffer) * Input Parameters: * fd - The file descriptor of the FT80x device. Opened by the caller * with write access. - * buffer - An instance of struct ft80x_dlbuffer_s allocated by the caller. * data - A pointer to the start of the data to be written. * len - The number of bytes to be written. * @@ -109,13 +105,12 @@ int ft80x_ramdl_rewind(int fd, FAR struct ft80x_dlbuffer_s *buffer) * ****************************************************************************/ -int ft80x_ramdl_append(int fd, FAR struct ft80x_dlbuffer_s *buffer, - FAR const void *data, size_t len) +int ft80x_ramdl_append(int fd, FAR const void *data, size_t len) { size_t nwritten; - DEBUGASSERT(fd >= 0 && buffer != NULL && data != NULL && - ((uintptr_t)data & 3) == 0 && len > 0 && (len & 3) == 0); + DEBUGASSERT(data != NULL && ((uintptr_t)data & 3) == 0 && + len > 0 && (len & 3) == 0); /* Write the aligned data directly to the FT80x hardware display list. *