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 +=
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 += reinvoke_isp.o
LIBS += core/libcore.a lcd/liblcd.a modules/libmodules.a
##########################################################################

View File

@ -10,6 +10,9 @@ void rbInit() {
gpioSetDir(RB_PWR_GOOD, gpioDirection_Output);
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
gpioSetDir(RB_BTN0, gpioDirection_Input);

View File

@ -114,6 +114,29 @@
#define RB_EEPROM_ADDR 0xA0
#define USB_CONNECT 0,6
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

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_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"
#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 systickRollovers = 0;
void tick_wrapper(void);
/**************************************************************************/
/*!
@brief Systick interrupt handler
@ -83,14 +80,7 @@ void SysTick_Handler (void)
// Increment rollover counter
if (systickTicks == 0xFFFFFFFF) systickRollovers++;
#ifdef CFG_SDCARD
fatTicks++;
if (fatTicks == 10)
{
fatTicks = 0;
disk_timerproc();
}
#endif
tick_wrapper();
}
/**************************************************************************/

View File

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

View File

@ -2,28 +2,7 @@
#include <sysdefs.h>
#include "lpc134x.h"
#include "gpio/gpio.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--;
}
}
#include "basic/basic.h"
/**************************************************************************/
/* Utility routines to manage nokia display */
@ -32,20 +11,10 @@ void delayms(uint32_t ms)
uint8_t lcdBuffer[RESX*RESY_B];
int inverted = 0;
/*
//TODO FIXME why doenst that work ?
#define CS RB_LCD_CS
#define SCK RB_SPI_SCK
#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)
{

6
main.c
View File

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

View File

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

View File

@ -1,7 +1,31 @@
#include <sysinit.h>
#include "basic/basic.h"
/**************************************************************************/
void module_default(void) {
systickInit(10);
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;
}
if (result == (BTN_LEFT+BTN_RIGHT)){ /* Development hack */
if (result == (BTN_LEFT+BTN_TOP+BTN_ENTER)){ /* Development hack */
gotoISP();
}

View File

@ -3,6 +3,7 @@
for a in $* ; do
base=${a%.o}
echo "void module_$base(void);"
echo "void tick_$base(void);"
done
echo
@ -14,3 +15,12 @@ for a in $* ; do
done
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/allfonts.h"
void ReinvokeISP(void);
void EnableWatchdog(uint32_t ms);
void delayms(uint32_t ms);
void backlightInit(void);
/**************************************************************************/
void module_sec(void) {
//Make PIO1_11 an analog input
gpioSetDir(RB_LED3, gpioDirection_Input);
IOCON_PIO1_11 = 0x41;
backlightInit();
uint32_t j=0;
//disable the JTAG on PIO3_3
IOCON_PIO3_3 = 0x10;
@ -27,105 +20,70 @@ void module_sec(void) {
int dx=0;
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;
uint8_t trigger;
#define SEND
#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
trigger=20;
uint32_t ctr=0;
char key;
while (1) {
ctr++;
uint32_t results;
lcdDisplay(j);
lcdDisplay(0);
delayms(10);
font=fonts[fontctr];
key= getInput();
if(key==BTN_UP){
trigger +=1;
}else if (key ==BTN_DOWN){
trigger -=1;
};
if(gpioGetValue(RB_BTN3)==0){
while(gpioGetValue(RB_BTN3)==0);
trigger +=10;
};
if(gpioGetValue(RB_BTN2)==0){
while(gpioGetValue(RB_BTN2)==0);
trigger -=10;
};
font=&Font_7x8;
dx=DoString(0,0,"Trig:");
dx=DoInt(dx,0,trigger);
DoString(dx,0," ");
if(gpioGetValue(RB_BTN0)==0){
while(gpioGetValue(RB_BTN0)==0);
// Easy flashing
if(key==BTN_LEFT){
DoString(0,8,"Enter ISP!");
lcdDisplay(0);
EnableWatchdog(1000*5);
ReinvokeISP();
ISPandReset(5);
};
// Display nickname
font = &Font_Ubuntu36pt;
dx=DoString(0,0,"Sec");
#ifdef SEND
if(ctr++>trigger/10){
// Blink LED
if(ctr++>trigger){
ctr=0;
if (gpioGetValue(RB_LED0) == CFG_LED_OFF){
gpioSetValue (RB_LED0, CFG_LED_ON);
// DoString(dx,14,"ON!");
if (gpioGetValue(RB_LED2) == CFG_LED_OFF){
gpioSetValue (RB_LED2, CFG_LED_ON);
} else {
gpioSetValue (RB_LED0, CFG_LED_OFF);
// DoString(dx,14,"off");
gpioSetValue (RB_LED2, CFG_LED_OFF);
};
};
#else
results = adcRead(0);
DoInt(dx,20,results);
if(results>trigger){
DoString(dx,30,"YES!");
}else{
DoString(dx,30," no ");
};
#endif
// Print Voltage
font = &Font_7x8;
results = adcRead(1);
dx=DoString(0,yctr+28,"Voltage:");
results *= 10560;
results /= 1024;
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 ");
;
}
DoInt(dx,yctr+28,GetVoltage());
}
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;
};