2011-05-20 22:53:09 +00:00
|
|
|
#include <sysinit.h>
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-20 23:12:09 +00:00
|
|
|
#include "basic/basic.h"
|
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
#include "lcd/render.h"
|
|
|
|
#include "lcd/smallfonts.h"
|
|
|
|
#include "lcd/ubuntu18.h"
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
#include "pmu/pmu.h"
|
|
|
|
#include "eeprom/eeprom.h"
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
void ReinvokeISP(void);
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
/**************************************************************************/
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
int main(void) {
|
|
|
|
// Configure cpu and mandatory peripherals
|
|
|
|
systemInit();
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
//enable clocks to adc and watchdog
|
|
|
|
pmuInit();
|
2011-05-12 00:24:35 +00:00
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
// initialise basic badge functions
|
|
|
|
rbInit();
|
|
|
|
|
2011-05-20 23:12:09 +00:00
|
|
|
lcdInit(); // display
|
2011-05-20 22:53:09 +00:00
|
|
|
|
|
|
|
//Make PIO1_11 an analog input
|
|
|
|
gpioSetDir(RB_LED3, gpioDirection_Input);
|
|
|
|
IOCON_PIO1_11 = 0x41;
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
adcInit();
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-20 23:12:09 +00:00
|
|
|
lcdFill(255);
|
|
|
|
lcdDisplay(0);
|
2011-05-20 22:53:09 +00:00
|
|
|
uint32_t j=0;
|
2011-05-18 22:20:10 +00:00
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
//disable the JTAG on PIO3_3
|
|
|
|
IOCON_PIO3_3 = 0x10;
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
int yctr=8;
|
|
|
|
int dx=0;
|
2011-05-19 12:05:28 +00:00
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
font_direction = FONT_DIR_LTR; // LeftToRight is the default
|
|
|
|
font = &Font_8x8;
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
static FONT fonts[] = {
|
|
|
|
&Font_7x8,
|
|
|
|
&Font_Ubuntu18pt, // 3 byte-font
|
|
|
|
&Font_8x8,
|
|
|
|
};
|
|
|
|
|
|
|
|
int fontctr=0;
|
|
|
|
yctr=18;
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-19 12:05:28 +00:00
|
|
|
uint8_t written = 0;
|
|
|
|
uint8_t eeprom_val = 0;
|
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
while (1) {
|
2011-05-20 23:12:09 +00:00
|
|
|
lcdDisplay(j);
|
2011-05-20 22:53:09 +00:00
|
|
|
delayms(10);
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-12 00:24:35 +00:00
|
|
|
font=fonts[fontctr];
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
if (!written) {
|
|
|
|
if (eeprom_ready()) {
|
|
|
|
if (eeprom_write_byte(127,15,42)) {
|
|
|
|
DoString(1, yctr, "Write OK!");
|
|
|
|
written++;
|
|
|
|
} else {
|
|
|
|
DoString(1, yctr, "Write NOK!");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DoString(1, yctr, "NOT READY!");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (eeprom_ready()) {
|
|
|
|
if (eeprom_read_byte(127,15,&eeprom_val)) {
|
|
|
|
if (eeprom_val == 42) {
|
|
|
|
DoString(1, yctr, "verified!");
|
|
|
|
} else {
|
|
|
|
DoString(1, yctr, "failed!");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DoString(1, yctr, "Read NOK!");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DoString(1, yctr, "NOT READY!!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(1 && gpioGetValue(RB_LED3) == 0){
|
|
|
|
gpioSetValue (RB_LED3, 0);
|
|
|
|
while(gpioGetValue(RB_LED3) == 0){
|
|
|
|
};
|
|
|
|
gpioSetValue (RB_LED3, 1);
|
2011-05-20 23:12:09 +00:00
|
|
|
lcdFill(255);
|
2011-05-12 00:24:35 +00:00
|
|
|
fontctr++;
|
2011-05-20 22:53:09 +00:00
|
|
|
if(fontctr > 2) {
|
|
|
|
fontctr = 0;
|
|
|
|
}
|
2011-05-11 21:24:05 +00:00
|
|
|
};
|
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
uint32_t results = adcRead(7);
|
|
|
|
|
|
|
|
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 ");
|
|
|
|
}
|
2011-05-11 21:24:05 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-05-20 22:53:09 +00:00
|
|
|
return 0;
|
2011-05-11 21:24:05 +00:00
|
|
|
|
|
|
|
}
|