Clean up my experiment module

This commit is contained in:
Stefan `Sec` Zehl 2011-06-13 23:59:02 +02:00
parent 4cd3460138
commit b861fecbc4
1 changed files with 49 additions and 91 deletions

View File

@ -5,21 +5,14 @@
#include "lcd/render.h" #include "lcd/render.h"
#include "lcd/allfonts.h" #include "lcd/allfonts.h"
void ReinvokeISP(void); void backlightInit(void);
void EnableWatchdog(uint32_t ms);
void delayms(uint32_t ms);
/**************************************************************************/ /**************************************************************************/
void module_sec(void) { void module_sec(void) {
//Make PIO1_11 an analog input
gpioSetDir(RB_LED3, gpioDirection_Input);
IOCON_PIO1_11 = 0x41;
backlightInit(); backlightInit();
uint32_t j=0;
//disable the JTAG on PIO3_3 //disable the JTAG on PIO3_3
IOCON_PIO3_3 = 0x10; IOCON_PIO3_3 = 0x10;
@ -27,105 +20,70 @@ void module_sec(void) {
int dx=0; int dx=0;
font_direction = FONT_DIR_LTR; // LeftToRight is the default font_direction = FONT_DIR_LTR; // LeftToRight is the default
font = &Font_8x8;
static FONT fonts[] = {
&Font_7x8,
&Font_Ubuntu18pt, // 3 byte-font
&Font_8x8,
};
int fontctr=0;
yctr=18; yctr=18;
uint8_t trigger; uint8_t trigger;
#define SEND trigger=20;
#ifdef SEND
trigger=200;
gpioSetDir(RB_LED0, gpioDirection_Output);
IOCON_JTAG_TDI_PIO0_11 = 0x11;
#else
trigger=380;
gpioSetDir(RB_LED0, gpioDirection_Input);
IOCON_JTAG_TDI_PIO0_11 = 0x42;
#endif
uint32_t ctr=0; uint32_t ctr=0;
char key;
while (1) { while (1) {
ctr++; ctr++;
uint32_t results;
lcdDisplay(j);
delayms(10);
font=fonts[fontctr]; lcdDisplay(0);
delayms(10);
if(gpioGetValue(RB_BTN3)==0){ key= getInput();
while(gpioGetValue(RB_BTN3)==0); if(key==BTN_UP){
trigger +=10; trigger +=1;
}; }else if (key ==BTN_DOWN){
if(gpioGetValue(RB_BTN2)==0){ trigger -=1;
while(gpioGetValue(RB_BTN2)==0); };
trigger -=10;
};
dx=DoString(0,0,"Trig:");
dx=DoInt(dx,0,trigger);
DoString(dx,0," ");
if(gpioGetValue(RB_BTN0)==0){ font=&Font_7x8;
while(gpioGetValue(RB_BTN0)==0); dx=DoString(0,0,"Trig:");
DoString(0,8,"Enter ISP!"); dx=DoInt(dx,0,trigger);
lcdDisplay(0); DoString(dx,0," ");
EnableWatchdog(1000*5);
ReinvokeISP();
};
font = &Font_Ubuntu36pt; // Easy flashing
dx=DoString(0,0,"Sec"); if(key==BTN_LEFT){
#ifdef SEND DoString(0,8,"Enter ISP!");
if(ctr++>trigger/10){ lcdDisplay(0);
ctr=0; ISPandReset(5);
if (gpioGetValue(RB_LED0) == CFG_LED_OFF){ };
gpioSetValue (RB_LED0, CFG_LED_ON);
// DoString(dx,14,"ON!");
} else {
gpioSetValue (RB_LED0, CFG_LED_OFF);
// DoString(dx,14,"off");
};
};
#else
results = adcRead(0);
DoInt(dx,20,results);
if(results>trigger){ // Display nickname
DoString(dx,30,"YES!"); font = &Font_Ubuntu36pt;
}else{ dx=DoString(0,0,"Sec");
DoString(dx,30," no ");
};
#endif // Blink LED
font = &Font_7x8; if(ctr++>trigger){
ctr=0;
if (gpioGetValue(RB_LED2) == CFG_LED_OFF){
gpioSetValue (RB_LED2, CFG_LED_ON);
} else {
gpioSetValue (RB_LED2, CFG_LED_OFF);
};
};
results = adcRead(1); // Print Voltage
dx=DoString(0,yctr+28,"Voltage:"); font = &Font_7x8;
results *= 10560; dx=DoString(0,yctr+28,"Voltage:");
results /= 1024; DoInt(dx,yctr+28,GetVoltage());
DoInt(dx,yctr+28,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; return;
} }
void tick_sec(void){
static int foo=0;
static int toggle=0;
if(foo++>50){
toggle=1-toggle;
foo=0;
gpioSetValue (RB_LED0, toggle);
};
return;
};