use basic/basic

indent
removed unused stuff
This commit is contained in:
kiu 2011-05-21 00:53:09 +02:00
parent 53c678cef5
commit dd5b101589
1 changed files with 96 additions and 207 deletions

303
main.c
View File

@ -1,238 +1,128 @@
#include <stdlib.h> #include <sysinit.h>
#include <stdio.h>
#include <string.h>
#include "sysinit.h" #include "lcd/render.h"
#include "lcd/smallfonts.h"
#include "lcd/ubuntu18.h"
#include "core/gpio/gpio.h" #include "pmu/pmu.h"
#include "core/adc/adc.h" #include "eeprom/eeprom.h"
#include "core/systick/systick.h" #include "basic/basic.h"
#include "lpc134x.h"
#include "sysdefs.h"
#define CFG_LED_PORT (1)
#define CFG_LED_PIN (11)
#define CFG_LED_ON (1)
#define CFG_LED_OFF (0)
void ReinvokeISP(void); void ReinvokeISP(void);
#include <lcd/render.h>
#include <lcd/smallfonts.h>
#include <lcd/ubuntu18.h>
#include "core/i2c/i2c.h"
#include "eeprom/eeprom.h"
/**************************************************************************/ /**************************************************************************/
int main(void) int main(void) {
{ // Configure cpu and mandatory peripherals
// Configure cpu and mandatory peripherals systemInit();
systemInit();
//enable clocks to adc and watchdog //enable clocks to adc and watchdog
pmuInit(); pmuInit();
//enable I2C // initialise basic badge functions
i2cInit(I2CMASTER); rbInit();
uint32_t currentSecond, lastSecond; init(); // display
currentSecond = lastSecond = 0;
//external vcc on //Make PIO1_11 an analog input
gpioSetDir(1, 9, 1); gpioSetDir(RB_LED3, gpioDirection_Input);
gpioSetValue (1, 9, 0); IOCON_PIO1_11 = 0x41;
//backlight on adcInit();
gpioSetDir(1, 10, 1);
gpioSetValue (1, 10, 1);
//gpioSetDir(0, 1, 0); fill(255);
//gpioSetValue (0, 1, 1); display(0);
uint32_t j=0;
//gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); //disable the JTAG on PIO3_3
// gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, 0); IOCON_PIO3_3 = 0x10;
//pmuSleep();
//pmuPowerDown();
init(); // display
//Make PIO1_11 an analog input int yctr=8;
gpioSetDir(CFG_LED_PORT, CFG_LED_PIN, 0); int dx=0;
IOCON_PIO1_11 = 0x41;
adcInit();
fill(255); font_direction = FONT_DIR_LTR; // LeftToRight is the default
display(0); font = &Font_8x8;
uint32_t j=0;
// Set GPIO3.3 to input static FONT fonts[] = {
gpioSetDir(3, 3, gpioDirection_Input); &Font_7x8,
// Disable the internal pullup/down resistor &Font_Ubuntu18pt, // 3 byte-font
// gpioSetPullup(&IOCON_PIO3_3, gpioPullupMode_Inactive); &Font_8x8,
//disable the JTAG on PIO3_3 };
IOCON_PIO3_3 = 0x10;
int yctr=0; int fontctr=0;
int dx=0; yctr=18;
font_direction=FONT_DIR_LTR; // LeftToRight is the default
font= &Font_8x8 ;
/*
DoString(0,yctr,"Hallo Welt");
yctr+=9;
font= &Font_8x8Thin ;
DoString(0,yctr,"Hallo Welt");
yctr+=9;
font= &Font_7x8;
DoString(0,yctr,"Hallo Welt");
yctr+=9;
font= &Font_5x8;
DoString(0,yctr,"Hallo Welt");
yctr+=9;
font= &Font_3x6;
DoString(0,yctr,"HALLO WELT");
yctr+=6;
*/
yctr+=1;
yctr=8;
/* Read & display serial number */
#include "core/iap/iap.h"
/*
IAP_return_t iap_return;
iap_return = iapReadSerialNumber();
if (iap_return.ReturnCode == 0) {
int x,y;
font= &Font_3x6;
x=RESX-(8*font->u8Width)-1;y=28;
dx=DoIntX(x,y,iap_return.Result[0]); y+=font->u8Height;
dx=DoIntX(x,y,iap_return.Result[1]); y+=font->u8Height;
dx=DoIntX(x,y,iap_return.Result[2]); y+=font->u8Height;
dx=DoIntX(x,y,iap_return.Result[3]); y+=font->u8Height;
font= &Font_7x8;
};
*/
static FONT fonts[]=
{
& Font_7x8,
& Font_Ubuntu18pt, // 3 byte-font
& Font_8x8,
};
int fontctr=0;
yctr=18;
uint8_t written = 0; uint8_t written = 0;
uint8_t eeprom_val = 0; uint8_t eeprom_val = 0;
while (1) while (1) {
{ display(j);
display(j); delayms(10);
delayms(10);
// Toggle LED once per second ... rollover = 136 years :)
/*
currentSecond = systickGetSecondsActive();
if (currentSecond != lastSecond){
dx=DoString(0,yctr,"UP:");
DoInt(dx,yctr,currentSecond);
};
*/
font=fonts[fontctr]; font=fonts[fontctr];
//DoString(1,yctr,"Hey Y!");
if (!written) { if (!written) {
if (eeprom_ready()) { if (eeprom_ready()) {
if (eeprom_write_byte(127,15,42)) { if (eeprom_write_byte(127,15,42)) {
DoString(1, yctr, "Write OK!"); DoString(1, yctr, "Write OK!");
written++; written++;
} else { } else {
DoString(1, yctr, "Write NOK!"); DoString(1, yctr, "Write NOK!");
} }
} else { } else {
DoString(1, yctr, "NOT READY!"); DoString(1, yctr, "NOT READY!");
} }
} else { } else {
if (eeprom_ready()) { if (eeprom_ready()) {
if (eeprom_read_byte(127,15,&eeprom_val)) { if (eeprom_read_byte(127,15,&eeprom_val)) {
if (eeprom_val == 42) { if (eeprom_val == 42) {
DoString(1, yctr, "verified!"); DoString(1, yctr, "verified!");
} else { } else {
DoString(1, yctr, "failed!"); DoString(1, yctr, "failed!");
} }
} else { } else {
DoString(1, yctr, "Read NOK!"); DoString(1, yctr, "Read NOK!");
} }
} else { } else {
DoString(1, yctr, "NOT READY!!"); DoString(1, yctr, "NOT READY!!");
} }
} }
if(1 && gpioGetValue(3,3)==0){ if(1 && gpioGetValue(RB_LED3) == 0){
gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); gpioSetValue (RB_LED3, 0);
while(gpioGetValue(3,3)==0); while(gpioGetValue(RB_LED3) == 0){
gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); };
gpioSetValue (RB_LED3, 1);
fill(255); fill(255);
fontctr++; fontctr++;
// yctr++; if(fontctr > 2) {
if(fontctr>2) fontctr = 0;
fontctr=0; }
}; };
uint32_t results = adcRead(7); uint32_t results = adcRead(7);
//dx=DoString(0,yctr+10,"LED:");
//DoInt(dx,yctr+9,results);
results = adcRead(1); results = adcRead(1);
dx=DoString(0,yctr+20,"Voltage:"); dx=DoString(0,yctr+20,"Voltage:");
results *= 10560; results *= 10560;
results /= 1024; results /= 1024;
DoInt(dx,yctr+20,results); 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 ");
}
if( results < 3500 ){
DoString(0,yctr+30,"Shutdown");
//external vcc off
gpioSetDir(1, 9, 0);
gpioSetValue (1, 9, 0);
//backlight off
gpioSetValue (1, 10, 0);
SCB_SCR |= SCB_SCR_SLEEPDEEP;
PMU_PMUCTRL = PMU_PMUCTRL_DPDEN_DEEPPOWERDOWN;
__asm volatile ("WFI");
}else{
DoString(0,yctr+30,"OK ");
} }
/* return 0;
lastSecond = currentSecond;
yctr++;
// uint32_t results = adcRead(7);
// if( results < 400 )
// gpioSetValue (1, 10, 1);
// else
// gpioSetValue (1, 10, 0);
if (gpioGetValue(CFG_LED_PORT, CFG_LED_PIN) == CFG_LED_OFF)
{
gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON);
//gpioSetValue (1, 10, 1);
}
else
{
gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF);
//gpioSetValue (1, 10, 0);
}
}
*/
}
return 0;
} }
/* This data must be global so it is not read from the stack */ /* This data must be global so it is not read from the stack */
@ -248,8 +138,7 @@ uint32_t command[5], result[4];
project. project.
*/ */
void ReinvokeISP(void) void ReinvokeISP(void) {
{
command[0] = 57; command[0] = 57;
/* Disable SYSTICK timer and interrupt before calling into ISP */ /* Disable SYSTICK timer and interrupt before calling into ISP */
SYSTICK_STCTRL &= ~(SYSTICK_STCTRL_ENABLE | SYSTICK_STCTRL_TICKINT); SYSTICK_STCTRL &= ~(SYSTICK_STCTRL_ENABLE | SYSTICK_STCTRL_TICKINT);
@ -269,11 +158,12 @@ void ReinvokeISP(void)
/* Set stack pointer to ROM value (reset default) This must be the last /* Set stack pointer to ROM value (reset default) This must be the last
piece of code executed before calling ISP, because most C expressions piece of code executed before calling ISP, because most C expressions
and function returns will fail after the stack pointer is changed. */ and function returns will fail after the stack pointer is changed. */
// __set_MSP(*((uint32_t *)0x1FFF0000)); /* inline asm function */
*((uint32_t *)(0x10000054)) = 0x0; //__set_MSP(*((uint32_t *)0x1FFF0000)); /* inline asm function */
//set stack pointer *((uint32_t *)(0x10000054)) = 0x0;
//set stack pointer
__asm(" ldr r0, =%0\n" __asm(" ldr r0, =%0\n"
" mov sp, r0\n" " mov sp, r0\n"
: :
@ -292,7 +182,6 @@ void ReinvokeISP(void)
" ldr r4,=0x1fff1ff1\n" " ldr r4,=0x1fff1ff1\n"
" bx r4\n" " bx r4\n"
); );
// my_iap_entry(command, result); //my_iap_entry(command, result);
// Not supposed to come back! // Not supposed to come back!
} }