diff --git a/firmware/applications/font.c b/firmware/applications/font.c index 9801653..a79b055 100644 --- a/firmware/applications/font.c +++ b/firmware/applications/font.c @@ -7,6 +7,7 @@ #include "lcd/allfonts.h" #include "filesystem/ff.h" +#include "filesystem/select.h" #include "funk/nrf24l01p.h" #include "usb/usbmsc.h" @@ -75,35 +76,22 @@ void f_init(void){ lcdPrintln("Done."); }; - -static FONT fonts[] = { - &Font_7x8, - &Font_Ubuntu18pt, - &Font_Ubuntu29pt, - &Font_Ubuntu36pt, - &Font_Orbitron14pt, - &Font_3x6, - &Font_5x8, - &Font_8x8, - &Font_8x8Thin, - &Font_Invaders -}; - +char fontname[15]; void f_nick(void){ static char ctr=0; char key; - signed char x=10; - signed char y=10; + static signed char x=10; + static signed char y=10; while (1) { lcdClear(); lcdFill(255); - font=fonts[ctr%10]; - DoString(x,y,nickname); -// lcdSafeSetPixel(x,y,1); + setExtFont(fontname); - font=&Font_7x8; + DoString(x,y,nickname); + + setIntFont(&Font_7x8); lcdSetCrsr(50,50); lcdPrintInt(x); lcdPrint("x"); @@ -135,6 +123,23 @@ void f_nick(void){ }; }; +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); +}; + /***********************************************************************/ void gotoISP(void) { @@ -178,7 +183,7 @@ 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_snd = {"F Send", &f_send}; +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}; @@ -188,7 +193,7 @@ const struct MENU_DEF menu_nop = {"---", NULL}; static menuentry menu[] = { &menu_init, &menu_nick, -// &menu_snd, + &menu_font, &menu_nop, &menu_mirror, &menu_invert, diff --git a/firmware/applications/funk.c b/firmware/applications/funk.c index 0160188..d592dbe 100644 --- a/firmware/applications/funk.c +++ b/firmware/applications/funk.c @@ -227,7 +227,7 @@ void main_funk(void) { backlightInit(); font=&Font_7x8; - openbeaconSetup(0x5ec); + openbeaconSetup(); while (1) { lcdFill(0); // clear display buffer lcdDisplay(); diff --git a/firmware/applications/vcard.c b/firmware/applications/vcard.c index 6cbda10..a5bf28a 100644 --- a/firmware/applications/vcard.c +++ b/firmware/applications/vcard.c @@ -58,7 +58,6 @@ int receiveKey(uint8_t type, uint8_t *x, uint8_t *y) uint8_t n; n = nrf_rcv_pkt_time(1000, 32, buf); - lcdPrint("pkt:"); lcdPrintInt(n);lcdPrintln(""); lcdRefresh(); if( n == 32 && buf[0] == type && buf[1] == 'X' ){ for(int i=0; i + +uint32_t GetUUID32(void); + +#endif + diff --git a/firmware/funk/filetransfer.c b/firmware/funk/filetransfer.c index aa8618a..ffa4b94 100644 --- a/firmware/funk/filetransfer.c +++ b/firmware/funk/filetransfer.c @@ -17,6 +17,7 @@ int filetransfer_send(uint8_t *filename, uint16_t size, FRESULT res; UINT readbytes; + if( size > MAXSIZE ) return 1; //File to big @@ -25,6 +26,9 @@ int filetransfer_send(uint8_t *filename, uint16_t size, return res; //res = f_read(&file, (char *)buf, size, &readbytes); + for(uint16_t i=0; i MAXSIZE ) return 1; //file to big //if(fileexists(metadata)) return 1; //file already exists - lcdPrint("open"); lcdPrintln((const char*)metadata); lcdRefresh(); + //lcdPrint("open"); lcdPrintln((const char*)metadata); lcdRefresh(); res = f_open(&file, (const char*)metadata, FA_OPEN_ALWAYS|FA_WRITE); //lcdPrintln("file opened"); lcdRefresh(); @@ -90,9 +97,18 @@ int filetransfer_receive(uint8_t *mac, uint32_t const k[4]) uint16_t wordcount = (size+3)/4; //nrf_set_rx_mac(0, 32, 5, mac); - lcdPrintln("get file"); lcdRefresh(); - rftransfer_receive(buf, wordcount*4, 1000); - lcdPrintln("got file"); lcdRefresh(); + //lcdPrintln("get file"); lcdRefresh(); + int fres = rftransfer_receive(buf, wordcount*4, 1000); + if( fres == -1 ){ + lcdPrintln("checksum wrong"); + }else if( fres == -2 ){ + lcdPrintln("timeout"); + }else{ + //lcdPrintln("got file"); + } + lcdRefresh(); + if( fres < 0 ) + return; //nrf_set_rx_mac(0, 32, 5, macbuf); xxtea_decode_words((uint32_t *)buf, wordcount, k); @@ -103,6 +119,8 @@ int filetransfer_receive(uint8_t *mac, uint32_t const k[4]) return res; if( written != size ) return 1; //error while writing + lcdClear(); + lcdPrintln("Received"); lcdPrintln((const char*)metadata); lcdRefresh(); return 0; } diff --git a/firmware/funk/openbeacon.c b/firmware/funk/openbeacon.c index 2b919bf..ab90436 100644 --- a/firmware/funk/openbeacon.c +++ b/firmware/funk/openbeacon.c @@ -4,6 +4,7 @@ #include "basic/byteorder.h" #include "sysdefs.h" #include "filesystem/ff.h" +#include "basic/uuid.h" //const uint32_t key[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}; const uint32_t openbeaconkey[4] = { 0xB4595344,0xD3E119B6,0xA814D0EC,0xEFF5A24E }; @@ -59,9 +60,9 @@ void openbeaconRead() } -void openbeaconSetup(uint32_t id) +void openbeaconSetup(void) { - oid = id; + oid = GetUUID32(); strength = 0; openbeaconRead(); openbeaconSaveBlock(); diff --git a/firmware/funk/rftransfer.c b/firmware/funk/rftransfer.c index 335b13a..7c52423 100644 --- a/firmware/funk/rftransfer.c +++ b/firmware/funk/rftransfer.c @@ -16,7 +16,6 @@ void rftransfer_send(uint16_t size, uint8_t *data) buf[3] = rand >> 8; buf[4] = rand & 0xFF; - //nrf_snd_pkt_crc(5,buf); //setup packet nrf_snd_pkt_crc(32,buf); //setup packet delayms(20); uint16_t index = 0; @@ -29,7 +28,7 @@ void rftransfer_send(uint16_t size, uint8_t *data) buf[2] = index & 0xFF; buf[3] = rand >> 8; buf[4] = rand & 0xFF; - for(i=5; i0; i++,size--){ + for(i=5; i0; i++,size--){ buf[i] = *data++; } index++; @@ -42,12 +41,11 @@ void rftransfer_send(uint16_t size, uint8_t *data) buf[2] = crc & 0xFF; buf[3] = rand >> 8; buf[4] = rand & 0xFF; - //nrf_snd_pkt_crc(5,buf); //crc packet nrf_snd_pkt_crc(32,buf); //setup packet delayms(20); } -uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout) +int16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout) { uint8_t buf[MAXPACKET]; uint8_t state = 0; @@ -56,7 +54,7 @@ uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout) unsigned int currentTick = systickGetTicks(); unsigned int startTick = currentTick; - while(currentTick < (startTick+timeout) ){//this fails if either overflows + while(systickGetTicks() < (startTick+timeout) ){//this fails if either overflows n = nrf_rcv_pkt_time(1000, MAXPACKET, buf); switch(state){ case 0: @@ -66,45 +64,45 @@ uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout) seq = 0; pos = 0; if( size <= maxlen ){ - lcdClear(); - lcdPrintln("got l"); lcdRefresh(); + //lcdClear(); + //lcdPrint("got l="); lcdPrintInt(size); + //lcdPrintln(""); lcdRefresh(); state = 1; } } break; case 1: if( n == 32 && buf[0] == 'D' && ((buf[3]<<8)|buf[4])==rand ){ - lcdPrint("got d"); lcdRefresh(); + //lcdPrint("got d"); lcdRefresh(); if( seq == ((buf[1]<<8)|buf[2]) ){ - lcdPrintln(" in seq"); lcdRefresh(); - //if( (pos + n - 5) void rftransfer_send(uint16_t size, uint8_t *data); -uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout); +int16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout); #endif diff --git a/firmware/lcd/decoder.c b/firmware/lcd/decoder.c index d4ff7b8..7073ee4 100644 --- a/firmware/lcd/decoder.c +++ b/firmware/lcd/decoder.c @@ -1,9 +1,6 @@ #include #include -#define MAXCHR (30*20) -static uint8_t buf[MAXCHR]; - // Local function: Get next nibble. int ctr=0; // offset for next nibble int hilo=0; // 0= high nibble next, 1=low nibble next @@ -15,7 +12,11 @@ static uint8_t buf[MAXCHR]; ctr++; hilo=1-hilo; if(hilo==1){ - byte=data[ctr]; + if(efont.type==FONT_EXTERNAL){ + byte=_getFontData(GET_DATA,0); + }else{ + byte=data[ctr]; + }; val=byte>>4; }else{ val=byte&0x0f; @@ -44,7 +45,7 @@ uint8_t * pk_decode(const uint8_t * ldata,int * len){ int length=*len; // Length of character bytestream int height; // Height of character in bytes int hoff; // bit position for non-integer heights - uint8_t * bufptr=buf; // Output buffer for decoded character + uint8_t * bufptr=charBuf; // Output buffer for decoded character height=(font->u8Height-1)/8+1; hoff=font->u8Height%8; @@ -55,10 +56,17 @@ uint8_t * pk_decode(const uint8_t * ldata,int * len){ int pos=0; // Decoder internal: current bit position (0..7) int nyb; // Decoder internal: current nibble / value - if(data[ctr]>>4 == 14){ // Char starts with 1-bits. - gnn(); - curbit=1; - }; + if(efont.type==FONT_EXTERNAL){ + if(_getFontData(PEEK_DATA,0)>>4 == 14){ // Char starts with 1-bits. + gnn(); + curbit=1; + }; + }else{ + if(data[ctr]>>4 == 14){ // Char starts with 1-bits. + gnn(); + curbit=1; + }; + }; while(ctr0){ for(int y=0;y + #include #include #include #include +#include "basic/basic.h" +#include "fonts/smallfonts.h" + +#include "filesystem/ff.h" /* Global Variables */ const struct FONT_DEF * font = NULL; -char font_direction = FONT_DIR_LTR; + +struct EXTFONT efont; + +FIL file; /* current font file */ /* Exported Functions */ +void setIntFont(const struct FONT_DEF * font){ + memcpy(&efont.def,font,sizeof(struct FONT_DEF)); + efont.type=FONT_INTERNAL; + font=NULL; +}; + +void setExtFont(const char *fname){ + if(strlen(fname)>8+4) + return; + strcpy(efont.name,fname); +// memcpy(efont.name+strlen(fname),".f0n",5); + + efont.type=FONT_EXTERNAL; + font=NULL; +}; + + +int _getFontData(int type, int offset){ + UINT readbytes; + UINT res; + static uint16_t extras; + static uint16_t character; + static const void * ptr; + + if(efont.type == FONT_EXTERNAL){ + + if (type == START_FONT){ + res = f_read(&file, &efont.def.u8Width, sizeof(uint8_t), &readbytes); + res = f_read(&file, &efont.def.u8Height, sizeof(uint8_t), &readbytes); + res = f_read(&file, &efont.def.u8FirstChar, sizeof(uint8_t), &readbytes); + res = f_read(&file, &efont.def.u8LastChar, sizeof(uint8_t), &readbytes); + res = f_read(&file, &extras, sizeof(uint16_t), &readbytes); + return 0; + }; + if (type == SEEK_EXTRAS){ + f_lseek(&file,6); + return 0; + }; + if(type == GET_EXTRAS){ + uint16_t word; + res = f_read(&file, &word, sizeof(uint16_t), &readbytes); + return word; + }; + if (type == SEEK_WIDTH){ + f_lseek(&file,6+(extras*sizeof(uint16_t))); + return 0; + }; + if(type == GET_WIDTH || type == GET_DATA){ + uint8_t width; + res = f_read(&file, &width, sizeof(uint8_t), &readbytes); + return width; + }; + if(type == SEEK_DATA){ + character=offset; + f_lseek(&file,6+ + (extras*sizeof(uint16_t))+ + ((extras+font->u8LastChar-font->u8FirstChar)*sizeof(uint8_t))+ + (offset*sizeof(uint8_t)) + ); + return 0; + }; + if(type == PEEK_DATA){ + uint8_t width; + res = f_read(&file, &width, sizeof(uint8_t), &readbytes); + f_lseek(&file,6+ + (extras*sizeof(uint16_t))+ + ((extras+font->u8LastChar-font->u8FirstChar)*sizeof(uint8_t))+ + (character*sizeof(uint8_t)) + ); + return width; + }; +#ifdef NOTYET + }else{ // efont.type==FONT_INTERNAL + + if (type == START_FONT){ + memcpy(&efont.def,font,sizeof(struct FONT_DEF)); + return 0; + }; + if (type == SEEK_EXTRAS){ + ptr=efont.def.charExtra; + return 0; + }; + if(type == GET_EXTRAS){ + uint16_t word; + word=*(uint16_t*)ptr; + ptr=((uint16_t*)ptr)+1; + return word; + }; + if (type == SEEK_WIDTH){ + ptr=efont.def.charInfo; + return 0; + }; + if(type == GET_WIDTH || type == GET_DATA){ + uint8_t width; + width=*(uint8_t*)ptr; + ptr=((uint8_t*)ptr)+1; + return width; + }; + if(type == SEEK_DATA){ + if(offset==REPEAT_LAST_CHARACTER) + offset=character; + else + character=offset; + + ptr=efont.def.au8FontTable; + return 0; + }; +#endif + }; + + /* NOTREACHED */ + return 0; +}; + +int _getIndex(int c){ +#define ERRCHR (font->u8FirstChar+1) + /* Does this font provide this character? */ + if(cu8FirstChar) + c=ERRCHR; + if(c>font->u8LastChar && efont.type!=FONT_EXTERNAL && font->charExtra == NULL) + c=ERRCHR; + + if(c>font->u8LastChar && (efont.type==FONT_EXTERNAL || font->charExtra != NULL)){ + if(efont.type==FONT_EXTERNAL){ + _getFontData(SEEK_EXTRAS,0); + int cc=0; + int cache; + while( (cache=_getFontData(GET_EXTRAS,0)) < c) + cc++; + if( cache > c) + c=ERRCHR; + else + c=font->u8LastChar+cc+1; + }else{ + int cc=0; + while( font->charExtra[cc] < c) + cc++; + if(font->charExtra[cc] > c) + c=ERRCHR; + else + c=font->u8LastChar+cc+1; + }; + }; + c-=font->u8FirstChar; + return c; +}; + +uint8_t charBuf[MAXCHR]; + int DoChar(int sx, int sy, int c){ +// font=NULL; + if(font==NULL){ + if(efont.type==FONT_INTERNAL){ + font=&efont.def; + }else if (efont.type==FONT_EXTERNAL){ + UINT res; + res=f_open(&file, efont.name, FA_OPEN_EXISTING|FA_READ); + if(res){ + efont.type=0; + font=&Font_7x8; + }else{ + _getFontData(START_FONT,0); + font=&efont.def; + }; + }else{ + font=&Font_7x8; + }; + }; + /* how many bytes is it high? */ char height=(font->u8Height-1)/8+1; char hoff=(8-(font->u8Height%8))%8; @@ -18,49 +195,76 @@ int DoChar(int sx, int sy, int c){ const uint8_t * data; int width,preblank=0,postblank=0; do { /* Get Character data */ - /* Does this font provide this character? */ - if(cu8FirstChar) - c=font->u8FirstChar+1; // error - if(c>font->u8LastChar && font->charExtra == NULL) - c=font->u8FirstChar+1; // error - - if(c>font->u8LastChar && font->charExtra != NULL){ - int cc=0; - while( font->charExtra[cc] < c) - cc++; - if(font->charExtra[cc] > c) - c=font->u8FirstChar+1; // error - else - c=font->u8LastChar+cc+1; - }; + /* Get intex into character list */ + c=_getIndex(c); /* starting offset into character source data */ int toff=0; if(font->u8Width==0){ - for(int y=0;yu8FirstChar;y++) - toff+=font->charInfo[y].widthBits; - width=font->charInfo[c-font->u8FirstChar].widthBits; + if(efont.type == FONT_EXTERNAL){ + _getFontData(SEEK_WIDTH,0); + for(int y=0;yau8FontTable[toff]; + _getFontData(SEEK_DATA,toff); + UINT res; + UINT readbytes; + res = f_read(&file, charBuf, width*height, &readbytes); + if(res != FR_OK || readbytescharInfo[y].widthBits; + width=font->charInfo[c].widthBits; + + toff*=height; + data=&font->au8FontTable[toff]; + }; postblank=1; }else if(font->u8Width==1){ // NEW CODE - // Find offset and length for our character - for(int y=0;yu8FirstChar;y++) - toff+=font->charInfo[y].widthBits; - width=font->charInfo[c-font->u8FirstChar].widthBits; - - if(font->au8FontTable[toff]>>4 == 15){ // It's a raw character! - preblank = font->au8FontTable[toff+1]; - postblank= font->au8FontTable[toff+2]; - data=&font->au8FontTable[toff+3]; - width=(width-3/height); + if(efont.type == FONT_EXTERNAL){ + _getFontData(SEEK_WIDTH,0); + for(int y=0;y>4 ==15){ + res = f_read(&file, &preblank, sizeof(uint8_t), &readbytes); + res = f_read(&file, &postblank, sizeof(uint8_t), &readbytes); + width-=3; + width/=height; + res = f_read(&file, charBuf, width*height, &readbytes); + if(res != FR_OK || readbytesau8FontTable[toff],&width); - } + // Find offset and length for our character + for(int y=0;ycharInfo[y].widthBits; + width=font->charInfo[c].widthBits; + if(font->au8FontTable[toff]>>4 == 15){ // It's a raw character! + preblank = font->au8FontTable[toff+1]; + postblank= font->au8FontTable[toff+2]; + data=&font->au8FontTable[toff+3]; + width=(width-3/height); + }else{ + data=pk_decode(&font->au8FontTable[toff],&width); + } + }; + }else{ - toff=(c-font->u8FirstChar)*font->u8Width*height; + toff=(c)*font->u8Width*height; width=font->u8Width; data=&font->au8FontTable[toff]; }; diff --git a/firmware/lcd/render.h b/firmware/lcd/render.h index 563c6a0..eaa69ef 100644 --- a/firmware/lcd/render.h +++ b/firmware/lcd/render.h @@ -2,6 +2,7 @@ #define __RENDER_H_ #include "display.h" +#include "fonts.h" /* #badge 96x68 @@ -33,5 +34,21 @@ int DoIntXn(int sx, int sy, unsigned int num, unsigned int maxlen); int DoIntX(int sx, int sy, unsigned int num); int DoCharX(int sx, int sy, unsigned char num); int DoShortX(int sx, int sy, uint16_t num); +void setIntFont(const struct FONT_DEF * font); +void setExtFont(const char *file); + +#define START_FONT 0 +#define SEEK_EXTRAS 1 +#define GET_EXTRAS 2 +#define SEEK_WIDTH 3 +#define GET_WIDTH 4 +#define SEEK_DATA 5 +#define GET_DATA 6 +#define PEEK_DATA 7 + +int _getFontData(int type, int offset); + +#define MAXCHR (30*20) +extern uint8_t charBuf[MAXCHR]; #endif diff --git a/tools/font/binary/invaders.f0n b/tools/font/binary/invaders.f0n new file mode 100644 index 0000000..9f5b284 Binary files /dev/null and b/tools/font/binary/invaders.f0n differ diff --git a/tools/font/binary/orbit14.f0n b/tools/font/binary/orbit14.f0n new file mode 100644 index 0000000..cf77c3a Binary files /dev/null and b/tools/font/binary/orbit14.f0n differ diff --git a/tools/font/binary/ubuntu18.f0n b/tools/font/binary/ubuntu18.f0n new file mode 100644 index 0000000..8d13d36 Binary files /dev/null and b/tools/font/binary/ubuntu18.f0n differ diff --git a/tools/font/binary/ubuntu29.f0n b/tools/font/binary/ubuntu29.f0n new file mode 100644 index 0000000..60e33cf Binary files /dev/null and b/tools/font/binary/ubuntu29.f0n differ diff --git a/tools/font/binary/ubuntu36.f0n b/tools/font/binary/ubuntu36.f0n new file mode 100644 index 0000000..df0bd90 Binary files /dev/null and b/tools/font/binary/ubuntu36.f0n differ