apps/graphics/ft80x: Add controls for enabling/disabling the audio amplifier; Add general interfaces for controlling FT80x GPIOs.

This commit is contained in:
Gregory Nutt 2018-02-27 08:48:15 -06:00
parent 9f6338566f
commit 305e470a90
5 changed files with 203 additions and 56 deletions

View File

@ -516,6 +516,12 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer)
dispr -= (dispr - displ) % gridsize; dispr -= (dispr - displ) % gridsize;
dispb -= (dispb - dispa) % gridsize; dispb -= (dispb - dispa) % gridsize;
ret = ft80x_audio_enable(fd, true);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_audio_enable(FT80X_IOC_AUDIO) failed: %d\n", ret);
}
for (i = 100; i > 0; i--) for (i = 100; i > 0; i--)
{ {
if ((xball + rball + 2) >= dispr || (xball - rball - 2) <= displ) if ((xball + rball + 2) >= dispr || (xball - rball - 2) <= displ)
@ -526,7 +532,7 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer)
if (ret < 0) if (ret < 0)
{ {
ft80x_err("ERROR: ft80x_audio_playsound failed: %d\n", ret); ft80x_err("ERROR: ft80x_audio_playsound failed: %d\n", ret);
return ret; goto errout_with_sound;;
} }
} }
@ -538,7 +544,7 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer)
if (ret < 0) if (ret < 0)
{ {
ft80x_err("ERROR: ft80x_audio_playsound failed: %d\n", ret); ft80x_err("ERROR: ft80x_audio_playsound failed: %d\n", ret);
return ret; goto errout_with_sound;;
} }
} }
@ -566,7 +572,7 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer)
if (ret < 0) if (ret < 0)
{ {
ft80x_err("ERROR: ft80x_dl_start failed: %d\n", ret); ft80x_err("ERROR: ft80x_dl_start failed: %d\n", ret);
return ret; goto errout_with_sound;;
} }
cmds.a.clearrgb.cmd = FT80X_CLEAR_COLOR_RGB(128, 128, 0); cmds.a.clearrgb.cmd = FT80X_CLEAR_COLOR_RGB(128, 128, 0);
@ -583,7 +589,7 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer)
if (ret < 0) if (ret < 0)
{ {
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret); ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret; goto errout_with_sound;;
} }
for (j = 0; j <= ((dispr - displ) / gridsize); j++) for (j = 0; j <= ((dispr - displ) / gridsize); j++)
@ -597,7 +603,7 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer)
if (ret < 0) if (ret < 0)
{ {
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret); ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret; goto errout_with_sound;;
} }
} }
@ -612,7 +618,7 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer)
if (ret < 0) if (ret < 0)
{ {
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret); ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret; goto errout_with_sound;;
} }
} }
@ -628,7 +634,7 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer)
if (ret < 0) if (ret < 0)
{ {
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret); ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret; goto errout_with_sound;;
} }
/* One side points */ /* One side points */
@ -667,7 +673,7 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer)
if (ret < 0) if (ret < 0)
{ {
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret); ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret; goto errout_with_sound;;
} }
/* Draw lines - line should be at least radius diameter */ /* Draw lines - line should be at least radius diameter */
@ -687,7 +693,7 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer)
if (ret < 0) if (ret < 0)
{ {
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret); ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret; goto errout_with_sound;;
} }
} }
@ -716,7 +722,7 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer)
if (ret < 0) if (ret < 0)
{ {
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret); ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret; goto errout_with_sound;;
} }
/* Finally, terminate the display list */ /* Finally, terminate the display list */
@ -728,6 +734,8 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer)
} }
} }
errout_with_sound:
(void)ft80x_audio_enable(fd, false);
return ret; return ret;
} }

View File

@ -66,37 +66,6 @@ config GRAPHICS_FT80X_AUDIO_BUFSIZE
The buffer may, of course, be used for other purposes when not The buffer may, of course, be used for other purposes when not
playing an audio file. playing an audio file.
choice
prompt "Audio Shutdown Options"
default GRAPHICS_FT80X_AUDIO_NOSHUTDOWN
config GRAPHICS_FT80X_AUDIO_NOSHUTDOWN
bool "No amplifier shutdown control"
---help---
There is no audio amplifier or the audio amplifier is not under
software control.
config GRAPHICS_FT80X_AUDIO_MCUSHUTDOWN
bool "MCU controls audio shutdown"
---help---
The audio amplifier is controlled via an MCU GPIO output pin.
config GRAPHICS_FT80X_AUDIO_GPIOSHUTDOWN
bool "FT80X controls audo shutdown"
---help---
The audio amplifier is controlled via an FT80x GPIO output pin.
endchoice # Audio Shutdown Option
config GRAPHICS_FT80X_AUDIO_GPIO
int "FT80x audio shutdown GPIO"
default 1
range 1 2
depends on GRAPHICS_FT80X_AUDIO_GPIOSHUTDOWN
---help---
Identifies the GPIO pin used to control the amplifier shutdown
output.
config GRAPHICS_FT80X_DEBUG_ERROR config GRAPHICS_FT80X_DEBUG_ERROR
bool "Enable error output" bool "Enable error output"
default y default y

