Add support for STM32 LCD backlight

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4087 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2011-11-10 20:31:21 +00:00
parent a1a523e21b
commit 345de9c454
7 changed files with 99 additions and 31 deletions

View File

@ -545,13 +545,25 @@ STM3210E-EVAL-specific Configuration Options
portrait" orientation support. In this orientation, the
STM3210E-EVAL's LCD ribbon cable is at the top of the display.
Default is 320x240 "landscape" orientation.
CONFIG_LCD_BACKLIGHT - Define to support an adjustable backlight
using timer 1. The granularity of the settings is determined
by CONFIG_LCD_MAXPOWER. Requires CONFIG_STM32_TIM1.
CONFIG_LCD_BACKLIGHT - Define to support a backlight.
CONFIG_LCD_PWM - If CONFIG_STM32_TIM1 is also defined, then an
adjustable backlight will be provided using timer 1 to generate
various pulse widthes. The granularity of the settings is
determined by CONFIG_LCD_MAXPOWER. If CONFIG_LCD_PWM (or
CONFIG_STM32_TIM1) is not defined, then a simple on/off backlight
is provided.
CONFIG_LCD_RDSHIFT - When reading 16-bit gram data, there appears
to be a shift in the returned data. This value fixes the offset.
Default 5.
The LCD driver dynamically selects the LCD based on the reported LCD
ID value. However, code size can be reduced by suppressing support for
individual LCDs using:
CONFIG_STM32_AM240320_DISABLE
CONFIG_STM32_SPFD5408B_DISABLE
CONFIG_STM32_R61580_DISABLE
Configurations
==============

View File

@ -906,14 +906,19 @@ CONFIG_NX_MXCLIENTMSGS=16
# portrait" orientation support. In this orientation, the
# STM3210E-EVAL's LCD ribbon cable is at the top of the display.
# Default is 320x240 "landscape" orientation.
# CONFIG_LCD_BACKLIGHT - Define to support an adjustable backlight
# using timer 1. The granularity of the settings is determined
# by CONFIG_LCD_MAXPOWER. Requires CONFIG_STM32_TIM1.
# CONFIG_LCD_BACKLIGHT - Define to support a backlight.
# CONFIG_LCD_PWM - If CONFIG_STM32_TIM1 is also defined, then an
# adjustable backlight will be provided using timer 1 to generate
# various pulse widthes. The granularity of the settings is
# determined by CONFIG_LCD_MAXPOWER. If CONFIG_LCD_PWM (or
# CONFIG_STM32_TIM1) is not defined, then a simple on/off backlight
# is provided.
#
CONFIG_LCD_LANDSCAPE=n
CONFIG_LCD_PORTRAIT=n
CONFIG_LCD_RPORTRAIT=y
CONFIG_LCD_BACKLIGHT=n
CONFIG_LCD_PWM=n
#
# Settings for examples/uip

View File

@ -893,14 +893,19 @@ CONFIG_NX_MXCLIENTMSGS=16
# portrait" orientation support. In this orientation, the
# STM3210E-EVAL's LCD ribbon cable is at the top of the display.
# Default is 320x240 "landscape" orientation.
# CONFIG_LCD_BACKLIGHT - Define to support an adjustable backlight
# using timer 1. The granularity of the settings is determined
# by CONFIG_LCD_MAXPOWER. Requires CONFIG_STM32_TIM1.
# CONFIG_LCD_BACKLIGHT - Define to support a backlight.
# CONFIG_LCD_PWM - If CONFIG_STM32_TIM1 is also defined, then an
# adjustable backlight will be provided using timer 1 to generate
# various pulse widthes. The granularity of the settings is
# determined by CONFIG_LCD_MAXPOWER. If CONFIG_LCD_PWM (or
# CONFIG_STM32_TIM1) is not defined, then a simple on/off backlight
# is provided.
#
CONFIG_LCD_LANDSCAPE=n
CONFIG_LCD_PORTRAIT=n
CONFIG_LCD_RPORTRAIT=y
CONFIG_LCD_BACKLIGHT=n
CONFIG_LCD_PWM=n
#
# Settings for examples/uip

View File

@ -892,14 +892,19 @@ CONFIG_NX_MXCLIENTMSGS=16
# portrait" orientation support. In this orientation, the
# STM3210E-EVAL's LCD ribbon cable is at the top of the display.
# Default is 320x240 "landscape" orientation.
# CONFIG_LCD_BACKLIGHT - Define to support an adjustable backlight
# using timer 1. The granularity of the settings is determined
# by CONFIG_LCD_MAXPOWER. Requires CONFIG_STM32_TIM1.
# CONFIG_LCD_BACKLIGHT - Define to support a backlight.
# CONFIG_LCD_PWM - If CONFIG_STM32_TIM1 is also defined, then an
# adjustable backlight will be provided using timer 1 to generate
# various pulse widthes. The granularity of the settings is
# determined by CONFIG_LCD_MAXPOWER. If CONFIG_LCD_PWM (or
# CONFIG_STM32_TIM1) is not defined, then a simple on/off backlight
# is provided.
#
CONFIG_LCD_LANDSCAPE=n
CONFIG_LCD_PORTRAIT=n
CONFIG_LCD_RPORTRAIT=y
CONFIG_LCD_BACKLIGHT=n
CONFIG_LCD_PWM=n
#
# Settings for examples/uip

View File

