2011-05-21 15:26:37 +00:00
|
|
|
/*
|
|
|
|
* Based on microbuilders PWM example.
|
|
|
|
*/
|
|
|
|
#include "lpc134x.h"
|
|
|
|
#include "sysdefs.h"
|
2011-06-12 20:54:41 +00:00
|
|
|
#include "core/gpio/gpio.h"
|
|
|
|
#include "basic/basic.h"
|
2011-05-21 15:26:37 +00:00
|
|
|
|
|
|
|
uint32_t brightness = 100;
|
|
|
|
|
|
|
|
void backlightInit(void) {
|
|
|
|
/* Enable the clock for CT16B1 */
|
|
|
|
SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT16B1);
|
|
|
|
|
2011-06-12 20:54:41 +00:00
|
|
|
/* Configure PIO1.9 as Timer1_16 MAT0 Output */
|
|
|
|
IOCON_PIO1_9 &= ~IOCON_PIO1_9_FUNC_MASK;
|
|
|
|
IOCON_PIO1_9 |= IOCON_PIO1_9_FUNC_CT16B1_MAT0;
|
2011-05-21 15:26:37 +00:00
|
|
|
|
|
|
|
/* Set default duty cycle (MR1) */
|
2011-06-12 20:54:41 +00:00
|
|
|
TMR_TMR16B1MR0 = (0xFFFF * (100 - brightness)) / 100;
|
2011-05-21 15:26:37 +00:00
|
|
|
|
|
|
|
/* External Match Register Settings for PWM */
|
2011-06-12 20:54:41 +00:00
|
|
|
TMR_TMR16B1EMR = TMR_TMR16B1EMR_EMC0_TOGGLE | TMR_TMR16B1EMR_EM0;
|
2011-05-21 15:26:37 +00:00
|
|
|
|
|
|
|
/* enable Timer1 */
|
|
|
|
TMR_TMR16B1TCR = TMR_TMR16B1TCR_COUNTERENABLE_ENABLED;
|
|
|
|
|
2011-06-12 20:54:41 +00:00
|
|
|
/* Enable PWM0 */
|
|
|
|
TMR_TMR16B1PWMC = TMR_TMR16B1PWMC_PWM0_ENABLED;
|
|
|
|
|
|
|
|
// Enable Step-UP
|
|
|
|
gpioSetDir(RB_PWR_LCDBL, gpioDirection_Output);
|
|
|
|
gpioSetValue(RB_PWR_LCDBL, 0);
|
2011-05-21 15:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int backlightSetBrightness(uint32_t percentage) {
|
2011-06-12 20:54:41 +00:00
|
|
|
if ((percentage < 0) || (percentage > 100)) {
|
2011-05-21 15:26:37 +00:00
|
|
|
/* brightness must be a value between 1 and 100 */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-06-12 20:54:41 +00:00
|
|
|
if( percentage == 0 ){
|
|
|
|
gpioSetDir(RB_PWR_LCDBL, gpioDirection_Input);
|
|
|
|
}else{
|
|
|
|
gpioSetDir(RB_PWR_LCDBL, gpioDirection_Output);
|
|
|
|
gpioSetValue(RB_PWR_LCDBL, 0);
|
|
|
|
}
|
|
|
|
|
2011-05-21 15:26:37 +00:00
|
|
|
/* Set Duty Cycle (MR1) */
|
2011-06-12 20:54:41 +00:00
|
|
|
TMR_TMR16B1MR0 = (0xFFFF * (100 - (brightness = percentage))) / 100;
|
2011-05-21 15:26:37 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t backlightGetBrightness(void) {
|
|
|
|
return brightness;
|
|
|
|
}
|