View File

@ -40,6 +40,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
#include <stdint.h> #include <stdint.h>
#include <fcntl.h> #include <fcntl.h>
@ -84,11 +85,51 @@
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* Name: ft80x_audio_enable
*
* Description:
* Play an short sound effect. If there is a audio amplifier on board
* (such as TPA6205A or LM4864), then there may also be an active low
* audio shutdown output. That output is controlled by this interface.
*
* Input Parameters:
* fd - The file descriptor of the FT80x device. Opened by the
* caller with write access.
* enable - True: Enabled the audio amplifier; false: disable
*
* Returned Value:
* Zero (OK) on success. A negated errno value on failure.
*
****************************************************************************/
int ft80x_audio_enable(int fd, bool enable)
{
#ifndef CONFIG_LCD_FT80X_AUDIO_NOSHUTDOWN
int ret;
ret = ioctl(fd, FT80X_IOC_AUDIO, (unsigned long)enable);
if (ret < 0)
{
ret = -errno;
ft80x_err("ERROR: ioctl(FT80X_IOC_AUDIO) failed: %d\n", ret);
}
return ret;
#else
return OK;
#endif
}
/**************************************************************************** /****************************************************************************
* Name: ft80x_audio_playsound * Name: ft80x_audio_playsound
* *
* Description: * Description:
* Play an short sound effect * Play an short sound effect.
*
* NOTE: It may be necessary to enable the audio amplifier with
* ft80x_audio_enable() prior to calling this function.
* *
* Input Parameters: * Input Parameters:
* fd - The file descriptor of the FT80x device. Opened by the * fd - The file descriptor of the FT80x device. Opened by the
@ -110,7 +151,7 @@ int ft80x_audio_playsound(int fd, uint16_t effect, uint16_t pitch)
cmds[0] = effect | pitch; cmds[0] = effect | pitch;
cmds[1] = 1; cmds[1] = 1;
return ft80x_putregs(fd,FT80X_REG_SOUND, cmds, 2); return ft80x_putregs(fd, FT80X_REG_SOUND, 2, cmds);
} }
/**************************************************************************** /****************************************************************************
@ -119,6 +160,9 @@ int ft80x_audio_playsound(int fd, uint16_t effect, uint16_t pitch)
* Description: * Description:
* Play an audio file. Audio files must consist of raw sample data. * Play an audio file. Audio files must consist of raw sample data.
* *
* NOTE: It may be necessary to enable the audio amplifier with
* ft80x_audio_enable() prior to calling this function.
*
* Input Parameters: * Input Parameters:
* fd - The file descriptor of the FT80x device. Opened by the * fd - The file descriptor of the FT80x device. Opened by the
* caller with write access. * caller with write access.

View File

@ -64,18 +64,75 @@
* with write access. * with write access.
* gpio - Identifies the GPIO pin {0,1} * gpio - Identifies the GPIO pin {0,1}
* dir - Direction: 0=input, 1=output * dir - Direction: 0=input, 1=output
* drive - Common output drive strength for GPIO 0 and 1: * drive - Common output drive strength for GPIO 0 and 1 (see
* 0=4mA, 1=8mA, 2=12mA, 3=16mA (default is 4mA) * FT80X_GPIO_DRIVE_* definitions). Default is 4mA.
* value - Initial value for output pins
* *
* Returned Value: * Returned Value:
* Zero (OK) on success. A negated errno value on failure. * Zero (OK) on success. A negated errno value on failure.
* *
****************************************************************************/ ****************************************************************************/
int ft80x_gpio_configure(int fd, uint8_t gpio, uint8_t dir, uint8_t drive) int ft80x_gpio_configure(int fd, uint8_t gpio, uint8_t dir, uint8_t drive,
bool value)
{ {
#warning "Missing logic" uint8_t regval8;
return OK; int ret;
DEBUGASSERT(gpio == 0 || gpio == 1 || gpio == 7);
DEBUGASSERT(dir == 0 || dir == 1);
DEBUGASSERT((drive & ~FT80X_GPIO_DRIVE_MASK) == 0);
/* Set the pin drive strength and output value */
ret = ft80x_getreg8(fd, FT80X_REG_GPIO, &regval8);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_getreg8 failed; %d\n", ret);
return ret;
}
regval8 &= ~(FT80X_GPIO_DRIVE_MASK | (1 << gpio));
regval8 |= drive;
if (value)
{
regval8 |= (1 << gpio);
}
ret = ft80x_putreg8(fd, FT80X_REG_GPIO, regval8);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_putreg8 failed; %d\n", ret);
return ret;
}
/* Set the pin direction */
ret = ft80x_getreg8(fd, FT80X_REG_GPIO_DIR, &regval8);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_getreg8 failed; %d\n", ret);
return ret;
}
if (dir == 0)
{
regval8 &= ~(1 << gpio);
}
else
{
regval8 |= (1 << gpio);
}
ret = ft80x_putreg8(fd, FT80X_REG_GPIO_DIR, regval8);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_putreg8 failed; %d\n", ret);
}
return ret;
} }
/**************************************************************************** /****************************************************************************
@ -97,8 +154,36 @@ int ft80x_gpio_configure(int fd, uint8_t gpio, uint8_t dir, uint8_t drive)
int ft80x_gpio_write(int fd, uint8_t gpio, bool value) int ft80x_gpio_write(int fd, uint8_t gpio, bool value)
{ {
#warning "Missing logic" uint8_t regval8;
return OK; int ret;
DEBUGASSERT(gpio == 0 || gpio == 1 || gpio == 7);
/* Set the output value */
ret = ft80x_getreg8(fd, FT80X_REG_GPIO, &regval8);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_getreg8 failed; %d\n", ret);
return ret;
}
if (value)
{
regval8 |= (1 << gpio);
}
else
{
regval8 &= ~(1 << gpio);
}
ret = ft80x_putreg8(fd, FT80X_REG_GPIO, regval8);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_putreg8 failed; %d\n", ret);
}
return ret;
} }
/**************************************************************************** /****************************************************************************
@ -119,6 +204,19 @@ int ft80x_gpio_write(int fd, uint8_t gpio, bool value)
bool ft80x_gpio_read(int fd, uint8_t gpio) bool ft80x_gpio_read(int fd, uint8_t gpio)
{ {
#warning "Missing logic" uint8_t regval8;
return OK; int ret;
DEBUGASSERT(gpio == 0 || gpio == 1 || gpio == 7);
/* Return the input value */
ret = ft80x_getreg8(fd, FT80X_REG_GPIO, &regval8);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_getreg8 failed; %d\n", ret);
return false;
}
return (regval8 & (1 << gpio)) != 0;
} }

