apps/graphics/ft80x: Add interfaces to control the backlight. apps/examples/ft80x: Fade the display on and off between each example.

This commit is contained in:
Gregory Nutt 2018-02-23 10:49:38 -06:00
parent 557fba6c4c
commit 9095bd4f1b
4 changed files with 183 additions and 6 deletions

View File

@ -166,6 +166,10 @@ static int ft80x_showname(int fd, FAR struct ft80x_dlbuffer_s *buffer,
struct ft80x_cmd_text_s text; struct ft80x_cmd_text_s text;
int ret; int ret;
/* Mkae sure that the backlight off */
(void)ft80x_backlight_set(fd, 0);
/* Create the display list */ /* Create the display list */
ret = ft80x_dl_start(fd, buffer, false); ret = ft80x_dl_start(fd, buffer, false);
@ -206,9 +210,10 @@ static int ft80x_showname(int fd, FAR struct ft80x_dlbuffer_s *buffer,
return ret; return ret;
} }
/* Wait bit so that the user can read the name */ /* Fade on, then wait bit so that the user can read the name */
sleep(2); (void)ft80x_backlight_fade(fd, 100, 1000);
(void)sleep(1);
return OK; return OK;
} }
@ -236,7 +241,7 @@ static int ft80x_example(int fd, FAR struct ft80x_dlbuffer_s *buffer,
return ret; return ret;
} }
/* Then executte the example */ /* Then execute the example */
ret = example->func(fd, buffer); ret = example->func(fd, buffer);
if (ret < 0) if (ret < 0)
@ -245,9 +250,10 @@ static int ft80x_example(int fd, FAR struct ft80x_dlbuffer_s *buffer,
return ret; return ret;
} }
/* Wait a bit */ /* Wait a bit, then fade out */
sleep(4); sleep(3);
(void)ft80x_backlight_fade(fd, 0, 1000);
return OK; return OK;
} }

View File

@ -41,7 +41,7 @@ include $(APPDIR)/Make.defs
ASRCS = ASRCS =
CSRCS = ft80x_dl.c ft80x_ramg.c ft80x_ramdl.c ft80x_ramcmd.c ft80x_coproc.c CSRCS = ft80x_dl.c ft80x_ramg.c ft80x_ramdl.c ft80x_ramcmd.c ft80x_coproc.c
CSRCS += ft80x_touch.c ft80x_regs.c CSRCS += ft80x_touch.c ft80x_backlight.c ft80x_regs.c
AOBJS = $(ASRCS:.S=$(OBJEXT)) AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT))

View File

@ -0,0 +1,133 @@
/****************************************************************************
* apps/graphics/ft80x/ft80x_backlight.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 <assert.h>
#include <errno.h>
#include <nuttx/lcd/ft80x.h>
#include "graphics/ft80x.h"
#include "ft80x.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: ft80x_backlight_set
*
* Description:
* Set the backlight intensity via the PWM duty.
*
* Input Parameters:
* fd - The file descriptor of the FT80x device. Opened by the caller
* with write access.
* duty - The new backlight duty (as a percentage 0..100)
* delay - The duration of the fade in milliseconds.
*
* Returned Value:
* Zero (OK) on success. A negated errno value on failure.
*
****************************************************************************/
int ft80x_backlight_set(int fd, uint8_t duty)
{
uint16_t duty128;
int ret;
DEBUGASSERT(duty <= 100);
/* 0% corresponds to the value 0, but 100% corresponds to the value 128 */
duty128 = ((uint16_t)duty << 7) / 100;
/* Perform the IOCTL to set the backlight duty */
ret = ft80x_putreg8(fd, FT80X_REG_PWM_DUTY, (uint8_t)duty128);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_putreg8 failed: %d\n", ret);
}
return ret;
}
/****************************************************************************
* Name: ft80x_backlight_fade
*
* Description:
* Change the backlight intensity with a controllable fade.
*
* Input Parameters:
* fd - The file descriptor of the FT80x device. Opened by the caller
* with write access.
* duty - The terminal duty (as a percentage 0..100)
* delay - The duration of the fade in milliseconds (10..16700)
*
* Returned Value:
* Zero (OK) on success. A negated errno value on failure.
*
****************************************************************************/
int ft80x_backlight_fade(int fd, uint8_t duty, uint16_t delay)
{
struct ft80x_fade_s fade;
int ret;
DEBUGASSERT(duty <= 100);
/* Perform the IOCTL to perform the fade */
fade.delay = duty;
fade.delay = delay;
ret = ioctl(fd, FT80X_IOC_FADE, (unsigned long)((uintptr_t)&fade));
if (ret < 0)
{
int errcode = errno;
ft80x_err("ERROR: ioctl(FT80X_IOC_FADE) failed: %d\n", errcode);
ret = -errcode;
}
return ret;
}

View File

@ -326,6 +326,44 @@ int ft80x_ramg_write(int fd, unsigned int offset, FAR const void *data,
int ft80x_touch_gettransform(int fd, FAR uint32_t matrix[6]); int ft80x_touch_gettransform(int fd, FAR uint32_t matrix[6]);
/****************************************************************************
* Name: ft80x_backlight_set
*
* Description:
* Set the backlight intensity via the PWM duty.
*
* Input Parameters:
* fd - The file descriptor of the FT80x device. Opened by the caller
* with write access.
* duty - The new backlight duty (as a percentage 0..100)
* delay - The duration of the fade in milliseconds.
*
* Returned Value:
* Zero (OK) on success. A negated errno value on failure.
*
****************************************************************************/
int ft80x_backlight_set(int fd, uint8_t duty);
/****************************************************************************
* Name: ft80x_backlight_fade
*
* Description:
* Change the backlight intensity with a controllable fade.
*
* Input Parameters:
* fd - The file descriptor of the FT80x device. Opened by the caller
* with write access.
* duty - The terminal duty (as a percentage 0..100)
* delay - The duration of the fade in milliseconds (10..16700).
*
* Returned Value:
* Zero (OK) on success. A negated errno value on failure.
*
****************************************************************************/
int ft80x_backlight_fade(int fd, uint8_t duty, uint16_t delay);
#undef EXTERN #undef EXTERN
#ifdef __cplusplus #ifdef __cplusplus
} }