From 305e470a9087050a180f56f52e01a3d12090792c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 27 Feb 2018 08:48:15 -0600 Subject: [PATCH] apps/graphics/ft80x: Add controls for enabling/disabling the audio amplifier; Add general interfaces for controlling FT80x GPIOs. --- examples/ft80x/ft80x_primitives.c | 28 +++++--- graphics/ft80x/Kconfig | 31 -------- graphics/ft80x/ft80x_audio.c | 48 ++++++++++++- graphics/ft80x/ft80x_gpio.c | 116 +++++++++++++++++++++++++++--- include/graphics/ft80x.h | 36 ++++++++-- 5 files changed, 203 insertions(+), 56 deletions(-) diff --git a/examples/ft80x/ft80x_primitives.c b/examples/ft80x/ft80x_primitives.c index 7f4bc9983..ee0d244fb 100644 --- a/examples/ft80x/ft80x_primitives.c +++ b/examples/ft80x/ft80x_primitives.c @@ -516,6 +516,12 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer) dispr -= (dispr - displ) % 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--) { 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) { 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) { 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) { 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); @@ -583,7 +589,7 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer) if (ret < 0) { ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret); - return ret; + goto errout_with_sound;; } 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) { 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) { 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) { ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret); - return ret; + goto errout_with_sound;; } /* One side points */ @@ -667,7 +673,7 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer) if (ret < 0) { 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 */ @@ -687,7 +693,7 @@ int ft80x_prim_stencil(int fd, FAR struct ft80x_dlbuffer_s *buffer) if (ret < 0) { 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) { ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret); - return ret; + goto errout_with_sound;; } /* 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; } diff --git a/graphics/ft80x/Kconfig b/graphics/ft80x/Kconfig index b0e945100..891d701ef 100644 --- a/graphics/ft80x/Kconfig +++ b/graphics/ft80x/Kconfig @@ -66,37 +66,6 @@ config GRAPHICS_FT80X_AUDIO_BUFSIZE The buffer may, of course, be used for other purposes when not 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 bool "Enable error output" default y diff --git a/graphics/ft80x/ft80x_audio.c b/graphics/ft80x/ft80x_audio.c index 130afbf01..bbc224650 100644 --- a/graphics/ft80x/ft80x_audio.c +++ b/graphics/ft80x/ft80x_audio.c @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -84,11 +85,51 @@ * 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 * * 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: * 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[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: * 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: * fd - The file descriptor of the FT80x device. Opened by the * caller with write access. diff --git a/graphics/ft80x/ft80x_gpio.c b/graphics/ft80x/ft80x_gpio.c index 1050fa373..5a6a6632a 100644 --- a/graphics/ft80x/ft80x_gpio.c +++ b/graphics/ft80x/ft80x_gpio.c @@ -64,18 +64,75 @@ * with write access. * gpio - Identifies the GPIO pin {0,1} * dir - Direction: 0=input, 1=output - * drive - Common output drive strength for GPIO 0 and 1: - * 0=4mA, 1=8mA, 2=12mA, 3=16mA (default is 4mA) + * drive - Common output drive strength for GPIO 0 and 1 (see + * FT80X_GPIO_DRIVE_* definitions). Default is 4mA. + * value - Initial value for output pins * * Returned Value: * 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" - return OK; + uint8_t regval8; + 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, ®val8); + 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, ®val8); + 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) { -#warning "Missing logic" - return OK; + uint8_t regval8; + int ret; + + DEBUGASSERT(gpio == 0 || gpio == 1 || gpio == 7); + + /* Set the output value */ + + ret = ft80x_getreg8(fd, FT80X_REG_GPIO, ®val8); + 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) { -#warning "Missing logic" - return OK; + uint8_t regval8; + int ret; + + DEBUGASSERT(gpio == 0 || gpio == 1 || gpio == 7); + + /* Return the input value */ + + ret = ft80x_getreg8(fd, FT80X_REG_GPIO, ®val8); + if (ret < 0) + { + ft80x_err("ERROR: ft80x_getreg8 failed; %d\n", ret); + return false; + } + + return (regval8 & (1 << gpio)) != 0; } diff --git a/include/graphics/ft80x.h b/include/graphics/ft80x.h index 387b2ddd6..5c796a512 100644 --- a/include/graphics/ft80x.h +++ b/include/graphics/ft80x.h @@ -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); +/**************************************************************************** + * 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 * * 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: * 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: * 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: * fd - The file descriptor of the FT80x device. Opened by the * caller with write access. @@ -523,15 +549,17 @@ int ft80x_backlight_fade(int fd, uint8_t duty, uint16_t delay); * with write access. * gpio - Identifies the GPIO pin {0,1} * dir - Direction: 0=input, 1=output - * drive - Common output drive strength for GPIO 0 and 1: - * 0=4mA, 1=8mA, 2=12mA, 3=16mA (default is 4mA) + * drive - Common output drive strength for GPIO 0 and 1 (see + * FT80X_GPIO_DRIVE_* definitions). Default is 4mA. + * value - Initial value for output pins * * Returned Value: * 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