diff --git a/firmware/Makefile b/firmware/Makefile index 349b4ff..40e36bc 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -10,8 +10,12 @@ VPATH += OBJS += main.o ifeq "$(wildcard table.c)" "table.c" +ifeq "$(APP)" "serial" +OBJS += +else OBJS += table.o endif +endif LIBS += lcd/liblcd.a LIBS += basic/libbasic.a diff --git a/firmware/SERIAL_DOKU b/firmware/SERIAL_DOKU index d67b459..99bb071 100644 --- a/firmware/SERIAL_DOKU +++ b/firmware/SERIAL_DOKU @@ -1,11 +1,18 @@ i: initialize -cb / cm / cr: config funk for beacon/mesh/remote -Ck: set encryptionkey -Ct: set txmac -Cc: set channel -Ct: set rxmac(0) -Cl: set rxlens -Ce: sec encrpytion on/off +pb: preset funk for beacon +pm: preset funk for mesh +pM: preset funk for pubMesh +pr: preset funk for rem0te + +t: set packet dump type (b/B/m/M/0) +f: set filter stuff + +ck: set encryptionkey +cm: set rxmac(0) +ct: set txmac +cc: set channel +cl: set rxlen +ce: sec encrpytion on/off s : send packet s+ : send packet 10 times @@ -13,4 +20,4 @@ sd : send packet with debugoutput r: recv packets r+: recv packets for seconds -r-: recv packets (5 seconds max) +r-: recv packets diff --git a/firmware/applications/serial.c b/firmware/applications/serial.c new file mode 100644 index 0000000..acb5cf4 --- /dev/null +++ b/firmware/applications/serial.c @@ -0,0 +1,20 @@ +#include + +#include "basic/basic.h" +#include "basic/config.h" + +#include + +/**************************************************************************/ + +#include "serial.gen" + +void main_serial(void) { + GLOBAL(daytrig)=10; + GLOBAL(lcdbacklight)=10; + handleMenu(&mainmenu); + gpioSetValue (RB_LED3, 1); + ISPandReset(); +}; + +void serial(void); diff --git a/firmware/applications/serial/serial.c b/firmware/applications/serial/serial.c index e780fbf..30ffae2 100644 --- a/firmware/applications/serial/serial.c +++ b/firmware/applications/serial/serial.c @@ -23,7 +23,7 @@ #define BEACON_CHANNEL 81 #define BEACON_MAC "\x1\x2\x3\x2\1" -#include "SECRETS" +#include "SECRETS.release" char funkencrypt=0; @@ -47,9 +47,15 @@ struct NRF_CFG config = { .maclen ="\x10", }; -int process(char * input); +char type=0; +char filter=0; +uint8_t filterdata[10]; +char outc[2]= {0,0}; + +static int process(char * input); #define INPUTLEN 99 +//# MENU serial void dwim(void){ char input[INPUTLEN+1]; int inputptr=0; @@ -58,6 +64,8 @@ void dwim(void){ usbCDCInit(); delayms(500); getInputWaitRelease(); + nrf_init(); + gpioSetValue (RB_LED1, 0); puts("D start\r\n"); while(!getInputRaw()){ @@ -97,13 +105,13 @@ void dwim(void){ }; inputptr+=l; }; - + gpioSetValue (RB_LED1, 0); puts("D exit\r\n"); } #define BUFLEN 32 #define NYB(x) ((x>'9')?(x|0x20)-'a'+10:x-'0') -uint8_t * hextobyte(char * input, int *len){ +static uint8_t * hextobyte(char * input, int *len){ static uint8_t buf[BUFLEN]; int p=0; @@ -123,7 +131,16 @@ uint8_t * hextobyte(char * input, int *len){ return buf; }; -int process(char * input){ +static uint32_t gethexval(char * input){ + int len; + uint8_t *hex=hextobyte(input,&len); + uint32_t v=hex[0]; + while(--len>0) + v=v*256+(*++hex); + return v; +}; + +static int process(char * input){ if(input == NULL || input[0]==0) return -1; @@ -135,7 +152,8 @@ int process(char * input){ if(input[0]=='i'){ nrf_init(); nrf_config_set(&config); - }else if(input[0]=='c'){ + }else if(input[0]=='p'){ + type=input[1]; if(input[1]=='m'){ config.channel=MESH_CHANNEL; memcpy(config.txmac,MESH_MAC,5); @@ -145,6 +163,18 @@ int process(char * input){ nrf_config_set(&config); memcpy(thekey,meshkey,sizeof(thekey)); funkencrypt=1; + }else if(input[1]=='M'){ + config.channel=83; + memcpy(config.txmac,MESH_MAC,5); + memcpy(config.mac0,MESH_MAC,5); + config.maclen[0]=0x20; + config.nrmacs=1; + nrf_config_set(&config); + static const uint32_t const pubmesh[4] = { + 0x00000042, 0x000005ec, 0x00000023, 0x00000005 + }; + memcpy(thekey,pubmesh,sizeof(thekey)); + funkencrypt=1; }else if(input[1]=='r'){ config.channel=REMOTE_CHANNEL; memcpy(config.txmac,REMOTE_MAC,5); @@ -163,6 +193,43 @@ int process(char * input){ nrf_config_set(&config); memcpy(thekey,openbeaconkey,sizeof(thekey)); funkencrypt=1; + }else if(input[1]=='B'){ + config.channel=BEACON_CHANNEL; + memcpy(config.txmac,BEACON_MAC,5); + memcpy(config.mac0,BEACON_MAC,5); + config.maclen[0]=0x10; + config.nrmacs=1; + nrf_config_set(&config); + static const uint32_t pubbeaconkey[4] = { + 0xB4595344, 0xD3E119B6, 0xA814D0EC, 0xEFF5A24E + }; + memcpy(thekey,pubbeaconkey,sizeof(thekey)); + funkencrypt=1; + }; + }else if(input[0]=='t'){ + type=input[1]; + }else if(input[0]=='c'){ + int len; + uint8_t *hex=hextobyte(&input[2],&len); + if(input[1]=='k'){ + thekey[0]=uint8ptouint32(hex); + thekey[1]=uint8ptouint32(hex+4); + thekey[2]=uint8ptouint32(hex+8); + thekey[3]=uint8ptouint32(hex+12); + }else if(input[1]=='m'){ + memcpy(config.mac0,hex,5); + nrf_config_set(&config); + }else if(input[1]=='t'){ + memcpy(config.txmac,hex,5); + nrf_config_set(&config); + }else if(input[1]=='c'){ + config.channel=hex[0]; + nrf_config_set(&config); + }else if(input[1]=='l'){ + config.maclen[0]=hex[0]; + nrf_config_set(&config); + }else if(input[1]=='e'){ + funkencrypt= hex[0]; }else if(input[1]=='?'){ nrf_config_get(&config); puts_plus("Ch: ");puts_plus(IntToStrX( config.channel,2 )); puts_plus("\r\n"); @@ -203,41 +270,6 @@ int process(char * input){ puts_plus(IntToStrX( funkencrypt,2 )); puts_plus("\r\n"); }; - }else if(input[0]=='C'){ - int len; - uint8_t *hex=hextobyte(&input[2],&len); - if(input[1]=='k'){ - thekey[0]=uint8ptouint32(hex); - thekey[1]=uint8ptouint32(hex+4); - thekey[2]=uint8ptouint32(hex+8); - thekey[3]=uint8ptouint32(hex+12); - }else if(input[1]=='m'){ - config.mac0[0]=uint8ptouint32(hex); - config.mac0[1]=uint8ptouint32(hex+4); - config.mac0[2]=uint8ptouint32(hex+8); - config.mac0[3]=uint8ptouint32(hex+12); - config.mac0[4]=uint8ptouint32(hex+16); - nrf_config_set(&config); - }else if(input[1]=='t'){ - config.txmac[0]=uint8ptouint32(hex); - config.txmac[1]=uint8ptouint32(hex+4); - config.txmac[2]=uint8ptouint32(hex+8); - config.txmac[3]=uint8ptouint32(hex+12); - config.txmac[4]=uint8ptouint32(hex+16); - nrf_config_set(&config); - }else if(input[1]=='c'){ - config.channel=*hex; - nrf_config_set(&config); - }else if(input[1]=='l'){ - config.maclen[0]=uint8ptouint32(hex); - config.maclen[1]=uint8ptouint32(hex+4); - config.maclen[2]=uint8ptouint32(hex+8); - config.maclen[3]=uint8ptouint32(hex+12); - config.maclen[4]=uint8ptouint32(hex+16); - nrf_config_set(&config); - }else if(input[1]=='e'){ - funkencrypt= uint8ptouint32(hex); - }; }else if (input[0]=='s'){ __attribute__ ((aligned (4))) uint8_t buf[32]; int status=0; @@ -262,14 +294,18 @@ int process(char * input){ memcpy(buf,hex,len); status=nrf_snd_pkt_crc_encr(len,buf,funkencrypt?thekey:NULL); - puts_plus("P "); - puts_plus("[");puts_plus(IntToStrX(len,2));puts_plus("] "); if(debug){ + puts_plus("P "); + puts_plus("[");puts_plus(IntToStrX(len,2));puts_plus("] "); for(int i=0;i0){ @@ -277,46 +313,60 @@ int process(char * input){ memcpy(buf,hex,len); status=nrf_snd_pkt_crc_encr(len,buf,funkencrypt?thekey:NULL); }; - }else if (input[1]=='t'){ - static int ctr=1; - int status; - - buf[0]=0x10; // Length: 16 bytes - buf[1]='1'; // Proto - buf[2]=0x00; - buf[3]=0x00; // Unused - - uint32touint8p(ctr++,buf+4); - - uint32touint8p(0x5ec,buf+8); - - buf[12]=0xff; // salt (0xffff always?) - buf[13]=0xff; - status=nrf_snd_pkt_crc_encr(16,buf,funkencrypt?thekey:NULL); }else{ + ; + }; + puts_plus("\r\n"); + }else if (input[0]=='f'){ + int len; + filter=input[1]; + uint8_t *hex=hextobyte(input+2,&len); + if(len>9) + len=9; + memcpy(filterdata,hex,len); + puts_plus("F "); + if(filter){ + puts_plus("["); + outc[0]=filter; + puts_plus(outc); + puts_plus("]"); + for(int i=0;i0) + t=getTimer()+t*1000/SYSTICKSPEED; nrf_rcv_pkt_start(); do{ len=nrf_rcv_pkt_poll_dec(sizeof(buf),buf,funkencrypt?thekey:NULL); @@ -325,17 +375,76 @@ int process(char * input){ delayms(10); continue; }; - puts_plus("R "); - puts_plus("[");puts_plus(IntToStrX(len,2));puts_plus("] "); - if(len==-3){ - puts_plus("[!crc] "); - len=16; + if (!filter){ + if(len==-3){ + puts_plus("[!crc] "); + len=32; + }; }; - for(int i=0;i0){ @@ -344,9 +453,9 @@ int process(char * input){ }; }; puts("\r\n"); - if(pctr--==0) + if(--pctr==0) break; - }while(t>getTimer()); + }while((t>0)?(t>getTimer()):1); nrf_rcv_pkt_end(); }else{ diff --git a/firmware/applications/uart.c b/firmware/applications/uart.c new file mode 100644 index 0000000..8712a86 --- /dev/null +++ b/firmware/applications/uart.c @@ -0,0 +1,49 @@ +#include + +#include "basic/basic.h" + +#include "lcd/print.h" + +#include + + +#include "core/cpu/cpu.h" +#include "core/uart/uart.h" + +/**************************************************************************/ +#define BUF 5 + +void main_uart(void) { + uint8_t uartBuffer[BUF] = { 'T', 'e', 's', 't', '\n' }; +uint8_t o[2]={0,0}; + + gpioSetDir(RB_LED0, gpioDirection_Output); + gpioSetValue (RB_LED0, 1); + lcdPrintln("Hi"); + lcdRefresh(); + uartInit(9600); + lcdPrintln("Inited."); + lcdRefresh(); + + uartSend((uint8_t *)uartBuffer, BUF); + lcdPrintln("sent."); + lcdRefresh(); + + uartRxBufferWrite('x'); + + // Get a reference to the UART control block +// uart_pcb_t *pcb = uartGetPCB(); + + gpioSetValue (RB_LED0, 1-gpioGetValue(RB_LED0)); + // Read any text available in the queue + while (uartRxBufferDataPending()) + { + gpioSetValue (RB_LED0, 1-gpioGetValue(RB_LED0)); + // Read the first available character + uint8_t c = uartRxBufferRead(); + o[0]=c; + lcdPrint(o); + lcdRefresh(); + uartSend(&c, 1); + } +}; diff --git a/firmware/core/projectconfig.h b/firmware/core/projectconfig.h index 7d58144..41d5420 100644 --- a/firmware/core/projectconfig.h +++ b/firmware/core/projectconfig.h @@ -82,3 +82,9 @@ #define CFG_USBCDC_BUFFERSIZE (256) +/* you will need these for the UART */ +#if 0 +#define CFG_INTERFACE_UART (1) +#define CFG_UART_BAUDRATE (115200) +#define CFG_UART_BUFSIZE (512) +#endif diff --git a/firmware/l0dable/voltage.c b/firmware/l0dable/voltage.c new file mode 100644 index 0000000..70a5266 --- /dev/null +++ b/firmware/l0dable/voltage.c @@ -0,0 +1,50 @@ +#include +#include + +#include "basic/basic.h" +#include "basic/config.h" + +#include "lcd/render.h" +#include "lcd/print.h" + +#include "usetable.h" + +/**************************************************************************/ + +void ram(void) { + int v,mv; + do{ + lcdClear(); + lcdPrintln("Battery status:"); + mv=GetVoltage(); + v=mv/1000; + + lcdNl(); + if (mv<3550){ + lcdPrintln(" Charge NOW!"); + }else if (mv<3650){ + lcdPrintln(" Charge soon"); + }else if (mv<4000){ + lcdPrintln(" OK"); + }else if(mv<4200){ + lcdPrintln(" Good"); + }else{ + lcdPrintln(" Full"); + }; + + lcdNl(); + lcdPrint(" "); + lcdPrint(IntToStr(v,2,0)); + lcdPrint("."); + lcdPrint(IntToStr(mv%1000,3,F_ZEROS)); + lcdPrintln("V"); + + lcdNl(); + if(gpioGetValue(RB_PWR_CHRG)){ + lcdPrintln("(not charging)"); + }else{ + lcdPrintln("CHARGING"); + }; + lcdRefresh(); + } while ((getInputWaitTimeout(242))==BTN_NONE); +} diff --git a/tools/bootloader/autoflash-cygwin.sh b/tools/bootloader/autoflash-cygwin.sh index ee86308..e363880 100644 --- a/tools/bootloader/autoflash-cygwin.sh +++ b/tools/bootloader/autoflash-cygwin.sh @@ -1,4 +1,8 @@ drive=/cygdrive/f +if [ ! -z "$1" ] ; then + dirve=/cygdrive/$a +fi + file=$drive/firmware.bin while : ; do