2011-05-11 21:24:05 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "sysinit.h"
|
|
|
|
|
|
|
|
#include "core/gpio/gpio.h"
|
|
|
|
#include "core/adc/adc.h"
|
|
|
|
#include "core/systick/systick.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);
|
|
|
|
|
2011-05-12 00:24:35 +00:00
|
|
|
#include <lcd/render.h>
|
2011-05-11 21:24:05 +00:00
|
|
|
#include <lcd/smallfonts.h>
|
2011-05-13 13:20:34 +00:00
|
|
|
#include <lcd/vera17.h>
|
2011-05-14 20:24:45 +00:00
|
|
|
#include <lcd/comic15.h>
|
2011-05-12 00:24:35 +00:00
|
|
|
|
2011-05-11 21:24:05 +00:00
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
// Configure cpu and mandatory peripherals
|
|
|
|
systemInit();
|
|
|
|
//pmuInit();
|
|
|
|
|
|
|
|
uint32_t currentSecond, lastSecond;
|
|
|
|
currentSecond = lastSecond = 0;
|
|
|
|
|
|
|
|
//external vcc on
|
|
|
|
gpioSetDir(1, 9, 1);
|
|
|
|
gpioSetValue (1, 9, 0);
|
|
|
|
|
|
|
|
//backlight off
|
|
|
|
gpioSetDir(1, 10, 1);
|
|
|
|
gpioSetValue (1, 10, 1);
|
|
|
|
|
|
|
|
//gpioSetDir(0, 1, 0);
|
|
|
|
//gpioSetValue (0, 1, 1);
|
|
|
|
|
|
|
|
//gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON);
|
|
|
|
// gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, 0);
|
|
|
|
//pmuSleep();
|
|
|
|
//pmuPowerDown();
|
|
|
|
init(); // display
|
2011-05-12 00:24:35 +00:00
|
|
|
/*
|
2011-05-11 21:24:05 +00:00
|
|
|
gpioSetDir(CFG_LED_PORT, CFG_LED_PIN, 0);
|
|
|
|
IOCON_PIO1_11 = 0x41;
|
|
|
|
adcInit();
|
2011-05-12 00:24:35 +00:00
|
|
|
*/
|
|
|
|
fill(255);
|
2011-05-11 21:24:05 +00:00
|
|
|
display(0);
|
|
|
|
uint32_t j=0;
|
|
|
|
|
|
|
|
// Set GPIO1.4 to input
|
|
|
|
gpioSetDir(3, 3, gpioDirection_Input);
|
|
|
|
// Disable the internal pullup/down resistor
|
|
|
|
// gpioSetPullup(&IOCON_PIO3_3, gpioPullupMode_Inactive);
|
|
|
|
IOCON_PIO3_3 = 0x10;
|
|
|
|
|
|
|
|
int yctr=0;
|
|
|
|
int dx=0;
|
|
|
|
|
|
|
|
font_direction=FONT_DIR_LTR; // LeftToRight is the default
|
|
|
|
font= &Font_8x8 ;
|
2011-05-12 00:24:35 +00:00
|
|
|
/*
|
2011-05-11 21:24:05 +00:00
|
|
|
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;
|
2011-05-12 00:24:35 +00:00
|
|
|
*/
|
2011-05-11 21:24:05 +00:00
|
|
|
|
|
|
|
yctr+=1;
|
2011-05-12 00:24:35 +00:00
|
|
|
yctr=8;
|
2011-05-11 21:24:05 +00:00
|
|
|
|
|
|
|
/* Read & display serial number */
|
|
|
|
#include "core/iap/iap.h"
|
|
|
|
|
2011-05-12 00:24:35 +00:00
|
|
|
/*
|
2011-05-11 21:24:05 +00:00
|
|
|
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;
|
|
|
|
};
|
2011-05-12 00:24:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static FONT fonts[]=
|
|
|
|
{
|
2011-05-14 20:24:45 +00:00
|
|
|
& Font_8x8,
|
2011-05-13 13:20:34 +00:00
|
|
|
& Font_Vera17pt, // 3 byte-font
|
2011-05-14 20:24:45 +00:00
|
|
|
& Font_Comic15pt,
|
2011-05-12 00:24:35 +00:00
|
|
|
};
|
|
|
|
int fontctr=0;
|
2011-05-14 20:24:45 +00:00
|
|
|
yctr=18;
|
2011-05-11 21:24:05 +00:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
display(j);
|
|
|
|
delayms(10);
|
|
|
|
// Toggle LED once per second ... rollover = 136 years :)
|
2011-05-12 00:24:35 +00:00
|
|
|
/*
|
2011-05-11 21:24:05 +00:00
|
|
|
currentSecond = systickGetSecondsActive();
|
|
|
|
if (currentSecond != lastSecond){
|
|
|
|
dx=DoString(0,yctr,"UP:");
|
|
|
|
DoInt(dx,yctr,currentSecond);
|
|
|
|
};
|
2011-05-12 00:24:35 +00:00
|
|
|
*/
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-12 00:24:35 +00:00
|
|
|
font=fonts[fontctr];
|
2011-05-13 13:20:34 +00:00
|
|
|
DoString(1,yctr,"Hey Y!");
|
2011-05-11 21:24:05 +00:00
|
|
|
|
2011-05-12 00:24:35 +00:00
|
|
|
if(1 && gpioGetValue(3,3)==0){
|
2011-05-11 21:24:05 +00:00
|
|
|
gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON);
|
|
|
|
while(gpioGetValue(3,3)==0);
|
|
|
|
gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF);
|
2011-05-14 20:24:45 +00:00
|
|
|
fill(255);
|
2011-05-12 00:24:35 +00:00
|
|
|
fontctr++;
|
2011-05-13 13:20:34 +00:00
|
|
|
// yctr++;
|
2011-05-14 20:24:45 +00:00
|
|
|
if(fontctr>2)
|
2011-05-12 00:24:35 +00:00
|
|
|
fontctr=0;
|
2011-05-11 21:24:05 +00:00
|
|
|
};
|
|
|
|
|
2011-05-12 00:24:35 +00:00
|
|
|
/*
|
2011-05-11 21:24:05 +00:00
|
|
|
uint32_t results = adcRead(7);
|
|
|
|
dx=DoString(0,yctr+9,"LED:");
|
|
|
|
DoInt(dx,yctr+9,results);
|
2011-05-12 00:24:35 +00:00
|
|
|
*/
|
2011-05-11 21:24:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
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 */
|
|
|
|
typedef void (*IAP)(uint32_t [], uint32_t []);
|
|
|
|
IAP my_iap_entry = (IAP)0x1fff1ff1;
|
|
|
|
uint32_t command[5], result[4];
|
|
|
|
|
|
|
|
/* This function resets some microcontroller peripherals to reset
|
|
|
|
hardware configuration to ensure that the USB In-System Programming module
|
|
|
|
will work properly. It is normally called from reset and assumes some reset
|
|
|
|
configuration settings for the MCU.
|
|
|
|
Some of the peripheral configurations may be redundant in your specific
|
|
|
|
project.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ReinvokeISP(void)
|
|
|
|
{
|
|
|
|
command[0] = 57;
|
|
|
|
/* Disable SYSTICK timer and interrupt before calling into ISP */
|
|
|
|
SYSTICK_STCTRL &= ~(SYSTICK_STCTRL_ENABLE | SYSTICK_STCTRL_TICKINT);
|
|
|
|
/* make sure USB clock is turned on before calling ISP */
|
|
|
|
SCB_SYSAHBCLKCTRL |= 0x04000;
|
|
|
|
/* make sure 32-bit Timer 1 is turned on before calling ISP */
|
|
|
|
SCB_SYSAHBCLKCTRL |= 0x00400;
|
|
|
|
/* make sure GPIO clock is turned on before calling ISP */
|
|
|
|
SCB_SYSAHBCLKCTRL |= 0x00040;
|
|
|
|
/* make sure IO configuration clock is turned on before calling ISP */
|
|
|
|
SCB_SYSAHBCLKCTRL |= 0x10000;
|
|
|
|
/* make sure AHB clock divider is 1:1 */
|
|
|
|
SCB_SYSAHBCLKDIV = 1;
|
|
|
|
/* Send Reinvoke ISP command to ISP entry point*/
|
|
|
|
gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON);
|
|
|
|
|
|
|
|
/* Set stack pointer to ROM value (reset default) This must be the last
|
|
|
|
piece of code executed before calling ISP, because most C expressions
|
|
|
|
and function returns will fail after the stack pointer is changed. */
|
|
|
|
// __set_MSP(*((uint32_t *)0x1FFF0000)); /* inline asm function */
|
|
|
|
|
|
|
|
*((uint32_t *)(0x10000054)) = 0x0;
|
|
|
|
|
|
|
|
//set stack pointer
|
|
|
|
__asm(" ldr r0, =%0\n"
|
|
|
|
" mov sp, r0\n"
|
|
|
|
:
|
|
|
|
: "i" (0x1FFF0000));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Enter ISP. We call "iap_entry" to enter ISP because the ISP entry is done
|
|
|
|
through the same command interface as IAP. */
|
|
|
|
__asm(
|
|
|
|
" ldr r0, =0x39\n"
|
|
|
|
" ldr r1, =0x39\n"
|
|
|
|
" ldr r2, =0x39\n"
|
|
|
|
" ldr r3, =0x39\n"
|
|
|
|
" push {r3}\n"
|
|
|
|
" ldr r4,=0x1fff1ff1\n"
|
|
|
|
" bx r4\n"
|
|
|
|
);
|
|
|
|
// my_iap_entry(command, result);
|
|
|
|
// Not supposed to come back!
|
|
|
|
}
|
|
|
|
|