diff --git a/firmware/Makefile b/firmware/Makefile index 0f54761..9f1b1f7 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -42,6 +42,7 @@ LDLIBS += -Llcd -llcd LDLIBS += -Lcore -lcore LDLIBS += -Lusb -lusb LDLIBS += -lbasic +LDLIBS += -lfunk OCFLAGS = --strip-unneeded SUBDIRS?= $(foreach lib,$(LIBS),$(dir $(lib))) diff --git a/firmware/Makefile.inc b/firmware/Makefile.inc index 7085dd9..855d011 100644 --- a/firmware/Makefile.inc +++ b/firmware/Makefile.inc @@ -23,6 +23,8 @@ CC = $(CROSS_COMPILE)gcc LD = $(CROSS_COMPILE)ld REALLD = $(CROSS_COMPILE)ld SIZE = $(CROSS_COMPILE)size +AR = $(CROSS_COMPILE)ar +RANLIB = $(CROSS_COMPILE)ranlib OBJCOPY = $(CROSS_COMPILE)objcopy OBJDUMP = $(CROSS_COMPILE)objdump OUTFILE = firmware diff --git a/firmware/Makefile.util b/firmware/Makefile.util index 5e7916b..735c919 100644 --- a/firmware/Makefile.util +++ b/firmware/Makefile.util @@ -6,6 +6,7 @@ all: $(LIBFILE) $(LIBFILE): $(OBJS) $(AR) rcs $@ $(OBJS) + $(RANLIB) $(RANLIBFLAGS) $@ %.o : %.c $(CC) $(CFLAGS) -o $@ $< diff --git a/firmware/applications/Makefile b/firmware/applications/Makefile index 86a45db..82b69df 100644 --- a/firmware/applications/Makefile +++ b/firmware/applications/Makefile @@ -8,6 +8,10 @@ ifeq "$(APP)" "initial" NODEFAULT = y endif +ifeq "$(APP)" "tester" +DEBUG = -d +endif + ifndef NODEFAULT OBJS += default.o endif @@ -33,6 +37,7 @@ endif WRAP=wrapper LIBNAME=app + ########################################################################## # GNU GCC compiler flags ########################################################################## @@ -66,21 +71,21 @@ $(LOBJ): OBJS += $(LOBJ) endif -ifeq "$(APP)" "tester" +ifeq "$(wildcard $(APP))" "$(APP)" ifndef TYPE TYPE=$(APP) endif -TSRCS = $(wildcard $(TYPE)/*.c) +TSRCS = $(foreach type,$(TYPE),$(wildcard $(type)/*.c)) TOBJS = $(foreach mod,$(TSRCS),$(subst .c,.o,$(mod))) -TWRAP=tester.gen +TWRAP=$(APP).gen .PHONY: $(TWRAP) $(APP).o: $(TWRAP) $(TWRAP): - ./mktester $(TSRCS) > $@ + ./mkfirmware.pl $(DEBUG) $(APP) $(TSRCS) > $@ OBJS += $(TOBJS) endif @@ -93,7 +98,7 @@ $(LIBFILE): $(OBJS) $(WRAPOBJ) $(CC) $(CFLAGS) -o $@ $< clean: - rm -f $(OBJS) $(WRAPOBJ) $(WRAPSRC) $(LIBFILE) *.o */*.o + rm -f $(OBJS) $(WRAPOBJ) $(WRAPSRC) $(LIBFILE) *.o */*.o *.gen %.c: @echo diff --git a/firmware/applications/adc.c b/firmware/applications/adc.c index 2d8b6c8..293fb44 100644 --- a/firmware/applications/adc.c +++ b/firmware/applications/adc.c @@ -15,9 +15,6 @@ void main_adc(void) { uint32_t brightness = 0; uint8_t c = 0; - font_direction = FONT_DIR_LTR; // LeftToRight is the default - font = &Font_7x8; - DoString(0, 0, "adc"); backlightInit(); diff --git a/firmware/applications/default.c b/firmware/applications/default.c index d4f0b00..eed6119 100644 --- a/firmware/applications/default.c +++ b/firmware/applications/default.c @@ -1,10 +1,12 @@ #include #include "basic/basic.h" +#include "basic/config.h" #include "lcd/lcd.h" #include "lcd/fonts/smallfonts.h" #include "lcd/print.h" #include "filesystem/ff.h" +#include "usb/usbmsc.h" #include "basic/random.h" /**************************************************************************/ @@ -12,51 +14,66 @@ void main_default(void) { systickInit(SYSTICKSPEED); - if(getInputRaw()==BTN_ENTER){ - ISPandReset(); + switch(getInputRaw()){ + case BTN_ENTER: + ISPandReset(); + break; + case BTN_DOWN: + usbMSCInit(); + while(1) + delayms_power(100); + break; }; readConfig(); - applyConfig(); randomInit(); return; }; + + +void queue_setinvert(void){ + lcdSetInvert(1); +}; +void queue_unsetinvert(void){ + lcdSetInvert(0); +}; + +#define EVERY(x,y) if((ctr+y)%(x/SYSTICKSPEED)==0) + // every 10 ms void tick_default(void) { static int ctr; ctr++; incTimer(); - if(ctr>1000/SYSTICKSPEED){ + + EVERY(1000,0){ if(!adcMutex){ VoltageCheck(); LightCheck(); - ctr=0; }else{ ctr--; }; }; - if(ctr>100/SYSTICKSPEED){ - if(isNight()){ - backlightSetBrightness(GLOBAL(lcdbacklight)); - if(GLOBAL(nightinvert)) - lcdSetInvert(0); - } else { - backlightSetBrightness(0); - if(GLOBAL(nightinvert)) - lcdSetInvert(1); - } - } + static char night=0; + EVERY(100,2){ + if(night!=isNight()){ + night=isNight(); + if(night){ + backlightSetBrightness(GLOBAL(lcdbacklight)); + push_queue(queue_unsetinvert); + }else{ + backlightSetBrightness(0); + push_queue(queue_setinvert); + }; + }; + }; - if(ctr%(50/SYSTICKSPEED)==0){ - if(GetVoltage()<3600 -#ifdef SAFE - || GetVoltage() > 10000 // pin not connected -#endif - ){ + EVERY(50,0){ + if(GetVoltage()<3600){ IOCON_PIO1_11 = 0x0; gpioSetDir(RB_LED3, gpioDirection_Output); if( (ctr/(50/SYSTICKSPEED))%10 == 1 ) @@ -65,6 +82,5 @@ void tick_default(void) { gpioSetValue (RB_LED3, 0); }; }; - return; }; diff --git a/firmware/applications/exe.c b/firmware/applications/exe.c index 44b2d2d..9ba0a1d 100644 --- a/firmware/applications/exe.c +++ b/firmware/applications/exe.c @@ -52,24 +52,16 @@ void adc_check(void) { /**************************************************************************/ -const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; -const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror}; -const struct MENU_DEF menu_volt = {"Akku", &adc_check}; -const struct MENU_DEF menu_nop = {"---", NULL}; -const struct MENU_DEF menu_msc = {"MSC", &msc_menu}; -const struct MENU_DEF menu_exe = {"Exec", &execute_menu}; +static const struct MENU mainmenu = {"Mainmenu", { + {"MSC", &msc_menu}, + {"Exec", &execute_menu}, + {"---", NULL}, + {"Mirror", &lcd_mirror}, + {"Akku", &adc_check}, + {"Invoke ISP", &gotoISP}, + {NULL,NULL} +}}; -static menuentry menu[] = { - &menu_msc, - &menu_exe, - &menu_nop, - &menu_mirror, - &menu_volt, - &menu_ISP, - NULL, -}; - -static const struct MENU mainmenu = {"Mainmenu", menu}; void main_exe(void) { diff --git a/firmware/applications/executor.c b/firmware/applications/executor.c deleted file mode 100644 index 3fdf65a..0000000 --- a/firmware/applications/executor.c +++ /dev/null @@ -1,181 +0,0 @@ -#include - -#include "basic/basic.h" - -#include "lcd/render.h" -#include "lcd/allfonts.h" - -void backlightInit(void); - -extern void * __sram_top; - -void execute (const void *function, uint16_t length){ - void (*dst)(void); - - dst=(void (*)(void)) (__sram_top); - - DoString(0,8,"Enter RAM!"); - DoIntX(0,16,(uint32_t)function); - DoIntX(0,24,(uint32_t)dst); - lcdDisplay(); - - for(int i=0;itrigger){ - ctr=0; - if (gpioGetValue(RB_LED2) == CFG_LED_OFF){ - gpioSetValue (RB_LED2, CFG_LED_ON); - } else { - gpioSetValue (RB_LED2, CFG_LED_OFF); - }; - }; - - // Print Voltage - font = &Font_7x8; - dx=DoString(0,yctr+28,"Voltage:"); - DoInt(dx,yctr+28,GetVoltage()); - - } - return; -} - -void tick_executor(void){ - static int foo=0; - static int toggle=0; - if(foo++>50){ - toggle=1-toggle; - foo=0; - gpioSetValue (RB_LED0, toggle); - }; - return; -}; - - - diff --git a/firmware/applications/final.c b/firmware/applications/final.c new file mode 100644 index 0000000..c2f757e --- /dev/null +++ b/firmware/applications/final.c @@ -0,0 +1,35 @@ +#include + +#include "basic/basic.h" + +#include "lcd/print.h" + +#include + +/**************************************************************************/ + +#include "final.gen" + +void init_nick(); +void fancyNickname(); + +void main_final(void) { + //checkFirstBoot(); + init_final(); + + while(1){ +#ifndef FINAL + if(getInputRaw()==BTN_LEFT) + ISPandReset(); +#endif + if(getInput()){ + handleMenu(&mainmenu); + getInputWaitRelease(); + init_nick(); + }; + fancyNickname(); + delayms_queue(100); + }; +}; + +void tick_final(void); diff --git a/firmware/applications/final/config.c b/firmware/applications/final/config.c new file mode 100644 index 0000000..943d31d --- /dev/null +++ b/firmware/applications/final/config.c @@ -0,0 +1,127 @@ +#include + +#include "basic/basic.h" +#include "basic/config.h" + +#include "lcd/print.h" +#include "lcd/render.h" +#include "lcd/display.h" + +#include "filesystem/ff.h" + +#include + +/**************************************************************************/ + +void readcfg(void) { + readConfig(); +}; + +void savecfg(void){ + saveConfig(); +}; + +void applycfg(void){ + applyConfig(); +}; + +//# MENU config +void changer(void){ + uint8_t numentries = 0; + signed char menuselection = 0; + uint8_t visible_lines = 0; + uint8_t current_offset = 0; + + for (int i=0;the_config[i].name!=NULL;i++){ + numentries++; + }; + + visible_lines = ((RESY/getFontHeight())-1)/2; + + while (1) { + // Display current menu page + lcdClear(); + lcdPrint("Config"); + + lcdSetCrsrX(60); + lcdPrint("["); + lcdPrint(IntToStr(current_offset/visible_lines,1,0)); + lcdPrint("/"); + lcdPrint(IntToStr(numentries/visible_lines,1,0)); + lcdPrint("]"); + lcdNl(); + + lcdNl(); + + for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++) { + if(i==0){ + lcdPrintln("Save changes:"); + if (i == menuselection) + lcdPrint("*"); + lcdSetCrsrX(14); + if (i == menuselection) + lcdPrintln("YES"); + else + lcdPrintln("no"); + }else{ + lcdPrintln(the_config[i].name); + if (i == menuselection) + lcdPrint("*"); + lcdSetCrsrX(14); + lcdPrint("<"); + lcdPrint(IntToStr(the_config[i].value,3,F_LONG)); + lcdPrintln(">"); + }; + } + lcdRefresh(); + + switch (getInputWait()) { + case BTN_UP: + menuselection--; + if (menuselection < current_offset) { + if (menuselection < 0) { + menuselection = numentries-1; + current_offset = ((numentries-1)/visible_lines) * visible_lines; + } else { + current_offset -= visible_lines; + } + } + break; + case BTN_DOWN: + menuselection++; + if (menuselection > (current_offset + visible_lines-1) || menuselection >= numentries) { + if (menuselection >= numentries) { + menuselection = 0; + current_offset = 0; + } else { + current_offset += visible_lines; + } + } + break; + case BTN_LEFT: + if(the_config[menuselection].value > + the_config[menuselection].min) + the_config[menuselection].value--; + if(the_config[menuselection].value > the_config[menuselection].max) + the_config[menuselection].value= + the_config[menuselection].max; + applyConfig(); + break; + case BTN_RIGHT: + if(the_config[menuselection].value < + the_config[menuselection].max) + the_config[menuselection].value++; + if(the_config[menuselection].value < the_config[menuselection].min) + the_config[menuselection].value= + the_config[menuselection].min; + applyConfig(); + break; + case BTN_ENTER: + if(menuselection==0) + saveConfig(); + return; + } + getInputWaitRelease(); + } + /* NOTREACHED */ +} diff --git a/firmware/applications/final/exe.c b/firmware/applications/final/exe.c new file mode 100644 index 0000000..bd7c7c1 --- /dev/null +++ b/firmware/applications/final/exe.c @@ -0,0 +1,21 @@ +#include +#include + +#include "basic/basic.h" +#include "lcd/lcd.h" +#include "lcd/allfonts.h" +#include "lcd/print.h" +#include "usb/usbmsc.h" +#include "filesystem/ff.h" +#include "filesystem/select.h" +#include "filesystem/execute.h" + +/**************************************************************************/ + +//# MENU execute +void execute_menu(void){ + while(getInput()!=BTN_NONE); + executeSelect("C0D"); + lcdRefresh(); +}; + diff --git a/firmware/applications/final/flame.c b/firmware/applications/final/flame.c new file mode 100644 index 0000000..9775ad1 --- /dev/null +++ b/firmware/applications/final/flame.c @@ -0,0 +1,174 @@ +/* + + flame m0dul - https://github.com/kiu/flame + +*/ + +#include "basic/basic.h" +#include "core/i2c/i2c.h" +#include "basic/config.h" + +#define FLAME_I2C_WRITE 0xC4 +#define FLAME_I2C_READ 0xC5 + +#define FLAME_I2C_CR_INPUT 0x00 +#define FLAME_I2C_CR_PSC0 0x01 +#define FLAME_I2C_CR_PWM0 0x02 +#define FLAME_I2C_CR_PSC1 0x03 +#define FLAME_I2C_CR_PWM1 0x04 +#define FLAME_I2C_CR_LS0 0x05 + +#define FLAME_I2C_LS0_OFF 0x00 +#define FLAME_I2C_LS0_ON 0x01 +#define FLAME_I2C_LS0_PWM0 0x02 +#define FLAME_I2C_LS0_PWM1 0x03 + +#define FLAME_I2C_LS0_LED0 0x00 +#define FLAME_I2C_LS0_LED1 0x02 +#define FLAME_I2C_LS0_LED2 0x04 +#define FLAME_I2C_LS0_LED3 0x06 + +#define FLAME_OFF 0x00 +#define FLAME_UP 0x01 +#define FLAME_UP_WAIT 0x02 +#define FLAME_DOWN 0x03 +#define FLAME_DOWN_WAIT 0x04 + +/**************************************************************************/ + +#define flameBrightnessMax GLOBAL(flamemax) +#define flameBrightnessMin GLOBAL(flamemin) +#define flameSpeedUp GLOBAL(flamespeed) +#define flameSpeedDown GLOBAL(flamespeed) +#define flameWaitUp GLOBAL(flamemaxw) +#define flameWaitDown GLOBAL(flameminw) + +uint8_t flameEnabled = 0; +uint8_t flameMode = FLAME_OFF; +uint8_t flameI2Cpwm = 0; +uint8_t flameTicks = 0; + +uint32_t flameSetI2C(uint8_t cr, uint8_t value) { + I2CMasterBuffer[0] = FLAME_I2C_WRITE; + I2CMasterBuffer[1] = cr; + I2CMasterBuffer[2] = value; + I2CWriteLength = 3; + I2CReadLength = 0; + return i2cEngine(); +} + +void setFlamePWM() { + flameSetI2C(FLAME_I2C_CR_PWM0, flameI2Cpwm); // set pwm +} + +void tick_flame(void) { // every 10ms + static char night=0; + + if(!flameEnabled) + return; + + if(night!=isNight()){ + night=isNight(); + if(!night){ + flameMode = FLAME_OFF; + flameI2Cpwm = 0; + push_queue(&setFlamePWM); + }; + }; + + flameTicks++; + + if (flameI2Cpwm > flameBrightnessMax) { + flameI2Cpwm = flameBrightnessMax; + } + if (flameI2Cpwm < flameBrightnessMin) { + flameI2Cpwm = flameBrightnessMin; + } + + if (flameMode == FLAME_OFF) { + if (isNight() && flameEnabled) { + flameTicks = 0; + flameMode = FLAME_UP; + } + } + + if (flameMode == FLAME_UP) { + if (flameI2Cpwm + flameSpeedUp > flameI2Cpwm ) { + flameI2Cpwm += flameSpeedUp; + } else { + flameI2Cpwm = 0xFF; + } + push_queue(&setFlamePWM); + if (flameI2Cpwm == flameBrightnessMax) { + flameMode = FLAME_UP_WAIT; + flameTicks = 0; + } + } + + if (flameMode == FLAME_UP_WAIT) { + if (flameTicks >= flameWaitUp) { + flameMode = FLAME_DOWN; + } + } + + if (flameMode == FLAME_DOWN) { + if (flameI2Cpwm - flameSpeedDown < flameI2Cpwm ) { + flameI2Cpwm -= flameSpeedDown; + } else { + flameI2Cpwm = 0x00; + } + push_queue(&setFlamePWM); + if (flameI2Cpwm == flameBrightnessMin) { + flameMode = FLAME_DOWN_WAIT; + flameTicks = 0; + } + } + + if (flameMode == FLAME_DOWN_WAIT) { + if (flameTicks >= flameWaitDown) { + flameMode = FLAME_OFF; + } + } +} + +//# MENU flame +void flameInit(void) { + + i2cInit(I2CMASTER); // Init I2C + + flameEnabled = (flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED0) == I2CSTATE_ACK); // probe i2c + + if (flameEnabled) { + flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED0); // set led0 off + flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED1); // set led1 off + flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED2); // set led2 off + flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED3); // set led3 off + + flameSetI2C(FLAME_I2C_CR_PSC0, 0x00); // set prescaler + flameSetI2C(FLAME_I2C_CR_PWM0, 0x00); // set pwm + flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_PWM0 << FLAME_I2C_LS0_LED0); // set led0 to pwm + } +} + +#include "lcd/print.h" + +//# MENU debug ChkFlame +void ChkFlame(void) { + do{ + lcdClear(); + lcdPrint("Enabled:"); + lcdPrintln(IntToStr(flameEnabled,1,0)); + + lcdPrint("State:"); + lcdPrintln(IntToStr(flameMode,1,0)); + + lcdPrint("PWMtarg:"); + lcdPrintln(IntToStr(flameI2Cpwm,3,0)); + + lcdPrint("FTicks:"); + lcdPrintln(IntToStr(flameTicks,3,0)); + + lcdRefresh(); + delayms_queue(10); + } while ((getInputRaw())==BTN_NONE); +} diff --git a/firmware/applications/final/mesh.c b/firmware/applications/final/mesh.c new file mode 100644 index 0000000..1dc3d95 --- /dev/null +++ b/firmware/applications/final/mesh.c @@ -0,0 +1,277 @@ +#include +#include +#include + +#include "basic/basic.h" +#include "basic/byteorder.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" + +#include "funk/nrf24l01p.h" + +#include "funk/mesh.h" + +#include + +/**************************************************************************/ + +void init_mesh(void){ + nrf_init(); + initMesh(); +}; + +void m_tset(void){ + _timet=1311961112; +}; + +//# MENU debug MeshInfo +void m_time(void){ + struct tm* tm; + char c[2]={0,0}; + getInputWaitRelease(); + delayms(100); + do{ + lcdClear(); + tm= mygmtime(getSeconds()); + lcdPrint(IntToStr(tm->tm_hour,2,F_LONG)); + lcdPrint(":"); + lcdPrint(IntToStr(tm->tm_min,2,F_LONG|F_ZEROS)); + lcdPrint(":"); + lcdPrint(IntToStr(tm->tm_sec,2,F_LONG|F_ZEROS)); + lcdNl(); + lcdPrint(IntToStr(tm->tm_mday,2,F_LONG)); + lcdPrint("."); + lcdPrint(IntToStr(tm->tm_mon+1,2,0)); + lcdPrint("."); + lcdPrint(IntToStr(tm->tm_year+YEAR0,4,F_LONG|F_ZEROS)); + lcdNl(); + + lcdNl(); + lcdPrint("<"); + + for(int i=0;i"); + + lcdPrint("Gen:"); + lcdPrintInt(meshgen); + lcdNl(); + lcdRefresh(); + delayms_queue(50); + }while ((getInputRaw())==BTN_NONE); +}; + + +inline void blink(char a, char b){ + gpioSetValue (a,b, 1-gpioGetValue(a,b)); +}; + + +int choose(char * texts, int8_t menuselection){ + uint8_t numentries = 0; + uint8_t visible_lines = 0; + uint8_t current_offset = 0; + + char*p=texts; + + do{ + lcdPrintln(p); + while(*p)p++; + numentries++;p++; + }while(*p); + numentries--; + + visible_lines = (RESY/getFontHeight())-1; // subtract title line + + while (1) { + // Display current menu page + lcdClear(); + lcdPrintln(texts); + p=texts; + while(*p++); + for(int i=0;i (current_offset + visible_lines-1) || menuselection >= numentries) { + if (menuselection >= numentries) { + menuselection = 0; + current_offset = 0; + } else { + current_offset += visible_lines; + } + } + break; + case BTN_LEFT: + return -1; + case BTN_RIGHT: + case BTN_ENTER: + return menuselection; + } + getInputWaitRelease(); + } + /* NOTREACHED */ +} + + + +/***********************************************************************/ + +char *meshmsgs(void){ + static char msgtypes[MESHBUFSIZE+1]; + memset(msgtypes,'_',MESHBUFSIZE); + msgtypes[MESHBUFSIZE]=0; + uint8_t lo=0; + uint8_t hi; + + for(int o=0;olo) + if(MO_TYPE(meshbuffer[i].pkt)='a' && tmm[i]<='z'){ + lcdPrintln(IntToStr(MO_TIME(meshbuffer[j].pkt),10,0)); + }else{ + struct tm *tm= mygmtime(MO_TIME(meshbuffer[j].pkt)); + lcdPrint(IntToStr(tm->tm_hour,2,F_LONG)); + lcdPrint(":"); + lcdPrint(IntToStr(tm->tm_min,2,F_LONG|F_ZEROS)); + lcdPrint(":"); + lcdPrint(IntToStr(tm->tm_sec,2,F_LONG|F_ZEROS)); + lcdNl(); + }; + char *foo=(char *)MO_BODY(meshbuffer[j].pkt); + while(strlen(foo)>13){ + int q; + for(q=0;q<13;q++){ + if(foo[q]==' ') + break; + }; + foo[q]=0; + lcdPrintln(foo); + foo[q]=' '; + foo+=q+1; + }; + lcdPrintln(foo); + lcdRefresh(); + getInputWaitRelease(); + }; +}; + + +void tick_mesh(void){ + mesh_systick(); +}; + diff --git a/firmware/applications/final/nickname.c b/firmware/applications/final/nickname.c new file mode 100644 index 0000000..48dde5f --- /dev/null +++ b/firmware/applications/final/nickname.c @@ -0,0 +1,64 @@ +#include +#include +#include + +#include "basic/basic.h" +#include "basic/byteorder.h" +#include "basic/config.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" + +#include "filesystem/ff.h" +#include "filesystem/select.h" + +#include + +/**************************************************************************/ + +void fancyNickname(void) { + int dx=0; + int dy=0; + static uint32_t ctr=0; + ctr++; + + + lcdClear(); + setExtFont(GLOBAL(nickfont)); + DoString(dx,dy,GLOBAL(nickname)); + lcdRefresh(); + + return; +} + +/**************************************************************************/ + +void init_nick(void){ + readFile("nick.cfg",GLOBAL(nickname),MAXNICK); +// readFile("font.cfg",GLOBAL(nickfont),FILENAMELEN); +}; + +//# MENU nick editNick +void doNick(void){ + input("Nickname:", GLOBAL(nickname), 32, 127, MAXNICK-1); + writeFile("nick.cfg",GLOBAL(nickname),strlen(GLOBAL(nickname))); + getInputWait(); +}; + +//# MENU nick changeFont +void doFont(void){ + getInputWaitRelease(); + if( selectFile(GLOBAL(nickfont),"F0N") != 0){ + lcdPrintln("No file selected."); + return; + }; + + lcdClear(); + lcdPrintln(GLOBAL(nickfont)); + setExtFont(GLOBAL(nickfont)); + lcdPrintln("PUabc€"); + setIntFont(&Font_7x8); + lcdPrintln("done."); + lcdDisplay(); + while(!getInputRaw())delayms(10); +}; diff --git a/firmware/applications/final/util.c b/firmware/applications/final/util.c new file mode 100644 index 0000000..fca9cdc --- /dev/null +++ b/firmware/applications/final/util.c @@ -0,0 +1,139 @@ +#include +#include + +#include "basic/basic.h" +#include "basic/config.h" + +#include "lcd/render.h" +#include "lcd/print.h" + +#include "usb/usbmsc.h" + +#include "core/iap/iap.h" + +/**************************************************************************/ + +//# MENU debug ChkLight +void ChkLight(void) { + int dx=0; + int dy=8; + dx=DoString(0,dy,"Light:"); + DoString(0,dy+16,"Night:"); + while ((getInputRaw())==BTN_NONE){ + DoInt(dx,dy,GetLight()); + DoInt(dx,dy+16,isNight()); + DoInt(dx,dy+8,GLOBAL(daytrig)); + lcdDisplay(); + delayms_queue(100); + }; + dx=DoString(0,dy+24,"Done."); +} + +//# MENU debug ChkBattery +void ChkBattery(void) { + do{ + lcdClear(); + lcdPrintln("Voltage:"); + lcdPrintln(IntToStr(GetVoltage(),5,0)); + lcdNl(); + lcdPrintln("Chrg_stat:"); + if(gpioGetValue(RB_PWR_CHRG)){ + lcdPrintln("1"); + }else{ + lcdPrintln("0"); + }; + lcdRefresh(); +// delayms_queue(100); + } while ((getInputRaw())==BTN_NONE); +} + +//# MENU debug Uptime +void uptime(void) { + int t; + int h; + char flag; + while ((getInputRaw())==BTN_NONE){ + lcdClear(); + lcdPrintln("Uptime:"); + t=getTimer()/(1000/SYSTICKSPEED); + h=t/60/60; + flag=F_ZEROS; + if(h>0){ + lcdPrint(IntToStr(h,2,flag)); + lcdPrint("h"); + flag|=F_LONG; + }; + h=t/60%60; + if(h>0){ + lcdPrint(IntToStr(h,2,flag)); + lcdPrint("m"); + flag|=F_LONG; + }; + h=t%60; + if(h>0){ + lcdPrint(IntToStr(h,2,flag)); + lcdPrint("s"); + }; + lcdNl(); + lcdNl(); + lcdPrintln("Ticks:"); + lcdPrint(IntToStr(_timectr,10,0)); + lcdRefresh(); + delayms_queue(200); + }; + lcdPrintln("done."); +} + +//# MENU debug Uuid +void uuid(void) { + IAP_return_t iap_return; + iap_return = iapReadSerialNumber(); + lcdClear(); + lcdPrintln("UUID:"); + lcdPrintIntHex(iap_return.Result[0]); lcdNl(); + lcdPrintIntHex(iap_return.Result[1]); lcdNl(); + lcdPrintIntHex(iap_return.Result[2]); lcdNl(); + lcdPrintIntHex(iap_return.Result[3]); lcdNl(); + lcdNl(); + lcdPrintln("Beacon ID:"); + lcdPrintln(IntToStrX(GetUUID32(),4)); + lcdRefresh(); +} + +//# MENU debug Qstatus +void Qstatus(void) { + int dx=0; + int dy=8; + lcdClear(); + dx=DoString(0,dy+16,"Qdepth:"); + while ((getInputRaw())!=BTN_ENTER){ + DoInt(dx,dy+16,(the_queue.qend-the_queue.qstart+MAXQENTRIES)%MAXQENTRIES); + lcdDisplay(); + if(getInputRaw()!=BTN_NONE) + work_queue(); + else + delayms(10); + }; + dy+=16; + dx=DoString(0,dy,"Done."); +}; + +void blink_led0(void){ + gpioSetValue (RB_LED0, 1-gpioGetValue(RB_LED0)); +}; + +void tick_alive(void){ + static int foo=0; + + if(GLOBAL(alivechk)==0) + return; + + if(foo++>500/SYSTICKSPEED){ + foo=0; + if(GLOBAL(alivechk)==2) + push_queue(blink_led0); + else + blink_led0(); + }; + return; +}; diff --git a/firmware/applications/flame.c b/firmware/applications/flame.c index 0b6ed48..387bae3 100644 --- a/firmware/applications/flame.c +++ b/firmware/applications/flame.c @@ -37,10 +37,20 @@ void ReinvokeISP(void); /**************************************************************************/ +//TODO SEC move to config +uint8_t flameBrightnessMax = 0xff; +uint8_t flameBrightnessMin = 0x00; +uint8_t flameSpeedUp = 0x01; +uint8_t flameSpeedDown = 0x01; +uint8_t flameWaitUp = 0xff; +uint8_t flameWaitDown = 0x8f; +//TODO SEC move to config + + uint8_t flameEnabled = 0; uint8_t flameMode = FLAME_OFF; uint8_t flameI2Cpwm = 0; -uint16_t flameTicks = 0; +uint8_t flameTicks = 0; uint32_t flameSetI2C(uint8_t cr, uint8_t value) { I2CMasterBuffer[0] = FLAME_I2C_WRITE; @@ -55,9 +65,17 @@ void setFlamePWM() { flameSetI2C(FLAME_I2C_CR_PWM0, flameI2Cpwm); // set pwm } + void tick_flame(void) { // every 10ms flameTicks++; + if (flameI2Cpwm > flameBrightnessMax) { + flameI2Cpwm = flameBrightnessMax; + } + if (flameI2Cpwm < flameBrightnessMin) { + flameI2Cpwm = flameBrightnessMin; + } + if (flameMode == FLAME_OFF) { if (isNight() && flameEnabled) { flameTicks = 0; @@ -66,31 +84,39 @@ void tick_flame(void) { // every 10ms } if (flameMode == FLAME_UP) { - flameI2Cpwm++; + if (flameI2Cpwm + flameSpeedUp > flameI2Cpwm ) { + flameI2Cpwm += flameSpeedUp; + } else { + flameI2Cpwm = 0xFF; + } push_queue(&setFlamePWM); - if (flameI2Cpwm == 0xFF) { + if (flameI2Cpwm == flameBrightnessMax) { flameMode = FLAME_UP_WAIT; flameTicks = 0; } } if (flameMode == FLAME_UP_WAIT) { - if (flameTicks > 0xFF) { + if (flameTicks >= flameWaitUp) { flameMode = FLAME_DOWN; } } if (flameMode == FLAME_DOWN) { - flameI2Cpwm--; + if (flameI2Cpwm - flameSpeedDown < flameI2Cpwm ) { + flameI2Cpwm -= flameSpeedDown; + } else { + flameI2Cpwm = 0x00; + } push_queue(&setFlamePWM); - if (flameI2Cpwm == 0x00) { + if (flameI2Cpwm == flameBrightnessMin) { flameMode = FLAME_DOWN_WAIT; flameTicks = 0; } } if (flameMode == FLAME_DOWN_WAIT) { - if (flameTicks > 0x8F) { + if (flameTicks >= flameWaitDown) { flameMode = FLAME_OFF; } } diff --git a/firmware/applications/font.c b/firmware/applications/font.c index a79b055..75115b1 100644 --- a/firmware/applications/font.c +++ b/firmware/applications/font.c @@ -27,18 +27,6 @@ void f_init(void){ UINT readbytes; int res; - nrf_init(); - - struct NRF_CFG config = { - .channel= 81, - .txmac= "REMOT", - .nrmacs=1, - .mac0= "REMOT", - .maclen ="\x10", - }; - - nrf_config_set(&config); - res=f_open(&file[0], "nick.cfg", FA_OPEN_EXISTING|FA_READ); lcdPrint("open:"); lcdPrintln(f_get_rc_string(res)); @@ -79,7 +67,6 @@ void f_init(void){ char fontname[15]; void f_nick(void){ - static char ctr=0; char key; static signed char x=10; static signed char y=10; @@ -97,6 +84,7 @@ void f_nick(void){ lcdPrint("x"); lcdPrintInt(y); + lcdDisplay(); delayms(40); @@ -117,7 +105,6 @@ void f_nick(void){ lcdClear(); lcdPrintln("Done."); lcdDisplay(); - ctr++; break; }; }; @@ -180,31 +167,19 @@ void msc_menu(void){ /**************************************************************************/ -const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; -const struct MENU_DEF menu_init = {"F Init", &f_init}; -const struct MENU_DEF menu_nick = {"F Nick", &f_nick}; -const struct MENU_DEF menu_font = {"F sel", &f_font}; -const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror}; -const struct MENU_DEF menu_invert = {"Invert", &lcd_invert}; -const struct MENU_DEF menu_volt = {"Akku", &adc_check}; -const struct MENU_DEF menu_msc = {"MSC", &msc_menu}; -const struct MENU_DEF menu_nop = {"---", NULL}; -static menuentry menu[] = { - &menu_init, - &menu_nick, - &menu_font, - &menu_nop, - &menu_mirror, - &menu_invert, - &menu_volt, - &menu_msc, - &menu_nop, - &menu_ISP, - NULL, -}; - -static const struct MENU mainmenu = {"Mainmenu", menu}; +static const struct MENU mainmenu = {"Mainmenu", { + {"Invoke ISP", &gotoISP}, + {"F Init", &f_init}, + {"F Nick", &f_nick}, + {"F sel", &f_font}, + {"Mirror", &lcd_mirror}, + {"Invert", &lcd_invert}, + {"Akku", &adc_check}, + {"MSC", &msc_menu}, + {"---", NULL}, + {NULL,NULL} +}}; void main_font(void) { diff --git a/firmware/applications/fs.c b/firmware/applications/fs.c index 89cf37b..d820c53 100644 --- a/firmware/applications/fs.c +++ b/firmware/applications/fs.c @@ -25,42 +25,25 @@ void fs_mount(void); /**************************************************************************/ -const struct MENU_DEF menu_incBL = {"Backlight++", &incBacklight}; -const struct MENU_DEF menu_decBL = {"Backlight--", &decBacklight}; -const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; -const struct MENU_DEF menu_status = {"FS Status", &fs_status}; -const struct MENU_DEF menu_mount = {"FS Mount", &fs_mount}; -const struct MENU_DEF menu_list = {"FS List", &fs_list}; -const struct MENU_DEF menu_create = {"FS Create", &fs_create}; -const struct MENU_DEF menu_format = {"FS format", &fs_format}; -const struct MENU_DEF menu_read = {"FS read", &fs_read}; +static const struct MENU mainmenu = {"Mainmenu", { + {"FS Mount", &fs_mount}, + {"FS Status", &fs_status}, + {"FS List", &fs_list}, + {"FS Create", &fs_create}, + {"FS read", &fs_read}, + {"FS format", &fs_format}, + {"---", NULL}, #if CFG_USBMSC -const struct MENU_DEF menu_usb = {"USB mount", &usbMSCInit}; -const struct MENU_DEF menu_usboff = {"USB unmount", &usbMSCOff}; + {"USB mount", &usbMSCInit}, + {"USB unmount", &usbMSCOff}, + {"---", NULL}, #endif -const struct MENU_DEF menu_nop = {"---", NULL}; + {"Invoke ISP", &gotoISP}, + {"Backlight++", &incBacklight}, + {"Backlight--", &decBacklight}, + {NULL,NULL} +}}; -static menuentry menu[] = { - &menu_mount, - &menu_status, - &menu_list, - &menu_create, - &menu_read, - &menu_nop, - &menu_format, - &menu_nop, -#if CFG_USBMSC - &menu_usb, - &menu_usboff, -#endif - &menu_nop, - &menu_ISP, - &menu_incBL, - &menu_decBL, - NULL, -}; - -static const struct MENU mainmenu = {"Mainmenu", menu}; void main_fs(void) { diff --git a/firmware/applications/funk.c b/firmware/applications/funk.c deleted file mode 100644 index d592dbe..0000000 --- a/firmware/applications/funk.c +++ /dev/null @@ -1,251 +0,0 @@ -#include - -#include "basic/basic.h" - -#include "lcd/lcd.h" -#include "lcd/print.h" - -#include "funk/nrf24l01p.h" - -#include - -#include "funk/rftransfer.h" -#include "funk/openbeacon.h" - -/**************************************************************************/ - -#define BEACON_CHANNEL 81 -#define BEACON_MAC "\x1\x2\x3\x2\1" - -uint32_t const testkey[4] = { - 0xB4595344,0xD3E119B6,0xA814D0EC,0xEFF5A24E -}; - -int enctoggle=0; - -void f_init(void){ - nrf_init(); - - struct NRF_CFG config = { - .channel= BEACON_CHANNEL, - .txmac= BEACON_MAC, - .nrmacs=1, - .mac0= BEACON_MAC, - .maclen ="\x10", - }; - - nrf_config_set(&config); - lcdPrintln("Done."); -}; - -void f_status(void){ - int dx=0; - int dy=8; - uint8_t buf[4]; - - buf[0]=C_R_REGISTER | R_CONFIG; - buf[1]=0; - buf[2]=0; - buf[3]=0; - dx=DoString(0,dy,"S:"); - dx=DoCharX(dx,dy,buf[0]); - dx=DoCharX(dx,dy,buf[1]); - dx=DoCharX(dx,dy,buf[2]); - dx=DoCharX(dx,dy,buf[3]); - dy+=8; - nrf_cmd_rw_long(buf,2); - dx=DoString(0,dy,"R:"); - dx=DoCharX(dx,dy,buf[0]); - dx=DoCharX(dx,dy,buf[1]); - dx=DoCharX(dx,dy,buf[2]); - dx=DoCharX(dx,dy,buf[3]); - dy+=8; - - int status=nrf_cmd_status(C_NOP); - dx=DoString(0,dy,"St:"); DoCharX(dx,dy,status);dy+=8; -}; - -void f_recv(void){ - __attribute__ ((aligned (4))) uint8_t buf[32]; - int len; - - len=nrf_rcv_pkt_time_encr(1000,sizeof(buf),buf,enctoggle?testkey:NULL); - - if(len==0){ - lcdPrintln("No pkt (Timeout)"); - }; - lcdPrint("Size:");lcdPrintInt(len);lcdNl(); - lcdPrint("1:");lcdPrintIntHex( *(int*)(buf+ 0) ); lcdNl(); - lcdPrint("2:");lcdPrintIntHex( *(int*)(buf+ 4) ); lcdNl(); - lcdPrint("3:");lcdPrintIntHex( *(int*)(buf+ 8) ); lcdNl(); - lcdPrint("4:");lcdPrintIntHex( *(int*)(buf+12) ); lcdNl(); - - len=crc16(buf,14); - lcdPrint("crc:");lcdPrintShortHex(len); lcdNl(); - -}; - -void f_cfg(void){ - struct NRF_CFG config; - - nrfconfig cfg=&config; - - nrf_config_get(cfg); - - lcdPrint("ch:");lcdPrintInt( cfg->channel ); lcdNl(); - lcdPrint("nr:");lcdPrintInt( cfg->nrmacs ); lcdNl(); - - lcdPrint("0:"); - lcdPrintCharHex(cfg->mac0[0]); - lcdPrintCharHex(cfg->mac0[1]); - lcdPrintCharHex(cfg->mac0[2]); - lcdPrintCharHex(cfg->mac0[3]); - lcdPrintCharHex(cfg->mac0[4]); - lcdNl(); - lcdPrint("1:"); - lcdPrintCharHex(cfg->mac1[0]); - lcdPrintCharHex(cfg->mac1[1]); - lcdPrintCharHex(cfg->mac1[2]); - lcdPrintCharHex(cfg->mac1[3]); - lcdPrintCharHex(cfg->mac1[4]); - lcdNl(); - lcdPrint("2345:"); - lcdPrintCharHex(cfg->mac2345[0]); - lcdPrintCharHex(cfg->mac2345[1]); - lcdPrintCharHex(cfg->mac2345[2]); - lcdPrintCharHex(cfg->mac2345[3]); - lcdNl(); - lcdPrint("tx:"); - lcdPrintCharHex(cfg->txmac[0]); - lcdPrintCharHex(cfg->txmac[1]); - lcdPrintCharHex(cfg->txmac[2]); - lcdPrintCharHex(cfg->txmac[3]); - lcdPrintCharHex(cfg->txmac[4]); - lcdNl(); - lcdPrint("len:"); - lcdPrintCharHex(cfg->maclen[0]); - lcdPrintCharHex(cfg->maclen[1]); - lcdPrintCharHex(cfg->maclen[2]); - lcdPrintCharHex(cfg->maclen[3]); - lcdPrintCharHex(cfg->maclen[4]); - lcdNl(); -}; - -void f_cfg_set(void){ - struct NRF_CFG config = { - .channel= 13, - .txmac= "R0KET", - .nrmacs=1, - .mac0= "R0KET", - .maclen ="\x10", - }; - - nrf_config_set(&config); -}; - -void f_enctog(void){ - enctoggle=1-enctoggle; - if(enctoggle) - lcdPrintln("Encrypt ON!"); - else - lcdPrintln("encrypt off!"); - -}; - -void f_send(void){ - uint8_t status; - - status = openbeaconSend(); - lcdPrint("Status:"); - lcdPrintCharHex(status); - lcdNl(); -}; - -void gotoISP(void) { - DoString(0,0,"Enter ISP!"); - lcdDisplay(); - ISPandReset(); -} - -void lcd_mirror(void) { - lcdToggleFlag(LCD_MIRRORX); -}; - -void adc_check(void) { - int dx=0; - int dy=8; - // Print Voltage - dx=DoString(0,dy,"Voltage:"); - while ((getInputRaw())==BTN_NONE){ - DoInt(dx,dy,GetVoltage()); - lcdDisplay(); - }; - dy+=8; - dx=DoString(0,dy,"Done."); -}; - -void f_sendBlock(void) -{ - uint8_t data[] = "hallo welt, das hier ist ein langer string, der" - "per funk verschickt werden soll."; - rftransfer_send(strlen((char *)data), data); -} - -/**************************************************************************/ - -const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; -const struct MENU_DEF menu_init = {"F Init", &f_init}; -const struct MENU_DEF menu_status = {"F Status", &f_status}; -const struct MENU_DEF menu_rcv = {"F Recv", &f_recv}; -const struct MENU_DEF menu_snd = {"F Send", &f_send}; -const struct MENU_DEF menu_cfg = {"F CfgGet", &f_cfg}; -const struct MENU_DEF menu_cfg2 = {"F CfgSet", &f_cfg_set}; -const struct MENU_DEF menu_enc = {"Toggle Encr", &f_enctog}; -const struct MENU_DEF menu_sndblock={"F Send block", &f_sendBlock}; -const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror}; -const struct MENU_DEF menu_volt = {"Akku", &adc_check}; -const struct MENU_DEF menu_nop = {"---", NULL}; - -static menuentry menu[] = { - &menu_init, - &menu_status, - &menu_rcv, - &menu_snd, - &menu_enc, - &menu_cfg2, - &menu_cfg, - &menu_nop, - &menu_mirror, - &menu_volt, - &menu_ISP, - NULL, -}; - -static const struct MENU mainmenu = {"Mainmenu", menu}; - -void main_funk(void) { - backlightInit(); - font=&Font_7x8; - - openbeaconSetup(); - while (1) { - lcdFill(0); // clear display buffer - lcdDisplay(); - handleMenu(&mainmenu); - gotoISP(); - } -}; - -void tick_funk(void){ - static int foo=0; - static int toggle=0; - - if(foo++>50){ - toggle=1-toggle; - foo=0; - gpioSetValue (RB_LED0, toggle); - }; - return; -}; - - diff --git a/firmware/applications/life.c b/firmware/applications/life.c index 7cb5b0e..2802cff 100644 --- a/firmware/applications/life.c +++ b/firmware/applications/life.c @@ -159,6 +159,7 @@ void nextledcycle() { uchar stepmode=0; uchar randdensity=0; +//uint8_t bl=0; void main_life(void) { backlightInit(); @@ -198,9 +199,12 @@ void main_life(void) { stepmode=1; break; } + // bl=(bl+1)%101; + // backlightSetBrightness(bl); draw_area(); // xor life pattern over display content lcdDisplay(); draw_area(); // xor life pattern again to restore original display content + lcdShift(1,-2,1); delayms(10); calc_area(); } diff --git a/firmware/applications/loadable.c b/firmware/applications/loadable.c index 63ec6cb..2457517 100644 --- a/firmware/applications/loadable.c +++ b/firmware/applications/loadable.c @@ -45,26 +45,17 @@ void msc_menu(void){ extern void (*ram)(void); -const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; -const struct MENU_DEF menu_again = {"Run Loadable", &ram}; -const struct MENU_DEF menu_nop = {"---", NULL}; -const struct MENU_DEF menu_msc = {"MSC", &msc_menu}; -const struct MENU_DEF menu_volt = {"Akku", &adc_check}; -const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror}; -const struct MENU_DEF menu_invert = {"Invert", &lcd_invert}; +static const struct MENU mainmenu = {"Mainmenu", { + {"Run Loadable", &ram}, + {"Invoke ISP", &gotoISP}, + {"---", NULL}, + {"MSC", &msc_menu}, + {"Akku", &adc_check}, + {"Mirror", &lcd_mirror}, + {"Invert", &lcd_invert}, + {NULL,NULL} +}}; -static menuentry menu[] = { - &menu_again, - &menu_ISP, - &menu_nop, - &menu_msc, - &menu_mirror, - &menu_invert, - &menu_volt, - NULL, -}; - -static const struct MENU mainmenu = {"Mainmenu", menu}; /**************************************************************************/ diff --git a/firmware/applications/menutest.c b/firmware/applications/menutest.c index 7aa01b1..cc0fb4c 100644 --- a/firmware/applications/menutest.c +++ b/firmware/applications/menutest.c @@ -21,42 +21,25 @@ void gotoISP(void); /**************************************************************************/ +static const struct MENU mainmenu = {"Mainmenu", { + {"Backlight++", &incBacklight}, + {"Backlight--", &decBacklight}, + {"Invoke ISP", &gotoISP}, + {"p1e4", NULL}, + {"p1e5", NULL}, + {"p1e6", NULL}, + {"p1e7", NULL}, + {"p2e1", NULL}, + {"p2e2", NULL}, + {"p2e3", NULL}, + {NULL, NULL}, +}}; -const struct MENU_DEF menu_incBL = {"Backlight++", &incBacklight}; -const struct MENU_DEF menu_decBL = {"Backlight--", &decBacklight}; -const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; -const struct MENU_DEF menu_Ep = {"p1e4", NULL}; -const struct MENU_DEF menu_Eq = {"p1e5", NULL}; -const struct MENU_DEF menu_Er = {"p1e6", NULL}; -const struct MENU_DEF menu_Es = {"p1e7", NULL}; -const struct MENU_DEF menu_Et = {"p2e1", NULL}; -const struct MENU_DEF menu_Eu = {"p2e2", NULL}; -const struct MENU_DEF menu_Ev = {"p2e3", NULL}; - -static menuentry menu[] = { - &menu_incBL, - &menu_decBL, - &menu_ISP, - &menu_Ep, - &menu_Eq, - &menu_Er, - &menu_Es, - &menu_Et, - &menu_Eu, - &menu_Ev, - &menu_Ev, - &menu_ISP, - NULL, -}; - -static const struct MENU mainmenu = {"Mainmenu", menu}; void main_menutest(void) { backlightInit(); - font_direction = FONT_DIR_LTR; // LeftToRight is the default - while (1) { lcdDisplay(); delayms(10); diff --git a/firmware/applications/mesh/config.c b/firmware/applications/mesh/config.c index 4343198..94a20f9 100644 --- a/firmware/applications/mesh/config.c +++ b/firmware/applications/mesh/config.c @@ -1,6 +1,7 @@ #include #include "basic/basic.h" +#include "basic/config.h" #include "lcd/print.h" #include "lcd/display.h" diff --git a/firmware/applications/mesh/util.c b/firmware/applications/mesh/util.c index 721cacd..a208a13 100644 --- a/firmware/applications/mesh/util.c +++ b/firmware/applications/mesh/util.c @@ -1,6 +1,7 @@ #include #include "basic/basic.h" +#include "basic/config.h" #include "lcd/lcd.h" #include "lcd/print.h" @@ -29,6 +30,18 @@ void show_ticks(void) { }; +void chrg_stat(void) { + int stat; + while ((getInputRaw())==BTN_NONE){ + lcdClear(); + lcdPrintln("Chrg_stat:"); + stat=gpioGetValue(RB_PWR_CHRG); + lcdPrint(IntToStr(stat,3,0)); + lcdNl(); + lcdRefresh(); + }; + lcdPrintln("Done."); +}; void adc_light(void) { int dx=0; int dy=8; @@ -37,7 +50,7 @@ void adc_light(void) { while ((getInputRaw())==BTN_NONE){ DoInt(dx,dy,GetLight()); DoInt(dx,dy+16,isNight()); - DoInt(dx,dy+8,GLOBAL(nighttrigger)); + DoInt(dx,dy+8,GLOBAL(daytrig)); lcdDisplay(); }; dy+=8; diff --git a/firmware/applications/mkfirmware.pl b/firmware/applications/mkfirmware.pl new file mode 100755 index 0000000..2c465b6 --- /dev/null +++ b/firmware/applications/mkfirmware.pl @@ -0,0 +1,123 @@ +#!/usr/bin/perl +# +# vim:set ts=4 sw=4: + +use strict; + +my $debug=0; +if($ARGV[0] eq "-d"){ + $debug=1; + shift; +}; + +my $app=shift; +my @files=@ARGV; +my %menu; +my (@ticks,@inits); + +$\="\n"; + +print "// Function definitions:"; +my $menudef; +for my $file (@files){ + open(F,"<",$file) || die "Can't open $file: $!"; + while(){ + chomp; + s/\r$//; # Dos line-end + + if(m!^\s*//#\s+(.*?)\s*$!){ # Menu definition + $menudef=$1; + next; + }; + next if(/^\s*$/); + next if(m!^\s*//!); + if(m!^\s*void\s+([^(]+)\(!){ # A suitable function + my $func=$1; + if($func=~/tick_/){ + push @ticks,$func; + print "void $func(void);"; + }; + if($func=~/init_/){ + push @inits,$func; + print "void $func(void);"; + }; + if($debug){ + my $f="debug"; + $file =~ m!([^/.]+)\.! && do {$f=$1}; + $menudef="MENU $f $func"; + }; + if(defined $menudef){ + my @words=split(/\s+/,$menudef); + if($words[0] ne "MENU"){ + warn "Not a menu definition?"; + }; + + if($#words==1){ + $menu{$words[1]}=$func; + }elsif($#words==2){ + $menu{$words[1]}{$words[2]}=$func; + }else{ + warn "Couldn't handle $menudef"; + }; + print "void $func(void);"; + }; + $menudef=undef; + }; + }; +}; + +print ""; +print "// Submenus:"; + +#use Data::Dumper; print Dumper \%menu; + +for (sort keys %menu){ + if(ref $menu{$_} eq "HASH"){ + printf "static const struct MENU submenu_${_}={"; + print qq! "$_", {!; + for my $entry(sort keys %{$menu{$_}}){ + print qq!\t{ "$entry", &$menu{$_}{$entry}},!; + }; + print qq!\t{NULL,NULL}!; + print "}};"; + }; +}; + +print ""; + +for (sort keys %menu){ + if(ref $menu{$_} eq "HASH"){ + print qq!void run_submenu_$_(void) {!; + print qq!\thandleMenu(&submenu_$_);!; + print qq!};!; + }; +}; + +print ""; +print "// Main menu:"; +printf "static const struct MENU mainmenu={"; +print qq! "Menu:", {!; +for (sort keys %menu){ + if(ref $menu{$_} eq "HASH"){ + print qq!\t{ "$_", &run_submenu_$_},!; + }else{ + print qq!\t{ "$_", &$menu{$_}},!; + }; +}; +print qq!\t\t{NULL,NULL}!; +print "}};"; + +print ""; +print "// Tick & init functions:"; +print qq!void tick_$app(void) {!; +for (sort @ticks){ + print qq!\t$_();!; +}; +print qq!};!; + +print qq!void init_$app(void) {!; +for (sort @inits){ + print qq!\t$_();!; +}; +print qq!};!; + diff --git a/firmware/applications/mktester b/firmware/applications/mktester deleted file mode 100755 index 661351d..0000000 --- a/firmware/applications/mktester +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/sh - -for f in $* ; do - grep -h '^void ' $f|sed 's/^void //;s/(.*//'|while read a ; do - echo "void $a(void);" - done -done - -for f in $* ; do - grep -h '^void ' $f|sed 's/^void //;s/(.*//'|while read a ; do - echo "const struct MENU_DEF menu_$a = {\"$a\", &$a};" - done -done - -echo "const struct MENU_DEF menu_nop = {\"---\", NULL};" -echo - -for f in $* ; do - t=${f#*/} - t=${t%.c} - echo "static menuentry mentry_$t[] = {" - grep -h '^void ' $f|sed 's/^void //;s/(.*//'|while read a ; do - echo "&menu_$a," - done - echo "NULL" - echo "};" -done - -for f in $* ; do - t=${f#*/} - t=${t%.c} - echo "static const struct MENU m_$t = {\"$t\", mentry_$t};" -done - - -for f in $* ; do - t=${f#*/} - t=${t%.c} - echo "void run_$t(void) {" - echo "handleMenu(&m_$t);" - echo "};" -done - -for f in $* ; do - t=${f#*/} - t=${t%.c} - echo "const struct MENU_DEF menu_$t = {\"$t\", &run_$t};" -done - -echo "static menuentry mentry[] = {" - -for f in $* ; do - t=${f#*/} - t=${t%.c} - echo "&menu_$t," -done - -echo "NULL" -echo "};" - -echo "inline void generated_tick(void){" -for f in $* ; do - grep -h '^void tick_' $f|sed 's/^void //;s/(.*//'|while read a ; do - echo "$a();" - done -done -echo "return;" -echo "};" - - diff --git a/firmware/applications/remote.c b/firmware/applications/remote.c deleted file mode 100644 index 4effc17..0000000 --- a/firmware/applications/remote.c +++ /dev/null @@ -1,197 +0,0 @@ -#include - -#include "basic/basic.h" - -#include "lcd/lcd.h" -#include "lcd/print.h" - -#include "funk/nrf24l01p.h" -#include "usb/usbmsc.h" - -#include - -/**************************************************************************/ - -uint32_t const testkey[4] = { - 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff -}; - -void f_init(void){ - nrf_init(); - - struct NRF_CFG config = { - .channel= 81, - .txmac= "REMOT", - .nrmacs=1, - .mac0= "REMOT", - .maclen ="\x10", - }; - - nrf_config_set(&config); - - lcdPrintln("Done."); -}; - -void f_recv(void){ - __attribute__ ((aligned (4))) uint8_t buf[32]; - int len; - - while(1){ - len=nrf_rcv_pkt_time_encr(1000,sizeof(buf),buf,testkey); - - if(len==0){ - lcdPrintln("No pkt (Timeout)"); - return; - }; - - lcdClear(); - lcdPrint("Size:");lcdPrintInt(len);lcdNl(); - - lcdPrintCharHex(buf[0]); - lcdPrint(" "); - lcdPrintCharHex(buf[1]); - lcdPrint(" "); - lcdPrintCharHex(buf[2]); - lcdPrint(" "); - lcdPrintCharHex(buf[3]); - lcdNl(); - - lcdPrint("ct:");lcdPrintIntHex( *(int*)(buf+ 4) ); lcdNl(); - lcdPrint("id:");lcdPrintIntHex( *(int*)(buf+ 8) ); lcdNl(); - lcdPrint("xx:");lcdPrintIntHex( *(int*)(buf+12) ); lcdNl(); - lcdDisplay(); - }; -}; - - -void f_send(void){ - int ctr=1; - __attribute__ ((aligned (4))) uint8_t buf[32]; - int len; - int status; - - while(1){ - - buf[0]=0x10; // Length: 16 bytes - buf[1]='C'; // Proto - buf[2]=getInputRaw(); - buf[3]=0x00; // Unused - - ctr++; - *(int*)(buf+4)=ctr; - - /* - buf[4]=0x00; // ctr - buf[5]=0x00; // ctr - buf[6]=0x00; // ctr - buf[7]=ctr++; // ctr - */ - - buf[8]=0x0; // Object id - buf[9]=0x0; - buf[10]=0x05; - buf[11]=0xec; - - buf[12]=0xff; // salt (0xffff always?) - buf[13]=0xff; - - status=nrf_snd_pkt_crc_encr(16,buf,testkey); - lcdClear(); - lcdPrint("Key:"); lcdPrintInt(buf[2]); lcdNl(); - lcdPrint("F-St:"); lcdPrintInt(status); - if(buf[2]==BTN_ENTER) - break; - lcdDisplay(); - len=nrf_rcv_pkt_time_encr(10,sizeof(buf),buf,testkey); - if(len>0){ - lcdPrint("Got!"); - }; - }; - - -}; - -void gotoISP(void) { - DoString(0,0,"Enter ISP!"); - lcdDisplay(); - ISPandReset(); -} - -void lcd_mirror(void) { - lcdToggleFlag(LCD_MIRRORX); -}; - -void adc_check(void) { - int dx=0; - int dy=8; - // Print Voltage - dx=DoString(0,dy,"Voltage:"); - while ((getInputRaw())==BTN_NONE){ - DoInt(dx,dy,GetVoltage()); - lcdDisplay(); - }; - dy+=8; - dx=DoString(0,dy,"Done."); -}; - -void msc_menu(void){ - DoString(0,8,"MSC Enabled."); - lcdDisplay(); - usbMSCInit(); - while(!getInputRaw())delayms(10); - DoString(0,16,"MSC Disabled."); - usbMSCOff(); -}; - -/**************************************************************************/ - -const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; -const struct MENU_DEF menu_init = {"F Init", &f_init}; -const struct MENU_DEF menu_rcv = {"F Recv", &f_recv}; -const struct MENU_DEF menu_snd = {"F Send", &f_send}; -//const struct MENU_DEF menu_cfg = {"F Cfg", &f_cfg}; -const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror}; -const struct MENU_DEF menu_volt = {"Akku", &adc_check}; -const struct MENU_DEF menu_msc = {"MSC", &msc_menu}; -const struct MENU_DEF menu_nop = {"---", NULL}; - -static menuentry menu[] = { - &menu_init, - &menu_rcv, - &menu_snd, -// &menu_cfg, - &menu_nop, - &menu_mirror, - &menu_volt, - &menu_msc, - &menu_nop, - &menu_ISP, - NULL, -}; - -static const struct MENU mainmenu = {"Mainmenu", menu}; - -void main_remote(void) { - - font=&Font_7x8; - - while (1) { - lcdFill(0); // clear display buffer - lcdDisplay(); - handleMenu(&mainmenu); - gotoISP(); - } -}; - -void tick_remote(void){ - static int foo=0; - static int toggle=0; - if(foo++>80){ - toggle=1-toggle; - foo=0; - gpioSetValue (RB_LED0, toggle); - }; - return; -}; - - diff --git a/firmware/applications/spaceinvaders.c b/firmware/applications/spaceinvaders.c deleted file mode 100644 index c774fd4..0000000 --- a/firmware/applications/spaceinvaders.c +++ /dev/null @@ -1,229 +0,0 @@ -#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 - -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 init_enemy() { - for (int row = 0; row= game.shot_y && game.enemy_row_y[row]+6 < game.shot_y+7) { - for(int col = 0; col= game.enemy_x[row][col] && game.shot_x < game.enemy_x[row][col]+8) { - game.enemy_x[row][col]=DISABLED; - game.shot_x = DISABLED; - game.alive--; - return; - } - } - } - } - - game.shot_y -= 3; -} - -void move_player() { - if(gpioGetValue(RB_BTN0)==0 && game.player > 0 ){ - game.player-=1; - } - - if(gpioGetValue(RB_BTN1)==0 && game.player < RESX-8){ - game.player+=1; - } - - if(gpioGetValue(RB_BTN4)==0 && game.shot_x == 255){ - game.shot_x = game.player+4; - game.shot_y = POS_PLAYER_Y; - } -} - -void move_enemy() { - if(game.move > 0){ - game.move--; - return; - } - - for (int col = 0; col < ENEMY_COLUMNS; col++) { - for (int row = 0; row < ENEMY_ROWS; row++) { - char pos = game.enemy_x[row][(game.direction==1)?(ENEMY_COLUMNS-(col+1)):col]; - if (pos != DISABLED) { - //Check collision with player - if(game.enemy_row_y[row]+8 >= POS_PLAYER_Y && pos+8 >= game.player && pos < game.player+8){ - game.killed = true; - } - - if((pos <=0 && game.direction != 1) || - (pos >=RESX-8-1 && game.direction == 1)){ - game.direction = (game.direction==1)?-1:1; - for (char r = 0; r=RESX-8 && game.direction == 1)){ - game.direction *= -1; - //TODOmove down - return; - } - game.enemy_x[row][col] += game.direction; - next = true; - } - } - if (next){ - game.lastcol += game.direction; - return; - } - } - game.move = game.alive; - return; - } - game.move--; -} -void draw_player() { - //draw_sprite(50, 20); - draw_sprite(game.player, POS_PLAYER_Y); -} - -void draw_enemy() { - for (int row = 0; row #include "basic/basic.h" +#include "basic/config.h" #include "lcd/lcd.h" #include "lcd/print.h" @@ -29,6 +30,18 @@ void show_ticks(void) { }; +void chrg_stat(void) { + int stat; + while ((getInputRaw())==BTN_NONE){ + lcdClear(); + lcdPrintln("Chrg_stat:"); + stat=gpioGetValue(RB_PWR_CHRG); + lcdPrint(IntToStr(stat,3,0)); + lcdNl(); + lcdRefresh(); + }; + lcdPrintln("Done."); +}; void adc_light(void) { int dx=0; int dy=8; @@ -37,7 +50,7 @@ void adc_light(void) { while ((getInputRaw())==BTN_NONE){ DoInt(dx,dy,GetLight()); DoInt(dx,dy+16,isNight()); - DoInt(dx,dy+8,GLOBAL(nighttrigger)); + DoInt(dx,dy+8,GLOBAL(daytrig)); lcdDisplay(); }; dy+=8; diff --git a/firmware/basic/basic.c b/firmware/basic/basic.c index 819de91..749547b 100644 --- a/firmware/basic/basic.c +++ b/firmware/basic/basic.c @@ -34,6 +34,9 @@ void rbInit() { gpioSetDir(RB_BTN4, gpioDirection_Input); gpioSetPullup (&RB_BTN4_IO, gpioPullupMode_PullUp); + // prepate chrg_stat + gpioSetDir(RB_PWR_CHRG, gpioDirection_Input); + gpioSetPullup (&RB_PWR_CHRG_IO, gpioPullupMode_PullUp); // prepare LEDs IOCON_JTAG_TDI_PIO0_11 &= ~IOCON_JTAG_TDI_PIO0_11_FUNC_MASK; diff --git a/firmware/basic/basic.h b/firmware/basic/basic.h index 41ed5c7..df3f2c9 100644 --- a/firmware/basic/basic.h +++ b/firmware/basic/basic.h @@ -81,6 +81,7 @@ #define RB_PWR_GOOD 1,8 #define RB_PWR_CHRG 2,3 +#define RB_PWR_CHRG_IO IOCON_PIO2_3 #define RB_PWR_LCDBL 0,0 #define RB_PWR_LCDBL_IO IOCON_nRESET_PIO0_0 @@ -171,11 +172,9 @@ struct MENU_DEF { void (*callback)(void); }; -typedef const struct MENU_DEF * menuentry; - struct MENU { char *title; - menuentry *entries; + struct MENU_DEF entries[]; }; @@ -185,36 +184,6 @@ void handleMenu(const struct MENU *the_menu); #include "basic/idle.h" -// config.c - -int readConfig(void); -int saveConfig(void); -void applyConfig(void); - - -struct CDESC { - char *name; - char value; - char min; - char max; -}; - -extern struct CDESC the_config[]; - -#define GLOBALversion (the_config[0].value) -#define GLOBALprivacy (the_config[1].value) -#define GLOBALnighttrigger (the_config[2].value) -#define GLOBALnightinvert (the_config[3].value) -#define GLOBALlcdbacklight (the_config[4].value) -#define GLOBALlcdmirror (the_config[5].value) -#define GLOBALlcdinvert (the_config[6].value) -#define GLOBALlcdcontrast (the_config[7].value) - -#define GLOBAL(x) GLOBAL ## x - - -#define SYSTICKSPEED 10 - // itoa.c #define F_ZEROS (1<<0) #define F_LONG (1<<1) @@ -227,4 +196,8 @@ const char* IntToStr(int num, unsigned int mxlen, char flag); #include "basic/simpletime.h" +// global +#define SYSTICKSPEED 10 + + #endif diff --git a/firmware/basic/config.c b/firmware/basic/config.c index 8933203..84f6d5a 100644 --- a/firmware/basic/config.c +++ b/firmware/basic/config.c @@ -1,32 +1,46 @@ #include #include "basic/basic.h" +#include "lcd/display.h" #include "lcd/print.h" #include "filesystem/ff.h" #include "basic/random.h" +#include "basic/config.h" -#define CFGVER 23 +#define CFGVER 1 struct CDESC the_config[]= { {"version", CFGVER, CFGVER, CFGVER}, + // dflt min max {"privacy", 3, 0, 2 }, - {"nighttrigger", 310/2, 0, 255}, - {"nightinvert", 1, 0, 1 }, + {"daytrig", 310/2, 0, 255}, + {"daytrighyst", 10, 0, 50 }, + {"dayinvert", 1, 0, 1 }, {"lcdbacklight", 50, 0, 100}, {"lcdmirror", 0, 0, 1 }, {"lcdinvert", 0, 0, 1 }, - {"lcdcontrast", 3, 0, 31 }, + {"lcdcontrast", 14, 0, 31 }, + {"alivechk", 0, 0, 2 }, + {"flamemax", 255, 0, 255}, + {"flamemin", 0, 0, 255}, + {"flamespeed", 1, 1, 100}, + {"flamemaxw", 255, 1, 255}, + {"flameminw", 0x8f, 1, 255}, { NULL, 0, 0, 0 }, }; +char nickname[MAXNICK]="anonymous"; +char nickfont[FILENAMELEN]; + #define CONFFILE "r0ket.cfg" #define CONF_ITER for(int i=0;the_config[i].name!=NULL;i++) /**************************************************************************/ void applyConfig(){ - lcdSetContrast(GLOBAL(lcdcontrast)); - return 0; + if(GLOBAL(lcdcontrast)>0) + lcdSetContrast(GLOBAL(lcdcontrast)); + return; }; int saveConfig(void){ diff --git a/firmware/basic/config.h b/firmware/basic/config.h new file mode 100644 index 0000000..bcd4f98 --- /dev/null +++ b/firmware/basic/config.h @@ -0,0 +1,41 @@ +#ifndef __BASICCONFIG_H_ +#define __BASICCONFIG_H_ + +int readConfig(void); +int saveConfig(void); +void applyConfig(void); + + +struct CDESC { + char *name; + char value; + char min; + char max; +}; + +#define MAXNICK 20 +extern struct CDESC the_config[]; +extern char nickname[MAXNICK]; +extern char nickfont[]; + +#define GLOBALversion (the_config[ 0].value) +#define GLOBALprivacy (the_config[ 1].value) +#define GLOBALdaytrig (the_config[ 2].value) +#define GLOBALdaytrighyst (the_config[ 3].value) +#define GLOBALdayinvert (the_config[ 4].value) +#define GLOBALlcdbacklight (the_config[ 5].value) +#define GLOBALlcdmirror (the_config[ 6].value) +#define GLOBALlcdinvert (the_config[ 7].value) +#define GLOBALlcdcontrast (the_config[ 8].value) +#define GLOBALalivechk (the_config[ 9].value) +#define GLOBALflamemax (the_config[10].value) +#define GLOBALflamemin (the_config[11].value) +#define GLOBALflamespeed (the_config[12].value) +#define GLOBALflamemaxw (the_config[13].value) +#define GLOBALflameminw (the_config[14].value) +#define GLOBALnickname (nickname) +#define GLOBALnickfont (nickfont) + +#define GLOBAL(x) GLOBAL ## x + +#endif diff --git a/firmware/basic/menu.c b/firmware/basic/menu.c index 4758d65..253bb55 100644 --- a/firmware/basic/menu.c +++ b/firmware/basic/menu.c @@ -2,8 +2,6 @@ #include "basic/basic.h" -#include "lcd/fonts.h" -#include "lcd/render.h" #include "lcd/print.h" /**************************************************************************/ @@ -17,31 +15,28 @@ void handleMenu(const struct MENU *the_menu) { if (the_menu == NULL) return; -// font = &Font_7x8; // Font needs to be set externally? + setSystemFont(); - for (numentries = 0; the_menu->entries[numentries] != NULL; numentries++); + for (numentries = 0; the_menu->entries[numentries].text != NULL ; numentries++); - visible_lines = (RESY/font->u8Height)-1; // subtract title line + visible_lines = lcdGetVisibleLines()-1; // subtract title line #ifdef SAFETY if (visible_lines < 2) return; #endif while (!back) { - uint8_t line = 0; - // Display current menu page - lcdFill(0); - DoString(0, line, the_menu->title); - line += font->u8Height; + lcdClear(); + lcdPrintln(the_menu->title); for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++) { - DoString(14, line, the_menu->entries[i]->text); if (i == menuselection) { - DoString(0, line, "* "); + lcdPrint("*"); } - line += font->u8Height; + lcdSetCrsrX(14); + lcdPrintln(the_menu->entries[i].text); } - lcdDisplay(); + lcdRefresh(); switch (getInputWait()) { case BTN_UP: @@ -69,17 +64,17 @@ void handleMenu(const struct MENU *the_menu) { case BTN_LEFT: return; case BTN_RIGHT: - if (the_menu->entries[menuselection]->callback!=NULL) - the_menu->entries[menuselection]->callback(); + if (the_menu->entries[menuselection].callback!=NULL) + the_menu->entries[menuselection].callback(); break; case BTN_ENTER: lcdClear(); lcdPrintln("Called..."); lcdRefresh(); getInputWaitRelease(); - if (the_menu->entries[menuselection]->callback!=NULL) - the_menu->entries[menuselection]->callback(); - lcdDisplay(); + if (the_menu->entries[menuselection].callback!=NULL) + the_menu->entries[menuselection].callback(); + lcdRefresh(); getInputWait(); break; diff --git a/firmware/basic/night.c b/firmware/basic/night.c index ae62db1..5efe7c4 100644 --- a/firmware/basic/night.c +++ b/firmware/basic/night.c @@ -1,45 +1,40 @@ #include #include "basic/basic.h" +#include "basic/config.h" -#define RANGE (10) -#define HYST (4) -uint32_t light=300*HYST; +#define SAMPCT (4) +uint32_t light=150*SAMPCT; char _isnight=1; -#define threshold GLOBAL(nighttrigger) +#define threshold GLOBAL(daytrig) +#define RANGE GLOBAL(daytrighyst) void LightCheck(void){ int iocon; char iodir; - int value; - iocon=IOCON_PIO1_11; // iodir=gpioGetDir(RB_LED3); iodir= (GPIO_GPIO1DIR & (1 << (RB_LED3) ))?1:0; gpioSetDir(RB_LED3, gpioDirection_Input); IOCON_PIO1_11 = IOCON_PIO1_11_FUNC_AD7|IOCON_PIO1_11_ADMODE_ANALOG; - light-=light/HYST; + light-=light/SAMPCT; light += (adcRead(7)/2); gpioSetDir(RB_LED3, iodir); IOCON_PIO1_11=iocon; - if(threshold==0){ // uninitialized? - threshold=320; - }; - - if(_isnight && light/HYST>(threshold+RANGE)) + if(_isnight && light/SAMPCT>(threshold+RANGE)) _isnight=0; - if(!_isnight && light/HYST #include "random.h" #include "xxtea.h" +#include "core/adc/adc.h" #define STATE_SIZE 8 uint32_t state[STATE_SIZE]; diff --git a/firmware/basic/voltage.c b/firmware/basic/voltage.c index 1ed2d69..624cbf8 100644 --- a/firmware/basic/voltage.c +++ b/firmware/basic/voltage.c @@ -11,6 +11,7 @@ void VoltageCheck(void){ results /= 1024; if( results < 3500 ){ + nrf_off(); gpioSetValue (RB_PWR_GOOD, 0); gpioSetValue (RB_LCD_BL, 0); SCB_SCR |= SCB_SCR_SLEEPDEEP; diff --git a/firmware/filesystem/at45db041d.c b/firmware/filesystem/at45db041d.c index 0c6fe37..99b1ff9 100644 --- a/firmware/filesystem/at45db041d.c +++ b/firmware/filesystem/at45db041d.c @@ -236,9 +236,13 @@ DRESULT dataflash_ioctl(BYTE ctrl, void *buff) { } #endif /* _USE_IOCTL != 0 */ - - DWORD get_fattime () { - // ToDo! - return 0; + struct tm* tm=mygmtime(getSeconds()); + DWORD t= (((tm->tm_year+YEAR0-1980)<<9)| + ((tm->tm_mon+1)<<5)| + (tm->tm_mday))<<16 | + ((tm->tm_hour<<11)| + (tm->tm_min<<5)| + (tm->tm_sec>>1)); + return t; } diff --git a/firmware/filesystem/ff.h b/firmware/filesystem/ff.h index 07eb8ad..611a703 100644 --- a/firmware/filesystem/ff.h +++ b/firmware/filesystem/ff.h @@ -329,8 +329,11 @@ int ff_del_syncobj (_SYNC_t); /* Delete a sync object */ #endif /* Utility functions */ +#define FILENAMELEN 13 // 8+1+3+1 const char* f_get_rc_string (FRESULT rc); void fsInit(); +int readFile(char * filename, char * data, int len); +int writeFile(char * filename, char * data, int len); #ifdef __cplusplus } diff --git a/firmware/filesystem/select.c b/firmware/filesystem/select.c index 74b4773..6ca3c47 100644 --- a/firmware/filesystem/select.c +++ b/firmware/filesystem/select.c @@ -13,29 +13,30 @@ int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, char *ext) DIR dir; /* Directory object */ FILINFO Finfo; FRESULT res; - int ctr; int pos = 0; + int extlen = strlen(ext); res = f_opendir(&dir, "0:"); if(res){ //lcdPrint("OpenDir:"); lcdPrintln(f_get_rc_string(res)); lcdRefresh(); return 0; }; - ctr=0; - while(1){ - res = f_readdir(&dir, &Finfo); - if ((res != FR_OK) || !Finfo.fname[0]) - break; - + while(f_readdir(&dir, &Finfo) == FR_OK && Finfo.fname[0]){ int len=strlen(Finfo.fname); - int extlen = strlen(ext); + + if(len0 ){ + skip--; continue; + }; + strcpy(files[pos++],Finfo.fname); if( pos == count ) break; @@ -43,6 +44,7 @@ int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, char *ext) return pos; } +#define PERPAGE 7 int selectFile(char *filename, char *extension) { int skip = 0; @@ -50,12 +52,23 @@ int selectFile(char *filename, char *extension) int selected = 0; font=&Font_7x8; while(1){ - char files[7][FLEN]; - int count = getFiles(files, 7, skip, extension); + char files[PERPAGE][FLEN]; + int count = getFiles(files, PERPAGE, skip, extension); + if(!count){ + lcdPrintln("No Files?"); + lcdRefresh(); + getInputWait(); + getInputWaitRelease(); + return -1; + }; + + if(count 0 ){ - selected--; - goto redraw; - }else{ - if( skip > 0 ){ - skip--; + switch(key){ + case BTN_DOWN: + if( selected < count-1 ){ + selected++; + goto redraw; + }else{ + skip++; } - } - }else if( key==BTN_LEFT ){ - return 1; - }else if( key==BTN_RIGHT ){ - strcpy(filename, files[selected]); - return 0; + break; + case BTN_UP: + if( selected > 0 ){ + selected--; + goto redraw; + }else{ + if( skip > 0 ){ + skip--; + } + } + break; + case BTN_LEFT: + return -1; + case BTN_ENTER: + case BTN_RIGHT: + strcpy(filename, files[selected]); + return 0; } } } diff --git a/firmware/filesystem/util.c b/firmware/filesystem/util.c index 7e635ad..2965656 100644 --- a/firmware/filesystem/util.c +++ b/firmware/filesystem/util.c @@ -1,3 +1,4 @@ +#include #include FATFS FatFs; /* File system object for logical drive */ @@ -22,3 +23,49 @@ const char* f_get_rc_string (FRESULT rc) { void fsInit(){ f_mount(0, &FatFs); }; + +void fsReInit(){ + f_mount(0, NULL); + f_mount(0, &FatFs); +}; + +int readFile(char * filename, char * data, int len){ + FIL file; + UINT readbytes; + int res; + + res=f_open(&file, filename, FA_OPEN_EXISTING|FA_READ); + if(res){ + return -1; + }; + + res = f_read(&file, data, len-1, &readbytes); + if(res){ + return -1; + }; + + f_close(&file); + + data[readbytes]=0; + return readbytes; +}; + +int writeFile(char * filename, char * data, int len){ + FIL file; + UINT writebytes; + int res; + + res=f_open(&file, filename, FA_OPEN_ALWAYS|FA_WRITE); + if(res){ + return -1; + }; + + res = f_write(&file, data, len, &writebytes); + if(res){ + return -1; + }; + f_close(&file); + + return writebytes; +}; + diff --git a/firmware/funk/filetransfer.c b/firmware/funk/filetransfer.c index ffa4b94..375d4cd 100644 --- a/firmware/funk/filetransfer.c +++ b/firmware/funk/filetransfer.c @@ -108,7 +108,7 @@ int filetransfer_receive(uint8_t *mac, uint32_t const k[4]) } lcdRefresh(); if( fres < 0 ) - return; + return 1; //nrf_set_rx_mac(0, 32, 5, macbuf); xxtea_decode_words((uint32_t *)buf, wordcount, k); diff --git a/firmware/funk/mesh.c b/firmware/funk/mesh.c index 4928cae..8e001e6 100644 --- a/firmware/funk/mesh.c +++ b/firmware/funk/mesh.c @@ -25,8 +25,26 @@ void initMesh(void){ meshbuffer[0].flags=MF_USED; }; -inline void blink(char a, char b){ - gpioSetValue (a,b, 1-gpioGetValue(a,b)); +MPKT * meshGetMessage(uint8_t type){ + int free=-1; + for(int i=0;iSECS_DAY) - meshbuffer[i].flags=MF_FREE; + if (MO_TYPE(meshbuffer[i].pkt)>='a' && + MO_TYPE(meshbuffer[i].pkt)<='z'){ + ; + }else{ + if (MO_TIME(meshbuffer[i].pkt)SECS_DAY) + meshbuffer[i].flags=MF_FREE; + }; }; }; }; @@ -76,44 +99,29 @@ void mesh_recvloop(void){ }; if(MO_TYPE(buf)=='T'){ - time_t toff=MO_TIME(buf)-((getTimer()-(200/SYSTICKSPEED))/(1000/SYSTICKSPEED)); + time_t toff=MO_TIME(buf)-((getTimer()+(300/SYSTICKSPEED))/(1000/SYSTICKSPEED)); if (toff>_timet) // Do not live in the past. _timet = toff; continue; }; // Safety: Truncate ascii packets by 0-ing the CRC - if (MO_TYPE(buf) >='A' && MO_TYPE(buf) <='Z'){ - buf[MESHPKTSIZE-2]=0; - }; + buf[MESHPKTSIZE-2]=0; - // Store packet in a free slot - int free=-1; - for(int i=0;i - MO_TIME(meshbuffer[i].pkt)){ - free=i; - break; - }else{ - free=-2; - break; - }; - }; - }; + // Store packet in a same/free slot + MPKT* mpkt=meshGetMessage(MO_TYPE(buf)); - if(free==-1){ // Buffer full. Ah well. Kill a random packet - free=1; // XXX: GetRandom()? - }; - - if(free<0) + // Skip locked packet + if(mpkt->flags&MF_LOCK) continue; - memcpy(meshbuffer[free].pkt,buf,MESHPKTSIZE); - meshbuffer[free].flags=MF_USED; + // only accept newer/better packets + if(mpkt->flags==MF_USED) + if(MO_TIME(buf)pkt)) + continue; + + memcpy(mpkt->pkt,buf,MESHPKTSIZE); + mpkt->flags=MF_USED; }while(getTimer()MESHBUFSIZE); @@ -137,6 +145,8 @@ void mesh_sendloop(void){ for (int i=0;i +#include #include #include diff --git a/firmware/lcd/display.c b/firmware/lcd/display.c index e8da386..5922e8e 100644 --- a/firmware/lcd/display.c +++ b/firmware/lcd/display.c @@ -6,6 +6,7 @@ #include "core/ssp/ssp.h" #include "gpio/gpio.h" #include "basic/basic.h" +#include "basic/config.h" #include "usb/usbmsc.h" /**************************************************************************/ diff --git a/firmware/lcd/display.h b/firmware/lcd/display.h index d1bcd64..14927d8 100644 --- a/firmware/lcd/display.h +++ b/firmware/lcd/display.h @@ -31,4 +31,5 @@ void lcdSafeSetPixel(char x, char y, bool f); bool lcdGetPixel(char x, char y); void lcdShift(int x, int y, bool wrap); void lcdSetContrast(int c); +void lcdSetInvert(); #endif diff --git a/firmware/lcd/fonts/invaders.c b/firmware/lcd/fonts/invaders.c index 25395b3..687f8a8 100644 --- a/firmware/lcd/fonts/invaders.c +++ b/firmware/lcd/fonts/invaders.c @@ -38,19 +38,18 @@ const uint8_t InvadersBitmaps[] = { 0x9c, /* * *** */ - /* Char 67 is 9px wide @ 23 */ + /* Char 67 is 8px wide @ 23 */ 0x58, /* * ** */ 0xbc, /* * **** */ 0x16, /* * ** */ 0x3f, /* ****** */ 0x3f, /* ****** */ - 0x36, /* ** ** */ - 0x1c, /* *** */ - 0xb8, /* * *** */ - 0x40, /* * */ + 0x16, /* * ** */ + 0xbc, /* * **** */ + 0x58, /* * ** */ - /* Char 80 is 7px wide @ 32 */ + /* Char 80 is 7px wide @ 31 */ 0xc0, /* ** */ 0xec, /* *** ** */ 0x7e, /* ****** */ @@ -60,7 +59,7 @@ const uint8_t InvadersBitmaps[] = { 0xc0, /* ** */ - /* Char 85 is 16px wide @ 39 */ + /* Char 85 is 16px wide @ 38 */ 0x20, /* * */ 0x30, /* ** */ 0x78, /* **** */ @@ -79,7 +78,7 @@ const uint8_t InvadersBitmaps[] = { 0x20, /* * */ - /* Char 97 is 11px wide @ 55 */ + /* Char 97 is 11px wide @ 54 */ 0x9e, /* * **** */ 0x38, /* *** */ 0x7d, /* ***** * */ @@ -93,7 +92,7 @@ const uint8_t InvadersBitmaps[] = { 0x9e, /* * **** */ - /* Char 98 is 12px wide @ 66 */ + /* Char 98 is 12px wide @ 65 */ 0x1c, /* *** */ 0x5e, /* * **** */ 0xfe, /* ******* */ @@ -108,7 +107,7 @@ const uint8_t InvadersBitmaps[] = { 0x1c, /* *** */ - /* Char 99 is 8px wide @ 78 */ + /* Char 99 is 8px wide @ 77 */ 0x98, /* * ** */ 0x5c, /* * *** */ 0xb6, /* * ** ** */ @@ -125,7 +124,7 @@ const uint8_t InvadersBitmaps[] = { const FONT_CHAR_INFO InvadersLengths[] = { {11}, /* A */ {12}, /* B */ - { 9}, /* C */ + { 8}, /* C */ { 7}, /* P */ {16}, /* U */ {11}, /* a */ @@ -150,5 +149,5 @@ const struct FONT_DEF Font_Invaders = { * Name: Invaders * Height: 8 px (1 bytes) * Maximum width: 16 px - * Storage size: 94 bytes (uncompressed) + * Storage size: 93 bytes (uncompressed) */ diff --git a/firmware/lcd/print.c b/firmware/lcd/print.c index 8466283..6f6ac75 100644 --- a/firmware/lcd/print.c +++ b/firmware/lcd/print.c @@ -2,6 +2,7 @@ #include #include #include +#include int x=0; int y=0; @@ -69,3 +70,13 @@ void lcdSetCrsr(int dx,int dy){ void lcdSetCrsrX(int dx){ x=dx; }; + +void setSystemFont(void){ + setIntFont(&Font_7x8); +}; + + +int lcdGetVisibleLines(void){ + return (RESY/getFontHeight()); // subtract title line +}; + diff --git a/firmware/lcd/print.h b/firmware/lcd/print.h index d1d8de5..dca2850 100644 --- a/firmware/lcd/print.h +++ b/firmware/lcd/print.h @@ -10,4 +10,5 @@ void lcdRefresh(); void lcdMoveCrsr(signed int dx,signed int dy); void lcdSetCrsr(int dx,int dy); void lcdSetCrsrX(int dx); - +void setSystemFont(void); +int lcdGetVisibleLines(void); diff --git a/firmware/lcd/render.c b/firmware/lcd/render.c index 62339df..2a2f692 100644 --- a/firmware/lcd/render.c +++ b/firmware/lcd/render.c @@ -18,10 +18,10 @@ FIL file; /* current font file */ /* Exported Functions */ -void setIntFont(const struct FONT_DEF * font){ - memcpy(&efont.def,font,sizeof(struct FONT_DEF)); +void setIntFont(const struct FONT_DEF * newfont){ + memcpy(&efont.def,newfont,sizeof(struct FONT_DEF)); efont.type=FONT_INTERNAL; - font=NULL; + font=&efont.def; }; void setExtFont(const char *fname){ diff --git a/firmware/loadable/spaceinvaders.c b/firmware/loadable/spaceinvaders.c index 432c1a9..7e482f6 100644 --- a/firmware/loadable/spaceinvaders.c +++ b/firmware/loadable/spaceinvaders.c @@ -4,8 +4,7 @@ #include "lcd/render.h" #include "lcd/display.h" -#include "lcd/fonts/invaders.c" -//#include "lcd/allfonts.h" +#include "lcd/allfonts.h" void ReinvokeISP(void); void EnableWatchdog(uint32_t ms); @@ -13,51 +12,170 @@ void delayms(uint32_t ms); /**************************************************************************/ #define POS_PLAYER_Y 60 +#define POS_UFO_Y 0 #define ENEMY_ROWS 3 #define ENEMY_COLUMNS 6 #define DISABLED 255 +#define UFO_PROB 1000 + #define TYPE_PLAYER 1 -#define TYPE_ALIEN 2 +#define TYPE_ENEMY_A 2 +#define TYPE_ENEMY_B 3 +#define TYPE_ENEMY_C 4 +#define TYPE_UFO 5 + +#define BUNKERS 3 +#define BUNKER_WIDTH 10 +static const BUNKER_X[] = {15, RESX/2-BUNKER_WIDTH/2,RESX-BUNKER_WIDTH-15}; +static const ENEMY_WIDTHS[] = {10,11,8}; struct gamestate { char player; + char ufo; char shot_x, shot_y; + char shots_x[ENEMY_COLUMNS]; + char shots_y[ENEMY_COLUMNS]; char alive; char move, direction, lastcol; - bool killed; + bool killed; + bool step; + uint32_t score; + char level; + int8_t rokets; 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}; + uint8_t bunker[BUNKERS][BUNKER_WIDTH]; +} game; char key; - -void ram(void) { - gpioSetValue (RB_LED1, CFG_LED_OFF); - init_enemy(); - - while (1) { - if(gpioGetValue(RB_BTN2)==0){ - delayms(200); - while(gpioGetValue(RB_BTN0)==0); - return; - } - lcdFill(0); - check_end(); - move_shot(); - move_player(); - move_enemy(); - draw_player(); - draw_enemy(); - draw_shot(); - draw_status(); - lcdDisplay(); - delayms(10); - } +void init_game(); +void check_end(); +void move_ufo(); +void move_shots(); +void move_player(); +void move_enemay(); +void draw_score(); +void draw_bunker(); +void draw_player(); +void draw_enemy(); +void draw_shots(); +void draw_ufo(); +void screen_intro(); +void screen_gameover(); +void screen_level(); +bool check_bunker(char xpos, char ypos, int8_t shift); + +void ram(void) { + //gpioSetValue (RB_LED1, CFG_LED_OFF); + //backlightInit(); + while(1) { + screen_intro(); + game.rokets = 3; + game.level = 1; + init_game(); + screen_level(); + while (game.rokets>=0) { + ////checkISP(); + lcdFill(0); + check_end(); + move_ufo(); + move_shot(); + move_shots(); + move_player(); + move_enemy(); + draw_score(); + draw_ufo(); + draw_bunker(); + draw_player(); + draw_enemy(); + draw_shots(); + // draw_status(); + lcdDisplay(); + delayms(12); + } + screen_gameover(); + } return; } +void screen_intro() { + char key=0; + while(key==0) { + lcdFill(0); + font = &Font_Invaders; + DoString(28,25,"ABC"); + font = &Font_7x8; + DoString (28,40,"SPACE"); + DoString (18,50,"INVADERS"); + //DoString (20,RESY-24, "Highscore"); + DoString (0, 0, "12345"); + DoString (0, 9, "iggy"); + lcdDisplay(); + + delayms_queue(50); + key=getInput(); + } +} + +void screen_gameover() { + char key =0; + while(key==0) { + lcdFill(0); + font = &Font_7x8; + DoString (12,32, "GAME OVER"); + DoInt (0,0, game.score); + DoString (0,9,"HIGHSCORE!"); + lcdDisplay(); + delayms_queue(50); + key=getInput(); + } +} + +void screen_level() { + lcdFill(0); + draw_score(); + font = &Font_7x8; + int dx = DoString(20,32, "Level "); + DoInt(dx,32,game.level); + lcdDisplay(); + delayms(500); +} + +void init_game(void) { + game.player = RESX/2-4; + game.shot_x = DISABLED; + game.shot_y = 0; + game.alive = ENEMY_ROWS*ENEMY_COLUMNS; + game.move = 0; + game.direction = -1; + game.lastcol = ENEMY_COLUMNS-1; + game.killed = 0; + game.step = false; + game.ufo = DISABLED; + init_enemy(); + + for (char col=0; colBUNKER_X[BUNKERS-1-b] && + xposRESY-16) { + int offset = BUNKER_WIDTH - (xpos-BUNKER_X[BUNKERS-1-b]); + if (game.bunker[b][offset]!=0) { + if (shift>0) + game.bunker[b][offset]&=game.bunker[b][offset]<>-shift; + return true; + } + } + } + return false; +} + void move_shot() { //No shot, do nothing if(game.shot_x == DISABLED) { @@ -79,21 +216,114 @@ void move_shot() { return; } + //check for collision with bunker +// for (int b=0; bBUNKER_X[BUNKERS-1-b] && +// game.shot_xRESY-16) { +// int offset = BUNKER_WIDTH - (game.shot_x-BUNKER_X[BUNKERS-1-b]); +// if (game.bunker[b][offset]!=0) { +// game.bunker[b][offset]&=game.bunker[b][offset]<<1; +// game.shot_x=DISABLED; +// } +// } +// } + if (check_bunker(game.shot_x,game.shot_y-5,1 )) + game.shot_x=DISABLED; + //check for collision with enemy, kill enemy if for (int row=0; row= game.shot_y && game.enemy_row_y[row]+6 < game.shot_y+7) { for(int col = 0; col= game.enemy_x[row][col] && game.shot_x < game.enemy_x[row][col]+8) { + if(game.shot_x >= game.enemy_x[row][col] && game.shot_x < game.enemy_x[row][col]+ENEMY_WIDTHS[row]) { game.enemy_x[row][col]=DISABLED; game.shot_x = DISABLED; game.alive--; + game.score++; return; } } } } - - game.shot_y -= 3; + //check for collision with ufo + if (game.ufo != DISABLED && + game.shot_x>game.ufo && + game.shot_x= RESY) { + game.shots_x[col] = DISABLED; + return; + } + //check for collision with bunker + if (check_bunker(game.shots_x[col],game.shots_y[col],-1)) + game.shots_x[col]=DISABLED; + +// for (int b=0; bBUNKER_X[BUNKERS-1-b] && +// game.shots_x[col]RESY-16) { +// int offset = BUNKER_WIDTH - (game.shots_x[col]-BUNKER_X[BUNKERS-1-b])-1; +// if (game.bunker[b][offset]!=0) { +// game.bunker[b][offset]&=game.bunker[b][offset]>>1; +// game.shots_x[col]=DISABLED; +// } +// } +// } + //check for collision with player + + if (game.shots_y[col] >= RESY-13 && + game.shots_x[col] > game.player+1 && + game.shots_x[col] < game.player+6) { + + game.killed = true; + } + + //move shots down + game.shots_y[col] += 1; + } +} + +void move_ufo() { + if (game.ufo == DISABLED) { + if ((getRandom()%UFO_PROB)==0) { + game.ufo = 0; + } + return; + } + if (game.ufo >= RESX){ + game.ufo = DISABLED; + return; + } + game.ufo++; } void move_player() { @@ -117,20 +347,40 @@ void move_enemy() { return; } + game.step = !game.step; for (int col = 0; col < ENEMY_COLUMNS; col++) { for (int row = 0; row < ENEMY_ROWS; row++) { char pos = game.enemy_x[row][(game.direction==1)?(ENEMY_COLUMNS-(col+1)):col]; if (pos != DISABLED) { //Check collision with player - if(game.enemy_row_y[row]+8 >= POS_PLAYER_Y && pos+8 >= game.player && pos < game.player+8){ - game.killed = true; + if((game.enemy_row_y[row]+8 >= POS_PLAYER_Y && pos+8 >= game.player && pos < game.player+8) || + game.enemy_row_y[row]+8 >= POS_PLAYER_Y+8) { + for(int row=0; row=BUNKER_X[BUNKERS-1-b] && + // pos<=BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH && + // game.enemy_row_y[row]+8RESY-16) { + // int offset = BUNKER_WIDTH - (pos-BUNKER_X[BUNKERS-1-b]); + // if (game.bunker[b][offset]!=0) { + // game.bunker[b][offset]&=game.bunker[b][offset]>>2; + // } + // } + // } + + + //Are we at the beginning or end? Direction change if((pos <=0 && game.direction != 1) || - (pos >=RESX-8-1 && game.direction == 1)){ + (pos >=RESX-11-1 && game.direction == 1)){ game.direction = (game.direction==1)?-1:1; for (char r = 0; r=RESX-8 && game.direction == 1)){ - game.direction *= -1; - //TODOmove down - return; - } - game.enemy_x[row][col] += game.direction; - next = true; - } - } - if (next){ - game.lastcol += game.direction; - return; - } - } - game.move = game.alive; - return; - } - game.move--; -} void draw_player() { //draw_sprite(50, 20); - draw_sprite(TYPE_PLAYER,game.player, POS_PLAYER_Y); + draw_sprite(TYPE_PLAYER, game.player, POS_PLAYER_Y); +} + +void draw_ufo() { + if (game.ufo!=DISABLED) + draw_sprite(TYPE_UFO, game.ufo, POS_UFO_Y); } void draw_enemy() { for (int row = 0; row/dev/null >/dev/null + then + TMPFILE=/tmp/firmware-$APP.bin$BUILD + echo OK $APP as $TMPFILE + cp firmware/firmware.bin $TMPFILE + else + echo FIRMWARE BUILD FAILED $APP + FIRMWARESUCCESS=0 + fi + fi + + if test $FIRMWARESUCCESS -eq 1 -a $BUILDSIM -eq 1; then + if make -C simulat0r APP=$APP 2>/dev/null >/dev/null + then + TMPFILE=/tmp/qsimulat0r-$APP$BUILD + echo OK $APP as $TMPFILE + cp simulat0r/gui/build/qsimulat0r $TMPFILE + else + echo SIMULAT0R BUILD FAILED $APP + fi + fi +} + +echo "Testing all applications..." + +for i in `find firmware/applications/ -iname \*.c | sort` +do + if grep -q main_ $i + then + APP=`basename $i | sed "s/\..*//"` + doTest $APP + fi +done diff --git a/simulat0r/firmware/Makefile.inc b/simulat0r/firmware/Makefile.inc index cfa0f0a..98a0713 100644 --- a/simulat0r/firmware/Makefile.inc +++ b/simulat0r/firmware/Makefile.inc @@ -23,6 +23,8 @@ CC = $(CROSS_COMPILE)gcc LD = $(CROSS_COMPILE)ld REALLD = $(CROSS_COMPILE)ld SIZE = $(CROSS_COMPILE)size +AR = $(CROSS_COMPILE)ar +RANLIB = $(CROSS_COMPILE)ranlib OBJCOPY = $(CROSS_COMPILE)objcopy OBJDUMP = $(CROSS_COMPILE)objdump OUTFILE = firmware @@ -44,6 +46,12 @@ endif CFLAGS = -std=c99 -c -g -O0 $(INCLUDE_PATHS) -Wall -funsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -DRAMCODE=$(RAMCODE) -fno-builtin -DSIMULATOR -I$(ROOT_PATH)/../simcore -include libc-unc0llide.h $(CONFIG_GCC_SHOWCOLUMN) #LDFLAGS = -nostartfiles +ifeq ($(shell uname), Darwin) +# Mac OS X provides a stdio.h with unwanted defines +CFLAGS += -D_FORTIFY_SOURCE=0 +# ld64 has problems with common symbols , apply a workaround +RANLIBFLAGS = -c +endif CONFIG_MAKE_PRINTDIRECTORY = --no-print-directory CONFIG_GCC_SHOWCOLUMN = diff --git a/simulat0r/firmware/applications/inputtest.c b/simulat0r/firmware/applications/inputtest.c new file mode 100644 index 0000000..9a04a36 --- /dev/null +++ b/simulat0r/firmware/applications/inputtest.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/applications/inputtest.c" diff --git a/simulat0r/firmware/applications/mesh/config.c b/simulat0r/firmware/applications/mesh/config.c new file mode 100644 index 0000000..b3ae6be --- /dev/null +++ b/simulat0r/firmware/applications/mesh/config.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../../firmware/applications/mesh/config.c" diff --git a/simulat0r/firmware/applications/mesh/mesh.c b/simulat0r/firmware/applications/mesh/mesh.c new file mode 100644 index 0000000..f733699 --- /dev/null +++ b/simulat0r/firmware/applications/mesh/mesh.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../../firmware/applications/mesh/mesh.c" diff --git a/simulat0r/firmware/applications/mesh/util.c b/simulat0r/firmware/applications/mesh/util.c new file mode 100644 index 0000000..54bf787 --- /dev/null +++ b/simulat0r/firmware/applications/mesh/util.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../../firmware/applications/mesh/util.c" diff --git a/simulat0r/firmware/applications/mesh/uuid.c b/simulat0r/firmware/applications/mesh/uuid.c new file mode 100644 index 0000000..86ea43c --- /dev/null +++ b/simulat0r/firmware/applications/mesh/uuid.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../../firmware/applications/mesh/uuid.c" diff --git a/simulat0r/firmware/basic/config.h b/simulat0r/firmware/basic/config.h new file mode 100644 index 0000000..fe5bbda --- /dev/null +++ b/simulat0r/firmware/basic/config.h @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/basic/config.h" diff --git a/simulat0r/firmware/basic/simpletime.c b/simulat0r/firmware/basic/simpletime.c new file mode 100644 index 0000000..ab04cd5 --- /dev/null +++ b/simulat0r/firmware/basic/simpletime.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/basic/simpletime.c" diff --git a/simulat0r/firmware/basic/simpletime.h b/simulat0r/firmware/basic/simpletime.h new file mode 100644 index 0000000..118da21 --- /dev/null +++ b/simulat0r/firmware/basic/simpletime.h @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/basic/simpletime.h" diff --git a/simulat0r/firmware/basic/stringin.c b/simulat0r/firmware/basic/stringin.c new file mode 100644 index 0000000..34cb6e3 --- /dev/null +++ b/simulat0r/firmware/basic/stringin.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/basic/stringin.c" diff --git a/simulat0r/firmware/funk/mesh.c b/simulat0r/firmware/funk/mesh.c new file mode 100644 index 0000000..29a9352 --- /dev/null +++ b/simulat0r/firmware/funk/mesh.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/funk/mesh.c" diff --git a/simulat0r/firmware/funk/mesh.h b/simulat0r/firmware/funk/mesh.h new file mode 100644 index 0000000..a5fe83f --- /dev/null +++ b/simulat0r/firmware/funk/mesh.h @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/funk/mesh.h" diff --git a/simulat0r/gui/qsimulat0r.cc b/simulat0r/gui/qsimulat0r.cc index c2146d2..e8bbb5c 100644 --- a/simulat0r/gui/qsimulat0r.cc +++ b/simulat0r/gui/qsimulat0r.cc @@ -19,6 +19,7 @@ using namespace std; extern "C" { #include "basic/basic.h" +#include "basic/config.h" #include "lcd/backlight.h" #define lcdGetPixel __hideaway_lcdGetPixel @@ -92,15 +93,15 @@ public: pixmap.setPixel(1,1,(QColor(backlight,backlight,backlight).rgb())); pixmap.fill(pixmap.pixel(1,1)); + const int pixelOn=GLOBAL(lcdinvert)?colorInvertedPixelOn:colorPixelOn; + const int pixelOff=GLOBAL(lcdinvert)?colorInvertedPixelOff:colorPixelOff; + // draw lcd array for (int x = 0; x < dimx; ++x) { for(int y=0; y void simlcdDisplayUpdate() { write(1,"\033[H",3); + const char* symbolOff=GLOBAL(lcdinvert)?"_":"@"; + const char* symbolOn=GLOBAL(lcdinvert)?"#":"."; + for(int y=0; y