From aa821fca3f570f17dacce3f20ddd5a10cea3b038 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Sun, 31 Jul 2011 22:13:06 +0200 Subject: [PATCH 01/17] Fix a few things. --- firmware/applications/default.c | 20 ++++++++++++++------ firmware/applications/mesh/util.c | 14 +++++++++++++- firmware/applications/tester/util.c | 14 +++++++++++++- firmware/basic/basic.c | 3 +++ firmware/basic/basic.h | 14 ++++++++------ firmware/basic/config.c | 10 ++++++---- firmware/basic/night.c | 16 ++++++++-------- firmware/funk/mesh.c | 2 +- firmware/lcd/display.h | 1 + 9 files changed, 67 insertions(+), 27 deletions(-) diff --git a/firmware/applications/default.c b/firmware/applications/default.c index d4f0b00..ed9aa8b 100644 --- a/firmware/applications/default.c +++ b/firmware/applications/default.c @@ -5,6 +5,7 @@ #include "lcd/fonts/smallfonts.h" #include "lcd/print.h" #include "filesystem/ff.h" +#include "usb/usbmsc.h" #include "basic/random.h" /**************************************************************************/ @@ -12,12 +13,18 @@ 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; @@ -41,12 +48,13 @@ void tick_default(void) { if(ctr>100/SYSTICKSPEED){ if(isNight()){ backlightSetBrightness(GLOBAL(lcdbacklight)); - if(GLOBAL(nightinvert)) - lcdSetInvert(0); + lcdSetInvert(0); } else { backlightSetBrightness(0); - if(GLOBAL(nightinvert)) + if(GLOBAL(dayinvert)) lcdSetInvert(1); + else + lcdSetInvert(0); } } diff --git a/firmware/applications/mesh/util.c b/firmware/applications/mesh/util.c index 721cacd..8359628 100644 --- a/firmware/applications/mesh/util.c +++ b/firmware/applications/mesh/util.c @@ -29,6 +29,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 +49,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/tester/util.c b/firmware/applications/tester/util.c index 721cacd..8359628 100644 --- a/firmware/applications/tester/util.c +++ b/firmware/applications/tester/util.c @@ -29,6 +29,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 +49,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..6da1410 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 @@ -203,12 +204,13 @@ 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 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 GLOBAL(x) GLOBAL ## x diff --git a/firmware/basic/config.c b/firmware/basic/config.c index d4a0b5a..a307853 100644 --- a/firmware/basic/config.c +++ b/firmware/basic/config.c @@ -10,12 +10,13 @@ struct CDESC the_config[]= { {"version", CFGVER, CFGVER, CFGVER}, {"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, 1, 6 }, + {"lcdcontrast", 0, 1, 6 }, { NULL, 0, 0, 0 }, }; @@ -25,7 +26,8 @@ struct CDESC the_config[]= { /**************************************************************************/ void applyConfig(){ - lcdSetContrast(GLOBAL(lcdcontrast)); + if(GLOBAL(lcdcontrast)>0) + lcdSetContrast(GLOBAL(lcdcontrast)); return 0; }; diff --git a/firmware/basic/night.c b/firmware/basic/night.c index ae62db1..8adc84c 100644 --- a/firmware/basic/night.c +++ b/firmware/basic/night.c @@ -2,12 +2,12 @@ #include "basic/basic.h" -#define RANGE (10) -#define HYST (4) -uint32_t light=300*HYST; +#define SAMPCT (4) +uint32_t light=300*SAMPCT; char _isnight=1; -#define threshold GLOBAL(nighttrigger) +#define threshold GLOBAL(daytrig) +#define RANGE GLOBAL(daytrighyst) void LightCheck(void){ int iocon; @@ -21,7 +21,7 @@ void LightCheck(void){ 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); @@ -31,15 +31,15 @@ void LightCheck(void){ threshold=320; }; - if(_isnight && light/HYST>(threshold+RANGE)) + if(_isnight && light/SAMPCT>(threshold+RANGE)) _isnight=0; - if(!_isnight && light/HYST_timet) // Do not live in the past. _timet = toff; continue; diff --git a/firmware/lcd/display.h b/firmware/lcd/display.h index 79f671e..d39ccd3 100644 --- a/firmware/lcd/display.h +++ b/firmware/lcd/display.h @@ -30,4 +30,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 From 1ccda41467b2740ccf90e79ae5ffe59da6b8e29c Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Sun, 31 Jul 2011 22:46:24 +0200 Subject: [PATCH 02/17] Sign error. Whoops. --- firmware/funk/mesh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/funk/mesh.c b/firmware/funk/mesh.c index 24a8e21..0bffc34 100644 --- a/firmware/funk/mesh.c +++ b/firmware/funk/mesh.c @@ -76,7 +76,7 @@ void mesh_recvloop(void){ }; if(MO_TYPE(buf)=='T'){ - time_t toff=MO_TIME(buf)-((getTimer()-(1000/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; From 621bca40b300109367b4b2f1c2d635d9f52cf8ba Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 01:08:05 +0200 Subject: [PATCH 03/17] improve application Makfile --- firmware/applications/Makefile | 9 +++++---- firmware/applications/{mktester => mkfirmware} | 5 ++++- firmware/applications/tester.c | 6 ------ 3 files changed, 9 insertions(+), 11 deletions(-) rename firmware/applications/{mktester => mkfirmware} (95%) diff --git a/firmware/applications/Makefile b/firmware/applications/Makefile index 86a45db..dacc19e 100644 --- a/firmware/applications/Makefile +++ b/firmware/applications/Makefile @@ -33,6 +33,7 @@ endif WRAP=wrapper LIBNAME=app + ########################################################################## # GNU GCC compiler flags ########################################################################## @@ -66,21 +67,21 @@ $(LOBJ): OBJS += $(LOBJ) endif -ifeq "$(APP)" "tester" +ifeq "$(wildcard $(APP))" "$(APP)" ifndef TYPE TYPE=$(APP) endif TSRCS = $(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 $(APP) $(TSRCS) > $@ OBJS += $(TOBJS) endif @@ -93,7 +94,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/mktester b/firmware/applications/mkfirmware similarity index 95% rename from firmware/applications/mktester rename to firmware/applications/mkfirmware index 661351d..fdf7f2d 100755 --- a/firmware/applications/mktester +++ b/firmware/applications/mkfirmware @@ -1,5 +1,8 @@ #!/bin/sh +APP=$1 +shift + for f in $* ; do grep -h '^void ' $f|sed 's/^void //;s/(.*//'|while read a ; do echo "void $a(void);" @@ -58,7 +61,7 @@ done echo "NULL" echo "};" -echo "inline void generated_tick(void){" +echo "inline void tick_${APP}(void){" for f in $* ; do grep -h '^void tick_' $f|sed 's/^void //;s/(.*//'|while read a ; do echo "$a();" diff --git a/firmware/applications/tester.c b/firmware/applications/tester.c index 50a3542..667b335 100644 --- a/firmware/applications/tester.c +++ b/firmware/applications/tester.c @@ -16,9 +16,3 @@ void main_tester(void) { handleMenu(&mainmenu); gotoISP(); }; - -void tick_tester(void){ - generated_tick(); -}; - - From 5d0887be714265fd57df3a819dc26217b19369ad Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 01:12:21 +0200 Subject: [PATCH 04/17] Move config stuff into own include. Iggy said its better :-) --- firmware/applications/mesh/config.c | 1 + firmware/applications/mesh/util.c | 1 + firmware/basic/basic.h | 35 ++++------------------------- firmware/basic/config.c | 6 ++++- firmware/basic/night.c | 1 + firmware/filesystem/ff.h | 1 + firmware/lcd/display.c | 1 + 7 files changed, 14 insertions(+), 32 deletions(-) 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 8359628..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" diff --git a/firmware/basic/basic.h b/firmware/basic/basic.h index 6da1410..ed67c74 100644 --- a/firmware/basic/basic.h +++ b/firmware/basic/basic.h @@ -186,37 +186,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 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 GLOBAL(x) GLOBAL ## x - - -#define SYSTICKSPEED 10 - // itoa.c #define F_ZEROS (1<<0) #define F_LONG (1<<1) @@ -229,4 +198,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 a307853..313d46e 100644 --- a/firmware/basic/config.c +++ b/firmware/basic/config.c @@ -4,8 +4,9 @@ #include "lcd/print.h" #include "filesystem/ff.h" #include "basic/random.h" +#include "basic/config.h" -#define CFGVER 23 +#define CFGVER 24 struct CDESC the_config[]= { {"version", CFGVER, CFGVER, CFGVER}, @@ -20,6 +21,9 @@ struct CDESC the_config[]= { { 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++) diff --git a/firmware/basic/night.c b/firmware/basic/night.c index 8adc84c..f944246 100644 --- a/firmware/basic/night.c +++ b/firmware/basic/night.c @@ -1,6 +1,7 @@ #include #include "basic/basic.h" +#include "basic/config.h" #define SAMPCT (4) uint32_t light=300*SAMPCT; diff --git a/firmware/filesystem/ff.h b/firmware/filesystem/ff.h index 07eb8ad..352ed5c 100644 --- a/firmware/filesystem/ff.h +++ b/firmware/filesystem/ff.h @@ -329,6 +329,7 @@ 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(); diff --git a/firmware/lcd/display.c b/firmware/lcd/display.c index 3ffd916..bdb1d4f 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" /**************************************************************************/ From 62992863489a42a21a5af965a7b9923ac7ef0941 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 01:12:58 +0200 Subject: [PATCH 05/17] Two utility functions to read/write small files --- firmware/filesystem/ff.h | 2 ++ firmware/filesystem/util.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/firmware/filesystem/ff.h b/firmware/filesystem/ff.h index 352ed5c..611a703 100644 --- a/firmware/filesystem/ff.h +++ b/firmware/filesystem/ff.h @@ -332,6 +332,8 @@ int ff_del_syncobj (_SYNC_t); /* Delete a sync object */ #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/util.c b/firmware/filesystem/util.c index 7e635ad..d5cc5d0 100644 --- a/firmware/filesystem/util.c +++ b/firmware/filesystem/util.c @@ -22,3 +22,41 @@ const char* f_get_rc_string (FRESULT rc) { void fsInit(){ 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; + }; + + 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; + }; + + return writebytes; +}; + From 29df9b9e1fed7f3f046a1ca6354cd2c68fe0e7a1 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 01:34:11 +0200 Subject: [PATCH 06/17] Add missing config.h --- firmware/applications/default.c | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/applications/default.c b/firmware/applications/default.c index ed9aa8b..1cc168e 100644 --- a/firmware/applications/default.c +++ b/firmware/applications/default.c @@ -1,5 +1,6 @@ #include #include "basic/basic.h" +#include "basic/config.h" #include "lcd/lcd.h" #include "lcd/fonts/smallfonts.h" From f2c5d53cb92e6a7dc28290a9ed09027947a876de Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 01:55:04 +0200 Subject: [PATCH 07/17] Oops. We need to close the files, too. --- firmware/filesystem/util.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/firmware/filesystem/util.c b/firmware/filesystem/util.c index d5cc5d0..0f3c939 100644 --- a/firmware/filesystem/util.c +++ b/firmware/filesystem/util.c @@ -38,6 +38,8 @@ int readFile(char * filename, char * data, int len){ return -1; }; + f_close(&file); + data[readbytes]=0; return readbytes; }; @@ -56,6 +58,7 @@ int writeFile(char * filename, char * data, int len){ if(res){ return -1; }; + f_close(&file); return writebytes; }; From 2a632870fd1992243c88ba1d7787e0e4815b810e Mon Sep 17 00:00:00 2001 From: schneider Date: Mon, 1 Aug 2011 02:18:03 +0200 Subject: [PATCH 08/17] added 32 level contrast --- firmware/basic/config.c | 2 +- firmware/lcd/display.c | 54 +++++++++++++++++++++++++++++++++++++++-- firmware/lcd/display.h | 1 + 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/firmware/basic/config.c b/firmware/basic/config.c index d4a0b5a..8933203 100644 --- a/firmware/basic/config.c +++ b/firmware/basic/config.c @@ -15,7 +15,7 @@ struct CDESC the_config[]= { {"lcdbacklight", 50, 0, 100}, {"lcdmirror", 0, 0, 1 }, {"lcdinvert", 0, 0, 1 }, - {"lcdcontrast", 3, 1, 6 }, + {"lcdcontrast", 3, 0, 31 }, { NULL, 0, 0, 0 }, }; diff --git a/firmware/lcd/display.c b/firmware/lcd/display.c index 3ffd916..e8da386 100644 --- a/firmware/lcd/display.c +++ b/firmware/lcd/display.c @@ -61,6 +61,55 @@ static void lcdWrite(uint8_t cd, uint8_t data) { frame = SSP_SSP0DR; } +#define CS 2,1 +#define SCK 2,11 +#define SDA 0,9 +#define RST 2,2 + +uint8_t lcdRead(uint8_t data) +{ + uint8_t i; + + gpioSetDir(SDA, 1); + gpioSetValue(SCK, 0); + delayms(1); + gpioSetValue(CS, 0); + delayms(1); + + gpioSetValue(SDA, 0); + delayms(1); + gpioSetValue(SCK, 1); + delayms(1); + + for(i=0; i<8; i++){ + gpioSetValue(SCK, 0); + delayms(1); + if( data & 0x80 ) + gpioSetValue(SDA, 1); + else + gpioSetValue(SDA, 0); + data <<= 1; + gpioSetValue(SCK, 1); + delayms(1); + } + uint8_t ret = 0; + + gpioSetDir(SDA, 0); + for(i=0; i<8; i++){ + gpioSetValue(SCK, 0); + delayms(1); + ret <<= 1; + ret |= gpioGetValue(SDA); + gpioSetValue(SCK, 1); + delayms(1); + } + + gpioSetValue(CS, 0); + gpioSetDir(SDA, 1); + delayms(1); +} + + void lcdInit(void) { sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge); @@ -172,8 +221,9 @@ inline void lcdInvert(void) { } void lcdSetContrast(int c) { - c+=0x20; - if(c>0x2e) c=0x24; + c+=0x80; + if(c>0x9F) + return; lcd_select(); lcdWrite(TYPE_CMD,c); lcd_deselect(); diff --git a/firmware/lcd/display.h b/firmware/lcd/display.h index 79f671e..d1bcd64 100644 --- a/firmware/lcd/display.h +++ b/firmware/lcd/display.h @@ -20,6 +20,7 @@ /* Display buffer */ extern uint8_t lcdBuffer[RESX*RESY_B]; +uint8_t lcdRead(uint8_t data); void lcdInit(void); void lcdFill(char f); void lcdDisplay(void); From 13df9eec9d732ba35929b53d93c5e9fa82564025 Mon Sep 17 00:00:00 2001 From: schneider Date: Mon, 1 Aug 2011 02:18:36 +0200 Subject: [PATCH 09/17] select: wait for key release --- firmware/filesystem/select.c | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/filesystem/select.c b/firmware/filesystem/select.c index 90c9af6..74b4773 100644 --- a/firmware/filesystem/select.c +++ b/firmware/filesystem/select.c @@ -66,6 +66,7 @@ int selectFile(char *filename, char *extension) } lcdRefresh(); key=getInputWait(); + getInputWaitRelease(); if( key==BTN_DOWN ){ if( selected < count-1 ){ selected++; From f41d900e0d54088f5d9c530aac7eea34c31ec797 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 05:06:20 +0200 Subject: [PATCH 10/17] Adjust startup value --- firmware/basic/night.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/basic/night.c b/firmware/basic/night.c index f944246..9423ffd 100644 --- a/firmware/basic/night.c +++ b/firmware/basic/night.c @@ -4,7 +4,7 @@ #include "basic/config.h" #define SAMPCT (4) -uint32_t light=300*SAMPCT; +uint32_t light=150*SAMPCT; char _isnight=1; #define threshold GLOBAL(daytrig) From 34869e2973d130e734517a102721f0d2e9b0a3c0 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 05:10:37 +0200 Subject: [PATCH 11/17] modernize menu.c --- firmware/basic/menu.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/firmware/basic/menu.c b/firmware/basic/menu.c index 4758d65..811e356 100644 --- a/firmware/basic/menu.c +++ b/firmware/basic/menu.c @@ -2,7 +2,6 @@ #include "basic/basic.h" -#include "lcd/fonts.h" #include "lcd/render.h" #include "lcd/print.h" @@ -21,27 +20,24 @@ void handleMenu(const struct MENU *the_menu) { for (numentries = 0; the_menu->entries[numentries] != NULL; numentries++); - visible_lines = (RESY/font->u8Height)-1; // subtract title line + visible_lines = (RESY/getFontHeight())-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: From 6bd703f006e249500ec701cb147fdd846388cf3a Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 05:11:04 +0200 Subject: [PATCH 12/17] fix new font setting for internal fonts --- firmware/lcd/render.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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){ From 61c12936110fcb45c4c26d2f76f17ffd20954cee Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 05:11:56 +0200 Subject: [PATCH 13/17] Add Timestamp support for filesystem. This took me 3h to debug :-/ --- firmware/filesystem/at45db041d.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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; } From cccb8694232bbde59e2981445c6bbddec839b3a9 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 05:22:24 +0200 Subject: [PATCH 14/17] Fix a few warnings --- firmware/basic/config.c | 3 ++- firmware/basic/night.c | 6 ------ firmware/basic/random.c | 1 + firmware/funk/filetransfer.c | 2 +- firmware/funk/rftransfer.c | 1 + firmware/main.c | 1 + 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/firmware/basic/config.c b/firmware/basic/config.c index 0e3b35f..396e500 100644 --- a/firmware/basic/config.c +++ b/firmware/basic/config.c @@ -1,6 +1,7 @@ #include #include "basic/basic.h" +#include "lcd/display.h" #include "lcd/print.h" #include "filesystem/ff.h" #include "basic/random.h" @@ -32,7 +33,7 @@ char nickfont[FILENAMELEN]; void applyConfig(){ if(GLOBAL(lcdcontrast)>0) lcdSetContrast(GLOBAL(lcdcontrast)); - return 0; + return; }; int saveConfig(void){ diff --git a/firmware/basic/night.c b/firmware/basic/night.c index 9423ffd..5efe7c4 100644 --- a/firmware/basic/night.c +++ b/firmware/basic/night.c @@ -14,8 +14,6 @@ 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; @@ -28,10 +26,6 @@ void LightCheck(void){ gpioSetDir(RB_LED3, iodir); IOCON_PIO1_11=iocon; - if(threshold==0){ // uninitialized? - threshold=320; - }; - if(_isnight && light/SAMPCT>(threshold+RANGE)) _isnight=0; diff --git a/firmware/basic/random.c b/firmware/basic/random.c index 06500ca..08b5a05 100644 --- a/firmware/basic/random.c +++ b/firmware/basic/random.c @@ -1,6 +1,7 @@ #include #include "random.h" #include "xxtea.h" +#include "core/adc/adc.h" #define STATE_SIZE 8 uint32_t state[STATE_SIZE]; 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/rftransfer.c b/firmware/funk/rftransfer.c index b392152..cda2e50 100644 --- a/firmware/funk/rftransfer.c +++ b/firmware/funk/rftransfer.c @@ -1,6 +1,7 @@ #include "rftransfer.h" #include "nrf24l01p.h" #include +#include #include #include diff --git a/firmware/main.c b/firmware/main.c index bcef02d..e24f7db 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -5,6 +5,7 @@ #include "basic/basic.h" #include "lcd/render.h" +#include "filesystem/ff.h" /**************************************************************************/ From 26515e271750fb542c720b8faf849b4f5249208d Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 05:23:14 +0200 Subject: [PATCH 15/17] I forgot this new .h file a few commits ago. --- firmware/basic/config.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 firmware/basic/config.h diff --git a/firmware/basic/config.h b/firmware/basic/config.h new file mode 100644 index 0000000..c4419c5 --- /dev/null +++ b/firmware/basic/config.h @@ -0,0 +1,35 @@ +#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 GLOBALnickname (nickname) +#define GLOBALnickfont (nickfont) + +#define GLOBAL(x) GLOBAL ## x + +#endif From d4c48f66c23fe3d7a44a75871ffe0cd3f2739274 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 05:31:47 +0200 Subject: [PATCH 16/17] Disable nrf on lowpower-off --- firmware/basic/voltage.c | 1 + firmware/funk/nrf24l01p.c | 7 +++++++ firmware/funk/nrf24l01p.h | 1 + 3 files changed, 9 insertions(+) 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/funk/nrf24l01p.c b/firmware/funk/nrf24l01p.c index bffaa34..8c3c464 100644 --- a/firmware/funk/nrf24l01p.c +++ b/firmware/funk/nrf24l01p.c @@ -395,3 +395,10 @@ void nrf_init() { nrf_write_reg(R_RF_SETUP,DEFAULT_SPEED|R_RF_SETUP_RF_PWR_3); }; +void nrf_off() { + nrf_write_reg(R_CONFIG, + R_CONFIG_MASK_RX_DR| + R_CONFIG_MASK_TX_DS| + R_CONFIG_MASK_MAX_RT + ); // Most important: no R_CONFIG_PWR_UP +}; diff --git a/firmware/funk/nrf24l01p.h b/firmware/funk/nrf24l01p.h index ace6122..252d747 100644 --- a/firmware/funk/nrf24l01p.h +++ b/firmware/funk/nrf24l01p.h @@ -138,6 +138,7 @@ int nrf_rcv_pkt_time_encr(int maxtime, int maxsize, uint8_t * pkt, uint32_t cons char nrf_snd_pkt_crc_encr(int size, uint8_t * pkt, uint32_t const k[4]); void nrf_init() ; +void nrf_off() ; void nrf_cmd(uint8_t cmd); uint8_t nrf_cmd_status(uint8_t cmd); From 377d614c385f4416b0ee1b027580992f93551cbd Mon Sep 17 00:00:00 2001 From: Rainer Mueller Date: Sun, 31 Jul 2011 21:52:28 +0200 Subject: [PATCH 17/17] Fix build on Mac OS X The header stdio.h on Mac OS X includes some defines to do buffer overflow checks if using _FORTIFY_SOURCE > 2, which is the default. Defining _FORTIFY_SOURCE=0 disables this behavior. The Mac OS X linker ld64 has problem with common symbols in static archives. The workaround here is to run 'ranlib -c' on the static archive. --- firmware/Makefile.inc | 2 ++ firmware/Makefile.util | 1 + simulat0r/firmware/Makefile.inc | 8 ++++++++ 3 files changed, 11 insertions(+) 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/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 =