parent
84fb2fa41e
commit
f6faddb190
|
@ -7,3 +7,4 @@ firmware.elf
|
||||||
*.a
|
*.a
|
||||||
*.swp
|
*.swp
|
||||||
lpc1xxx/memory.ld
|
lpc1xxx/memory.ld
|
||||||
|
modules/wrapper.c
|
||||||
|
|
|
@ -11,6 +11,7 @@ OBJS += orbitron14.o
|
||||||
OBJS += display.o
|
OBJS += display.o
|
||||||
OBJS += render.o
|
OBJS += render.o
|
||||||
OBJS += decoder.o
|
OBJS += decoder.o
|
||||||
|
OBJS += backlight.o
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# GNU GCC compiler flags
|
# GNU GCC compiler flags
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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_ */
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue