added LCD backlight driver

see example in module/bsx.c
This commit is contained in:
bsx 2011-05-21 17:26:37 +02:00
parent 84fb2fa41e
commit f6faddb190
5 changed files with 128 additions and 0 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ firmware.elf
*.a
*.swp
lpc1xxx/memory.ld
modules/wrapper.c

View File

@ -11,6 +11,7 @@ OBJS += orbitron14.o
OBJS += display.o
OBJS += render.o
OBJS += decoder.o
OBJS += backlight.o
##########################################################################
# GNU GCC compiler flags

44
lcd/backlight.c Normal file
View File

@ -0,0 +1,44 @@
/*
* Based on microbuilders PWM example.
*/
#include "lpc134x.h"
#include "sysdefs.h"
uint32_t brightness = 100;
void backlightInit(void) {
/* Enable the clock for CT16B1 */
SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT16B1);
/* Configure PIO1.10 as Timer1_16 MAT1 Output */
IOCON_PIO1_10 &= ~IOCON_PIO1_10_FUNC_MASK;
IOCON_PIO1_10 |= IOCON_PIO1_10_FUNC_CT16B1_MAT1;
/* Set default duty cycle (MR1) */
TMR_TMR16B1MR1 = (0xFFFF * (100 - brightness)) / 100;
/* External Match Register Settings for PWM */
TMR_TMR16B1EMR = TMR_TMR16B1EMR_EMC1_TOGGLE | TMR_TMR16B1EMR_EM1;
/* enable Timer1 */
TMR_TMR16B1TCR = TMR_TMR16B1TCR_COUNTERENABLE_ENABLED;
/* Enable PWM1 */
TMR_TMR16B1PWMC = TMR_TMR16B1PWMC_PWM1_ENABLED;
}
int backlightSetBrightness(uint32_t percentage) {
if ((percentage < 1) || (percentage > 100)) {
/* brightness must be a value between 1 and 100 */
return -1;
}
/* Set Duty Cycle (MR1) */
TMR_TMR16B1MR1 = (0xFFFF * (100 - (brightness = percentage))) / 100;
return 0;
}
uint32_t backlightGetBrightness(void) {
return brightness;
}

8
lcd/backlight.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef __BACKLIGHT_H_
#define __BACKLIGHT_H_ 1
void backlightInit(void);
int backlightSetBrightness(uint32_t percentage);
uint32_t backlightGetBrightness(void);
#endif /* __BACKLIGHT_H_ */

74
modules/bsx.c Normal file
View File

@ -0,0 +1,74 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/render.h"
#include "lcd/backlight.h"
#include "lcd/smallfonts.h"
void ReinvokeISP(void);
/**************************************************************************/
void module_bsx(void) {
int yctr = 18;
int dx = 0;
uint32_t brightness = 0;
font_direction = FONT_DIR_LTR; // LeftToRight is the default
font = &Font_7x8;
DoString(0, 0, "bsx");
backlightInit();
brightness = backlightGetBrightness();
while (1) {
uint32_t results;
lcdDisplay(0);
delayms(10);
if(gpioGetValue(RB_BTN1)==0){
brightness++;
if (brightness > 100) brightness = 100;
backlightSetBrightness(brightness);
};
if(gpioGetValue(RB_BTN0)==0){
brightness--;
if (brightness > 100) brightness = 0;
backlightSetBrightness(brightness);
};
if (gpioGetValue(RB_BTN4)==0) {
while(gpioGetValue(RB_BTN4)==0);
DoString(0,8,"Enter ISP!");
lcdDisplay(0);
ReinvokeISP();
};
dx = DoString(0, yctr, "Bright:");
dx = DoInt(dx, yctr, brightness);
DoString(dx, yctr, "% ");
results = adcRead(1);
dx=DoString(0,yctr+20,"Voltage:");
results *= 10560;
results /= 1024;
DoInt(dx,yctr+20,results);
if (results < 3500) {
DoString(0,yctr+30,"Shutdown");
gpioSetValue (RB_PWR_GOOD, 0);
gpioSetValue (RB_LCD_BL, 0);
SCB_SCR |= SCB_SCR_SLEEPDEEP;
PMU_PMUCTRL = PMU_PMUCTRL_DPDEN_DEEPPOWERDOWN;
__asm volatile ("WFI");
} else {
DoString(0,yctr+30,"OK ");
}
}
return;
}