Merge branch 'master' of github.com:p42/project42

This commit is contained in:
Sebastian Steuer 2011-06-14 02:20:42 +02:00
commit dbe67406df
16 changed files with 215 additions and 152 deletions

View File

@ -7,9 +7,9 @@ OBJS = main.o
VPATH += VPATH +=
OBJS += OBJS +=
OBJS += basic/basic.o OBJS += basic/basic.o basic/reinvoke_isp.o basic/delayms.o basic/voltage.o
OBJS += basic/keyin.o
OBJS += eeprom/eeprom.o OBJS += eeprom/eeprom.o
OBJS += reinvoke_isp.o
LIBS += core/libcore.a lcd/liblcd.a modules/libmodules.a LIBS += core/libcore.a lcd/liblcd.a modules/libmodules.a
########################################################################## ##########################################################################

View File

@ -10,6 +10,9 @@ void rbInit() {
gpioSetDir(RB_PWR_GOOD, gpioDirection_Output); gpioSetDir(RB_PWR_GOOD, gpioDirection_Output);
gpioSetValue (RB_PWR_GOOD, 0); gpioSetValue (RB_PWR_GOOD, 0);
// Disable USB Connect (we don't want USB by default)
gpioSetDir(USB_CONNECT, gpioDirection_Output);
gpioSetValue(USB_CONNECT, 1);
// prepare buttons // prepare buttons
gpioSetDir(RB_BTN0, gpioDirection_Input); gpioSetDir(RB_BTN0, gpioDirection_Input);

View File

@ -114,6 +114,29 @@
#define RB_EEPROM_ADDR 0xA0 #define RB_EEPROM_ADDR 0xA0
#define USB_CONNECT 0,6
void rbInit(void); void rbInit(void);
// reinvoke_isp.c
void ReinvokeISP(void);
void EnableWatchdog(uint32_t ms);
void ISPandReset(int delay);
// delayms.c
void delayms(uint32_t ms);
// voltage.c
void VoltageCheck(void);
uint32_t GetVoltage(void);
// keyin.c
#define BTN_NONE 0
#define BTN_UP (1<<0)
#define BTN_DOWN (1<<1)
#define BTN_LEFT (1<<2)
#define BTN_RIGHT (1<<3)
#define BTN_ENTER (1<<4)
uint8_t getInput(void);
#endif #endif

24
basic/delayms.c Normal file
View File

@ -0,0 +1,24 @@
#include <sysdefs.h>
#include "lpc134x.h"
/**************************************************************************/
/*!
Approximates a 1 millisecond delay using "nop". This is less
accurate than a dedicated timer, but is useful in certain situations.
The number of ticks to delay depends on the optimisation level set
when compiling (-O). Depending on the compiler settings, one of the
two defined values for 'delay' should be used.
*/
/**************************************************************************/
void delayms(uint32_t ms)
{
uint32_t delay = ms * ((CFG_CPU_CCLK / 100) / 45); // Release Mode (-Os)
// uint32_t delay = ms * ((CFG_CPU_CCLK / 100) / 120); // Debug Mode (No optimisations)
while (delay > 0)
{
__asm volatile ("nop");
delay--;
}
}

38
basic/keyin.c Normal file
View File

@ -0,0 +1,38 @@
#include <sysinit.h>
#include "basic/basic.h"
uint8_t getInput(void) {
uint8_t result = BTN_NONE;
if (gpioGetValue(RB_BTN3)==0) {
while(gpioGetValue(RB_BTN3)==0);
result += BTN_UP;
}
if (gpioGetValue(RB_BTN2)==0) {
while(gpioGetValue(RB_BTN2)==0);
result += BTN_DOWN;
}
if (gpioGetValue(RB_BTN4)==0) {
while(gpioGetValue(RB_BTN4)==0);
result += BTN_ENTER;
}
if (gpioGetValue(RB_BTN0)==0) {
while(gpioGetValue(RB_BTN0)==0);
result += BTN_LEFT;
}
if (gpioGetValue(RB_BTN1)==0) {
while(gpioGetValue(RB_BTN1)==0);
result += BTN_RIGHT;
}
if (result == (BTN_LEFT+BTN_UP+BTN_ENTER)){ /* Development hack */
ISPandReset(5);
}
return result;
}

View File

@ -71,3 +71,9 @@ void EnableWatchdog(uint32_t ms){
WDT_WDFEED = WDT_WDFEED_FEED1; WDT_WDFEED = WDT_WDFEED_FEED1;
WDT_WDFEED = WDT_WDFEED_FEED2; WDT_WDFEED = WDT_WDFEED_FEED2;
}; };
void ISPandReset(int delay){
EnableWatchdog(1000*delay);
ReinvokeISP();
};

24
basic/voltage.c Normal file
View File

@ -0,0 +1,24 @@
#include <sysinit.h>
#include "basic/basic.h"
uint32_t results=5000;
void VoltageCheck(void){
results = adcRead(1);
results *= 10560;
results /= 1024;
if( results < 3500 ){
gpioSetValue (RB_PWR_GOOD, 0);
gpioSetValue (RB_LCD_BL, 0);
SCB_SCR |= SCB_SCR_SLEEPDEEP;
PMU_PMUCTRL = PMU_PMUCTRL_DPDEN_DEEPPOWERDOWN;
__asm volatile ("WFI");
};
};
uint32_t GetVoltage(void){
return results;
};

View File