View File

@ -421,11 +421,34 @@ int ft80x_touch_waittag(int fd, uint8_t oldtag);
int ft80x_touch_info(int fd, FAR struct ft80x_touchinfo_s *info); int ft80x_touch_info(int fd, FAR struct ft80x_touchinfo_s *info);
/****************************************************************************
* Name: ft80x_audio_enable
*
* Description:
* Play an short sound effect. If there is a audio amplifier on board
* (such as TPA6205A or LM4864), then there may also be an active low
* audio shutdown output. That output is controlled by this interface.
*
* Input Parameters:
* fd - The file descriptor of the FT80x device. Opened by the
* caller with write access.
* enable - True: Enabled the audio amplifier; false: disable
*
* Returned Value:
* Zero (OK) on success. A negated errno value on failure.
*
****************************************************************************/
int ft80x_audio_enable(int fd, bool enable);
/**************************************************************************** /****************************************************************************
* Name: ft80x_audio_playsound * Name: ft80x_audio_playsound
* *
* Description: * Description:
* Play an short sound effect * Play an short sound effect.
*
* NOTE: It may be necessary to enable the audio amplifier with
* ft80x_audio_enable() prior to calling this function.
* *
* Input Parameters: * Input Parameters:
* fd - The file descriptor of the FT80x device. Opened by the * fd - The file descriptor of the FT80x device. Opened by the
@ -448,6 +471,9 @@ int ft80x_audio_playsound(int fd, uint16_t effect, uint16_t pitch);
* Description: * Description:
* Play an audio file. Audio files must consist of raw sample data. * Play an audio file. Audio files must consist of raw sample data.
* *
* NOTE: It may be necessary to enable the audio amplifier with
* ft80x_audio_enable() prior to calling this function.
*
* Input Parameters: * Input Parameters:
* fd - The file descriptor of the FT80x device. Opened by the * fd - The file descriptor of the FT80x device. Opened by the
* caller with write access. * caller with write access.
@ -523,15 +549,17 @@ int ft80x_backlight_fade(int fd, uint8_t duty, uint16_t delay);
* with write access. * with write access.
* gpio - Identifies the GPIO pin {0,1} * gpio - Identifies the GPIO pin {0,1}
* dir - Direction: 0=input, 1=output * dir - Direction: 0=input, 1=output
* drive - Common output drive strength for GPIO 0 and 1: * drive - Common output drive strength for GPIO 0 and 1 (see
* 0=4mA, 1=8mA, 2=12mA, 3=16mA (default is 4mA) * FT80X_GPIO_DRIVE_* definitions). Default is 4mA.
* value - Initial value for output pins
* *
* Returned Value: * Returned Value:
* Zero (OK) on success. A negated errno value on failure. * Zero (OK) on success. A negated errno value on failure.
* *
****************************************************************************/ ****************************************************************************/
int ft80x_gpio_configure(int fd, uint8_t gpio, uint8_t dir, uint8_t drive); int ft80x_gpio_configure(int fd, uint8_t gpio, uint8_t dir, uint8_t drive,
bool value);
/**************************************************************************** /****************************************************************************
* Name: ft80x_gpio_write * Name: ft80x_gpio_write