From 97532cbaafe1225ad8e96ff52212681cd87ed907 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 10 Nov 2011 20:31:21 +0000 Subject: Add support for STM32 LCD backlight git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4087 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/configs/stm3210e-eval/README.txt | 18 +++++-- nuttx/configs/stm3210e-eval/nsh2/defconfig | 11 ++-- nuttx/configs/stm3210e-eval/nx/defconfig | 11 ++-- nuttx/configs/stm3210e-eval/nxlines/defconfig | 11 ++-- nuttx/configs/stm3210e-eval/nxtext/defconfig | 11 ++-- .../configs/stm3210e-eval/src/stm3210e-internal.h | 10 ++++ nuttx/configs/stm3210e-eval/src/up_lcd.c | 58 ++++++++++++++++------ 7 files changed, 99 insertions(+), 31 deletions(-) (limited to 'nuttx/configs/stm3210e-eval') diff --git a/nuttx/configs/stm3210e-eval/README.txt b/nuttx/configs/stm3210e-eval/README.txt index 15d621d5b..1f29ae66a 100755 --- a/nuttx/configs/stm3210e-eval/README.txt +++ b/nuttx/configs/stm3210e-eval/README.txt @@ -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 ============== diff --git a/nuttx/configs/stm3210e-eval/nsh2/defconfig b/nuttx/configs/stm3210e-eval/nsh2/defconfig index 03cebdd1a..281fec5b7 100644 --- a/nuttx/configs/stm3210e-eval/nsh2/defconfig +++ b/nuttx/configs/stm3210e-eval/nsh2/defconfig @@ -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 diff --git a/nuttx/configs/stm3210e-eval/nx/defconfig b/nuttx/configs/stm3210e-eval/nx/defconfig index 6310407e2..8381ae8f6 100644 --- a/nuttx/configs/stm3210e-eval/nx/defconfig +++ b/nuttx/configs/stm3210e-eval/nx/defconfig @@ -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 diff --git a/nuttx/configs/stm3210e-eval/nxlines/defconfig b/nuttx/configs/stm3210e-eval/nxlines/defconfig index bbd6d20c1..048476296 100644 --- a/nuttx/configs/stm3210e-eval/nxlines/defconfig +++ b/nuttx/configs/stm3210e-eval/nxlines/defconfig @@ -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 diff --git a/nuttx/configs/stm3210e-eval/nxtext/defconfig b/nuttx/configs/stm3210e-eval/nxtext/defconfig index e86d4ce99..07ab05c74 100644 --- a/nuttx/configs/stm3210e-eval/nxtext/defconfig +++ b/nuttx/configs/stm3210e-eval/nxtext/defconfig @@ -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 diff --git a/nuttx/configs/stm3210e-eval/src/stm3210e-internal.h b/nuttx/configs/stm3210e-eval/src/stm3210e-internal.h index e86b9a66a..0a953b5e6 100644 --- a/nuttx/configs/stm3210e-eval/src/stm3210e-internal.h +++ b/nuttx/configs/stm3210e-eval/src/stm3210e-internal.h @@ -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|\ diff --git a/nuttx/configs/stm3210e-eval/src/up_lcd.c b/nuttx/configs/stm3210e-eval/src/up_lcd.c index 587d4092c..481da54dd 100644 --- a/nuttx/configs/stm3210e-eval/src/up_lcd.c +++ b/nuttx/configs/stm3210e-eval/src/up_lcd.c @@ -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 -- cgit v1.2.3