From cef9ad954087c81b3bdf18258466828b85aca882 Mon Sep 17 00:00:00 2001 From: bernd Date: Tue, 19 Jul 2011 12:28:21 +0200 Subject: [PATCH 01/24] Added life application --- firmware/applications/life.c | 246 +++++++++++++++++++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 firmware/applications/life.c diff --git a/firmware/applications/life.c b/firmware/applications/life.c new file mode 100644 index 0000000..128a437 --- /dev/null +++ b/firmware/applications/life.c @@ -0,0 +1,246 @@ +#include + +#include "basic/basic.h" + +#include "lcd/render.h" +#include "lcd/display.h" +#include "lcd/allfonts.h" + +void ReinvokeISP(void); +void EnableWatchdog(uint32_t ms); +void delayms(uint32_t ms); + +/**************************************************************************/ +#define POS_PLAYER_Y 60 +#define ENEMY_ROWS 3 +#define ENEMY_COLUMNS 6 +#define DISABLED 255 + + +unsigned char rnd1(); + +struct gamestate { + char player; + char shot_x, shot_y; + char alive; + char move, direction, lastcol; + bool killed; + char enemy_x[ENEMY_ROWS][ENEMY_COLUMNS]; + char enemy_row_y[ENEMY_ROWS]; + +} game = {RESX/2-4, DISABLED, 0,ENEMY_ROWS*ENEMY_COLUMNS, 0, -1, ENEMY_COLUMNS-1, false}; +char key; + + +void checkISP(void) { + if(gpioGetValue(RB_BTN2)==0){ + gpioSetValue (RB_LED1, CFG_LED_ON); + delayms(200); + gpioSetValue (RB_LED1, CFG_LED_OFF); + while(gpioGetValue(RB_BTN0)==0); + EnableWatchdog(1000*5); + ReinvokeISP(); + } +} + + +void draw_rect(char x0, char y0, char x1, char y1) { + for(char x=x0; x<=x1; ++x) { + lcdSetPixel(x,y0,true); + lcdSetPixel(x,y1,true); + } + for(char y=y0+1; y0; --x) { + for(uchar y=1; y Date: Tue, 19 Jul 2011 12:35:08 +0200 Subject: [PATCH 02/24] Code cleanup: removed remaining spaceinvader definitions --- firmware/applications/life.c | 38 +----------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/firmware/applications/life.c b/firmware/applications/life.c index 128a437..03bc23f 100644 --- a/firmware/applications/life.c +++ b/firmware/applications/life.c @@ -6,44 +6,8 @@ #include "lcd/display.h" #include "lcd/allfonts.h" -void ReinvokeISP(void); -void EnableWatchdog(uint32_t ms); -void delayms(uint32_t ms); - -/**************************************************************************/ -#define POS_PLAYER_Y 60 -#define ENEMY_ROWS 3 -#define ENEMY_COLUMNS 6 -#define DISABLED 255 - - unsigned char rnd1(); -struct gamestate { - char player; - char shot_x, shot_y; - char alive; - char move, direction, lastcol; - bool killed; - char enemy_x[ENEMY_ROWS][ENEMY_COLUMNS]; - char enemy_row_y[ENEMY_ROWS]; - -} game = {RESX/2-4, DISABLED, 0,ENEMY_ROWS*ENEMY_COLUMNS, 0, -1, ENEMY_COLUMNS-1, false}; -char key; - - -void checkISP(void) { - if(gpioGetValue(RB_BTN2)==0){ - gpioSetValue (RB_LED1, CFG_LED_ON); - delayms(200); - gpioSetValue (RB_LED1, CFG_LED_OFF); - while(gpioGetValue(RB_BTN0)==0); - EnableWatchdog(1000*5); - ReinvokeISP(); - } -} - - void draw_rect(char x0, char y0, char x1, char y1) { for(char x=x0; x<=x1; ++x) { lcdSetPixel(x,y0,true); @@ -135,7 +99,7 @@ void calc_area() { for(uchar x=1; x<=RESX; ++x) { for(uchar y=1; y<=RESY; ++y) { uchar sum=sum_area(life,x-1,y-1,x+1,y+1)-life[x][y]; - new[x][y]=sum==3||sum==2&&life[x][y]; + new[x][y]=sum==3||(sum==2&&life[x][y]); } } swap_areas(); From 38ee62537b483ab7412fb448c86010d48998e324 Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 20 Jul 2011 06:00:02 +0200 Subject: [PATCH 03/24] Correct LED colors and positions --- simulat0r/gui/qsimulat0r.cc | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/simulat0r/gui/qsimulat0r.cc b/simulat0r/gui/qsimulat0r.cc index a5ae2d9..f519766 100644 --- a/simulat0r/gui/qsimulat0r.cc +++ b/simulat0r/gui/qsimulat0r.cc @@ -27,6 +27,15 @@ extern int lcd_layout; time_t starttime; long framecount=0; +const int colorGreenLED=QColor(0,255,0).rgb(); +const int colorRedLED=QColor(255,0,0).rgb(); +const int colorOffLED=QColor(64,64,64).rgb(); + +const int colorPixelOn=QColor(255,192,0).rgb(); +const int colorPixelOff=QColor(64,64,64).rgb(); +const int colorInvertedPixelOn=QColor(128,128,128).rgb(); // inverted and on => dark +const int colorInvertedPixelOff=QColor(128,255,128).rgb(); // inverted and off => bright + class LCD : public QWidget { public: static const int ledsize=10; @@ -41,8 +50,8 @@ public: static const int dimx=RESX; //96; static const int dimy=RESY; - void drawLED(QImage& pixmap,int led, int x, int y) { - int color=simGetLED(led)?QColor(255,0,0).rgb():QColor(64,64,64).rgb(); + void drawLED(QImage& pixmap,int led, int x, int y,int colorOn) { + int color=simGetLED(led)?colorOn:colorOffLED; for(int minix=0; minix Date: Wed, 20 Jul 2011 06:25:11 +0200 Subject: [PATCH 04/24] Stay close to r0ket firmware and just #define away some lowlevel functions --- simulat0r/firmware/core/i2c/i2c.c | 36 +++++++++++++++++++-- simulat0r/firmware/lcd/display.c | 54 ++++--------------------------- 2 files changed, 40 insertions(+), 50 deletions(-) diff --git a/simulat0r/firmware/core/i2c/i2c.c b/simulat0r/firmware/core/i2c/i2c.c index 6a27b27..cca2ebc 100644 --- a/simulat0r/firmware/core/i2c/i2c.c +++ b/simulat0r/firmware/core/i2c/i2c.c @@ -1,2 +1,34 @@ -/* AUTOGENERATED SOURCE FILE */ -#include "../../../../firmware/core/i2c/i2c.c" + +// dummy implementation instead of #include "../../../../firmware/core/i2c/i2c.c" + + +#include "i2c.h" + +volatile uint32_t I2CMasterState = I2CSTATE_IDLE; +volatile uint32_t I2CSlaveState = I2CSTATE_IDLE; + +volatile uint8_t I2CMasterBuffer[I2C_BUFSIZE]; +volatile uint8_t I2CSlaveBuffer[I2C_BUFSIZE]; +volatile uint32_t I2CReadLength; +volatile uint32_t I2CWriteLength; + +volatile uint32_t RdIndex = 0; +volatile uint32_t WrIndex = 0; + + +void I2C_IRQHandler(void) { +} + +uint32_t i2cInit( uint32_t I2cMode ) { + return( TRUE ); +} + +uint32_t i2cEngine( void ) { + return I2CSTATE_IDLE; +} + +/****************************************************************************** +** End Of File +******************************************************************************/ + + diff --git a/simulat0r/firmware/lcd/display.c b/simulat0r/firmware/lcd/display.c index 8e12c67..de1d975 100644 --- a/simulat0r/firmware/lcd/display.c +++ b/simulat0r/firmware/lcd/display.c @@ -1,56 +1,14 @@ -#if 0 -#include "../firmware/lcd/display.c" -#else +#define lcdDisplay _hideaway_lcdDisplay +#define lcdInit _hideaway_lcdInit +#include "../../../firmware/lcd/display.c" +#undef lcdDisplay +#undef lcdInit -#include "../firmware/lcd/display.h" #include "simulator.h" -uint8_t lcdBuffer[RESX*RESY_B]; -int lcd_layout = 0; -const int TYPE_DATA=0; - - -void lcdInit(void) { - fprintf(stderr,"lcdInit(void)\n"); -} - - -void lcdFill(char f){ - int x; - for(x=0;x Date: Wed, 20 Jul 2011 06:28:41 +0200 Subject: [PATCH 05/24] Cleaned up function declarations --- simulat0r/simcore/simulator.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/simulat0r/simcore/simulator.h b/simulat0r/simcore/simulator.h index 5d85dec..82b0d2f 100644 --- a/simulat0r/simcore/simulator.h +++ b/simulat0r/simcore/simulator.h @@ -3,10 +3,7 @@ #include -void simlcdPrepareUpdate(); -void simlcdWrite(int ignored, int bit); -void simlcdLineFeed(); -void simlcdCompleteUpdate(); +void simlcdDisplayUpdate(); int simButtonPressed(int button); From 575f1a7d423493b8ad511bf0c3b716140d25b51b Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 20 Jul 2011 07:05:58 +0200 Subject: [PATCH 06/24] Use generated include-bridges for Makefiles --- simulat0r/bin/update-bridge-files.sh | 21 +++++++- simulat0r/firmware/applications/Makefile | 68 +----------------------- simulat0r/firmware/core/Makefile | 58 +------------------- simulat0r/firmware/filesystem/Makefile | 32 +---------- simulat0r/firmware/funk/Makefile | 27 +--------- simulat0r/firmware/lcd/Makefile | 47 +--------------- simulat0r/firmware/loadable/Makefile | 14 +---- simulat0r/firmware/loadable/Makefile.sub | 57 -------------------- simulat0r/firmware/usb/Makefile | 38 +------------ 9 files changed, 34 insertions(+), 328 deletions(-) delete mode 100644 simulat0r/firmware/loadable/Makefile.sub diff --git a/simulat0r/bin/update-bridge-files.sh b/simulat0r/bin/update-bridge-files.sh index 5d74ef4..f278dc5 100755 --- a/simulat0r/bin/update-bridge-files.sh +++ b/simulat0r/bin/update-bridge-files.sh @@ -5,6 +5,13 @@ true # echo $1 } +if test ! -d simulat0r/firmware -o ! -d firmware +then +echo ERROR: +echo This script must be run from toplevel r0ket directory +exit +fi + echo "Updating directories" for i in `find firmware/ -type d ` do @@ -14,7 +21,7 @@ else mkdir -v simulat0r/$i fi done -echo "Updating bridge files" +echo "Updating bridge files for C source" for i in `find firmware/ \! -path firmware/lcd/allfonts.h -type f -iname \*.[ch]` do if test -f simulat0r/$i; @@ -25,3 +32,15 @@ do (printf "/* AUTOGENERATED SOURCE FILE */\n"; echo \#include \"`dirname $i | sed "s#[^/]*#..#g" `/../$i\") >simulat0r/$i fi done + +echo "Updating bridge files for Makefiles" +for i in `find firmware/ -type f -iname Makefile` +do + if test -f simulat0r/$i; + then + verbmsg "OK File already exists: $i" + else + echo Writing bridge file simulat0r/$i + (printf "# GENERATED INCLUDE BRIDGE/\n"; echo include `dirname $i | sed "s#[^/]*#..#g" `/../$i) >simulat0r/$i + fi +done diff --git a/simulat0r/firmware/applications/Makefile b/simulat0r/firmware/applications/Makefile index 6d034d3..adbca02 100644 --- a/simulat0r/firmware/applications/Makefile +++ b/simulat0r/firmware/applications/Makefile @@ -1,66 +1,2 @@ -########################################################################## -# User configuration and firmware specific object files -########################################################################## - -OBJS = default.o -OBJS += $(foreach mod,$(APP),$(mod).o) - -SRCS = $(foreach mod,$(APP),$(mod).c) - -ifndef APP -ME_OBJ=$(USERNAME) - -ifeq "$(ME_OBJ)" "" -ME_OBJ=$(USER) -endif - -ifeq "$(ME_OBJ)" "" -ME_OBJ=nouser -endif - -OBJS += $(ME_OBJ).o -endif - -WRAP=wrapper -LIBNAME=app - -########################################################################## -# GNU GCC compiler flags -########################################################################## -ROOT_PATH?= .. -INCLUDE_PATHS = -I$(ROOT_PATH) -I../core -I. - -include $(ROOT_PATH)/Makefile.inc - -WRAPOBJ=$(WRAP).o -WRAPSRC=$(WRAP).c -LIBFILE=lib$(LIBNAME).a - -########################################################################## -# Compiler settings, parameters and flags -########################################################################## - -all: $(LIBFILE) - -$(LIBFILE): $(OBJS) $(WRAPOBJ) - $(AR) rcs $@ $(OBJS) $(WRAPOBJ) - -%.o : %.c - $(CC) $(CFLAGS) -o $@ $< - -clean: - rm -f $(OBJS) $(WRAPOBJ) $(WRAPSRC) $(LIBFILE) *.o - -%.c: - @echo - @echo "You need to create $@ first" - @echo "It should contain a single function void main_filename(void)" - @echo - @exit 1 - -$(WRAPSRC): - ./mkwrapper $(OBJS) > $@ - -.PHONY: $(LIBFILE) $(WRAPSRC) $(SRCS) - -.SUFFIXES: +# GENERATED INCLUDE BRIDGE/ +include ../../../firmware/applications/Makefile diff --git a/simulat0r/firmware/core/Makefile b/simulat0r/firmware/core/Makefile index ec1df9e..f85ccd8 100644 --- a/simulat0r/firmware/core/Makefile +++ b/simulat0r/firmware/core/Makefile @@ -1,56 +1,2 @@ -########################################################################## -# User configuration and firmware specific object files -########################################################################## - -# The target, flash and ram of the LPC1xxx microprocessor. -# Use for the target the value: LPC11xx, LPC13xx or LPC17xx -TARGET = LPC13xx - -OBJS = sysinit.o -OBJS += adc/adc.o -#OBJS += cmd/cmd.o -OBJS += cpu/cpu.o -OBJS += gpio/gpio.o -OBJS += i2c/i2c.o -OBJS += iap/iap.o -OBJS += libc/ctype.o -OBJS += libc/stdio.o -OBJS += libc/string.o -OBJS += pmu/pmu.o -#OBJS += pwm/pwm.o -OBJS += ssp/ssp.o -OBJS += systick/systick.o -OBJS += timer16/timer16.o -OBJS += timer32/timer32.o -#OBJS += uart/uart.o -#OBJS += uart/uart_buf.o -#OBJS += usbcdc/cdcuser.o -#OBJS += usbcdc/cdc_buf.o -#OBJS += usbcdc/usbcore.o -#OBJS += usbcdc/usbdesc.o -#OBJS += usbcdc/usbhw.o -#OBJS += usbcdc/usbuser.o -OBJS += wdt/wdt.o - -########################################################################## -# GNU GCC compiler flags -########################################################################## -ROOT_PATH?= .. -INCLUDE_PATHS = -I$(ROOT_PATH) -I. - -include $(ROOT_PATH)/Makefile.inc - -########################################################################## -# Compiler settings, parameters and flags -########################################################################## - -all: libcore.a - -libcore.a: $(OBJS) - $(AR) rcs libcore.a $(OBJS) - -%.o : %.c projectconfig.h - $(CC) $(CFLAGS) -o $@ $< - -clean: - rm -f $(OBJS) libcore.a +# GENERATED INCLUDE BRIDGE/ +include ../../../firmware/core/Makefile diff --git a/simulat0r/firmware/filesystem/Makefile b/simulat0r/firmware/filesystem/Makefile index 76b2d19..b6fed1f 100644 --- a/simulat0r/firmware/filesystem/Makefile +++ b/simulat0r/firmware/filesystem/Makefile @@ -1,30 +1,2 @@ -########################################################################## -# User configuration and firmware specific object files -########################################################################## - -OBJS = - -OBJS += ff.o -OBJS += diskio.o -OBJS += iobase.o -OBJS += mmc.o -OBJS += at45db041d.o -OBJS += util.o -OBJS += select.o -OBJS += execute.o - -LIBNAME=fat - -########################################################################## -# GNU GCC compiler flags -########################################################################## -ROOT_PATH?= .. -INCLUDE_PATHS = -I$(ROOT_PATH) -I../core -I. - -include $(ROOT_PATH)/Makefile.inc - -########################################################################## -# Actual work -########################################################################## - -include $(ROOT_PATH)/Makefile.util +# GENERATED INCLUDE BRIDGE/ +include ../../../firmware/filesystem/Makefile diff --git a/simulat0r/firmware/funk/Makefile b/simulat0r/firmware/funk/Makefile index dd2a593..e5dba98 100644 --- a/simulat0r/firmware/funk/Makefile +++ b/simulat0r/firmware/funk/Makefile @@ -1,25 +1,2 @@ -########################################################################## -# User configuration and firmware specific object files -########################################################################## - -OBJS = - -OBJS += nrf24l01p.o -OBJS += rftransfer.o -OBJS += filetransfer.o - -LIBNAME=funk - -########################################################################## -# GNU GCC compiler flags -########################################################################## -ROOT_PATH?= .. -INCLUDE_PATHS = -I$(ROOT_PATH) -I../core -I. - -include $(ROOT_PATH)/Makefile.inc - -########################################################################## -# Actual work -########################################################################## - -include $(ROOT_PATH)/Makefile.util +# GENERATED INCLUDE BRIDGE/ +include ../../../firmware/funk/Makefile diff --git a/simulat0r/firmware/lcd/Makefile b/simulat0r/firmware/lcd/Makefile index fe639a3..d17981e 100644 --- a/simulat0r/firmware/lcd/Makefile +++ b/simulat0r/firmware/lcd/Makefile @@ -1,45 +1,2 @@ -########################################################################## -# User configuration and firmware specific object files -########################################################################## - -OBJS = - -OBJS += display.o -OBJS += render.o -OBJS += decoder.o -OBJS += backlight.o -OBJS += print.o - -FONTS = $(basename $(wildcard fonts/*.c)) - -LIBNAME=lcd - -########################################################################## -# GNU GCC compiler flags -########################################################################## -ROOT_PATH?= .. -INCLUDE_PATHS = -I$(ROOT_PATH) -I../core -I. - -include $(ROOT_PATH)/Makefile.inc - -FOBJS= $(foreach ft,$(FONTS),$(ft).o) -OBJS+= $(FOBJS) - -########################################################################## -# Actual work -########################################################################## - -include $(ROOT_PATH)/Makefile.util - -all: allfonts.h - -$(FOBJS): $(foreach ft,$(FONTS),$(ft).h) fonts.h - -clean:: - rm -f fonts/*.o allfonts.h - touch allfonts.h - -.PHONY: allfonts.h - -allfonts.h: - (echo "#include ";for a in $(FONTS) ; do echo "#include "; done) > $@ +# GENERATED INCLUDE BRIDGE/ +include ../../../firmware/lcd/Makefile diff --git a/simulat0r/firmware/loadable/Makefile b/simulat0r/firmware/loadable/Makefile index fa86f1e..38a36e7 100644 --- a/simulat0r/firmware/loadable/Makefile +++ b/simulat0r/firmware/loadable/Makefile @@ -1,12 +1,2 @@ -# Make doesn't allow dependencies on parent directory, so we need to -# run make from one level up: - -MAKEFILE=loadable/Makefile.sub -MAKE+=--no-print-directory - -all: - @cd .. && $(MAKE) -f $(MAKEFILE) - -clean: - @cd .. && $(MAKE) -f $(MAKEFILE) clean - +# GENERATED INCLUDE BRIDGE/ +include ../../../firmware/loadable/Makefile diff --git a/simulat0r/firmware/loadable/Makefile.sub b/simulat0r/firmware/loadable/Makefile.sub deleted file mode 100644 index aa2f3ee..0000000 --- a/simulat0r/firmware/loadable/Makefile.sub +++ /dev/null @@ -1,57 +0,0 @@ -DIR?= loadable - -########################################################################## -# User configuration and firmware specific object files -########################################################################## -SRCS = $(wildcard $(DIR)/*.c) -OBJS = $(foreach mod,$(SRCS),$(subst .c,.o,$(mod))) -ELFS = $(foreach mod,$(SRCS),$(subst .c,.elf,$(mod))) -BINS = $(foreach mod,$(SRCS),$(subst .c,.bin,$(mod))) -HDRS = $(foreach mod,$(SRCS),$(subst .c,.h,$(mod))) - -########################################################################## -# GNU GCC compiler flags -########################################################################## -ROOT_PATH?= . - -INCLUDE_PATHS = -I$(ROOT_PATH) -I$(ROOT_PATH)/core - -include $(ROOT_PATH)/Makefile.inc - -########################################################################## -# Compiler settings, parameters and flags -########################################################################## -FIRMWARE=$(ROOT_PATH)/$(OUTFILE).elf -LDSRCFILE=$(DIR)/ram.ld -LDFILE=$(DIR)/loadable.ld -CFLAGS+=-mlong-calls -fno-toplevel-reorder -LDFLAGS+= -R $(FIRMWARE) - -all: $(OBJS) $(ELFS) $(BINS) $(HDRS) - -$(LDFILE): - -@echo "MEMORY" > $(LDFILE) - -@echo "{" >> $(LDFILE) - -@echo " sram(rwx): ORIGIN = 0x10002000 - $(RAMCODE), LENGTH = $(RAMCODE)" >> $(LDFILE) - -@echo "}" >> $(LDFILE) - -@echo "INCLUDE $(LDSRCFILE)" >> $(LDFILE) - -%.o : %.c - $(CC) $(CFLAGS) -o $@ $< - -%.elf: %.o $(FIRMWARE) $(LDFILE) - $(LD) $(LDFLAGS) -T $(LDFILE) -o $@ $< - $(SIZE) $@ - -%.bin: %.elf - $(OBJCOPY) $(OCFLAGS) -O binary $< $@ - -%.h: %.bin $(DIR)/bin2h.pl - $(DIR)/bin2h.pl $< - -clean: - cd $(DIR) && rm -f *.o *.elf *.bin - -.SUFFIXES: - -.PHONY: $(LDFILE) diff --git a/simulat0r/firmware/usb/Makefile b/simulat0r/firmware/usb/Makefile index d54ddf3..76d0639 100644 --- a/simulat0r/firmware/usb/Makefile +++ b/simulat0r/firmware/usb/Makefile @@ -1,36 +1,2 @@ -########################################################################## -# User configuration and firmware specific object files -########################################################################## - -OBJS = - -OBJS += usbconfig.o -OBJS += usbhid.o -OBJS += usbmsc.o - -LIBNAME=usb - -########################################################################## -# GNU GCC compiler flags -########################################################################## -ROOT_PATH?= .. -INCLUDE_PATHS = -I$(ROOT_PATH) -I../core -I. - -include $(ROOT_PATH)/Makefile.inc - -LIBFILE=lib$(LIBNAME).a -########################################################################## -# Compiler settings, parameters and flags -########################################################################## - -all: $(LIBFILE) - -$(LIBFILE): $(OBJS) - $(AR) rcs $@ $(OBJS) - -%.o : %.c - $(CC) $(CFLAGS) -o $@ $< - -clean: - rm -f $(OBJS) $(LIBFILE) - +# GENERATED INCLUDE BRIDGE/ +include ../../../firmware/usb/Makefile From ffcd95d412e9d5e36c68530cf00318e811bf3a47 Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 20 Jul 2011 07:07:50 +0200 Subject: [PATCH 07/24] Added new include bridge files --- simulat0r/firmware/applications/flame.c | 2 ++ simulat0r/firmware/applications/loadable.c | 2 ++ simulat0r/firmware/basic/Makefile | 2 ++ simulat0r/firmware/usbcdc/Makefile | 2 ++ 4 files changed, 8 insertions(+) create mode 100644 simulat0r/firmware/applications/flame.c create mode 100644 simulat0r/firmware/applications/loadable.c create mode 100644 simulat0r/firmware/basic/Makefile create mode 100644 simulat0r/firmware/usbcdc/Makefile diff --git a/simulat0r/firmware/applications/flame.c b/simulat0r/firmware/applications/flame.c new file mode 100644 index 0000000..2b63c47 --- /dev/null +++ b/simulat0r/firmware/applications/flame.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/applications/flame.c" diff --git a/simulat0r/firmware/applications/loadable.c b/simulat0r/firmware/applications/loadable.c new file mode 100644 index 0000000..1700a51 --- /dev/null +++ b/simulat0r/firmware/applications/loadable.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/applications/loadable.c" diff --git a/simulat0r/firmware/basic/Makefile b/simulat0r/firmware/basic/Makefile new file mode 100644 index 0000000..64a786e --- /dev/null +++ b/simulat0r/firmware/basic/Makefile @@ -0,0 +1,2 @@ +# GENERATED INCLUDE BRIDGE/ +include ../../../firmware/basic/Makefile diff --git a/simulat0r/firmware/usbcdc/Makefile b/simulat0r/firmware/usbcdc/Makefile new file mode 100644 index 0000000..2bb4268 --- /dev/null +++ b/simulat0r/firmware/usbcdc/Makefile @@ -0,0 +1,2 @@ +# GENERATED INCLUDE BRIDGE/ +include ../../../firmware/usbcdc/Makefile From fca18b502933e772cf882d46b73e8a2e3cce5aa8 Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 20 Jul 2011 07:41:14 +0200 Subject: [PATCH 08/24] Added workaround ARM asm --- simulat0r/firmware/basic/xxtea.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/simulat0r/firmware/basic/xxtea.c b/simulat0r/firmware/basic/xxtea.c index 77604be..c315d35 100644 --- a/simulat0r/firmware/basic/xxtea.c +++ b/simulat0r/firmware/basic/xxtea.c @@ -1,2 +1,4 @@ -/* AUTOGENERATED SOURCE FILE */ +/* use SAFE version instead of ARM asm */ +#define SAFE + #include "../../../firmware/basic/xxtea.c" From 72eb4e0c0627c57443776d31fa7585ff068b51f1 Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 20 Jul 2011 07:42:08 +0200 Subject: [PATCH 09/24] Removed crc function stub as now we get it from app library --- simulat0r/simcore/misc.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/simulat0r/simcore/misc.c b/simulat0r/simcore/misc.c index b006768..36c5cfb 100644 --- a/simulat0r/simcore/misc.c +++ b/simulat0r/simcore/misc.c @@ -1,6 +1,3 @@ -int crc16(int x) { -} - void __disable_irq() { } From 2ced2603798659e2576a1f54c77fe941dde18051 Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 20 Jul 2011 07:45:54 +0200 Subject: [PATCH 10/24] =?UTF-8?q?Simulat0r=20doesn=C2=B4t=20have=20siprint?= =?UTF-8?q?f,=20use=20sprintf=20instead=20where=20needed=20by=20firmware?= =?UTF-8?q?=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simulat0r/firmware/libc-unc0llide.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/simulat0r/firmware/libc-unc0llide.h b/simulat0r/firmware/libc-unc0llide.h index 19d8cf8..0ca4b6a 100644 --- a/simulat0r/firmware/libc-unc0llide.h +++ b/simulat0r/firmware/libc-unc0llide.h @@ -1,5 +1,13 @@ /* This header is "gcc -include"d for all compilations of firmware files when building as simulat0r. +*/ + +/* +The following symbols are expected from r0ket firmware to come from libc +*/ +#define siprintf sprintf + +/* The following symbols were found to be defined within glibc. Use different names within simulat0r to keep the firmware and simulat0r-host universes collision-free. */ From 5629836c37242ad8b01b0aac80d91a308bf8a327 Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 20 Jul 2011 07:57:06 +0200 Subject: [PATCH 11/24] Use patching include bridge for simulat0r/firmware Makefile --- simulat0r/firmware/Makefile | 110 +----------------------------------- 1 file changed, 3 insertions(+), 107 deletions(-) diff --git a/simulat0r/firmware/Makefile b/simulat0r/firmware/Makefile index dd71a3a..3c50af5 100644 --- a/simulat0r/firmware/Makefile +++ b/simulat0r/firmware/Makefile @@ -1,108 +1,4 @@ -VPATH = -OBJS = main.o - -########################################################################## -# Project-specific files -########################################################################## - -VPATH += -OBJS += -OBJS += basic/basic.o basic/reinvoke_isp.o basic/delayms.o basic/voltage.o -OBJS += basic/keyin.o basic/uuid.o -LIBS += core/libcore.a lcd/liblcd.a applications/libapp.a filesystem/libfat.a usb/libusb.a - -########################################################################## -# GNU GCC compiler flags -########################################################################## -ROOT_PATH = . -INCLUDE_PATHS = -I$(ROOT_PATH) -I$(ROOT_PATH)/core - -include $(ROOT_PATH)/Makefile.inc - -LDFLAGS+= -Wl,--gc-sections -VPATH += lpc1xxx -OBJS += $(TARGET)_handlers.o LPC1xxx_startup.o - -########################################################################## -# Startup files -########################################################################## -LDLIBS = -lm -LDLIBS += -Lapplications -lapp -LDLIBS += -Lfunk -lfunk -LDLIBS += -Lusbcdc -lusbcdc -LDLIBS += -Lfilesystem -lfat -LDLIBS += -Lbasic -lbasic -LDLIBS += -Llcd -llcd -LDLIBS += -Lcore -lcore -LDLIBS += -Lusb -lusb - - -LD_PATH = lpc1xxx -LD_SCRIPT = $(LD_PATH)/linkscript.ld -LD_TEMP = $(LD_PATH)/memory.ld - -### User targets: - -all: $(OUTFILE).bin - -protect: $(OUTFILE).bin - $(LPCFIX) -p 2 $(OUTFILE).bin - -loadables: $(OUTFILE).bin - @cd loadable && $(MAKE) - -clean: - rm -f $(OBJS) $(LD_TEMP) $(OUTFILE).elf $(OUTFILE).bin $(OUTFILE).hex - @cd core && $(MAKE) clean -# @cd ../tools/bootloader && $(MAKE) clean - @cd lcd && $(MAKE) clean - @cd applications && $(MAKE) clean - @cd filesystem && $(MAKE) clean - @cd usb && $(MAKE) clean - @cd loadable && $(MAKE) clean - -### Internal targets - -%.o : %.c - $(CC) $(CFLAGS) -o $@ $< - -core/libcore.a: core/projectconfig.h - cd core && $(MAKE) ROOT_PATH=../$(ROOT_PATH) - -lcd/liblcd.a lcd/render.o lcd/display.o: - cd lcd && $(MAKE) ROOT_PATH=../$(ROOT_PATH) - -applications/libapp.a: - cd applications && $(MAKE) ROOT_PATH=../$(ROOT_PATH) - -filesystem/libfat.a: - cd filesystem && $(MAKE) ROOT_PATH=../$(ROOT_PATH) - -usb/libusb.a: - cd usb && $(MAKE) ROOT_PATH=../$(ROOT_PATH) - -../tools/bootloader/lpcfix: -# cd ../tools/bootloader && $(MAKE) - -$(LD_TEMP): - -@echo "MEMORY" > $(LD_TEMP) - -@echo "{" >> $(LD_TEMP) - -@echo " flash(rx): ORIGIN = 0x00000000, LENGTH = $(FLASH)" >> $(LD_TEMP) - -@echo " sram(rwx): ORIGIN = 0x10000000+$(SRAM_USB), LENGTH = $(SRAM)-$(SRAM_USB)-$(RAMCODE)" >> $(LD_TEMP) - -@echo "}" >> $(LD_TEMP) - -@echo "INCLUDE $(LD_SCRIPT)" >> $(LD_TEMP) - -.IGNORE: $(OUTFILE).elf -$(OUTFILE).elf: $(OBJS) $(SYS_OBJS) $(LIBS) $(LPCFIX) $(LD_TEMP) - $(CC) $(LDFLAGS) -T $(LD_TEMP) -o $(OUTFILE).elf $(OBJS) $(LDLIBS) - -@echo "" -# $(SIZE) $(OUTFILE).elf -# -@echo "" - -%.bin: %.elf -# $(OBJCOPY) $(OCFLAGS) -O binary $< $@ - -@echo "" -# $(LPCFIX) -c $@ - -.PHONY: $(LD_TEMP) lcd/liblcd.a applications/libapp.a filesystem/libfat.a usb/libusb.a +# GENERATED INCLUDE BRIDGE/ +include ../../firmware/Makefile +.IGNORE: $(OUTFILE).elf $(OUTFILE).bin From 032e3a4fbb890c4af23bdebbb93d5adb3239f0d9 Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 20 Jul 2011 07:59:35 +0200 Subject: [PATCH 12/24] Find all the firmware in libraries greatly simplifies CMakeLists.txt --- simulat0r/gui/CMakeLists.txt | 38 ++++++++++++++---------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/simulat0r/gui/CMakeLists.txt b/simulat0r/gui/CMakeLists.txt index 0bb9087..f209214 100644 --- a/simulat0r/gui/CMakeLists.txt +++ b/simulat0r/gui/CMakeLists.txt @@ -7,6 +7,10 @@ link_directories(${CMAKE_CURRENT_BINARY_DIR} ../../firmware/applications ../../firmware/filesystem ../../firmware/lcd +../../firmware/funk +../../firmware/basic +../../firmware/core +../../firmware/usbcdc ../../firmware/usb) include(${QT_USE_FILE}) @@ -27,28 +31,6 @@ QT_WRAP_CPP(qsimulat0r MocSources ${qsimulat0r_SRCS}) set(FIRMWARE_OBJS ../simcore/simcore.o ../simcore/misc.o - -../firmware/basic/basic.o -../firmware/basic/reinvoke_isp.o -../firmware/basic/delayms.o -../firmware/basic/uuid.o -../firmware/basic/keyin.o -../firmware/basic/voltage.o -../firmware/core/sysinit.o -../firmware/core/adc/adc.o -../firmware/core/cpu/cpu.o -../firmware/core/gpio/gpio.o -../firmware/core/i2c/i2c.o -../firmware/core/iap/iap.o -../firmware/core/libc/ctype.o -../firmware/core/libc/stdio.o -../firmware/core/libc/string.o -../firmware/core/pmu/pmu.o -../firmware/core/ssp/ssp.o -../firmware/core/systick/systick.o -../firmware/core/timer16/timer16.o -../firmware/core/timer32/timer32.o -../firmware/core/wdt/wdt.o ) @@ -62,7 +44,17 @@ add_executable(qsimulat0r ${qsimulat0r_SRCS} ${MocSources} ${FIRMWARE_OBJS} ) -target_link_libraries(qsimulat0r ${QT_LIBRARIES} libapp.a liblcd.a libusb.a libfat.a) +target_link_libraries(qsimulat0r +${QT_LIBRARIES} +libapp.a +liblcd.a +libusb.a +libfat.a +libfunk.a +libusbcdc.a +libbasic.a +libcore.a +) From 0ecb6ddffb92f4a8babdc6dc6153197a655cdc1c Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 20 Jul 2011 08:01:01 +0200 Subject: [PATCH 13/24] Added include bridge file --- simulat0r/firmware/applications/cbitset.h | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 simulat0r/firmware/applications/cbitset.h diff --git a/simulat0r/firmware/applications/cbitset.h b/simulat0r/firmware/applications/cbitset.h new file mode 100644 index 0000000..913a87e --- /dev/null +++ b/simulat0r/firmware/applications/cbitset.h @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/applications/cbitset.h" From eabf38452f236523040221231d4f5c831f03f4e1 Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 20 Jul 2011 08:03:02 +0200 Subject: [PATCH 14/24] Use cbitset for game of life to reduce data size - making it run on r0ket --- firmware/applications/cbitset.h | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 firmware/applications/cbitset.h diff --git a/firmware/applications/cbitset.h b/firmware/applications/cbitset.h new file mode 100644 index 0000000..4e76b82 --- /dev/null +++ b/firmware/applications/cbitset.h @@ -0,0 +1,53 @@ +#ifndef CBITFIELD_H +#define CBITFIELD_H + +#define BITSETCHUNKSIZE 32 + +#define one ((uint32_t)1) + +struct bitset { + uint16_t size; + uint32_t bits[BITSET_SIZE/BITSETCHUNKSIZE+1]; +}; + +static inline void bitset_set(struct bitset *bs,uint16_t index, uint8_t value) { + uint16_t base=index/BITSETCHUNKSIZE; + uint16_t offset=index%BITSETCHUNKSIZE; + if(value) { + bs->bits[base]|=(one<bits[base]&=~(one<bits[base]^=(one<bits[base]&(one< Date: Wed, 20 Jul 2011 08:08:09 +0200 Subject: [PATCH 15/24] Use cbitset for game of life to reduce data size - making it run on r0ket --- firmware/applications/life.c | 150 +++++++++++++++++------------------ 1 file changed, 71 insertions(+), 79 deletions(-) diff --git a/firmware/applications/life.c b/firmware/applications/life.c index 03bc23f..bafee14 100644 --- a/firmware/applications/life.c +++ b/firmware/applications/life.c @@ -2,9 +2,17 @@ #include "basic/basic.h" -#include "lcd/render.h" +//#include "lcd/render.h" #include "lcd/display.h" -#include "lcd/allfonts.h" +//#include "lcd/allfonts.h" + +#define BITSET_X (RESX+2) +#define BITSET_Y (RESY+2) +#define BITSET_SIZE (BITSET_X*BITSET_Y) + +#include "cbitset.h" + +typedef uint8_t uchar; unsigned char rnd1(); @@ -28,78 +36,63 @@ void fill_rect(char x0, char y0, char x1, char y1) { } #define STARTVALUE 10 -typedef unsigned char uchar; -typedef uchar row_t[RESY+2]; -uchar buf1[RESX+2][RESY+2]; -uchar buf2[RESX+2][RESY+2]; -row_t *life =buf1; -row_t *new =buf2; + +struct bitset _buf1,*buf1=&_buf1; +struct bitset _buf2,*buf2=&_buf2; + +struct bitset *life =&_buf1; +struct bitset *new =&_buf2; void swap_areas() { - row_t *tmp=life; + struct bitset *tmp=life; life=new; new=tmp; } -void fill_area(uchar area[RESX+2][RESY+2], uchar x0, uchar y0, uchar x1, uchar y1,uchar value) { +void fill_area(struct bitset *area, uchar x0, uchar y0, uchar x1, uchar y1,uchar value) { for(uchar x=x0; x<=x1; ++x) { for(uchar y=y0; y<=y1; ++y) { - area[x][y]=value; + bitset_set2(area,x,y,value); } } } -bool find_area(uchar area[RESX+2][RESY+2], uchar x0, uchar y0, uchar x1, uchar y1,uchar value) { +bool find_area(struct bitset *area, uchar x0, uchar y0, uchar x1, uchar y1,uchar value) { for(uchar x=x0; x<=x1; ++x) { for(uchar y=y0; y<=y1; ++y) { - if(area[x][y]==value) return true; + if(bitset_get2(area,x,y)==value) return true; } } return false; } -uint32_t sum_area(uchar area[RESX+2][RESY+2], uchar x0, uchar y0, uchar x1, uchar y1) { +uint32_t sum_area(struct bitset *area, uchar x0, uchar y0, uchar x1, uchar y1) { uint32_t sum=0; for(uchar x=x0; x<=x1; ++x) { for(uchar y=y0; y<=y1; ++y) { - sum+=area[x][y]; + sum+=bitset_get2(area,x,y); } } return sum; } void draw_area() { - for(uchar x=1; x<=RESX; ++x) { - for(uchar y=1; y<=RESY; ++y) { - lcdSetPixel(x,y,life[x+1][y+1]&1); + for(uchar x=0; x0; --x) { - for(uchar y=1; y Date: Thu, 21 Jul 2011 17:04:22 +0200 Subject: [PATCH 16/24] mandelbrot displaybuffer scrolling, zoom out --- firmware/applications/mandelbrot2.c | 149 +++++++++++++++++++--------- 1 file changed, 103 insertions(+), 46 deletions(-) diff --git a/firmware/applications/mandelbrot2.c b/firmware/applications/mandelbrot2.c index 5425108..1130992 100644 --- a/firmware/applications/mandelbrot2.c +++ b/firmware/applications/mandelbrot2.c @@ -24,7 +24,7 @@ void blink(){ struct mb { long rmin, rmax, imin, imax; - bool dirty; + bool dirty, dup, ddown, dleft, dright; } mandel; void mandelInit() { @@ -38,68 +38,126 @@ void mandelInit() { mandel.imax = fixpt(2); mandel.dirty = true; + mandel.dup = false; + mandel.ddown = false; + mandel.dleft = false; + mandel.dright = false; } void mandelMove() { - long delta_r = (mandel.rmax - mandel.rmin)/10; - long delta_i = (mandel.imax - mandel.imin)/10; - char key = getInputRaw(); + //long delta_r = (mandel.rmax - mandel.rmin)/10; + //long delta_i = (mandel.imax - mandel.imin)/10; + + long rs =(mandel.rmax-mandel.rmin)/RESY; + long is =(mandel.imax-mandel.imin)/RESX; - if(key == BTN_LEFT) { - mandel.imax -= delta_i; - mandel.imin -= delta_i; - mandel.dirty = true; + char key = getInputRaw(); + + if (key == BTN_LEFT) { + mandel.imax -=is; + mandel.imin -=is; + mandel.dleft = true; } else if (key == BTN_RIGHT) { - mandel.imax += delta_i; - mandel.imin += delta_i; - mandel.dirty = true; + mandel.imax += is; + mandel.imin += is; + mandel.dright = true; } else if (key == BTN_DOWN) { - mandel.rmax += delta_r; - mandel.rmin += delta_r; - mandel.dirty = true; + mandel.rmax += rs; + mandel.rmin += rs; + mandel.ddown = true; } else if (key == BTN_UP) { - mandel.rmax -= delta_r; - mandel.rmin -= delta_r; - mandel.dirty = true; - } else if (key == BTN_ENTER) { + mandel.rmax -= rs; + mandel.rmin -= rs; + mandel.dup = true; + } else if (key == (BTN_ENTER + BTN_UP)) { mandel.imin = mandel.imin + (mandel.imax-mandel.imin)/10; mandel.imax = mandel.imax - (mandel.imax-mandel.imin)/10; mandel.rmin = mandel.rmin +(mandel.rmax-mandel.rmin)/10; mandel.rmax = mandel.rmax -(mandel.rmax-mandel.rmin)/10; - mandel.dirty = true; - } - + mandel.dirty = true; + } else if (key == (BTN_ENTER + BTN_DOWN)) { + mandel.imin = mandel.imin - (mandel.imax-mandel.imin)/10; + mandel.imax = mandel.imax + (mandel.imax-mandel.imin)/10; + mandel.rmin = mandel.rmin -(mandel.rmax-mandel.rmin)/10; + mandel.rmax = mandel.rmax +(mandel.rmax-mandel.rmin)/10; + mandel.dirty = true; + } } - -void mandelCalc() { + +void mandelPixel(int x, int y) { long r0,i0,rn, p,q; long rs,is; int iteration; - char x, y; - rs=(mandel.rmax-mandel.rmin)/RESY; + + rs=(mandel.rmax-mandel.rmin)/RESY; is=(mandel.imax-mandel.imin)/RESX; - - for (x=0; x1); - lcdSetPixel(x, y, pixel); + //p=fixpt(mandel.rmin+y*rs); + //q=fixpt(mandel.imin+x*is); + p=mandel.rmin+y*rs; + q=mandel.imin+x*is; + + rn=0; + r0=0; + i0=0; + iteration=0; + while ((mul(rn,rn)+mul(i0,i0))1); + lcdSetPixel(x, y, pixel); +} + +void mandelUpdate() { + int xmin,xmax,ymin,ymax; + if (mandel.dirty) { + xmin = 0; + xmax = RESX; + ymin = 0; + ymax = RESY; + mandel.dirty = false; + } else if (mandel.dleft) { + lcdShift(1,0,false); + xmin = 0; + xmax = 1; + ymin = 0; + ymax = RESY; + mandel.dleft = false; + } else if (mandel.dright) { + lcdShift(-1,0,false); + xmin = RESX-1; + xmax = RESX; + ymin = 0; + ymax = RESY; + mandel.dright = false; + } else if (mandel.dup) { + lcdShift(0,-1,true); + xmin=0; + xmax=RESX; + ymin=0; + ymax=1; + mandel.dup = false; + } else if (mandel.ddown) { + lcdShift(0,1,true); + xmin=0; + xmax=RESX; + ymin=RESY-1; + ymax=RESY; + mandel.ddown = false; + } else { + return; + } + + for (int x = xmin; x Date: Thu, 21 Jul 2011 20:01:49 +0200 Subject: [PATCH 17/24] fix missing include. Also make lcdScroll nicer to read. --- firmware/lcd/display.c | 56 +++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/firmware/lcd/display.c b/firmware/lcd/display.c index e18fdaf..bf045ba 100644 --- a/firmware/lcd/display.c +++ b/firmware/lcd/display.c @@ -1,3 +1,5 @@ +#include + #include #include #include "lpc134x.h" @@ -213,42 +215,28 @@ void lcdShiftV(bool up, bool wrap) { } void lcdShift(int x, int y, bool wrap) { - int yb, yr, ya; - bool dir; + bool dir=true; - if (x>0) { - for (int cx = 0; cx < x; cx++) { - lcdShiftH(true, wrap); - } - } else if (x<0) { - for (int cx = x; cx < 0; cx++) { - lcdShiftH(false, wrap); - } - } + if(x<0){ + dir=false; + x=-x; + }; + while(x-->0) + lcdShiftH(dir, wrap); - if (y != 0) { - if (y>0) { - ya = y; - yb = y/8; - yr = y%8; - dir = true; - - } else if (y<0) { - ya = -y; - yb = (-y)/8; - yr = (-y)%8; - dir = false; - } - - //for (int cyb = 0; cyb < yb; cyb++) { - // lcdShiftV8(dir, wrap); - //} - //for (int cyr = 0; cyr < yr; cyr++) { - // lcdShiftV(dir, wrap); - //} - for (int cya = 0; cya < ya; cya++) { + if(y<0){ + dir=false; + y=-y; + }else{ + dir=true; + }; + + while(y>=8){ + y-=8; + lcdShiftV8(dir, wrap); + }; + + while(y-->0) lcdShiftV(dir, wrap); - } - } } From 742c422439bc07e5e660f2c78d380b10287b62ff Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 21 Jul 2011 20:02:44 +0200 Subject: [PATCH 18/24] Also enable diagonal scrolling. --- firmware/applications/scroll.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/firmware/applications/scroll.c b/firmware/applications/scroll.c index db41c14..2499b25 100644 --- a/firmware/applications/scroll.c +++ b/firmware/applications/scroll.c @@ -14,7 +14,6 @@ void main_scroll(void) { int dx=0; char key; backlightInit(); - font_direction = FONT_DIR_LTR; // LeftToRight is the default font=&Font_7x8; dx=DoString(0,0,"Hello World"); @@ -23,24 +22,24 @@ void main_scroll(void) { lcdDisplay(); //// delayms(10); - key= getInput(); + key= getInputRaw(); // Easy flashing - if(key==BTN_ENTER){ + if(key&BTN_ENTER){ DoString(0,8,"Enter ISP!"); lcdDisplay(); ISPandReset(); } - if(key==BTN_RIGHT){ + if(key&BTN_RIGHT){ lcdShift(1,0,true); } - if(key==BTN_LEFT){ + if(key&BTN_LEFT){ lcdShift(-1,0,true); } - if(key==BTN_UP){ + if(key&BTN_UP){ lcdShift(0,1,true); } - if(key==BTN_DOWN){ + if(key&BTN_DOWN){ lcdShift(0,-1,true); } From 148b2d9aee05cf1b784e39a8e5e6003d100f610c Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 21 Jul 2011 20:08:00 +0200 Subject: [PATCH 19/24] Also allow diagonal movement here. --- firmware/applications/font.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/firmware/applications/font.c b/firmware/applications/font.c index 25475e9..9801653 100644 --- a/firmware/applications/font.c +++ b/firmware/applications/font.c @@ -113,15 +113,19 @@ void f_nick(void){ delayms(40); key= getInputRaw(); - if(key==BTN_UP){ + if(key & BTN_UP){ --y;//if(--y<0) y=0; - }else if (key ==BTN_DOWN){ + }; + if (key & BTN_DOWN){ ++y;//if(++y>=RESY) y=RESY-1; - }else if (key ==BTN_LEFT){ + }; + if (key & BTN_LEFT){ --x;//if(--x<0) x=0; - }else if (key ==BTN_RIGHT){ + }; + if (key & BTN_RIGHT){ ++x;//if(++x>=RESX) x=RESX-1; - }else if (key ==BTN_ENTER){ + }; + if (key == BTN_ENTER){ lcdClear(); lcdPrintln("Done."); lcdDisplay(); From 63572af567e7d14afd3d183478374e6b333456d0 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 21 Jul 2011 20:37:04 +0200 Subject: [PATCH 20/24] Refactor getInput() using getInputRaw() --- firmware/basic/keyin.c | 51 +++++++++++++----------------------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/firmware/basic/keyin.c b/firmware/basic/keyin.c index 69254be..b8be57b 100644 --- a/firmware/basic/keyin.c +++ b/firmware/basic/keyin.c @@ -1,63 +1,42 @@ #include #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; - } - - return result; -} - uint8_t getInputRaw(void) { uint8_t result = BTN_NONE; if (gpioGetValue(RB_BTN3)==0) { - result += BTN_UP; + result |= BTN_UP; } if (gpioGetValue(RB_BTN2)==0) { - result += BTN_DOWN; + result |= BTN_DOWN; } if (gpioGetValue(RB_BTN4)==0) { - result += BTN_ENTER; + result |= BTN_ENTER; } if (gpioGetValue(RB_BTN0)==0) { - result += BTN_LEFT; + result |= BTN_LEFT; } if (gpioGetValue(RB_BTN1)==0) { - result += BTN_RIGHT; + result |= BTN_RIGHT; } return result; } +uint8_t getInput(void) { + uint8_t key = BTN_NONE; + + key=getInputRaw(); + if(key != BTN_NONE) + while(key==getInputRaw()); // Wait for any release + + return key; +} + uint8_t getInputWait(void) { uint8_t key; while ((key=getInput())==BTN_NONE) From 80ea686dc8795d92c08fe1e467ffc8f73ce9a8d2 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 21 Jul 2011 22:21:41 +0200 Subject: [PATCH 21/24] Fix "wrap==false" scrolling case. --- firmware/lcd/display.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/firmware/lcd/display.c b/firmware/lcd/display.c index bf045ba..8c44ab4 100644 --- a/firmware/lcd/display.c +++ b/firmware/lcd/display.c @@ -169,11 +169,11 @@ void lcdShiftH(bool right, bool wrap) { if (right) { tmp = lcdBuffer[yb*RESX]; memmove(lcdBuffer + yb*RESX,lcdBuffer + yb*RESX+1 ,RESX-1); - if (wrap) lcdBuffer[yb*RESX+(RESX-1)] = tmp; + lcdBuffer[yb*RESX+(RESX-1)] = wrap?tmp:0; } else { tmp = lcdBuffer[yb*RESX+(RESX-1)]; memmove(lcdBuffer + yb*RESX+1,lcdBuffer + yb*RESX ,RESX-1); - if (wrap) lcdBuffer[yb*RESX] = tmp; + lcdBuffer[yb*RESX] = wrap?tmp:0; } } } @@ -181,34 +181,46 @@ void lcdShiftH(bool right, bool wrap) { void lcdShiftV8(bool up, bool wrap) { uint8_t tmp[RESX]; if (up) { - if (wrap) memmove(tmp, lcdBuffer, RESX); + if (wrap) + memmove(tmp, lcdBuffer, RESX); + else + memset(tmp,0,RESX); memmove(lcdBuffer,lcdBuffer+RESX ,RESX*(RESY_B-1)); - if (wrap) memmove(lcdBuffer+RESX*(RESY_B-1),tmp,RESX); + memmove(lcdBuffer+RESX*(RESY_B-1),tmp,RESX); } else { - if (wrap) memmove(tmp, lcdBuffer+RESX*(RESY_B-1), RESX); + if (wrap) + memmove(tmp, lcdBuffer+RESX*(RESY_B-1), RESX); + else + memset(tmp,0,RESX); memmove(lcdBuffer+RESX,lcdBuffer ,RESX*(RESY_B-1)); - if (wrap) memmove(lcdBuffer,tmp,RESX); + memmove(lcdBuffer,tmp,RESX); } } void lcdShiftV(bool up, bool wrap) { uint8_t tmp[RESX]; if (up) { - if (wrap) memmove(tmp,lcdBuffer+((RESY_B-1)*RESX),RESX); + if (wrap) + memmove(tmp,lcdBuffer+((RESY_B-1)*RESX),RESX); + else + memset(tmp,0,RESX); for (int x = 0; x 0; y--){ lcdBuffer[x+(y*RESX)] = (lcdBuffer[x+(y*RESX)] << 1) |( lcdBuffer[x+((y-1)*RESX)] >> 7); } - if (wrap) lcdBuffer[x] = ( lcdBuffer[x] << 1) | ((tmp[x]>>3)&1); + lcdBuffer[x] = ( lcdBuffer[x] << 1) | ((tmp[x]>>3)&1); } } else { - if (wrap) memmove(tmp,lcdBuffer,RESX); + if (wrap) + memmove(tmp,lcdBuffer,RESX); + else + memset(tmp,0,RESX); for (int x = 0; x> 1) |( lcdBuffer[x+((y+1)*RESX)] << 7); } - if (wrap) lcdBuffer[x+((RESY_B-1)*RESX)] = ( lcdBuffer[x+((RESY_B-1)*RESX)] >> 1) | ((tmp[x]<<3)&8); + lcdBuffer[x+((RESY_B-1)*RESX)] = ( lcdBuffer[x+((RESY_B-1)*RESX)] >> 1) | ((tmp[x]<<3)&8); } } From c69431c0853607517936bff1f08e5d371c3c0f33 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 21 Jul 2011 22:27:08 +0200 Subject: [PATCH 22/24] Whoops. lcdShiftV8 had up/down swapped :) --- firmware/lcd/display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/lcd/display.c b/firmware/lcd/display.c index 8c44ab4..ca08074 100644 --- a/firmware/lcd/display.c +++ b/firmware/lcd/display.c @@ -180,7 +180,7 @@ void lcdShiftH(bool right, bool wrap) { void lcdShiftV8(bool up, bool wrap) { uint8_t tmp[RESX]; - if (up) { + if (!up) { if (wrap) memmove(tmp, lcdBuffer, RESX); else From bb3dc0044ce9d15c05bfd0f24aea8adc3d7d374f Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 21 Jul 2011 22:31:26 +0200 Subject: [PATCH 23/24] Add scrolling to lcdPrint() & co. --- firmware/lcd/print.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/firmware/lcd/print.c b/firmware/lcd/print.c index 6eb241e..8466283 100644 --- a/firmware/lcd/print.c +++ b/firmware/lcd/print.c @@ -6,7 +6,15 @@ int x=0; int y=0; +void checkScroll(void){ + if(y+font->u8Height>RESY){ + lcdShift(0,y+font->u8Height-RESY,false); + y=RESY-font->u8Height; + }; +}; + void lcdPrint(const char *string){ + checkScroll(); x=DoString(x,y,string); }; @@ -20,18 +28,22 @@ void lcdPrintln(const char *string){ }; void lcdPrintInt(const int num){ + checkScroll(); x=DoInt(x,y,num); }; void lcdPrintIntHex(const int num){ + checkScroll(); x=DoIntX(x,y,num); }; void lcdPrintCharHex(const uint8_t num){ + checkScroll(); x=DoCharX(x,y,num); }; void lcdPrintShortHex(const uint16_t num){ + checkScroll(); x=DoShortX(x,y,num); }; From 89e430de97f0bd97b58b3db0392185474963cae4 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 21 Jul 2011 22:32:48 +0200 Subject: [PATCH 24/24] Add more code to test scrolling --- firmware/applications/scroll.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/firmware/applications/scroll.c b/firmware/applications/scroll.c index 2499b25..4217a7c 100644 --- a/firmware/applications/scroll.c +++ b/firmware/applications/scroll.c @@ -5,6 +5,7 @@ #include "lcd/render.h" #include "lcd/display.h" #include "lcd/allfonts.h" +#include "lcd/print.h" void backlightInit(void); @@ -14,6 +15,8 @@ void main_scroll(void) { int dx=0; char key; backlightInit(); + bool wrap=true; + int ctr=0; font=&Font_7x8; dx=DoString(0,0,"Hello World"); @@ -25,22 +28,27 @@ void main_scroll(void) { key= getInputRaw(); // Easy flashing - if(key&BTN_ENTER){ + if((key&(BTN_ENTER|BTN_LEFT))==(BTN_ENTER|BTN_LEFT)){ DoString(0,8,"Enter ISP!"); lcdDisplay(); ISPandReset(); } + if(key&BTN_ENTER){ + lcdPrintInt(ctr++); + lcdPrintln("."); + while(getInputRaw())delayms(10); + }; if(key&BTN_RIGHT){ - lcdShift(1,0,true); + lcdShift(1,0,wrap); } if(key&BTN_LEFT){ - lcdShift(-1,0,true); + lcdShift(-1,0,wrap); } if(key&BTN_UP){ - lcdShift(0,1,true); + lcdShift(0,1,wrap); } if(key&BTN_DOWN){ - lcdShift(0,-1,true); + lcdShift(0,-1,wrap); } //font = &Font_Ubuntu36pt;