@ -63,14 +63,11 @@
#include "systick.h" #include "systick.h"
#ifdef CFG_SDCARD
#include "drivers/fatfs/diskio.h"
volatile uint32_t fatTicks = 0;
#endif
volatile uint32_t systickTicks = 0; // 1ms tick counter volatile uint32_t systickTicks = 0; // 1ms tick counter
volatile uint32_t systickRollovers = 0; volatile uint32_t systickRollovers = 0;
void tick_wrapper(void);
/**************************************************************************/ /**************************************************************************/
/*! /*!
@brief Systick interrupt handler @brief Systick interrupt handler
@ -83,14 +80,7 @@ void SysTick_Handler (void)
// Increment rollover counter // Increment rollover counter
if (systickTicks == 0xFFFFFFFF) systickRollovers++; if (systickTicks == 0xFFFFFFFF) systickRollovers++;
#ifdef CFG_SDCARD tick_wrapper();
fatTicks++;
if (fatTicks == 10)
{
fatTicks = 0;
disk_timerproc();
}
#endif
} }
/**************************************************************************/ /**************************************************************************/

View File

@ -1,7 +1,7 @@
#include <fonts.h> #include <fonts.h>
#include <render.h> #include <render.h>
#define MAXCHR (20*10) #define MAXCHR (30*20)
static uint8_t buf[MAXCHR]; static uint8_t buf[MAXCHR];
// Local function: Get next nibble. // Local function: Get next nibble.

View File

@ -2,28 +2,7 @@
#include <sysdefs.h> #include <sysdefs.h>
#include "lpc134x.h" #include "lpc134x.h"
#include "gpio/gpio.h" #include "gpio/gpio.h"
#include "basic/basic.h"
/**************************************************************************/
/*!
Approximates a 1 millisecond delay using "nop". This is less
accurate than a dedicated timer, but is useful in certain situations.
The number of ticks to delay depends on the optimisation level set
when compiling (-O). Depending on the compiler settings, one of the
two defined values for 'delay' should be used.
*/
/**************************************************************************/
void delayms(uint32_t ms)
{
uint32_t delay = ms * ((CFG_CPU_CCLK / 100) / 45); // Release Mode (-Os)
// uint32_t delay = ms * ((CFG_CPU_CCLK / 100) / 120); // Debug Mode (No optimisations)
while (delay > 0)
{
__asm volatile ("nop");
delay--;
}
}
/**************************************************************************/ /**************************************************************************/
/* Utility routines to manage nokia display */ /* Utility routines to manage nokia display */
@ -32,20 +11,10 @@ void delayms(uint32_t ms)
uint8_t lcdBuffer[RESX*RESY_B]; uint8_t lcdBuffer[RESX*RESY_B];
int inverted = 0; int inverted = 0;
/* #define CS RB_LCD_CS
//TODO FIXME why doenst that work ? #define SCK RB_SPI_SCK
#define CS RB_LCD_CS #define SDA RB_SPI_MOSI
#define SCK RB_SPI_SCK #define RST RB_LCD_RST
#define SDA RB_SPI_MOSI
#define RST RB_LCD_RST
*/
#define CS 2,1
#define SCK 2,11
//#define SCK 2,8
#define SDA 0,9
//#define SDA 2,8
#define RST 2,2
void lcdWrite(uint8_t cd, uint8_t data) void lcdWrite(uint8_t cd, uint8_t data)
{ {

6
main.c
View File

@ -17,16 +17,10 @@ int main(void) {
// Configure cpu and mandatory peripherals // Configure cpu and mandatory peripherals
systemInit(); systemInit();
//enable clocks to adc and watchdog
pmuInit();
// initialise basic badge functions // initialise basic badge functions
rbInit(); rbInit();
lcdInit(); // display lcdInit(); // display
adcInit();
lcdFill(0); lcdFill(0);
lcdDisplay(0); lcdDisplay(0);

View File

@ -59,6 +59,6 @@ clean:
$(WRAPSRC): $(WRAPSRC):
./mkwrapper $(OBJS) > $@ ./mkwrapper $(OBJS) > $@
.PHONY: $(LIBFILE) .PHONY: $(LIBFILE) $(WRAPSRC)
.SUFFIXES: .SUFFIXES:

View File

@ -1,7 +1,31 @@
#include <sysinit.h> #include <sysinit.h>
#include "basic/basic.h"
/**************************************************************************/ /**************************************************************************/
void module_default(void) { void module_default(void) {
systickInit(10);
return; return;
} };
// every 10 ms
void tick_default(void) {
static int ctr;
ctr++;
if(ctr>100){
VoltageCheck();
ctr=0;
};
if(ctr%5==0){
if(GetVoltage()<3600){
IOCON_PIO1_11 = 0x0;
gpioSetDir(RB_LED3, gpioDirection_Output);
if( (ctr/5)%10 == 1 )
gpioSetValue (RB_LED3, 1);
else
gpioSetValue (RB_LED3, 0);
};
};
return;
};

View File

@ -94,7 +94,7 @@ uint8_t getInput(void) {
result += BTN_RIGHT; result += BTN_RIGHT;
} }
if (result == (BTN_LEFT+BTN_RIGHT)){ /* Development hack */ if (result == (BTN_LEFT+BTN_TOP+BTN_ENTER)){ /* Development hack */
gotoISP(); gotoISP();
} }

View File

@ -3,6 +3,7 @@
for a in $* ; do for a in $* ; do
base=${a%.o} base=${a%.o}
echo "void module_$base(void);" echo "void module_$base(void);"
echo "void tick_$base(void);"
done done
echo echo
@ -14,3 +15,12 @@ for a in $* ; do
done done
echo "}" echo "}"
echo "void tick_wrapper(void){"
for a in $* ; do
base=${a%.o}
grep -q \ tick_$base ${base}.c && echo "tick_$base();"
done
echo "}"

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;
};