Add backlight control

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3163 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2010-12-05 19:54:23 +00:00
parent d19e58eeb7
commit 67f1072e7b
2 changed files with 123 additions and 3 deletions

View File

@ -165,12 +165,13 @@
* P1[23]/MCFB1/PWM1[4]/MISO0 37 MISO0
* P1[24]/MCFB2/PWM1[5]/MOSI0 38 MOSI0
* P3[25]/MAT0[0]/PWM1[2] 27 LCD_RST
* P3[26]/STCLK/MAT0[1]/PWM1[3] 26 LCD_BL
* P3[26]/STCLK/MAT0[1]/PWM1[3] 26 LCD_BL (PWM1)
*/
#define LPC1766STK_LCD_CS (GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_PORT3 | GPIO_PIN25)
#define LPC1766STK_LCD_CS (GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_PORT1 | GPIO_PIN21)
#define LPC1766STK_LCD_RST (GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_PORT3 | GPIO_PIN25)
#define LPC1766STK_LCD_BL (GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_PORT3 | GPIO_PIN26)
#define LPC1766STK_LCD_BL GPIO_PWM1p3_3
#define GPIO_PWM1p3 GPIO_PWM1p3_3
/* SD/MMC GPIO PIN SIGNAL NAME
* -------------------------------- ---- --------------

View File

@ -48,6 +48,7 @@
#include <nuttx/lcd/lcd.h>
#include <nuttx/lcd/nokia6100.h>
#include "lpc17_syscon.h"
#include "lpc17_internal.h"
#include "lpc17stk_internal.h"
@ -57,6 +58,16 @@
* Pre-Processor Definitions
****************************************************************************/
/* Check power setting */
#if !defined(CONFIG_LCD_MAXPOWER) || CONFIG_LCD_MAXPOWER != 128
# error "CONFIG_LCD_MAXPOWER must be 128"
#endif
/* Backlight OFF PWM setting */
#define NOKIA_BACKLIGHT_OFF 0x40
/* Define the CONFIG_LCD_NOKIADBG to enable detailed debug output (stuff you
* would never want to see unless you are debugging this file).
*
@ -80,6 +91,84 @@
# define lcd_dumpgpio(m)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nokia_blinitialize
*
* Description:
* Initialize PWM1 to manage the LCD backlight.
*
****************************************************************************/
void nokia_blinitialize(void)
{
uint32_t regval;
/* Enable clocking of PWM1 */
regval = regreg32(LPC17_SYSCON_PCONP);
regval |= SYSCON_PCONP_PCPWM1;
putreg32(regval, LPC17_SYSCON_PCONP);
/* Disable and reset PWM1 */
regval = getreg32(LPC17_PWM1_TCR);
regval &= ~(PWM_TCR_PWMEN|PWM_TCR_CNTREN);
regval |= PWM_TCR_CNTRRST;
putreg32(regval, LPC17_PWM1_TCR);
/* Put PWM1 in timer mode */
regval = getreg32(LPC17_PWM1_CTCR);
regval &= ~PWM_CTCR_MODE_MASK;
regval |= PWM_CTCR_MODE_TIMER;
putreg32(regval, LPC17_PWM1_CTCR);
/* Reset on MR0 */
putreg32(PWM_MCR_MR0R, LPC17_PWM1_MCR);
/* Single edge controlled mod for PWM3 and enable output */
regval = getreg32(LPC17_PWM1_PCR);
regval &= ~PWM_PCR_SEL3;
regval |= PWM_PCR_ENA3;
putreg32(regval, LPC17_PWM1_PCR);
/* Clear prescaler */
putreg32(0, LPC17_PWM1_PR);
/* Set 8-bit resolution */
putreg32(0xff, LPC17_PWM1_MCR);
/* Enable PWM match 1 latch */
regval = getreg32(LPC17_PWM1_LER);
regval |= PWM_LER_M0EN;
putreg32(regval, LPC17_PWM1_LER);
/* Clear match register 3 */
putreg32(0, LPC17_PWM1_MR3);
/* Enable PWM1 */
regval |= PWM_LER_M3EN;
putreg32(regval, LPC17_PWM1_LER);
regval = getreg32(LPC17_PWM1_TCR);
regval &= ~(PWM_TCR_CNTRRST);
regval |= (PWM_TCR_PWMEN|PWM_TCR_CNTREN);
putreg32(regval, LPC17_PWM1_TCR);
nokia_backlight(0);
}
/****************************************************************************
* Public Functions
****************************************************************************/
@ -111,6 +200,10 @@ FAR struct lcd_dev_s *up_nxdrvinit(unsigned int devno)
lpc17_gpiowrite(LPC1766STK_LCD_RST, true);
up_msdelay(5);
/* Configure PWM1 to support the backlight */
nokia_blinitialize();
/* Get the SSP port (configure as a Freescale SPI port) */
spi = up_spiinitialize(0);
@ -140,4 +233,30 @@ FAR struct lcd_dev_s *up_nxdrvinit(unsigned int devno)
return NULL;
}
/****************************************************************************
* Name: nokia_backlight
*
* Description:
* The Nokia 6100 backlight is controlled by logic outside of the LCD
* assembly. This function must be provided by board specific logic to
* manage the backlight. This function will receive a power value (0:
* full off - CONFIG_LCD_MAXPOWER: full on) and should set the backlight
* accordingly.
*
* On the Olimex LPC1766STK, the backlight level is controlled by PWM1.
*
****************************************************************************/
int nokia_backlight(unsigned int power)
{
uint32_t regval;
putreg32(NOKIA_BACKLIGHT_OFF + power, LPC17_PWM1_MR3);
regval = getreg32(LPC17_PWM1_LER);
regval |= PWM_LER_M3EN;
putreg32(regval, LPC17_PWM1_LER);
return OK;
}
#endif /* CONFIG_NX_LCDDRIVER && CONFIG_LCD_NOKIA6100 && CONFIG_LPC17_SSP0 */