From 942440ec0caa8b402c5254deb38ad16da74d0bd1 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 2 Aug 2011 10:50:51 +0200 Subject: [PATCH 1/5] Whoops. Swapped day/night invert --- firmware/applications/default.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/applications/default.c b/firmware/applications/default.c index 831adfb..eed6119 100644 --- a/firmware/applications/default.c +++ b/firmware/applications/default.c @@ -63,10 +63,10 @@ void tick_default(void) { night=isNight(); if(night){ backlightSetBrightness(GLOBAL(lcdbacklight)); - push_queue(queue_setinvert); + push_queue(queue_unsetinvert); }else{ backlightSetBrightness(0); - push_queue(queue_unsetinvert); + push_queue(queue_setinvert); }; }; }; From 999b3bd80998873a1a316ebceeade916355b2c8f Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 2 Aug 2011 10:51:34 +0200 Subject: [PATCH 2/5] Properly turn off flame when it's day. Also: skip everything if disabled. And: debugging display --- firmware/applications/final/flame.c | 36 ++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/firmware/applications/final/flame.c b/firmware/applications/final/flame.c index a67175c..d010671 100644 --- a/firmware/applications/final/flame.c +++ b/firmware/applications/final/flame.c @@ -61,8 +61,21 @@ 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) { @@ -135,3 +148,24 @@ void flameInit(void) { flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_PWM0 << FLAME_I2C_LS0_LED0); // set led0 to pwm } } + +#include "lcd/print.h" + +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(); + } while ((getInputRaw())==BTN_NONE); +} From 3c3d1032c5d87a44304826df005ac66f68568538 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 2 Aug 2011 10:54:05 +0200 Subject: [PATCH 3/5] Correct default for contrast setting. Add alivecheck(systick blink) setting --- firmware/basic/config.c | 5 +++-- firmware/basic/config.h | 29 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/firmware/basic/config.c b/firmware/basic/config.c index 4393798..84f6d5a 100644 --- a/firmware/basic/config.c +++ b/firmware/basic/config.c @@ -7,7 +7,7 @@ #include "basic/random.h" #include "basic/config.h" -#define CFGVER 24 +#define CFGVER 1 struct CDESC the_config[]= { {"version", CFGVER, CFGVER, CFGVER}, @@ -19,7 +19,8 @@ struct CDESC the_config[]= { {"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}, diff --git a/firmware/basic/config.h b/firmware/basic/config.h index 66365f9..bcd4f98 100644 --- a/firmware/basic/config.h +++ b/firmware/basic/config.h @@ -18,20 +18,21 @@ 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 GLOBALflamemax (the_config[9].value) -#define GLOBALflamemin (the_config[10].value) -#define GLOBALflamespeed (the_config[11].value) -#define GLOBALflamemaxw (the_config[12].value) -#define GLOBALflameminw (the_config[13].value) +#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) From 7eaa5f4e4b51454e2c4e7dd852b1d74fcde84f23 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 2 Aug 2011 10:55:01 +0200 Subject: [PATCH 4/5] more utility/debugging/info stuff --- firmware/applications/final/util.c | 40 +++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/firmware/applications/final/util.c b/firmware/applications/final/util.c index 9876ea4..401a3f5 100644 --- a/firmware/applications/final/util.c +++ b/firmware/applications/final/util.c @@ -4,6 +4,7 @@ #include "basic/basic.h" #include "basic/config.h" +#include "lcd/render.h" #include "lcd/print.h" #include "usb/usbmsc.h" @@ -40,7 +41,7 @@ void ChkBattery(void) { lcdPrintln("0"); }; lcdRefresh(); - delayms_queue(100); +// delayms_queue(100); } while ((getInputRaw())==BTN_NONE); } @@ -94,3 +95,40 @@ void uuid(void) { lcdPrintln(IntToStrX(GetUUID32(),4)); lcdRefresh(); } + +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; +}; From 3a4490db18d75acbd0b1195510d0c62d5e8e1fc1 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 2 Aug 2011 13:31:57 +0200 Subject: [PATCH 5/5] Some menu changes. Also: cleanup apps and make the rest build again --- firmware/applications/Makefile | 8 +- firmware/applications/adc.c | 3 - firmware/applications/exe.c | 26 +-- firmware/applications/executor.c | 181 ------------------ firmware/applications/final.c | 8 +- firmware/applications/final/config.c | 1 + firmware/applications/final/exe.c | 21 +++ firmware/applications/final/flame.c | 3 + firmware/applications/final/mesh.c | 15 +- firmware/applications/final/nickname.c | 25 +-- firmware/applications/final/util.c | 5 + firmware/applications/font.c | 36 ++-- firmware/applications/fs.c | 49 ++--- firmware/applications/funk.c | 251 ------------------------- firmware/applications/loadable.c | 29 +-- firmware/applications/menutest.c | 43 ++--- firmware/applications/mkfirmware | 73 ------- firmware/applications/mkfirmware.pl | 123 ++++++++++++ firmware/applications/remote.c | 197 ------------------- firmware/applications/tester.c | 2 - firmware/basic/basic.h | 4 +- firmware/basic/menu.c | 12 +- 22 files changed, 235 insertions(+), 880 deletions(-) delete mode 100644 firmware/applications/executor.c create mode 100644 firmware/applications/final/exe.c delete mode 100644 firmware/applications/funk.c delete mode 100755 firmware/applications/mkfirmware create mode 100755 firmware/applications/mkfirmware.pl delete mode 100644 firmware/applications/remote.c diff --git a/firmware/applications/Makefile b/firmware/applications/Makefile index dacc19e..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 @@ -71,7 +75,7 @@ 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=$(APP).gen @@ -81,7 +85,7 @@ TWRAP=$(APP).gen $(APP).o: $(TWRAP) $(TWRAP): - ./mkfirmware $(APP) $(TSRCS) > $@ + ./mkfirmware.pl $(DEBUG) $(APP) $(TSRCS) > $@ OBJS += $(TOBJS) endif 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/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 index 16525d0..c2f757e 100644 --- a/firmware/applications/final.c +++ b/firmware/applications/final.c @@ -10,15 +10,13 @@ #include "final.gen" -static const struct MENU mainmenu = {"Menu", mentry}; - -void initNick(); +void init_nick(); void fancyNickname(); void main_final(void) { //checkFirstBoot(); + init_final(); - initNick(); while(1){ #ifndef FINAL if(getInputRaw()==BTN_LEFT) @@ -27,7 +25,7 @@ void main_final(void) { if(getInput()){ handleMenu(&mainmenu); getInputWaitRelease(); - initNick(); + init_nick(); }; fancyNickname(); delayms_queue(100); diff --git a/firmware/applications/final/config.c b/firmware/applications/final/config.c index 1451483..943d31d 100644 --- a/firmware/applications/final/config.c +++ b/firmware/applications/final/config.c @@ -25,6 +25,7 @@ void applycfg(void){ applyConfig(); }; +//# MENU config void changer(void){ uint8_t numentries = 0; signed char menuselection = 0; 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 index d010671..9775ad1 100644 --- a/firmware/applications/final/flame.c +++ b/firmware/applications/final/flame.c @@ -131,6 +131,7 @@ void tick_flame(void) { // every 10ms } } +//# MENU flame void flameInit(void) { i2cInit(I2CMASTER); // Init I2C @@ -151,6 +152,7 @@ void flameInit(void) { #include "lcd/print.h" +//# MENU debug ChkFlame void ChkFlame(void) { do{ lcdClear(); @@ -167,5 +169,6 @@ void ChkFlame(void) { 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 index c6d1f63..1dc3d95 100644 --- a/firmware/applications/final/mesh.c +++ b/firmware/applications/final/mesh.c @@ -16,19 +16,8 @@ /**************************************************************************/ -void m_init(void){ +void init_mesh(void){ nrf_init(); - - struct NRF_CFG config = { - .channel= MESH_CHANNEL, - .txmac= MESH_MAC, - .nrmacs=1, - .mac0= MESH_MAC, - .maclen ="\x20", // XXX: MESHPKTSIZE - }; - - nrf_config_set(&config); - initMesh(); }; @@ -36,6 +25,7 @@ void m_tset(void){ _timet=1311961112; }; +//# MENU debug MeshInfo void m_time(void){ struct tm* tm; char c[2]={0,0}; @@ -185,6 +175,7 @@ char *meshmsgs(void){ extern MPKT meshbuffer[MESHBUFSIZE]; +//# MENU mesh Messages void m_choose(){ char list[99]; int i=0; diff --git a/firmware/applications/final/nickname.c b/firmware/applications/final/nickname.c index 9eb46c7..48dde5f 100644 --- a/firmware/applications/final/nickname.c +++ b/firmware/applications/final/nickname.c @@ -33,17 +33,19 @@ void fancyNickname(void) { /**************************************************************************/ -void initNick(void){ +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){ @@ -60,24 +62,3 @@ void doFont(void){ lcdDisplay(); while(!getInputRaw())delayms(10); }; - - -#if 0 - void f_font(void){ - - if( selectFile(fontname,"F0N") != 0){ - lcdPrintln("No file selected."); - return; - }; - - lcdClear(); - lcdPrintln(fontname); - setExtFont(fontname); - lcdPrintln("PUabc€"); - setIntFont(&Font_7x8); - lcdPrintln("done."); - lcdDisplay(); - while(!getInputRaw())delayms(10); -}; - -#endif diff --git a/firmware/applications/final/util.c b/firmware/applications/final/util.c index 401a3f5..fca9cdc 100644 --- a/firmware/applications/final/util.c +++ b/firmware/applications/final/util.c @@ -13,6 +13,7 @@ /**************************************************************************/ +//# MENU debug ChkLight void ChkLight(void) { int dx=0; int dy=8; @@ -28,6 +29,7 @@ void ChkLight(void) { dx=DoString(0,dy+24,"Done."); } +//# MENU debug ChkBattery void ChkBattery(void) { do{ lcdClear(); @@ -45,6 +47,7 @@ void ChkBattery(void) { } while ((getInputRaw())==BTN_NONE); } +//# MENU debug Uptime void uptime(void) { int t; int h; @@ -81,6 +84,7 @@ void uptime(void) { lcdPrintln("done."); } +//# MENU debug Uuid void uuid(void) { IAP_return_t iap_return; iap_return = iapReadSerialNumber(); @@ -96,6 +100,7 @@ void uuid(void) { lcdRefresh(); } +//# MENU debug Qstatus void Qstatus(void) { int dx=0; int dy=8; diff --git a/firmware/applications/font.c b/firmware/applications/font.c index 9e6b045..75115b1 100644 --- a/firmware/applications/font.c +++ b/firmware/applications/font.c @@ -167,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/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/mkfirmware b/firmware/applications/mkfirmware deleted file mode 100755 index fdf7f2d..0000000 --- a/firmware/applications/mkfirmware +++ /dev/null @@ -1,73 +0,0 @@ -#!/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);" - 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 tick_${APP}(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/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/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/tester.c b/firmware/applications/tester.c index d494e42..c0dabab 100644 --- a/firmware/applications/tester.c +++ b/firmware/applications/tester.c @@ -10,8 +10,6 @@ #include "tester.gen" -static const struct MENU mainmenu = {"Mainmenu", mentry}; - void main_tester(void) { handleMenu(&mainmenu); gotoISP(); diff --git a/firmware/basic/basic.h b/firmware/basic/basic.h index ed67c74..df3f2c9 100644 --- a/firmware/basic/basic.h +++ b/firmware/basic/basic.h @@ -172,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[]; }; diff --git a/firmware/basic/menu.c b/firmware/basic/menu.c index 2216dd2..253bb55 100644 --- a/firmware/basic/menu.c +++ b/firmware/basic/menu.c @@ -17,7 +17,7 @@ void handleMenu(const struct MENU *the_menu) { setSystemFont(); - for (numentries = 0; the_menu->entries[numentries] != NULL; numentries++); + for (numentries = 0; the_menu->entries[numentries].text != NULL ; numentries++); visible_lines = lcdGetVisibleLines()-1; // subtract title line #ifdef SAFETY @@ -34,7 +34,7 @@ void handleMenu(const struct MENU *the_menu) { lcdPrint("*"); } lcdSetCrsrX(14); - lcdPrintln(the_menu->entries[i]->text); + lcdPrintln(the_menu->entries[i].text); } lcdRefresh(); @@ -64,16 +64,16 @@ 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(); + if (the_menu->entries[menuselection].callback!=NULL) + the_menu->entries[menuselection].callback(); lcdRefresh(); getInputWait();