@ -892,14 +892,19 @@ CONFIG_NX_MXCLIENTMSGS=16
# portrait" orientation support. In this orientation, the
# STM3210E-EVAL's LCD ribbon cable is at the top of the display.
# Default is 320x240 "landscape" orientation.
# CONFIG_LCD_BACKLIGHT - Define to support an adjustable backlight
# using timer 1. The granularity of the settings is determined
# by CONFIG_LCD_MAXPOWER. Requires CONFIG_STM32_TIM1.
# CONFIG_LCD_BACKLIGHT - Define to support a backlight.
# CONFIG_LCD_PWM - If CONFIG_STM32_TIM1 is also defined, then an
# adjustable backlight will be provided using timer 1 to generate
# various pulse widthes. The granularity of the settings is
# determined by CONFIG_LCD_MAXPOWER. If CONFIG_LCD_PWM (or
# CONFIG_STM32_TIM1) is not defined, then a simple on/off backlight
# is provided.
#
CONFIG_LCD_LANDSCAPE=n
CONFIG_LCD_PORTRAIT=n
CONFIG_LCD_RPORTRAIT=y
CONFIG_LCD_BACKLIGHT=n
CONFIG_LCD_PWM=n
#
# Settings for examples/uip

View File

@ -101,6 +101,16 @@
#define GPIO_FLASH_CS (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN2)
/* Backlight control: PA.8
*
* If CONFIG_LCD_TIM1 (and CONFIG_STM32_TIM1) is defined, PA.8 will be
* configured as CH1OUT for variable backlight control. Otherwise, the
* following definition will be used to support a discrete backlight control.
*/
#define GPIO_LCD_BACKLIGHT (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTA|GPIO_PIN8)
/* USB Soft Connect Pullup: PB.14 */
#define GPIO_USB_PULLUP (GPIO_OUTPUT|GPIO_CNF_OUTOD|GPIO_MODE_50MHz|\

View File

@ -84,11 +84,34 @@
# define CONFIG_LCD_MAXCONTRAST 1
#endif
/* Backlight */
#ifndef CONFIG_LCD_BACKLIGHT
# undef CONFIG_LCD_PWM
#endif
#if defined(CONFIG_LCD_BACKLIGHT) && defined(CONFIG_LCD_PWM)
# if !defined(CONFIG_STM32_TIM1)
# warning "CONFIG_LCD_PWM requires CONFIG_STM32_TIM1"
# undef CONFIG_LCD_PWM
# endif
# if defined(CONFIG_STM32_TIM1_FULL_REMAP)
# warning "PA8 cannot be configured as TIM1 CH1 with full remap"
# undef CONFIG_LCD_PWM
# endif
#endif
#if defined(CONFIG_LCD_BACKLIGHT) && defined(CONFIG_LCD_PWM)
# if CONFIG_LCD_MAXPOWER < 2
# warning "A larger value of CONFIG_LCD_MAXPOWER is recommended"
# endif
#endif
/* Check power setting */
#if !defined(CONFIG_LCD_MAXPOWER) || CONFIG_LCD_MAXPOWER < 1
# undef CONFIG_LCD_MAXPOWER
# ifdef CONFIG_LCD_BACKLIGHT
# if defined(CONFIG_LCD_BACKLIGHT) && defined(CONFIG_LCD_PWM)
# define CONFIG_LCD_MAXPOWER 100
# else
# define CONFIG_LCD_MAXPOWER 1
@ -113,21 +136,6 @@
# define CONFIG_LCD_LANDSCAPE 1
#endif
/* Backlight */
#ifdef CONFIG_LCD_BACKLIGHT
# ifndef CONFIG_STM32_TIM1
# error "CONFIG_STM32_TIM1 to use the LCD backlight controls"
# endif
# if CONFIG_LCD_MAXPOWER < 2
# warning "A larger value of CONFIG_LCD_MAXPOWER is recommended"
# endif
#endif
#if defined(CONFIG_STM32_TIM1_FULL_REMAP)
# error "PA8 cannot be configured as TIM1 CH1 with full remap"
#endif
/* When reading 16-bit gram data, there may some shifts in the returned data
* and/or there may be some colors in the incorrect posisions:
*
@ -969,6 +977,7 @@ static int stm3210e_setpower(struct lcd_dev_s *dev, int power)
if (power > 0)
{
#ifdef CONFIG_LCD_BACKLIGHT
#ifdef CONFIG_LCD_PWM
uint32_t duty;
/* Caclulate the new backlight duty. It is a faction of the timer1
@ -982,6 +991,11 @@ static int stm3210e_setpower(struct lcd_dev_s *dev, int power)
duty = LCD_BL_TIMER_PERIOD - 1;
}
putreg16((uint16_t)duty, STM32_TIM1_CCR1);
#else
/* Turn the backlight on */
stm32_gpiowrite(GPIO_LCD_BACKLIGHT, true);
#endif
#endif
/* Then turn the display on */
@ -998,7 +1012,15 @@ static int stm3210e_setpower(struct lcd_dev_s *dev, int power)
}
else
{
/* Turn the display off */
stm3210e_writereg(LCD_REG_7, 0);
/* Turn the backlight off */
#if defined(CONFIG_LCD_BACKLIGHT) && !defined(CONFIG_LCD_PWM)
stm32_gpiowrite(GPIO_LCD_BACKLIGHT, true);
#endif
g_lcddev.power = 0;
}
@ -1279,6 +1301,7 @@ static inline void stm3210e_lcdinitialize(void)
#ifdef CONFIG_LCD_BACKLIGHT
static void stm3210e_backlight(void)
{
#ifdef CONFIG_LCD_PWM
uint16_t ccmr;
uint16_t ccer;
uint16_t cr2;
@ -1387,6 +1410,9 @@ static void stm3210e_backlight(void)
lcddbg("CCR4: %04x\n", getreg32(STM32_TIM1_CCR4));
lcddbg("CCR4: %04x\n", getreg32(STM32_TIM1_CCR4));
lcddbg("DMAR: %04x\n", getreg32(STM32_TIM1_DMAR));
#else
stm32_configgpio(GPIO_LCD_BACKLIGHT);
#endif
}
#endif